Bitburner – Basic Auto Hack Script for Beginners

Basic auto hack script that finds and automates the farming of servers.

Guide to Auto Farm for New Players

The guide is pretty much in the code section with my attempt at documentation.

It’s plug and play once you have the 3 tiny scripts in your home directory.

Beware that it will shut off any scripts on servers it gains control of.

disableLog("disableLog"); disableLog("brutessh"); disableLog("ftpcrack"); disableLog("relaysmtp");
disableLog("httpworm"); disableLog("sqlinject"); disableLog("nuke"); disableLog("getServerMinSecurityLevel");
disableLog("getServerRequiredHackingLevel"); disableLog("getHackingLevel"); disableLog("scp");
disableLog("getServerMoneyAvailable"); disableLog("fileExists"); disableLog("getServerNumPortsRequired");
disableLog("getServerUsedRam"); disableLog("getServerSecurityLevel"); disableLog("scan"); disableLog("killall");
disableLog("getServerMaxMoney"); disableLog("getServerMaxRam"); disableLog("getScriptRam"); tail();
//Stuff above is just for visual clarity in the console, couldn't get disable ALL to work :P

//      Welcome to my messy, horribly optimised, quickly slapped together script for beginners, by a beginner, good luck with this brain aneurysm which I tried to document
//      This whole thing will scan for all servers you can hack, then start automatically farming them, but it's not the fastest

var files = ["weaken.script", "grow.script", "hack.script"];//   The files you need to make in your home directory which will be sent with scp
//Contents:   weaken(args[0]); grow(args[0]); hack(args[0]);     These are as small as possible to allow for many threads

//Sets variables, I wouldn't touch them, might explode
var serverList = scan("home"); var serverCount = [serverList.length, 0];
var hk = [0, 0, 0, 0, 0]; var possibleThreads = 0; var scanLevel = 2;
var count = 0; var inner = 0; var approvedList = []; var exeCount = 0;
var linked; var target; var depth = 0; var checked = 0; var hackType;

//Checks if you have hacks so we know for later
if (fileExists("BruteSSH.exe"))   { hk[0] = 1; exeCount++ };
if (fileExists("FTPCrack.exe"))   { hk[1] = 1; exeCount++ };
if (fileExists("relaySMTP.exe"))  { hk[2] = 1; exeCount++ };
if (fileExists("HTTPWorm.exe"))   { hk[3] = 1; exeCount++ };
if (fileExists("SQLInject.exe"))  { hk[4] = 1; exeCount++ };
if (fileExists("DeepscanV1.exe")) { scanLevel += 2 };  //Comment out one or both of these lines if you don't have 
if (fileExists("DeepscanV2.exe")) { scanLevel += 5 }; //high hack skill or want to avoid time consuming deep scans

//The badly formatted fun begins...
print("/---/ SEARCHING \\---\\\n-- Default --\n > "+ serverList.join("\n > ") + "\n>- Scan Limit: L" + [scanLevel + 1] + " -<") //Print is just for the visuals
while (count <= serverCount[depth] - 1 && depth < scanLevel) {//The scan will stop if  we hit depth limit
    linked = scan(serverList[checked]);checked++; //Scan will bring back all connected servers which we then run through checks below
    for (i = 0; i <= linked.length - 1; i++) {//If the scan results in 1 or more linked servers this area will cycle through them
        target = linked[i];//Targets 1 part of the scan result at a time
        if (target != "home" && !serverList.includes(target)) {//Makes sure our target isn't home or a server we already know of
            serverList.push(target);//Adds the target to the list
            print("L"+ [depth + 2] + " > " + target); serverCount[depth + 1]++;
        }
    }
    if (count == serverCount[depth] - 1) { count = 0; depth++; serverCount.push(0) } else { count++ };//I made this part 24 hours ago, good luck getting an explanation
}

