defense-mcp-server 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.
Files changed (186) hide show
  1. package/CHANGELOG.md +471 -0
  2. package/LICENSE +21 -0
  3. package/README.md +242 -0
  4. package/build/core/auto-installer.d.ts +102 -0
  5. package/build/core/auto-installer.d.ts.map +1 -0
  6. package/build/core/auto-installer.js +833 -0
  7. package/build/core/backup-manager.d.ts +63 -0
  8. package/build/core/backup-manager.d.ts.map +1 -0
  9. package/build/core/backup-manager.js +189 -0
  10. package/build/core/changelog.d.ts +75 -0
  11. package/build/core/changelog.d.ts.map +1 -0
  12. package/build/core/changelog.js +123 -0
  13. package/build/core/command-allowlist.d.ts +129 -0
  14. package/build/core/command-allowlist.d.ts.map +1 -0
  15. package/build/core/command-allowlist.js +849 -0
  16. package/build/core/config.d.ts +79 -0
  17. package/build/core/config.d.ts.map +1 -0
  18. package/build/core/config.js +193 -0
  19. package/build/core/dependency-validator.d.ts +106 -0
  20. package/build/core/dependency-validator.d.ts.map +1 -0
  21. package/build/core/dependency-validator.js +405 -0
  22. package/build/core/distro-adapter.d.ts +177 -0
  23. package/build/core/distro-adapter.d.ts.map +1 -0
  24. package/build/core/distro-adapter.js +481 -0
  25. package/build/core/distro.d.ts +68 -0
  26. package/build/core/distro.d.ts.map +1 -0
  27. package/build/core/distro.js +457 -0
  28. package/build/core/encrypted-state.d.ts +76 -0
  29. package/build/core/encrypted-state.d.ts.map +1 -0
  30. package/build/core/encrypted-state.js +209 -0
  31. package/build/core/executor.d.ts +56 -0
  32. package/build/core/executor.d.ts.map +1 -0
  33. package/build/core/executor.js +350 -0
  34. package/build/core/installer.d.ts +92 -0
  35. package/build/core/installer.d.ts.map +1 -0
  36. package/build/core/installer.js +1072 -0
  37. package/build/core/logger.d.ts +102 -0
  38. package/build/core/logger.d.ts.map +1 -0
  39. package/build/core/logger.js +132 -0
  40. package/build/core/parsers.d.ts +151 -0
  41. package/build/core/parsers.d.ts.map +1 -0
  42. package/build/core/parsers.js +479 -0
  43. package/build/core/policy-engine.d.ts +170 -0
  44. package/build/core/policy-engine.d.ts.map +1 -0
  45. package/build/core/policy-engine.js +656 -0
  46. package/build/core/preflight.d.ts +157 -0
  47. package/build/core/preflight.d.ts.map +1 -0
  48. package/build/core/preflight.js +638 -0
  49. package/build/core/privilege-manager.d.ts +108 -0
  50. package/build/core/privilege-manager.d.ts.map +1 -0
  51. package/build/core/privilege-manager.js +363 -0
  52. package/build/core/rate-limiter.d.ts +67 -0
  53. package/build/core/rate-limiter.d.ts.map +1 -0
  54. package/build/core/rate-limiter.js +129 -0
  55. package/build/core/rollback.d.ts +73 -0
  56. package/build/core/rollback.d.ts.map +1 -0
  57. package/build/core/rollback.js +278 -0
  58. package/build/core/safeguards.d.ts +58 -0
  59. package/build/core/safeguards.d.ts.map +1 -0
  60. package/build/core/safeguards.js +448 -0
  61. package/build/core/sanitizer.d.ts +118 -0
  62. package/build/core/sanitizer.d.ts.map +1 -0
  63. package/build/core/sanitizer.js +459 -0
  64. package/build/core/secure-fs.d.ts +67 -0
  65. package/build/core/secure-fs.d.ts.map +1 -0
  66. package/build/core/secure-fs.js +143 -0
  67. package/build/core/spawn-safe.d.ts +55 -0
  68. package/build/core/spawn-safe.d.ts.map +1 -0
  69. package/build/core/spawn-safe.js +146 -0
  70. package/build/core/sudo-guard.d.ts +145 -0
  71. package/build/core/sudo-guard.d.ts.map +1 -0
  72. package/build/core/sudo-guard.js +349 -0
  73. package/build/core/sudo-session.d.ts +100 -0
  74. package/build/core/sudo-session.d.ts.map +1 -0
  75. package/build/core/sudo-session.js +319 -0
  76. package/build/core/tool-dependencies.d.ts +61 -0
  77. package/build/core/tool-dependencies.d.ts.map +1 -0
  78. package/build/core/tool-dependencies.js +571 -0
  79. package/build/core/tool-registry.d.ts +111 -0
  80. package/build/core/tool-registry.d.ts.map +1 -0
  81. package/build/core/tool-registry.js +656 -0
  82. package/build/core/tool-wrapper.d.ts +73 -0
  83. package/build/core/tool-wrapper.d.ts.map +1 -0
  84. package/build/core/tool-wrapper.js +296 -0
  85. package/build/index.d.ts +3 -0
  86. package/build/index.d.ts.map +1 -0
  87. package/build/index.js +247 -0
  88. package/build/tools/access-control.d.ts +9 -0
  89. package/build/tools/access-control.d.ts.map +1 -0
  90. package/build/tools/access-control.js +1818 -0
  91. package/build/tools/api-security.d.ts +12 -0
  92. package/build/tools/api-security.d.ts.map +1 -0
  93. package/build/tools/api-security.js +901 -0
  94. package/build/tools/app-hardening.d.ts +11 -0
  95. package/build/tools/app-hardening.d.ts.map +1 -0
  96. package/build/tools/app-hardening.js +768 -0
  97. package/build/tools/backup.d.ts +8 -0
  98. package/build/tools/backup.d.ts.map +1 -0
  99. package/build/tools/backup.js +381 -0
  100. package/build/tools/cloud-security.d.ts +17 -0
  101. package/build/tools/cloud-security.d.ts.map +1 -0
  102. package/build/tools/cloud-security.js +739 -0
  103. package/build/tools/compliance.d.ts +10 -0
  104. package/build/tools/compliance.d.ts.map +1 -0
  105. package/build/tools/compliance.js +1225 -0
  106. package/build/tools/container-security.d.ts +14 -0
  107. package/build/tools/container-security.d.ts.map +1 -0
  108. package/build/tools/container-security.js +788 -0
  109. package/build/tools/deception.d.ts +13 -0
  110. package/build/tools/deception.d.ts.map +1 -0
  111. package/build/tools/deception.js +763 -0
  112. package/build/tools/dns-security.d.ts +93 -0
  113. package/build/tools/dns-security.d.ts.map +1 -0
  114. package/build/tools/dns-security.js +745 -0
  115. package/build/tools/drift-detection.d.ts +8 -0
  116. package/build/tools/drift-detection.d.ts.map +1 -0
  117. package/build/tools/drift-detection.js +326 -0
  118. package/build/tools/ebpf-security.d.ts +15 -0
  119. package/build/tools/ebpf-security.d.ts.map +1 -0
  120. package/build/tools/ebpf-security.js +294 -0
  121. package/build/tools/encryption.d.ts +9 -0
  122. package/build/tools/encryption.d.ts.map +1 -0
  123. package/build/tools/encryption.js +1667 -0
  124. package/build/tools/firewall.d.ts +9 -0
  125. package/build/tools/firewall.d.ts.map +1 -0
  126. package/build/tools/firewall.js +1398 -0
  127. package/build/tools/hardening.d.ts +10 -0
  128. package/build/tools/hardening.d.ts.map +1 -0
  129. package/build/tools/hardening.js +2654 -0
  130. package/build/tools/ids.d.ts +9 -0
  131. package/build/tools/ids.d.ts.map +1 -0
  132. package/build/tools/ids.js +624 -0
  133. package/build/tools/incident-response.d.ts +10 -0
  134. package/build/tools/incident-response.d.ts.map +1 -0
  135. package/build/tools/incident-response.js +1180 -0
  136. package/build/tools/logging.d.ts +12 -0
  137. package/build/tools/logging.d.ts.map +1 -0
  138. package/build/tools/logging.js +454 -0
  139. package/build/tools/malware.d.ts +10 -0
  140. package/build/tools/malware.d.ts.map +1 -0
  141. package/build/tools/malware.js +532 -0
  142. package/build/tools/meta.d.ts +11 -0
  143. package/build/tools/meta.d.ts.map +1 -0
  144. package/build/tools/meta.js +2278 -0
  145. package/build/tools/network-defense.d.ts +12 -0
  146. package/build/tools/network-defense.d.ts.map +1 -0
  147. package/build/tools/network-defense.js +760 -0
  148. package/build/tools/patch-management.d.ts +3 -0
  149. package/build/tools/patch-management.d.ts.map +1 -0
  150. package/build/tools/patch-management.js +708 -0
  151. package/build/tools/process-security.d.ts +12 -0
  152. package/build/tools/process-security.d.ts.map +1 -0
  153. package/build/tools/process-security.js +784 -0
  154. package/build/tools/reporting.d.ts +11 -0
  155. package/build/tools/reporting.d.ts.map +1 -0
  156. package/build/tools/reporting.js +559 -0
  157. package/build/tools/secrets.d.ts +9 -0
  158. package/build/tools/secrets.d.ts.map +1 -0
  159. package/build/tools/secrets.js +596 -0
  160. package/build/tools/siem-integration.d.ts +18 -0
  161. package/build/tools/siem-integration.d.ts.map +1 -0
  162. package/build/tools/siem-integration.js +754 -0
  163. package/build/tools/sudo-management.d.ts +18 -0
  164. package/build/tools/sudo-management.d.ts.map +1 -0
  165. package/build/tools/sudo-management.js +737 -0
  166. package/build/tools/supply-chain-security.d.ts +8 -0
  167. package/build/tools/supply-chain-security.d.ts.map +1 -0
  168. package/build/tools/supply-chain-security.js +256 -0
  169. package/build/tools/threat-intel.d.ts +22 -0
  170. package/build/tools/threat-intel.d.ts.map +1 -0
  171. package/build/tools/threat-intel.js +749 -0
  172. package/build/tools/vulnerability-management.d.ts +11 -0
  173. package/build/tools/vulnerability-management.d.ts.map +1 -0
  174. package/build/tools/vulnerability-management.js +667 -0
  175. package/build/tools/waf.d.ts +12 -0
  176. package/build/tools/waf.d.ts.map +1 -0
  177. package/build/tools/waf.js +843 -0
  178. package/build/tools/wireless-security.d.ts +19 -0
  179. package/build/tools/wireless-security.d.ts.map +1 -0
  180. package/build/tools/wireless-security.js +826 -0
  181. package/build/tools/zero-trust-network.d.ts +8 -0
  182. package/build/tools/zero-trust-network.d.ts.map +1 -0
  183. package/build/tools/zero-trust-network.js +367 -0
  184. package/docs/SAFEGUARDS.md +518 -0
  185. package/docs/TOOLS-REFERENCE.md +665 -0
  186. package/package.json +87 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,471 @@
