orvex 0.2.5__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.
- agents/__init__.py +0 -0
- agents/base.py +149 -0
- agents/critic.py +123 -0
- agents/investigator.py +301 -0
- agents/planner.py +220 -0
- agents/recon.py +85 -0
- assets/__init__.py +0 -0
- audit/__init__.py +0 -0
- audit/hashchain.py +217 -0
- authorization/__init__.py +0 -0
- authorization/approval_manager.py +39 -0
- authorization/policy_engine.py +246 -0
- authorization/scope_manager.py +347 -0
- checklist/__init__.py +0 -0
- checklist/engine.py +200 -0
- checklist/models.py +156 -0
- cli/__init__.py +0 -0
- cli/assess.py +267 -0
- cli/autonomous.py +369 -0
- cli/main.py +670 -0
- cli/setup.py +199 -0
- config/__init__.py +0 -0
- config/settings.py +100 -0
- core/__init__.py +0 -0
- core/budgets.py +176 -0
- core/event_bus.py +40 -0
- core/modes.py +77 -0
- core/orchestrator/__init__.py +0 -0
- core/orchestrator/agentic.py +337 -0
- core/orchestrator/engine.py +1007 -0
- core/state.py +1117 -0
- core/steering.py +206 -0
- execution/__init__.py +0 -0
- execution/core_tools.py +497 -0
- execution/evidence_collector.py +57 -0
- execution/network_broker.py +556 -0
- execution/tool_registry.py +111 -0
- execution/tool_runner.py +262 -0
- findings/__init__.py +0 -0
- leads/__init__.py +0 -0
- models/__init__.py +0 -0
- models/anthropic.py +113 -0
- models/fallback_manager.py +82 -0
- models/identity.py +36 -0
- models/ollama.py +96 -0
- models/openai_compatible.py +140 -0
- models/provider_interface.py +137 -0
- models/role_router.py +119 -0
- orvex-0.2.5.dist-info/METADATA +135 -0
- orvex-0.2.5.dist-info/RECORD +71 -0
- orvex-0.2.5.dist-info/WHEEL +5 -0
- orvex-0.2.5.dist-info/entry_points.txt +4 -0
- orvex-0.2.5.dist-info/licenses/LICENSE +21 -0
- orvex-0.2.5.dist-info/top_level.txt +18 -0
- reconnaissance/ai_application.py +130 -0
- reconnaissance/cve_correlator.py +185 -0
- reconnaissance/network.py +150 -0
- reconnaissance/subdomains.py +270 -0
- reconnaissance/web.py +470 -0
- reporting/__init__.py +0 -0
- reporting/report.py +159 -0
- skills/__init__.py +0 -0
- skills/base.py +322 -0
- tui/__init__.py +0 -0
- tui/app.py +791 -0
- ui/__init__.py +0 -0
- ui/index.html +937 -0
- ui/server.py +542 -0
- verification/__init__.py +0 -0
- verification/fixtures.py +125 -0
- verification/programmatic.py +74 -0
agents/__init__.py
ADDED
|
File without changes
|
agents/base.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Base agent role.
|
|
2
|
+
|
|
3
|
+
An agent role is a thin layer over the role router: it builds prompts,
|
|
4
|
+
calls the configured model via its fallback chain, and records usage.
|
|
5
|
+
When no model is configured for a role, the agent falls back to
|
|
6
|
+
deterministic behavior (never fabricating results).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from core.state import EngagementContext
|
|
14
|
+
from models.provider_interface import ModelCallParams, ModelMessage
|
|
15
|
+
from models.role_router import RoleRouter
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AgentRole:
|
|
19
|
+
role: str = "base"
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
router: RoleRouter | None,
|
|
24
|
+
context: EngagementContext,
|
|
25
|
+
*,
|
|
26
|
+
fallback_ok: bool = True,
|
|
27
|
+
audit=None,
|
|
28
|
+
budgets=None,
|
|
29
|
+
) -> None:
|
|
30
|
+
self.router = router
|
|
31
|
+
self.context = context
|
|
32
|
+
self.fallback_ok = fallback_ok
|
|
33
|
+
self.audit = audit
|
|
34
|
+
self.budgets = budgets
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def configured(self) -> bool:
|
|
38
|
+
return self.router is not None and self.router.has_role(self.role)
|
|
39
|
+
|
|
40
|
+
def _call_model(
|
|
41
|
+
self,
|
|
42
|
+
messages: list[ModelMessage],
|
|
43
|
+
params: ModelCallParams | None = None,
|
|
44
|
+
*,
|
|
45
|
+
reason: str = "",
|
|
46
|
+
lead_id: str = "",
|
|
47
|
+
context_ref: str = "",
|
|
48
|
+
) -> tuple[bool, str, dict[str, Any]]:
|
|
49
|
+
"""Call the configured model. Returns (ok, text, meta).
|
|
50
|
+
|
|
51
|
+
Provider errors never propagate: they degrade to deterministic
|
|
52
|
+
behavior and are recorded (never treated as a clean result).
|
|
53
|
+
"""
|
|
54
|
+
import time as _time
|
|
55
|
+
|
|
56
|
+
if not self.configured:
|
|
57
|
+
return False, "", {"reason": f"no provider configured for role {self.role}"}
|
|
58
|
+
if self.budgets is not None:
|
|
59
|
+
try:
|
|
60
|
+
self.budgets.check()
|
|
61
|
+
except Exception as exc:
|
|
62
|
+
return False, "", {"reason": f"model budget blocked: {exc}", "degraded": True}
|
|
63
|
+
started = _time.time()
|
|
64
|
+
try:
|
|
65
|
+
fb, result = self.router.call(self.role, messages, params)
|
|
66
|
+
except Exception as exc: # noqa: BLE001 - provider/network/parse
|
|
67
|
+
duration_ms = int((_time.time() - started) * 1000)
|
|
68
|
+
err_msg = f"{type(exc).__name__}: {str(exc)[:200]}"
|
|
69
|
+
if self.context is not None:
|
|
70
|
+
self.context.add_activity(
|
|
71
|
+
"model",
|
|
72
|
+
f"{self.role} provider error",
|
|
73
|
+
scenario=lead_id,
|
|
74
|
+
detail=err_msg,
|
|
75
|
+
)
|
|
76
|
+
self.context.add_model_call(
|
|
77
|
+
self.role,
|
|
78
|
+
"error",
|
|
79
|
+
"",
|
|
80
|
+
description=f"{self.role} failed: {err_msg}",
|
|
81
|
+
reason=reason,
|
|
82
|
+
lead_id=lead_id,
|
|
83
|
+
context_ref=context_ref,
|
|
84
|
+
output_preview=err_msg,
|
|
85
|
+
duration_ms=duration_ms,
|
|
86
|
+
status="error",
|
|
87
|
+
)
|
|
88
|
+
if self.audit is not None and self.context is not None:
|
|
89
|
+
self.audit.write(
|
|
90
|
+
"model.error",
|
|
91
|
+
self.role,
|
|
92
|
+
{"error": err_msg, "reason": reason, "lead_id": lead_id},
|
|
93
|
+
self.context.engagement_id,
|
|
94
|
+
)
|
|
95
|
+
return False, "", {"reason": f"provider error: {exc}", "degraded": True}
|
|
96
|
+
resp = result.response
|
|
97
|
+
duration_ms = int(getattr(resp, "duration_ms", 0) or (_time.time() - started) * 1000)
|
|
98
|
+
total_tokens = resp.usage.prompt_tokens + resp.usage.completion_tokens
|
|
99
|
+
if self.budgets is not None:
|
|
100
|
+
self.budgets.record_model_usage(total_tokens, resp.usage.cost_estimate)
|
|
101
|
+
if self.context is not None:
|
|
102
|
+
self.context.record_model_usage(
|
|
103
|
+
self.role,
|
|
104
|
+
resp.provider,
|
|
105
|
+
resp.model,
|
|
106
|
+
prompt_tokens=resp.usage.prompt_tokens,
|
|
107
|
+
completion_tokens=resp.usage.completion_tokens,
|
|
108
|
+
cost_estimate=resp.usage.cost_estimate,
|
|
109
|
+
)
|
|
110
|
+
self.context.add_model_call(
|
|
111
|
+
self.role,
|
|
112
|
+
resp.provider,
|
|
113
|
+
resp.model,
|
|
114
|
+
fallback=result.fallback_used,
|
|
115
|
+
prompt_tokens=resp.usage.prompt_tokens,
|
|
116
|
+
completion_tokens=resp.usage.completion_tokens,
|
|
117
|
+
description=reason or f"{self.role} model call ({len(messages)} messages)",
|
|
118
|
+
reason=reason,
|
|
119
|
+
lead_id=lead_id,
|
|
120
|
+
context_ref=context_ref,
|
|
121
|
+
output_preview=resp.text[:400],
|
|
122
|
+
duration_ms=duration_ms,
|
|
123
|
+
cost_estimate=resp.usage.cost_estimate,
|
|
124
|
+
status="completed",
|
|
125
|
+
)
|
|
126
|
+
if self.audit is not None and self.context is not None:
|
|
127
|
+
self.audit.write(
|
|
128
|
+
"model.call",
|
|
129
|
+
self.role,
|
|
130
|
+
{
|
|
131
|
+
"provider": resp.provider,
|
|
132
|
+
"model": resp.model,
|
|
133
|
+
"fallback": result.fallback_used,
|
|
134
|
+
"prompt_tokens": resp.usage.prompt_tokens,
|
|
135
|
+
"completion_tokens": resp.usage.completion_tokens,
|
|
136
|
+
"duration_ms": duration_ms,
|
|
137
|
+
"reason": reason,
|
|
138
|
+
"lead_id": lead_id,
|
|
139
|
+
"attempts": result.attempts,
|
|
140
|
+
},
|
|
141
|
+
self.context.engagement_id,
|
|
142
|
+
)
|
|
143
|
+
return True, resp.text, {
|
|
144
|
+
"provider": resp.provider,
|
|
145
|
+
"model": resp.model,
|
|
146
|
+
"fallback": result.fallback_used,
|
|
147
|
+
"attempts": result.attempts,
|
|
148
|
+
"duration_ms": duration_ms,
|
|
149
|
+
}
|
agents/critic.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Independent critic agent (Gate 2).
|
|
2
|
+
|
|
3
|
+
The critic attempts to disprove a finding: it re-checks the evidence,
|
|
4
|
+
enforces the skill's false-positive disqualifiers, and -- when a separate
|
|
5
|
+
model is configured -- asks it to challenge the conclusion. Programmatic
|
|
6
|
+
Gate 1 and deterministic FP disqualifiers cannot be bypassed by model prose.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from agents.base import AgentRole
|
|
16
|
+
from models.provider_interface import ModelCallParams, ModelMessage
|
|
17
|
+
from skills.base import SkillSpec
|
|
18
|
+
from verification.programmatic import verify_finding
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CriticAgent(AgentRole):
|
|
22
|
+
role = "critic"
|
|
23
|
+
|
|
24
|
+
def review(
|
|
25
|
+
self, context: Any, finding_id: str, skill: SkillSpec | None
|
|
26
|
+
) -> dict[str, Any]:
|
|
27
|
+
gate1 = verify_finding(context, finding_id)
|
|
28
|
+
if not gate1.passed:
|
|
29
|
+
return {
|
|
30
|
+
"verdict": "rejected",
|
|
31
|
+
"detail": "programmatic gate failed: " + "; ".join(gate1.reasons),
|
|
32
|
+
"model_used": "",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
finding = context.finding(finding_id)
|
|
36
|
+
disqualifiers: list[str] = list(skill.fp_disqualifiers) if skill is not None else []
|
|
37
|
+
|
|
38
|
+
# Evaluate false-positive disqualifiers against actual evidence & finding text.
|
|
39
|
+
haystack = (finding.get("description") or "").lower()
|
|
40
|
+
for ref in finding.get("evidence_refs") or []:
|
|
41
|
+
ev = context.evidence(ref)
|
|
42
|
+
if ev is not None:
|
|
43
|
+
haystack += " " + (ev.get("content") or "").lower()
|
|
44
|
+
disqualifier_matches = [dq for dq in disqualifiers if dq.lower() in haystack]
|
|
45
|
+
if disqualifier_matches:
|
|
46
|
+
return {
|
|
47
|
+
"verdict": "rejected",
|
|
48
|
+
"detail": f"false-positive disqualifier matched evidence: {', '.join(disqualifier_matches)}",
|
|
49
|
+
"model_used": "",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if self.configured:
|
|
53
|
+
ok, text, meta = self._call_model(
|
|
54
|
+
[
|
|
55
|
+
ModelMessage(
|
|
56
|
+
"system",
|
|
57
|
+
"You are an independent adversarial security critic. Challenge candidate findings "
|
|
58
|
+
"against false-positive disqualifiers and evidence quality. Return strict JSON: "
|
|
59
|
+
'{"verdict":"upheld|rejected","reason":"<concise justification>"}.',
|
|
60
|
+
),
|
|
61
|
+
ModelMessage(
|
|
62
|
+
"user",
|
|
63
|
+
f"Finding: {json.dumps(finding, default=str)[:1800]}\n"
|
|
64
|
+
f"FP disqualifiers: {json.dumps(disqualifiers)}",
|
|
65
|
+
),
|
|
66
|
+
],
|
|
67
|
+
ModelCallParams(max_tokens=400),
|
|
68
|
+
reason=f"adversarial verification of finding {finding_id}",
|
|
69
|
+
lead_id=str(finding.get("checklist_item_id", "")),
|
|
70
|
+
context_ref=finding_id,
|
|
71
|
+
)
|
|
72
|
+
if ok and text.strip():
|
|
73
|
+
verdict, detail = self._parse_critic_response(text)
|
|
74
|
+
return {
|
|
75
|
+
"verdict": verdict,
|
|
76
|
+
"detail": detail[:1500],
|
|
77
|
+
"model_used": f"{meta.get('provider')}/{meta.get('model')}",
|
|
78
|
+
}
|
|
79
|
+
reason = (
|
|
80
|
+
"empty model response"
|
|
81
|
+
if ok
|
|
82
|
+
else (meta.get("reason", "unavailable") if isinstance(meta, dict) else "unavailable")
|
|
83
|
+
)
|
|
84
|
+
return {
|
|
85
|
+
"verdict": "upheld",
|
|
86
|
+
"detail": f"critic model unavailable ({reason}); deterministic critic used (FP disqualifiers evaluated: {len(disqualifiers)}, 0 matched)",
|
|
87
|
+
"model_used": "",
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
fp_note = (
|
|
91
|
+
f"; FP disqualifiers evaluated: {len(disqualifiers)} "
|
|
92
|
+
f"({len(disqualifier_matches)} matched evidence)"
|
|
93
|
+
if disqualifiers
|
|
94
|
+
else ""
|
|
95
|
+
)
|
|
96
|
+
return {
|
|
97
|
+
"verdict": "upheld",
|
|
98
|
+
"detail": "programmatic gate passed; no critic model configured" + fp_note,
|
|
99
|
+
"model_used": "",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def _parse_critic_response(text: str) -> tuple[str, str]:
|
|
104
|
+
raw = (text or "").strip()
|
|
105
|
+
if raw.startswith("```"):
|
|
106
|
+
raw = "\n".join(ln for ln in raw.splitlines() if not ln.strip().startswith("```")).strip()
|
|
107
|
+
if raw.startswith("{") or ("{" in raw and "}" in raw):
|
|
108
|
+
candidate = raw if raw.startswith("{") else raw[raw.find("{") : raw.rfind("}") + 1]
|
|
109
|
+
try:
|
|
110
|
+
parsed = json.loads(candidate)
|
|
111
|
+
v = str(parsed.get("verdict", "")).lower().strip()
|
|
112
|
+
if v in ("rejected", "reject"):
|
|
113
|
+
return "rejected", str(parsed.get("reason") or raw)
|
|
114
|
+
if v in ("upheld", "uphold", "clear", "confirmed"):
|
|
115
|
+
return "upheld", str(parsed.get("reason") or raw)
|
|
116
|
+
except Exception:
|
|
117
|
+
pass
|
|
118
|
+
# Explicit verdict-line fallback; avoids matching "cannot reject".
|
|
119
|
+
if re.search(r"(?im)^\s*(?:verdict\s*:\s*)?reject(?:ed)?\b", raw) or re.search(
|
|
120
|
+
r"(?i)\bthis is not a vulnerability\b", raw
|
|
121
|
+
):
|
|
122
|
+
return "rejected", raw
|
|
123
|
+
return "upheld", raw
|
agents/investigator.py
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"""Investigator agent: interprets test observations.
|
|
2
|
+
|
|
3
|
+
Maps tool output to a checklist result (confirmed / not observed /
|
|
4
|
+
inconclusive / manual review) while applying deterministic signal checks
|
|
5
|
+
and skill false-positive disqualifiers. When a model is configured and
|
|
6
|
+
explicitly requested for ambiguous output, it enriches or classifies without
|
|
7
|
+
ever overriding a deterministic failure or disqualifier.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import re
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from agents.base import AgentRole
|
|
17
|
+
from checklist.models import (
|
|
18
|
+
RESULT_CONFIRMED,
|
|
19
|
+
RESULT_INCONCLUSIVE,
|
|
20
|
+
RESULT_MANUAL,
|
|
21
|
+
RESULT_NOT_OBSERVED,
|
|
22
|
+
)
|
|
23
|
+
from execution.tool_runner import RunResult
|
|
24
|
+
from models.provider_interface import ModelCallParams, ModelMessage
|
|
25
|
+
from skills.base import SkillSpec
|
|
26
|
+
|
|
27
|
+
_VERSION_HEADER_NAMES = frozenset(
|
|
28
|
+
{"server", "x-powered-by", "x-aspnet-version", "x-generator", "x-runtime"}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class InvestigatorAgent(AgentRole):
|
|
33
|
+
role = "investigator"
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def _header_version_leaks(headers: dict) -> list[str]:
|
|
37
|
+
leaks: list[str] = []
|
|
38
|
+
for header, value in (headers or {}).items():
|
|
39
|
+
if header.lower() not in _VERSION_HEADER_NAMES:
|
|
40
|
+
continue
|
|
41
|
+
if isinstance(value, str) and re.search(r"\b\d+\.\d+(?:\.\d+)?\b", value):
|
|
42
|
+
leaks.append(f"{header}={value.strip()[:40]}")
|
|
43
|
+
return leaks
|
|
44
|
+
|
|
45
|
+
ALLOWED_VERDICTS = {
|
|
46
|
+
RESULT_CONFIRMED, RESULT_NOT_OBSERVED, RESULT_INCONCLUSIVE, RESULT_MANUAL,
|
|
47
|
+
}
|
|
48
|
+
_TOKEN_TO_VERDICT = {
|
|
49
|
+
"confirmed": RESULT_CONFIRMED,
|
|
50
|
+
"vulnerability_confirmed": RESULT_CONFIRMED,
|
|
51
|
+
"not_observed": RESULT_NOT_OBSERVED,
|
|
52
|
+
"vulnerability_not_observed": RESULT_NOT_OBSERVED,
|
|
53
|
+
"inconclusive": RESULT_INCONCLUSIVE,
|
|
54
|
+
"manual_review": RESULT_MANUAL,
|
|
55
|
+
"requires_manual_review": RESULT_MANUAL,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
def _model_judge(self, run: RunResult, *, reason: str = "classify ambiguous tool output") -> tuple[str, str, str] | None:
|
|
59
|
+
"""Ask the configured model to classify an ambiguous result; only
|
|
60
|
+
whitelisted verdicts are accepted, and failures fall back safely."""
|
|
61
|
+
if not self.configured or self.context is None:
|
|
62
|
+
return None
|
|
63
|
+
ok, text, _ = self._call_model(
|
|
64
|
+
[
|
|
65
|
+
ModelMessage(
|
|
66
|
+
"system",
|
|
67
|
+
"You are a security investigator. Classify observed tool output strictly from evidence. "
|
|
68
|
+
"Never claim a vulnerability without supporting output.",
|
|
69
|
+
),
|
|
70
|
+
ModelMessage(
|
|
71
|
+
"user",
|
|
72
|
+
"Classify this tool result for a security engagement. Return JSON "
|
|
73
|
+
'{"verdict":"confirmed|not_observed|inconclusive|manual_review",'
|
|
74
|
+
'"analysis":"<one sentence>","confidence":"low|medium|high"}.\n'
|
|
75
|
+
f"Result: {str(run.output)[:1800]}",
|
|
76
|
+
),
|
|
77
|
+
],
|
|
78
|
+
ModelCallParams(max_tokens=300),
|
|
79
|
+
reason=reason,
|
|
80
|
+
context_ref=str(run.execution_id or ""),
|
|
81
|
+
)
|
|
82
|
+
if not ok:
|
|
83
|
+
return None
|
|
84
|
+
raw = text.strip()
|
|
85
|
+
if raw.startswith("```"):
|
|
86
|
+
raw = "\n".join(ln for ln in raw.splitlines() if not ln.strip().startswith("```")).strip()
|
|
87
|
+
if not raw.startswith("{"):
|
|
88
|
+
start = raw.find("{")
|
|
89
|
+
end = raw.rfind("}")
|
|
90
|
+
if start == -1 or end <= start:
|
|
91
|
+
return None
|
|
92
|
+
raw = raw[start : end + 1]
|
|
93
|
+
try:
|
|
94
|
+
parsed = json.loads(raw)
|
|
95
|
+
except Exception:
|
|
96
|
+
return None
|
|
97
|
+
token = str(parsed.get("verdict", "")).lower()
|
|
98
|
+
verdict = self._TOKEN_TO_VERDICT.get(token)
|
|
99
|
+
if verdict is None:
|
|
100
|
+
return None
|
|
101
|
+
analysis = str(parsed.get("analysis", ""))[:500]
|
|
102
|
+
confidence = str(parsed.get("confidence", "low"))
|
|
103
|
+
if confidence not in ("low", "medium", "high"):
|
|
104
|
+
confidence = "low"
|
|
105
|
+
return verdict, analysis or "model-assessed result", confidence
|
|
106
|
+
|
|
107
|
+
def evaluate(
|
|
108
|
+
self, skill: SkillSpec | None, run: RunResult, *, use_model: bool = False
|
|
109
|
+
) -> tuple[str, str, str]:
|
|
110
|
+
"""Return (result_code, analysis, confidence)."""
|
|
111
|
+
if not run.success:
|
|
112
|
+
return RESULT_INCONCLUSIVE, f"execution failed: {run.error}", "low"
|
|
113
|
+
|
|
114
|
+
out = dict(run.output or {})
|
|
115
|
+
analysis_parts: list[str] = []
|
|
116
|
+
verdict = RESULT_NOT_OBSERVED
|
|
117
|
+
confidence = "high"
|
|
118
|
+
deterministic_signal = False
|
|
119
|
+
_rank = {
|
|
120
|
+
RESULT_NOT_OBSERVED: 0,
|
|
121
|
+
RESULT_INCONCLUSIVE: 1,
|
|
122
|
+
RESULT_MANUAL: 2,
|
|
123
|
+
RESULT_CONFIRMED: 3,
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
def _elevate(new_verdict: str, new_conf: str | None = None) -> None:
|
|
127
|
+
nonlocal verdict, confidence
|
|
128
|
+
if _rank.get(new_verdict, 0) > _rank.get(verdict, 0):
|
|
129
|
+
verdict = new_verdict
|
|
130
|
+
if new_conf is not None:
|
|
131
|
+
confidence = new_conf
|
|
132
|
+
|
|
133
|
+
if "missing_security_headers" in out:
|
|
134
|
+
deterministic_signal = True
|
|
135
|
+
status = out.get("status_code")
|
|
136
|
+
if status is not None and not (200 <= status < 400):
|
|
137
|
+
return (
|
|
138
|
+
RESULT_INCONCLUSIVE,
|
|
139
|
+
f"unexpected HTTP status {status}; application response not obtained",
|
|
140
|
+
"low",
|
|
141
|
+
)
|
|
142
|
+
missing = out.get("missing_security_headers") or []
|
|
143
|
+
if missing:
|
|
144
|
+
_elevate(RESULT_CONFIRMED)
|
|
145
|
+
analysis_parts.append(f"missing security headers: {', '.join(missing)}")
|
|
146
|
+
else:
|
|
147
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
148
|
+
analysis_parts.append("all expected security headers present")
|
|
149
|
+
leaks = self._header_version_leaks(out.get("headers", {}))
|
|
150
|
+
if leaks:
|
|
151
|
+
out["version_leaks"] = leaks
|
|
152
|
+
_elevate(RESULT_CONFIRMED)
|
|
153
|
+
analysis_parts.append(f"version disclosure: {', '.join(leaks)}")
|
|
154
|
+
|
|
155
|
+
if "insecure_auth_transport" in out or "cookie_issues" in out:
|
|
156
|
+
deterministic_signal = True
|
|
157
|
+
status = out.get("status_code")
|
|
158
|
+
if status is not None and not (200 <= status < 400):
|
|
159
|
+
return (
|
|
160
|
+
RESULT_INCONCLUSIVE,
|
|
161
|
+
f"unexpected HTTP status {status} on auth surface",
|
|
162
|
+
"low",
|
|
163
|
+
)
|
|
164
|
+
issues: list[str] = []
|
|
165
|
+
if out.get("insecure_auth_transport"):
|
|
166
|
+
issues.append("login form served over cleartext HTTP")
|
|
167
|
+
if out.get("missing_csrf_token"):
|
|
168
|
+
issues.append("login/password form lacks detectable CSRF token")
|
|
169
|
+
if out.get("cookie_issues"):
|
|
170
|
+
issues.append(f"cookie flags missing: {', '.join(out['cookie_issues'])}")
|
|
171
|
+
if issues:
|
|
172
|
+
_elevate(RESULT_CONFIRMED, "high" if out.get("insecure_auth_transport") else "medium")
|
|
173
|
+
analysis_parts.append("; ".join(issues))
|
|
174
|
+
else:
|
|
175
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
176
|
+
analysis_parts.append("no transport, cookie flag, or CSRF issues detected on auth surface")
|
|
177
|
+
|
|
178
|
+
if "permissive_cors" in out:
|
|
179
|
+
deterministic_signal = True
|
|
180
|
+
status = out.get("status_code")
|
|
181
|
+
if status is not None and not (200 <= status < 400):
|
|
182
|
+
return (
|
|
183
|
+
RESULT_INCONCLUSIVE,
|
|
184
|
+
f"unexpected HTTP status {status} on API endpoint",
|
|
185
|
+
"low",
|
|
186
|
+
)
|
|
187
|
+
if out.get("permissive_cors"):
|
|
188
|
+
_elevate(RESULT_CONFIRMED)
|
|
189
|
+
analysis_parts.append("permissive CORS (Access-Control-Allow-Origin: * with credentials)")
|
|
190
|
+
else:
|
|
191
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
192
|
+
allow = out.get("allow_methods") or "default"
|
|
193
|
+
analysis_parts.append(f"API endpoint inspected (methods={allow}; no wildcard+credentials CORS)")
|
|
194
|
+
|
|
195
|
+
if "graphql_introspection_enabled" in out:
|
|
196
|
+
deterministic_signal = True
|
|
197
|
+
if out.get("graphql_introspection_enabled"):
|
|
198
|
+
_elevate(RESULT_CONFIRMED)
|
|
199
|
+
analysis_parts.append(
|
|
200
|
+
f"GraphQL introspection enabled ({out.get('schema_types_count', 0)} schema types exposed)"
|
|
201
|
+
)
|
|
202
|
+
else:
|
|
203
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
204
|
+
analysis_parts.append("GraphQL introspection not enabled")
|
|
205
|
+
|
|
206
|
+
if "unrestricted_upload_input" in out:
|
|
207
|
+
deterministic_signal = True
|
|
208
|
+
if out.get("unrestricted_upload_input"):
|
|
209
|
+
_elevate(RESULT_MANUAL, "medium")
|
|
210
|
+
analysis_parts.append(
|
|
211
|
+
"file upload input lacks client-side accept restriction; server-side validation requires manual review"
|
|
212
|
+
)
|
|
213
|
+
else:
|
|
214
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
215
|
+
analysis_parts.append("no unrestricted upload surface observed")
|
|
216
|
+
|
|
217
|
+
if "open" in out and not any(k in out for k in ("expired", "fingerprint")):
|
|
218
|
+
deterministic_signal = True
|
|
219
|
+
if out.get("open"):
|
|
220
|
+
_elevate(RESULT_MANUAL)
|
|
221
|
+
analysis_parts.append(
|
|
222
|
+
f"service reachable on {out.get('host')}:{out.get('port')}; "
|
|
223
|
+
"service-level fingerprinting required"
|
|
224
|
+
)
|
|
225
|
+
else:
|
|
226
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
227
|
+
analysis_parts.append("port not reachable")
|
|
228
|
+
|
|
229
|
+
if "injected_instruction_obeyed" in out:
|
|
230
|
+
deterministic_signal = True
|
|
231
|
+
obeys = out.get("injected_instruction_obeyed")
|
|
232
|
+
leaked = out.get("system_prompt_leaked")
|
|
233
|
+
if obeys:
|
|
234
|
+
_elevate(RESULT_CONFIRMED)
|
|
235
|
+
analysis_parts.append("model obeyed injected instruction over governing prompt")
|
|
236
|
+
elif leaked:
|
|
237
|
+
_elevate(RESULT_CONFIRMED)
|
|
238
|
+
analysis_parts.append("model leaked system-prompt material in response")
|
|
239
|
+
else:
|
|
240
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
241
|
+
analysis_parts.append("no behavioral difference from baseline")
|
|
242
|
+
|
|
243
|
+
if "expired" in out:
|
|
244
|
+
deterministic_signal = True
|
|
245
|
+
if out.get("expired"):
|
|
246
|
+
_elevate(RESULT_CONFIRMED)
|
|
247
|
+
analysis_parts.append(
|
|
248
|
+
f"TLS certificate expired (not after {out.get('not_after')})"
|
|
249
|
+
)
|
|
250
|
+
elif out.get("verify_failed"):
|
|
251
|
+
_elevate(RESULT_MANUAL)
|
|
252
|
+
analysis_parts.append(
|
|
253
|
+
f"TLS certificate verification failed: {out.get('tls_error', 'untrusted')}"
|
|
254
|
+
)
|
|
255
|
+
elif out.get("protocol") in ("TLSv1", "TLSv1.1"):
|
|
256
|
+
_elevate(RESULT_CONFIRMED)
|
|
257
|
+
analysis_parts.append(f"legacy TLS protocol in use: {out.get('protocol')}")
|
|
258
|
+
else:
|
|
259
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
260
|
+
analysis_parts.append(f"TLS configuration nominal ({out.get('protocol')})")
|
|
261
|
+
|
|
262
|
+
if "fingerprint" in out:
|
|
263
|
+
deterministic_signal = True
|
|
264
|
+
fp = out.get("fingerprint")
|
|
265
|
+
if fp and fp != "unknown":
|
|
266
|
+
_elevate(RESULT_CONFIRMED)
|
|
267
|
+
analysis_parts.append(f"exposed service identified via banner: {fp}")
|
|
268
|
+
else:
|
|
269
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
270
|
+
analysis_parts.append("no identifying banner observed")
|
|
271
|
+
|
|
272
|
+
if "canary_in_retrieved_response" in out:
|
|
273
|
+
deterministic_signal = True
|
|
274
|
+
if out.get("canary_in_retrieved_response"):
|
|
275
|
+
_elevate(RESULT_CONFIRMED)
|
|
276
|
+
analysis_parts.append("retrieved-context canary leaked into model response")
|
|
277
|
+
else:
|
|
278
|
+
_elevate(RESULT_NOT_OBSERVED)
|
|
279
|
+
analysis_parts.append("no canary leakage from retrieved context")
|
|
280
|
+
|
|
281
|
+
if "version_leaks" in out and out.get("version_leaks"):
|
|
282
|
+
deterministic_signal = True
|
|
283
|
+
_elevate(RESULT_CONFIRMED)
|
|
284
|
+
if not any("version disclosure" in p for p in analysis_parts):
|
|
285
|
+
analysis_parts.append("server/technology version information disclosed in headers")
|
|
286
|
+
|
|
287
|
+
if not deterministic_signal:
|
|
288
|
+
if use_model:
|
|
289
|
+
judged = self._model_judge(run, reason="classify tool output without deterministic parser")
|
|
290
|
+
if judged is not None:
|
|
291
|
+
return judged
|
|
292
|
+
if out.get("ok") and str(out.get("status_code", "")) not in ("", "200", "204"):
|
|
293
|
+
verdict = RESULT_INCONCLUSIVE
|
|
294
|
+
analysis_parts.append(
|
|
295
|
+
f"unexpected status {out.get('status_code')}; manual review needed"
|
|
296
|
+
)
|
|
297
|
+
confidence = "low"
|
|
298
|
+
else:
|
|
299
|
+
analysis_parts.append("no vulnerability signals observed in output")
|
|
300
|
+
|
|
301
|
+
return verdict, "; ".join(analysis_parts), confidence
|