Bitburner

Bitburner

215 ratings
Bitburner Hacking for Dummies
By Zac Starfire
A short & comprehensive guide including simple working scripts for beginning hacking in the Bitburner game.
3
5
9
2
2
2
2
2
   
Award
Favorite
Favorited
Unfavorite
The Beginning
     It all really boils down to 3 main tasks that I have provided some beginner code (or templates) for. Please go ahead and modify or extend them as you see fit. I learned long ago from my first programming teacher (back in the 1980s) that it is not the amount of code you write that makes you a a great programmer, but the amount of code you can steal. In other words, don’t reinvent the wheel, just make it better.

     For help with scripting or Netscript in general, go here and then return to this guide for more details on hacking: https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2717682356
1) Scope the Servers
    a) What’s out there?
  •      You have access to the command ‘scan’ which will tell you what is nearby within 1 ‘hop’ from where you're currently logged into. (ie ‘home’). These are your first targets, especially 'n00ldes', that's the newbie server you can experiment with and use with your first attacks.

  •      Next, you will have access to the ‘scan-analyze’ command which will map out the network for 5 hops from where you ran the command. Later you can upgrade this to 10 hops. This is useful for finding networks with deeper networks to explore. You can start a list of servers found and their hacking level and max money, these will be your next targets as you gain hacking xp.

  •      Diagram the network - You can use a free designer to visually map out your network if you like: https://docs.google.com/drawings

         That will help you visualize the network in your head and that’s actually what real world professionals do with larger networks with more expensive software:
    https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2860835090
    Note:     Everyone’s server locations and network complexity is different, it is randomized when you start the game.
    b) Can I hack it?
  •      You need Hacking XP to hack more secure servers, so keep track of hacking levels required of servers you find, then you can jump on them when you have enough xp. Also, either due to bugs or design, you will find servers that have no RAM. In those cases, you won’t be able to run programs on the server even if you backdoor it, so you have to attack it from home or another server.
    c) What do I get from hacking it?
  •      You need to know how much money a server can have in total and how much it has on it currently. Keep track of this so you know which servers are the most fruitful to hack once you’ve created a server farm to do mass hacking with.

  •      Even if you fail to hack it, you still gain xp from weakening its security, growing money on it and all hack attempts. Even if a server has no money and never will due to bug or design, you still can get xp from it by just having it hack itself constantly (or from another server if it has no RAM).

     Here is a simple script you can use and run it from home to get all this information from a server, just pass the server name as an argument you need info on. You can use the alias command to simply run the script, then pass the target server to the script:

alias serverinfo="run serverinfo.js"
serverinfo n00dles


/** @param {NS} ns */ export async function main(ns) { let target = ns.args[0]; let server = ns.getServer(target); let ramAvailable = server.maxRam - server.ramUsed; let ramPerThread = ns.getScriptRam('/scripts/hack.js'); let maxThreads = Math.floor(ramAvailable / ramPerThread); ns.tprint("------------------------------------"); ns.tprint("Server Infomation"); ns.tprint("------------------------------------"); ns.tprint("Host Name: " + server.hostname); ns.tprint("IP: " + server.ip); ns.tprint("Owned By: " + server.organizationName); ns.tprint(""); ns.tprint("------------------------------------"); ns.tprint("Security Infomation"); ns.tprint("------------------------------------"); ns.tprint("Required Hacking Level: " + server.requiredHackingSkill); ns.tprint("Min Security level: " + server.minDifficulty); ns.tprint("Current security: " + ns.nFormat(server.hackDifficulty, "0.00")); ns.tprint(""); ns.tprint("------------------------------------"); ns.tprint("Money Infomation"); ns.tprint("------------------------------------"); ns.tprint("Max Money: " + ns.nFormat(server.moneyMax, "$0.000a")); ns.tprint("Current Money: " + ns.nFormat(server.moneyAvailable, "$0.000a")); ns.tprint("Server Growth: " + server.serverGrowth); ns.tprint(""); ns.tprint("------------------------------------"); ns.tprint("Hardware Infomation"); ns.tprint("------------------------------------"); ns.tprint("Cores: " + server.cpuCores); ns.tprint("Max RAM: " + server.maxRam); ns.tprint("Used RAM: " + server.ramUsed); ns.tprint("Max Threads: " + maxThreads); ns.tprint(""); ns.tprint("------------------------------------"); ns.tprint("Hacking Infomation"); ns.tprint("------------------------------------"); ns.tprint("Rooted: " + server.hasAdminRights); ns.tprint("Backdoored: " + server.backdoorInstalled); ns.tprint("Required Open Ports: " + server.numOpenPortsRequired); ns.tprint("Ports Currently Open: " + server.openPortCount); ns.tprint("------------------------------------"); }


     The following script will crawl the network, find servers with the min/max Hack Level set in the header and sort them by their respective Hacking Level. I'm not sure where I originally found this code, but I've highly modified it for my own purposes. Notice how infiniteLoopProtection code works.

