Updated auto-pwn.js

This commit is contained in:
Zakary Timson 2022-02-10 18:55:16 +00:00
parent 355a9fe590
commit d80f33a513
3 changed files with 91 additions and 41 deletions

View File

@ -15,14 +15,31 @@ The repository can be loaded into the game by doing the following:
run scripts/node-manager.js 8 run scripts/node-manager.js 8
# Chain the crawler, auto-pwner & miner to hack everything within 3 hops # Chain the crawler, auto-pwner & miner to hack everything within 3 hops
run scripts/crawler.js 3 scripts/auto-pwn.js scripts/miner.js run scripts/crawler.js 3 /scripts/auto-pwn.js {{TARGET}} /scripts/miner.js
``` ```
## Scripts ## Scripts
### [auto-pwn.js](./scripts/auto-pwn.js) (WIP) ### [auto-pwn.js](./scripts/auto-pwn.js)
Automatically gains root on a target machine. After being pwned, the specified files will be coppied & ran. **RAM:** 4.75 GB
It's recomended you use this in combination with `miner.js` Automatically gain root on a target machine. Optionaly after being rooted, a file can be coppied & executed.
```
[home ~/]> run scripts/auto-pwn.js --help
Running script with 1 thread(s), pid 176 and args: ["--help"].
/scripts/auto-pwn.js:
Automatically gain root on a target machine. Optionaly after being rooted, a file can be coppied & executed.
Usage: run auto-pwn.js [TARGET] [SCRIPT] [ARGS]...
run auto-pwn.js --help
TARGET Target machine to root. Defaults to localhost
SCRIPT Script to copy & execute
ARGS Any aditional arguments to pass to SCRIPT. Passing '{{TARGET}}' will forward the current target
Options:
-h --help Display help message
```
### [bruteforce.js](./scripts/bruteforce.js) (WIP) ### [bruteforce.js](./scripts/bruteforce.js) (WIP)
Attacks target until security falls bellow threshold. Useful for throwing extra compute power & cracking a specific computer. Attacks target until security falls bellow threshold. Useful for throwing extra compute power & cracking a specific computer.
@ -69,6 +86,7 @@ Automatically download the latest versions of all scripts using wget.
[home ~/]> run scripts/update.js [home ~/]> run scripts/update.js
Running script with 1 thread(s), pid 142 and args: []. Running script with 1 thread(s), pid 142 and args: [].
/scripts/update.js: Downloading scripts: /scripts/update.js: Downloading scripts:
/scripts/update.js:
/scripts/update.js: lib/arg-parser.js [==================>] 100% (15 MB/s) /scripts/update.js: lib/arg-parser.js [==================>] 100% (15 MB/s)
/scripts/update.js: auto-pwn.js [==================>] 100% (22.3 MB/s) /scripts/update.js: auto-pwn.js [==================>] 100% (22.3 MB/s)
/scripts/update.js: bruteforce.js [==================>] 100% (22 MB/s) /scripts/update.js: bruteforce.js [==================>] 100% (22 MB/s)
@ -76,5 +94,6 @@ Running script with 1 thread(s), pid 142 and args: [].
/scripts/update.js: miner.js [==================>] 100% (10.8 MB/s) /scripts/update.js: miner.js [==================>] 100% (10.8 MB/s)
/scripts/update.js: node-manager.js [==================>] 100% (14.6 MB/s) /scripts/update.js: node-manager.js [==================>] 100% (14.6 MB/s)
/scripts/update.js: update.js [==================>] 100% (11.1 MB/s) /scripts/update.js: update.js [==================>] 100% (11.1 MB/s)
/scripts/update.js:
/scripts/update.js: ✅ Done! /scripts/update.js: ✅ Done!
``` ```

View File

@ -1,58 +1,86 @@
import {ArgParser} from './scripts/lib/arg-parser';
export async function main(ns) { export async function main(ns) {
ns.disableLog('ALL');
/** /**
* Prints text and waits a random amount of time to emulate * Prints text and waits a random amount of time to emulate work being complete.
* work being complete. * @param text {String} - message to Display
* @param min {Number} - minimum amount of time to wait in seconds. Defaults to 1 second.
* @param max {Number} - maximum amount of time to wait in seconds. Defaults to 1 second.
*/ */
async function printWithDelay(text, min=1, max=1) { async function printWithDelay(text, min=1, max=1) {
ns.tprint(text); ns.tprint(text);
await ns.sleep(~~(Math.random() * (max * 1000 - min * 1000)) + min * 1000); await ns.sleep(~~(Math.random() * (max * 1000 - min * 1000)) + min * 1000);
} }
function usage(message) { // Initilize script arguments
ns.tprint(`${!message ? '' : `${message}\n\n`}Usage:\nrun hack.js <target> <script1> [...scripts]\n\n\ttarget - Hostname or Address to attack\n\tscript1 - Path to script to run\n\tscripts - Additional scripts to run`); const argParser = new ArgParser({
} desc: 'Automatically gain root on a target machine. Optionaly after being rooted, a file can be coppied & executed.',
examples: [
'run auto-pwn.js [TARGET] [SCRIPT] [ARGS]...',
'run auto-pwn.js --help',
],
args: [
{key: 'TARGET', desc: 'Target machine to root. Defaults to localhost'},
{key: 'SCRIPT', desc: 'Script to copy & execute'},
{key: 'ARGS', desc: 'Any aditional arguments to pass to SCRIPT. Passing \'{{TARGET}}\' will forward the current target'},
{key: 'help', alias: 'h', optional: true, desc: 'Display help message'},
]
});
const args = argParser.parse(ns.args);
if(args['help']) return ns.tprint(argParser.help());
// Setup // Setup
ns.disableLog('ALL'); const target = args['TARGET'] && args['TARGET'] != 'localhost' ? args['TARGET'] : ns.getHostname();
if (ns.args[0] == null) return usage('Missing target address');
if (ns.args.length < 2) return usage('Provide scritp(s) for remote execution');
const TARGET = ns.args[0];
const SCRIPTS = ns.args.slice(1);
// Banner // Banner
ns.tprint('==================================================='); ns.tprint('===================================================');
ns.tprint(`🧑‍💻 Hacking: ${TARGET}`); ns.tprint(`🧑‍💻 Pwning: ${target}`);
await printWithDelay('==================================================='); await printWithDelay('===================================================');
// Gain root // Gain root
// await printWithDelay(`Attacking (SSH) ⚔️ ${TARGET}:22`, 3, 5); try {
// ns.brutessh(TARGET); ns.brutessh(target);
// await printWithDelay(`Attacking (FTP) ⚔️ ${TARGET}:24`, 3, 5); await printWithDelay(`Attacking (SSH) ⚔️ ${target}:22`, 3, 5);
// ns.ftpcrack(TARGET); ns.ftpcrack(target);
ns.nuke(TARGET); await printWithDelay(`Attacking (FTP) ⚔️ ${target}:24`, 3, 5);
await printWithDelay(`💀 Root Granted 💀`); } catch {
} finally {
// Copy scripts try {
ns.tprint(''); ns.nuke(target)
await printWithDelay('Copying scripts:'); await printWithDelay(`💀 Root Granted 💀`);
await Promise.all(SCRIPTS.map(async s => { } catch {
const SPEED = ~~(Math.random() * 100) / 10 await printWithDelay(`⚠️ Failed to Root ⚠️`);
await printWithDelay(`${s} \t [==================>] 100% \t (${SPEED} MB/s)`); }
await ns.scp(s, TARGET); }
}));
if(args['SCRIPT']) {
// Run scripts // Copy scripts
ns.tprint(''); ns.tprint('');
const THREADS = Math.floor(ns.getServerMaxRam(TARGET) / 2.3); await printWithDelay('Copying script:');
await Promise.all(SCRIPTS.map(async s => { const speed = ~~(Math.random() * 100) / 10
ns.scriptKill(s, TARGET); await ns.scp(args['SCRIPT'], target);
await printWithDelay(`ssh -c "run ${s} -t ${THREADS}" root@${TARGET}`); await printWithDelay(`${args['SCRIPT']} \t [==================>] 100% \t (${speed} MB/s)`);
const PID = ns.exec(s, TARGET, THREADS, TARGET);
if(!PID) ns.tprint('⚠️ Failed to start ⚠️'); // Run scripts
})); ns.tprint('');
ns.tprint('✅ Complete!'); ns.tprint('Executing:');
const threads = Math.floor(ns.getServerMaxRam(target) / 2.3);
ns.scriptKill(args['SCRIPT'], target);
await printWithDelay(`ssh -c "run ${args['SCRIPT']} ${args['extra'].join(' ')} -t ${threads}" root@${target}`);
const pid = ns.exec(args['SCRIPT'], target, threads, ...args['extra'].map(a => a == '{{TARGET}}' ? target : a));
if(!pid) return ns.tprint('⚠️ Failed to start ⚠️');
ns.tprint('');
ns.tprint('✅ Complete!');
ns.tprint('');
}
} }
/**
* Autocomplete script arguments
* @param data - provided by API
*/
export function autocomplete(data) { export function autocomplete(data) {
return [...data.servers, ...data.scripts]; return [...data.servers, ...data.scripts];
} }

View File

@ -17,11 +17,14 @@ export async function main(ns) {
// Download each file // Download each file
ns.tprint("Downloading scripts:"); ns.tprint("Downloading scripts:");
ns.tprint('');
for(const file of fileList) { for(const file of fileList) {
await ns.sleep(500); await ns.sleep(500);
await ns.wget(`${src}${file}`, `${dist}${file}`); await ns.wget(`${src}${file}`, `${dist}${file}`);
const speed = ~~((Math.random() * 200) + 100) / 10; const speed = ~~((Math.random() * 200) + 100) / 10;
ns.tprint(`${file} ${file.length <= 10 ? '\t' : ''}\t [==================>] 100% \t (${speed} MB/s)`); ns.tprint(`${file} ${file.length <= 10 ? '\t' : ''}\t [==================>] 100% \t (${speed} MB/s)`);
} }
ns.tprint('');
ns.tprint('✅ Done!'); ns.tprint('✅ Done!');
ns.tprint('');
} }