Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Advanced / Red-team your own AI system

Red-team your own AI system cheat sheet

Set up (lesson 0)

TaskCommand or code
Make the lab foldermkdir -p ~/krlab/red-team-your-ai
Check the lab (the model is optional)python3 labcheck.py
Start the target with the stand-in modelKR_STUB=1 python3 target.py
Start the target with the local modelpython3 target.py
Switch fixes on for a retestKR_STUB=1 KR_FIX=owner,path,debug python3 target.py

Scope and rules (lesson 1)

TaskCommand or code
Check planned requests against the scopepython3 rules.py check draft.json
Check at a time, with repeatspython3 rules.py check draft.json --at 10:00 --runs 6
Use another scope filepython3 rules.py check draft-b.json --scope scope-b.json
Send a request through the rules (no redirect, no proxy, http only)call(scope, "GET", url)
A scope has one entry for each port, with its own paths and methods"in_scope": [{"host": ..., "port": ..., "paths": [...], "methods": [...]}]
Show the budget that is spentpython3 rules.py used
Start a new budget (the owner gives it)python3 rules.py reset
Ask whether the test must stopstop_reason(scope, used, errors_in_row, stop_file_present)
Stop with the stop wordtouch STOP-NOW

Map the target (lesson 2)

TaskCommand or code
Probe the paths inside the scopepython3 mapper.py probe paths.txt
Find routes and tools in the sourcegrep -n "self.path|def do_" target.py
Scan a folder or a file for secretspython3 secretscan.py repo-sample
Mask secrets in a textmask(text)
Check the data flowspython3 mapper.py flows flows.txt

Test cases (lesson 3)

TaskCommand or code
Check the table and count the cases for each riskpython3 coverage.py cases.csv not-tested.txt
A judge that looks for a textcontains:PINEAPPLE, missing:30 days
A judge that looks for a patternregex:<img|<script
A judge for a tool calltool_called:order_status:PC-1002, forbidden_path

The harness (lesson 4)

TaskCommand or code
Send every case three times and save the countspython3 harness.py run -n 3 --summary before.json
Send only some casespython3 harness.py run --only info-1,info-2
Read the exit code0 clean, 1 unsafe run, 2 broken: no answer, stopped early, a case refused by the scope, or no case ran
Keep the old recorda new run renames an old runs.jsonl to runs.jsonl.1, then .2
Score recorded answers, send nothingpython3 harness.py score recorded-04.jsonl
Point the harness at another targetKR_TARGET=http://127.0.0.1:8411 python3 harness.py run

Manual testing (lesson 5)

TaskCommand or code
Send one message and write a notepython3 probe.py "message" --change "word=code"
Let a harness judge fill auto, and add your verdictpython3 probe.py "message" --judge contains:PINE-STAFF --verdict unsafe
Probe as another customerpython3 probe.py "message" --customer u2
Vary one thing at a timevary(start, axes)
Summarise a session of notespython3 notes.py read session-05.jsonl

The infrastructure (lesson 6)

TaskCommand or code
Show the listening portsss -ltn
Check the ports of the scopepython3 ports.py
Check a saved listingpython3 ports.py ss-sample.txt
Check login, debug page, log and body size (only the expected refusal is ok)python3 infra.py --summary before.json

Findings (lesson 7)

TaskCommand or code
Score impact times likelihoodpython3 severity.py 3 4
Turn counts into a likelihoodlikelihood_from_rate(hits, runs)
Upper bound of the true rate (95 percent)upper_bound(hits, runs)
Check a findings file (WEAK: the upper bound allows a higher likelihood)python3 findcheck.py findings.json
Send the evidence againpython3 findcheck.py findings.json --replay

Report and retest (lesson 8)

TaskCommand or code
Generate the reportpython3 report.py findings.json before.json after.json not-tested.txt > report.md
Report for a live runpython3 report.py ... --live llama3.2:3b > report.md
Check the reportpython3 reportcheck.py report.md findings.json
Compare counts before and afteroutcome(before, after)

The whole assessment (lesson 9)

TaskCommand or code
Draft the findingspython3 draftfind.py before.json runs.jsonl judgement.json > findings.json
Run every stage (exit 0 pass, 1 critical open, 2 broken stage; a broken run leaves report-full.INCOMPLETE.md)./assess.sh

Safety habits