1
+ # Changelog
2
+
3
+ All notable changes to the defense-mcp-server are documented in this file.
4
+
5
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+
7
+ ---
8
+
9
+ ## [0.6.0] — 2026-03-09
10
+
11
+ ### v0.6.0 — 16 New Security Tools
12
+
13
+ #### Added
14
+ - **Reporting** — `report_export` tool: generate consolidated security reports in Markdown/HTML/JSON/CSV
15
+ - **DNS Security** — `dns_security` tool: DNSSEC validation, DNS tunneling detection, domain blocklists, query log analysis
16
+ - **Vulnerability Management** — `vuln_manage` tool: nmap/nikto vulnerability scanning, vulnerability lifecycle tracking, risk prioritization
17
+ - **Forensics** — `ir_forensics` tool: memory acquisition, forensic disk imaging, evidence chain-of-custody
18
+ - **Process Security** — `process_security` tool: capability auditing, namespace isolation, anomaly detection (deleted binaries, shell spawning)
19
+ - **WAF Management** — `waf_manage` tool: ModSecurity audit/rules, OWASP CRS deployment, rate limiting, WAF log analysis
20
+ - **Network Segmentation** — `network_segmentation_audit` tool: zone mapping, isolation verification, path testing, VLAN auditing
21
+ - **Threat Intelligence** — `threat_intel` tool: IP/hash/domain checking against feeds, blocklist application to iptables/fail2ban
22
+ - **Auto-Remediation** — `auto_remediate` tool: consolidated remediation planning, batch safe-fix application with rollback sessions
23
+ - **Cloud Security** — `cloud_security` tool: AWS/GCP/Azure detection, IMDS security, IAM credential scanning, cloud storage audit
24
+ - **API Security** — `api_security` tool: local API discovery, auth auditing, rate-limit testing, TLS verification, CORS checking
25
+ - **Deception/Honeypots** — `honeypot_manage` tool: canary token deployment, honeyport listeners, trigger monitoring
26
+ - **Wireless Security** — `wireless_security` tool: Bluetooth/WiFi auditing, rogue AP detection, interface disabling
27
+ - **Certificate Lifecycle** — `certificate_lifecycle` tool: cert inventory, Let's Encrypt renewal check, CA trust store audit, OCSP, CT logs
28
+ - **SIEM Integration** — `siem_export` tool: rsyslog/Filebeat configuration, log forwarding audit, connectivity testing
29
+ - **USB Device Control** — `usb_device_control` tool: device auditing, storage blocking (modprobe/udev), whitelisting, event monitoring
30
+
31
+ #### Infrastructure
32
+ - Added 37 new binary entries to command allowlist
33
+ - Added 16 new tool dependency declarations
34
+ - Updated TOOLS-REFERENCE.md with documentation for all 16 new tools
35
+ - 1,801 total tests passing across 60 test files
36
+
37
+ ---
38
+
39
+ ## [0.5.2] — 2026-03-09
40
+
41
+ ### Security
42
+ - Upgraded `@modelcontextprotocol/sdk` from 1.12.3 to 1.27.1 (fixes 3 high-severity CVEs: ReDoS, cross-client data leak, DNS rebinding)
43
+ - Removed accidental self-referential dependency
44
+ - `npm audit` now reports 0 vulnerabilities
45
+
46
+ ---
47
+
48
+ ## [0.5.1] — 2026-03-09
49
+
50
+ ### Stable Release
51
+ First stable release incorporating complete security audit remediation.
52
+
53
+ - **78 security findings resolved** (12 Critical, 22 High, 29 Medium, 15 Low)
54
+ - **1054 tests** across 49 test files (71.66% line coverage)
55
+ - **78 defensive security tools** across 21 modules
56
+ - Clean TypeScript build with zero errors
57
+ - Pinned runtime dependencies for reproducible builds
58
+ - Published to npm as stable release
59
+
60
+ See [CHANGELOG for 0.5.0-beta.3 through 0.5.0-beta.6](CHANGELOG.md) for detailed remediation history.
61
+
62
+ ---
63
+
64
+ ## [0.5.0-beta.5] — 2026-03-08
65
+
66
+ ### GA Readiness — Phase 10
67
+ - **Tool naming consistency:** 7 tools renamed to follow `prefix_subject` convention
68
+ - **Specification rewrite:** Complete rewrite of defense-mcp-server-spec.md (12 sections)
69
+ - **Dependency pinning:** Runtime deps pinned to exact versions, dev deps to tilde ranges
70
+ - **Encrypted state storage:** New `src/core/encrypted-state.ts` — AES-256-GCM with PBKDF2 key derivation
71
+ - **Atomic file writes:** New `atomicWriteFileSync()` in `src/core/secure-fs.ts` with write-to-temp-then-rename
72
+ - **Test coverage:** 1054 tests across 49 files (up from 421/12 at audit baseline)
73
+ - **Pen test requirements:** Documented in docs/PENTEST-REQUIREMENTS.md
74
+ - **Documentation sync:** All 7 documentation files updated to v0.5.0 with accurate module/tool counts
75
+
76
+ ### Summary Since Audit (v0.5.0-beta.2 → v0.5.0-beta.5)
77
+ - **78/78 security findings** resolved (12 Critical, 22 High, 29 Medium, 15 Low)
78
+ - **Security score:** 36/100 → target 80+ (pending re-assessment)
79
+ - **Tests:** 421 → 1054 (+150%)
80
+ - **New security infrastructure:** Rate limiter, structured logger, encrypted state, atomic writes, CodeQL SAST, ESLint security, husky pre-commit
81
+
82
+ ---
83
+
84
+ ## [0.5.0-rc.1] — 2026-03-07
85
+
86
+ ### Security — Complete Audit Remediation (Phases 7-9)
87
+
88
+ #### Phase 7: Medium-Severity Fixes (29/29) ✅
89
+ - **Core hardening (7):** stdin buffer zeroing on error (CORE-011), config rejects `/` in allowedDirs (CORE-012), policy savePolicy uses secure-fs (CORE-013), resolveCommandSafe fails hard instead of bare fallback (CORE-014), backup manager path traversal protection (CORE-015), askpass candidate verification (CORE-016), safe Python module detection via pip show (CORE-017)
90
+ - **Tool validation (12):** Path traversal protection in logging/IDS/firewall/drift-detection/backup tools (TOOL-015/016/017/024/026), BPF filter injection prevention (TOOL-018), privilege pre-checks in hardening (TOOL-019), secure-fs enforcement (TOOL-020), error message sanitization in secrets (TOOL-021), network parameter validation (TOOL-022), encryption algorithm allowlist (TOOL-023), supply chain package name & URL validation (TOOL-025)
91
+ - **CI/CD hardening (10):** Multi-OS matrix (CICD-002), dependency caching (CICD-003), ESLint security plugin (CICD-009), build verification script (CICD-010), secure defaults (CICD-014), signed commits note (CICD-015), architecture doc sync (CICD-017), tilde version ranges for runtime deps (CICD-022), rate limiter (CICD-024), structured JSON logger (CICD-027)
92
+
93
+ #### Phase 8: Low-Severity Fixes (15/15) ✅
94
+ - **Core robustness (4):** Argument redaction in spawn-safe logs (CORE-018), shell metachar regex backslash fix (CORE-019), sync-only uncaughtException handler (CORE-020), singleton protection via module-scoped instances (CORE-021)
95
+ - **Tool consistency (6):** All dry_run defaults standardized to true (TOOL-027), dry-run parameter additions (TOOL-028), error sanitization helper (TOOL-029), strict identifier regex (TOOL-030), eliminated empty catch blocks (TOOL-031), Zod .min(1) constraints (TOOL-032)
96
+ - **CI/CD & DX (5):** Changelog check script (CICD-004), license compliance checker (CICD-011), test naming convention docs (CICD-016), husky pre-commit hooks (CICD-018), sudo session user tracking (CICD-028)
97
+
98
+ #### Phase 9: Test Coverage Push
99
+ - 6 new core test files: installer, dependency-validator, distro-adapter, tool-dependencies, rate-limiter, logger
100
+ - 13 new tool test files: all remaining tool modules now have test coverage
101
+ - **Total: 873 tests across 47 test files** (up from 421/12 at audit time)
102
+ - Every source module (26 core + 21 tools) now has a corresponding test file
103
+
104
+ ### New Modules
105
+ - `src/core/rate-limiter.ts` — Per-tool and global invocation rate limiting
106
+ - `src/core/logger.ts` — Structured JSON logging with security event level
107
+ - `eslint.config.mjs` — ESLint security plugin configuration
108
+ - `.husky/pre-commit` — Type-check pre-commit hook
109
+ - `.github/workflows/codeql.yml` — CodeQL SAST workflow
110
+
111
+ ---
112
+
113
+ ## [0.5.0-beta.3] — 2026-03-07
114
+
115
+ ### Security — Audit Remediation Phase 6
116
+ - **CRITICAL fixes (12 findings):** Hardened rollback command validation (CORE-003), eliminated shell invocations across 5 tool modules (TOOL-001–005), fixed printf format string injection in mcp-call.sh (CICD-020), added npm audit script (CICD-006), synchronized lockfile (CICD-023)
117
+ - **HIGH fixes (22 findings):** Password Buffer handling (CORE-005), SUDO_ASKPASS integrity checks (CORE-006), TOCTOU binary path verification (CORE-007), auto-installer package allowlists (CORE-008), ReDoS regex limits (CORE-009), removed hardcoded paths (CORE-010), path traversal protection in malware/hardening tools (TOOL-006/007), nftables table validation (TOOL-008), secure-fs enforcement for AppArmor/Falco/seccomp writes (TOOL-009/010/011), SSH config input validation (TOOL-012), safe dry_run defaults in compliance tools (TOOL-013/014), disabled source maps (CICD-001), pinned Actions to SHA (CICD-005), added CodeQL SAST (CICD-007), CI coverage enforcement (CICD-008), removed /etc from default allowedDirs (CICD-013), secured run-assessment.mjs distribution (CICD-021)
118
+
119
+ ### Testing
120
+ - 242 new tests across 16 new test files (8 core + 8 tool modules)
121
+ - Total: 663 tests across 28 test files (up from 421/12)
122
+ - All security remediation code paths covered
123
+
124
+ ### CI/CD
125
+ - GitHub Actions pinned to immutable commit SHAs
126
+ - CodeQL SAST workflow added (.github/workflows/codeql.yml)
127
+ - Coverage enforcement step in CI pipeline
128
+ - npm audit security check script added
129
+ - .npmignore created to exclude dev-only files from distribution
130
+
131
+ ---
132
+
133
+ ## [0.5.0-beta.2] — 2026-03-07
134
+
135
+ ### Phase 5: Hardening & Robustness
136
+
137
+ - **Fix 5.1: Startup Error Isolation** — Each of the 21 tool module registrations is wrapped in try/catch. Failed modules are logged but don't crash the server. Summary shows registered/failed count.
138
+ - **Fix 5.2: Graceful Shutdown** — SIGTERM/SIGINT handlers zero the sudo password buffer, log shutdown to changelog. uncaughtException and unhandledRejection handlers prevent silent crashes.
139
+ - **Fix 5.3: Network Timeout Handling** — Added `commandTimeout` (120s) and `networkTimeout` (30s) config options. Executor enforces SIGTERM→SIGKILL escalation on timeout. `spawn-safe.ts` passes timeout to `execFileSync`. NVD API calls use configurable timeout.
140
+ - **Fix 5.4: Binary Integrity Verification** — 14 critical security binaries verified against expected distro packages at startup via `dpkg -S`/`rpm -qf`/`pacman -Qo`. Warnings logged for unverified or unexpected ownership.
141
+ - **Fix 5.5: Expanded Test Coverage** — Added 87 new tests (executor, rollback, spawn-safe, backup-manager). Total: 323 tests across 10 test files. All passing.
142
+ - **Fix 5.6: Changelog User Attribution** — `ChangeEntry` now includes `user` (OS username, auto-populated) and `sessionId` (optional MCP session identifier) fields.
143
+
144
+ ### Changed
145
+
146
+ - `src/index.ts` — `safeRegister()` wrapper, graceful shutdown handlers, binary integrity verification at startup
147
+ - `src/core/config.ts` — Added `commandTimeout` and `networkTimeout` configuration options
148
+ - `src/core/executor.ts` — Timeout enforcement with SIGTERM→SIGKILL escalation
149
+ - `src/core/spawn-safe.ts` — Timeout passthrough to `execFileSync`
150
+ - `src/core/command-allowlist.ts` — `verifyBinaryOwnership()` and `verifyAllBinaries()` functions
151
+ - `src/core/changelog.ts` — `user` and `sessionId` fields on `ChangeEntry`
152
+ - `src/tools/patch-management.ts` — NVD API calls use configurable network timeout
153
+ - `package.json` — Version `0.5.0-beta.2`
154
+
155
+ ---
156
+
157
+ ## [0.5.0-beta.1] — 2026-03-06
158
+
159
+ ### Summary
160
+
161
+ Major security remediation release consolidating 157 tools down to 78 action-based tools across 21 modules. Introduces security hardening of the server itself including password buffer security, command allowlisting, auto-install safeguards, secure file permissions, comprehensive test infrastructure, and unified backup/rollback.
162
+
163
+ ### Security Fixes (Phase 1)
164
+
165
+ - **Fix 1.1: Password Buffer Pipeline** — Sudo password now stored in a zeroable `Buffer` (not V8-interned strings). Auto-expires after configurable timeout. Temp files overwritten with random bytes before deletion.
166
+ - **Fix 1.2: Command Allowlist** — All commands executed via `spawn()` are resolved against a strict allowlist of known-safe binaries. Unknown binaries are rejected before execution. Paths resolved to absolute at startup.
167
+ - **Fix 1.3: Auto-Install Hardening** — `KALI_DEFENSE_AUTO_INSTALL` now defaults to `false`. When enabled, only packages from the `DEFENSIVE_TOOLS` catalog are installable — arbitrary package names are blocked.
168
+ - **Fix 1.4: Secure File Permissions** — All state files (`changelog.json`, `rollback-state.json`, backups, quarantine) created with `0o600`/`0o700` permissions. Existing directories hardened at startup via `hardenDirPermissions()`.
169
+
170
+ ### Test Infrastructure (Phase 2)
171
+
172
+ - **Fix 2.1: Vitest Test Suite** — 221 tests across 6 test files covering sanitizer, config, command-allowlist, secure-fs, changelog, and safeguards modules. All tests pass with zero failures.
173
+ - **Fix 2.2: Backup/Rollback Unification** — `BackupManager` and `RollbackManager` consolidated under `~/.kali-defense/` with consistent secure file permissions.
174
+ - **Fix 2.3: Safeguards Real Blockers** — `SafeguardRegistry.checkSafety()` now produces real blocking conditions, not just advisory warnings.
175
+ - **Fix 2.4: spawn-safe.ts Circular Dependency** — Extracted safe spawn helper to break circular dependency between `executor.ts` and `sudo-session.ts`.
176
+
177
+ ### Tool Consolidation (Phase 3)
178
+
179
+ - **Fix 3.1: Tool Consolidation 157 → 78** — Merged granular single-purpose tools into action-based tools with `action` parameters. For example, `harden_sysctl_get`, `harden_sysctl_set`, and `harden_sysctl_audit` became `harden_sysctl` with `action: "get" | "set" | "audit"`. This reduces MCP tool registration overhead while maintaining all functionality.
180
+ - **Fix 3.2: Document Synchronization** — All documentation (`README.md`, `ARCHITECTURE.md`, `TOOLS-REFERENCE.md`, `PREFLIGHT-ARCHITECTURE.md`, `SAFEGUARDS.md`, `CHANGELOG.md`) updated to reflect 78 tools across 21 modules. Version strings synchronized to `0.5.0-beta.1`.
181
+
182
+ ### Changed
183
+
184
+ - `src/core/tool-dependencies.ts` — Rewritten for 78 consolidated tool names with union of absorbed tool dependencies
185
+ - `src/core/tool-registry.ts` — Rewritten with 78 tool sudo overlays matching new consolidated names
186
+ - `src/index.ts` — Version bumped to `0.5.0-beta.1`; tool count updated to 78
187
+ - `package.json` — Version `0.5.0-beta.1`; description updated to "78 defensive security tools"
188
+ - All 21 tool modules in `src/tools/` — Consolidated from fine-grained tools to action-based tools
189
+
190
+ ---
191
+
192
+ ## [0.4.0-beta.2] — 2026-03-04
193
+
194
+ **Critical Fix — `firewall_set_policy`:**
195
+ - Auto-injects loopback (`lo` ACCEPT) and established/related connection ACCEPT rules before setting INPUT or FORWARD default policy to DROP — prevents network lockout
196
+ - Aborts with clear error if prerequisite safety rules fail to add
197
+ - IPv6 safety rules also injected when `ipv6=true`
198
+
199
+ **Bug Fixes — `compliance_cis_check` (5 detection improvements):**
200
+ - CIS-1.1.4: Now checks `/etc/fstab` for `noexec` in addition to live mount options
201
+ - CIS-1.5.1-limits: Uses `sudo grep` across `limits.conf` and `limits.d/`
202
+ - CIS-5.5.5: Checks `login.defs`, `/etc/profile`, and `/etc/bash.bashrc` for umask
203
+ - CIS-5.1.8: Uses `sudo test` for root-owned 600-perm `cron.allow`
204
+ - CIS-5.1.9: Uses `sudo test` for root-owned 600-perm `at.allow`
205
+
206
+ These fixes improve CIS detection accuracy from ~71% to ~87% on hardened systems.
207
+
208
+ ---
209
+
210
+ ## [0.4.0-beta.1] — 2026-03-03
211
+
212
+ **New Features:**
213
+ - 🔐 `sudo_elevate_gui` — Secure two-phase GUI password elevation. Password never visible to the AI.
214
+ - 📋 Updated README with Getting Started guide, MCP client setup instructions, and sudo security documentation
215
+ - 🔢 Synced all version references to beta versioning scheme
216
+
217
+ **Sudo Management:**
218
+ - Added `sudo_elevate_gui` tool with native zenity/kdialog password dialog
219
+ - Two-phase flow: GUI captures password to temp file → MCP server reads, elevates, and securely wipes (2x random overwrite + unlink)
220
+ - File permission validation (rejects non-600 files)
221
+ - Added to pre-flight bypass list in tool-wrapper.ts
222
+
223
+ ---
224
+
225
+ ## [0.3.0] — 2026-03-03
226
+
227
+ ### Summary
228
+
229
+ Adds a comprehensive pre-flight validation system that automatically checks dependencies, detects privilege requirements, and optionally auto-installs missing packages before every tool invocation — transparently, with zero changes to existing tool handlers.
230
+
231
+ ---
232
+
233
+ ### Added
234
+
235
+ #### Pre-flight Validation Middleware (`src/core/tool-wrapper.ts`)
236
+ - `createPreflightServer()` — Proxy-based middleware that wraps `McpServer` to intercept `.tool()` registrations and inject pre-flight validation before every tool handler
237
+ - Transparent integration via JavaScript `Proxy` pattern — all 29 existing tool registration files work without modification
238
+ - Configurable bypass set for sudo management tools (`sudo_elevate`, `sudo_status`, `sudo_drop`, `sudo_extend`)
239
+ - Optional status banners prepended to tool output when there are warnings or auto-installed dependencies
240
+ - Safety net: if pre-flight itself throws unexpectedly, falls through to the original handler
241
+
242
+ #### Enhanced Tool Manifest Registry (`src/core/tool-registry.ts`)
243
+ - `ToolRegistry` singleton with O(1) manifest lookup for all 155 tools
244
+ - `ToolManifest` type supporting: required/optional binaries, Python modules, npm packages, system libraries, required files, sudo level (`never`/`always`/`conditional`), Linux capabilities, category, and tags
245
+ - `SUDO_OVERLAYS` — static privilege annotations for all 155 tools derived from handler analysis
246
+ - `initializeRegistry()` — merges legacy `TOOL_DEPENDENCIES` binary data with privilege overlays
247
+ - Category inference from tool name prefixes
248
+
249
+ #### Privilege Detection (`src/core/privilege-manager.ts`)
250
+ - `PrivilegeManager` singleton with 30-second cached status
251
+ - Detects UID/EUID via `process.getuid()`/`process.geteuid()`
252
+ - Parses Linux capabilities from `/proc/self/status` CapEff hex bitmask (41 capability names mapped)
253
+ - Tests passwordless sudo via `sudo -n true`
254
+ - Checks active `SudoSession` cached credentials
255
+ - Reads user group memberships via `id -Gn`
256
+ - `checkForTool(manifest)` evaluates tool's privilege requirements against current state
257
+
258
+ #### Auto-Dependency Resolution (`src/core/auto-installer.ts`)
259
+ - `AutoInstaller` singleton supporting 8+ package managers: apt, dnf, yum, pacman, apk, zypper, brew, pip, and npm
260
+ - Resolves distro-specific package names from the `DEFENSIVE_TOOLS` catalog
261
+ - Python module installation: tries user-site (`--user`) first, falls back to sudo
262
+ - npm package installation: tries non-sudo first, falls back to sudo
263
+ - Library installation: generates distro-family-specific dev package name candidates
264
+ - Post-install verification for all dependency types
265
+
266
+ #### Pre-flight Orchestration Engine (`src/core/preflight.ts`)
267
+ - `PreflightEngine` singleton with 60-second result cache (passing results only)
268
+ - Full pipeline: manifest resolution → dependency checking (binary, Python, npm, library, file) → auto-installation → privilege validation → pass/fail determination
269
+ - Structured `PreflightResult` with checked/missing/installed deps, privilege issues, errors, warnings
270
+ - `formatSummary()` — human-readable pass/fail output with install hints and resolution steps
271
+ - `formatStatusMessage()` — compact one-line status for prepending to tool output
272
+
273
+ #### New Environment Variables
274
+ - `KALI_DEFENSE_PREFLIGHT` (default: `true`) — enable/disable pre-flight checks entirely
275
+ - `KALI_DEFENSE_PREFLIGHT_BANNERS` (default: `true`) — show pre-flight status banners in tool output
276
+
277
+ ### Changed
278
+
279
+ - `src/index.ts` — Wraps `McpServer` with `createPreflightServer()` proxy; initializes the tool registry at startup
280
+ - `src/tools/sudo-management.ts` — Calls `invalidatePreflightCaches()` on `sudo_elevate` and `sudo_drop` to clear stale privilege/dependency caches
281
+
282
+ ---
283
+
284
+ ## [2.0.0] — 2026-02-21
285
+
286
+ ### Summary
287
+
288
+ Major release expanding the server from 69 tools across 12 categories to 130+ tools across 26 categories. Introduces application safeguards, rollback infrastructure, a dedicated BackupManager, 11 new tool modules, and multi-framework compliance support.
289
+
290
+ ---
291
+
292
+ ### New Tool Modules (11 modules, ~65 new tools)
293
+
294
+ #### Supply Chain Security (`supply-chain-security.ts`)
295
+ - `generate_sbom` — Generate Software Bill of Materials using syft, cdxgen, or dpkg/rpm fallback
296
+ - `verify_package_integrity` — Verify installed package checksums (debsums/rpm -V)
297
+ - `setup_cosign_signing` — Sign container images or artifacts with cosign (keyless or key-based)
298
+ - `check_slsa_attestation` — Verify SLSA provenance attestation for binaries or artifacts
299
+
300
+ #### Memory Protection (`memory-protection.ts`)
301
+ - `audit_memory_protections` — Audit ASLR, PIE, RELRO, NX, stack canary on specified binaries
302
+ - `enforce_aslr` — Enable full ASLR by setting kernel.randomize_va_space=2
303
+ - `report_exploit_mitigations` — Report system-wide exploit mitigation status (SMEP, SMAP, PTI, KASLR)
304
+
305
+ #### Drift Detection (`drift-detection.ts`)
306
+ - `create_baseline` — Create system baseline (file hashes, sysctl state, service states)
307
+ - `compare_to_baseline` — Compare current system state against a saved baseline
308
+ - `list_drift_alerts` — List available baselines and summarize changes since last baseline
309
+
310
+ #### Vulnerability Intelligence (`vulnerability-intel.ts`)
311
+ - `lookup_cve` — Look up CVE details from the NVD API
312
+ - `scan_packages_cves` — Scan installed packages for known CVEs
313
+ - `get_patch_urgency` — Get patch urgency for a specific package
314
+
315
+ #### Security Posture (`security-posture.ts`)
316
+ - `calculate_security_score` — Weighted security score (0-100) across 7 security domains
317
+ - `get_posture_trend` — Compare current score against historical scores
318
+ - `generate_posture_dashboard` — Structured posture dashboard with findings and recommendations
319
+
320
+ #### Secrets Scanner (`secrets-scanner.ts`)
321
+ - `scan_for_secrets` — Directory secrets scan using truffleHog, gitleaks, or built-in grep patterns
322
+ - `audit_env_vars` — Audit current process environment variables for potential secrets
323
+ - `scan_git_history` — Scan git repository history for leaked secrets
324
+
325
+ #### Zero-Trust Network (`zero-trust-network.ts`)
326
+ - `setup_wireguard` — Set up WireGuard VPN interface with key generation and configuration
327
+ - `manage_wg_peers` — Add, remove, or list WireGuard peers
328
+ - `setup_mtls` — Generate CA, server, and client certificates for mutual TLS authentication
329
+ - `configure_microsegmentation` — Configure iptables/nftables rules for service-level microsegmentation
330
+
331
+ #### Container Advanced (`container-advanced.ts`)
332
+ - `generate_seccomp_profile` — Generate custom seccomp profile JSON from allowed syscall list
333
+ - `apply_apparmor_container` — Generate and optionally load an AppArmor profile for a container
334
+ - `setup_rootless_containers` — Configure rootless container support (newuidmap/newgidmap, user namespaces)
335
+ - `scan_image_trivy` — Scan container image for vulnerabilities using Trivy
336
+
337
+ #### Compliance Extended (`compliance-extended.ts`)
338
+ - `run_compliance_check` — Run structured compliance checks against PCI-DSS v4, HIPAA, SOC 2, ISO 27001, or GDPR frameworks
339
+
340
+ #### eBPF Security (`ebpf-security.ts`)
341
+ - `list_ebpf_programs` — List loaded eBPF programs and pinned maps
342
+ - `check_falco` — Check Falco runtime security status, version, and configuration
343
+ - `deploy_falco_rules` — Deploy custom Falco rules to /etc/falco/rules.d/
344
+ - `get_ebpf_events` — Read recent Falco events from the JSON log
345
+
346
+ #### Automation Workflows (`automation-workflows.ts`)
347
+ - `setup_scheduled_audit` — Create scheduled security audit using systemd timer or cron
348
+ - `list_scheduled_audits` — List all scheduled security audits
349
+ - `remove_scheduled_audit` — Remove a scheduled security audit by name
350
+ - `get_audit_history` — Read historical output from scheduled audit jobs
351
+
352
+ ---
353
+
354
+ ### New Tools in Existing Modules
355
+
356
+ #### Firewall Management (5 new tools, 12 total)
357
+ - `firewall_nftables_list` — List nftables ruleset; nftables is the modern replacement for iptables
358
+ - `firewall_set_policy` — Set default chain policy (INPUT/FORWARD/OUTPUT) with rollback tracking
359
+ - `firewall_create_chain` — Create custom iptables chain with optional ip6tables mirror
360
+ - `firewall_persistence` — Manage iptables-persistent: install, save, and check persistence status
361
+ - `firewall_policy_audit` — Audit firewall configuration for default policy issues and misconfigurations
362
+
363
+ #### System Hardening (12 new tools, 19 total)
364
+ - `harden_systemd_audit` — Audit service units using systemd-analyze security; scores 40+ properties
365
+ - `harden_kernel_security_audit` — Audit CPU vulnerability mitigations, Landlock, lockdown mode, ASLR
366
+ - `harden_bootloader_audit` — Audit GRUB: password protection, Secure Boot status, kernel parameters
367
+ - `harden_module_audit` — Audit kernel module blacklisting per CIS benchmark
368
+ - `harden_cron_audit` — Audit cron and at access control configuration (cron.allow/deny)
369
+ - `harden_umask_audit` — Audit default umask in login.defs, profile, bashrc
370
+ - `harden_banner_audit` — Audit login warning banners per CIS benchmark
371
+ - `harden_umask_set` — Set default umask across login.defs, /etc/profile, /etc/bash.bashrc
372
+ - `harden_coredump_disable` — Disable core dumps via limits.conf, coredump.conf, and sysctl
373
+ - `harden_banner_set` — Set CIS-compliant login warning banner content
374
+ - `harden_bootloader_configure` — Configure GRUB kernel parameters (add_kernel_params/status)
375
+ - `harden_systemd_apply` — Apply systemd security hardening overrides (basic/strict preset)
376
+
377
+ #### Logging and Monitoring (3 new tools, 10 total)
378
+ - `log_auditd_cis_rules` — Check or deploy complete set of CIS Benchmark-required auditd rules
379
+ - `log_rotation_audit` — Audit logrotate configuration and journald persistence settings
380
+ - `log_fail2ban_audit` — Audit fail2ban jail configurations for weak ban times and missing jails
381
+
382
+ #### Network Defense (2 new tools, 8 total)
383
+ - `netdef_ipv6_audit` — Audit IPv6 configuration, firewall status, and whether IPv6 should be disabled
384
+ - `netdef_self_scan` — Run nmap self-scan to discover exposed services from a network perspective
385
+
386
+ #### Compliance and Benchmarking (2 new tools, 7 total)
387
+ - `compliance_cron_restrict` — Create/manage /etc/cron.allow and /etc/at.allow (CIS 5.1.8, 5.1.9)
388
+ - `compliance_tmp_hardening` — Audit and apply /tmp mount hardening with nodev,nosuid,noexec
389
+
390
+ #### Malware Analysis (1 new tool, 6 total)
391
+ - `malware_webshell_detect` — Scan web server directories for web shells using pattern matching
392
+
393
+ #### Access Control (3 new tools, 9 total)
394
+ - `access_ssh_cipher_audit` — Audit SSH cryptographic algorithms against Mozilla/NIST recommendations
395
+ - `access_pam_configure` — Configure PAM modules: pam_pwquality (complexity) and pam_faillock (lockout)
396
+ - `access_restrict_shell` — Restrict a user's login shell to nologin or /bin/false
397
+
398
+ #### Container Security (4 new tools, 9 total)
399
+ - `container_image_scan` — Scan Docker images for vulnerabilities using Trivy or Grype
400
+ - `container_seccomp_audit` — Audit Docker containers for seccomp profile configuration
401
+ - `container_daemon_configure` — Audit/apply Docker daemon security settings in /etc/docker/daemon.json
402
+ - `container_apparmor_install` — Install AppArmor profile packages and list loaded profiles
403
+
404
+ ---
405
+
406
+ ### New Core Infrastructure
407
+
408
+ #### `src/core/safeguards.ts` — SafeguardRegistry
409
+ - Singleton that detects running applications before modifying operations execute
410
+ - Parallel detection of VS Code (process + `.vscode` dir + IPC sockets), Docker (socket + container list), MCP servers (`.mcp.json` + node processes), databases (TCP port probes: PostgreSQL 5432, MySQL 3306, MongoDB 27017, Redis 6379), and web servers (nginx/apache2/httpd via pgrep)
411
+ - `checkSafety(operation, params)` returns `SafetyResult` with `warnings[]`, `blockers[]`, and `impactedApps[]`
412
+ - `appSafetyReport()` generates a full detection report across all application categories
413
+ - All detection errors are caught gracefully and converted to warnings rather than failures
414
+
415
+ #### `src/core/backup-manager.ts` — BackupManager
416
+ - Manages file backups with manifest tracking under `~/.kali-mcp-backups/`
417
+ - Each backup entry has a UUID, original path, backup path, timestamp, and size
418
+ - `manifest.json` maintains the full backup inventory for list and restore operations
419
+ - `backup(filePath)` — creates timestamped copy and adds to manifest, returns UUID
420
+ - `restore(backupId)` — restores by UUID with target directory auto-creation
421
+ - `listBackups()` — returns all entries sorted by timestamp (newest first)
422
+ - `pruneOldBackups(daysOld)` — removes backups older than N days and updates manifest
423
+
424
+ #### `src/core/rollback.ts` — RollbackManager
425
+ - Singleton that tracks system changes within and across sessions
426
+ - State persisted to `~/.kali-defense/rollback-state.json`
427
+ - Supports four change types: `file` (backup path), `sysctl` (previous value), `service` (previous state), `firewall` (rollback command)
428
+ - `rollback(operationId)` — reverses all changes for a specific operation in reverse order
429
+ - `rollbackSession(sessionId)` — reverses all changes from the current session
430
+ - `listChanges()` — returns all tracked changes sorted by timestamp
431
+
432
+ ---
433
+
434
+ ### Documentation Added
435
+
436
+ - `SAFEGUARDS.md` — Complete SafeguardRegistry reference: detection methods, operation trigger mapping, warning vs blocker levels, dry-run examples, backup storage layout, rollback and restore guide
437
+ - `TOOLS-REFERENCE.md` — Alphabetical table of all 130+ tools with MCP tool name, description, key parameters, dryRun support, OS compatibility, and safety level
438
+ - `STANDARDS.md` — Security standards mapping covering CIS Benchmark section-by-section, NIST SP 800-53 control families, and five compliance frameworks (PCI-DSS v4, HIPAA, SOC 2, ISO 27001, GDPR) with coverage estimates and evidence types
439
+ - `CHANGELOG.md` — This file; version history beginning at v2.0.0
440
+ - `README.md` — Updated with new tool categories, application safeguards section, OS compatibility matrix, and quick-start examples for each new tool category
441
+
442
+ ---
443
+
444
+ ### Changed
445
+
446
+ - `src/index.ts` — Updated server version to `2.0.0`, added imports and registration calls for all 11 new modules; server now registers 26 tool modules
447
+ - `README.md` — Complete rewrite to reflect 130+ tools; added OS matrix, safeguards section, quick-start examples for all new categories
448
+ - Tool count in server startup message updated to `130+`
449
+
450
+ ---
451
+
452
+ ## [1.0.0] — 2025 (initial release)
453
+
454
+ ### Initial Release
455
+
456
+ 69 defensive security tools across 12 categories:
457
+
458
+ - Firewall Management (7 tools): iptables list/add/delete, UFW status/rule, save, restore
459
+ - System Hardening (7 tools): sysctl get/set/audit, service manage/audit, file permissions, permissions audit
460
+ - Intrusion Detection (5 tools): AIDE, rkhunter, chkrootkit, file integrity check, rootkit summary
461
+ - Log Analysis (7 tools): auditd rules/search/report, journalctl, fail2ban status/manage, syslog analyze
462
+ - Network Defense (6 tools): connections, port scan detect, tcpdump, DNS monitor, ARP monitor, open ports audit
463
+ - Compliance (5 tools): lynis, oscap, CIS check, policy evaluate, report
464
+ - Malware Analysis (5 tools): ClamAV scan/update, YARA scan, suspicious files, quarantine manage
465
+ - Backup and Recovery (5 tools): config backup, system state, restore, verify, list
466
+ - Access Control (6 tools): SSH audit/harden, sudo audit, user audit, password policy, PAM audit
467
+ - Encryption and PKI (6 tools): TLS audit, cert expiry, GPG keys, LUKS manage, file hash, TLS config audit
468
+ - Container Security (5 tools): Docker audit/bench, AppArmor manage, SELinux manage, namespace check
469
+ - Meta and Orchestration (5 tools): check tools, suggest workflow, security posture, change history, run workflow
470
+
471
+ Core infrastructure: executor (spawn with shell:false), sanitizer (17+ validators), config (env-based), parsers, distro detection, installer, changelog, policy engine
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kali Defense Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.