wize-dev-kit 0.5.0 → 0.6.0
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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/security-overlay/_shared/allowlist.js +154 -0
- package/src/security-overlay/_shared/cli-runner.js +87 -0
- package/src/security-overlay/_shared/cvss.js +108 -0
- package/src/security-overlay/_shared/detect.js +125 -0
- package/src/security-overlay/_shared/install-script.js +205 -0
- package/src/security-overlay/_shared/invoke-phase.js +86 -0
- package/src/security-overlay/_shared/owasp.js +56 -0
- package/src/security-overlay/_shared/partial.js +225 -0
- package/src/security-overlay/_shared/preflight.js +175 -0
- package/src/security-overlay/_shared/scope-gate.js +172 -0
- package/src/security-overlay/_shared/scope-parser.js +120 -0
- package/src/security-overlay/agents/red-teamer/agent.yaml +51 -0
- package/src/security-overlay/agents/red-teamer/persona.md +43 -0
- package/src/security-overlay/data/common.txt +115 -0
- package/src/security-overlay/data/owasp-top10.json +15 -0
- package/src/security-overlay/data/tool-allowlist.json +31 -0
- package/src/security-overlay/skills/wize-sec-enumerate/scripts/run-enumerate.js +180 -0
- package/src/security-overlay/skills/wize-sec-enumerate/skill.md +32 -0
- package/src/security-overlay/skills/wize-sec-exploit/data/common.txt +117 -0
- package/src/security-overlay/skills/wize-sec-exploit/scripts/run-ffuf.js +147 -0
- package/src/security-overlay/skills/wize-sec-exploit/scripts/run-nikto.js +145 -0
- package/src/security-overlay/skills/wize-sec-exploit/scripts/run-nuclei.js +176 -0
- package/src/security-overlay/skills/wize-sec-exploit/scripts/run-sqlmap.js +139 -0
- package/src/security-overlay/skills/wize-sec-pentest/scripts/run-pipeline.js +157 -0
- package/src/security-overlay/skills/wize-sec-pentest/skill.md +52 -0
- package/src/security-overlay/skills/wize-sec-recon/scripts/run-gitleaks.js +139 -0
- package/src/security-overlay/skills/wize-sec-recon/scripts/run-osv.js +227 -0
- package/src/security-overlay/skills/wize-sec-recon/scripts/run-recon.js +162 -0
- package/src/security-overlay/skills/wize-sec-recon/skill.md +35 -0
- package/src/security-overlay/skills/wize-sec-report/scripts/render-report.js +999 -0
- package/tools/installer/onboarding.js +1 -0
- package/tools/installer/render-shared.js +5 -1
- package/tools/installer/wize-cli.js +8 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// run-nuclei.js — DAST nuclei phase. Default is passive (info disclosure,
|
|
4
|
+
// misconfig, headers). Active mode is gated by --active (sqlmap/ffuf
|
|
5
|
+
// come in separate stories).
|
|
6
|
+
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const { execFileSync } = require('node:child_process');
|
|
10
|
+
|
|
11
|
+
const { assertTargetInScope } = require('../../../_shared/scope-gate.js');
|
|
12
|
+
const { filterArgs } = require('../../../_shared/allowlist.js');
|
|
13
|
+
const { writePartial } = require('../../../_shared/partial.js');
|
|
14
|
+
const { tagOwasp } = require('../../../_shared/owasp.js');
|
|
15
|
+
|
|
16
|
+
// Build the nuclei args list. Returns the raw argv (before filterArgs).
|
|
17
|
+
// Kept as a separate function so tests can assert on the raw list.
|
|
18
|
+
function filterNucleiArgs(targetUrl, active, outputPath) {
|
|
19
|
+
// nuclei v3: there is no `-t passive` template path. We run the default
|
|
20
|
+
// template set and filter by severity. Passive = lower-impact severities
|
|
21
|
+
// + aggressive rate limit; active = full severity range. Output is JSONL
|
|
22
|
+
// (-jsonl), disable update check (-duc), non-colored (-nc), silent.
|
|
23
|
+
const args = [
|
|
24
|
+
'-u', targetUrl,
|
|
25
|
+
'-severity', active ? 'info,low,medium,high,critical' : 'info,low,medium',
|
|
26
|
+
'-rl', '10',
|
|
27
|
+
'-jsonl', '-o', outputPath,
|
|
28
|
+
'-duc', '-nc', '-silent'
|
|
29
|
+
];
|
|
30
|
+
return args;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Parse line-delimited nuclei JSON output (one finding per line).
|
|
34
|
+
function parseNucleiJson(text) {
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const line of String(text || '').split('\n')) {
|
|
37
|
+
const trimmed = line.trim();
|
|
38
|
+
if (!trimmed) continue;
|
|
39
|
+
try {
|
|
40
|
+
const f = JSON.parse(trimmed);
|
|
41
|
+
out.push(f);
|
|
42
|
+
} catch (_) { /* skip malformed lines */ }
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Build a nuclei finding object (flat) with template_id, severity, owasp, etc.
|
|
48
|
+
function normalizeFinding(raw) {
|
|
49
|
+
const templateId = raw['template-id'] || raw.templateID || raw.template || '<unknown>';
|
|
50
|
+
const info = raw.info || {};
|
|
51
|
+
const severity = (info.severity || raw.severity || 'unknown').toString().toLowerCase();
|
|
52
|
+
const name = info.name || raw.name || templateId;
|
|
53
|
+
const matchedAt = raw['matched-at'] || raw.matched || raw.host || '<unknown>';
|
|
54
|
+
// CVSS: nuclei sometimes nests it.
|
|
55
|
+
let cvss = raw.cvss;
|
|
56
|
+
if (typeof cvss !== 'number' && info && info.classification && info.classification.cvss_score) {
|
|
57
|
+
cvss = Number(info.classification.cvss_score);
|
|
58
|
+
}
|
|
59
|
+
if (typeof cvss !== 'number') cvss = null;
|
|
60
|
+
const owasp = tagOwasp({ rule: templateId, cve: raw['cve-id'] || raw.cve });
|
|
61
|
+
return { template_id: templateId, name, severity, cvss, matched_at: matchedAt, owasp };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// runNuclei({securityDir, scope, active, execFn?, detectFn?}) -> {ok, partialStatus}
|
|
65
|
+
async function runNuclei(opts = {}) {
|
|
66
|
+
const sec = opts.securityDir;
|
|
67
|
+
const scope = opts.scope;
|
|
68
|
+
const active = opts.active === true;
|
|
69
|
+
|
|
70
|
+
const execFn = opts.execFn || ((bin, args) => {
|
|
71
|
+
return execFileSync(bin, args, { encoding: 'utf8', timeout: 10 * 60 * 1000 });
|
|
72
|
+
});
|
|
73
|
+
const detectFn = opts.detectFn || require('../../../_shared/detect.js').detectTools;
|
|
74
|
+
|
|
75
|
+
const tools = detectFn(['nuclei'], { cacheDir: sec });
|
|
76
|
+
const present = !!(tools.nuclei && tools.nuclei.present);
|
|
77
|
+
|
|
78
|
+
// 1. Target resolution — prefer scope body's ## dast_target.url.
|
|
79
|
+
let targetUrl = null;
|
|
80
|
+
const lines = (scope.body || '').split('\n');
|
|
81
|
+
let inDast = false;
|
|
82
|
+
for (const line of lines) {
|
|
83
|
+
if (/^## dast_target/.test(line)) { inDast = true; continue; }
|
|
84
|
+
if (inDast && /^url:\s*(.+?)\s*$/.test(line)) { targetUrl = line.match(/^url:\s*(.+?)\s*$/)[1]; break; }
|
|
85
|
+
if (inDast && /^## /.test(line)) break;
|
|
86
|
+
}
|
|
87
|
+
if (!targetUrl) {
|
|
88
|
+
writePartial({
|
|
89
|
+
securityDir: sec,
|
|
90
|
+
phase: 'dast',
|
|
91
|
+
mode: active ? 'active' : 'passive',
|
|
92
|
+
scope,
|
|
93
|
+
status: 'incomplete',
|
|
94
|
+
tools,
|
|
95
|
+
sections: { degraded_checks: '- nuclei: dast_target.url ausente no scope.md' }
|
|
96
|
+
});
|
|
97
|
+
return { ok: true, partialStatus: 'incomplete' };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 2. Gate — target must be in scope.
|
|
101
|
+
const urlObj = new URL(targetUrl);
|
|
102
|
+
const inScope = assertTargetInScope(scope, { host: urlObj.hostname, url: targetUrl }, { refusalsDir: sec });
|
|
103
|
+
if (!inScope) {
|
|
104
|
+
writePartial({
|
|
105
|
+
securityDir: sec,
|
|
106
|
+
phase: 'dast',
|
|
107
|
+
mode: active ? 'active' : 'passive',
|
|
108
|
+
scope,
|
|
109
|
+
status: 'incomplete',
|
|
110
|
+
tools,
|
|
111
|
+
sections: { degraded_checks: `- nuclei: target ${targetUrl} recusado pelo gate` }
|
|
112
|
+
});
|
|
113
|
+
return { ok: false, partialStatus: 'incomplete' };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 3. Missing tool -> degraded.
|
|
117
|
+
if (!present) {
|
|
118
|
+
writePartial({
|
|
119
|
+
securityDir: sec,
|
|
120
|
+
phase: 'dast',
|
|
121
|
+
mode: active ? 'active' : 'passive',
|
|
122
|
+
scope,
|
|
123
|
+
status: 'incomplete',
|
|
124
|
+
tools,
|
|
125
|
+
sections: { degraded_checks: '- nuclei: nuclei ausente — instale nuclei e re-rode a fase.' }
|
|
126
|
+
});
|
|
127
|
+
return { ok: true, partialStatus: 'incomplete' };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 4. happy path.
|
|
131
|
+
const outPath = path.join(sec, '.nuclei.json');
|
|
132
|
+
const rawArgs = filterNucleiArgs(targetUrl, active, outPath);
|
|
133
|
+
const args = filterArgs('nuclei', rawArgs);
|
|
134
|
+
// nuclei may exit non-zero on some template errors; the JSONL output is
|
|
135
|
+
// still written for whatever ran. Read it regardless of exit status.
|
|
136
|
+
try {
|
|
137
|
+
execFn('nuclei', args, { timeout: 10 * 60 * 1000 });
|
|
138
|
+
} catch (_) { /* partial results still in outPath */ }
|
|
139
|
+
|
|
140
|
+
let findings = [];
|
|
141
|
+
if (fs.existsSync(outPath)) {
|
|
142
|
+
try {
|
|
143
|
+
findings = parseNucleiJson(fs.readFileSync(outPath, 'utf8'));
|
|
144
|
+
} catch (_) {
|
|
145
|
+
findings = [];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const normalized = findings.map(normalizeFinding);
|
|
149
|
+
const bodyLines = normalized.length
|
|
150
|
+
? normalized.map(f => `- **${f.template_id}** (\`${f.name}\`) severity=${f.severity} owasp=\`${f.owasp}\`${f.cvss != null ? ` cvss=${f.cvss}` : ''} matched_at: ${f.matched_at}`)
|
|
151
|
+
: ['_(nenhum finding do nuclei)_'];
|
|
152
|
+
|
|
153
|
+
writePartial({
|
|
154
|
+
securityDir: sec,
|
|
155
|
+
phase: 'dast',
|
|
156
|
+
mode: active ? 'active' : 'passive',
|
|
157
|
+
scope,
|
|
158
|
+
status: normalized.length ? 'complete' : 'incomplete',
|
|
159
|
+
tools,
|
|
160
|
+
sections: { nuclei: bodyLines.join('\n') }
|
|
161
|
+
});
|
|
162
|
+
return { ok: true, partialStatus: normalized.length ? 'complete' : 'incomplete' };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = { runNuclei, filterNucleiArgs, parseNucleiJson, normalizeFinding };
|
|
166
|
+
|
|
167
|
+
if (require.main === module) {
|
|
168
|
+
require('../../../_shared/cli-runner.js').runFromArgv({
|
|
169
|
+
fn: ({ securityDir, scopePath, active, target } = {}) => {
|
|
170
|
+
const { loadScope } = require('../../../_shared/scope-gate.js');
|
|
171
|
+
const scope = loadScope(scopePath);
|
|
172
|
+
return runNuclei({ securityDir, scope, active, target });
|
|
173
|
+
},
|
|
174
|
+
argMap: { 'securityDir': 'securityDir', 'scope': 'scopePath', 'active': 'active', 'target': 'target' }
|
|
175
|
+
});
|
|
176
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// run-sqlmap.js — DAST sqlmap. GATED by --active (ADR-004). Without
|
|
4
|
+
// --active, sqlmap is NOT invoked even if the tool is installed.
|
|
5
|
+
// filterArgs() blocks --dump and --os-shell (exfiltration / shell) —
|
|
6
|
+
// they're not in the allowlist.
|
|
7
|
+
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
const { execFileSync } = require('node:child_process');
|
|
11
|
+
|
|
12
|
+
const { assertTargetInScope } = require('../../../_shared/scope-gate.js');
|
|
13
|
+
const { filterArgs } = require('../../../_shared/allowlist.js');
|
|
14
|
+
const { writePartial, loadPartial } = require('../../../_shared/partial.js');
|
|
15
|
+
const { tagOwasp } = require('../../../_shared/owasp.js');
|
|
16
|
+
|
|
17
|
+
const TIMEOUT_MS = 5 * 60 * 1000;
|
|
18
|
+
|
|
19
|
+
function defaultArgs(targetUrl) {
|
|
20
|
+
// Conservative defaults. filterArgs() drops --dump, --os-shell, --level>1,
|
|
21
|
+
// --risk>1, etc. — they're not in the allowlist.
|
|
22
|
+
return ['-u', targetUrl, '--batch', '--level=1', '--risk=1', '--threads=2', '--timeout=10', '--retries=1', '--random-agent'];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Parse a slice of sqlmap stdout into findings. Sqlmap's output is fairly
|
|
26
|
+
// free-form; we use a relaxed parser that looks for the canonical
|
|
27
|
+
// "Parameter: <name> ... Type: ..." block.
|
|
28
|
+
function parseSqlmapStdout(stdout) {
|
|
29
|
+
const findings = [];
|
|
30
|
+
const lines = String(stdout || '').split('\n');
|
|
31
|
+
let current = null;
|
|
32
|
+
for (const line of lines) {
|
|
33
|
+
const pm = line.match(/Parameter:\s*(\S+).*Type:\s*(\S+)/i);
|
|
34
|
+
if (pm) {
|
|
35
|
+
if (current) findings.push(current);
|
|
36
|
+
current = { parameter: pm[1], type: pm[2] };
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const dm = line.match(/DBMS:\s*(.+?)\s*$/i);
|
|
40
|
+
if (dm && current) current.dbms = dm[1];
|
|
41
|
+
const pm2 = line.match(/Payload:\s*(.+?)\s*$/i);
|
|
42
|
+
if (pm2 && current) current.payload = pm2[1];
|
|
43
|
+
const reqm = line.match(/^\s*Type:\s*UNION.*query/i);
|
|
44
|
+
if (reqm && current) current.kind = 'union';
|
|
45
|
+
}
|
|
46
|
+
if (current) findings.push(current);
|
|
47
|
+
return findings;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function runSqlmap(opts = {}) {
|
|
51
|
+
const sec = opts.securityDir;
|
|
52
|
+
const scope = opts.scope;
|
|
53
|
+
const active = opts.active === true;
|
|
54
|
+
|
|
55
|
+
const execFn = opts.execFn || ((bin, args) => {
|
|
56
|
+
return execFileSync(bin, args, { encoding: 'utf8', timeout: TIMEOUT_MS });
|
|
57
|
+
});
|
|
58
|
+
const detectFn = opts.detectFn || require('../../../_shared/detect.js').detectTools;
|
|
59
|
+
|
|
60
|
+
const tools = detectFn(['sqlmap'], { cacheDir: sec });
|
|
61
|
+
const present = !!(tools.sqlmap && tools.sqlmap.present);
|
|
62
|
+
|
|
63
|
+
// Resolve dast_target.url.
|
|
64
|
+
let targetUrl = null;
|
|
65
|
+
for (const line of (scope.body || '').split('\n')) {
|
|
66
|
+
const m = line.match(/^url:\s*(.+?)\s*$/);
|
|
67
|
+
if (m && line.indexOf('url') === 0) { targetUrl = m[1]; break; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function mergeDast(sections, status) {
|
|
71
|
+
const existing = loadPartial({ securityDir: sec, phase: 'dast' });
|
|
72
|
+
const merged = {};
|
|
73
|
+
if (existing && existing.body) {
|
|
74
|
+
const re = /## ([a-z_]+)\n\n([\s\S]*?)(?=\n## |$)/g;
|
|
75
|
+
let m;
|
|
76
|
+
while ((m = re.exec(existing.body)) !== null) {
|
|
77
|
+
merged[m[1]] = m[2].trim();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
Object.assign(merged, sections);
|
|
81
|
+
const finalStatus = merged.degraded_checks ? 'incomplete' : status;
|
|
82
|
+
writePartial({
|
|
83
|
+
securityDir: sec, phase: 'dast', mode: active ? 'active' : 'passive',
|
|
84
|
+
scope, status: finalStatus, tools, sections: merged
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 1. Not active -> degraded with [sqlmap-pasive].
|
|
89
|
+
if (!active) {
|
|
90
|
+
mergeDast({ degraded_checks: '- sqlmap-pasive: --active ausente — sqlmap não é invocado sem opt-in explícito.' }, 'incomplete');
|
|
91
|
+
return { ok: true, partialStatus: 'incomplete' };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!targetUrl) {
|
|
95
|
+
mergeDast({ degraded_checks: '- sqlmap: dast_target.url ausente' }, 'incomplete');
|
|
96
|
+
return { ok: true, partialStatus: 'incomplete' };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 2. Gate first.
|
|
100
|
+
const urlObj = new URL(targetUrl);
|
|
101
|
+
const inScope = assertTargetInScope(scope, { host: urlObj.hostname, url: targetUrl }, { refusalsDir: sec });
|
|
102
|
+
if (!inScope) {
|
|
103
|
+
mergeDast({ degraded_checks: `- sqlmap: target ${targetUrl} recusado pelo gate` }, 'incomplete');
|
|
104
|
+
return { ok: false, partialStatus: 'incomplete' };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 3. Missing tool.
|
|
108
|
+
if (!present) {
|
|
109
|
+
mergeDast({ degraded_checks: '- sqlmap: sqlmap ausente — instale sqlmap e re-rode com --active.' }, 'incomplete');
|
|
110
|
+
return { ok: true, partialStatus: 'incomplete' };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 4. happy path (active + present + in scope).
|
|
114
|
+
const rawArgs = defaultArgs(targetUrl);
|
|
115
|
+
const args = filterArgs('sqlmap', rawArgs);
|
|
116
|
+
const r = execFn('sqlmap', args, { timeout: TIMEOUT_MS });
|
|
117
|
+
const stdout = r && r.stdout ? r.stdout : '';
|
|
118
|
+
const findings = parseSqlmapStdout(stdout);
|
|
119
|
+
const findingsWithOwasp = findings.map(f => ({ ...f, owasp: tagOwasp({ rule: f.type || 'sqlmap' }) }));
|
|
120
|
+
const body = findingsWithOwasp.length
|
|
121
|
+
? findingsWithOwasp.map(f => `- **${f.parameter || '?'}** (\`${f.type || '?'}\`) dbms=\`${f.dbms || '?'}\` owasp=\`${f.owasp}\` payload: ${f.payload || 'n/a'}`).join('\n')
|
|
122
|
+
: '_(nenhum finding do sqlmap)_';
|
|
123
|
+
|
|
124
|
+
mergeDast({ sqlmap: body }, findingsWithOwasp.length ? 'complete' : 'incomplete');
|
|
125
|
+
return { ok: true, partialStatus: findingsWithOwasp.length ? 'complete' : 'incomplete' };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { runSqlmap, defaultArgs, parseSqlmapStdout };
|
|
129
|
+
|
|
130
|
+
if (require.main === module) {
|
|
131
|
+
require('../../../_shared/cli-runner.js').runFromArgv({
|
|
132
|
+
fn: ({ securityDir, scopePath, active, target } = {}) => {
|
|
133
|
+
const { loadScope } = require('../../../_shared/scope-gate.js');
|
|
134
|
+
const scope = loadScope(scopePath);
|
|
135
|
+
return runSqlmap({ securityDir, scope, active, target });
|
|
136
|
+
},
|
|
137
|
+
argMap: { 'securityDir': 'securityDir', 'scope': 'scopePath', 'active': 'active', 'target': 'target' }
|
|
138
|
+
});
|
|
139
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// run-pipeline.js — the orchestrator for the security-overlay. Chains
|
|
4
|
+
// the four phase skills (recon -> enumerate -> exploit -> report) and
|
|
5
|
+
// propagates --active. This module exposes a `runPipeline(opts)` function
|
|
6
|
+
// so the test suite can drive it directly; the SKILL.md entrypoint
|
|
7
|
+
// (wize-sec-pentest) is a thin wrapper that just calls runPipeline with
|
|
8
|
+
// argv-derived options.
|
|
9
|
+
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
|
|
13
|
+
// Default kit root when running from the kit itself. Tests inject their own.
|
|
14
|
+
const DEFAULT_KIT_ROOT = path.resolve(__dirname, '..', '..', '..', '..', '..');
|
|
15
|
+
|
|
16
|
+
const PHASES = ['wize-sec-recon', 'wize-sec-enumerate', 'wize-sec-exploit', 'wize-sec-report'];
|
|
17
|
+
|
|
18
|
+
// Per-phase script manifests. Each phase can run one or more scripts.
|
|
19
|
+
// Scripts in the same phase run sequentially and any failure (or skip)
|
|
20
|
+
// marks the phase as incomplete, but does not abort the pipeline.
|
|
21
|
+
const PHASE_SCRIPTS = {
|
|
22
|
+
'wize-sec-recon': ['recon', 'gitleaks', 'osv'],
|
|
23
|
+
'wize-sec-enumerate': ['enumerate'],
|
|
24
|
+
'wize-sec-exploit': ['nuclei', 'nikto', 'sqlmap', 'ffuf'],
|
|
25
|
+
'wize-sec-report': ['report']
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function parseArgv(argv) {
|
|
29
|
+
const out = { active: false, scopePath: null, kitRoot: DEFAULT_KIT_ROOT };
|
|
30
|
+
for (let i = 0; i < (argv || []).length; i++) {
|
|
31
|
+
const a = argv[i];
|
|
32
|
+
if (a === '--active') out.active = true;
|
|
33
|
+
else if (a === '--scope' && argv[i + 1]) { out.scopePath = argv[i + 1]; i++; }
|
|
34
|
+
else if (a.startsWith('--scope=')) out.scopePath = a.slice('--scope='.length);
|
|
35
|
+
}
|
|
36
|
+
if (!out.scopePath) out.scopePath = path.join(process.cwd(), '.wize', 'security', 'scope.md');
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// runPipeline({ scopePath, active, kitRoot?, loadScopeFn?, invokePhase? })
|
|
41
|
+
// - loadScopeFn defaults to the real scope-gate loadScope.
|
|
42
|
+
// - invokePhase defaults to the real invokePhase (subprocess).
|
|
43
|
+
// Both are injectable for testing. We resolve the defaults lazily via a
|
|
44
|
+
// small indirection (a getter) so a test that mutates the real module's
|
|
45
|
+
// exports before loading this file sees the mocked value.
|
|
46
|
+
async function runPipeline(opts = {}) {
|
|
47
|
+
const scopePath = opts.scopePath;
|
|
48
|
+
const active = opts.active === true;
|
|
49
|
+
const kitRoot = opts.kitRoot || DEFAULT_KIT_ROOT;
|
|
50
|
+
const securityDir = opts.securityDir || path.join(process.cwd(), '.wize', 'security');
|
|
51
|
+
|
|
52
|
+
// Lazy default resolution — must read at call time, not destructured at
|
|
53
|
+
// module load, so a test that swaps the real module's exports is honored.
|
|
54
|
+
const loadScopeFn = opts.loadScopeFn
|
|
55
|
+
|| require('../../../_shared/scope-gate.js').loadScope;
|
|
56
|
+
const invokePhase = opts.invokePhase
|
|
57
|
+
|| require('../../../_shared/invoke-phase.js').invokePhase;
|
|
58
|
+
|
|
59
|
+
// 0. Preflight (permissive — always continues, but writes the install
|
|
60
|
+
// script if anything is missing). In test mode the env vars short-
|
|
61
|
+
// circuit the real probes so the result is deterministic.
|
|
62
|
+
const preflight = opts.preflight
|
|
63
|
+
|| require('../../../_shared/preflight.js').runPreflight({ kitRoot });
|
|
64
|
+
if (preflight.missing.length > 0 && opts.writeInstallScript !== false) {
|
|
65
|
+
const { generateInstallScript } = require('../../../_shared/install-script.js');
|
|
66
|
+
const script = generateInstallScript(preflight);
|
|
67
|
+
try {
|
|
68
|
+
const scriptPath = path.join(securityDir, 'install-pentest-tools.sh');
|
|
69
|
+
// Don't clobber a user-edited script.
|
|
70
|
+
if (!fs.existsSync(scriptPath)) {
|
|
71
|
+
fs.mkdirSync(securityDir, { recursive: true });
|
|
72
|
+
fs.writeFileSync(scriptPath, script, 'utf8');
|
|
73
|
+
try { fs.chmodSync(scriptPath, 0o755); } catch (_) { /* best-effort */ }
|
|
74
|
+
}
|
|
75
|
+
} catch (_) { /* best-effort: a write failure here does not block the pipeline */ }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 1. Gate first — if the scope is invalid, abort the whole pipeline.
|
|
79
|
+
const scope = loadScopeFn(scopePath);
|
|
80
|
+
|
|
81
|
+
const results = {};
|
|
82
|
+
const skipped = [];
|
|
83
|
+
|
|
84
|
+
for (const phase of PHASES) {
|
|
85
|
+
const scripts = PHASE_SCRIPTS[phase] || [phase.split('-').pop()];
|
|
86
|
+
const phaseResults = [];
|
|
87
|
+
for (const sub of scripts) {
|
|
88
|
+
// Naming convention: scripts in the skill dir are run-<sub>.js, except
|
|
89
|
+
// for the report phase which is render-report.js.
|
|
90
|
+
const baseName = phase === 'wize-sec-report' ? `render-${sub}` : `run-${sub}`;
|
|
91
|
+
const scriptName = baseName.endsWith('.js') ? baseName : baseName + '.js';
|
|
92
|
+
try {
|
|
93
|
+
const r = await invokePhase(phase, { kitRoot, active, securityDir, scopePath, scriptName });
|
|
94
|
+
phaseResults.push({ sub, ...r });
|
|
95
|
+
if (!r.ok) skipped.push(`${phase}/${sub}`);
|
|
96
|
+
} catch (_) {
|
|
97
|
+
phaseResults.push({ sub, ok: false, code: -1, stdout: '', stderr: '', error: 'invoke-threw' });
|
|
98
|
+
skipped.push(`${phase}/${sub}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Phase is OK if at least one sub-script succeeded.
|
|
102
|
+
const anyOk = phaseResults.some(r => r && r.ok);
|
|
103
|
+
results[phase] = { ok: anyOk, subs: phaseResults };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const anyOk = Object.values(results).some(r => r && r.ok);
|
|
107
|
+
return {
|
|
108
|
+
ok: anyOk,
|
|
109
|
+
scopePath,
|
|
110
|
+
active,
|
|
111
|
+
preflight,
|
|
112
|
+
results,
|
|
113
|
+
skipped
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Entry point when invoked as a subprocess (the SKILL.md frontmatter
|
|
118
|
+
// declares commands: [run-pipeline.js]). The harness's adapter renders
|
|
119
|
+
// this file as the skill body and runs `node run-pipeline.js` when the
|
|
120
|
+
// user invokes `/wize-sec-pentest`.
|
|
121
|
+
async function main() {
|
|
122
|
+
const args = parseArgv(process.argv.slice(2));
|
|
123
|
+
let result;
|
|
124
|
+
try {
|
|
125
|
+
// Derive the securityDir from the scopePath's parent (the .wize/security
|
|
126
|
+
// directory) so the preflight's install script lands next to the scope.
|
|
127
|
+
const secDir = path.dirname(args.scopePath);
|
|
128
|
+
result = await runPipeline({
|
|
129
|
+
scopePath: args.scopePath,
|
|
130
|
+
active: args.active,
|
|
131
|
+
kitRoot: args.kitRoot,
|
|
132
|
+
securityDir: secDir
|
|
133
|
+
});
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error('✖ wize-sec-pentest aborted:', err && err.message ? err.message : err);
|
|
136
|
+
process.exit(2);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Minimal stdout surface — the partials already carry detail.
|
|
140
|
+
for (const phase of PHASES) {
|
|
141
|
+
const r = result.results[phase];
|
|
142
|
+
if (!r) { console.log(`= ${phase}: (no result)`); continue; }
|
|
143
|
+
const mark = r.ok ? '✓' : '✗';
|
|
144
|
+
const subs = (r.subs || []).map(s => `${s.sub}:${s.ok ? 'ok' : 'fail'}`).join(',');
|
|
145
|
+
console.log(`${mark} ${phase}: ${subs}`);
|
|
146
|
+
}
|
|
147
|
+
if (result.skipped.length) {
|
|
148
|
+
console.log(`! skipped: ${result.skipped.join(', ')}`);
|
|
149
|
+
}
|
|
150
|
+
process.exit(result.ok ? 0 : 1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (require.main === module) {
|
|
154
|
+
main();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = { runPipeline, parseArgv, PHASES };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
code: wize-sec-pentest
|
|
3
|
+
name: wize-sec-pentest
|
|
4
|
+
overlay: security
|
|
5
|
+
module: security-overlay
|
|
6
|
+
owner: red-teamer
|
|
7
|
+
status: ready
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# wize-sec-pentest — Orchestrator (Security Overlay)
|
|
11
|
+
|
|
12
|
+
End-to-end security pipeline. Chains **recon → enumerate → sast → dast → report** through the four phase skills (`wize-sec-recon`, `wize-sec-enumerate`, `wize-sec-exploit`, `wize-sec-report`). Loads `.wize/security/scope.md` first; aborts the whole pipeline if the scope is missing or invalid.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Default (passive — read-only checks only)
|
|
18
|
+
/wize-sec-pentest
|
|
19
|
+
|
|
20
|
+
# Active exploitation (sqlmap, ffuf active fuzzing) — requires scope acceptance
|
|
21
|
+
/wize-sec-pentest --active
|
|
22
|
+
|
|
23
|
+
# Custom scope path (default: .wize/security/scope.md)
|
|
24
|
+
/wize-sec-pentest --scope=/path/to/scope.md
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Phases (in order)
|
|
28
|
+
|
|
29
|
+
1. **recon** — nmap (passive) → `recon.md`
|
|
30
|
+
2. **enumerate** — nuclei passive, HTTP probing → `enumerate.md`
|
|
31
|
+
3. **sast** — gitleaks (secrets) + osv-scanner/grype (deps) → `sast.md` (run inside `wize-sec-recon` per the architecture decision)
|
|
32
|
+
4. **dast** — nuclei + nikto (passive) + sqlmap/ffuf (gated by `--active`) → `dast.md`
|
|
33
|
+
5. **report** — render `report.md` + `report.html` from all partials
|
|
34
|
+
|
|
35
|
+
Each phase produces a partial. The report phase consumes them. A phase that fails is marked `partial_status: skipped` and the pipeline continues with the next one.
|
|
36
|
+
|
|
37
|
+
## Gate
|
|
38
|
+
|
|
39
|
+
Before any phase, the orchestrator calls `loadScope()` (the shared gate). An invalid scope aborts the whole pipeline with the error code from `ScopeError`. The gate is the single source of truth — phases do not re-validate.
|
|
40
|
+
|
|
41
|
+
## Propagation
|
|
42
|
+
|
|
43
|
+
`--active` is read from argv and passed to every phase invocation. Each phase that supports active checks (currently `wize-sec-exploit`) decides what changes in active mode.
|
|
44
|
+
|
|
45
|
+
## Output
|
|
46
|
+
|
|
47
|
+
- `recon.md`, `enumerate.md`, `sast.md`, `dast.md` — partials (one per phase)
|
|
48
|
+
- `report.md`, `report.html` — final consolidated report
|
|
49
|
+
- `.refusals.log` — audit trail of out-of-scope refusals
|
|
50
|
+
- `.tools.json` — detection cache for the toolchain
|
|
51
|
+
|
|
52
|
+
Exits 0 if at least one phase ran; 1 if all phases failed; 2 if the scope gate aborted.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// run-gitleaks.js — SAST secrets via gitleaks. Runs inside the
|
|
4
|
+
// wize-sec-recon skill (per the architecture decision that recon hosts
|
|
5
|
+
// the no-app-running checks). Writes a redaction into sast.md and stores
|
|
6
|
+
// the full gitleaks report in the security dir for the user to inspect.
|
|
7
|
+
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
const { execFileSync } = require('node:child_process');
|
|
11
|
+
|
|
12
|
+
const { filterArgs } = require('../../../_shared/allowlist.js');
|
|
13
|
+
const { writePartial, loadPartial } = require('../../../_shared/partial.js');
|
|
14
|
+
|
|
15
|
+
const REDACTED = '***REDACTED***';
|
|
16
|
+
|
|
17
|
+
// runGitleaks({ securityDir, scope, active, execFn?, detectFn?, reportFilename? })
|
|
18
|
+
// -> { ok, partialStatus, findingsCount }
|
|
19
|
+
async function runGitleaks(opts = {}) {
|
|
20
|
+
const sec = opts.securityDir;
|
|
21
|
+
const scope = opts.scope;
|
|
22
|
+
const active = opts.active === true;
|
|
23
|
+
const reportFilename = opts.reportFilename || 'gitleaks-report.json';
|
|
24
|
+
// The project to scan is the parent of `.wize/security/`. The scripts run
|
|
25
|
+
// with cwd = the kit, so we MUST point gitleaks at the target repo, not '.'.
|
|
26
|
+
const projectRoot = opts.projectRoot || (sec ? path.resolve(sec, '..', '..') : process.cwd());
|
|
27
|
+
|
|
28
|
+
const execFn = opts.execFn || ((bin, args) => {
|
|
29
|
+
return execFileSync(bin, args, { encoding: 'utf8', timeout: 5 * 60 * 1000 });
|
|
30
|
+
});
|
|
31
|
+
const detectFn = opts.detectFn || require('../../../_shared/detect.js').detectTools;
|
|
32
|
+
|
|
33
|
+
const tools = detectFn(['gitleaks'], { cacheDir: sec });
|
|
34
|
+
const present = !!(tools.gitleaks && tools.gitleaks.present);
|
|
35
|
+
|
|
36
|
+
if (!present) {
|
|
37
|
+
// Update or create sast.md with the degraded_checks entry.
|
|
38
|
+
mergeSast(sec, scope, active, tools, {
|
|
39
|
+
degraded: '- secrets: gitleaks ausente — instale gitleaks e re-rode para scan completo.'
|
|
40
|
+
});
|
|
41
|
+
return { ok: true, partialStatus: 'incomplete', findingsCount: 0 };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const reportPath = path.join(sec, reportFilename);
|
|
45
|
+
// gitleaks 8.18: `-s/--source` is the scan path, `-f/--report-format` is
|
|
46
|
+
// the output format (json), `-r/--report-path` is the file. (Earlier
|
|
47
|
+
// versions used `-f` for the path — do NOT use that here.)
|
|
48
|
+
const args = filterArgs('gitleaks', [
|
|
49
|
+
'detect', '--no-banner', '-s', projectRoot, '-f', 'json', '-r', reportPath, '--exit-code', '0'
|
|
50
|
+
]);
|
|
51
|
+
// gitleaks exits non-zero when it FINDS leaks (default exit-code 1). That
|
|
52
|
+
// is the success path for us, not an error — so we pass --exit-code 0 and
|
|
53
|
+
// also swallow any non-zero status defensively (we read the JSON report
|
|
54
|
+
// regardless).
|
|
55
|
+
try {
|
|
56
|
+
execFn('gitleaks', args, { timeout: 5 * 60 * 1000 });
|
|
57
|
+
} catch (_) {
|
|
58
|
+
// Leaks found (or gitleaks returned non-zero) — the report file is still
|
|
59
|
+
// written; we parse it below.
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Read the JSON report gitleaks wrote. It is an array of findings.
|
|
63
|
+
let findings = [];
|
|
64
|
+
if (fs.existsSync(reportPath)) {
|
|
65
|
+
try {
|
|
66
|
+
findings = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
|
|
67
|
+
} catch (_) {
|
|
68
|
+
findings = [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Build the secrets section from findings — ONLY redacted values.
|
|
73
|
+
const secretLines = findings.map(f => {
|
|
74
|
+
const file = f.File || f.file || '<unknown>';
|
|
75
|
+
const line = f.StartLine || f.startLine || '?';
|
|
76
|
+
const rule = f.RuleID || f.ruleID || 'unknown';
|
|
77
|
+
return `- **${file}** line ${line} rule \`${rule}\` — redacted_value: \`${REDACTED}\``;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Merge into existing sast.md (preserve other sections like deps from E05-S02).
|
|
81
|
+
mergeSast(sec, scope, active, tools, {
|
|
82
|
+
secrets: secretLines.length ? secretLines.join('\n') : '_(nenhum secret encontrado)_'
|
|
83
|
+
});
|
|
84
|
+
return { ok: true, partialStatus: secretLines.length ? 'complete' : 'incomplete', findingsCount: secretLines.length };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Helper: load existing sast.md, update the relevant section, and write back.
|
|
88
|
+
// Preserves sections that other SAST scripts (e.g. run-osv) added.
|
|
89
|
+
function mergeSast(sec, scope, active, tools, update) {
|
|
90
|
+
const existing = loadPartial({ securityDir: sec, phase: 'sast' });
|
|
91
|
+
const sections = {};
|
|
92
|
+
let mergedTools = Object.assign({}, tools);
|
|
93
|
+
if (existing) {
|
|
94
|
+
if (existing.body) {
|
|
95
|
+
// Extract known section bodies from the existing partial.
|
|
96
|
+
const re = /## ([a-z_]+)\n\n([\s\S]*?)(?=\n## |$)/g;
|
|
97
|
+
let m;
|
|
98
|
+
while ((m = re.exec(existing.body)) !== null) {
|
|
99
|
+
sections[m[1]] = m[2].trim();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Preserve tools detected by sibling SAST scripts (gitleaks + osv each
|
|
103
|
+
// run separately; neither should clobber the other's tools block).
|
|
104
|
+
if (existing.frontmatter && existing.frontmatter.tools) {
|
|
105
|
+
mergedTools = Object.assign({}, existing.frontmatter.tools, tools);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Apply updates.
|
|
109
|
+
if (update.degraded) {
|
|
110
|
+
// Append to degraded_checks if present, else create.
|
|
111
|
+
if (sections.degraded_checks) sections.degraded_checks += '\n' + update.degraded;
|
|
112
|
+
else sections.degraded_checks = update.degraded;
|
|
113
|
+
}
|
|
114
|
+
if (update.secrets !== undefined) sections.secrets = update.secrets;
|
|
115
|
+
|
|
116
|
+
const status = sections.degraded_checks ? 'incomplete' : 'complete';
|
|
117
|
+
writePartial({
|
|
118
|
+
securityDir: sec,
|
|
119
|
+
phase: 'sast',
|
|
120
|
+
mode: active ? 'active' : 'passive',
|
|
121
|
+
scope,
|
|
122
|
+
status,
|
|
123
|
+
tools: mergedTools,
|
|
124
|
+
sections
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { runGitleaks, mergeSast, REDACTED };
|
|
129
|
+
|
|
130
|
+
if (require.main === module) {
|
|
131
|
+
require('../../../_shared/cli-runner.js').runFromArgv({
|
|
132
|
+
fn: ({ securityDir, scopePath, active, reportFilename } = {}) => {
|
|
133
|
+
const { loadScope } = require('../../../_shared/scope-gate.js');
|
|
134
|
+
const scope = loadScope(scopePath);
|
|
135
|
+
return runGitleaks({ securityDir, scope, active, reportFilename });
|
|
136
|
+
},
|
|
137
|
+
argMap: { 'securityDir': 'securityDir', 'scope': 'scopePath', 'active': 'active', 'reportFilename': 'reportFilename' }
|
|
138
|
+
});
|
|
139
|
+
}
|