-
Notifications
You must be signed in to change notification settings - Fork 0
/
autohack1.js
77 lines (69 loc) · 1.87 KB
/
autohack1.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
72
73
74
75
76
77
var _list = [];
var _scriptName = "early-hack-template.js";
var _scriptSize = 2.6;
var _ownerServersPattern = "pc-";
/** @param {NS} ns **/
export async function main(ns) {
GetAllServersAsList(ns, "home");
for (let i = 0; i < _list.length; i++) {
let host = _list[i];
Hack(ns, host);
await InstallScript(ns, host);
}
// ns.tprintf("ServerList:" + _list);
ns.tprintf("===>END<===");
}
async function InstallScript(ns, host) {
try {
if (!ns.hasRootAccess(host)) {
ns.tprintf("WARN Could not install service. Host " + host + " NOT hacked");
return;
}
await ns.scp(_scriptName, host);
let maxRAM = ns.getServerMaxRam(host);
let usedRAM = ns.getServerUsedRam(host);
let countThreads = (maxRAM - usedRAM) / _scriptSize | 0;
if (countThreads > 0) {
// RUN SCRIPT
ns.exec(_scriptName, host, countThreads, host);
// ==============
ns.tprint("INFO " + host + " threads " + countThreads + " ====>Installed Service<====");
}
}
catch (e) {
ns.tprintf("ERROR Could not install Service on host " + host + ". Error:" + e);
}
}
function Hack(ns, host) {
try {
if (ns.hasRootAccess(host)) {
ns.tprintf("WARN Host " + host + " already hacked");
return;
}
if (ns.fileExists("BruteSSH.exe", "home")) {
ns.brutessh(host);
}
if (ns.fileExists("FTPCrack.exe", "home")) {
ns.ftpcrack(host);
}
if (ns.fileExists("relaySMTP.exe", "home")) {
ns.relaysmtp(host);
}
ns.nuke(host);
ns.tprintf("INFO ===> Host " + host + " hacked<===");
}
catch (e) {
ns.tprintf("ERROR Could not hacked " + host + ". Error:" + e);
}
}
function GetAllServersAsList(ns, targetHost) {
// ns.tprintf("GetAllServersAsList - " + targetHost);
let res = ns.scan(targetHost);
for (let i = 0; i < res.length; i++) {
let host = res[i];
if (_list.includes(host) || host.includes(_ownerServersPattern))
continue;
_list.push(host);
GetAllServersAsList(ns, host);
}
}