This commit is contained in:
Zakary Timson 2022-02-04 16:49:05 +00:00
parent 128f2a8d2d
commit 308b422c75
7 changed files with 256 additions and 1 deletions

View File

@ -1,3 +1,49 @@
# BitBurner
These scripts are for playing the [open source](https://github.com/danielyxie/bitburner) game [BitBurner](https://danielyxie.github.io/bitburner/)
Scripts created for the game BitBurner
## Table of Contents
[[_TOC_]]
## Setup
The repository can be loaded into the game by doing the following:
1. Download the update scritp in-game by running: `wget https://gitlab.zakscode.com/ztimson/BitBurner/-/raw/develop/scripts/update.js scripts/update.js`
2. Run the update script to pull the entire repository: `run scripts/update.js`
## Quick Start
```bash
# Start the node manager
run scripts/node-manager.js 8
# Chain the crawler, auto-pwner & miner to hack everything within 3 hops
run scripts/crawler.js 3 scripts/auto-pwn.js scripts/miner.js
```
## Scripts
### auto-pwn.js
Automatically gains root on a target machine. After being pwned, the specified files will be coppied & ran.
It's recomended you use this in combination with `miner.js`
### bruteforce.js
Attacks target until security falls bellow threshold. Useful for throwing extra compute power & cracking a specific computer.
It's recommended you use any extra compute power on your home computer/servers to break strong servers & speed up the process.
### crawler.js
Scans the network to a desired depth & runs the specified script against targets.
It's recommended you use this in combination with `auto-pwn.js`.
### miner.js
Will weaken, spoof & hack the target in a loop.
It's recommended you run this in combination with `auto-pwn.js` to gain root & run the miner on the remote machine.
### node-manager.js
Manages the specified number of nodes buying any if they don't exist.
It's recommended you run this from your home computer, it useses very little RAM.
### update.js
Automaticlly downloads all the scripts in this repo using the in-game `wget`.

58
scripts/auto-pwn.js Normal file
View File

@ -0,0 +1,58 @@
export async function main(ns) {
/**
* Prints text and waits a random amount of time to emulate
* work being complete.
*/
async function printWithDelay(text, min=1, max=1) {
ns.tprint(text);
await ns.sleep(~~(Math.random() * (max * 1000 - min * 1000)) + min * 1000);
}
function usage(message) {
ns.tprint(`${!message ? '' : `${message}\n\n`}Usage:\nrun hack.js <target> <script1> [...scripts]\n\n\ttarget - Hostname or Address to attack\n\tscript1 - Path to script to run\n\tscripts - Additional scripts to run`);
}
// Setup
ns.disableLog('ALL');
if (ns.args[0] == null) return usage('Missing target address');
if (ns.args.length < 2) return usage('Provide scritp(s) for remote execution');
const TARGET = ns.args[0];
const SCRIPTS = ns.args.slice(1);
// Banner
ns.tprint('===================================================');
ns.tprint(`🧑‍💻 Hacking: ${TARGET}`);
await printWithDelay('===================================================');
// Gain root
// await printWithDelay(`Attacking (SSH) ⚔️ ${TARGET}:22`, 3, 5);
// ns.brutessh(TARGET);
// await printWithDelay(`Attacking (FTP) ⚔️ ${TARGET}:24`, 3, 5);
// ns.ftpcrack(TARGET);
ns.nuke(TARGET);
await printWithDelay(`💀 Root Granted 💀`);
// Copy scripts
ns.tprint('');
await printWithDelay('Copying scripts:');
await Promise.all(SCRIPTS.map(async s => {
const SPEED = ~~(Math.random() * 100) / 10
await printWithDelay(`${s} \t [==================>] 100% \t (${SPEED} MB/s)`);
await ns.scp(s, TARGET);
}));
// Run scripts
ns.tprint('');
const THREADS = Math.floor(ns.getServerMaxRam(TARGET) / 2.3);
await Promise.all(SCRIPTS.map(async s => {
ns.scriptKill(s, TARGET);
await printWithDelay(`ssh -c "run ${s} -t ${THREADS}" root@${TARGET}`);
const PID = ns.exec(s, TARGET, THREADS, TARGET);
if(!PID) ns.tprint('⚠️ Failed to start ⚠️');
}));
ns.tprint('✅ Complete!');
}
export function autocomplete(data) {
return [...data.servers, ...data.scripts];
}

27
scripts/bruteforce.js Normal file
View File

@ -0,0 +1,27 @@
export async function main(ns) {
ns.disableLog('ALL');
const TARGET = ns.args[0];
const SECURITY = ns.getServerMinSecurityLevel(TARGET);
let security, once = true;
do {
security = ns.getServerSecurityLevel(TARGET);
if(once) {
ns.print('===================================================');
ns.print(`🔐 Bruteforcing: ${TARGET}`);
ns.print('===================================================');
ns.print(`Security: ${Math.round(security * 100) / 100}/${SECURITY}`);
ns.print('===================================================');
once = false;
}
ns.print(`Attacking ⚔️...`);
const w = await ns.weaken(TARGET);
ns.print(`Security: ${w} (${Math.round((security - w) * 100) / 100}/${SECURITY})`);
} while (security > SECURITY);
ns.print('Complete!');
}
export function autocomplete(data) {
return [...data.servers];
}

21
scripts/crawler.js Normal file
View File

@ -0,0 +1,21 @@
export async function main(ns) {
function usage(message) {
ns.tprint(`${!message ? '' : `${message}\n\n`}Usage:\nrun hack-all.js [...scripts]\n\n\tdepth - Follows network recersively\n\tscript1 - Path to script to run\n\tscripts - Additional scripts to run`);
}
ns.disableLog('ALL');
if(ns.args[0] == null) return usage('Missing depth');
if(ns.args.length < 2) return usage('Missing script(s)');
let targets = ns.scan().map(h => [h, 1]);
for(let i = 0; i < targets.length; i++) {
if(targets[i][1] < ns.args[0]) ns.scan(targets[i][0]).forEach(h => {
if(h != 'home') targets.push([h, targets[i][1] + 1])
});
if(ns.getServerRequiredHackingLevel(targets[i][0]) > ns.getHackingLevel()) continue;
if(ns.getServerNumPortsRequired(targets[i][0]) > 0) continue;
ns.run('hack.js', 1, targets[i][0], ...ns.args.slice(1));
do { await ns.sleep(1000); }
while(ns.scriptRunning('hack.js', 'home'));
}
}

40
scripts/miner.js Normal file
View File

@ -0,0 +1,40 @@
export async function main(ns) {
ns.disableLog('ALL');
const TARGET = ns.args[0];
const SECURITY = ns.getServerMinSecurityLevel(TARGET) + 2;
let BALANCE, once = true;
while(true) {
let s = await ns.getServerSecurityLevel(TARGET);
let b = await ns.getServerMoneyAvailable(TARGET);
if(BALANCE == null) BALANCE = b;
if(once) {
ns.print('===================================================');
ns.print(`Bankrupting: ${TARGET}`);
ns.print('===================================================');
ns.print(`Security: ${Math.round(s * 100) / 100}/${SECURITY}`);
ns.print(`Balance: $${Math.round(BALANCE * 100) / 100}`);
ns.print('===================================================');
once = false;
}
if(s > SECURITY) {
ns.print('Attacking Security...');
const w = await ns.weaken(TARGET);
ns.print(`Security: -${w} (${Math.round((s - w) * 100) / 100}/${SECURITY})`);
} else if(b < BALANCE) {
ns.print('Spoofing Balance...');
const g = await ns.grow(TARGET);
ns.print(`Balance: +${Math.round(g * 10) / 10}% ($${Math.round(b * g * 100) / 100})`);
} else {
ns.print('Hacking Account...');
const h = await ns.hack(TARGET);
ns.print(`Balance: -$${h} ($${Math.round((b - h) * 100) / 100})`);
}
}
}
export function autocomplete(data) {
return [...data.servers];
}

45
scripts/node-manager.js Normal file
View File

@ -0,0 +1,45 @@
export function sortByProp(prop, reverse = false) {
return function(a, b) {
if(a[prop] > b[prop]) return reverse ? -1 : 1;
if(a[prop] < b[prop]) return reverse ? 1: -1;
return 0;
};
}
export async function main(ns) {
ns.disableLog('ALL');
const LIMIT = ns.args[0] || 8;
let nodeCount = ns.hacknet.numNodes();
ns.print('===================================================');
ns.print(`🖥️ Node Manager: ${nodeCount}`);
ns.print('===================================================');
while(true) {
let limit = LIMIT < ns.hacknet.maxNumNodes() ? LIMIT : ns.hacknet.maxNumNodes();
while(nodeCount < limit) {
const res = ns.hacknet.purchaseNode();
if(res == -1) break;
nodeCount++;
ns.print(`Purchased Node: ${nodeCount}`);
}
const NODES = Array(nodeCount).fill(null)
.map((ignore, i) => ({index: i, ...ns.hacknet.getNodeStats(i)}));
NODES.sort(sortByProp('level')).forEach(n => {
const s = ns.hacknet.upgradeLevel(n.index, 1);
if(s) ns.print(`Purchased Level for: ${n.index}`);
});
NODES.sort(sortByProp('ram')).forEach(n => {
const s = ns.hacknet.upgradeRam(n.index, 1);
if(s) ns.print(`Purchased RAM for: ${n.index}`);
});
NODES.sort(sortByProp('cores')).forEach(n => {
const s = ns.hacknet.upgradeCore(n.index, 1);
if(s) ns.print(`Purchased CPU for: ${n.index}`);
});
await ns.sleep(10000);
}
}

18
scripts/update.js Normal file
View File

@ -0,0 +1,18 @@
export async function main(ns) {
const FILE_LIST = [
'scripts/auto-pwn.js',
'scripts/bruteforce.js',
'scripts/crawler.js',
'scripts/miner.js',
'scripts/node-manager.js',
'scripts/update.js'
];
function getUrl(file) {
return `https://gitlab.zakscode.com/ztimson/BitBurner/-/raw/develop/${file}`;
}
for(const FILE of FILE_LIST) {
await ns.wget(getUrl(FILE), FILE);
}
}