46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { NS } from '@ns'
|
|
import { parse } from './lib/flag';
|
|
import { sprintf } from './lib/printf';
|
|
import { selectRootedServerList } from "./lib/servers"
|
|
|
|
|
|
async function propagateBackdoor(ns:NS, hostname: string): Promise<void>{
|
|
ns.singularity.connect(hostname);
|
|
const list = ns.scan(hostname);
|
|
for (const relname of list) {
|
|
const info = ns.getServer(relname);
|
|
if(info.backdoorInstalled){
|
|
continue;
|
|
}
|
|
if(info.requiredHackingSkill > ns.getHackingLevel()){
|
|
continue;
|
|
}
|
|
ns.tprint(`install backdoor ${relname}`);
|
|
ns.singularity.connect(relname);
|
|
await ns.singularity.installBackdoor();
|
|
ns.singularity.connect(hostname);
|
|
}
|
|
}
|
|
|
|
export async function main(ns: NS) : Promise<void> {
|
|
const flag = parse(ns.args.map(x=>x.toString()));
|
|
if(flag.h || flag.help){
|
|
const msg = ['run cmd']
|
|
msg.forEach(x=>ns.tprint(x));
|
|
return;
|
|
}
|
|
if(flag._.length === 0){
|
|
const servers = selectRootedServerList(ns);
|
|
for(const server of servers){
|
|
ns.tprint("prop backdoor to "+server.hostname);
|
|
await propagateBackdoor(ns,server.hostname);
|
|
}
|
|
}
|
|
else{
|
|
// const hostname = flag._[0];
|
|
// ns.tprint(sprintf("install backdoor %s",hostname));
|
|
// await ns.singularity.installBackdoor(hostname);
|
|
// ns.tprint("done");
|
|
}
|
|
}
|
|
|