Rootkit will skip rooting if it already has it to save time

This commit is contained in:
Zakary Timson 2022-03-20 09:01:52 -04:00
parent 86158da1b2
commit 65050fb619
2 changed files with 27 additions and 32 deletions

View File

@ -218,7 +218,7 @@ Options:
```
### [rootkit.js](./scripts/rootkit.js)
**RAM:** 4.75 GB - 4.90 GB <small>(depending on un-commented programs)</small>
**RAM:** 4.80 GB - 4.95 GB <small>(depending on un-commented programs)</small>
Automatically gain root on a target machine. A file can also be uploaded & executed.

View File

@ -36,36 +36,29 @@ export async function main(ns) {
ns.tprint('===================================================');
}
// Check if we already have root
if(ns.hasRootAccess(args['device'])) {
if(!args['silent']) ns.tprint('Root: Skipped');
} else {
let spacer = false;
const sleep = 750;
try {
// Run exploits
ns.brutessh(args['device']);
if(!args['silent']) {
await slowPrint(ns, `Attacking over SSH (${args['device']}:22)...`, 0.5, 1.5);
await ns.sleep(sleep);
spacer = true;
}
ns.ftpcrack(args['device']);
if(!args['silent']) {
await slowPrint(ns, `Attacking over FTP (${args['device']}:24)...`, 0.5, 1.5);
await ns.sleep(sleep);
}
if(!args['silent']) await slowPrint(ns, `Attacking over FTP (${args['device']}:24)...`, 0.5, 1.5);
ns.relaysmtp(args['device']);
if(!args['silent']) {
await slowPrint(ns, `Attacking over SMTP (${args['device']}:25)...`, 0.5, 1.5);
await ns.sleep(sleep);
}
if(!args['silent']) await slowPrint(ns, `Attacking over SMTP (${args['device']}:25)...`, 0.5, 1.5);
} catch {
} finally {
try {
// Attempt root
if(spacer) ns.tprint('');
ns.nuke(args['device'])
if(!args['silent']) {
ns.tprint(`Root: Success!`);
ns.tprint('');
}
ns.nuke(args['device']);
if(!args['silent']) ns.tprint(`Root: Success!`);
} catch {
if(!args['silent']) {
ns.tprint(`Root: Failed`);
@ -74,6 +67,8 @@ export async function main(ns) {
ns.exit();
}
}
}
ns.tprint('');
if(args['script']) {
// Detect script dependencies & copy everything to target