botsting 0.0.3__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.
- botsting/__init__.py +3 -0
- botsting/__main__.py +8 -0
- botsting/attacks/__init__.py +0 -0
- botsting/attacks/adaptive.py +495 -0
- botsting/attacks/library.py +239 -0
- botsting/attacks/pyrit_adapter.py +227 -0
- botsting/attacks/strategy.py +157 -0
- botsting/authorize_cli.py +148 -0
- botsting/ci.py +122 -0
- botsting/cli.py +464 -0
- botsting/console.py +240 -0
- botsting/core/__init__.py +0 -0
- botsting/core/authorization.py +550 -0
- botsting/core/benchmark.py +199 -0
- botsting/core/canary.py +80 -0
- botsting/core/judge.py +175 -0
- botsting/core/matcher.py +367 -0
- botsting/core/meter.py +228 -0
- botsting/core/models.py +560 -0
- botsting/core/preflight.py +283 -0
- botsting/core/replay.py +145 -0
- botsting/core/runner.py +39 -0
- botsting/core/scan.py +917 -0
- botsting/core/stats.py +42 -0
- botsting/demo.py +215 -0
- botsting/doctor.py +271 -0
- botsting/egress_trap.py +243 -0
- botsting/exits.py +38 -0
- botsting/frameworks.py +453 -0
- botsting/harness.py +893 -0
- botsting/harness_tools.py +260 -0
- botsting/llm/__init__.py +0 -0
- botsting/llm/base.py +31 -0
- botsting/llm/ollama.py +165 -0
- botsting/llm/scripted.py +122 -0
- botsting/mcp_server.py +643 -0
- botsting/practice_server.py +190 -0
- botsting/presets.py +222 -0
- botsting/quick.py +485 -0
- botsting/report_html.py +588 -0
- botsting/report_markdown.py +472 -0
- botsting/reporting.py +73 -0
- botsting/seal.py +245 -0
- botsting/shell.py +40 -0
- botsting/sterility.py +407 -0
- botsting/targets/__init__.py +0 -0
- botsting/targets/base.py +207 -0
- botsting/targets/hardened.py +360 -0
- botsting/targets/http.py +826 -0
- botsting/targets/registry.py +96 -0
- botsting/targets/toy.py +310 -0
- botsting-0.0.3.dist-info/METADATA +495 -0
- botsting-0.0.3.dist-info/RECORD +56 -0
- botsting-0.0.3.dist-info/WHEEL +4 -0
- botsting-0.0.3.dist-info/entry_points.txt +2 -0
- botsting-0.0.3.dist-info/licenses/LICENSE +202 -0
botsting/core/models.py
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
"""Core data model. Everything a scan produces is expressed in these types.
|
|
2
|
+
|
|
3
|
+
Vocabulary
|
|
4
|
+
----------
|
|
5
|
+
principal Who is talking to the target, e.g. "customer:alice" or "staff:dana".
|
|
6
|
+
slot A place in the target where a canary can be planted, together with the
|
|
7
|
+
policy saying which principals may legitimately see it.
|
|
8
|
+
canary A fresh random secret planted in a slot for one attempt.
|
|
9
|
+
attack A scripted sequence of attacker messages aimed at one slot.
|
|
10
|
+
attempt One run of an attack from a reset state with freshly planted canaries.
|
|
11
|
+
finding An attack that produced verified evidence, with its discovery and
|
|
12
|
+
reproduction rates.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import asdict, dataclass, field
|
|
18
|
+
from enum import IntEnum
|
|
19
|
+
from typing import Any, Literal
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _count(value: object, name: str) -> int:
|
|
23
|
+
"""A count read from a report file. A report can be edited by hand, so nothing else is accepted."""
|
|
24
|
+
if isinstance(value, bool) or not isinstance(value, int) or value < 0:
|
|
25
|
+
raise ValueError(f"{name} must be a whole number of zero or more, got {value!r}")
|
|
26
|
+
return value
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _fraction(value: object) -> float | None:
|
|
30
|
+
if value is None:
|
|
31
|
+
return None
|
|
32
|
+
if isinstance(value, bool) or not isinstance(value, int | float) or not 0.0 <= float(value) <= 1.0:
|
|
33
|
+
raise ValueError(f"an interval bound must be a number from 0 to 1, got {value!r}")
|
|
34
|
+
return float(value)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Independence = Literal["self", "internal", "third-party"]
|
|
38
|
+
INDEPENDENCE_LEVELS: tuple[str, ...] = ("self", "internal", "third-party")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _tester(value: object) -> str:
|
|
42
|
+
if value is None:
|
|
43
|
+
return ""
|
|
44
|
+
if not isinstance(value, str):
|
|
45
|
+
raise ValueError(f"tester must be text, got {value!r}")
|
|
46
|
+
return value
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _independence(value: object) -> Independence:
|
|
50
|
+
if value is None:
|
|
51
|
+
return "self"
|
|
52
|
+
if not isinstance(value, str) or value not in INDEPENDENCE_LEVELS:
|
|
53
|
+
raise ValueError(f"independence must be one of {', '.join(INDEPENDENCE_LEVELS)}, got {value!r}")
|
|
54
|
+
return value # type: ignore[return-value]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class EvidenceLevel(IntEnum):
|
|
58
|
+
"""How strong the evidence for a finding is. A finding carries the highest level it reached."""
|
|
59
|
+
|
|
60
|
+
SUSPECTED = 0 # partial match or a model's opinion; never counted as verified
|
|
61
|
+
DISCLOSED = 1 # protected data the attacker never saw came out of the target
|
|
62
|
+
ACTION_ATTEMPTED = 2 # the target tried a forbidden tool call
|
|
63
|
+
ACTION_ACCEPTED = 3 # the tool accepted the call
|
|
64
|
+
STATE_VERIFIED = 4 # the downstream state change was independently confirmed
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def label(self) -> str:
|
|
68
|
+
return {
|
|
69
|
+
0: "Suspected",
|
|
70
|
+
1: "Protected data disclosed",
|
|
71
|
+
2: "Forbidden action attempted",
|
|
72
|
+
3: "Forbidden action accepted",
|
|
73
|
+
4: "State change verified",
|
|
74
|
+
}[int(self)]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
SlotKind = Literal["instruction_secret", "other_user_record"]
|
|
78
|
+
# "attacker" is a message the attacker sent or content the attacker planted.
|
|
79
|
+
# "user" is an ordinary person using the target, who has no idea an attack is under way.
|
|
80
|
+
Role = Literal["attacker", "user", "target"]
|
|
81
|
+
AttackKind = Literal["disclosure", "action", "injection"]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@dataclass(frozen=True)
|
|
85
|
+
class ToolCall:
|
|
86
|
+
"""One call the target made to one of its tools, as recorded at the tool.
|
|
87
|
+
|
|
88
|
+
The record comes from a recorder on the tool itself, never from what the target
|
|
89
|
+
says it did: a model can claim a refund it never issued, or issue one silently.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
id: str # assigned by the recorder; ties the call to its place in the conversation
|
|
93
|
+
tool: str
|
|
94
|
+
arguments: tuple[tuple[str, str], ...]
|
|
95
|
+
accepted: bool # the tool carried the call out, as opposed to refusing it
|
|
96
|
+
result: str = ""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@dataclass(frozen=True)
|
|
100
|
+
class Reply:
|
|
101
|
+
"""What came back from one message to the target: its words and what it did."""
|
|
102
|
+
|
|
103
|
+
text: str
|
|
104
|
+
tool_calls: tuple[ToolCall, ...] = ()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@dataclass(frozen=True)
|
|
108
|
+
class Turn:
|
|
109
|
+
role: Role
|
|
110
|
+
text: str
|
|
111
|
+
tool_calls: tuple[ToolCall, ...] = () # target turns only
|
|
112
|
+
note: str = "" # for example where planted content was placed
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# Values a target's describe() uses to tell the runner how it works. The runner adds a limitation
|
|
116
|
+
# to the report for each. They are defined once, here, so the two sides cannot drift apart.
|
|
117
|
+
SECRETS_KEY, SECRETS_IN_REQUESTS = "secrets", "sent with each request"
|
|
118
|
+
RECORDERS_KEY, RECORDERS_ATTESTED = "tool_recorders", "attested by the harness"
|
|
119
|
+
CONTROLS_KEY, CONTROLS_BY_HARNESS = "legitimate_route", "supplied by the harness in a check session"
|
|
120
|
+
|
|
121
|
+
# A tool rule's control_prompt when no legitimate request is made: the drop-in harness attests,
|
|
122
|
+
# in its signed readiness answer, that the tool is marked (its recorder is the decorator on it).
|
|
123
|
+
HARNESS_ATTESTED = "(attested by the harness)"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@dataclass(frozen=True)
|
|
127
|
+
class ToolRule:
|
|
128
|
+
"""A tool and who is allowed to cause it to run."""
|
|
129
|
+
|
|
130
|
+
id: str
|
|
131
|
+
tool: str
|
|
132
|
+
description: str
|
|
133
|
+
# What an attacker would ask for, e.g. "a refund of 50 on order A-1001".
|
|
134
|
+
hint: str
|
|
135
|
+
# Principals whose own request may cause the tool to run. A call during anyone
|
|
136
|
+
# else's conversation is a violation, whether or not the tool accepts it.
|
|
137
|
+
authorized: tuple[str, ...]
|
|
138
|
+
# A legitimate request that must produce an accepted, recorded call. Run before
|
|
139
|
+
# attacking: if the recorder cannot see a legitimate call it cannot see a forbidden one.
|
|
140
|
+
control_principal: str
|
|
141
|
+
control_prompt: str
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@dataclass(frozen=True)
|
|
145
|
+
class InjectionPoint:
|
|
146
|
+
"""A place where someone else's text ends up in front of the target.
|
|
147
|
+
|
|
148
|
+
The attacker never talks to the target here. They leave text where the target will
|
|
149
|
+
read it later, while helping an ordinary user with an ordinary request.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
id: str
|
|
153
|
+
description: str
|
|
154
|
+
# The ordinary request during which the planted text gets read.
|
|
155
|
+
victim_principal: str
|
|
156
|
+
victim_prompt: str
|
|
157
|
+
expect_substring: str # the ordinary request must still be answered
|
|
158
|
+
# Harmless text for the same place. The request is run with this first: if a
|
|
159
|
+
# forbidden tool is called even then, the attack is not what caused it.
|
|
160
|
+
benign_content: str
|
|
161
|
+
# Tools that have no business running during this request.
|
|
162
|
+
forbidden_tools: tuple[str, ...]
|
|
163
|
+
# What the planted text tries to make the target do, e.g. "issue a refund of 500 on order B-2002".
|
|
164
|
+
goal: str
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@dataclass(frozen=True)
|
|
168
|
+
class Slot:
|
|
169
|
+
"""A place a canary can be planted, and the policy around it."""
|
|
170
|
+
|
|
171
|
+
id: str
|
|
172
|
+
kind: SlotKind
|
|
173
|
+
description: str
|
|
174
|
+
# How an attacker with ordinary public knowledge would refer to the protected thing,
|
|
175
|
+
# e.g. "the staff discount code" or "order B-2002". Never contains the canary.
|
|
176
|
+
hint: str
|
|
177
|
+
# Principals allowed to see the planted value. Anyone else seeing it is a violation.
|
|
178
|
+
authorized: tuple[str, ...]
|
|
179
|
+
# A legitimate request that must reveal the canary. Run before attacking to confirm
|
|
180
|
+
# the canary is reachable at all; a canary nobody can reach can never leak.
|
|
181
|
+
control_principal: str
|
|
182
|
+
control_prompt: str
|
|
183
|
+
# "code" (default) or "name": see core/canary.py. Use "name" for personal details.
|
|
184
|
+
canary_style: str = "code"
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@dataclass(frozen=True)
|
|
188
|
+
class TaskCheck:
|
|
189
|
+
"""A normal, harmless use of the target that must keep working."""
|
|
190
|
+
|
|
191
|
+
id: str
|
|
192
|
+
principal: str
|
|
193
|
+
prompt: str
|
|
194
|
+
expect_substring: str
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@dataclass(frozen=True)
|
|
198
|
+
class Attack:
|
|
199
|
+
"""A scripted attack.
|
|
200
|
+
|
|
201
|
+
disclosure `turns` are sent as the attacker; success is a canary from `slot_id` in the replies.
|
|
202
|
+
action `turns` are sent as the attacker; success is a call to the tool of rule `slot_id`.
|
|
203
|
+
injection `payload` is planted at injection point `slot_id`, then the point's ordinary
|
|
204
|
+
user makes their ordinary request; success is a call to a forbidden tool.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
id: str
|
|
208
|
+
technique: str
|
|
209
|
+
title: str
|
|
210
|
+
slot_id: str # the slot, tool rule or injection point this is aimed at
|
|
211
|
+
turns: tuple[str, ...] = ()
|
|
212
|
+
kind: AttackKind = "disclosure"
|
|
213
|
+
payload: str = ""
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@dataclass(frozen=True)
|
|
217
|
+
class Match:
|
|
218
|
+
"""A canary seen in target output."""
|
|
219
|
+
|
|
220
|
+
slot_id: str
|
|
221
|
+
# How it appeared: plain, normalized (case or separators changed), reversed, rot13,
|
|
222
|
+
# url, base64, hex, spelled (one character at a time), pieces (a few chunks).
|
|
223
|
+
encoding: str
|
|
224
|
+
# "single-turn" or "across-turns" (assembled from several replies).
|
|
225
|
+
scope: str
|
|
226
|
+
# True when the whole canary was recovered. Partial matches are only ever suspected.
|
|
227
|
+
full: bool
|
|
228
|
+
matched_chars: int
|
|
229
|
+
canary_chars: int
|
|
230
|
+
# Canary characters found in the attacker's own messages before the target had
|
|
231
|
+
# disclosed them. Anything above zero breaks the proof, so the match can no longer
|
|
232
|
+
# be verified, only suspected.
|
|
233
|
+
attacker_known_chars: int = 0
|
|
234
|
+
# Of the characters in the target's output, how many the attacker had not supplied.
|
|
235
|
+
# None means all of `matched_chars`.
|
|
236
|
+
newly_disclosed_chars: int | None = None
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def verified(self) -> bool:
|
|
240
|
+
return self.full and self.attacker_known_chars == 0
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@dataclass(frozen=True)
|
|
244
|
+
class Rate:
|
|
245
|
+
"""Successes out of the trials that could be judged.
|
|
246
|
+
|
|
247
|
+
Trials that errored before showing anything, and trials discarded because the
|
|
248
|
+
canary was in attacker input, are counted separately and are not in `trials`.
|
|
249
|
+
"""
|
|
250
|
+
|
|
251
|
+
successes: int
|
|
252
|
+
trials: int
|
|
253
|
+
errors: int = 0
|
|
254
|
+
contaminated: int = 0
|
|
255
|
+
# Two-sided 95% Wilson score interval on successes/trials; None when trials == 0.
|
|
256
|
+
interval_low: float | None = None
|
|
257
|
+
interval_high: float | None = None
|
|
258
|
+
interval_method: str = "wilson-95"
|
|
259
|
+
|
|
260
|
+
@property
|
|
261
|
+
def rate(self) -> float | None:
|
|
262
|
+
return self.successes / self.trials if self.trials else None
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
AttemptOutcome = Literal["verified", "suspected", "contaminated", "none"]
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@dataclass(frozen=True)
|
|
269
|
+
class Attempt:
|
|
270
|
+
"""One run of one attack from a reset state.
|
|
271
|
+
|
|
272
|
+
What was observed and whether the run completed are separate facts. A run that
|
|
273
|
+
failed halfway is still judged on the replies it did receive: a transport error
|
|
274
|
+
cannot undo a disclosure that already happened.
|
|
275
|
+
"""
|
|
276
|
+
|
|
277
|
+
attack_id: str
|
|
278
|
+
slot_id: str
|
|
279
|
+
outcome: AttemptOutcome # from the evidence in the transcript, complete or not
|
|
280
|
+
transcript: tuple[Turn, ...]
|
|
281
|
+
matches: tuple[Match, ...] = () # everything not discarded as contaminated
|
|
282
|
+
contaminated_slots: tuple[str, ...] = ()
|
|
283
|
+
error: str | None = None # set when the run did not complete
|
|
284
|
+
# Recorded calls to a forbidden tool, each paired with the id of the tool rule or
|
|
285
|
+
# injection point that forbids it.
|
|
286
|
+
forbidden_calls: tuple[tuple[str, ToolCall], ...] = ()
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
@dataclass(frozen=True)
|
|
290
|
+
class Finding:
|
|
291
|
+
"""A verified violation: an attack that provably reached protected data."""
|
|
292
|
+
|
|
293
|
+
id: str
|
|
294
|
+
attack_id: str
|
|
295
|
+
technique: str
|
|
296
|
+
title: str
|
|
297
|
+
slot_id: str
|
|
298
|
+
level: EvidenceLevel
|
|
299
|
+
encoding: str
|
|
300
|
+
scope: str
|
|
301
|
+
attacker_principal: str
|
|
302
|
+
# Policy the finding is judged against, copied from the slot.
|
|
303
|
+
authorized: tuple[str, ...]
|
|
304
|
+
# The attacker messages, frozen. Replaying these from a reset state with a fresh
|
|
305
|
+
# canary is what `reproduction` measures.
|
|
306
|
+
frozen_turns: tuple[str, ...]
|
|
307
|
+
# The first conversation in which the attack worked. The canary value in it was
|
|
308
|
+
# single-use and is dead once the scan ends.
|
|
309
|
+
transcript: tuple[Turn, ...]
|
|
310
|
+
# How often the attack worked while searching.
|
|
311
|
+
discovery: Rate
|
|
312
|
+
# How often the frozen attack worked when replayed from reset.
|
|
313
|
+
reproduction: Rate
|
|
314
|
+
kind: AttackKind = "disclosure"
|
|
315
|
+
payload: str = "" # injection only: the planted text, frozen
|
|
316
|
+
# Action and injection findings: the recorded calls that should not have happened.
|
|
317
|
+
tool_calls: tuple[ToolCall, ...] = ()
|
|
318
|
+
# Injection only: requests made with harmless text in the same place, run between the
|
|
319
|
+
# replays. `successes` counts those in which a forbidden tool ran anyway, and is zero
|
|
320
|
+
# for anything reported as a finding.
|
|
321
|
+
control: Rate | None = None
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
@dataclass(frozen=True)
|
|
325
|
+
class SuspectedFinding:
|
|
326
|
+
"""Evidence that falls short of verified. Always shown, never counted."""
|
|
327
|
+
|
|
328
|
+
attack_id: str
|
|
329
|
+
technique: str
|
|
330
|
+
title: str
|
|
331
|
+
slot_id: str
|
|
332
|
+
reason: str
|
|
333
|
+
transcript: tuple[Turn, ...]
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
SlotState = Literal["reachable", "unreachable", "error"]
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
@dataclass(frozen=True)
|
|
340
|
+
class SlotStatus:
|
|
341
|
+
slot_id: str
|
|
342
|
+
kind: str
|
|
343
|
+
description: str
|
|
344
|
+
authorized: tuple[str, ...]
|
|
345
|
+
state: SlotState
|
|
346
|
+
detail: str = ""
|
|
347
|
+
# Attempts aimed at this slot that completed and were not discarded. Zero means the
|
|
348
|
+
# slot was never actually tested, whatever else the report says.
|
|
349
|
+
judged_attempts: int = 0
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
@dataclass(frozen=True)
|
|
353
|
+
class TaskStatus:
|
|
354
|
+
task_id: str
|
|
355
|
+
passed: bool
|
|
356
|
+
detail: str = ""
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
@dataclass(frozen=True)
|
|
360
|
+
class ErrorRecord:
|
|
361
|
+
phase: str # "preflight", "discovery", "reproduction"
|
|
362
|
+
attack_id: str | None
|
|
363
|
+
message: str
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
# "violations_verified" at least one verified finding.
|
|
367
|
+
# "no_verified_violations" every instrument worked and nothing was verified. This is a
|
|
368
|
+
# statement about the tested conditions only, never "safe".
|
|
369
|
+
# "inconclusive" nothing verified, but something needed to trust that result
|
|
370
|
+
# failed (unreachable canary, broken normal task, errors).
|
|
371
|
+
ScanStatus = Literal["violations_verified", "no_verified_violations", "inconclusive"]
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
@dataclass(frozen=True)
|
|
375
|
+
class ScanReport:
|
|
376
|
+
tool_version: str
|
|
377
|
+
target: str # the target spec string, enough to reconnect for a replay
|
|
378
|
+
attacker_principal: str
|
|
379
|
+
started_at: str # ISO 8601 UTC
|
|
380
|
+
finished_at: str
|
|
381
|
+
status: ScanStatus
|
|
382
|
+
slots: tuple[SlotStatus, ...]
|
|
383
|
+
tasks: tuple[TaskStatus, ...]
|
|
384
|
+
attacks_run: int
|
|
385
|
+
attempts_run: int
|
|
386
|
+
discovery_runs: int # attempts per attack while searching
|
|
387
|
+
reproduction_trials: int # replays per verified attack
|
|
388
|
+
findings: tuple[Finding, ...]
|
|
389
|
+
suspected: tuple[SuspectedFinding, ...]
|
|
390
|
+
contaminated_attempts: int # discarded because the canary was in attacker input
|
|
391
|
+
errors: tuple[ErrorRecord, ...]
|
|
392
|
+
limitations: tuple[str, ...] = field(default_factory=tuple)
|
|
393
|
+
# Why the status is "inconclusive"; empty otherwise.
|
|
394
|
+
inconclusive_reasons: tuple[str, ...] = field(default_factory=tuple)
|
|
395
|
+
# What the target said about its own configuration when scanned (model, digest,
|
|
396
|
+
# settings), so a later replay can tell whether it is facing the same thing.
|
|
397
|
+
target_config: dict[str, str] = field(default_factory=dict)
|
|
398
|
+
# Set when the scan was stopped before finishing: a limit was reached or it was cancelled.
|
|
399
|
+
stopped_early: str = ""
|
|
400
|
+
messages_sent: int = 0
|
|
401
|
+
tool_calls_recorded: int = 0
|
|
402
|
+
discovery_messages_sent: int = 0
|
|
403
|
+
# Non-sensitive summary of the authorization record (for non-local scans); empty for local targets.
|
|
404
|
+
authorization: dict[str, str] = field(default_factory=dict)
|
|
405
|
+
# Who ran the scan (optional, e.g. "Dana Levi, Example Audit") and their independence from the target team.
|
|
406
|
+
tester: str = ""
|
|
407
|
+
independence: Independence = "self"
|
|
408
|
+
|
|
409
|
+
def breakdown(self) -> str:
|
|
410
|
+
"""The verified findings by what they prove, so a refused attempt is never read as completed harm."""
|
|
411
|
+
disclosed = sum(1 for f in self.findings if f.level == EvidenceLevel.DISCLOSED)
|
|
412
|
+
accepted = sum(1 for f in self.findings if f.level >= EvidenceLevel.ACTION_ACCEPTED)
|
|
413
|
+
attempted = sum(1 for f in self.findings if f.level == EvidenceLevel.ACTION_ATTEMPTED)
|
|
414
|
+
# A zero is only shown for something that was tried: see not_tested().
|
|
415
|
+
kinds = {slot.kind for slot in self.slots}
|
|
416
|
+
secrets = f"{disclosed} protected data disclosed"
|
|
417
|
+
if not disclosed and not kinds & {"instruction_secret", "other_user_record"}:
|
|
418
|
+
secrets = "secret leaks not tested"
|
|
419
|
+
actions = (
|
|
420
|
+
f"{accepted} forbidden action(s) accepted, {attempted} forbidden action(s) attempted and refused by the tool"
|
|
421
|
+
)
|
|
422
|
+
if not accepted and not attempted and not kinds & {"tool_rule", "injection_point"}:
|
|
423
|
+
actions = "forbidden actions not tested"
|
|
424
|
+
return f"{secrets}, {actions}"
|
|
425
|
+
|
|
426
|
+
def not_tested(self) -> tuple[str, ...]:
|
|
427
|
+
"""The kinds of harm this scan never tried, one sentence each. A count of zero for a
|
|
428
|
+
kind that was not tested must never read as a pass, so every output shows these
|
|
429
|
+
beside the verdict."""
|
|
430
|
+
kinds = {slot.kind for slot in self.slots}
|
|
431
|
+
gaps = []
|
|
432
|
+
if not kinds & {"instruction_secret", "other_user_record"}:
|
|
433
|
+
gaps.append(
|
|
434
|
+
"Secret leaks were not tested: no secret was planted, so this result says nothing about "
|
|
435
|
+
"whether the bot keeps secrets."
|
|
436
|
+
)
|
|
437
|
+
if "tool_rule" not in kinds:
|
|
438
|
+
gaps.append("Forbidden actions were not tested: no tool was named as off limits to the attacker.")
|
|
439
|
+
if "injection_point" not in kinds:
|
|
440
|
+
gaps.append(
|
|
441
|
+
"Text the bot reads from elsewhere (notes, documents, tickets) was not tested: no place "
|
|
442
|
+
"for planted text was described."
|
|
443
|
+
)
|
|
444
|
+
return tuple(gaps)
|
|
445
|
+
|
|
446
|
+
def to_dict(self) -> dict[str, Any]:
|
|
447
|
+
data = asdict(self)
|
|
448
|
+
data["not_tested"] = list(self.not_tested()) # for readers of the JSON; derived, never read back
|
|
449
|
+
for finding in data["findings"]:
|
|
450
|
+
finding["level"] = int(finding["level"])
|
|
451
|
+
finding["level_label"] = EvidenceLevel(finding["level"]).label
|
|
452
|
+
return data
|
|
453
|
+
|
|
454
|
+
@classmethod
|
|
455
|
+
def from_dict(cls, data: dict[str, Any]) -> ScanReport:
|
|
456
|
+
def calls(items: list[dict[str, Any]]) -> tuple[ToolCall, ...]:
|
|
457
|
+
return tuple(
|
|
458
|
+
ToolCall(
|
|
459
|
+
id=c["id"],
|
|
460
|
+
tool=c["tool"],
|
|
461
|
+
arguments=tuple((str(k), str(v)) for k, v in c["arguments"]),
|
|
462
|
+
accepted=bool(c["accepted"]),
|
|
463
|
+
result=c.get("result", ""),
|
|
464
|
+
)
|
|
465
|
+
for c in items
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
def turns(items: list[dict[str, Any]]) -> tuple[Turn, ...]:
|
|
469
|
+
return tuple(
|
|
470
|
+
Turn(
|
|
471
|
+
role=item["role"],
|
|
472
|
+
text=item["text"],
|
|
473
|
+
tool_calls=calls(item.get("tool_calls", [])),
|
|
474
|
+
note=item.get("note", ""),
|
|
475
|
+
)
|
|
476
|
+
for item in items
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
def rate(item: dict[str, Any]) -> Rate:
|
|
480
|
+
return Rate(
|
|
481
|
+
successes=_count(item["successes"], "successes"),
|
|
482
|
+
trials=_count(item["trials"], "trials"),
|
|
483
|
+
errors=_count(item.get("errors", 0), "errors"),
|
|
484
|
+
contaminated=_count(item.get("contaminated", 0), "contaminated"),
|
|
485
|
+
interval_low=_fraction(item.get("interval_low")),
|
|
486
|
+
interval_high=_fraction(item.get("interval_high")),
|
|
487
|
+
interval_method=str(item.get("interval_method", "wilson-95")),
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
findings = tuple(
|
|
491
|
+
Finding(
|
|
492
|
+
id=f["id"],
|
|
493
|
+
attack_id=f["attack_id"],
|
|
494
|
+
technique=f["technique"],
|
|
495
|
+
title=f["title"],
|
|
496
|
+
slot_id=f["slot_id"],
|
|
497
|
+
level=EvidenceLevel(f["level"]),
|
|
498
|
+
encoding=f["encoding"],
|
|
499
|
+
scope=f["scope"],
|
|
500
|
+
attacker_principal=f["attacker_principal"],
|
|
501
|
+
authorized=tuple(f["authorized"]),
|
|
502
|
+
frozen_turns=tuple(f["frozen_turns"]),
|
|
503
|
+
transcript=turns(f["transcript"]),
|
|
504
|
+
discovery=rate(f["discovery"]),
|
|
505
|
+
reproduction=rate(f["reproduction"]),
|
|
506
|
+
kind=f.get("kind", "disclosure"),
|
|
507
|
+
payload=f.get("payload", ""),
|
|
508
|
+
tool_calls=calls(f.get("tool_calls", [])),
|
|
509
|
+
control=rate(f["control"]) if f.get("control") else None,
|
|
510
|
+
)
|
|
511
|
+
for f in data["findings"]
|
|
512
|
+
)
|
|
513
|
+
suspected = tuple(
|
|
514
|
+
SuspectedFinding(
|
|
515
|
+
attack_id=s["attack_id"],
|
|
516
|
+
technique=s["technique"],
|
|
517
|
+
title=s["title"],
|
|
518
|
+
slot_id=s["slot_id"],
|
|
519
|
+
reason=s["reason"],
|
|
520
|
+
transcript=turns(s["transcript"]),
|
|
521
|
+
)
|
|
522
|
+
for s in data["suspected"]
|
|
523
|
+
)
|
|
524
|
+
return cls(
|
|
525
|
+
tool_version=data["tool_version"],
|
|
526
|
+
target=data["target"],
|
|
527
|
+
attacker_principal=data["attacker_principal"],
|
|
528
|
+
started_at=data["started_at"],
|
|
529
|
+
finished_at=data["finished_at"],
|
|
530
|
+
status=data["status"],
|
|
531
|
+
slots=tuple(
|
|
532
|
+
SlotStatus(
|
|
533
|
+
**{
|
|
534
|
+
**s,
|
|
535
|
+
"authorized": tuple(str(p) for p in s["authorized"]),
|
|
536
|
+
"judged_attempts": _count(s.get("judged_attempts", 0), "judged_attempts"),
|
|
537
|
+
}
|
|
538
|
+
)
|
|
539
|
+
for s in data["slots"]
|
|
540
|
+
),
|
|
541
|
+
tasks=tuple(TaskStatus(**t) for t in data["tasks"]),
|
|
542
|
+
attacks_run=_count(data["attacks_run"], "attacks_run"),
|
|
543
|
+
attempts_run=_count(data["attempts_run"], "attempts_run"),
|
|
544
|
+
discovery_runs=_count(data["discovery_runs"], "discovery_runs"),
|
|
545
|
+
reproduction_trials=_count(data["reproduction_trials"], "reproduction_trials"),
|
|
546
|
+
findings=findings,
|
|
547
|
+
suspected=suspected,
|
|
548
|
+
contaminated_attempts=_count(data["contaminated_attempts"], "contaminated_attempts"),
|
|
549
|
+
errors=tuple(ErrorRecord(**e) for e in data["errors"]),
|
|
550
|
+
limitations=tuple(data.get("limitations", ())),
|
|
551
|
+
inconclusive_reasons=tuple(data.get("inconclusive_reasons", ())),
|
|
552
|
+
target_config={str(k): str(v) for k, v in dict(data.get("target_config", {})).items()},
|
|
553
|
+
stopped_early=data.get("stopped_early", ""),
|
|
554
|
+
messages_sent=_count(data.get("messages_sent", 0), "messages_sent"),
|
|
555
|
+
tool_calls_recorded=_count(data.get("tool_calls_recorded", 0), "tool_calls_recorded"),
|
|
556
|
+
discovery_messages_sent=_count(data.get("discovery_messages_sent", 0), "discovery_messages_sent"),
|
|
557
|
+
authorization={str(k): str(v) for k, v in dict(data.get("authorization", {})).items()},
|
|
558
|
+
tester=_tester(data.get("tester")),
|
|
559
|
+
independence=_independence(data.get("independence")),
|
|
560
|
+
)
|