notaffected 1.0.0__py3-none-any.whl

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.
@@ -0,0 +1,3 @@
1
+ """notaffected — Deterministic CVE exploitability prover and OpenVEX generator."""
2
+
3
+ __version__ = "1.0.0"
@@ -0,0 +1,8 @@
1
+ """CLI entrypoint for `python -m notaffected`."""
2
+
3
+ import sys
4
+
5
+ from notaffected.cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())
@@ -0,0 +1 @@
1
+ """Advisory fetching, built-in golden CheckSpecs, and precondition extraction."""
@@ -0,0 +1,104 @@
1
+ """AI-assisted and deterministic post-verdict remediation & operational risk advisor.
2
+
3
+ Takes the deterministic probe evidence from AFFECTED and UNDER_INVESTIGATION hosts
4
+ and synthesizes a prioritized, service-aware remediation plan.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from notaffected.local_model import detect_provider, generate, get_ai_status
10
+ from notaffected.model import CheckSpec, HostVerdict, VerdictStatus
11
+
12
+
13
+ def build_remediation_briefing(
14
+ specs: list[CheckSpec],
15
+ verdicts: list[HostVerdict],
16
+ use_llm: bool = True,
17
+ ) -> str:
18
+ """Generate a host-aware remediation & operational impact briefing."""
19
+ affected = [v for v in verdicts if v.status == VerdictStatus.AFFECTED]
20
+ under_inv = [v for v in verdicts if v.status == VerdictStatus.UNDER_INVESTIGATION]
21
+ actionable = affected + under_inv
22
+ if not actionable:
23
+ return "All evaluated hosts are deterministically NOT AFFECTED. No remediation actions required."
24
+
25
+ # Prioritize confirmed AFFECTED findings. The budget does not depend on the provider: the
26
+ # user picks the model, so its size and speed are not ours to assume.
27
+ provider = detect_provider()
28
+ max_items = 8
29
+ max_toks = 512
30
+ llm_items = actionable[:max_items]
31
+ spec_map = {s.cve_id: s for s in specs}
32
+ findings_lines: list[str] = []
33
+ for v in llm_items:
34
+ spec = spec_map.get(v.cve_id)
35
+ patch_str = v.patch.status if v.patch else "unknown"
36
+ short_reason = v.reason[:120]
37
+ short_mit = (v.mitigation[0] if v.mitigation else "None")[:100]
38
+ findings_lines.append(
39
+ f"- {v.host} ({v.os_family}) {v.cve_id} [{spec.severity if spec else 'HIGH'}] "
40
+ f"Patch={patch_str} | Mit={short_mit} | Proof={short_reason}"
41
+ )
42
+
43
+ prompt = (
44
+ f"Write {len(findings_lines)} short bullets (max 18 words each, no intro): "
45
+ "[Host CVE] Risk & safest action.\n"
46
+ + "\n".join(findings_lines)
47
+ )
48
+
49
+ if use_llm:
50
+ llm_reply = generate(prompt, timeout=90, json_format=False, max_tokens=max_toks).strip()
51
+ if llm_reply:
52
+ st = get_ai_status()
53
+ model_name = st.get("model") or "unknown"
54
+ extra_note = (
55
+ f"\n(Showing AI triage for top {len(llm_items)} of {len(actionable)} actionable findings)"
56
+ if len(actionable) > len(llm_items)
57
+ else ""
58
+ )
59
+ return f"[AI Provider: {provider} | Model: {model_name} | Local-Only: {st.get('local_only')}]\n{llm_reply}{extra_note}"
60
+
61
+ # Deterministic host-aware operational triage when no LLM is reachable
62
+ out_lines: list[str] = [
63
+ "Structured Operational Triage (deterministic; AI advisor not configured or unavailable):"
64
+ ]
65
+ for idx, v in enumerate(actionable, start=1):
66
+ patch_status = v.patch.status if v.patch else "unknown"
67
+ fixed_ver = (v.patch.fixed_version if v.patch else None) or "pending"
68
+ caution_notes: list[str] = []
69
+ search_text = f"{v.reason} {' '.join(v.mitigation)}".lower()
70
+ if "nginx" in search_text or ":443" in search_text or ":80" in search_text:
71
+ caution_notes.append(
72
+ "Active web listener detected on host; prefer targeted sysctl/config mitigation over blanket incoming firewall deny."
73
+ )
74
+ if "sshd" in search_text or ":22" in search_text:
75
+ caution_notes.append(
76
+ "Active OpenSSH listener detected; reload sshd rather than blocking TCP/22 to avoid losing remote access."
77
+ )
78
+ if v.os_family == "windows" and "spooler" in search_text:
79
+ caution_notes.append(
80
+ "If this Windows Server is not a dedicated print server, disabling 'Spooler' is safe and takes effect immediately without reboot."
81
+ )
82
+ if v.os_family == "windows" and "disabledcomponents" in search_text:
83
+ caution_notes.append(
84
+ "Setting Tcpip6 DisabledComponents=0xff requires a reboot; verify Active Directory / dual-stack dependencies before disabling IPv6 on a Domain Controller."
85
+ )
86
+
87
+ out_lines.append(
88
+ f"{idx}. {v.host} [{v.os_family.upper()}] — {v.cve_id} ({v.status.value.upper()})"
89
+ )
90
+ out_lines.append(f" • Patch Readiness: {patch_status} (fix: {fixed_ver})")
91
+ if caution_notes:
92
+ for note in caution_notes:
93
+ out_lines.append(f" • Operational Safety Note: {note}")
94
+ if v.mitigation:
95
+ first_action = v.mitigation[0]
96
+ if (
97
+ ("nginx" in search_text or ":443" in search_text or ":80" in search_text)
98
+ and "ufw default deny" in first_action.lower()
99
+ and len(v.mitigation) > 1
100
+ ):
101
+ first_action = v.mitigation[1]
102
+ out_lines.append(f" • Recommended First Action: {first_action}")
103
+
104
+ return "\n".join(out_lines)
@@ -0,0 +1,371 @@
1
+ """Curated, deterministic CheckSpecs for high-profile Linux CVEs.
2
+
3
+ These work 100% offline with zero external API or LLM calls.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from pathlib import Path
9
+
10
+ import yaml
11
+
12
+ from notaffected.model import CheckSpec, PatchInfo, Precondition, VexJustification
13
+
14
+ BUILTIN_SPECS: dict[str, CheckSpec] = {
15
+ "CVE-2026-98432": CheckSpec(
16
+ cve_id="CVE-2026-98432",
17
+ summary=(
18
+ "Linux kernel IPv4 TCP/MPTCP options use-after-free race condition "
19
+ "allowing remote code execution against exposed TCP listeners"
20
+ ),
21
+ severity="CRITICAL",
22
+ preconditions=[
23
+ Precondition(
24
+ probe="kernel_version_vulnerable",
25
+ params={"min_version": "4.4.0", "fixed_version": "6.8.0-45"},
26
+ description="Running Linux kernel is older than patched release (6.8.0-45)",
27
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_PRESENT,
28
+ ),
29
+ Precondition(
30
+ probe="network_listener",
31
+ params={"proto": "tcp", "scope": "non_loopback"},
32
+ description="At least one TCP/MPTCP service is listening on a non-loopback address",
33
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
34
+ ),
35
+ Precondition(
36
+ probe="firewall_allows_port",
37
+ params={"port": "any", "proto": "tcp"},
38
+ description="Host firewall allows incoming TCP traffic from external networks",
39
+ justification_if_not_met=VexJustification.INLINE_MITIGATIONS_ALREADY_EXIST,
40
+ ),
41
+ ],
42
+ mitigation=[
43
+ "sudo ufw default deny incoming && sudo ufw enable",
44
+ "sudo sysctl -w net.mptcp.enabled=0",
45
+ "Drop IPv4 packets carrying Record Route (type 7) or Timestamp (type 68) TCP/IP options at perimeter firewall",
46
+ ],
47
+ patch=PatchInfo(
48
+ status="staged",
49
+ fixed_version="6.8.0-45.45",
50
+ pocket="noble-proposed",
51
+ advisory_url="https://ubuntu.com/security/CVE-2026-98432",
52
+ ),
53
+ confidence="high",
54
+ source="builtin",
55
+ os_source="curated",
56
+ ),
57
+ "CVE-2024-47176": CheckSpec(
58
+ cve_id="CVE-2024-47176",
59
+ summary="OpenPrinting cups-browsed UDP port 631 remote code execution chain",
60
+ severity="CRITICAL",
61
+ preconditions=[
62
+ Precondition(
63
+ probe="package_installed_vulnerable",
64
+ params={
65
+ "package": "cups-browsed",
66
+ "fixed_version": "2.0.0-0ubuntu10.2",
67
+ # Per-release binary fixes from UBUNTU-CVE-2024-47176 on OSV (checked 2026-11-20);
68
+ # 20.04/22.04 build cups-browsed from the cups-filters source.
69
+ "release_fixes": {
70
+ "ubuntu:20.04": "1.27.4-1ubuntu0.4",
71
+ "ubuntu:22.04": "1.28.15-0ubuntu1.4",
72
+ "ubuntu:24.04": "2.0.0-0ubuntu10.2",
73
+ },
74
+ },
75
+ description="Package 'cups-browsed' is installed and < 2.0.0-0ubuntu10.2",
76
+ justification_if_not_met=VexJustification.COMPONENT_NOT_PRESENT,
77
+ ),
78
+ Precondition(
79
+ probe="systemd_service_active",
80
+ params={"service": "cups-browsed.service"},
81
+ description="systemd unit 'cups-browsed.service' is running",
82
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
83
+ ),
84
+ Precondition(
85
+ probe="network_listener",
86
+ params={"proto": "udp", "port": 631, "scope": "non_loopback"},
87
+ description="UDP port 631 is listening on a non-loopback address",
88
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
89
+ ),
90
+ ],
91
+ mitigation=[
92
+ "sudo systemctl disable --now cups-browsed.service",
93
+ "sudo ufw deny 631/udp",
94
+ ],
95
+ patch=PatchInfo(
96
+ status="released",
97
+ fixed_version="2.0.0-0ubuntu10.2",
98
+ pocket="noble-security",
99
+ advisory_url="https://ubuntu.com/security/CVE-2024-47176",
100
+ ),
101
+ confidence="high",
102
+ source="builtin",
103
+ os_source="curated",
104
+ ),
105
+ "CVE-2023-32233": CheckSpec(
106
+ cve_id="CVE-2023-32233",
107
+ summary="Linux kernel Netfilter nf_tables anonymous sets use-after-free local privilege escalation",
108
+ severity="HIGH",
109
+ preconditions=[
110
+ Precondition(
111
+ probe="kernel_version_vulnerable",
112
+ # NVD: last affected range 6.3 to 6.3.2 (fix commit c1592a89942e), so mainline 6.4+ has the fix.
113
+ params={"fixed_version": "6.2.0-21", "mainline_from": "6.4"},
114
+ description="Running Linux kernel is < 6.2.0-21",
115
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_PRESENT,
116
+ ),
117
+ Precondition(
118
+ probe="kernel_module_loaded",
119
+ params={"module": "nf_tables"},
120
+ description="Kernel module 'nf_tables' is loaded in /proc/modules",
121
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
122
+ ),
123
+ Precondition(
124
+ probe="sysctl_equals",
125
+ params={"key": "kernel.unprivileged_userns_clone", "value": "1"},
126
+ description="Unprivileged user namespaces enabled (kernel.unprivileged_userns_clone = 1)",
127
+ justification_if_not_met=VexJustification.INLINE_MITIGATIONS_ALREADY_EXIST,
128
+ ),
129
+ ],
130
+ mitigation=[
131
+ "sudo sysctl -w kernel.unprivileged_userns_clone=0",
132
+ "echo 'blacklist nf_tables' | sudo tee /etc/modprobe.d/blacklist-nftables.conf",
133
+ ],
134
+ patch=PatchInfo(
135
+ status="released",
136
+ fixed_version="6.2.0-21.21",
137
+ pocket="ubuntu-security",
138
+ advisory_url="https://ubuntu.com/security/CVE-2023-32233",
139
+ ),
140
+ confidence="high",
141
+ source="builtin",
142
+ os_source="curated",
143
+ ),
144
+ "CVE-2022-47942": CheckSpec(
145
+ cve_id="CVE-2022-47942",
146
+ summary="Linux kernel ksmbd in-kernel SMB server pre-auth remote code execution",
147
+ severity="CRITICAL",
148
+ preconditions=[
149
+ Precondition(
150
+ probe="kernel_version_vulnerable",
151
+ # NVD: last affected range 5.19 to 5.19.2 (fix commit 8f0541186e9a), so mainline 6.0+ has the fix.
152
+ params={"fixed_version": "5.19.0-28", "mainline_from": "6.0"},
153
+ description="Running Linux kernel is < 5.19.0-28",
154
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_PRESENT,
155
+ ),
156
+ Precondition(
157
+ probe="kernel_module_loaded",
158
+ params={"module": "ksmbd"},
159
+ description="In-kernel SMB server module 'ksmbd' is loaded in /proc/modules",
160
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
161
+ ),
162
+ Precondition(
163
+ probe="network_listener",
164
+ params={"proto": "tcp", "port": 445, "scope": "non_loopback"},
165
+ description="TCP port 445 (SMB) is listening on a non-loopback address",
166
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
167
+ ),
168
+ ],
169
+ mitigation=[
170
+ "sudo modprobe -r ksmbd",
171
+ "echo 'install ksmbd /bin/false' | sudo tee /etc/modprobe.d/disable-ksmbd.conf",
172
+ "sudo ufw deny 445/tcp",
173
+ ],
174
+ patch=PatchInfo(
175
+ status="released",
176
+ fixed_version="5.19.0-28",
177
+ pocket="ubuntu-security",
178
+ advisory_url="https://ubuntu.com/security/CVE-2022-47942",
179
+ ),
180
+ confidence="high",
181
+ source="builtin",
182
+ os_source="curated",
183
+ ),
184
+ "CVE-2024-6387": CheckSpec(
185
+ cve_id="CVE-2024-6387",
186
+ summary="OpenSSH server (sshd) regreSSHion SIGALRM race condition unauthenticated RCE",
187
+ severity="CRITICAL",
188
+ preconditions=[
189
+ Precondition(
190
+ probe="package_installed_vulnerable",
191
+ params={
192
+ "package": "openssh-server",
193
+ "fixed_version": "1:9.6p1-3ubuntu13.3",
194
+ # Per-release fixes from UBUNTU-CVE-2024-6387 on OSV (checked 2026-11-20).
195
+ # 20.04 (8.2p1) predates the regression and is not listed, so it gives UNKNOWN.
196
+ "release_fixes": {
197
+ "ubuntu:22.04": "1:8.9p1-3ubuntu0.10",
198
+ "ubuntu:24.04": "1:9.6p1-3ubuntu13.3",
199
+ },
200
+ },
201
+ description="Package 'openssh-server' is installed and < 1:9.6p1-3ubuntu13.3",
202
+ justification_if_not_met=VexJustification.COMPONENT_NOT_PRESENT,
203
+ ),
204
+ Precondition(
205
+ probe="process_running",
206
+ # Ubuntu 22.10+ starts sshd on demand from ssh.socket, so no sshd process is not proof.
207
+ params={"process": "sshd", "socket_unit": "ssh.socket"},
208
+ description="OpenSSH daemon ('sshd') process is running",
209
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
210
+ ),
211
+ Precondition(
212
+ probe="network_listener",
213
+ params={"proto": "tcp", "port": 22, "scope": "non_loopback"},
214
+ description="TCP port 22 (SSH) is listening on a non-loopback address",
215
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
216
+ ),
217
+ Precondition(
218
+ probe="config_contains",
219
+ params={
220
+ "path": "/etc/ssh/sshd_config",
221
+ "pattern": r"^\s*LoginGraceTime\s+0\b",
222
+ "negate": True,
223
+ # sshd keeps the first value it reads, so only the first LoginGraceTime counts.
224
+ "semantics": "first",
225
+ "directive": "LoginGraceTime",
226
+ },
227
+ description="LoginGraceTime is not set to 0 in /etc/ssh/sshd_config",
228
+ justification_if_not_met=VexJustification.INLINE_MITIGATIONS_ALREADY_EXIST,
229
+ ),
230
+ ],
231
+ mitigation=[
232
+ # A drop-in is read through the Include at the top of Ubuntu's sshd_config, so it is the first
233
+ # value sshd sees; appending to sshd_config would lose to an earlier LoginGraceTime line.
234
+ "echo 'LoginGraceTime 0' | sudo tee /etc/ssh/sshd_config.d/00-notaffected.conf && sudo systemctl reload ssh",
235
+ "sudo apt update && sudo apt install --only-upgrade openssh-server",
236
+ ],
237
+ patch=PatchInfo(
238
+ status="released",
239
+ fixed_version="1:9.6p1-3ubuntu13.3",
240
+ pocket="noble-security",
241
+ advisory_url="https://ubuntu.com/security/CVE-2024-6387",
242
+ ),
243
+ confidence="high",
244
+ source="builtin",
245
+ os_source="curated",
246
+ ),
247
+ "CVE-2024-38063": CheckSpec(
248
+ cve_id="CVE-2024-38063",
249
+ summary=(
250
+ "Windows TCP/IP IPv6 stack integer underflow remote code execution "
251
+ "(unauthenticated packet-of-death)"
252
+ ),
253
+ severity="CRITICAL",
254
+ os_family="windows",
255
+ preconditions=[
256
+ Precondition(
257
+ probe="windows_build_vulnerable",
258
+ params={"kb": "KB5041585", "fixed_build": "20348.2655"},
259
+ description="Windows OS build is < 20348.2655 and security update KB5041585 is not installed",
260
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_PRESENT,
261
+ ),
262
+ Precondition(
263
+ probe="windows_registry_equals",
264
+ params={
265
+ "path": r"HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters",
266
+ "name": "DisabledComponents",
267
+ "value": "255",
268
+ "negate": True,
269
+ },
270
+ description="IPv6 is not disabled via Registry (DisabledComponents != 0xff / 255)",
271
+ justification_if_not_met=VexJustification.INLINE_MITIGATIONS_ALREADY_EXIST,
272
+ ),
273
+ ],
274
+ mitigation=[
275
+ r"Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters' -Name 'DisabledComponents' -Value 0xff -Type DWord",
276
+ "Install Windows Security Update KB5041585 (OS Build 20348.2655+)",
277
+ ],
278
+ patch=PatchInfo(
279
+ status="released",
280
+ fixed_version="KB5041585 (20348.2655)",
281
+ pocket="msrc-security-update",
282
+ advisory_url="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2024-38063",
283
+ ),
284
+ confidence="high",
285
+ source="builtin",
286
+ os_source="curated",
287
+ ),
288
+ "CVE-2021-34527": CheckSpec(
289
+ cve_id="CVE-2021-34527",
290
+ summary="Windows Print Spooler (PrintNightmare) remote code execution and privilege escalation",
291
+ severity="CRITICAL",
292
+ os_family="windows",
293
+ preconditions=[
294
+ Precondition(
295
+ probe="windows_build_vulnerable",
296
+ params={"kb": "KB5004945", "fixed_build": "20348.2600"},
297
+ description="Security update KB5004945 is not installed and Windows build < 20348.2600",
298
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_PRESENT,
299
+ ),
300
+ Precondition(
301
+ probe="windows_service_active",
302
+ params={"service": "Spooler"},
303
+ description="Windows Print Spooler service ('Spooler') is Running",
304
+ justification_if_not_met=VexJustification.VULNERABLE_CODE_NOT_IN_EXECUTE_PATH,
305
+ ),
306
+ ],
307
+ mitigation=[
308
+ "Stop-Service -Name Spooler -Force; Set-Service -Name Spooler -StartupType Disabled",
309
+ "Install Windows Security Update KB5004945 and restrict Point and Print in Group Policy",
310
+ ],
311
+ patch=PatchInfo(
312
+ status="released",
313
+ fixed_version="KB5004945 (OS Build 20348.2600)",
314
+ pocket="msrc-out-of-band",
315
+ advisory_url="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527",
316
+ ),
317
+ confidence="high",
318
+ source="builtin",
319
+ os_source="curated",
320
+ ),
321
+ }
322
+
323
+
324
+ def _load_bundled_yaml_rules() -> dict[str, CheckSpec]:
325
+ """Load bundled YAML curated rules from `notaffected/rules/**/*.yaml` into `BUILTIN_SPECS`."""
326
+ rules_root = Path(__file__).resolve().parent.parent / "rules"
327
+ if not rules_root.is_dir():
328
+ return {}
329
+ loaded: dict[str, CheckSpec] = {}
330
+ for yf in sorted(rules_root.rglob("*.yaml")):
331
+ data = yaml.safe_load(yf.read_text(encoding="utf-8"))
332
+ if not isinstance(data, dict) or not isinstance(data.get("rules"), list):
333
+ continue
334
+ for raw in data["rules"]:
335
+ if not isinstance(raw, dict):
336
+ continue
337
+ cve_id = str(raw["cve_id"]).strip().upper()
338
+ pres = [
339
+ Precondition(
340
+ probe=str(p["probe"]).strip(),
341
+ params=dict(p.get("params") or {}),
342
+ description=str(p.get("description") or "").strip(),
343
+ justification_if_not_met=VexJustification(str(p["justification_if_not_met"]).strip()),
344
+ origin="curated",
345
+ )
346
+ for p in raw.get("preconditions", [])
347
+ ]
348
+ raw_patch = raw.get("patch") or {}
349
+ patch = PatchInfo(
350
+ status=str(raw_patch.get("status") or "unknown"),
351
+ fixed_version=raw_patch.get("fixed_version"),
352
+ pocket=raw_patch.get("pocket"),
353
+ advisory_url=raw_patch.get("advisory_url"),
354
+ )
355
+ loaded[cve_id] = CheckSpec(
356
+ cve_id=cve_id,
357
+ summary=str(raw["summary"]).strip(),
358
+ severity=str(raw.get("severity") or "HIGH").strip().upper(),
359
+ preconditions=pres,
360
+ mitigation=[str(m).strip() for m in raw.get("mitigation", []) if str(m).strip()],
361
+ patch=patch,
362
+ confidence=str(raw.get("confidence") or "high").strip().lower(),
363
+ source="builtin",
364
+ os_family=str(raw.get("os_family") or "linux").strip().lower(),
365
+ os_source="curated",
366
+ )
367
+ return loaded
368
+
369
+
370
+ for _cid, _spec in _load_bundled_yaml_rules().items():
371
+ BUILTIN_SPECS.setdefault(_cid, _spec)