Home Experience
Linkedin Dice Github Email Me
Java C++ Python Javascript

What walks on four legs in the morning, two legs at noon, and three legs in the evening?

BitBurner Scripts

wormMother.js


		
		
export async function main(ns) {
	const worm = "worm.js";
	const hackScript = "wormHack.js";
	const growScript = "wormGrow.js";
	const weakenScript = "wormWeaken.js";

	while (true) {
		const servers = scanAll(ns, "home");

		for (const server of servers) {
			if (server === "home") continue;
			if (server.startsWith("hacknet-server-")) continue;


			tryRoot(ns, server);

			if (!ns.hasRootAccess(server)) continue;
			if (ns.getServerMaxRam(server) <= 0) continue;

			await ns.scp(worm, server);
			await ns.scp(hackScript, server);
			await ns.scp(growScript, server);
			await ns.scp(weakenScript, server);

			if (!ns.isRunning(worm, server)) {
				ns.exec(worm, server, 1);
				ns.print("Deployed worm to " + server);
			}
		}

		await ns.sleep(10000);
	}
}

function scanAll(ns, start) {
	const found = [];
	const visited = new Set();
	const queue = [start];

	while (queue.length > 0) {
		const server = queue.shift();

		if (visited.has(server)) continue;

		visited.add(server);
		found.push(server);

		for (const neighbor of ns.scan(server)) {
			if (!visited.has(neighbor)) {
				queue.push(neighbor);
			}
		}
	}

	return found;
}

function tryRoot(ns, server) {
	if (ns.hasRootAccess(server)) return;

	if (ns.fileExists("BruteSSH.exe", "home")) ns.brutessh(server);
	if (ns.fileExists("FTPCrack.exe", "home")) ns.ftpcrack(server);
	if (ns.fileExists("relaySMTP.exe", "home")) ns.relaysmtp(server);
	if (ns.fileExists("HTTPWorm.exe", "home")) ns.httpworm(server);
	if (ns.fileExists("SQLInject.exe", "home")) ns.sqlinject(server);

	if (countOpeners(ns) >= ns.getServerNumPortsRequired(server)) {
		ns.nuke(server);
	}
}

function countOpeners(ns) {
	let count = 0;

	if (ns.fileExists("BruteSSH.exe", "home")) count++;
	if (ns.fileExists("FTPCrack.exe", "home")) count++;
	if (ns.fileExists("relaySMTP.exe", "home")) count++;
	if (ns.fileExists("HTTPWorm.exe", "home")) count++;
	if (ns.fileExists("SQLInject.exe", "home")) count++;

	return count;
}


			
		


WormMother.js is the deployment and coordination script for the Bitburner automation system.

It scans the full server network using breadth-first traversal, attempts to gain root access using the available cracking tools,
copies the required worker scripts to usable servers, and launches a worm process when one is not already running.

The script continuously rescans the network so newly accessible servers are automatically added to the system.

worm.js


		

export async function main(ns) {
    const host = ns.getHostname();
		const hackScript = "wormHack.js";
		const growScript = "wormGrow.js";
		const weakenScript = "wormWeaken.js";
			

		while(true)
		{

		const target = findBestTarget(ns);
			if (target == null)
			{
				ns.print("NO VALID TARGET FOUND");
				await ns.sleep(10000);
				continue;
			}


			const minSec = ns.getServerMinSecurityLevel(target);
			const curSec = ns.getServerSecurityLevel(target);
			const maxMoney = ns.getServerMaxMoney(target);
			const curMoney = ns.getServerMoneyAvailable(target);
			

			if (curSec>minSec+1)
			{
				runMax(ns, host, weakenScript, target);
				await ns.sleep(ns.getWeakenTime(target)+Math.floor(Math.random() * 100));
			}
			else if (curMoney < maxMoney * .8)
			{
				runMax(ns,host,growScript, target);
				await ns.sleep(ns.getGrowTime(target)+Math.floor(Math.random() * 100))
			}
			else
			{
				runMax(ns,host,hackScript,target);
				await ns.sleep(ns.getHackTime(target)+Math.floor(Math.random() * 100))
			}
		}

}

function runMax(ns, host, script, target)
{
	const freeRam = ns.getServerMaxRam(host) - ns.getServerUsedRam(host);
	const scriptRam = ns.getScriptRam(script);
	const threads = Math.floor(freeRam/scriptRam);

	if (threads > 0)
	{
		ns.exec(script, host, threads, target);
	}

}

function findBestTarget(ns)
{
	const servers = scanAll(ns,"home");
	
	let bestServer = null;
	let bestMoney = 0;

	for (const server of servers)
	{
		if (server === "home") continue;
		if (server.startsWith("hacknet-server")) continue;
		if (!ns.hasRootAccess(server)) continue;
		if (ns.getServerRequiredHackingLevel(server) > ns.getHackingLevel()) continue;
	
	const maxMoney = ns.getServerMaxMoney(server);

		if (maxMoney > bestMoney)
		{
			bestMoney = maxMoney;
			bestServer = server;
		}
	}

	return bestServer;
}


function scanAll(ns, start)
{
	const found = [];
	const visited = new Set();
	const queue = [start];

	while (queue.length > 0)
	{
		const server = queue.shift();

		if (visited.has(server)) continue;

		visited.add(server);
		found.push(server);

		for (const neighbor of ns.scan(server))
		{
			if (!visited.has(neighbor))
			{
				queue.push(neighbor);
			}
		}
	}

	return found;
}
			
		


Worm.js is the decision-making worker for the Bitburner automation system. Each deployed instance independently scans the network,
selects the most valuable valid target, evaluates its security and available money, and chooses whether to weaken, grow, or hack it.

The script dynamically allocates the host server's available RAM to the selected task and uses operation timing with small randomized delays to keep distributed workers from remaining synchronized.

wormHack.js


export async function main(ns) {
	await ns.hack(ns.args[0]);
} 




This is the Worm Hack payload.
Hack is used to take money from a server.

wormGrow.js


export async function main(ns) {
	await ns.grow(ns.args[0]);
}
		


This is the Worm Grow payload.
Grow is used to increase the amount of money on a server.

wormWeaken.js


		
		
	export async function main(ns) {
		await ns.weaken(ns.args[0]);
	}
			


This is the Worm Weaken payload.
Weaken is used to reduce the securty value of a server.