print("/-------/ CHECKING \\-------\\");
for (i = 0; i <= serverList.length - 1; i++) {//Runs once for each entry in serverList
    target = serverList[i];
    if (getServerNumPortsRequired(target) > exeCount)                   { print(" >X<  SOFTWARE " + target) } //Denied if you cannot open the required ports
    else if (getServerMoneyAvailable(target) == 0)                      { print(" >X<  NO MONEY " + target) }//Denied if there's no loot
    else if (getServerMaxRam(target) < 2)                               { print(" >X<  NO RAM " + target) } //Denied because potato
    else if (getHackingLevel() < getServerRequiredHackingLevel(target)) { print(" >X<  SKILL " + target) } //Denied because your hacking is too low
    else {//Server approved, 5 lines below will open ports on target if you have the required exe
        if (hk[0]) { brutessh(target)  };
        if (hk[1]) { ftpcrack(target)  };
        if (hk[2]) { relaysmtp(target) };
        if (hk[3]) { httpworm(target)  };
        if (hk[4]) { sqlinject(target) };
        nuke(target); scp(files, "home", target); killall(target);//Nuke, transfer files and kill running scripts on target
        approvedList.push(target);//This server is ready to farm, puts it in the approved list for later
        print(" >>>  VALID " + target);
    }
}

print("/------------/ HACKING \\------------\\");
count = 0;//Reset so we can use it again
while (true) {//Runs forever
    if (count > approvedList.length - 1) { count = 0 }//Sets count to 0 if we reach the end of list, starts cycle again
    target = approvedList[count];//Picks server from list based on count
    if (getServerUsedRam(target) == 0) {                                                                    //If nothing is already running on server
        if (getServerSecurityLevel(target) > getServerMinSecurityLevel(target) + 5) { hackType = "weaken" }//and the security is too high, weaken           /You can change the 5
        else if (getServerMoneyAvailable(target) < getServerMaxMoney(target) * 0.80) { hackType = "grow" }//and the money is too low, boosto               /and the 0.80
        else { hackType = "hack" }                                                                       //and if everything is just right...
        print("|||||||||| " + hackType + " --> " + approvedList[count] + " ||||||||||");
        exec(hackType + ".script", target, Math.floor(getServerMaxRam(target) / getScriptRam(hackType + ".script")), target)//Runs 1 of the 3 scripts on target server against itself
    } count++;//Helps us cycle through our list                                                                   Threads are based on the amount of RAM the server has, rounded down
}

Do note that with lots of “approved servers” this will not be optimal, at all, this is just a lazy way to do things at the start.

With very little thought you could make the scripts run against a different target too, hope you find this mess even slightly helpful, and have a good day.

Recommended for You

