-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathif.server.hackable.js
70 lines (61 loc) · 2.07 KB
/
if.server.hackable.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
import BaseServer from "./if.server"
export default class HackableBaseServer extends BaseServer {
/** @param {NS} ns */
constructor(ns, hostname) {
super();
this.ns = ns;
this._id = hostname
}
get isTarget() { return (!this.purchased && !this.isHome && (this.money.max > 0) && (this.ports.open >= this.ports.required) && this.admin && (this.level <= this.ns.getHackingLevel()))}
get isAttacker() { return ( this.purchased || this.isHome || (this.ram.max > 0 && this.admin))}
get pids() { return this.ns.ps(this.id) }
get targeting_pids() {
const dpList = (ns, current="home", set=new Set()) => {
let connections = ns.scan(current);
let next = connections.filter(c => !set.has(c));
next.forEach(n => {
set.add(n);
return dpList(ns, n, set);
});
return Array.from(set.keys());
};
let pids = [];
for (let server of dpList(this.ns)) {
const ps = this.ns.ps(server);
for (let process of ps) {
if (process.args.length > 0) {
if (process.args[0] === this.id) {
pids.push(process);
}
}
}
}
return pids;
}
sudo = () => {
try {
this.ns.brutessh(this.id)
this.ns.ftpcrack(this.id)
this.ns.relaysmtp(this.id)
this.ns.httpworm(this.id)
this.ns.sqlinject(this.id)
} catch {}
try {
this.ns.nuke(this.id)
} catch {}
}
async updateCache(repeat=true, kv=new Map()) {
do {
let getters = this.listGetters(this)
for (let o of Object.keys(getters)) {
if (!kv.has(getters[o])) {
kv.set(getters[o], this[getters[o]])
}
}
await super.updateCache(false, kv)
if (repeat) {
await this.ns.asleep((Math.random() * 10000) + 55000); // base server update rate is 60s. we'll call faster updates when we need them.
}
} while (repeat)
}
}