Advertisement
r00key

jormungandr.js

Aug 15th, 2022 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Bitburner script: jormungandr.js
  2. /** @param {NS} ns */
  3. export async function main(ns) {
  4.     let branches = ns.scan();
  5.     let validBranches = getValidBranches(ns, branches);
  6.  
  7.     for (let branch of validBranches) {
  8.         getRootAccess(ns, branch);
  9.     }
  10.  
  11. }
  12.  
  13. function getValidBranches(ns, branches) {
  14.     let validBranches = [];
  15.     for (let branch of branches) {
  16.         if (branchValid(ns, branch)) {
  17.             validBranches.push(branch);
  18.         }
  19.     }
  20.     return validBranches;
  21. }
  22.  
  23. function branchValid(ns, branch) {
  24.     let hackingLevel = ns.getHackingLevel();
  25.     var retVal = ns.getServerRequiredHackingLevel(branch) <= hackingLevel;
  26.     return retVal;
  27. }
  28.  
  29. function getRootAccess(ns, target) {
  30.     if (!ns.hasRootAccess(target) && openPorts(ns, target)) {
  31.         ns.nuke(target);
  32.     }
  33. }
  34.  
  35. function openPorts(ns, target) {
  36.     let portsRequired = ns.getServerNumPortsRequired(target);
  37.     let portsBroken = 0;
  38.     if (portsRequired == 0) {
  39.         return true;
  40.     } else {
  41.         if (ns.fileExists("BruteSSH.exe", "home") && portsBroken < portsRequired) {
  42.             ns.brutessh(target);
  43.             portsBroken++;
  44.         }
  45.         if (ns.fileExists("FTPCrack.exe", "home") && portsBroken < portsRequired) {
  46.             ns.ftpcrack(target);
  47.             portsBroken++;
  48.         }
  49.         if (ns.fileExists("relaySMTP.exe", "home") && portsBroken < portsRequired) {
  50.             ns.relaysmtp(target);
  51.             portsBroken++;
  52.         }
  53.         if (ns.fileExists("HTTPWorm.exe", "home") && portsBroken < portsRequired) {
  54.             ns.httpworm(target);
  55.             portsBroken++;
  56.         }
  57.         if (ns.fileExists("SQLInject.exe", "home") && portsBroken < portsRequired) {
  58.             ns.sqlinject(target);
  59.             portsBroken++;
  60.         }
  61.         if (portsBroken >= portsRequired) {
  62.             return true;
  63.         }
  64.     }
  65.     return false;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement