Updated crawler to support more flags

This commit is contained in:
Zakary Timson 2022-03-22 14:18:56 -04:00
parent de7eb3bc4f
commit a76ab24efb
3 changed files with 55 additions and 28 deletions

View File

@ -10,7 +10,7 @@ These scripts are for playing the [open source](https://github.com/danielyxie/bi
- [connect.js](#connectjs)
- [copy.js](#copyjs)
- [crawler.js](#crawlerjs)
- [find-target.js](#besttargetjs)
- [find-target.js](#findtargetjs)
- [hacknet-manager.js](#hacknet-managerjs)
- [miner.js](#minerjs)
- [network-graph.js](#network-graphjs)
@ -20,21 +20,25 @@ These scripts are for playing the [open source](https://github.com/danielyxie/bi
## Quick Start
```bash
# Download the update script in-game
# Download the update script in-game & run it
wget https://gitlab.zakscode.com/ztimson/BitBurner/-/raw/develop/scripts/update.js scripts/update.js
run scripts/update.js # Repeat to pull the latest
# Run the update script (Repeat this to pull this repository in the future)
run scripts/update.js
# View the network
run scripts/network-graph.js --verbose
run scripts/netowkr-graph.js --verbose --filter CSEC # Find path to a specific device
# Start the node manager with 8 nodes
# Start the node manager & cap it at 8 nodes
run scripts/node-manager.js 8
# Chain the crawler, rootkit & miner to hack everything on the network
alias hackAll="run scripts/crawler.js /scripts/rootkit.js {{TARGET}} /scripts/miner.js"
hackAll
# Chain the crawler & rootkit to root all devices on the network
run scripts/crawler.js --not-rooted --local /scripts/rootkit.js {{TARGET}}
# Identify & install a backdoor on CSEC
run scripts/network-graph.js -f CSEC
# Find the most profitable server & use the crawler to deploy miners on the network targeting it
run scripts/find-target.js # Output: n00dles
run scriipts/crawler.js --rooted /scripts/miner.js n00dles
# Install backdoor on CSEC
run scripts/rootkit.js CSEC
run scripts/connect.js CSEC
backdoor
@ -115,11 +119,14 @@ Usage: run crawler.js [OPTIONS] SCRIPT [ARGS]...
Options:
-c --cpu Number of CPU threads to use with script
-d --depth Depth to scan to, defaults to 3
-l --level Exclude targets with higher hack level, defaults to current hack level
-k --kill Kill all scripts running on device
--level Exclude targets with higher hack level, defaults to current hack level
-l --local Execute on current machine otherwise execute on remote device
-r --rooted Filter to devices that have been rooted
-n --not-rooted Filter to devices that have not been rooted
-p --ports Exclude targets with too many closed ports
-s --silent Suppress program output
-v --verbose Display the device names in the final report
-h --help Display this help message
```
@ -210,7 +217,7 @@ Usage: run network-graph.js [OPTIONS] [DEVICE]
DEVICE Point to start scan from, defaults to current machine
Options:
-d --depth Depth to scan to, defaults is 3
-d --depth Depth to scan to
-f --filter Filter to device matching name
-e --regex Filter to devices matching pattern
-r --rooted Filter to devices that have been rooted

View File

@ -1,5 +1,5 @@
import {ArgError, ArgParser} from '/scripts/lib/arg-parser';
import {scanNetwork} from '/scripts/lib/utils';
import {copyWithDependencies, scanNetwork} from '/scripts/lib/utils';
/**
* BitBurner autocomplete
@ -20,20 +20,24 @@ export async function main(ns) {
const argParser = new ArgParser('crawler.js', 'Search the network for targets to execute a script against.', null, [
{name: 'script', desc: 'Script to copy & execute', type: 'string'},
{name: 'args', desc: 'Arguments for script. Forward the current target with: {{TARGET}}', optional: true, extras: true, type: 'string'},
{name: 'cpu', desc: 'Number of CPU threads to use with script', flags: ['-c', '--cpu'], default: 1, type: 'num'},
{name: 'cpu', desc: 'Number of CPU threads to use with script', flags: ['-c', '--cpu'], type: 'num'},
{name: 'depth', desc: 'Depth to scan to, defaults to 3', flags: ['-d', '--depth'], default: Infinity, type: 'num'},
{name: 'level', desc: 'Exclude targets with higher hack level, defaults to current hack level', flags: ['-l', '--level'], default: ns.getHackingLevel(), type: 'num'},
{name: 'kill', desc: 'Kill all scripts running on device', flags: ['-k', '--kill'], type: 'bool'},
{name: 'level', desc: 'Exclude targets with higher hack level, defaults to current hack level', flags: ['--level'], default: ns.getHackingLevel(), type: 'num'},
{name: 'remoteExec', desc: 'Copy script to remote device & run there', flags: ['-e', '--remote-exec'], type: 'bool'},
{name: 'rooted', desc: 'Filter to devices that have been rooted', flags: ['-r', '--rooted'], type: 'bool'},
{name: 'notRooted', desc: 'Filter to devices that have not been rooted', flags: ['-n', '--not-rooted'], type: 'bool'},
{name: 'ports', desc: 'Exclude targets with too many closed ports', flags: ['-p', '--ports'], default: Infinity, type: 'num'},
{name: 'silent', desc: 'Suppress program output', flags: ['-s', '--silent'], type: 'bool'}
{name: 'silent', desc: 'Suppress program output', flags: ['-s', '--silent'], type: 'bool'},
{name: 'verbose', desc: 'Display the device names in the final report', flags: ['-v', '--verbose'], type: 'bool'},
], true);
try {
// Run
const localhost = ns.getHostname();
const args = argParser.parse(ns.args);
const [devices, network] = scanNetwork(ns);
let complete = 0, failed = 0, skipped = 0;
let complete = [], failed = [], skipped = [];
for(let device of devices) {
// Check root status if needed
const rooted = ns.hasRootAccess(device);
@ -42,31 +46,47 @@ export async function main(ns) {
// Skip invalid devices
if(device == 'home' || args['level'] < ns.getServerRequiredHackingLevel(device) || args['ports'] < ns.getServerNumPortsRequired(device)) {
skipped++;
skipped.push(device);
continue;
}
// Start script
if(args['kill']) ns.killall(device);
const scriptArgs = args['args'].map(arg => arg.toUpperCase() == '{{TARGET}}' ? device : arg);
const pid = ns.run(args['script'], args['cpu'], ...scriptArgs);
const [totalRam, usedRam] = ns.getServerRam(args['remoteExec'] ? device : localhost);
const threads = args['cpu'] || ~~((totalRam - usedRam) / ns.getScriptRam(args['script'], localhost)) || 1;
if(args['remoteExec']) await copyWithDependencies(ns, args['script'], device);
const pid = ns.exec(args['script'], args['remoteExec'] ? device : localhost, threads, ...scriptArgs);
if(pid == 0) {
failed++;
failed.push(device);
continue;
}
// Wait for script to finish
while(ns.scriptRunning(args['script'], 'home'))
await ns.sleep(1000);
complete++;
// Wait for script to finish if local
if(!args['remoteExec'])
while(ns.scriptRunning(args['script'], localhost)) await ns.sleep(1000);
complete.push(device);
}
// Output report
if(!args['silent']) {
ns.tprint('===================================================');
ns.tprint(`Crawler Report: ${complete + failed + skipped} Devices`);
ns.tprint(`Crawler Report: ${complete.length + failed.length + skipped.length} Devices`);
ns.tprint('===================================================');
ns.tprint(`Complete: ${complete}\tFailed: ${failed}\tSkipped: ${skipped}`);
ns.tprint('');
if(args['verbose']) {
ns.tprint(`Complete (${complete.length}):`);
if(complete.length) ns.tprint(complete.join(', '));
ns.tprint('');
ns.tprint(`Failed (${failed.length}):`);
if(failed.length) ns.tprint(failed.join(', '));
ns.tprint('');
ns.tprint(`Skipped (${skipped.length}):`);
if(skipped.length) ns.tprint(skipped.join(', '));
ns.tprint('');
} else {
ns.tprint(`Complete: ${complete.length}\tFailed: ${failed.length}\tSkipped: ${skipped.length}`);
ns.tprint('');
}
}
} catch(err) {
if(err instanceof ArgError) return ns.tprint(argParser.help(err.message));

View File

@ -36,7 +36,7 @@ export async function main(ns) {
ns.disableLog('ALL');
const argParser = new ArgParser('network-graph.js', 'Scan the network for devices and display as an ASCII tree:\n home\n ├─ n00dles (ROOTED)\n | └─ max-hardware (80|1)\n | └─ neo-net (50|1)\n ├─ foodnstuff (ROOTED)\n └─ sigma-cosmetics (ROOTED)', null, [
{name: 'device', desc: 'Point to start scan from, defaults to current machine', optional: true, default: ns.getHostname(), type: 'string'},
{name: 'depth', desc: 'Depth to scan to, defaults is 3', flags: ['-d', '--depth'], default: Infinity, type: 'num'},
{name: 'depth', desc: 'Depth to scan to', flags: ['-d', '--depth'], default: Infinity, type: 'num'},
{name: 'filter', desc: 'Filter to device matching name', flags: ['-f', '--filter'], type: 'string'},
{name: 'regex', desc: 'Filter to devices matching pattern', flags: ['-e', '--regex'], type: 'string'},
{name: 'rooted', desc: 'Filter to devices that have been rooted', flags: ['-r', '--rooted'], type: 'bool'},