For Example:
/** @param {NS} ns */ export async function main(ns) { let infiniteLoopProtection = 9999; // In case you mess with this code, this should save you from getting stuck let minHackingLevel = 750; let maxHackingLevel = 850; let serversToScan = ["home"]; // Servers we know about, but have no yet scanned let discoveredServers = []; // Servers we have scanned let hackableServers = []; // Servers we can hack while (serversToScan.length > 0 && infiniteLoopProtection-- > 0) { // Loop until the list of servers to scan is empty let serverName = serversToScan.pop(); // Get the next server to be scanned let serverHackingLevel = ns.getServerRequiredHackingLevel(serverName); // Scan all servers that are connected current server) for (let connectedServer of ns.scan(serverName)) { // If we haven't already scanned this servers, add it to the queue of servers to be scanned if (!discoveredServers.includes(connectedServer)) serversToScan.push(connectedServer); // } // Mark this server as scanned discoveredServers.push(serverName); if (serverHackingLevel > minHackingLevel && serverHackingLevel < maxHackingLevel) { let hackableServer = {}; hackableServer.serverName = serverName; hackableServer.serverHackingLevel = serverHackingLevel; hackableServers.push(hackableServer); } } // Sort Hackable Servers by Hacking Level hackableServers.sort((a, b) => a.serverHackingLevel - b.serverHackingLevel); // Output Display for (let server of hackableServers) { ns.tprint("------------------------------------"); ns.tprint("Server: " + server.serverName); ns.tprint("Hacking Level: " + server.serverHackingLevel); } ns.tprint("------------------------------------"); }

alias findservers="run /scripts/findservers.js"
findservers

2) Crack the Server
          Or basically ‘bust it open with a crowbar’. You need to run programs to open ports, gain root access and backdoor the server. These are entirely fictional programs - you never know exactly how they work and are just for the Bitburner world, but it is very similar to real life where you write programs that manipulate data on ‘sockets’ on the thousands of ‘ports’ a computer can actually have based with known exploits in security, hardware and software which is acquired through research, hacker communities, experimentation or even purchased from the real darkweb itself.

The TOR Router in Bitburner is only 200k and you will find all the programs (except Nuke.exe) you need to crack a server on the nearby server when you run 'scan', named 'darkweb'.

Network Information Programs
ServerProfiler.exe - Displays detailed information about a server. (cost: 1m or Hacking Level:
75)
DeepscanV1.exe -Enables 'scan-analyze' with a depth up to 5. (cost: 500k or Hacking Level: 75)
DeepscanV2.exe - Enables 'scan-analyze' with a depth up to 10. (cost: 25m or Hacking Level: 400)
AutoLink.exe - Enables direct connect via 'scan-analyze'. (cost: 1m or Hacking Level: 25)
Formulas.exe - Unlock access to the formulas API. (cost: 5b)

Hacking Programs
NUKE.exe - Grants Root Access. (cost: free, you write at Hacking Level: 1)
BruteSSH.exe - Opens up SSH Ports. (cost: 500k or Hacking Level: 50,)
FTPCrack.exe - Opens up FTP Ports. (cost: 1.5m or Hacking Level: 100)
relaySMTP.exe - Opens up SMTP Ports. (cost: 5m or Hacking Level: 250)
HTTPWorm.exe -Opens up HTTP Ports. (cost: 30m or Hacking Level: 500)
SQLInject.exe - Opens up SQL Ports. (cost: 250m or Hacking Level: 750)

          In Bitburner, you only need to worry about up to 5 ports to crack open a server depending on its difficulty and everything else is just basically given to you in time or purchased from the darkweb as you progress in the game. For me, I only wrote the first few programs myself, then was making enough money to buy my programs off the darkweb before I even had the xp required to write the rest of them myself.

Root Access - Simply means you're the 'super user' on the machine and can run/kill anything on the server without any user restrictions.
Backdooring - Really just allows you to connect to it directly without going through another server and gives you the final satisfaction that you now ‘own’ that server and it is now your ‘b*tch’.

For more information on TOR routing and the Anonymous Internet (deep/dark web) in the real world, go here:
https://tails.boum.org/doc/anonymous_internet/index.en.html
But don't ask me any questions on that topic - remember, I'm retired :p
That link will at least give you an idea how TOR works and the darkweb along with the software used.

          I’ve provided a basic script to accomplish this using the programs you currently actually own. It simply runs the programs you own to open ports and then runs ‘nuke’ on the server to grant root access to the server.

Just pass the target server name as an argument to the script:
alias crack="run crack.js"
crack n00dles


