-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworm.js
More file actions
52 lines (47 loc) · 1.39 KB
/
worm.js
File metadata and controls
52 lines (47 loc) · 1.39 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
/** @param {NS} ns **/
export async function main(ns) {
var queue = ['home'];
var visited = [];
var rooted = []
while (queue.length) {
var now = queue.shift()
if (!visited.includes(now)) {
visited.push(now)
}
for (const server of ns.scan(now)) {
if (!visited.includes(server)) {
queue.push(server)
}
}
}
var toollist = ['BruteSSH.exe', 'FTPCrack.exe', 'relaySMTP.exe', 'HTTPWorm.exe', 'SQLInject.exe']
var toolCount = 0;
for (const tool of toollist) {
if (ns.fileExists(tool, 'home')) {
toolCount++;
}
}
function attack(server) {
if (!ns.hasRootAccess(server)) {
if (ns.getServerNumPortsRequired(server) <= toolCount) {
ns.toast("nuking " + server);
try {
ns.brutessh(server);
ns.ftpcrack(server);
ns.relaysmtp(server);
ns.httpworm(server);
ns.sqlinject(server);
} catch (e) {}
ns.nuke(server);
}
}
if (ns.hasRootAccess(server)) {
rooted.push(server);
}
}
visited.splice(visited.indexOf('home'), 1);
for (const server of visited) {
attack(server);
}
await ns.write('rooted.txt', rooted, 'w');
}