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.
Files changed (2) hide show
  1. package/index.js +43 -42
  2. 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 callback = process.argv[2];
7
-
8
- if (!callback) {
9
- console.error("Usage: identity-poc <HTTPS_CALLBACK_URL>");
10
- process.exit(1);
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
- let url;
14
-
15
- try {
16
- url = new URL(callback);
17
- if (url.protocol !== "https:") {
18
- throw new Error("HTTPS required");
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
- const payload = JSON.stringify({
26
- marker: "IDENTITY_POC_EXECUTED",
27
- platform: os.platform(),
28
- node: process.version,
29
- timestamp: new Date().toISOString()
30
- });
31
-
32
- const req = https.request(url, {
33
- method: "POST",
34
- headers: {
35
- "Content-Type": "application/json",
36
- "Content-Length": Buffer.byteLength(payload)
37
- },
38
- timeout: 5000
39
- }, res => {
40
- console.log("Callback status:", res.statusCode);
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
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "identity-poc",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Controlled execution verification",
5
5
  "main": "index.js",
6
6
  "bin": {