/** @param {NS} ns */ export async function main(ns) { let target = ns.args[0]; if (ns.fileExists("BruteSSH.exe", "home")) { ns.brutessh(target); } if (ns.fileExists("FTPCrack.exe", "home")) { ns.ftpcrack(target); } if (ns.fileExists("relaySMTP.exe", "home")) { ns.relaysmtp(target); } if (ns.fileExists("HTTPWorm.exe", "home")) { ns.httpworm(target); } if (ns.fileExists("SQLInject.exe", "home")) { ns.sqlinject(target); } ns.nuke(target); ns.tprint("Nuke complete on " + target + "."); }

*** IMPORTANT *** - Note you cannot backdoor a server automatically until much later, so the final task you have to do yourself. Simply connect to the server after you ‘crack’ it open and run the ‘backdoor’ command manually and wait for it to complete.

You need Source File 4 to be able to execute the ns.connect() function from a nearby server so you can connect to the target server and use the ns.installBackdoor() function.
3) Hack the Server
     The actual hacking of a server is broken down to the three main sub-tasks (weaken/grow/hack) which are performed according to these very basic formulas from the examples in the basic documentation:

If currentSecurityLevel > securityLevelMin + 5 then weaken();
If serverMoneyAvailable < (serverMaxMoney * 0.75) then grow();
If within 5 of min security level and 75% of max money, then hack();


You can read more about it here:
https://bitburner.readthedocs.io/en/latest/guidesandtips/gettingstartedguideforbeginnerprogrammers.html

Weaken the Security on the Server - The server will constantly try to increase its security level to lower the effectiveness of growing and hacking. You want to be within 5 of the minimum before performing any other task or they won't be as effective. This is performed with the weaken() command:

securityLevelMin = ns.getServerMinSecurityLevel(target); // Get the Min Security Level currentSecurityLevel = ns.getServerSecurityLevel(target); // Get the Current Sevurity Level while (currentSecurityLevel > securityLevelMin + 5) { // Our security formula await ns.weaken(target); // The weaken() command currentSecurityLevel = ns.getServerSecurityLevel(target); // Update our current security } // to breakout of the while loop

Grow Money on the Server - You will get the most money from a server when it is within 75% of its maximum amount. This is performed with the grow() command:

serverMoneyAvailable = ns.getServerMoneyAvailable(target); // Get money on server serverMaxMoney = ns.getServerMaxMoney(target); // Get max money for server while (serverMoneyAvailable < (serverMaxMoney * 0.75)) { // Our grow formula await ns.grow(target); // The grow() command serverMoneyAvailable = ns.getServerMoneyAvailable(target); // Update our variables serverMaxMoney = ns.getServerMaxMoney(target); // This one too just in case } // to breakout of the while loop

Finally, Hack the Server - Once the first 2 above criteria have been met, the server is now prime for the hack attempt. This is performed with the hack() command. Even if you fail, you gain XP from the attempt, so keep doing this, even on servers you don’t make much money off of.

await ns.hack(target); // The hack () command serverMoneyAvailable = ns.getServerMoneyAvailable(target) // Update our variables serverMaxMoney = ns.getServerMaxMoney(target); // This one too just in case

    Now, it loops back around to the while (true) statement and starts over, cracking the security, then growing money, check the security, check the money, finally the hack and then repeat over and over until you kill the script.

   I may have updated the variables often, but it leaves a debug trail in the log window if you check it under 'Active Scripts'. Any function you execute goes in the log with the results. This actually saves you from making a lot spam in your terminal and why you should output to the log and use ns.tail() to automatically open a tail window with all the debug for the script. This is a bit more advanced and I demonstrate it more in my next guide for the Stock Market's script which uses a nice, static tail() window for output of the script.

    Of course, you can vastly improve efficiency of hack.js with the Formulas API, but we're starting now with the bare-bones basics, taking baby steps before we start jumping....

     I’ve provided a basic script to perform the three sub-tasks according to the provided formulas from the basic documentation. There is much debug messages I left that you can comment out and see exactly what is happening and when but its very verbose and spammy.

Once again, just pass the target server to the script after you create the alias.
alias hack="run hack.js"
hack n00dles


