summaryrefslogtreecommitdiff
path: root/bitburnerFiles1026/milestones.js
blob: 856900aa325b9dfae41d17bd9e114eed22e5ecf0 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const HOME = "home";

// You have to run this script once per target

let hacked = [];

/** @param {NS} ns */
export async function main(ns) {
	
	ns.tail();
	ns.moveTail(1650, 725);
	ns.resizeTail(250, 100);

	ns.disableLog("disableLog");
	ns.disableLog("clearLog");
	ns.disableLog("sleep");
	ns.disableLog("scan");
	ns.clearLog();
	
	const targets = [
		"CSEC",
		"avmnite-02h",
		"I.I.I.I",
		"run4theh111z"//,
		// "w0r1d_d43m0n"
	];

	while (!ns.fileExists("SQLInject.exe")) {
		await ns.sleep(12000);
	}
	for (let i = 0; i < targets.length; i++) {
		if (targets[i] == "w0rld_d43m0n") {
			while (!ns.singularity.getOwnedAugmentations().includes("The Red Pill")) {
				ns.clearLog();
				ns.print("Waiting for red pill");
				await ns.sleep(60000);
			}
		}
		await root(ns, targets[i]);
	}
}
function buildRoute(ns, parent, target, route, seen = []) {
    //first time we run we need to add the parent to the list of servers we've seen
    if (!seen.includes(parent)) {
        seen.push(parent);
	}
    //add to route
    route.push(parent);
    const children = ns.scan(parent);
    for (const child of children) {
        if (seen.includes(child)) {
            //already checked
            continue;
        }
        seen.push(child);
        if (child == target) {
            //found target, add it to the route and finish recursion
            route.push(child);
            return true;
        }
        if (buildRoute(ns, child, target, route, seen)) {
            //target found, finish recursion
            return true;
        }
        else {
            //target not found in this branch, remove from route
            route.pop();
        }
    }
    //didn't find target in this route, reset route
    route = [];
    return false;
}
async function printRoute(ns, route) {
    let result = [];
    for (const node of route) {
        result.push(node);
    }
    return result;
}
async function root(ns, target) {
	if (!ns.hasRootAccess(target)) {
		ns.brutessh(target);
		ns.ftpcrack(target);
		ns.relaysmtp(target);
		ns.httpworm(target);
		ns.sqlinject(target);
		ns.print("Gained root access to ", target);
		while (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(target)) {
			await ns.sleep(6000);
		}
		ns.nuke(target);

		ns.singularity.connect(HOME);
		await ns.sleep(100);

		let result = [];
		let route = [];

		buildRoute(ns, HOME, target, route)
		result = await printRoute(ns, route);

		for (let n = 0; n < result.length; n++) {
			ns.singularity.connect(result[n]);
			await ns.sleep(100);
		}
		await ns.singularity.installBackdoor();
		ns.singularity.connect(HOME);
	} else if (!ns.getServer(target).backdoorInstalled) {
		ns.singularity.connect(HOME);
		await ns.sleep(100);

		let result = [];
		let route = [];
		
		buildRoute(ns, HOME, target, route)
		result = await printRoute(ns, route);
		
		for (let n = 0; n < result.length; n++) {
			ns.singularity.connect(result[n]);
			await ns.sleep(100);
		}
		await ns.singularity.installBackdoor();
		ns.singularity.connect(HOME);
	}
	hacked.push(target);
	ns.clearLog();
	ns.print("Hacked servers: ", )
	for (let j = 0; j < hacked.length; j++) {
		ns.print(hacked[j]);
	}
	return 0;
}