12 Comments

  1. where you write “I made this part 24 hours ago, good luck getting an explanation”
    this is where it increases “count” (which should be named serverIndex) if there are still servers on this level, if not it resets the index to 0 and goes one level deeper 🙂

  2. Thanks, works nicely, total noob in this kind of thing, but I like them anyways :s
    disableLog(‘ALL’), seems to work.

  3. damn that’s a lot better than my method of making everyone hack n00dles (mainly because i had to manually put a .js on each one)
    i might try making an upgraded version of this
    to code in a .js instead of .script the big differences are:
    -you need to type await before certain functions that take time to complete, though in this case most of those functions are being run by the victim server since they’re all hacking related
    -most functions become ns.functionname(functionargs)

    but hte return is that your code runs faster for maximum farming 🙂

  4. one idea that might speed it up is to have the main hacking loop as a seperate script so it can be run in multiple instances, then run an instance on any server that has enough ram but otherwise wouldn’t be a target, you can run code on any nuked server, even if your level is too low to run the hack command.

  5. just realised that you can make it more efficient by splitting the victim servers array according to how many hacker servers are available, and making each hacker server responsible for managing a smaller number of victims.
    and for a more advanced farming we can have a small script wait for certain thresholds in skill and money, then buy a bunch of 8gb servers (the smallest that can run your script), then all the hackers and wait for the victims to finish their last instruction before we repopulate the server list based on the new values.

  6. powertoys that code isn’t as hard to make, but you’d want to also change the criteria for approving servers, since we just need ram and ports to be available for running code, you also can’t run as many attacks though since this would turn every available server against a single target.

  7. hello,

    maybe i am stupid but where did i get those scripts for var files = [“weaken.script”, “grow.script”, “hack.script”]; ?

    i just make a file on home as you said, but it seems like you have to fill it woth some code?!

  8. I tried to clean this up for you a little. I didn’t change much, if anything; but its certainly more legible.

    disableLog(“disableLog”); disableLog(“brutessh”); disableLog(“ftpcrack”); disableLog(“relaysmtp”);
    disableLog(“httpworm”); disableLog(“sqlinject”); disableLog(“nuke”); disableLog(“getServerMinSecurityLevel”);
    disableLog(“getServerRequiredHackingLevel”); disableLog(“getHackingLevel”); disableLog(“scp”);
    disableLog(“getServerMoneyAvailable”); disableLog(“fileExists”); disableLog(“getServerNumPortsRequired”);
    disableLog(“getServerUsedRam”); disableLog(“getServerSecurityLevel”); disableLog(“scan”); disableLog(“killall”);
    disableLog(“getServerMaxMoney”); disableLog(“getServerMaxRam”); disableLog(“getScriptRam”); tail();
    //Stuff above is just for visual clarity in the console, couldn’t get disable ALL to work 😛
    // Welcome to my messy, horribly optimised, quickly slapped together script for beginners, by a beginner, good luck with this brain aneurysm which I tried to document
    // This whole thing will scan for all servers you can hack, then start automatically farming them, but it’s not the fastest

    var files = [“weaken.script”, “grow.script”, “hack.script”];
    // The files you need to make in your home directory which will be sent with scp
    //Contents: weaken(args[0]); grow(args[0]); hack(args[0]); These are as small as possible to allow for many threads

    //Sets variables, I wouldn’t touch them, might explode
    var serverList = scan(“home”); var serverCount = [serverList.length, 0];
    var hk = [0, 0, 0, 0, 0]; var possibleThreads = 0; var scanLevel = 2;
    var count = 0; var inner = 0; var approvedList = []; var exeCount = 0;
    var linked; var target; var depth = 0; var checked = 0; var hackType;

    //Checks if you have hacks so we know for later
    if (fileExists(“BruteSSH.exe”)) { hk[0] = 1; exeCount++ };
    if (fileExists(“FTPCrack.exe”)) { hk[1] = 1; exeCount++ };
    if (fileExists(“relaySMTP.exe”)) { hk[2] = 1; exeCount++ };
    if (fileExists(“HTTPWorm.exe”)) { hk[3] = 1; exeCount++ };
    if (fileExists(“SQLInject.exe”)) { hk[4] = 1; exeCount++ };
    if (fileExists(“DeepscanV1.exe”)) { scanLevel += 2 };

    //Comment out one or both of these lines if you don’t have
    if (fileExists(“DeepscanV2.exe”)) { scanLevel += 5 };

    //high hack skill or want to avoid time consuming deep scans

    //The badly formatted fun begins…
    print(“/—/ SEARCHING \—\|/n– Default –n\ > ” + serverList.join(“\n > “) + “\n>- Scan Limit: L” + [scanLevel + 1] + ” -<")
    //Print is just for the visuals
    while (count <= serverCount[depth] – 1 && depth < scanLevel) {
    //The scan will stop if we hit depth limit
    linked = scan(serverList[checked]); checked++;

    //Scan will bring back all connected servers which we then run through checks below
    for (i = 0; i ” + target); serverCount[depth + 1]++;
    }
    }
    if (count == serverCount[depth] – 1) { count = 0; depth++; serverCount.push(0) } else { count++ };
    //I made this part 24 hours ago, good luck getting an explanation
    }

    print(“/——-/ CHECKING \——-\”);
    for (i = 0; i exeCount) { print(” >XX< NO MONEY " + target) }
    //Denied if there's no loot
    else if (getServerMaxRam(target) X< NO RAM " + target) }
    //Denied because potato
    else if (getHackingLevel() X>> VALID ” + target);
    }
    }

    print(“/————/ HACKING \————\”);
    count = 0;

    //Reset so we can use it again
    while (true) {

    //Sets count to 0 if we reach the end of list, starts cycle again
    if (count > approvedList.length – 1) { count = 0 }

    //Picks server from list based on count
    target = approvedList[count];
    if (getServerUsedRam(target) == 0) {

    //If nothing is already running on server
    if (getServerSecurityLevel(target) > getServerMinSecurityLevel(target) + 5) { hackType = “weaken” }

    //and the security is too high, weaken
    //You can change the 5
    else if (getServerMoneyAvailable(target) ” + approvedList[count] + ” ||||||||||”);
    exec(hackType + “.script”, target, Math.floor(getServerMaxRam(target) / getScriptRam(hackType + “.script”)), target)

    //Runs 1 of the 3 scripts on target server against itself
    } count++;

    //Helps us cycle through our list
    //Threads are based on the amount of RAM the server has, rounded down
    }

Leave a Reply

Your email address will not be published.


*