Now the full script:
/** @param {NS} ns */ export async function main(ns) { let target = ns.args[0]; let securityLevelMin; let currentSecurityLevel; let serverMaxMoney; let serverMoneyAvailable; while (true) { securityLevelMin = ns.getServerMinSecurityLevel(target); // Get the Min Security Level currentSecurityLevel = ns.getServerSecurityLevel(target); // Get max money for server //ns.tprint("---------------------------------------------------------------"); //ns.tprint("Starting attack on " + target + " with " + ns.getHostname() + "..."); while (currentSecurityLevel > securityLevelMin + 5) { //ns.tprint("---------------------------------------------------------------"); //ns.tprint(target + " min security level is " + securityLevelMin); //ns.tprint("Current security level on " + target + " is " + ns.nFormat(currentSecurityLevel, "0.00") + "."); //ns.tprint("Weakening " + target + " with " + ns.getHostname() + "..."); await ns.weaken(target); currentSecurityLevel = ns.getServerSecurityLevel(target) } //ns.tprint("---------------------------------------------------------------"); serverMoneyAvailable = ns.getServerMoneyAvailable(target); serverMaxMoney = ns.getServerMaxMoney(target); //ns.tprint("Minimum security level on " + target + " reached !!!"); while (serverMoneyAvailable < (serverMaxMoney * 0.75)) { //ns.tprint("---------------------------------------------------------------"); //ns.tprint(target + " Current Money: " + ns.nFormat(serverMoneyAvailable, "$0.000a")); //ns.tprint(target + " Max Money: " + ns.nFormat(serverMaxMoney, "$0.000a")); //ns.tprint("Growing " + target + " with " + ns.getHostname() + " to " + ns.nFormat(serverMaxMoney * 0.75, "$0.000a") + "..."); await ns.grow(target); serverMoneyAvailable = ns.getServerMoneyAvailable(target); serverMaxMoney = ns.getServerMaxMoney(target); } //ns.tprint("---------------------------------------------------------------"); //ns.tprint("Optimal current money on " + target + " reached !!!"); //ns.tprint(target + " Current Money: " + ns.nFormat(serverMoneyAvailable, "$0.000a")); //ns.tprint(target + " Max Money: " + ns.nFormat(serverMaxMoney, "$0.000a")); //ns.tprint("---------------------------------------------------------------"); //ns.tprint("Hacking " + target + " with " + ns.getHostname() + "..."); await ns.hack(target); serverMoneyAvailable = ns.getServerMoneyAvailable(target) serverMaxMoney = ns.getServerMaxMoney(target); } }
What's Next ?
Here are a few things you'll want to work on next to progress in the game.

Remember, these are just templates that work on my own game. You may have to modify them slightly for your own scenarios and environment.
1) Create a Deploy Script
          To copy scripts to servers under your control using arrays and the scp function. Get your code out on the servers you control so you can run them from the server and get updated code out to these servers as needed.

For Example:
export async function main(ns) { let deployServers = []; let serverFarm = []; let serverName; let hostNamePrefix = "SERVER-"; // Prefix farm server with this name let numOfServers = 20; // Server total in farm const knownServers = ['n00dles', 'foodnstuff', 'joesguns', 'harakiri-sushi', 'hong-fang-tea', 'iron-gym', 'neo-net', 'zer0', 'phantasy', 'max-hardware', 'omega-net', 'netlink', 'crush-fitness', 'silver-helix', 'the-hub', 'rothman-uni', 'syscore', 'johnson-ortho', 'sigma-cosmetics', 'computek', 'I.I.I.I', 'aevum-police', 'summit-uni', 'rho-construction', '.', 'alpha-ent', 'syscore', 'zb-institute', 'lexo-corp', 'catalyst', 'millenium-fitness']; const helperServers = ['Darkstar', 'Starlight', 'Starbright', 'Battlestar', 'Blackhole']; //let dedicatedServers = ['johnson-ortho-HACK', 'crush-fitness-HACK', 'foodnstuff-HACK', 'sigma-cosmetics-HACK', // 'joesguns-HACK']; const scripts = ['/scripts/crack.js', '/scripts/hack.js', '/scripts/grow.js', '/scripts/supergrow.js', '/scripts/crack.js', '/scripts/deployscripts.js', '/scripts/hacknow.js', '/scripts/crackall.js', '/scripts/share.js']; for (let index = 1; index <= numOfServers; index++) { serverName = hostNamePrefix + index.toString(); serverFarm.push(serverName); } deployServers = deployServers.concat(knownServers, helperServers, serverFarm); ns.tprint(deployServers[1]); for (let server of deployServers) { await ns.scp(scripts, server); ns.tprint("Scripts deployed to " + server); }; }

1) What I'm doing here is first defining the servers I've cracked in the knownServers array.

2) Then, I define my 5 named helper servers in the helperServers array.

3) Next, the 20 servers I have in my server farm. They all have names with the prefix "SERVER-" followed by a respective number 1-20. This makes it work with the servers by using a loop that goes around through the 20 servers I own as part of the 'farm'.

4) Next, I have dedicated servers defined. These were servers I have bought before I could afford 20 and were for 4 servers I had found that had no RAM, so I had a dedicated server for each to hack. Later when I found more fruitful servers to hack, I just upgraded them as part of the server farm and committed them out since they no longer exist.

5) Finally, I've defined the scripts in the scripts array. You only need the scripts you need to run on host servers and remote servers. Note that you can pass an array of files to scp, which is nice and saves you some additional programming.

