Bitburner Hacking for Dummies

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://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’).

Later 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.

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://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 augment 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 requiredHackingLevel = ns.getServerRequiredHackingLevel(target); let securityLevelMin = ns.getServerMinSecurityLevel(target); let currentSecurityLevel = ns.getServerSecurityLevel(target); let serverMoneyAvailable = ns.getServerMoneyAvailable(target); let serverMaxMoney = ns.getServerMaxMoney(target); let maxServerRam = ns.getServerMaxRam(target); let usedServerRam = ns.getServerUsedRam(target); ns.tprint(target + " required hacking level is " + requiredHackingLevel + "."); ns.tprint(target + " min security level is " + securityLevelMin + "."); ns.tprint("Current security level on " + target + " is " + ns.nFormat(currentSecurityLevel, "0.00") + "."); ns.tprint(target + " Current Money: " + ns.nFormat(serverMoneyAvailable, "$0.000a")); ns.tprint(target + " Max Money: " + ns.nFormat(serverMaxMoney, "$0.000a")); ns.tprint(target + " Max Server RAM: " + maxServerRam); ns.tprint(target + " Used Server RAM: " + usedServerRam); }

Note: There is a server object you can request with an API function and get even more information on that server, then display that information - this was just with the basic functions in the script. Also, later you’ll also have to be able to crawl the networks looking for contract files on servers to perform needed faction work. I’ll let you figure those two things out on your own or maybe I'll save for a later guide, just something to think about on how to improve these scripts for yourself later.

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.

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 them myself.

Root Access - Simply means you're the 'super user' on the machine and can run 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’.

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) { var 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.

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 a very basic formula from the examples in the basic documentation: 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. This is performed with the weaken() command.

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.

Finally, Hack the Server - Once the first 2 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.

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

/** @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); currentSecurityLevel = ns.getServerSecurityLevel(target); //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 ?

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 = ['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 = ['n00dles', '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); }; }

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); }

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.

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. Just a little less coding but I do recommend using 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); //} } }

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 command to do this initially, unfortunately) 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 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"

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 25 years 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 and favorite my guide after you're done !!!

Source: https://steamcommunity.com/sharedfiles/filedetails/?id=2860828429					

More Bitburner guilds