@abdulr7man/pensieve 0.0.0-stage → 1.2.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/LICENSE +684 -0
- package/README.md +180 -2
- package/VERSION +1 -0
- package/agents/README.md +16 -0
- package/agents/pensieve-code-auditor.md +58 -0
- package/agents/pensieve-mapper.md +46 -0
- package/agents/pensieve-planner.md +67 -0
- package/agents/pensieve-reconner.md +76 -0
- package/agents/pensieve-reporter.md +61 -0
- package/agents/pensieve-roe-checker.md +46 -0
- package/agents/pensieve-scoper.md +77 -0
- package/agents/pensieve-tester.md +83 -0
- package/agents/pensieve-validator.md +62 -0
- package/bin/pensieve +452 -0
- package/bin/pensieve-installer.cjs +5 -0
- package/commands/pensieve-close.md +6 -0
- package/commands/pensieve-map.md +6 -0
- package/commands/pensieve-new-engagement.md +6 -0
- package/commands/pensieve-pause.md +15 -0
- package/commands/pensieve-plan.md +6 -0
- package/commands/pensieve-progress.md +34 -0
- package/commands/pensieve-quick.md +8 -0
- package/commands/pensieve-recon.md +6 -0
- package/commands/pensieve-report.md +6 -0
- package/commands/pensieve-resume.md +6 -0
- package/commands/pensieve-retest.md +10 -0
- package/commands/pensieve-scope.md +49 -0
- package/commands/pensieve-surface.md +8 -0
- package/commands/pensieve-test.md +6 -0
- package/commands/pensieve-validate.md +6 -0
- package/docker/Dockerfile.pensieve-toolbox +75 -0
- package/docker/compose.pensieve-net.yml +37 -0
- package/docker/squid.conf.template +21 -0
- package/package.json +39 -4
- package/packs/ad/ad-killchain/checklist.md +64 -0
- package/packs/ad/ad-killchain/pack.yaml +19 -0
- package/packs/cloud/cloud-cis/checklist.md +66 -0
- package/packs/cloud/cloud-cis/pack.yaml +20 -0
- package/packs/fintech/practice-core/checklist.md +33 -0
- package/packs/fintech/practice-core/learnings.md +5 -0
- package/packs/fintech/practice-core/pack.yaml +18 -0
- package/packs/infra/ptes-infra/checklist.md +22 -0
- package/packs/infra/ptes-infra/pack.yaml +19 -0
- package/packs/mobile/owasp-masvs/checklist.md +80 -0
- package/packs/mobile/owasp-masvs/pack.yaml +20 -0
- package/packs/owasp-api-v4/checklist.md +85 -0
- package/packs/owasp-api-v4/learnings.md +6 -0
- package/packs/owasp-api-v4/pack.yaml +23 -0
- package/packs/owasp-api-v4/runbooks/API1/SKILL.md +66 -0
- package/packs/owasp-api-v4/runbooks/API10/SKILL.md +67 -0
- package/packs/owasp-api-v4/runbooks/API2/SKILL.md +129 -0
- package/packs/owasp-api-v4/runbooks/API3/SKILL.md +55 -0
- package/packs/owasp-api-v4/runbooks/API4/SKILL.md +59 -0
- package/packs/owasp-api-v4/runbooks/API5/SKILL.md +60 -0
- package/packs/owasp-api-v4/runbooks/API6/SKILL.md +63 -0
- package/packs/owasp-api-v4/runbooks/API7/SKILL.md +70 -0
- package/packs/owasp-api-v4/runbooks/API8/SKILL.md +72 -0
- package/packs/owasp-api-v4/runbooks/API9/SKILL.md +66 -0
- package/packs/thickclient/thickclient-core/checklist.md +60 -0
- package/packs/thickclient/thickclient-core/pack.yaml +24 -0
- package/packs/web/asvs-l2/checklist.md +50 -0
- package/packs/web/asvs-l2/learnings.md +6 -0
- package/packs/web/asvs-l2/pack.yaml +19 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-ENUM/SKILL.md +75 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-LIVE/SKILL.md +78 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-MFA/SKILL.md +76 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-RATE/SKILL.md +72 -0
- package/packs/web/owasp-testing-checklist/checklist.md +52 -0
- package/packs/web/owasp-testing-checklist/learnings.md +47 -0
- package/packs/web/owasp-testing-checklist/pack.yaml +21 -0
- package/packs/web/unauth-perimeter/checklist.md +72 -0
- package/packs/web/unauth-perimeter/pack.yaml +18 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-01/SKILL.md +60 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-02/SKILL.md +63 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-03/SKILL.md +62 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-04/SKILL.md +75 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-05/SKILL.md +66 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-06/SKILL.md +59 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-07/SKILL.md +56 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-08/SKILL.md +57 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-09/SKILL.md +62 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-10/SKILL.md +60 -0
- package/packs/whitebox/code-audit-core/checklist.md +36 -0
- package/packs/whitebox/code-audit-core/learnings.md +6 -0
- package/packs/whitebox/code-audit-core/pack.yaml +14 -0
- package/prompts/orchestrator-core.md +52 -0
- package/reference/attack-playbooks.md +57 -0
- package/reference/otp-relay.md +98 -0
- package/reference/param-profiles.md +48 -0
- package/reference/templates/FINDING.md +97 -0
- package/reference/tool-selection.md +64 -0
- package/reference/vulnerability-finding-standard.md +80 -0
- package/runtimes/hermes/hooks/injection-scan.py +290 -0
- package/runtimes/hermes/hooks/scope-guard.py +136 -0
- package/skills/pensieve/SKILL.md +134 -0
- package/skills/pensieve-close/SKILL.md +31 -0
- package/skills/pensieve-map/SKILL.md +25 -0
- package/skills/pensieve-new-engagement/SKILL.md +28 -0
- package/skills/pensieve-pause/SKILL.md +22 -0
- package/skills/pensieve-plan/SKILL.md +39 -0
- package/skills/pensieve-progress/SKILL.md +35 -0
- package/skills/pensieve-quick/SKILL.md +47 -0
- package/skills/pensieve-recon/SKILL.md +30 -0
- package/skills/pensieve-report/SKILL.md +46 -0
- package/skills/pensieve-resume/SKILL.md +33 -0
- package/skills/pensieve-retest/SKILL.md +35 -0
- package/skills/pensieve-scope/SKILL.md +35 -0
- package/skills/pensieve-surface/SKILL.md +36 -0
- package/skills/pensieve-test/SKILL.md +35 -0
- package/skills/pensieve-validate/SKILL.md +28 -0
- package/skills/pensieve-wiki/SKILL.md +39 -0
- package/src/installer/cli.cjs +209 -0
- package/src/installer/home.cjs +155 -0
- package/src/installer/runtimes.cjs +276 -0
- package/src/installer/uninstall.cjs +342 -0
- package/src/pensieve-sdk/bin/pensieve-sdk.cjs +1045 -0
- package/src/pensieve-sdk/lib/agent-translate.cjs +50 -0
- package/src/pensieve-sdk/lib/approvals.cjs +408 -0
- package/src/pensieve-sdk/lib/audit.cjs +290 -0
- package/src/pensieve-sdk/lib/checklist.cjs +337 -0
- package/src/pensieve-sdk/lib/clientlist.cjs +814 -0
- package/src/pensieve-sdk/lib/close.cjs +133 -0
- package/src/pensieve-sdk/lib/config.cjs +156 -0
- package/src/pensieve-sdk/lib/cvss.cjs +91 -0
- package/src/pensieve-sdk/lib/env.cjs +272 -0
- package/src/pensieve-sdk/lib/evidence.cjs +217 -0
- package/src/pensieve-sdk/lib/findings.cjs +1096 -0
- package/src/pensieve-sdk/lib/frontmatter.cjs +178 -0
- package/src/pensieve-sdk/lib/graph.cjs +607 -0
- package/src/pensieve-sdk/lib/ids.cjs +63 -0
- package/src/pensieve-sdk/lib/init.cjs +79 -0
- package/src/pensieve-sdk/lib/liveness.cjs +176 -0
- package/src/pensieve-sdk/lib/loop.cjs +619 -0
- package/src/pensieve-sdk/lib/migrate.cjs +57 -0
- package/src/pensieve-sdk/lib/monitor.cjs +69 -0
- package/src/pensieve-sdk/lib/pack.cjs +607 -0
- package/src/pensieve-sdk/lib/paths.cjs +73 -0
- package/src/pensieve-sdk/lib/pdf.cjs +291 -0
- package/src/pensieve-sdk/lib/recon.cjs +296 -0
- package/src/pensieve-sdk/lib/renderers/__pycache__/formal_report.cpython-314.pyc +0 -0
- package/src/pensieve-sdk/lib/renderers/formal_report.py +608 -0
- package/src/pensieve-sdk/lib/report.cjs +1135 -0
- package/src/pensieve-sdk/lib/runbook.cjs +124 -0
- package/src/pensieve-sdk/lib/sarif.cjs +154 -0
- package/src/pensieve-sdk/lib/scope.cjs +621 -0
- package/src/pensieve-sdk/lib/security.cjs +61 -0
- package/src/pensieve-sdk/lib/skills.cjs +193 -0
- package/src/pensieve-sdk/lib/state.cjs +610 -0
- package/src/pensieve-sdk/lib/subagent.cjs +658 -0
- package/src/pensieve-sdk/lib/target.cjs +149 -0
- package/src/pensieve-sdk/lib/tools.cjs +66 -0
- package/src/pensieve-sdk/lib/vault.cjs +122 -0
- package/src/pensieve-sdk/lib/vendor/cvss40.LICENSE +22 -0
- package/src/pensieve-sdk/lib/vendor/cvss40.js +1208 -0
- package/src/pensieve-sdk/package.json +11 -0
- package/templates/ACCOUNTS.md +35 -0
- package/templates/ATTACK-SURFACE.md +30 -0
- package/templates/FINDING.md +43 -0
- package/templates/PLAN.md +33 -0
- package/templates/PROJECT.md +29 -0
- package/templates/ROE.md +50 -0
- package/templates/RUN-LOG.md +19 -0
- package/templates/SCOPE.md +32 -0
- package/templates/VALIDATION.md +62 -0
- package/templates/report/REPORT.md +49 -0
- package/workflows/close.md +34 -0
- package/workflows/map.md +39 -0
- package/workflows/new-engagement.md +37 -0
- package/workflows/plan.md +45 -0
- package/workflows/progress.md +28 -0
- package/workflows/quick.md +67 -0
- package/workflows/recon.md +87 -0
- package/workflows/report.md +51 -0
- package/workflows/resume.md +26 -0
- package/workflows/retest.md +53 -0
- package/workflows/scope.md +47 -0
- package/workflows/surface.md +29 -0
- package/workflows/test.md +95 -0
- package/workflows/validate.md +34 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* target.cjs — cross-engagement target profiles (v0.6 05-02).
|
|
4
|
+
*
|
|
5
|
+
* Home: $PENSIEVE_HOME/targets/<host>/TARGET-PROFILE.md (default ~/.pensieve/).
|
|
6
|
+
* A profile captures what an engagement had to figure out the hard way about an
|
|
7
|
+
* asset — the login flow, auth method, session/token handling, WAF signature —
|
|
8
|
+
* so a later engagement against the same host REUSES it instead of
|
|
9
|
+
* re-discovering it (saving time and tokens).
|
|
10
|
+
*
|
|
11
|
+
* Recognition is automatic, per the design: recon/map call recognize(host) on
|
|
12
|
+
* every asset they identify; a known profile is auto-loaded (reuse_count
|
|
13
|
+
* bumped, last_seen stamped) and the engagement skips login discovery. No
|
|
14
|
+
* human pick. Learning is the reverse: when an engagement works out a login
|
|
15
|
+
* flow, it saves it with target.put and the next engagement picks it up.
|
|
16
|
+
*/
|
|
17
|
+
const fs = require('node:fs');
|
|
18
|
+
const os = require('node:os');
|
|
19
|
+
const path = require('node:path');
|
|
20
|
+
const fm = require('./frontmatter.cjs');
|
|
21
|
+
const paths = require('./paths.cjs');
|
|
22
|
+
|
|
23
|
+
function pensieveHome() {
|
|
24
|
+
return paths.pensieveHome();
|
|
25
|
+
}
|
|
26
|
+
function targetsDir() { return path.join(pensieveHome(), 'targets'); }
|
|
27
|
+
|
|
28
|
+
// Normalize to a bare host key: strip scheme, path, port; lowercase; safe chars.
|
|
29
|
+
// https://Example-Gate.Test:8443/api/login -> example-gate.test
|
|
30
|
+
function sanitizeHost(host) {
|
|
31
|
+
let h = String(host || '').trim().toLowerCase();
|
|
32
|
+
h = h.replace(/^https?:\/\//, '');
|
|
33
|
+
h = h.split('/')[0];
|
|
34
|
+
h = h.split(':')[0];
|
|
35
|
+
h = h.replace(/[^a-z0-9.-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
36
|
+
return h;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function targetDir(host) { return path.join(targetsDir(), sanitizeHost(host)); }
|
|
40
|
+
function targetFile(host) { return path.join(targetDir(host), 'TARGET-PROFILE.md'); }
|
|
41
|
+
|
|
42
|
+
/** get(host) — the parsed profile, or null when the host is unknown. */
|
|
43
|
+
function get(host) {
|
|
44
|
+
const f = targetFile(host);
|
|
45
|
+
if (!fs.existsSync(f)) return null;
|
|
46
|
+
const text = fs.readFileSync(f, 'utf8');
|
|
47
|
+
const { data, body } = fm.parse(text);
|
|
48
|
+
return { file: f, host: sanitizeHost(host), data, body };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Replace (or append) a "## <heading>" prose section in a markdown body.
|
|
52
|
+
function setSection(body, heading, text) {
|
|
53
|
+
const lines = String(body).split('\n');
|
|
54
|
+
const re = new RegExp('^##\\s+' + heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\s*$');
|
|
55
|
+
let start = -1;
|
|
56
|
+
let end = lines.length;
|
|
57
|
+
for (let i = 0; i < lines.length; i++) {
|
|
58
|
+
if (re.test(lines[i])) { start = i; break; }
|
|
59
|
+
}
|
|
60
|
+
if (start === -1) {
|
|
61
|
+
return String(body).replace(/\s*$/, '') + `\n\n## ${heading}\n\n${text}\n`;
|
|
62
|
+
}
|
|
63
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
64
|
+
if (/^##\s+/.test(lines[i])) { end = i; break; }
|
|
65
|
+
}
|
|
66
|
+
const before = lines.slice(0, start + 1);
|
|
67
|
+
const after = lines.slice(end);
|
|
68
|
+
return [...before, '', String(text), '', ...after].join('\n').replace(/\n{3,}/g, '\n\n');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* put(host, fields) — create or merge a target profile. Structured fields go
|
|
73
|
+
* into frontmatter; the special keys login_flow and notes are prose and go into
|
|
74
|
+
* the body's "## Login flow" / "## Notes" sections. Merge never clobbers a
|
|
75
|
+
* field that is already set (pass an explicit value to change one).
|
|
76
|
+
*/
|
|
77
|
+
function put(host, fields = {}) {
|
|
78
|
+
const h = sanitizeHost(host);
|
|
79
|
+
if (!h) throw new Error('target.put requires a host');
|
|
80
|
+
const existing = get(h);
|
|
81
|
+
const now = new Date().toISOString();
|
|
82
|
+
const { login_flow, notes, ...fmFields } = fields;
|
|
83
|
+
|
|
84
|
+
const data = existing ? { ...existing.data } : { host: h, first_seen: now, reuse_count: 0 };
|
|
85
|
+
for (const [k, v] of Object.entries(fmFields)) {
|
|
86
|
+
if (v !== undefined && v !== null && v !== '') data[k] = v;
|
|
87
|
+
}
|
|
88
|
+
data.host = h;
|
|
89
|
+
data.last_seen = now;
|
|
90
|
+
if (typeof data.reuse_count !== 'number') data.reuse_count = 0;
|
|
91
|
+
|
|
92
|
+
let body = existing
|
|
93
|
+
? existing.body
|
|
94
|
+
: `# Target profile: ${h}\n\n## Login flow\n\n(not yet captured)\n\n## Notes\n\n(none)\n`;
|
|
95
|
+
if (login_flow !== undefined) body = setSection(body, 'Login flow', login_flow);
|
|
96
|
+
if (notes !== undefined) body = setSection(body, 'Notes', notes);
|
|
97
|
+
|
|
98
|
+
fs.mkdirSync(targetDir(h), { recursive: true });
|
|
99
|
+
fs.writeFileSync(targetFile(h), fm.stringify(data, body));
|
|
100
|
+
return { file: targetFile(h), host: h, created: !existing, data };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* recognize(host) — the automatic reuse path. Unknown host -> {known:false}
|
|
105
|
+
* (a miss, not a prompt). Known host -> the profile is auto-loaded AND the
|
|
106
|
+
* reuse is recorded (reuse_count +1, last_seen stamped), so the audit trail
|
|
107
|
+
* shows the profile was reused rather than rediscovered.
|
|
108
|
+
*/
|
|
109
|
+
function recognize(host) {
|
|
110
|
+
const h = sanitizeHost(host);
|
|
111
|
+
const existing = get(h);
|
|
112
|
+
if (!existing) return { known: false, host: h, profile: null };
|
|
113
|
+
const now = new Date().toISOString();
|
|
114
|
+
const data = { ...existing.data, last_seen: now, reuse_count: (existing.data.reuse_count || 0) + 1 };
|
|
115
|
+
fs.writeFileSync(existing.file, fm.stringify(data, existing.body));
|
|
116
|
+
return { known: true, host: h, profile: { ...data, body: existing.body }, file: existing.file };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** list() — every known target with the key reuse fields, sorted by host. */
|
|
120
|
+
function list() {
|
|
121
|
+
const dir = targetsDir();
|
|
122
|
+
if (!fs.existsSync(dir)) return [];
|
|
123
|
+
return fs.readdirSync(dir, { withFileTypes: true })
|
|
124
|
+
.filter((d) => d.isDirectory())
|
|
125
|
+
.map((d) => {
|
|
126
|
+
const p = get(d.name);
|
|
127
|
+
if (!p) return null;
|
|
128
|
+
return {
|
|
129
|
+
host: p.host,
|
|
130
|
+
auth_method: p.data.auth_method || null,
|
|
131
|
+
login_endpoint: p.data.login_endpoint || null,
|
|
132
|
+
waf: p.data.waf || null,
|
|
133
|
+
reuse_count: p.data.reuse_count || 0,
|
|
134
|
+
last_seen: p.data.last_seen || null,
|
|
135
|
+
};
|
|
136
|
+
})
|
|
137
|
+
.filter(Boolean)
|
|
138
|
+
.sort((a, b) => a.host.localeCompare(b.host));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** remove(host) — delete a profile (human veto / stale-asset cleanup). */
|
|
142
|
+
function remove(host) {
|
|
143
|
+
const dir = targetDir(host);
|
|
144
|
+
if (!fs.existsSync(dir)) return false;
|
|
145
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = { get, put, recognize, list, remove, sanitizeHost, targetsDir, targetFile };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* tools.cjs — just-in-time tool provisioning (ADR-014).
|
|
4
|
+
* Install-time footprint is the Kali toolbox image ONLY. Anything else is
|
|
5
|
+
* provisioned per-engagement, after explicit user approval, and recorded.
|
|
6
|
+
*
|
|
7
|
+
* Pack manifests declare tools as pipe-delimited strings (survives the
|
|
8
|
+
* frontmatter subset parser):
|
|
9
|
+
* tools:
|
|
10
|
+
* - "httpx|A|builtin|httpx"
|
|
11
|
+
* - "nbtscan|A|apt|nbtscan"
|
|
12
|
+
* - "jwt_tool|A|pip|jwt_tool"
|
|
13
|
+
* - "joern|B|host-manual|see https://joern.io"
|
|
14
|
+
* name | lane(A=toolbox, B=host) | kind(builtin|apt|pip|host-manual) | spec
|
|
15
|
+
*
|
|
16
|
+
* Safety: lane B is NEVER auto-installed — planActions returns 'manual' with
|
|
17
|
+
* instructions; the human runs it (and the plan checkpoint approves it).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function parseTools(lines) {
|
|
21
|
+
if (!Array.isArray(lines)) return [];
|
|
22
|
+
const rows = [];
|
|
23
|
+
for (const raw of lines) {
|
|
24
|
+
const s = String(raw || '').trim().replace(/^["']|["']$/g, '');
|
|
25
|
+
if (!s) continue;
|
|
26
|
+
const [name, lane, kind, ...rest] = s.split('|').map((x) => x.trim());
|
|
27
|
+
rows.push({
|
|
28
|
+
name,
|
|
29
|
+
lane: lane === 'B' ? 'B' : 'A',
|
|
30
|
+
kind: kind || 'builtin',
|
|
31
|
+
spec: rest.join('|') || name,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return rows;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function planActions(rows, presentSet) {
|
|
38
|
+
return rows.map((t) => {
|
|
39
|
+
if (presentSet.has(t.name)) return { name: t.name, action: 'present' };
|
|
40
|
+
if (t.lane === 'B' || t.kind === 'host-manual') {
|
|
41
|
+
return { name: t.name, action: 'manual', lane: 'B', instructions: t.spec };
|
|
42
|
+
}
|
|
43
|
+
if (t.kind === 'apt' || t.kind === 'pip') {
|
|
44
|
+
return { name: t.name, action: 'install', how: t.kind, spec: t.spec };
|
|
45
|
+
}
|
|
46
|
+
return { name: t.name, action: 'missing-builtin', note: `${t.name} expected in toolbox image but not found — rebuild or add an apt/pip entry` };
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const PROXY = 'http://egress:3128';
|
|
51
|
+
|
|
52
|
+
function provisioningHosts(kind) {
|
|
53
|
+
if (kind === 'apt') return ['archive.ubuntu.com', 'security.ubuntu.com', 'ports.ubuntu.com', 'kali.download', 'http.kali.org'];
|
|
54
|
+
if (kind === 'pip') return ['pypi.org', 'files.pythonhosted.org'];
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function installCommands(plan) {
|
|
59
|
+
return plan
|
|
60
|
+
.filter((p) => p.action === 'install')
|
|
61
|
+
.map((p) => (p.how === 'apt'
|
|
62
|
+
? `apt-get update -o Acquire::http::Proxy=${PROXY} -o Acquire::https::Proxy=${PROXY} && apt-get install -y -o Acquire::http::Proxy=${PROXY} -o Acquire::https::Proxy=${PROXY} ${p.spec}`
|
|
63
|
+
: `pip install ${p.spec} --break-system-packages || pip install ${p.spec}`));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { parseTools, planActions, installCommands, provisioningHosts };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* vault.cjs — the per-engagement credential vault (Phase 23, VAULT-01).
|
|
4
|
+
*
|
|
5
|
+
* Storage: <engagement>/.env — a JSON object of key -> string value, written
|
|
6
|
+
* ATOMICALLY (temp + rename) with chmod 0600 on every write, and kept out of
|
|
7
|
+
* git by the init scaffold's .gitignore entry.
|
|
8
|
+
*
|
|
9
|
+
* Masked read-back is the ONLY read surface this module exports: key, length
|
|
10
|
+
* and the first 8 hex chars of the value's sha256. There is DELIBERATELY no
|
|
11
|
+
* function or CLI flag that prints a value — consumers that need the actual
|
|
12
|
+
* secret read the 0600 file directly with their own tooling. No error message
|
|
13
|
+
* on any path embeds a value (or the raw file contents).
|
|
14
|
+
*
|
|
15
|
+
* Rotation (owner rule from the operational record): set() on an EXISTING key
|
|
16
|
+
* moves the current value to `<key>.old.<n>` (next free integer) before the
|
|
17
|
+
* new value is stored — old values are never lost. Rotated credentials are
|
|
18
|
+
* persisted immediately, in the same atomic write.
|
|
19
|
+
*
|
|
20
|
+
* The SDK never reads the vault itself beyond this module: tools/agents
|
|
21
|
+
* reference it (evidence.cjs loads KEY NAMES only, for the leak warning).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const fs = require('node:fs');
|
|
25
|
+
const path = require('node:path');
|
|
26
|
+
const crypto = require('node:crypto');
|
|
27
|
+
|
|
28
|
+
const KEY_RE = /^[A-Za-z0-9_][A-Za-z0-9._-]{0,127}$/;
|
|
29
|
+
|
|
30
|
+
const vaultFile = (engagementDir) => path.join(engagementDir, '.env');
|
|
31
|
+
|
|
32
|
+
function mask(value) {
|
|
33
|
+
return { length: value.length, sha8: crypto.createHash('sha256').update(value).digest('hex').slice(0, 8) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* readVault — parse <engagement>/.env. Missing file -> {} (fresh engagement).
|
|
38
|
+
* A file that EXISTS but does not parse refuses loudly: silently treating it
|
|
39
|
+
* as empty would let the next set() wipe every stored credential.
|
|
40
|
+
* The thrown error never embeds the file's contents.
|
|
41
|
+
*/
|
|
42
|
+
function readVault(engagementDir) {
|
|
43
|
+
let text;
|
|
44
|
+
try {
|
|
45
|
+
text = fs.readFileSync(vaultFile(engagementDir), 'utf8');
|
|
46
|
+
} catch {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const v = JSON.parse(text);
|
|
51
|
+
if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('not an object');
|
|
52
|
+
return v;
|
|
53
|
+
} catch {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`vault file is not valid JSON (${vaultFile(engagementDir)}) — refusing to overwrite; inspect it manually`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** atomic write: temp file (created 0600) -> chmod 0600 -> rename over target -> chmod 0600 again */
|
|
61
|
+
function writeVault(engagementDir, data) {
|
|
62
|
+
const file = vaultFile(engagementDir);
|
|
63
|
+
const tmp = path.join(path.dirname(file), `.env.tmp-${process.pid}-${Date.now()}`);
|
|
64
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n', { mode: 0o600 });
|
|
65
|
+
fs.chmodSync(tmp, 0o600); // writeFileSync mode applies at creation only — enforce on every write
|
|
66
|
+
fs.renameSync(tmp, file);
|
|
67
|
+
fs.chmodSync(file, 0o600);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** keys() — key NAMES only (never values); evidence.put's leak warning scans these. */
|
|
71
|
+
function keys(engagementDir) {
|
|
72
|
+
return Object.keys(readVault(engagementDir)).sort();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* set — write/rotate one slot. Value must be a non-empty string (the CLI reads
|
|
77
|
+
* it from stdin). Returns the MASKED result; `previous_slot` names where the
|
|
78
|
+
* old value was preserved (`<key>.old.<n>`), or null on first write.
|
|
79
|
+
*/
|
|
80
|
+
function set(engagementDir, key, value) {
|
|
81
|
+
if (typeof key !== 'string' || !KEY_RE.test(key)) {
|
|
82
|
+
throw new Error(`invalid vault key name ${JSON.stringify(key)} — must match ${KEY_RE}`);
|
|
83
|
+
}
|
|
84
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
85
|
+
throw new Error('vault value required (non-empty string)');
|
|
86
|
+
}
|
|
87
|
+
const v = readVault(engagementDir);
|
|
88
|
+
let previousSlot = null;
|
|
89
|
+
if (Object.prototype.hasOwnProperty.call(v, key)) {
|
|
90
|
+
let n = 1;
|
|
91
|
+
while (Object.prototype.hasOwnProperty.call(v, `${key}.old.${n}`)) n++;
|
|
92
|
+
previousSlot = `${key}.old.${n}`;
|
|
93
|
+
v[previousSlot] = v[key]; // old value preserved — never lost
|
|
94
|
+
}
|
|
95
|
+
v[key] = value;
|
|
96
|
+
writeVault(engagementDir, v); // single atomic write covers rotation + new value
|
|
97
|
+
return { key, ...mask(value), rotated: previousSlot != null, previous_slot: previousSlot };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** getMasked — {key, length, sha8}. Unknown key throws naming the KEY only. */
|
|
101
|
+
function getMasked(engagementDir, key) {
|
|
102
|
+
const v = readVault(engagementDir);
|
|
103
|
+
if (!Object.prototype.hasOwnProperty.call(v, key)) {
|
|
104
|
+
throw new Error(`unknown vault key: ${key}`);
|
|
105
|
+
}
|
|
106
|
+
return { key, ...mask(v[key]) };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** list — every slot (including preserved .old.<n>) with a masked fingerprint. */
|
|
110
|
+
function list(engagementDir) {
|
|
111
|
+
const v = readVault(engagementDir);
|
|
112
|
+
return Object.keys(v).sort().map((k) => ({ key: k, ...mask(v[k]) }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** verify — does the key exist? Masked fingerprint included on a hit; no value ever. */
|
|
116
|
+
function verify(engagementDir, key) {
|
|
117
|
+
const v = readVault(engagementDir);
|
|
118
|
+
if (!Object.prototype.hasOwnProperty.call(v, key)) return { key, exists: false };
|
|
119
|
+
return { key, exists: true, ...mask(v[key]) };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = { set, getMasked, list, verify, keys, vaultFile };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2023 FIRST.ORG, Inc., Red Hat, and contributors
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
14
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
17
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
18
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
19
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
20
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
21
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
22
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|