Now, I combine all the server arrays into a larger array, deployServers. These are all the servers I need to deploy scripts to.


2) Create an Automation Script
          To start scripts on servers automatically based on available memory that you have deployed so you can control and help manage them as a group or even alone. Servers you control can either hack itself, hack another server, or even pitch in with sharing faction work depending on the scripts you deploy to it and run on it.

For example:
/** @param {NS} ns */ export async function main(ns) { // Globals const servers = ['n00dles', 'foodnstuff', 'joesguns', 'harakiri-sushi', 'hong-fang-tea', 'iron-gym', 'neo-net', 'zer0', 'phantasy', 'max-hardware', 'omega-net', 'silver-helix', 'the-hub', 'rothman-uni', 'sigma-cosmetics', 'aevum-police', 'summit-uni', 'rho-construction', '.', 'alpha-ent', 'zb-institute', 'lexo-corp', 'catalyst', 'millenium-fitness']; const targets = ['rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'rho-construction', 'aevum-police', 'summit-uni', 'rho-construction', 'alpha-ent', 'alpha-ent', 'zb-institute', 'lexo-corp', 'catalyst', 'millenium-fitness']; const script = '/scripts/hack.js'; //const script = '/scripts/share.js'; // Variables let totalRAMavailable = 0; let serverRAM = 0; // Calculate total RAM available on all servers for (let index = 0; index < servers.length; index++) { ns.killall(servers[index]); serverRAM = ns.getServerMaxRam(servers[index]); totalRAMavailable += serverRAM; //ns.tprint("Server RAM available = " + serverRAM); } for (let index = 0; index < servers.length; index++) { let ramAvailable = ns.getServerMaxRam(servers[index]) - ns.getServerUsedRam(servers[index]); let ramPerThread = ns.getScriptRam(script); let threads = Math.floor(ramAvailable / ramPerThread); ns.tprint(threads + " threads can be runned on " + servers[index] + "."); if (threads > 0) { ns.tprint("Starting " + script + " on " + targets[index] + " with " + servers[index] + "."); ns.exec(script, servers[index], threads, targets[index]); } else { ns.tprint("NOT ENOUGH MEMORY ON " + servers[index] + "."); } }; ns.tprint("Total RAM available = " + totalRAMavailable); }

          What I'm doing here, is first defining my host servers that I am going to run the hack.js script on using all available RAM in the host server and maximum threads. Next I define their targets It may be the different target server for all the host servers, or specific target server. Then, I define the scripts that I want to run on the host server against the target server. I use this script also to share my severs to gain more faction reputation for the faction I currently am working for reputation. I just comment the 'hack.js' line and comment in the 'share.js' script. The 'share.js', I provide in my 3rd guide, 'Bitburner Contracts for Dummies', since it deals with factions.

          I recommend much later creating separate weaken/grow/hack scripts to be automated by a larger master script(s). You could also then use port functions to pass data between scripts for like coordinating attacks while manipulating the stock market through automated purchases - Just some ideas for even later. You also want to figure out how more efficiently you can do your attacks with the Functions API (see below).
3) Create a Server Farm Script
          Purchase servers with custom RAM requirements to perform mass hacking or sharing tasks. You get 25 of them initially, so build this out as soon as you can afford it and upgrade the RAM as you make more money and have more difficult servers to hack. You can then enslave these servers to help with hacking tasks or focus on a single task even like sharing resources to a faction to boost faction gained.

          Note, you have to kill processes on servers before you can delete them and you have to delete them before you can buy new ones with the same name, but more RAM. I read you get some money back when you delete servers, but I'm not for sure and it's probably not very significant amount because I didn't notice much cash gained when I've deleted my servers, but at this point, you should have tons of cash to afford it and don't really care.

          I personally like to have a group of helper servers with unique names and then a larger farm of servers with the same name prefixed and a index number. This makes it easier for automation scripts because you don't need an array for the servers, just a loop to go through each one with an index. Just a little less coding but I do recommend using arrays of objects or multi-dimensional arrays for more complex scripting, I'm just trying to keep things simple for now.

          For servers you discover without RAM, you can create a dedicated server to constantly hack it using your own RAM you purchased with the dedicated server for some extra XP and cash.

For Example:

