@yagyeshvyas/vibeguard 1.3.0 → 1.11.1
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/.vibeguard-mcp.example.json +51 -0
- package/CHANGELOG.md +604 -216
- package/MCP-FIREWALL.md +296 -0
- package/README.md +355 -31
- package/bin/cli.js +355 -27
- package/bin/cmd-agent-monitor.js +45 -0
- package/bin/cmd-agent-risk.js +64 -0
- package/bin/cmd-gif.js +62 -0
- package/bin/cmd-git-scan.js +74 -0
- package/bin/cmd-llm-proxy.js +164 -0
- package/bin/cmd-mcp-firewall.js +191 -0
- package/bin/cmd-pentest.js +103 -0
- package/bin/cmd-platform.js +137 -0
- package/bin/cmd-pr-scan.js +135 -0
- package/bin/cmd-sbom-diff.js +38 -0
- package/bin/cmd-skill-scan.js +35 -0
- package/docs/AISVS.md +25 -0
- package/docs/ARCHITECTURE.md +81 -0
- package/docs/INSTALLATION.md +139 -0
- package/docs/WINDOWS.md +74 -0
- package/docs/security-policy.strict.example.json +134 -0
- package/docs/security-policy.strict.example.pub.pem +3 -0
- package/package.json +45 -7
- package/src/.vibeguard/cache/file-hashes.json +60 -0
- package/src/.vibeguard/latest-snapshot.json +36 -0
- package/src/.vibeguard/mcp-pins.json +1 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +2051 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +37 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +279 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +151 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +65 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +2054 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +150 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +164 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +144 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +299 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +37 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +168 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +362 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +220 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +428 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +344 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +297 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +33 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +2055 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +1611 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +292 -0
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +220 -0
- package/src/.vibeguard-baseline.json +5226 -0
- package/src/action-guard.js +84 -6
- package/src/agent-monitor.js +262 -0
- package/src/agent-policy.js +642 -0
- package/src/agent-risk.js +271 -0
- package/src/agentic.js +1513 -0
- package/src/ast.js +165 -7
- package/src/audit-trail.js +212 -67
- package/src/auto.js +427 -427
- package/src/autofix.js +11 -4
- package/src/bundles.js +198 -0
- package/src/daemon.js +343 -343
- package/src/dashboard.js +278 -278
- package/src/engine.js +3 -0
- package/src/entropy.js +187 -0
- package/src/firewall.js +19 -3
- package/src/gif.js +134 -0
- package/src/gitscan.js +282 -0
- package/src/hook.js +151 -151
- package/src/injection-decode.js +136 -0
- package/src/install.js +298 -280
- package/src/integrity.js +16 -1
- package/src/integrity.json +43 -13
- package/src/interceptor.js +12 -9
- package/src/llm-proxy.js +986 -0
- package/src/mcp-audit.js +61 -5
- package/src/mcp-firewall.js +971 -0
- package/src/mcp-server.js +2500 -2047
- package/src/obfuscation.js +315 -0
- package/src/owasp-agentic.js +314 -0
- package/src/pentest.js +589 -0
- package/src/pii.js +4 -0
- package/src/platform/aisvs.js +38 -0
- package/src/platform/approval.js +187 -0
- package/src/platform/canonical.js +73 -0
- package/src/platform/contracts.js +158 -0
- package/src/platform/delegation.js +73 -0
- package/src/platform/http-gateway.js +177 -0
- package/src/platform/identity.js +253 -0
- package/src/platform/jwt.js +86 -0
- package/src/platform/mcp-http-bridge.js +199 -0
- package/src/platform/memory-guard.js +64 -0
- package/src/platform/os-sandbox.js +144 -0
- package/src/platform/policy.js +332 -0
- package/src/platform/sandbox-manager.js +92 -0
- package/src/platform/signed-audit.js +357 -0
- package/src/platform/ssrf.js +129 -0
- package/src/plugin.js +182 -168
- package/src/pre-deploy.js +170 -55
- package/src/privacy-audit.js +272 -272
- package/src/repl.js +150 -150
- package/src/report.js +7 -1
- package/src/routes.js +1210 -0
- package/src/rules-2026.js +1407 -0
- package/src/rules-pack.js +3068 -3019
- package/src/rules.js +376 -60
- package/src/sandbox.js +200 -10
- package/src/sbom.js +193 -164
- package/src/scanner.js +189 -33
- package/src/shell-guard.js +11 -0
- package/src/skill-scan.js +477 -0
- package/src/slopsquat.js +144 -144
- package/src/surface.js +408 -0
- package/src/taint-ast.js +204 -37
- package/src/taint.js +15 -3
- package/src/tokenlean.js +579 -0
- package/src/trace.js +220 -220
package/src/pentest.js
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard Active Pentest — `vibeguard pentest <url>`
|
|
5
|
+
*
|
|
6
|
+
* An active web/API security probe suite (Strix.ai-class "autonomous
|
|
7
|
+
* pentesting", 100% local, zero dependencies, deterministic).
|
|
8
|
+
*
|
|
9
|
+
* Every finding ships with: severity, CWE, evidence (status/headers/excerpt)
|
|
10
|
+
* and a copy-paste curl REPRODUCTION command — the "proof" that commercial
|
|
11
|
+
* platforms charge for, generated deterministically.
|
|
12
|
+
*
|
|
13
|
+
* Includes an out-of-band SSRF proof mode (--verify-ssrf): a local callback
|
|
14
|
+
* listener + URL-param fuzzing. If the target fetches the listener URL, that
|
|
15
|
+
* is proof-of-exploit for SSRF — no third-party service needed.
|
|
16
|
+
*
|
|
17
|
+
* SAFETY: test only systems you own or are authorized to test. All probes are
|
|
18
|
+
* read-only / non-destructive (no writes, no brute force, no exploit
|
|
19
|
+
* delivery). The SSRF callback uses a loopback listener on this machine.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const http = require('http');
|
|
23
|
+
const https = require('https');
|
|
24
|
+
const zlib = require('zlib');
|
|
25
|
+
const { URL } = require('url');
|
|
26
|
+
|
|
27
|
+
const DEFAULT_TIMEOUT = 10000;
|
|
28
|
+
const MAX_RESPONSE_BYTES = 512 * 1024;
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// HTTP probe helper (zero deps)
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
function httpReq(method, urlStr, opts = {}) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
let url;
|
|
37
|
+
try {
|
|
38
|
+
url = new URL(urlStr);
|
|
39
|
+
} catch {
|
|
40
|
+
return resolve({ error: 'invalid-url', status: 0, headers: {}, body: '', finalUrl: urlStr });
|
|
41
|
+
}
|
|
42
|
+
const mod = url.protocol === 'https:' ? https : http;
|
|
43
|
+
const reqOpts = {
|
|
44
|
+
method: method || 'GET',
|
|
45
|
+
hostname: url.hostname,
|
|
46
|
+
port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
|
47
|
+
path: url.pathname + url.search,
|
|
48
|
+
headers: Object.assign({ 'User-Agent': 'vibeguard-pentest/1.0', Accept: '*/*' }, opts.headers || {}),
|
|
49
|
+
timeout: opts.timeout || DEFAULT_TIMEOUT,
|
|
50
|
+
rejectUnauthorized: false, // TLS checks are done separately; probe anyway
|
|
51
|
+
agent: false,
|
|
52
|
+
};
|
|
53
|
+
const req = mod.request(reqOpts, (res) => {
|
|
54
|
+
const chunks = [];
|
|
55
|
+
let size = 0;
|
|
56
|
+
res.on('data', (c) => {
|
|
57
|
+
size += c.length;
|
|
58
|
+
if (size <= MAX_RESPONSE_BYTES) chunks.push(c);
|
|
59
|
+
});
|
|
60
|
+
res.on('end', () => {
|
|
61
|
+
let body = Buffer.concat(chunks).toString('utf8');
|
|
62
|
+
const enc = (res.headers['content-encoding'] || '').toLowerCase();
|
|
63
|
+
if (enc === 'gzip') {
|
|
64
|
+
try { body = zlib.gunzipSync(Buffer.concat(chunks)).toString('utf8'); } catch { /* keep raw */ }
|
|
65
|
+
} else if (enc === 'deflate') {
|
|
66
|
+
try { body = zlib.inflateSync(Buffer.concat(chunks)).toString('utf8'); } catch { /* keep raw */ }
|
|
67
|
+
} else if (enc === 'br') {
|
|
68
|
+
try { body = zlib.brotliDecompressSync(Buffer.concat(chunks)).toString('utf8'); } catch { /* keep raw */ }
|
|
69
|
+
}
|
|
70
|
+
resolve({
|
|
71
|
+
status: res.statusCode || 0,
|
|
72
|
+
headers: res.headers,
|
|
73
|
+
body,
|
|
74
|
+
finalUrl: urlStr,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
req.on('timeout', () => { req.destroy(); resolve({ error: 'timeout', status: 0, headers: {}, body: '', finalUrl: urlStr }); });
|
|
79
|
+
req.on('error', (e) => resolve({ error: String((e && e.code) || e.message || 'network'), status: 0, headers: {}, body: '', finalUrl: urlStr }));
|
|
80
|
+
if (opts.body) req.write(opts.body);
|
|
81
|
+
req.end();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Follow redirects manually (bounded) unless noRedirect (open-redirect check).
|
|
86
|
+
async function probe(method, urlStr, opts = {}) {
|
|
87
|
+
let cur = urlStr;
|
|
88
|
+
const maxFollow = opts.maxFollow === undefined ? 3 : opts.maxFollow;
|
|
89
|
+
let last = null;
|
|
90
|
+
for (let i = 0; i <= maxFollow; i++) {
|
|
91
|
+
last = await httpReq(method, cur, { headers: opts.headers, body: opts.body, timeout: opts.timeout });
|
|
92
|
+
if (opts.noRedirect) return last;
|
|
93
|
+
const loc = last.headers && last.headers.location;
|
|
94
|
+
if (last.status >= 300 && last.status < 400 && loc) {
|
|
95
|
+
try { cur = new URL(loc, cur).toString(); } catch { return last; }
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
return last;
|
|
99
|
+
}
|
|
100
|
+
return last;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function curlCommand(method, urlStr, headers = {}, body) {
|
|
104
|
+
const parts = [`curl -s -i -X ${method || 'GET'}`, `'${urlStr}'`];
|
|
105
|
+
for (const [k, v] of Object.entries(headers || {})) parts.push(`-H '${k}: ${v}'`);
|
|
106
|
+
if (body) parts.push(`-d '${body}'`);
|
|
107
|
+
return parts.join(' ');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// SSRF out-of-band listener
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
function startCallbackListener() {
|
|
115
|
+
return new Promise((resolve) => {
|
|
116
|
+
const hits = [];
|
|
117
|
+
const server = http.createServer((req, res) => {
|
|
118
|
+
hits.push({ url: req.url, time: new Date().toISOString(), headers: req.headers });
|
|
119
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
120
|
+
res.end('vibeguard-ssrf-callback');
|
|
121
|
+
});
|
|
122
|
+
server.listen(0, '127.0.0.1', () => {
|
|
123
|
+
const port = server.address().port;
|
|
124
|
+
resolve({
|
|
125
|
+
port,
|
|
126
|
+
url: `http://127.0.0.1:${port}`,
|
|
127
|
+
hits,
|
|
128
|
+
close: () => new Promise((r) => server.close(r)),
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Check helpers
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
function finding(id, title, severity, cwe, detail, evidence, reproduction) {
|
|
139
|
+
return { id, title, severity, cwe, detail, evidence, reproduction };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const COMMON_SSRF_PARAMS = [
|
|
143
|
+
'url', 'uri', 'path', 'dest', 'destination', 'redirect', 'redirect_uri', 'next', 'return',
|
|
144
|
+
'return_to', 'file', 'image', 'img', 'load', 'fetch', 'src', 'data', 'domain', 'host',
|
|
145
|
+
'proxy', 'target', 'endpoint', 'webhook', 'callback', 'link', 'ref', 'page', 'download',
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
const EXPOSED_PATHS = [
|
|
149
|
+
{ path: '/.env', sig: /(?:^|\n)\s*[A-Z][A-Z0-9_]{2,}\s*=/ },
|
|
150
|
+
{ path: '/.git/config', sig: /\[core\]/ },
|
|
151
|
+
{ path: '/.git/HEAD', sig: /ref:\s*refs\/heads\// },
|
|
152
|
+
{ path: '/.gitignore', sig: /node_modules|\.env|dist|build/i },
|
|
153
|
+
{ path: '/.svn/entries', sig: /^\d+|dir/ },
|
|
154
|
+
{ path: '/.DS_Store', sig: /Bud1/ },
|
|
155
|
+
{ path: '/backup.zip', sig: /PK\x03\x04/ },
|
|
156
|
+
{ path: '/backup.tar.gz', sig: /\x1f\x8b/ },
|
|
157
|
+
{ path: '/app.zip', sig: /PK\x03\x04/ },
|
|
158
|
+
{ path: '/dump.sql', sig: /CREATE TABLE|INSERT INTO/i },
|
|
159
|
+
{ path: '/db.sql', sig: /CREATE TABLE|INSERT INTO/i },
|
|
160
|
+
{ path: '/config.php.bak', sig: /<\?php|\$[a-z_]+=/i },
|
|
161
|
+
{ path: '/server-status', sig: /Apache Server Status/i },
|
|
162
|
+
{ path: '/swagger.json', sig: /"swagger"\s*:\s*["']?2|"openapi"\s*:/i },
|
|
163
|
+
{ path: '/swagger-ui.html', sig: /swagger/i },
|
|
164
|
+
{ path: '/openapi.json', sig: /"openapi"\s*:|"swagger"\s*:/i },
|
|
165
|
+
{ path: '/api-docs', sig: /"openapi"\s*:|"swagger"\s*:/i },
|
|
166
|
+
{ path: '/actuator', sig: /"status"\s*:\s*"UP"|_links/i },
|
|
167
|
+
{ path: '/actuator/env', sig: /"propertySources"|"systemEnvironment"/i },
|
|
168
|
+
{ path: '/actuator/health', sig: /"status"\s*:\s*"UP"/i },
|
|
169
|
+
{ path: '/graphql', sig: /__schema|"data"/i },
|
|
170
|
+
{ path: '/phpinfo.php', sig: /phpinfo\(\)/i },
|
|
171
|
+
{ path: '/info.php', sig: /phpinfo\(\)/i },
|
|
172
|
+
{ path: '/wp-config.php.bak', sig: /DB_PASSWORD|WP_/i },
|
|
173
|
+
{ path: '/robots.txt', sig: /User-agent:/i },
|
|
174
|
+
{ path: '/sitemap.xml', sig: /<urlset|<sitemapindex/i },
|
|
175
|
+
{ path: '/debug', sig: /debug|trace|dump/i },
|
|
176
|
+
{ path: '/console', sig: /console|terminal/i },
|
|
177
|
+
{ path: '/health', sig: /"status"\s*:\s*"(UP|OK|healthy)"/i },
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const GRAPHQL_PATHS = ['/graphql', '/api/graphql', '/graphiql', '/v1/graphql', '/query'];
|
|
181
|
+
const GRAPHQL_INTROSPECTION = JSON.stringify({
|
|
182
|
+
query: '{ __schema { types { name } } }',
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
// Main runner
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Run the active probe suite against one target.
|
|
191
|
+
* @param {string} target base URL (http://host[:port][/base])
|
|
192
|
+
* @param {object} [opts]
|
|
193
|
+
* - timeout per-request timeout ms (default 10000)
|
|
194
|
+
* - verifySsrf spin the OOB listener + fuzz URL params (default false)
|
|
195
|
+
* - token a JWT to test alg:none acceptance against
|
|
196
|
+
* - tokenHeader header the token goes in (default Authorization: Bearer)
|
|
197
|
+
* - fuzz allow active fuzz probes (traversal/injection) (default false)
|
|
198
|
+
* - maxRedirects redirect follow limit
|
|
199
|
+
* @returns {Promise<{findings: Array, stats: object}>}
|
|
200
|
+
*/
|
|
201
|
+
async function runPentest(target, opts = {}) {
|
|
202
|
+
const findings = [];
|
|
203
|
+
const stats = { checks: 0, requests: 0, durationMs: 0, callbackHits: 0 };
|
|
204
|
+
const t0 = Date.now();
|
|
205
|
+
const timeout = opts.timeout || DEFAULT_TIMEOUT;
|
|
206
|
+
|
|
207
|
+
let base = String(target).trim();
|
|
208
|
+
if (!/^https?:\/\//i.test(base)) base = 'http://' + base;
|
|
209
|
+
try {
|
|
210
|
+
base = new URL(base).toString().replace(/\/$/, '');
|
|
211
|
+
} catch {
|
|
212
|
+
return { findings: [finding('web.invalid-target', 'Invalid target URL', 'high', 'CWE-20', `Cannot parse target: ${target}`, '', '')], stats };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const log = (f) => { findings.push(f); stats.checks++; };
|
|
216
|
+
const reqCount = () => stats.requests++;
|
|
217
|
+
|
|
218
|
+
const P = (method, path, o = {}) => {
|
|
219
|
+
reqCount();
|
|
220
|
+
return probe(method, base + path, Object.assign({ timeout }, o));
|
|
221
|
+
};
|
|
222
|
+
const absProbe = (method, url, o = {}) => {
|
|
223
|
+
reqCount();
|
|
224
|
+
return probe(method, url, Object.assign({ timeout }, o));
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
let listener = null;
|
|
228
|
+
if (opts.verifySsrf) {
|
|
229
|
+
listener = await startCallbackListener();
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
// ── 0. reachability + baseline ────────────────────────────────────────
|
|
233
|
+
const root = await P('GET', '/');
|
|
234
|
+
if (root.error || root.status === 0) {
|
|
235
|
+
log(finding('web.unreachable', 'Target unreachable', 'high', 'CWE-20',
|
|
236
|
+
`No HTTP response from ${base} (${root.error || 'no status'}). Check the URL and that the service is up.`,
|
|
237
|
+
`${root.error || 'no status'}`, `curl -s -i '${base}/'`));
|
|
238
|
+
stats.durationMs = Date.now() - t0;
|
|
239
|
+
if (listener) await listener.close();
|
|
240
|
+
return { findings, stats };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ── 1. security headers ───────────────────────────────────────────────
|
|
244
|
+
const h = root.headers;
|
|
245
|
+
const missing = [];
|
|
246
|
+
if (!h['content-security-policy']) missing.push('Content-Security-Policy');
|
|
247
|
+
if (!h['strict-transport-security']) missing.push('Strict-Transport-Security');
|
|
248
|
+
if (!h['x-frame-options']) missing.push('X-Frame-Options');
|
|
249
|
+
if (!h['x-content-type-options']) missing.push('X-Content-Type-Options');
|
|
250
|
+
if (!h['referrer-policy']) missing.push('Referrer-Policy');
|
|
251
|
+
if (!h['permissions-policy']) missing.push('Permissions-Policy');
|
|
252
|
+
if (missing.length > 0) {
|
|
253
|
+
const critical = missing.includes('Content-Security-Policy') && missing.includes('Strict-Transport-Security');
|
|
254
|
+
log(finding('web.security-headers', 'Missing security headers', critical ? 'medium' : 'low', 'CWE-693',
|
|
255
|
+
`Response is missing: ${missing.join(', ')}. These headers mitigate XSS, clickjacking, MIME sniffing and protocol downgrade.`,
|
|
256
|
+
`GET / -> ${root.status} · missing: ${missing.join(', ')}`,
|
|
257
|
+
`curl -s -i '${base}/'`));
|
|
258
|
+
}
|
|
259
|
+
// HSTS present but weak (max-age < 180 days per OWASP)
|
|
260
|
+
const hsts = h['strict-transport-security'];
|
|
261
|
+
if (hsts) {
|
|
262
|
+
const ma = /max-age=(\d+)/i.exec(hsts);
|
|
263
|
+
if (ma && Number(ma[1]) < 15552000) {
|
|
264
|
+
log(finding('web.hsts-weak', 'HSTS max-age too short', 'medium', 'CWE-319',
|
|
265
|
+
`Strict-Transport-Security max-age=${ma[1]} (< 15552000s/180d per OWASP).`,
|
|
266
|
+
`Strict-Transport-Security: ${hsts}`, `curl -s -i '${base}/'`));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// CSP present but allows unsafe-inline scripts
|
|
270
|
+
const csp = h['content-security-policy'];
|
|
271
|
+
if (csp && /script-src[^;]*'unsafe-inline'/.test(csp)) {
|
|
272
|
+
log(finding('web.csp-unsafe-inline', 'CSP allows unsafe-inline scripts', 'low', 'CWE-693',
|
|
273
|
+
"Content-Security-Policy's script-src contains 'unsafe-inline' — XSS protections are largely neutralized.",
|
|
274
|
+
`Content-Security-Policy: ${csp.slice(0, 120)}`, `curl -s -i '${base}/'`));
|
|
275
|
+
}
|
|
276
|
+
if (h['server']) {
|
|
277
|
+
log(finding('web.server-banner', 'Server banner discloses technology', 'low', 'CWE-200',
|
|
278
|
+
`Server header: ${h['server']}. Version disclosure helps attackers pick exploits.`,
|
|
279
|
+
`Server: ${h['server']}`, `curl -s -i '${base}/'`));
|
|
280
|
+
}
|
|
281
|
+
const xpb = h['x-powered-by'];
|
|
282
|
+
if (xpb) {
|
|
283
|
+
log(finding('web.tech-disclosure', 'X-Powered-By discloses framework', 'low', 'CWE-200',
|
|
284
|
+
`X-Powered-By: ${xpb}.`, `X-Powered-By: ${xpb}`, `curl -s -i '${base}/'`));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ── 2. cookie flags ───────────────────────────────────────────────────
|
|
288
|
+
const setCookies = h['set-cookie'];
|
|
289
|
+
if (setCookies && setCookies.length) {
|
|
290
|
+
const weak = setCookies.filter((c) => !/HttpOnly/i.test(c) || !/Secure/i.test(c) || !/SameSite=/i.test(c));
|
|
291
|
+
if (weak.length) {
|
|
292
|
+
log(finding('web.cookie-flags', 'Cookies missing security flags', 'medium', 'CWE-1004',
|
|
293
|
+
`Set-Cookie without HttpOnly/Secure/SameSite: ${weak.join(' | ')}. Session cookies should set all three.`,
|
|
294
|
+
`Set-Cookie: ${weak.join(' | ')}`, `curl -s -i '${base}/'`));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ── 3. CORS misconfiguration ──────────────────────────────────────────
|
|
299
|
+
const corsRes = await P('GET', '/', { headers: { Origin: 'https://evil.example' } });
|
|
300
|
+
const acao = corsRes.headers['access-control-allow-origin'];
|
|
301
|
+
const acac = corsRes.headers['access-control-allow-credentials'];
|
|
302
|
+
if (acao && acao.includes('evil.example')) {
|
|
303
|
+
log(finding('web.cors-reflection', 'CORS reflects arbitrary Origin', 'high', 'CWE-942',
|
|
304
|
+
`Access-Control-Allow-Origin reflects attacker origins (${acao}${acac === 'true' ? ' with credentials' : ''}). Any malicious site can read authenticated responses.`,
|
|
305
|
+
`Origin: https://evil.example -> ACAO: ${acao} · ACAC: ${acac}`,
|
|
306
|
+
`curl -s -i -H 'Origin: https://evil.example' '${base}/'`));
|
|
307
|
+
} else if (acao === '*' && acac === 'true') {
|
|
308
|
+
log(finding('web.cors-wildcard-credentials', 'CORS wildcard origin with credentials', 'high', 'CWE-942',
|
|
309
|
+
'Access-Control-Allow-Origin: * combined with Access-Control-Allow-Credentials: true — browsers reject this, which usually signals a broken but dangerous config. Review.',
|
|
310
|
+
`ACAO: * · ACAC: true`, `curl -s -i -H 'Origin: https://evil.example' '${base}/'`));
|
|
311
|
+
}
|
|
312
|
+
const nullRes = await P('GET', '/', { headers: { Origin: 'null' } });
|
|
313
|
+
if (nullRes.headers['access-control-allow-origin'] === 'null') {
|
|
314
|
+
log(finding('web.cors-null-origin', 'CORS allows null origin', 'medium', 'CWE-942',
|
|
315
|
+
'Access-Control-Allow-Origin: null — sandboxed iframes/file:// pages can read responses.',
|
|
316
|
+
'Origin: null -> ACAO: null', `curl -s -i -H 'Origin: null' '${base}/'`));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ── 4. open redirect ──────────────────────────────────────────────────
|
|
320
|
+
const redirectParams = ['next', 'redirect', 'redirect_uri', 'url', 'return', 'return_to', 'dest', 'target', 'page', 'ref'];
|
|
321
|
+
const redirectPaths = ['/', '/redirect', '/login', '/signin', '/auth', '/logout', '/go', '/link', '/out', '/callback'];
|
|
322
|
+
outer: for (const rp of redirectPaths) {
|
|
323
|
+
for (const p of redirectParams) {
|
|
324
|
+
for (const payload of ['//evil.example', '/\\evil.example', '///evil.example', '/%2f%2fevil.example']) {
|
|
325
|
+
const r = await P('GET', `${rp}?${p}=${payload}`, { noRedirect: true });
|
|
326
|
+
const loc = r.headers && r.headers.location;
|
|
327
|
+
if (loc && (loc.startsWith('//') || /^https?:\/\/evil\.example/i.test(loc) || loc.includes('%2f%2fevil'))) {
|
|
328
|
+
log(finding('web.open-redirect', 'Open redirect', 'medium', 'CWE-601',
|
|
329
|
+
`Parameter "${p}" on ${rp} redirects to attacker-controlled input (Location: ${loc}). Phishing/credential-harvesting vector.`,
|
|
330
|
+
`GET ${rp}?${p}=${payload} -> ${r.status} Location: ${loc}`,
|
|
331
|
+
`curl -s -i '${base}${rp}?${p}=${payload}'`));
|
|
332
|
+
break outer;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ── 5. exposed files & endpoints ──────────────────────────────────────
|
|
339
|
+
// 404/soft-404 baseline: SPA servers return 200 HTML for every path; a hit
|
|
340
|
+
// whose body equals the baseline body is not a real exposure.
|
|
341
|
+
const baseline = await P('GET', '/__vibeguard_nonexistent_' + Date.now() + '__', { noRedirect: true });
|
|
342
|
+
const baselineBody = baseline.status === 404 ? baseline.body : '';
|
|
343
|
+
for (const item of EXPOSED_PATHS) {
|
|
344
|
+
const r = await P('GET', item.path);
|
|
345
|
+
if (r.status === 200 && baselineBody && r.body === baselineBody) continue;
|
|
346
|
+
if (r.status === 200 && item.sig.test(r.body)) {
|
|
347
|
+
log(finding('web.exposed-file', `Exposed sensitive file/endpoint: ${item.path}`, 'high', 'CWE-200',
|
|
348
|
+
`${item.path} returned 200 with content matching an exposed-resource signature. ${item.path === '/.env' ? 'Environment variables likely leaked.' : ''}`,
|
|
349
|
+
`GET ${item.path} -> 200 (${r.body.length} bytes)`,
|
|
350
|
+
`curl -s -i '${base}${item.path}'`));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ── 6. GraphQL introspection ──────────────────────────────────────────
|
|
355
|
+
for (const p of GRAPHQL_PATHS) {
|
|
356
|
+
const r = await P('POST', p, {
|
|
357
|
+
headers: { 'Content-Type': 'application/json' },
|
|
358
|
+
body: GRAPHQL_INTROSPECTION,
|
|
359
|
+
});
|
|
360
|
+
if (r.status === 200 && r.body.includes('__schema')) {
|
|
361
|
+
log(finding('web.graphql-introspection', `GraphQL introspection enabled at ${p}`, 'medium', 'CWE-200',
|
|
362
|
+
'The schema (all types, fields, arguments) is readable by anyone — a complete map for attackers.',
|
|
363
|
+
`POST ${p} introspection -> 200 with __schema`,
|
|
364
|
+
`curl -s -X POST '${base}${p}' -H 'Content-Type: application/json' -d '${GRAPHQL_INTROSPECTION}'`));
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// ── 7. verbose errors ─────────────────────────────────────────────────
|
|
370
|
+
const errRes = await P('GET', '/?x=%5B&y=undefined%20function', { noRedirect: true });
|
|
371
|
+
if (errRes.status >= 500 && /(Error:|at\s+[A-Za-z_$]|node_modules|processTicksAndRejections|\.js:\d+:\d+|Traceback|Exception)/.test(errRes.body)) {
|
|
372
|
+
log(finding('web.verbose-errors', 'Verbose error messages leak internals', 'medium', 'CWE-209',
|
|
373
|
+
'A malformed request triggered a 500 response containing stack traces/paths. Internal details aid exploitation.',
|
|
374
|
+
`GET /?x=[ -> ${errRes.status} (excerpt: ${errRes.body.slice(0, 160).replace(/\s+/g, ' ').trim()})`,
|
|
375
|
+
`curl -s -i '${base}/?x=%5B'`));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ── 8. rate limiting (crude; auth endpoints only per OWASP API8) ──────
|
|
379
|
+
const authPaths = ['/login', '/signin', '/auth', '/signup', '/otp', '/reset', '/token', '/api/login', '/api/auth'];
|
|
380
|
+
let ratePath = null;
|
|
381
|
+
for (const ap of authPaths) {
|
|
382
|
+
const r = await P('POST', ap, {
|
|
383
|
+
headers: { 'Content-Type': 'application/json' },
|
|
384
|
+
body: '{"username":"demo","password":"demo"}',
|
|
385
|
+
noRedirect: true,
|
|
386
|
+
});
|
|
387
|
+
if (r.status === 401 || r.status === 403 || r.status === 302 || r.status === 200) { ratePath = ap; break; } // app processed it
|
|
388
|
+
}
|
|
389
|
+
if (!ratePath) ratePath = '/';
|
|
390
|
+
let throttled = false;
|
|
391
|
+
for (let i = 0; i < 10; i++) {
|
|
392
|
+
const r = await P(ratePath === '/' ? 'GET' : 'POST', ratePath, {
|
|
393
|
+
headers: ratePath === '/' ? {} : { 'Content-Type': 'application/json' },
|
|
394
|
+
body: ratePath === '/' ? undefined : '{"username":"demo","password":"demo"}',
|
|
395
|
+
noRedirect: true,
|
|
396
|
+
});
|
|
397
|
+
if (r.status === 429 || r.status === 503) { throttled = true; break; }
|
|
398
|
+
}
|
|
399
|
+
if (!throttled) {
|
|
400
|
+
log(finding('web.rate-limiting', 'No rate limiting observed', 'low', 'CWE-307',
|
|
401
|
+
`10 rapid requests to ${ratePath} all succeeded without throttling (no 429/503). Brute-force and credential-stuffing vectors are unmitigated.`,
|
|
402
|
+
`10x ${ratePath} -> no 429/503`,
|
|
403
|
+
`for i in $(seq 10); do curl -s -o /dev/null -w '%{http_code}\n' '${base}${ratePath}'; done`));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// ── 9. TLS deep check (version, cert validity, hostname) ─────
|
|
407
|
+
if (base.startsWith('https://')) {
|
|
408
|
+
const tls = require('tls');
|
|
409
|
+
const hostname = new URL(base).hostname;
|
|
410
|
+
try {
|
|
411
|
+
const socket = tls.connect({ host: hostname, port: 443, servername: hostname, rejectUnauthorized: false, timeout: Math.min(timeout, 5000) });
|
|
412
|
+
const tlsResult = await new Promise((resolve) => {
|
|
413
|
+
const timer = setTimeout(() => { socket.destroy(); resolve({ error: 'timeout' }); }, Math.min(timeout, 5000));
|
|
414
|
+
socket.once('secureConnect', () => {
|
|
415
|
+
clearTimeout(timer);
|
|
416
|
+
const cert = socket.getPeerCertificate();
|
|
417
|
+
const proto = socket.getProtocol();
|
|
418
|
+
socket.destroy();
|
|
419
|
+
resolve({ proto, cert });
|
|
420
|
+
});
|
|
421
|
+
socket.once('error', (e) => { clearTimeout(timer); resolve({ error: String(e.code || e.message) }); });
|
|
422
|
+
});
|
|
423
|
+
if (tlsResult.proto && /TLSv1(?!\.[23])/.test(tlsResult.proto)) {
|
|
424
|
+
log(finding('web.tls-old-version', `Obsolete TLS version: ${tlsResult.proto}`, 'high', 'CWE-326',
|
|
425
|
+
`${tlsResult.proto} is deprecated (TLS 1.2+ required).`,
|
|
426
|
+
`protocol: ${tlsResult.proto}`, `openssl s_client -connect ${hostname}:443`));
|
|
427
|
+
}
|
|
428
|
+
const cert = tlsResult.cert;
|
|
429
|
+
if (cert && cert.valid_to && cert.valid_from) {
|
|
430
|
+
const now = Date.now();
|
|
431
|
+
const validTo = new Date(cert.valid_to).getTime();
|
|
432
|
+
if (now > validTo) {
|
|
433
|
+
log(finding('web.tls-expired', 'TLS certificate expired', 'high', 'CWE-299',
|
|
434
|
+
`Certificate valid_to ${cert.valid_to} is in the past.`,
|
|
435
|
+
`CN=${cert.subject && cert.subject.CN} · valid_to ${cert.valid_to}`, `openssl s_client -connect ${hostname}:443`));
|
|
436
|
+
} else if (validTo - now < 30 * 86400000) {
|
|
437
|
+
log(finding('web.tls-expiring', 'TLS certificate expiring soon', 'low', 'CWE-299',
|
|
438
|
+
`Certificate expires ${cert.valid_to} (< 30 days).`,
|
|
439
|
+
`CN=${cert.subject && cert.subject.CN} · valid_to ${cert.valid_to}`, `openssl s_client -connect ${hostname}:443`));
|
|
440
|
+
}
|
|
441
|
+
if (cert.subject && cert.issuer && cert.subject.CN === cert.issuer.CN) {
|
|
442
|
+
log(finding('web.tls-self-signed', 'Self-signed TLS certificate', 'medium', 'CWE-295',
|
|
443
|
+
'The server presents a self-signed certificate (issuer == subject).',
|
|
444
|
+
`CN=${cert.subject.CN}`, `openssl s_client -connect ${hostname}:443`));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
} catch {
|
|
448
|
+
/* TLS probe errors never fail the scan — recorded, continue */
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ── 9. JWT alg:none (opt-in with --token) ─────────────────────────────
|
|
453
|
+
if (opts.token && typeof opts.token === 'string') {
|
|
454
|
+
const jwt = opts.token.trim();
|
|
455
|
+
const parts = jwt.split('.');
|
|
456
|
+
if (parts.length === 3) {
|
|
457
|
+
let header;
|
|
458
|
+
try { header = JSON.parse(Buffer.from(parts[0], 'base64url').toString('utf8')); } catch { header = null; }
|
|
459
|
+
if (header) {
|
|
460
|
+
const hdr = opts.tokenHeader || 'Authorization';
|
|
461
|
+
const bogusHeader = Object.assign({}, header, { alg: header.alg || 'HS256' });
|
|
462
|
+
const bogusToken = Buffer.from(JSON.stringify(bogusHeader)).toString('base64url') + '.' + parts[1] + '.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
|
|
463
|
+
const bogusRes = await P('GET', '/', { headers: { [hdr]: `Bearer ${bogusToken}` } });
|
|
464
|
+
// alg:none with case variants (None / NONE / nOnE) + trailing dot
|
|
465
|
+
for (const algVariant of ['none', 'None', 'NONE', 'nOnE']) {
|
|
466
|
+
const noneHeader = Object.assign({}, header, { alg: algVariant });
|
|
467
|
+
const noneToken = Buffer.from(JSON.stringify(noneHeader)).toString('base64url') + '.' + parts[1] + '.';
|
|
468
|
+
const noneRes = await P('GET', '/', { headers: { [hdr]: `Bearer ${noneToken}` } });
|
|
469
|
+
if (noneRes.status !== bogusRes.status && noneRes.status !== 401 && noneRes.status !== 403) {
|
|
470
|
+
log(finding('web.jwt-alg-none', 'JWT alg:none accepted', 'critical', 'CWE-347',
|
|
471
|
+
`A token with alg:"${algVariant}" and an empty signature was treated differently (${noneRes.status}) from a bogus-signature token (${bogusRes.status}). The server likely accepts unsigned tokens — full authentication bypass.`,
|
|
472
|
+
`alg:${algVariant} token -> ${noneRes.status} · bogus sig -> ${bogusRes.status}`,
|
|
473
|
+
`curl -s -i -H '${hdr}: Bearer ${noneToken}' '${base}/'`));
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// weak-HMAC: try signing with common weak secrets and compare against
|
|
478
|
+
// the user's real token (mismatch = server rejects; 2xx delta = weak secret)
|
|
479
|
+
if (header.alg === 'HS256' || /HS256/i.test(String(header.alg))) {
|
|
480
|
+
const crypto = require('crypto');
|
|
481
|
+
const payload = parts[1];
|
|
482
|
+
for (const secret of ['secret', 'password', '123456', 'changeme', 'secretkey']) {
|
|
483
|
+
const sig = crypto.createHmac('sha256', secret).update(parts[0] + '.' + payload).digest('base64url');
|
|
484
|
+
const forged = parts[0] + '.' + payload + '.' + sig;
|
|
485
|
+
const weakRes = await P('GET', '/', { headers: { [hdr]: `Bearer ${forged}` } });
|
|
486
|
+
if (weakRes.status !== bogusRes.status && weakRes.status !== 401 && weakRes.status !== 403) {
|
|
487
|
+
log(finding('web.jwt-weak-secret', 'JWT signed with a weak known secret', 'high', 'CWE-347',
|
|
488
|
+
`A token signed with the common secret "${secret}" was accepted (${weakRes.status}) while a bogus-signature token was not. The signing key is guessable.`,
|
|
489
|
+
`HS256 secret="${secret}" -> ${weakRes.status} · bogus sig -> ${bogusRes.status}`,
|
|
490
|
+
`# forge with: HMAC-SHA256(header.payload, '${secret}')`));
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// ── 10. TLS / HTTPS ───────────────────────────────────────────────────
|
|
500
|
+
if (base.startsWith('https://')) {
|
|
501
|
+
const tlsRes = await absProbe('GET', base + '/', {});
|
|
502
|
+
if (tlsRes.error === 'SELF_SIGNED_CERT_IN_CHAIN' || tlsRes.error === 'DEPTH_ZERO_SELF_SIGNED_CERT' || tlsRes.error === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
|
|
503
|
+
log(finding('web.tls-self-signed', 'Self-signed TLS certificate', 'high', 'CWE-295',
|
|
504
|
+
'The server presents a self-signed certificate. Man-in-the-middle attacks are trivial for users who ignore warnings.',
|
|
505
|
+
`TLS verification error: ${tlsRes.error}`, `curl -sI '${base}/'`));
|
|
506
|
+
}
|
|
507
|
+
} else {
|
|
508
|
+
const httpsUrl = base.replace(/^http:/, 'https:');
|
|
509
|
+
const r = await absProbe('GET', httpsUrl + '/', {});
|
|
510
|
+
if (!r.error && r.status > 0) {
|
|
511
|
+
// https exists — check if http redirects to it
|
|
512
|
+
const httpRoot = await P('GET', '/', { noRedirect: true });
|
|
513
|
+
const loc = httpRoot.headers && httpRoot.headers.location;
|
|
514
|
+
if (!(loc && loc.includes('https:'))) {
|
|
515
|
+
log(finding('web.no-https-redirect', 'HTTP does not redirect to HTTPS', 'medium', 'CWE-319',
|
|
516
|
+
'The site serves over HTTP and does not force HTTPS. Credentials and tokens travel in cleartext.',
|
|
517
|
+
`GET http://... -> ${httpRoot.status} (no https Location)`,
|
|
518
|
+
`curl -s -i '${base}/'`));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// ── 11. SSRF out-of-band proof (opt-in) ───────────────────────────────
|
|
524
|
+
if (opts.verifySsrf && listener) {
|
|
525
|
+
const paramCandidates = new Set(COMMON_SSRF_PARAMS);
|
|
526
|
+
// harvest params from the homepage's own links/forms/scripts
|
|
527
|
+
const links = root.body.match(/(?:href|src|action)\s*=\s*["'][^"']*["']/gi) || [];
|
|
528
|
+
for (const l of links) {
|
|
529
|
+
const u = l.replace(/^(?:href|src|action)\s*=\s*["']/i, '').replace(/["']$/, '');
|
|
530
|
+
try {
|
|
531
|
+
const parsed = new URL(u, base);
|
|
532
|
+
for (const [k] of parsed.searchParams) paramCandidates.add(k);
|
|
533
|
+
} catch { /* skip */ }
|
|
534
|
+
}
|
|
535
|
+
// harvest (action, input-name) pairs from <form> tags — real SSRF
|
|
536
|
+
// sinks live on form actions, not just root query params
|
|
537
|
+
const formTargets = [];
|
|
538
|
+
const forms = root.body.match(/<form[^>]*>[\s\S]*?<\/form>/gi) || [];
|
|
539
|
+
for (const form of forms) {
|
|
540
|
+
const am = /action\s*=\s*["']([^"']*)["']/i.exec(form);
|
|
541
|
+
const action = am ? am[1] : '/';
|
|
542
|
+
const inputs = form.match(/<input[^>]*name\s*=\s*["']([^"']*)["'][^>]*>/gi) || [];
|
|
543
|
+
for (const inp of inputs) {
|
|
544
|
+
const nm = /name\s*=\s*["']([^"']*)["']/i.exec(inp);
|
|
545
|
+
if (nm && nm[1]) formTargets.push({ action, param: nm[1] });
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
let probeCount = 0;
|
|
549
|
+
const hitsBefore = listener.hits.length;
|
|
550
|
+
for (const { action, param } of formTargets) {
|
|
551
|
+
if (probeCount >= 20) break;
|
|
552
|
+
probeCount++;
|
|
553
|
+
const probeUrl = `${listener.url}/cb-${encodeURIComponent(param)}-${Date.now()}`;
|
|
554
|
+
await P('GET', `${action}?${param}=${encodeURIComponent(probeUrl)}`, { noRedirect: true, timeout: Math.min(timeout, 4000) });
|
|
555
|
+
}
|
|
556
|
+
for (const p of paramCandidates) {
|
|
557
|
+
if (probeCount >= 40) break;
|
|
558
|
+
probeCount++;
|
|
559
|
+
const probeUrl = `${listener.url}/cb-${encodeURIComponent(p)}-${Date.now()}`;
|
|
560
|
+
const r = await P('GET', `/?${p}=${encodeURIComponent(probeUrl)}`, { noRedirect: true, timeout: Math.min(timeout, 4000) });
|
|
561
|
+
// also try it as POST body param on the base path
|
|
562
|
+
if (r.status !== 0 && p === 'url') {
|
|
563
|
+
await P('POST', '/', { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: `${p}=${encodeURIComponent(probeUrl)}` });
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
// wait briefly for callbacks
|
|
567
|
+
await new Promise((r) => setTimeout(r, opts.ssrfWaitMs || 1500));
|
|
568
|
+
const newHits = listener.hits.slice(hitsBefore);
|
|
569
|
+
if (newHits.length > 0) {
|
|
570
|
+
const hit = newHits[0];
|
|
571
|
+
const param = String(hit.url).match(/cb-([^-\/]+)-/);
|
|
572
|
+
log(finding('web.ssrf-proof', 'SSRF — out-of-band callback observed', 'critical', 'CWE-918',
|
|
573
|
+
`The target fetched an attacker-controlled URL from this machine (callback on ${listener.url}${hit.url}). Proof-of-exploit: a URL-like parameter on / triggers server-side requests. Parameter: ${param ? param[1] : 'unknown'}.`,
|
|
574
|
+
`Callback ${hit.url} at ${hit.time}`,
|
|
575
|
+
`curl -s -i '${base}/?${param ? param[1] : 'url'}=http://YOUR-LISTENER/cb'`));
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
stats.callbackHits = listener.hits.length;
|
|
579
|
+
await listener.close();
|
|
580
|
+
}
|
|
581
|
+
} finally {
|
|
582
|
+
if (listener && listener.hits) await listener.close().catch(() => {});
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
stats.durationMs = Date.now() - t0;
|
|
586
|
+
return { findings, stats };
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
module.exports = { runPentest, probe, httpReq, startCallbackListener, curlCommand };
|
package/src/pii.js
CHANGED
|
@@ -82,6 +82,10 @@ const DETECTORS = [
|
|
|
82
82
|
// don't grab bare integers. 10–15 significant digits.
|
|
83
83
|
re: /(?<![\w.])(?:\+?\d{1,3}[ .-]?)?(?:\(\d{2,4}\)[ .-]?)?\d{2,4}[ .-]\d{2,4}[ .-]\d{2,4}(?:[ .-]\d{2,4})?(?![\w])/g,
|
|
84
84
|
validate(m) {
|
|
85
|
+
// An IPv4 address is not a phone number, even if its octets look like
|
|
86
|
+
// three numeric groups. Without this, http://169.254.169.254/ reads as a
|
|
87
|
+
// phone and every metadata-URL check gets a phantom PII hit.
|
|
88
|
+
if (/^\d{1,3}(?:\.\d{1,3}){3}$/.test(m.trim())) return false;
|
|
85
89
|
const d = m.replace(/[^\d]/g, '');
|
|
86
90
|
return d.length >= 10 && d.length <= 15;
|
|
87
91
|
},
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* AISVS-style control mapping. This is an internal readiness matrix, not a
|
|
5
|
+
* certification and not a claim that every AISVS 1.01 requirement is met.
|
|
6
|
+
* Statuses are derived from the independent verification evidence IDs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const CONTROLS = [
|
|
10
|
+
{ id: 'AISVS-GOV-01', title: 'AI security ownership and policy', status: 'partial', evidence: ['research/SECURITY_TEST_MATRIX.md'], note: 'Strict policy exists; no organizational governance evidence.' },
|
|
11
|
+
{ id: 'AISVS-INV-01', title: 'Agent/tool/model inventory', status: 'partial', evidence: ['src/mcp-audit.js'], note: 'Config discovery only; no complete registry.' },
|
|
12
|
+
{ id: 'AISVS-PI-01', title: 'Prompt injection resistance', status: 'partial', evidence: ['IV-PI-01..09'], note: 'Tested patterns; no precision corpus coverage beyond small corpus.' },
|
|
13
|
+
{ id: 'AISVS-TOOL-01', title: 'Tool definition integrity', status: 'partial', evidence: ['IV-TP-01..05'], note: 'Hash/pin and text scanning; no full schema provenance.' },
|
|
14
|
+
{ id: 'AISVS-AUTH-01', title: 'Caller authentication', status: 'partial', evidence: ['IV-AUTH-01..07'], note: 'HTTP/stdio token path exists; approval approver unauthenticated.' },
|
|
15
|
+
{ id: 'AISVS-AUTHZ-01', title: 'Least-privilege authorization', status: 'partial', evidence: ['IV-UA-01..07'], note: 'Strict policy/v2 library; legacy default allow.' },
|
|
16
|
+
{ id: 'AISVS-DATA-01', title: 'Secret/PII protection', status: 'partial', evidence: ['IV-SEC-01..08'], note: 'Pattern/entropy DLP; no universal coverage.' },
|
|
17
|
+
{ id: 'AISVS-SBX-01', title: 'Untrusted code isolation', status: 'not_verified', evidence: ['IV-SBX-01..06'], note: 'Linux network/PID namespace backend added; Windows/macOS OS isolation absent.' },
|
|
18
|
+
{ id: 'AISVS-LOG-01', title: 'Tamper-evident audit', status: 'partial', evidence: ['IV-AUD-01..07'], note: 'Signed logger/checkpoint; gateway strict uses it; external anchor absent.' },
|
|
19
|
+
{ id: 'AISVS-MON-01', title: 'Runtime monitoring/response', status: 'partial', evidence: ['IV-FO-08'], note: 'Kill-on-block added; no OS network/process monitor.' },
|
|
20
|
+
{ id: 'AISVS-SC-01', title: 'Supply-chain integrity', status: 'partial', evidence: ['IV-DEP-01..03'], note: 'Audit overrides; no provenance/signature.' },
|
|
21
|
+
{ id: 'AISVS-MA-01', title: 'Multi-agent isolation', status: 'not_implemented', evidence: ['IV-MA-01..03'], note: 'Library controls only, not wired.' },
|
|
22
|
+
{ id: 'AISVS-MEM-01', title: 'Memory/context integrity', status: 'not_implemented', evidence: ['IV-MEM-01..03'], note: 'No persistent memory path.' },
|
|
23
|
+
{ id: 'AISVS-EVAL-01', title: 'Adversarial evaluation', status: 'partial', evidence: ['test/corpus', 'research/REPRODUCIBLE_BENCHMARKS.md'], note: 'Small labeled corpus + local tests; no independent penetration test.' },
|
|
24
|
+
{ id: 'AISVS-IR-01', title: 'Incident response/forensics', status: 'partial', evidence: ['IV-FO-01..08'], note: 'Audit + kill switch; no incident workflow/SIEM.' },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function getAisvsReport() {
|
|
28
|
+
const counts = { implemented: 0, partial: 0, not_implemented: 0, not_verified: 0 };
|
|
29
|
+
for (const c of CONTROLS) counts[c.status] = (counts[c.status] || 0) + 1;
|
|
30
|
+
return {
|
|
31
|
+
framework: 'AISVS-style internal mapping (not certified AISVS 1.01 coverage)',
|
|
32
|
+
generatedAt: new Date().toISOString(),
|
|
33
|
+
counts,
|
|
34
|
+
controls: CONTROLS,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { CONTROLS, getAisvsReport };
|