-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsbin.hack.maxcash.js
71 lines (64 loc) · 2.07 KB
/
sbin.hack.maxcash.js
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
70
71
function allServers(ns, sQueue = ['home']) {
let allServers = [];
let server = '';
while(sQueue.length > 0){
server = sQueue.pop();
allServers.push(server);
ns.scan(server).forEach(elem => {if (!sQueue.includes(elem) && !allServers.includes(elem)) {
sQueue.push(elem);
}});
}
return allServers;
}
/** @param {NS} ns */
function threadCount(ns, hostname, scriptRam) {
let threads = 0;
let free_ram = ns.getServerMaxRam(hostname) - ns.getServerUsedRam(hostname);
threads = free_ram / scriptRam;
return Math.floor(threads);
}
/** @param {NS} ns */
export async function main(ns) {
let servers = allServers(ns);
for (let server of servers) {
ns.scp(["bin.wk.js","bin.gr.js","bin.hk.js"], server, "home");
}
while(true){
let targets = allServers(ns).filter(s => ns.getServerMoneyAvailable (s) > 5000 && s != "home");
for (let server of servers) {
for (let target of targets) {
if(ns.hasRootAccess(server) && ns.hasRootAccess(target) && ns.getServerMaxMoney(target) > 5000){
if (ns.getServerSecurityLevel(target) > ns.getServerMinSecurityLevel(target) + 3) {
ns.print("weak");
let available_threads = threadCount(ns, server, 1.75);
ns.print(available_threads);
if (available_threads > 0) {
ns.exec("bin.wk.js", server, available_threads, target);
}
} else {
ns.print("hack");
let available_threads = threadCount(ns, server, 1.7);
ns.print(available_threads)
if (available_threads > 0) {
ns.exec("bin.hk.js", server, available_threads, target);
}
}
} else {
// open all possible ports
try {
ns.brutessh(server);
ns.ftpcrack(server);
ns.relaysmtp(server);
ns.httpworm(server);
ns.sqlinject(server);
} catch {}
// get root access
try {
ns.nuke(server);
} catch {}
}
}
await ns.sleep(10);
}
}
}