/** @param {NS} ns */ export async function main(ns) { // Globals const memory = 262144; // Memory to purchase on the servers const numOfServers = 5; // For use with the purchase calculation dry run or purchasing Server Farms const hostNamePrefix = "SERVER-"; // When creating a server farm, prefix servers with this name const buy = false; // Check prices or simulate the purchase before you actually buy // Variables let serverName; let serversCost = ns.getPurchasedServerCost(memory) * numOfServers; // Comment out * numOfServers if needed let totalCost = serversCost * numOfServers; // Quick total purchase cost dry calculation ns.tprint("Total Cost is " + ns.nFormat(totalCost, "$0.000a" + ".")); // Main Script // Toggle buy flag in Globals to enable actual purchase if (buy) { // You have to kill all scripts on servers before you can delete or buy new ones ns.killall("Darkstar"); ns.killall("Starlight"); ns.killall("Starbright"); ns.killall("Battlestar"); ns.killall("Blackhole"); // Remove existing servers ns.deleteServer("Darkstar"); ns.deleteServer("Starlight"); ns.deleteServer("Starbright"); ns.deleteServer("Battlestar"); ns.deleteServer("Blackhole"); // Buy new servers with required memory ns.purchaseServer("Darkstar", memory); ns.purchaseServer("Starlight", memory); ns.purchaseServer("Starbright", memory); ns.purchaseServer("Battlestar", memory); ns.purchaseServer("Blackhole", memory); // For buying a Server Farm uncomment this below and set the proper number of servers to purchase in the header. // This will buy a group of servers with a common name and number, which makes it easier to manage and automate. // //for (var index = 1; index <= numOfServers; index++) { // serverName = hostNamePrefix + index.toString(); // ns.tprint("Buying " + serverName); // ns.killall(serverName); // ns.deleteServer(serverName); // ns.purchaseServer(serverName, memory); //} } }

Edit everything in the header you need and don't forget to set 'buy' to 'true' after you know the cost and ready to actually buy.
4) Create a Startup Script
         Sometimes when you're working on writing or debugging a script and it crashes Bitburner due to an infinite loop error or say you had to reboot your computer for some reason and have to start Bitburner again as well as all the scripts you had running. If you're like me, you’ve got a bunch of tail windows open to monitor things while working on a script and to get everything going again takes a lot of starting up individual scripts. So, I created a startup script for that purpose:

