Created
September 6, 2022 06:26
-
-
Save Draco18s/1df40652ba69c6884bae19327751c6a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Automated process to discover and gain control of servers in Bitburner | |
*/ | |
/** @param {NS} ns */ | |
let knowntargets = []; | |
let lastlevel = -1; | |
export async function main(ns) { | |
knowntargets = []; | |
if (knowntargets.length == 0) init(ns); | |
ns.disableLog('disableLog'); | |
ns.disableLog('sleep'); | |
ns.disableLog('getHackingLevel'); | |
ns.disableLog('getServerRequiredHackingLevel'); | |
ns.disableLog('getServerMaxMoney'); | |
ns.disableLog('getServerMoneyAvailable'); | |
ns.disableLog('getServerNumPortsRequired'); | |
ns.disableLog('getServerMaxRam'); | |
ns.disableLog('brutessh'); | |
ns.disableLog('ftpcrack'); | |
ns.disableLog('relaysmtp'); | |
ns.disableLog('sqlinject'); | |
ns.disableLog('httpworm'); | |
while (true) { | |
var lv = ns.getHackingLevel(); | |
if (lv > lastlevel) | |
await DoUpdates(ns, lv); | |
lastlevel = lv; | |
ns.write('known-servers.txt', knowntargets.join(','), 'w'); | |
await ns.sleep(60000); | |
} | |
} | |
function init(ns) { | |
if (ns.fileExists('known-servers.txt')) | |
knowntargets = ns.read('known-servers.txt').split(','); | |
else | |
knowntargets = ns.scan('home'); | |
} | |
async function DoUpdates(ns, lv) { | |
var freshTarg = []; | |
for (var loc in knowntargets) { | |
var newlocs = ns.scan(knowntargets[loc]); | |
for (var lc in newlocs) { | |
var l = newlocs[lc]; | |
if (knowntargets.includes(l) || l == 'home' || freshTarg.includes(l)) continue; | |
if (ns.fileExists('ignore.txt', l)) continue; | |
freshTarg.push(l); | |
ns.tprint("Discovered " + l); | |
} | |
} | |
await ns.sleep(100); | |
knowntargets = knowntargets.concat(freshTarg); | |
var badtargs = []; | |
for (var loc in knowntargets) { | |
var targ = knowntargets[loc]; | |
var req = ns.getServerRequiredHackingLevel(targ); | |
await ns.sleep(100); | |
if (req <= lv) { | |
ns.print('Accessing ' + targ); | |
if (!ns.hasRootAccess(targ)) { | |
var maxHack = 0; | |
if (ns.fileExists('BruteSSH.exe', 'home')) | |
maxHack++; | |
if (ns.fileExists('FTPCrack.exe', 'home')) | |
maxHack++; | |
if (ns.fileExists('relaySMTP.exe', 'home')) | |
maxHack++; | |
if (ns.fileExists('SQLInject.exe', 'home')) | |
maxHack++; | |
if (ns.fileExists('HTTPWorm.exe', 'home')) | |
maxHack++; | |
if (ns.getServerNumPortsRequired(targ) > maxHack) continue; | |
ns.tprint(targ + ' is potentially hackable!'); | |
if (ns.fileExists('BruteSSH.exe', 'home')) | |
ns.brutessh(targ); | |
if (ns.fileExists('FTPCrack.exe', 'home')) | |
ns.ftpcrack(targ); | |
if (ns.fileExists('relaySMTP.exe', 'home')) | |
ns.relaysmtp(targ); | |
if (ns.fileExists('SQLInject.exe', 'home')) | |
ns.sqlinject(targ); | |
if (ns.fileExists('HTTPWorm.exe', 'home')) | |
ns.httpworm(targ); | |
if (ns.nuke(targ)) { | |
ns.tprint('Gained control of ' + targ + '!'); | |
if (ns.ls(targ, 'cct').length > 0) ns.tprint(targ + ' has smart contracts!'); | |
} | |
} | |
if (!ns.hasRootAccess(targ)) continue; | |
if (ns.fileExists('ignore.txt', targ)) { | |
ns.print('found ignore file on ' + targ); | |
badtargs.push(targ); | |
continue; | |
} | |
if (ns.getServerMaxMoney(targ) < 100 || ns.getServerMoneyAvailable(targ) < 100) { | |
ns.scp('ignore.txt', targ, 'home'); | |
ns.print(targ + ' has no money'); | |
badtargs.push(targ); | |
continue; | |
} | |
var ram = ns.getServerMaxRam(targ); | |
if (ram == 0) { | |
badtargs.push(targ); | |
ns.print(targ + ' has no ram'); | |
ns.scp('ignore.txt', targ, 'home'); | |
} | |
if (ram < 10) { | |
ns.print(targ + ' has low ram'); | |
var noram = ns.read('no-ram-servers.txt').split(','); | |
if (!noram.includes(targ)) noram.push(targ); | |
ns.write('no-ram-servers.txt', noram.join(','), 'w'); | |
} | |
} | |
} | |
knowntargets = knowntargets.filter(function (el) { | |
return !badtargs.includes(el); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment