initial
This commit is contained in:
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
{
|
||||
// Place your Bitburner workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
|
||||
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
|
||||
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
|
||||
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
|
||||
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
|
||||
// Placeholders with the same ids are connected.
|
||||
// Example:
|
||||
// "Print to console": {
|
||||
// "scope": "javascript,typescript",
|
||||
// "prefix": "log",
|
||||
// "body": [
|
||||
// "console.log('$1');",
|
||||
// "$2"
|
||||
// ],
|
||||
// "description": "Log output to console"
|
||||
// }
|
||||
//,
|
||||
// "": {
|
||||
// "scope": "",
|
||||
// "prefix": "",
|
||||
// "body": [
|
||||
// ""
|
||||
// ],
|
||||
// "description": ""
|
||||
// }
|
||||
"initmain": {
|
||||
"scope": "",
|
||||
"prefix": "initmain",
|
||||
"body": [
|
||||
"/** @param {import(\".\").NS } ns */",
|
||||
"",
|
||||
"export async function main(ns) {",
|
||||
" ns.disableLog('ALL');",
|
||||
" ",
|
||||
" $0",
|
||||
"}"
|
||||
],
|
||||
"description": "New file template for Bitburner."
|
||||
},
|
||||
"print": {
|
||||
"scope": "",
|
||||
"prefix": "print",
|
||||
"body": [
|
||||
"ns.print(`$0`);"
|
||||
],
|
||||
"description": "NS print"
|
||||
},
|
||||
"tprint": {
|
||||
"scope": "",
|
||||
"prefix": "tprint",
|
||||
"body": [
|
||||
"ns.tprint(`$0`);"
|
||||
],
|
||||
"description": "NS terminal print"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"bitburner.authToken": "iQitq5P5Qm+bzKxz8I3KQow1tOfRtZByqcdIP9H8b2aEmwsznA9osU5xHdgJnyUt",
|
||||
"bitburner.fileWatcher.enable": true,
|
||||
"bitburner.showFileWatcherEnabledNotification": false,
|
||||
"bitburner.showPushSuccessNotification": false,
|
||||
"autoSnippet.snippets": [
|
||||
{
|
||||
"pattern": "**/*.js",
|
||||
"snippet": "initmain"
|
||||
},
|
||||
{
|
||||
"language": "javascript",
|
||||
"snippet": "initmain"
|
||||
}
|
||||
],
|
||||
"code-runner.executorMap": {
|
||||
"javascript": "node",
|
||||
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
|
||||
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"php": "php",
|
||||
"python": "python -u",
|
||||
"perl": "perl",
|
||||
"perl6": "perl6",
|
||||
"ruby": "ruby",
|
||||
"go": "go run",
|
||||
"lua": "lua",
|
||||
"groovy": "groovy",
|
||||
"powershell": "powershell -ExecutionPolicy ByPass -File",
|
||||
"bat": "cmd /c",
|
||||
"shellscript": "bash",
|
||||
"fsharp": "fsi",
|
||||
"csharp": "scriptcs",
|
||||
"vbscript": "cscript //Nologo",
|
||||
"typescript": "ts-node",
|
||||
"coffeescript": "coffee",
|
||||
"scala": "scala",
|
||||
"swift": "swift",
|
||||
"julia": "julia",
|
||||
"crystal": "crystal",
|
||||
"ocaml": "ocaml",
|
||||
"r": "Rscript",
|
||||
"applescript": "osascript",
|
||||
"clojure": "lein exec",
|
||||
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
|
||||
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
|
||||
"racket": "racket",
|
||||
"scheme": "csi -script",
|
||||
"ahk": "autohotkey",
|
||||
"autoit": "autoit3",
|
||||
"dart": "dart",
|
||||
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
|
||||
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
|
||||
"haskell": "runhaskell",
|
||||
"nim": "nim compile --verbosity:0 --hints:off --run",
|
||||
"lisp": "sbcl --script",
|
||||
"kit": "kitc --run",
|
||||
"v": "v run",
|
||||
"sass": "sass --style expanded",
|
||||
"scss": "scss --style expanded",
|
||||
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
|
||||
"FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
|
||||
"sml": "cd $dir && sml $fileName"
|
||||
},
|
||||
"cSpell.words": [
|
||||
"brutessh",
|
||||
"CSEC",
|
||||
"ftpcrack",
|
||||
"Hacknet",
|
||||
"httpworm",
|
||||
"relaysmtp",
|
||||
"sqlinject",
|
||||
"tprint"
|
||||
]
|
||||
}
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
export async function main(ns) {
|
||||
// ns.disableLog('ALL');
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
const EXPLOITS = [
|
||||
'BruteSSH.exe',
|
||||
'FTPCrack.exe',
|
||||
'relaySMTP.exe',
|
||||
'HTTPWorm.exe',
|
||||
'SQLInject.exe'
|
||||
];
|
||||
|
||||
/** @function maxPortsToHack
|
||||
* Calculate how many ports you're able to open
|
||||
* @returns {number} number of ports you're able to open
|
||||
*/
|
||||
function maxPortsToHack() {
|
||||
let maxPorts = 0;
|
||||
EXPLOITS.forEach(exploit => {
|
||||
if (ns.fileExists(exploit)) ++maxPorts;
|
||||
});
|
||||
// ns.tprint(`Max ports for hacking ${maxPorts}`);
|
||||
return maxPorts;
|
||||
}
|
||||
|
||||
/** @function analyzeServer
|
||||
* Analyze server requirements
|
||||
* @param {string} server
|
||||
* @returns {object} object containing server information
|
||||
*/
|
||||
function analyzeServer(server) {
|
||||
let requiredHacking = ns.getServerRequiredHackingLevel(server);
|
||||
let requiredPorts = ns.getServerNumPortsRequired(server);
|
||||
let currentHacking = ns.getHackingLevel();
|
||||
|
||||
return {
|
||||
"rootAccess": ns.hasRootAccess(server),
|
||||
"requiredHacking": requiredHacking,
|
||||
"requiredPorts": requiredPorts,
|
||||
"nukeAvailable": (currentHacking >= requiredHacking && maxPortsToHack() >= requiredPorts)
|
||||
};
|
||||
}
|
||||
|
||||
/** @function runHack
|
||||
* Recursively scan, try to nuke and hack servers in the network
|
||||
* @param {string} server server to nuke and hack
|
||||
* @returns {number} exit code; if negative error, if positive hack script PID, if 0 already running
|
||||
*/
|
||||
function runHack(server) {
|
||||
let script = 'simple-hack.js';
|
||||
|
||||
let serverStatus = analyzeServer(server);
|
||||
ns.tprint(`${server}: ${JSON.stringify(serverStatus)}`);
|
||||
|
||||
if (!serverStatus.rootAccess) {
|
||||
if (serverStatus.nukeAvailable) {
|
||||
ns.tprint(`Nuking ${server}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`);
|
||||
for (let i = 0; i < maxPortsToHack(); ++i) {
|
||||
switch (EXPLOITS[i]) {
|
||||
case 'BruteSSH.exe':
|
||||
ns.brutessh(server);
|
||||
break;
|
||||
|
||||
case 'FTPCrack.exe':
|
||||
ns.ftpcrack(server);
|
||||
break;
|
||||
|
||||
case 'relaySMTP.exe':
|
||||
ns.relaysmtp(server);
|
||||
break;
|
||||
|
||||
case 'HTTPWorm.exe':
|
||||
ns.httpworm(server);
|
||||
break;
|
||||
|
||||
case 'SQLInject.exe':
|
||||
ns.sqlinject(server);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
ns.nuke(server);
|
||||
}
|
||||
}
|
||||
|
||||
serverStatus = analyzeServer(server);
|
||||
|
||||
if (serverStatus.rootAccess) {
|
||||
if (!ns.fileExists(script, 'home')) {
|
||||
ns.tprint(`Script '${script}' doesn't exist!`);
|
||||
return -3;
|
||||
}
|
||||
ns.scp(script, server, 'home');
|
||||
|
||||
let serverMaxRam = ns.getServerMaxRam(server);
|
||||
let serverUsedRam = ns.getServerUsedRam(server);
|
||||
let serverFreeRam = serverMaxRam - serverUsedRam;
|
||||
let scriptRam = ns.getScriptRam(script, server);
|
||||
let maxThreads = Math.floor(serverFreeRam / scriptRam);
|
||||
|
||||
let a = ns.scriptRunning(script, server);
|
||||
if (!a) {
|
||||
if (maxThreads == 0) {
|
||||
ns.tprint(`Not enough ram to run '${script}' on '${server}', ${scriptRam}/${serverFreeRam}!`);
|
||||
return -4;
|
||||
}
|
||||
let execExitCode = ns.exec(script, server, maxThreads, server);
|
||||
ns.tprint(`post exec ${execExitCode}`);
|
||||
if (!execExitCode) {
|
||||
ns.tprint(`Exec error running script '${script} on '${server}!`);
|
||||
return -5;
|
||||
}
|
||||
else {
|
||||
return execExitCode;
|
||||
}
|
||||
} else {
|
||||
ns.tprint(`Hack already running on ${server}`);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -6;
|
||||
}
|
||||
|
||||
let nukedServers = ['home', 'CSEC'];
|
||||
/**
|
||||
* Recursively scan, try to nuke and hack servers in the network
|
||||
* @async
|
||||
* @param {string} server server to scan
|
||||
*/
|
||||
async function scanServer(server, maxDepth = Number.MAX_SAFE_INTEGER, depth = 1) {
|
||||
if (depth <= maxDepth) {
|
||||
let availableServers = ns.scan(server);
|
||||
|
||||
// hack servers in current scan
|
||||
for (let i = 0; i < availableServers.length; ++i) {
|
||||
ns.tprint(`${availableServers[i]} ${nukedServers.indexOf(availableServers[i])} ${nukedServers}`);
|
||||
if (nukedServers.indexOf(availableServers[i]) == -1) {
|
||||
nukedServers.push(availableServers[i]);
|
||||
await scanServer(availableServers[i], maxDepth, depth + 1);
|
||||
let hackExitCode = runHack(availableServers[i]);
|
||||
|
||||
if (hackExitCode == 0) {
|
||||
ns.tprint(`Hack already running on ${availableServers[i]}`);
|
||||
} if (hackExitCode == -6) {
|
||||
ns.tprint(`No root access to ${availableServers[i]}!`);
|
||||
} else {
|
||||
if (hackExitCode < 0) {
|
||||
ns.tprint(`Hack exec ERROR on '${availableServers[i]}': ${hackExitCode}!`);
|
||||
} else {
|
||||
ns.tprint(`Hack started on '${availableServers[i]}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await ns.sleep(10);
|
||||
}
|
||||
|
||||
let runDepth = ns.args.length ? ns.args[0] : 1;
|
||||
ns.tprint(`Running scan depth: ${runDepth}`);
|
||||
await scanServer('home', );
|
||||
|
||||
|
||||
// let serversToNuke = {};
|
||||
// let availableServers = { "home": "home" };
|
||||
|
||||
// for (let depth = 0; depth < 2; ++depth) {
|
||||
// for (const key in availableServers) {
|
||||
// if (Object.hasOwnProperty.call(availableServers, key)) {
|
||||
// const element = availableServers[key];
|
||||
|
||||
// ns.scan(element).forEach(elem => {
|
||||
// availableServers[elem] = elem;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// ns.tprint(availableServers);
|
||||
|
||||
// for (const element in availableServers) {
|
||||
// ns.tprint(`start loop ${element}`);
|
||||
|
||||
// if (element != 'home' && element != 'CSEC') {
|
||||
// let hackExitCode = runHack(element);
|
||||
|
||||
// if (hackExitCode == 0) {
|
||||
// ns.tprint(`Hack already running on ${element}`);
|
||||
// } if (hackExitCode == -6) {
|
||||
// ns.tprint(`No root access to ${element}`);
|
||||
// } else {
|
||||
// if (hackExitCode < 0) {
|
||||
// ns.tprint(`Hack exec ERROR on '${element}': ${hackExitCode}!`);
|
||||
// } else {
|
||||
// ns.tprint(`Hack started on '${element}'`);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
await ns.sleep(10);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
let costThreshold = ns.args.length > 0 ? ns.args[0] : 1;
|
||||
let upgradeCount = ns.args.length > 1 ? ns.args[1] : 1;
|
||||
|
||||
await ns.sleep(10000);
|
||||
|
||||
while (true) {
|
||||
let currentMoney = ns.getServerMoneyAvailable("home");
|
||||
let nodePurchaseCost = ns.hacknet.getPurchaseNodeCost();
|
||||
let nodeCount = ns.hacknet.numNodes();
|
||||
|
||||
if (nodePurchaseCost / Math.abs(currentMoney) < costThreshold) {
|
||||
ns.hacknet.purchaseNode();
|
||||
currentMoney = ns.getServerMoneyAvailable("home");
|
||||
++nodeCount;
|
||||
}
|
||||
|
||||
for (let index = 0; index < nodeCount; ++index) {
|
||||
if (ns.hacknet.getLevelUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < costThreshold) {
|
||||
ns.hacknet.upgradeLevel(index, upgradeCount);
|
||||
currentMoney = ns.getServerMoneyAvailable("home");
|
||||
}
|
||||
if (ns.hacknet.getRamUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < costThreshold) {
|
||||
ns.hacknet.upgradeRam(index, upgradeCount);
|
||||
currentMoney = ns.getServerMoneyAvailable("home");
|
||||
}
|
||||
if (ns.hacknet.getCoreUpgradeCost(index, upgradeCount) / Math.abs(currentMoney) < costThreshold) {
|
||||
ns.hacknet.upgradeCore(index, upgradeCount);
|
||||
currentMoney = ns.getServerMoneyAvailable("home");
|
||||
}
|
||||
}
|
||||
|
||||
await ns.sleep(10);
|
||||
}
|
||||
}
|
||||
Vendored
+7397
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
|
||||
let nukedServers = ['home', 'CSEC'];
|
||||
/**
|
||||
* Recursively kill simple-hack.js running on servers in the network
|
||||
* @async
|
||||
* @param {string} server server to scan
|
||||
*/
|
||||
async function scanServer(server, maxDepth = Number.MAX_SAFE_INTEGER, depth = 1) {
|
||||
if (depth <= maxDepth) {
|
||||
let availableServers = ns.scan(server);
|
||||
|
||||
// hack servers in current scan
|
||||
for (let i = 0; i < availableServers.length; ++i) {
|
||||
if (nukedServers.indexOf(availableServers[i]) == -1) {
|
||||
nukedServers.push(availableServers[i]);
|
||||
await scanServer(availableServers[i], maxDepth, depth + 1);
|
||||
ns.scriptKill('simple-hack.js', availableServers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
await ns.sleep(10);
|
||||
}
|
||||
|
||||
let runDepth = ns.args.length ? ns.args[0] : 1;
|
||||
ns.tprint(`Running scan depth: ${runDepth}`);
|
||||
await scanServer('home',);
|
||||
|
||||
|
||||
await ns.sleep(10);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
ns.scriptKill('hacknet-bot.js', 'home');
|
||||
await ns.sleep(10);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
let host = ns.args[0];
|
||||
let remote = ns.args[1];
|
||||
let script = 'simple-hack.js';
|
||||
|
||||
if (!ns.serverExists(host)) {
|
||||
ns.print(`Host '${host}'' doesn't exist!`);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!ns.serverExists(remote)) {
|
||||
ns.print(`Remote '${remote}'' doesn't exist!`);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!ns.fileExists(script, host)) {
|
||||
if (!ns.fileExists(script, 'home')) {
|
||||
ns.print(`Script '${script}' doesn't exist!`);
|
||||
return 3;
|
||||
}
|
||||
|
||||
ns.scp(script, host, 'home');
|
||||
}
|
||||
|
||||
let serverMaxRam = ns.getServerMaxRam(host);
|
||||
let serverUsedRam = ns.getServerUsedRam(host);
|
||||
let serverFreeRam = serverMaxRam - serverUsedRam;
|
||||
let scriptRam = ns.getScriptRam(script, host);
|
||||
let maxThreads = Math.floor(serverFreeRam / scriptRam);
|
||||
if(maxThreads == 0)
|
||||
{
|
||||
ns.print(`Not enough ram to run '${script}', ${scriptRam}/${serverFreeRam}!`)
|
||||
}
|
||||
|
||||
ns.scriptKill(script, host);
|
||||
|
||||
if (!ns.exec(script, host, maxThreads, remote)) {
|
||||
ns.tprint(`Exec error running script '${script} on '${host}!`);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
// ns.disableLog('ALL');
|
||||
|
||||
let server = ns.args[0];
|
||||
let maxMoney = ns.getServerMaxMoney(server);
|
||||
let minSecurity = ns.getServerMinSecurityLevel(server);
|
||||
let loop = 0;
|
||||
|
||||
while (true) {
|
||||
let currentMoney = ns.getServerMoneyAvailable(server);
|
||||
let currentSecurity = ns.getServerSecurityLevel(server);
|
||||
ns.print(`Money: ${currentMoney} / ${maxMoney}`);
|
||||
ns.print(`Security: ${currentSecurity} / ${minSecurity}`);
|
||||
|
||||
let newMoney = 'N/A';
|
||||
if (currentMoney < 0.95 * maxMoney) {
|
||||
newMoney = await ns.grow(server);
|
||||
}
|
||||
|
||||
let newSecurity = 'N/A';
|
||||
if (currentSecurity > 2 * minSecurity) {
|
||||
newSecurity = await ns.weaken(server);
|
||||
}
|
||||
|
||||
let hackedMoney = 0;
|
||||
if (currentMoney > 0.4 * maxMoney) {
|
||||
hackedMoney = await ns.hack(server);
|
||||
}
|
||||
|
||||
ns.tprint(`{${server}: {loop: ${++loop}, hack: ${Math.floor(hackedMoney)}, money: ${Math.floor(currentMoney)} / ${Math.floor(maxMoney)} = ${((currentMoney / maxMoney) * 100).toFixed(2)}, security: ${currentSecurity.toFixed(2)} / ${Math.floor(minSecurity) } = ${((currentSecurity / minSecurity) * 100).toFixed(4)}}}`);
|
||||
await ns.sleep(10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user