init
This commit is contained in:
		
							
								
								
									
										58
									
								
								scripts/auto-pwn.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								scripts/auto-pwn.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										27
									
								
								scripts/bruteforce.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										21
									
								
								scripts/crawler.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										40
									
								
								scripts/miner.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										45
									
								
								scripts/node-manager.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										18
									
								
								scripts/update.js
									
									
									
									
									
										Normal 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user