Bitburner Hack Script Update Version 2

Bitburner Hack Script Update Version 2 1 - steamsplay.com
Bitburner Hack Script Update Version 2 1 - steamsplay.com

This is the best hacking script that I could come up with.
 
Fully optimized, works with parallel tasks, minimal runtime.
 
 

Introduction

Hey all,
 
 
this is my idea of the ultimate hacking script.
 
Not only does it generate a lot of money in the least possible time, but it also generates a lot of hacking exp.
 
It took a hot minute to make, because neither am I a programmer, nor do I know any JavaScript.
 


 

UPDATE Version 2

 
I wanted to make a quick update, since I’ve converted the initial version to a lighter and simpler version using the batch method, as suggested by ICU大师 in the comments. The size was reduced by roughly 3 GB, so it now requires 6.5 GB to run instead of the 9.55 GB previously. In my testing, the amount of hack threads did not change. The next plan is to implement the functionality to hack the same server from as many different servers as the sleepTime allows. I will focus on purchased servers, so it’ll be up to 25 servers hacking the same server.
 


 
I mentioned this in the comments in the code as well, but I recommend running the script on ‘home’ and using purchased servers to run the worker tasks on for maximum RAM.
 
When starting out you can also use the RAM of the hacked servers.
 
 
You need to have all 5 script files on ‘home’ or the server you’re starting it from. Also this doesn’t buy the necessary *.exe files for port opening, so you have to do this manually.
 
 
Even when just starting out, I highly recommend purchasing servers for hacking. The available RAM on the servers that you can hack in the beginning is really limited. Even the total amount of all server is only around 3000 GB RAM, I haven’t checked if this is randomized.
 
 
A 128 GB server only costs around $7m. Follow the tutorial, hack n00dles a few times and you should have enough to buy one server.
 
 

USAGE

 
 

// This will hack 'joesguns' and use it's own RAM
home: run masterHack.js joesguns 

// This will hack 'joesguns' and use the RAM of the private server 's1'
home: run masterHack.js joesguns s1

 
 
If you have any questions regarding the usage or the code itself that might not be answered in the code, feel free to drop a comment.
 
 
TL;DR: scrip gud, munny and hack exp go brrrr.
 
 
 

Pastebin links

Here are all the necessary files on Pastebin.
 
nuke.js – NUKE subscript – [pastebin.com] 
 
hack.js – hack() subscript – [pastebin.com] 
 
grow.js – grow() subscript – [pastebin.com] 
 
weaken.js – weaken() subscript – [pastebin.com] 
 
V2 of masterHack.js – Master script – [pastebin.com] 
 
 
You can also use wget to download these to the game servers:
 
 

wget https://pastebin.com/raw/cA4S81ND - [pastebin.com]  nuke.js
wget https://pastebin.com/raw/xvujKPdk - [pastebin.com]  weaken.js
wget https://pastebin.com/raw/N5kdX3rB - [pastebin.com]  grow.js
wget https://pastebin.com/raw/6N1mPpZ9 - [pastebin.com]  hack.js
wget https://pastebin.com/raw/RG2zE6rE - [pastebin.com]  masterHack.js

 
 
 

Archive

Previous versions:
 
V1 of masterHack.js – Master script – [pastebin.com] 
 
 
 

MasterHack.js V2

