-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadToNew.js
More file actions
69 lines (64 loc) · 2.31 KB
/
Copy pathuploadToNew.js
File metadata and controls
69 lines (64 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/** @param {NS} ns */
export function scan(ns) {
ns.disableLog("scan");
function subscan(ns, parent, server, list) {
const children = ns.scan(server);
for (let child of children) {
if (parent == child) {
continue;
}
list.push(child);
subscan(ns, server, child, list);
}
}
const l = [];
subscan(ns, '', 'home', l);
return l;
}
export function hasTools(ns, ports) {
const toolsList = ['BruteSSH.exe', 'FTPCrack.exe', 'RelaySMTP.exe', 'HTTPWorm.exe', 'SQLInject.exe'];
let haveTools = 0;
toolsList.forEach(t => {
if (ns.fileExists(t)) {
haveTools++;
}
});
return ports <= haveTools;
}
/** @param {NS} ns */
export async function unlockAndExecute(ns, hostname, serverToHack) {
const unlockScriptName = 'unlock.js';
const scriptToExecute = 'autohack.js';
const autohackMemCost = ns.getScriptRam(scriptToExecute);
ns.tprintf("Unlocking hostanme: %s", hostname);
ns.exec(unlockScriptName, 'home', 1, hostname);
while (!ns.hasRootAccess(hostname)) {
await ns.sleep(1000);
}
var freeRam = ns.getServerMaxRam(hostname) - ns.getServerUsedRam(hostname);
var threadCount = Math.floor(freeRam / autohackMemCost);
ns.tprintf("%s thread count: %d", scriptToExecute, threadCount);
while (!ns.hasRootAccess(hostname)) {
await ns.sleep(1000);
}
if (threadCount > 0) {
ns.scp(scriptToExecute, hostname);
ns.exec(scriptToExecute, hostname, threadCount, serverToHack);
}
}
/** @param {NS} ns */
export async function main(ns) {
var target = ns.args[0]
var servers = [];
scan(ns).forEach(s => servers.push(ns.getServer(s)));
servers = servers.filter(s => !s.hasAdminRights && s.requiredHackingSkill <= ns.getHackingLevel() && hasTools(ns, s.numOpenPortsRequired));
//servers = servers.filter(s => s.hasAdminRights && s.ramUsed == 0);
await unlockAndExecute(ns, target, target); // Make sure to hack target first
ns.tprint(`Server found after filter: ${servers.length}`)
for (const s of servers) {
await unlockAndExecute(ns, s.hostname, target);
};
}
export function autocomplete(data, args) {
return data.servers;
}