Bitburner

Bitburner

Not enough ratings
Kupos easy Backdoor Worm
By Kupo
In this guide, I present my very simple and small programme that automatically backdoors ALL systems automatically you can currently hack. It also supports only backdooring one system you give the script via argument.
If you don't know what BN4 is or don't have it yet, this guide is unfortunately not for you.
   
Award
Favorite
Favorited
Unfavorite
Prerequisite: BN4
Spoilers ahead for those who never heard of BitNode.

You need to be in or have finished BN4 getting the source file, at least level 1.

Otherwise you can sadly not use a script to install a backdoor.
RAM Usage
The script uses Singularity functions. Their RAM cost depends on your BN4 SF Level.
If you finished BN4 once, you have BN4.1.

SF Level
Singularity RAM
base RAM
optional RAM
total RAM
BN4.1
64GB
2GB
2GB
66-68GB
BN4.2
16GB
2GB
2GB
18-20GB
BN4.3
4GB
2GB
2GB
6-8GB

You can reduce normal functions RAM by 2GB if you do not check if a backdoor is already installed. This way you don't need getServer.

The Backdoor Worm Script
nano worm.js
/** @param {NS} ns **/ export async function main(ns) { await wormFunc(ns, "home", ""); } async function wormFunc(ns, serv, oldserv) { const SERVERS_TO_SCAN = ns.scan(serv); ns.connect(serv); for (let CURR_SERV of SERVERS_TO_SCAN) { if (CURR_SERV == oldserv) continue; await wormFunc(ns, CURR_SERV, serv); ns.connect(serv); } if ((!ns.args[0] || serv == ns.args[0]) && !ns.getServer(serv).backdoorInstalled && ns.hasRootAccess(serv) && ns.getServerRequiredHackingLevel(serv) <= ns.getHackingLevel()) await ns.installBackdoor(); }
how does it work
Let's go through the code again:

The main script does nothing except using our recursive function wormFunc, giving it "home" as the system to start with.
/** @param {NS} ns **/ export async function main(ns) { await wormFunc(ns, "home", ""); }

// We build the function, giving ns, the server to scan, and also what server we came from if any async function wormFunc(ns, serv, oldserv) { // We first save all neighboors which should be scanned const SERVERS_TO_SCAN = ns.scan(serv); // We then connect our terminal to the server we are currently on ns.connect(serv); // Now we will go through each neighboor we have for (let CURR_SERV of SERVERS_TO_SCAN) { // Make sure we DO NOT do anything with the server we just came from. // or else we are doomed because of endless recursive loops if (CURR_SERV == oldserv) continue; // Now we go on the neighboor and start all over again await wormFunc(ns, CURR_SERV, serv); // also note the await, we actively wait until everything in there has finished //Then we connect again on our server, as we are probably on the last neighboor ns.connect(serv); } // Here we are done with all existing neighboors, or we simply have no neighboors (last server in the tree) // Finally we check if there is no backdoor and we can install one based on hacking level // you can remove the backdoorInstalled check if you like if (!ns.getServer(serv).backdoorInstalled && (!ns.args[0] || serv == ns.args[0]) // <-- this will backdoor all servers, or only the server given && ns.hasRootAccess(serv) && ns.getServerRequiredHackingLevel(serv) <= ns.getHackingLevel()) // We install the backdoor and wait for it to finish. await ns.installBackdoor(); } // the function will end, and the previous server will continue, until all servers are done.
result example

2 Comments
Kupo  [author] 16 Jul, 2022 @ 1:42am 
@SuperSamwise Thank you for pointing that out! I changed the for loop and forgot to change it in the commented part too. Fixed it.
SuperSamwise 16 Jul, 2022 @ 12:31am 
need to remove this line:
// lets save the current server as a variable for easy access
const CURR_SERV = SERVERS_TO_SCAN[j];