/** @param {NS} ns **/
export async function main(ns) {
 // Parameters
 // param 1: Server you want to hack
 // param 2: OPTIONAL - Server you want to start the hack from, i.e. any public servers, purchased servers or 'home'
 //
 // EXAMPLE 1: run masterHack.js joesguns
 // This will start hacking 'joesguns' using the RAM of 'joesguns'
 //
 // EXAMPLE 2: run masterHack.js joesguns s1
 // This will start hacking 'joesguns' using the RAM of my purchased server 's1'
 //
 // This 'masterHack.js' process will stay active on whatever server you execute it from.
 // I usually start it from 'home', then I can track all my earnings in one place.
 // Keep in mind, when using 'home' as second parameter the script might use all available RAM
 // and you might become unable to execute any other scripts on 'home' until you kill the process.

 var target = ns.args[0];
 var serverToHackFrom = target; // For single argument calls - server will hack itself
 var hackScript = "hack.js";
 var growScript = "grow.js";
 var weakenScript = "weaken.js";
 var growScriptRAM = ns.getScriptRam(growScript);
 var serverMaxMoney = ns.getServerMaxMoney(target);
 var serverMaxRAM;
 // var batchServers;
 var moneyThresh = serverMaxMoney * 0.9; // 0.90 to maintain near 100% server money. You can use 0.75 when starting out/using low thread counts
 var securityThresh = ns.getServerMinSecurityLevel(target) + 5;
 var currentServerMoney;
 var currentServerSecurity;
 var useThreadsHack, useThreadsWeaken1, useThreadsWeaken2, useThreadsGrow;
 var possibleThreads;
 var maxHackFactor = 0.01;
 var growWeakenRatio = 0.9; // How many threads are used for growing vs. weaking (90:10).
 var sleepTimeHack, sleepTimeGrow, sleepTimeWeaken, sleepDelay = 200; // Sleep delay should range between 20ms and 200ms as per the documentation. I'll keep the default at 200, adjust as needed. 

 // If second argument is provided, hack will run from this server instead
 if (ns.args[1]) {
 /* if(ns.args[1] == "batch")
 batchServers = ns.getPurchasedServers();
 else */
 serverToHackFrom = ns.args[1];
 }
 serverMaxRAM = ns.getServerMaxRam(serverToHackFrom);

 // Gain root access. Make sure you have the nuke.js script on 'home'
 if (!ns.hasRootAccess(target)) {
 ns.exec("nuke.js", "home", 1, target);
 await ns.sleep(1000);
 }

 // Copy the work scripts, if not already on server
 if (!ns.fileExists(hackScript, serverToHackFrom)) {
 await ns.scp(hackScript, "home", serverToHackFrom);
 }
 if (!ns.fileExists(growScript, serverToHackFrom)) {
 await ns.scp(growScript, "home", serverToHackFrom);
 }
 if (!ns.fileExists(weakenScript, serverToHackFrom)) {
 await ns.scp(weakenScript, "home", serverToHackFrom);
 }

 // To prevent the script from crashing/terminating after closing and restarting the game.
 while (ns.isRunning(hackScript, serverToHackFrom, target) || ns.isRunning(growScript, serverToHackFrom, target) || ns.isRunning(weakenScript, serverToHackFrom, target)) {
 await ns.sleep(10000);
 }

 // Main loop - will terminate if no RAM available
 while (3 < (possibleThreads = Math.floor((serverMaxRAM - ns.getServerUsedRam(serverToHackFrom)) / growScriptRAM))) {
 currentServerMoney = ns.getServerMoneyAvailable(target);
 currentServerSecurity = ns.getServerSecurityLevel(target);

 // The first to cases are for new servers with high SECURITY LEVELS and to quickly grow the server to above the threshold
 if (currentServerSecurity > securityThresh && currentServerMoney < moneyThresh) {
 sleepTimeWeaken = ns.getWeakenTime(target) + sleepDelay; // Added 100 milliseconds to the 'sleepTime' variables to prevent any issues with overlapping work scripts
 ns.exec(growScript, serverToHackFrom, Math.ceil(possibleThreads / 2), target);
 ns.exec(weakenScript, serverToHackFrom, Math.floor(possibleThreads / 2), target);
 await ns.sleep(sleepTimeWeaken); // wait for the weaken command to finish
 } else if (currentServerMoney < moneyThresh) {
 sleepTimeWeaken = ns.getWeakenTime(target) + sleepDelay;
 ns.exec(growScript, serverToHackFrom, Math.floor(possibleThreads * growWeakenRatio), target);
 ns.exec(weakenScript, serverToHackFrom, Math.ceil(possibleThreads * (1 - growWeakenRatio)), target);
 await ns.sleep(sleepTimeWeaken); // wait for the weaken command to finish
 } else {
 // Define max amount that can be restored with one grow and therefore will be used to define hack threads.
 // The max grow threads are considering the weaken threads needed to weaken hack security and the weaken threads needed to weaken grow security.
 // I didn't bother optimizing the 'growWeakenRatio' further, as 90% is good enough already. It will be just a few more hack threads, if any at all - even with large RAM sizes.
 while (maxHackFactor < 0.999 &&
 Math.floor((possibleThreads - (useThreadsHack = Math.floor(ns.hackAnalyzeThreads(target, currentServerMoney * maxHackFactor))) - Math.ceil(useThreadsHack / 25)) * growWeakenRatio)
 > Math.ceil(ns.growthAnalyze(target, serverMaxMoney / (serverMaxMoney * (1 - maxHackFactor))))) {
 maxHackFactor += 0.001; // increase by 0.1% with each iteration
 }
 maxHackFactor -= 0.001; // Since it's more than 'possibleThreads' can handle now, we need to dial it back once.
 useThreadsHack = Math.floor(ns.hackAnalyzeThreads(target, currentServerMoney * maxHackFactor)); // Forgot this in the first version.
 useThreadsWeaken1 = Math.ceil(useThreadsHack / 25); // You can weaken the security of 25 hack threads with 1 weaken thread
 useThreadsGrow = Math.floor((possibleThreads - useThreadsWeaken1 - useThreadsHack) * growWeakenRatio);
 useThreadsWeaken2 = possibleThreads - useThreadsHack - useThreadsGrow - useThreadsWeaken1;
 sleepTimeHack = ns.getHackTime(target);
 sleepTimeGrow = ns.getGrowTime(target);
 sleepTimeWeaken = ns.getWeakenTime(target);
 ns.exec(weakenScript, serverToHackFrom, useThreadsWeaken1, target, "1");
 await ns.sleep(2 * sleepDelay);
 ns.exec(weakenScript, serverToHackFrom, useThreadsWeaken2, target, "2"); // Second weaken script runs after the first
 await ns.sleep(sleepTimeWeaken - sleepTimeGrow - sleepDelay);
 ns.exec(growScript, serverToHackFrom, useThreadsGrow, target); // Grow script ends before second weaken script
 await ns.sleep(sleepTimeGrow - sleepTimeHack - 2 * sleepDelay);
 ns.exec(hackScript, serverToHackFrom, useThreadsHack, target); // Hack script ends before first weaken script
 await ns.sleep(sleepTimeHack + 4 * sleepDelay); // wait after second weaken script
 maxHackFactor = 0.01;
 }
 }
 ns.tprint("Script was terminated. Not enough RAM available on '" + serverToHackFrom + "'.")
}

 
 
 

