Added connect.js
This commit is contained in:
parent
851ef2b01b
commit
694199b148
27
README.md
27
README.md
@ -6,6 +6,7 @@ These scripts are for playing the [open source](https://github.com/danielyxie/bi
|
|||||||
- [Table of Contents](#table-of-contents)
|
- [Table of Contents](#table-of-contents)
|
||||||
- [Quick Start](#quick-start)
|
- [Quick Start](#quick-start)
|
||||||
- [Scripts](#scripts)
|
- [Scripts](#scripts)
|
||||||
|
- [connect.js](#connectjs)
|
||||||
- [crawler.js](#crawlerjs)
|
- [crawler.js](#crawlerjs)
|
||||||
- [miner.js](#minerjs)
|
- [miner.js](#minerjs)
|
||||||
- [network-graph.js](#network-graphjs)
|
- [network-graph.js](#network-graphjs)
|
||||||
@ -29,12 +30,38 @@ run scripts/node-manager.js 8
|
|||||||
# Chain the crawler, rootkit & miner to hack everything on the network
|
# Chain the crawler, rootkit & miner to hack everything on the network
|
||||||
alias hackAll="run scripts/crawler.js /scripts/rootkit.js {{TARGET}} /scripts/miner.js"
|
alias hackAll="run scripts/crawler.js /scripts/rootkit.js {{TARGET}} /scripts/miner.js"
|
||||||
hackAll
|
hackAll
|
||||||
|
|
||||||
|
# Identify & install a backdoor on CSEC
|
||||||
|
run scripts/network-graph.js -f CSEC
|
||||||
|
run scripts/rootkit.js CSEC
|
||||||
|
run scripts/connect.js CSEC
|
||||||
|
backdoor
|
||||||
```
|
```
|
||||||
|
|
||||||
Learn more about the [availible scripts](#scripts) bellow or pass the `--help` flag to any of the included scripts in-game.
|
Learn more about the [availible scripts](#scripts) bellow or pass the `--help` flag to any of the included scripts in-game.
|
||||||
|
|
||||||
## Scripts
|
## Scripts
|
||||||
|
|
||||||
|
### [connect.js](./scripts/connect.js)
|
||||||
|
**RAM:** 1.85 GB
|
||||||
|
|
||||||
|
Connect to a device on a different network.
|
||||||
|
```
|
||||||
|
[home ~/]> run /scripts/connect.js --help
|
||||||
|
Running script with 1 thread(s), pid 1 and args: ["--help"].
|
||||||
|
/scripts/connect.js:
|
||||||
|
|
||||||
|
Connect to a device on a different network.
|
||||||
|
|
||||||
|
Usage: run connect.js DEVICE
|
||||||
|
run connect.js --help
|
||||||
|
|
||||||
|
DEVICE Device to connect to
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h --help Display this help message
|
||||||
|
```
|
||||||
|
|
||||||
### [crawler.js](./scripts/crawler.js)
|
### [crawler.js](./scripts/crawler.js)
|
||||||
**RAM:** 4.05 GB
|
**RAM:** 4.05 GB
|
||||||
|
|
||||||
|
48
scripts/connect.js
Normal file
48
scripts/connect.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import {ArgError, ArgParser} from './scripts/lib/arg-parser';
|
||||||
|
import {terminal} from './scripts/lib/utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to a device on a different network.
|
||||||
|
* @param ns {NS} - BitBurner API
|
||||||
|
*/
|
||||||
|
export function main(ns) {
|
||||||
|
// Setup
|
||||||
|
ns.disableLog('ALL');
|
||||||
|
let args;
|
||||||
|
const argParser = new ArgParser('connect.js', 'Connect to a device on a different network.', null, [
|
||||||
|
{name: 'device', desc: 'Device to connect to', default: ns.getHostname(), type: 'string'}
|
||||||
|
]);
|
||||||
|
try {
|
||||||
|
args = argParser.parse(ns.args);
|
||||||
|
} catch(err) {
|
||||||
|
if(err instanceof ArgError) return ns.tprint(argParser.help(err.message));
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find path to a device recursively
|
||||||
|
* @param device {string} - Device to locate
|
||||||
|
* @param current {string} - Current device to scan
|
||||||
|
* @param path {string[]} - Path the the current device
|
||||||
|
* @param all {Set} - Stop devices from being scanned
|
||||||
|
* @returns {string[]} - Path to the located device
|
||||||
|
*/
|
||||||
|
function find(device, current = 'home', path = [current], blacklist = new Set()) {
|
||||||
|
blacklist.add(current);
|
||||||
|
const newDevices = ns.scan(current).filter(d => !blacklist.has(d));
|
||||||
|
if(newDevices.length == 0) return [];
|
||||||
|
if(newDevices.find(d => d == device)) return [...path, device];
|
||||||
|
return newDevices.map(d => find(device, d, [...path, d], all)).find(p => p && p.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run
|
||||||
|
const path = find(args['device']);
|
||||||
|
path.splice(0, 1); // Delete 'home' from from the path
|
||||||
|
for(let d of path) {
|
||||||
|
terminal(`connect ${d}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function autocomplete(data) {
|
||||||
|
return [...data.servers];
|
||||||
|
}
|
@ -21,3 +21,18 @@ export async function slowPrint(ns, message, min = 0.5, max = 1.5) {
|
|||||||
ns.tprint(message);
|
ns.tprint(message);
|
||||||
await ns.sleep(time);
|
await ns.sleep(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a command to the terminal.
|
||||||
|
* @params command {string} - Command that will be run
|
||||||
|
* @returns {string} - Response
|
||||||
|
*/
|
||||||
|
export async function terminal(command) {
|
||||||
|
// Get Terminal
|
||||||
|
const cli = eval('document').querySelector("#terminal-input"); // Terminal
|
||||||
|
const key = Object.keys(cli)[1];
|
||||||
|
|
||||||
|
// Send command
|
||||||
|
cli[key].onChange({ target: {value: command} });
|
||||||
|
cli[key].onKeyDown({ keyCode: 13, preventDefault: () => {} });
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user