For example:
/** @param {NS} ns */ export async function main(ns) { //ns.tprint("Killing scripts..."); //ns.exec('/scripts/killallscripts.js', 'home', 1); //ns.tprint(""); ns.tprint("------------------------------------"); ns.tprint("Deploying Scripts..."); ns.tprint("------------------------------------"); ns.exec('/scripts/deployscripts.js', 'home', 1); // Wait for deployment to finish await ns.sleep(1000); ns.tprint("------------------------------------"); ns.tprint("Starting Hacking with Slaved Servers..."); ns.exec('/scripts/autohack.js', 'home', 1); // Wait for slaved servers to start await ns.sleep(1000); ns.tprint("------------------------------------"); ns.tprint("Starting Hacking with Helper Servers..."); ns.tprint("------------------------------------"); ns.exec('/scripts/autohackhelp.js', 'home', 1); // Wait for helper servers to start await ns.sleep(1000); ns.tprint("------------------------------------"); ns.tprint("Starting Server Farm..."); ns.tprint("------------------------------------"); ns.exec('/scripts/startserverfarm.js', 'home', 1); // Wait for server farm to start await ns.sleep(1000); ns.tprint("------------------------------------"); ns.tprint("Starting Hacking with Home Computer..."); ns.tprint("------------------------------------"); ns.run('/scripts/homeattack.js', 1, 'global-pharm', 776721); ns.run('/scripts/homeattack.js', 1, 'unitalife', 776721); ns.run('/scripts/homeattack.js', 1, 'zb-def', 776721); ns.run('/scripts/homeattack.js', 1, 'vitalife', 776721); ns.run('/scripts/homeattack.js', 1, 'snap-fitness', 776721); // Wait for home computer to finish starting hacking scripts await ns.sleep(1000); ns.tprint("------------------------------------"); ns.tprint("Starting Stock Market on Home Computer..."); ns.run('/stocks/stocktrader4.js', 1); // Wait for home computer to finish starting stock market scripts await ns.sleep(1000); ns.tprint("Stock Market Started on Home Computer..."); ns.tprint("------------------------------------"); ns.tprint("------------------------------------"); ns.tprint("Solving All Contracts Available..."); ns.run('/contracts/solveallcontracts.js', 1); // Wait for everything to complete await ns.sleep(1000); ns.tprint("Startup Completed."); }
Oops Honey, I Drained the Server!
         In the beginning of the game, you may accidentally (or intentionally) drain a server of all of its money and find it really hard to regrow the money back up to max. Don’t panic, you’ll get an achievement for draining a server completely of all its money. Just focus all your servers you control on the server you wish to regrow.

        I've provided a few scripts to do this that you may have to adjust slightly to work in your game and environment. Don't forget to deploy to supergrow.js and grow.js scripts to the host and target servers you control before you execute the script. Later, when you've upgraded your home computer with more cores and RAM, you'll weaken, grow and hack much faster, so it becomes much easier to regrow a depleted server.

supergrow.js - This is the master starting script. It will execute grow.js on the target server you pass as the second argument with the max available threads calculated on the host computer you past as the first argument.

grow.js - This is a just basic grow script. It takes just takes the target and is used as a slave to the supergrow.js script or ran manually with a single thread.

Master Script supergrow.js:
/** @param {NS} ns */ export async function main(ns) { let server = ns.args[0]; let target = ns.args[1]; let ramAvailable = ns.getServerMaxRam(server) - ns.getServerUsedRam(server); let ramPerThread = ns.getScriptRam('/scripts/grow.js'); let threads = Math.floor(ramAvailable / ramPerThread); ns.tprint("Super growing on " + target + " with " + threads + " threads."); ns.exec('/scripts/grow.js', server, threads, target); }

Slave Script grow.js
/** @param {NS} ns */ export async function main(ns) { let target = ns.args[0]; let serverMoneyAvailable = ns.getServerMoneyAvailable(target); let serverMaxMoney = ns.getServerMaxMoney(target); while (serverMoneyAvailable < (serverMaxMoney * 0.75)) { serverMoneyAvailable = ns.getServerMoneyAvailable(target); serverMaxMoney = ns.getServerMaxMoney(target); ns.tprint("-------------------------------------------------------"); ns.tprint("Server money available on " + target + " is " + ns.nFormat(serverMoneyAvailable, "$0.000a" + ".")); ns.tprint("Server max money on " + target + " is " + ns.nFormat(serverMaxMoney, "$0.000a" + ".")); ns.tprint("Starting grow on " + target + " with " + ns.getHostname() + " to " + ns.nFormat(serverMaxMoney * 0.75, "$0.000a") + "..."); await ns.grow(target); } serverMoneyAvailable = ns.getServerMoneyAvailable(target); serverMaxMoney = ns.getServerMaxMoney(target); ns.tprint("-------------------------------------------------------"); ns.tprint("Optimal current money on " + target + " reached !!!"); ns.tprint("Server money available on " + target + " is " + ns.nFormat(serverMoneyAvailable, "$0.000a" + ".")); ns.tprint("Server max money on" + target + " is " + ns.nFormat(serverMaxMoney, "$0.000a" + ".")); }

     These scripts are intended to be called by an automation script, but you can run it manually if you pass the host server and the target server. Just make sure both scripts have been deployed to your host computer or run them from home:

alias supergrow="run supergrow.js"
supergrow n00dles foodnstuff                                                             // supergrow ‘foodstuff’ with ‘n00dles’

grow.js is intended to use with the above master script so it can allocate the proper RAM for the max amount of threads to execute grow with. You can also use grow.js manually, but with a single thread since that should be calculated with the master script calling the slave script:

alias grow="run grow.js"
grow foodnstuff                                 

     You may want to also create a weaken script as well and integrate it into this one, or run it on another server with a modified master script. Remember, your grow will be more effective when the server has been weakened to within 5 of its min security level like in the beginning of the hack script. Just grab the code block from hack.js in the 'Hack the Server' section and integrate it into grow.js if you need to or create a separate, simple slave weaken.js slave script. You'll want to do this for later, anyways.
About Formulas.exe
          Formulas.exe you can purchase for 5 billion off the darkweb, so you can purchase it quite early in the game even though you don’t really need it until later.

The link to the HackingFormulas interface reference is here: https://github.com/danielyxie/bitburner/blob/dev/markdown/bitburner.hackingformulas.md

          These methods will be needed later in more advanced hacking scripts most likely after you augment the first time. Of course, since they are so cheap, you can always get them and play with them to improve your own hacking scripts now. They would most likely be used more in advanced server attacks like coordinated attacks to influence the stock market. I haven’t needed to use them myself and they would be for a more advanced guide.

          The above hack.js script I provided is very bare-bones and could be vastly be improved with Formulas.exe, since there is a more optimal approaches if you look at other's more experienced player's scripts. Just take baby steps until your ready to jump in completely. Once I get to using Formulas.exe, I will probably write a more advanced guide on it's use. For now, for us 'newbies', it should be efficient and it's much easier to make money with the Stock Market than hacking initially. Of course that will change once you augment and able to hack deeper into your network.

From what I've read, you'll need the Formulas API in Bit Node 5.

          I am working on some Formulas.exe code while I grind away on stocks, but still working things out and fixing the bugs. I'll update this section soon with some basics you can do.

Some Tips To Consider
  • 1) Use folders (or directories) to organize scripts. For example, to create a scripts folder, I used nano /scripts/hack.js to initially create the /scripts folder. There is no 'create directory' command, unfortunately, so you have to use nano. Then use ‘cd scripts’ (change directory) into that folder. Do a ‘ls’ (list) command then display the files in that folder(or directory). You can then do a ‘cd ..’ to drop down to the previous directory. This will greatly help organize files and scripts you’ll eventually collect. For myself, I have directories for general scripts (/scripts), contracts scripts (/contracts) and stocks scripts (/stocks).

  • 2) Use Aliases. Linux(and UNIX) systems in general, require a lot of command line typing and remembering of complex commands since the use of GUIs was much later introduced to these systems and seemed to be installed usually as an afterthought. The use of a GUI was even actually considered ‘amature’ among the communities of these operating system users for a very long time. To be honest, I’d rather push a few buttons on a GUI with a mouse like George Jetson, than type out long commands on a terminal, but to each their own :p

    Use the alias command to create aliases to simplify commands and tasks, so you don’t have to type or remember that long and difficult command string.

    For Example:
    alias nuke="run NUKE.exe"

    Also you can do:
    alias - lists all defined aliases
    unalias nuke - removes the nuke alias