Hack.js

/** @param {NS} ns **/
export async function main(ns) {
 await ns.hack(ns.args[0]);
}

 
 
 

Grow.js

/** @param {NS} ns **/
export async function main(ns) {
 await ns.grow(ns.args[0]);
}

 
 
 

Weaken.js

/** @param {NS} ns **/
export async function main(ns) {
 await ns.weaken(ns.args[0]);
}

 
 
 

Nuke.js

/** @param {NS} ns **/
export async function main(ns) {
 var serv = ns.args[0];
 if(ns.fileExists("BruteSSH.exe"))
 ns.brutessh(serv);

 if(ns.fileExists("FTPCrack.exe"))
 ns.ftpcrack(serv);

 if(ns.fileExists("relaySMTP.exe"))
 ns.relaysmtp(serv);

 if(ns.fileExists("HTTPWorm.exe"))
 ns.httpworm(serv);

 if(ns.fileExists("SQLInject.exe"))
 ns.sqlinject(serv);

 ns.nuke(serv);
}

 
 

Written by JoeMomma

 
 
Here we come to an end for Bitburner Hack Script Update Version 2 hope you enjoy it. If you think we forget something to include or we should make an update to the post let us know via comment, and we will fix it asap! Thanks and have a great day!
 


Be the first to comment

Leave a Reply

Your email address will not be published.


*