The End
          Well, hopefully I have helped you along in your Bitburner journey and have inspired you to continue playing Bitburner addictively and maybe leave a good review for it so that maybe someday it will be recognized by Steam as a regular game (then the Steam achievements will hopefully apply officially)!

          Go ahead and use my scripts as templates to learn from and build your own scripts. I’ve been programming for over 30 years (I am a retired Software Engineer) since the dawn of personal computers in way too many different languages and platforms including mainframes even - really! So, I think I've learned some good programming habits and programming patterns over the years, if very old-school-ish.

Please rate & favorite my Bitburner guides. The game has a very small community and I could use any help getting the rating stars going on them. I'll also return the favor if you tell me what you need.

Also, please read the entire series:
https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2860828429

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2860330999

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2863116304

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2874771586

Disclaimer: 'The For Dummies' in the title is just a name I borrowed from an old series of books from the 1990's, by the way, not to call anyone a Dummy or even an Ape. :p

https://en.wikipedia.org/wiki/For_Dummies

This guide was created by Zac Starfire on Steam. If you found it on another server, this is where it originated.
Change Log
3/2/23
- Added Scripts guide link

9/25/22
- Updated a few things.

9/21/22:
- Expanded the cracking section with more info.
- Added link for info on TOR
- Fixed somethings, grammar and typos.

9/20/22:
- Updated the hack sections with more details as requested.

9/18/22:
- Added the Formulas.exe section.
- Added the Oops Honey, I Drained the Server! section.
- Added more information to the Deployment and Automation sections.
- Minor edits and fixes.

9/17/22:
- Added startup script.
- Fixed some spelling and grammar.
- Added more info on the alias command.

9/16/22:
- Updated serverinfo.js to use the server object and display more information.
- Added Max Threads to serverinfo.js
- Changed var to let in crack.js
- Added spoiler for ns.connect() function.
- Added Change Log section and moved my comments to that section.
- Some more misc stuff.

9/15/22:
- Added isRooted code to serverinfo.js.
- Added findservers.js code.
- Did some cleanup and fixed a few things.
36 Comments
FlynnTheFearless 10 Mar @ 12:11pm 
first loop clips a server.
gmd9224 1 Nov, 2024 @ 3:55pm 
Loved this. It does help a lot for us veteran programmers too.:steamhappy:
Archimedes 13 Oct, 2024 @ 9:08pm 
Thanks for making this. I have been looking for someone to help break this down and you've done a wonderful job. Much appreciated.
Last Lofas 14 Sep, 2024 @ 3:46am 
hm I am not dummy enoughh to even copy paste it and make it work :D
Zac Starfire  [author] 10 Jan, 2024 @ 7:49pm 
@HiEv ya I know - but you got me thinking out of the box ... maybe a mod that adds an another interpreter to the game engine.


It's not my game - so I'm not going to re-write it without being paid :p
HiEv 10 Jan, 2024 @ 6:16pm 
The game is made using JavaScript/TypeScript and runs using an engine that interprets JavaScript, so having the coding in JavaScript makes sense. You'd need to build a whole interpreter in JavaScript to make it run Python or any other language, so there's pretty much zero chance of support for any other language being added.

The game is open source, though, so feel free to add it yourself. 😉
Zac Starfire  [author] 10 Jan, 2024 @ 5:02pm 
@HiEv Ah, cools, thx for headsup :tta_smile_very_happy:
Maybe that will draw me back into the game and get me to update the guides.
I'd also like to see some Python support added since I'm currently mastering Python for AI programming.
HiEv 10 Jan, 2024 @ 11:20am 
Well, a new Bitnode is planned to be added next release (v2.6.0). Not sure how much story is going to be added, though.
Zac Starfire  [author] 8 Jan, 2024 @ 7:36pm 
@HiEv Ah, much better, about time they cleaned up that messy API a bit more :p
Now if they only gave us more story ...
HiEv 8 Jan, 2024 @ 4:34pm 
Nope. You can rename them without deleting them now by using the ns.renamePurchasedServer() [github.com] method.