zebbern-kali-mcp
CLAUDE.md49 starsChanged 3 months agoMITView on GitHub
Operational notes for this repo. Every entry is a mistake that has actually been made here, not general advice. The measurements are recorded because they cost real effort and cannot be cheaply re-derived. Read Three rules first; the rest of the file leans on them. Three rules · Release tracks · Releasing · Integration gate · Things that go stale silently · Environment · Timeouts · Background jobs · Output integrity · Session lifetime · Invariants not to break ·…
- Commits and pushes
The file
We split this CLAUDE.md into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 7
Read Three rules first; the rest of the file leans on them.
- Very specific: line 439
Every background job's full stdout+stderr is written to $JOB_OUTPUT_DIR/<job_id>.log (the image sets /app/tmp/jobs.
- Distinctive: line 473
Do not carry it into a wrapper, a default, or a suggestion to an operator.
- Distinctive: line 802
AFTER a change proves nothing — they would merely enshrine whatever the new code does, the very trap the live diff caught — so the …
- Very specific: line 983
Do not do this by hand with str.replace.
- Very specific: line 993
Run across the guards written in one sweep, 22 of 26 verified and four did not: three anchors that silently matched nothing, and one guard …
- Very specific: line 1004
Add a mutation to tests/mutations.json whenever you add a guard.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
Operational notes for this repo. Every entry is a mistake that has actually been made here, not general advice. The measurements are recorded because they cost real effort and cannot be cheaply re-derived.
Read Three rules first; the rest of the file leans on them.
Three rules · Release tracks · Releasing · Integration gate · Things that go stale silently · Environment · Timeouts · Background jobs · Output integrity · Session lifetime · Invariants not to break · Typed-wrapper verdict · Tests · Defect shapes · Mutation checking
Three rules
1. Check the flag, never success. success: true is the least informative field
in any reply here: a truncated scan, a crashed msfconsole, an unpinned chisel tunnel
and an already-cancelled job all carry it. The flags that answer the question are
timed_out, console_exited, connected, listening, canceled, version_match,
output_logged, carry_over. They are advisory — they never flip success or
status, and "fixing" that is the recurring wrong instinct. A flag that cannot tell
"no" from "nothing could tell me" returns None, not False.
2. Output is never capped, truncated, redacted or discarded — not by a buffer ceiling, not to bound memory, not to make room in a window. Unbounded memory on a very long run is a known, accepted hazard; dropping operator output to bound it is the same sin as redacting it. If it ever needs bounding, spill to disk. The only bounded thing here is a polling window, and whatever it could not hand back must be carried.
3. A live process is not a working one, and a status read must not have side effects
on what it reports. proc.poll() proves nothing against a tool that retries forever
— read its log. A liveness probe that dials through a forwarder is traffic against the
target, not a status check.
Release tracks
The wheel ships only mcp_server.py and mcp_tools/* (pyproject.toml
py-modules / packages.find). Everything under zebbern-kali/ ships in the Docker
image instead, and reaches users when docker-publish.yml rebuilds — not when you
publish to PyPI. Before proposing a release check which track the change is on, with
git diff --name-only <last-tag>..main: a change under zebbern-kali/ does not justify
a PyPI bump, and a PyPI release does not deliver it. This has been misread once already
— a proposed release turned out to contain nothing but a comment.
Releasing
publish.yml is workflow_dispatch on main only. validate-input runs
verify_release_artifacts.py declared-version and refuses if the dispatched version
differs from pyproject.toml.
- Bump two files:
pyproject.tomlandzebbern-kali/core/config.py(currently 1.0.19). Everything else derives.test_backend_version_tracks_pyprojectfails if only one is touched — they used to drift by hand.config.pymust keep a literal VERSION:pyproject.tomlis excluded from the image by.dockerignoreand the backend runs from source, so deriving it would break/healthat container startup. - Re-pin the integration gate digest (below) if the image changed — in a separate
commit, after step 1 has merged and rebuilt.
run_smoke.pycompares the pinned image's own/liveversion against the version declared in this source, so a commit carrying both the bump and the pin fails the gate by construction: the only digest that exists when the pin is written was built from the previous version. It fails with a message that reads like the pin is merely stale —pinned image reports version '1.0.17', expected '1.0.18': the integration digest is stale and must be re-pinned to an image built from this source. The gate'spull_request.pathsexcludepyproject.tomlandzebbern-kali/**, and that exclusion is what makes the sequence work: the bump merges without the gate running, theconfig.pychange rebuilds the image at the new version, and only then can the pin be written. Bump first, pin second, two PRs. - Dry-run the gate:
gh workflow run integration.yml --ref main. gh workflow run publish.yml --ref main -f version=X.Y.Z- Tag afterwards:
git tag -a vX.Y.Z <commit> && git push origin vX.Y.Z. Tags for 1.0.2–1.0.4 had to be backfilled because this step was skipped. - Bump the pinned
uvx zebbern-kali-mcp@X.Y.Zin the MCP client config (see the deployed client).
PyPI index lag is normal. For a few minutes after publish the JSON API and
uvx --from pkg==X.Y.Z will claim the version does not exist. The
post-publish-verify job matching filenames and SHA-256s is authoritative;
https://pypi.org/simple/zebbern-kali-mcp/ updates before the JSON API.
The integration gate pins a digest
.github/workflows/integration.yml env.IMAGE is an immutable @sha256: digest and
publish.yml has needs: [gate, integration], so no release ships without real tools
executing. Nothing keeps that pin in step with :latest; it drifted three builds within
hours of being introduced. Re-pin as a release step, and pin a digest you have
actually booted, not one you only looked up.
gh run watch --exit-status can exit 0 while the build is still running. Measured
during the 1.0.18 release: it returned success, and :latest was still the previous
digest. Pinning on that signal would have pinned the image before the change — the
stale-image failure above, arriving through a new door, and invisible because the watch
command had just reported success. Ask the run for its own status and treat anything but
completed as not finished:
gh run view <id> --json status,conclusion --jq '"\(.status)/\(.conclusion)"'
docker buildx imagetools inspect ghcr.io/zebbern/zebbern-kali-mcp:latest | grep -i '^Digest'A digest that has not moved is the tell, so read it before and after. The digest is also passed to compose as
ZKM_IMAGE, because a digest pull leaves no local tag — without it docker compose up
would miss :latest and rebuild from the Dockerfile, far exceeding the job timeout.
A backend-only PR is all-green having never run its own code. The gate's
pull_request.paths covers mcp_tools/**, tests/integration/** and the compose files
but not zebbern-kali/** — structural, not an oversight: the gate boots a pinned
published digest, so running it on an unmerged backend change would certify the old
backend and prove nothing about the diff. A PR that rewrites tool execution therefore
shows lint and Trivy green and nothing else, reading exactly like a validated change.
The only real check is post-merge — rebuild, boot the new digest, call the tools through
a client, then re-pin. Cheaper pre-merge check:
two containers from one image.
Things that go stale silently
The local backend image
ghcr.io/zebbern/zebbern-kali-mcp:latest moves on every docker-publish run, which
triggers on any push to main touching Dockerfile, .dockerignore, docker/**,
docker-compose*.yml, entrypoint.sh, requirements.txt or zebbern-kali/**. A local
copy pulled earlier keeps serving, and the symptoms never look like staleness: the
container reports unhealthy (an old image predating the /live route), /health
reports an old version, and tests pass against bits nobody ships.
docker compose pull && docker compose up -d --force-recreate
docker buildx imagetools inspect ghcr.io/zebbern/zebbern-kali-mcp:latest # remote
docker image inspect ghcr.io/zebbern/zebbern-kali-mcp:latest --format '{{index .RepoDigests 0}}'Compare those two digests before trusting anything the backend says. This has happened three times.
The deployed MCP client
uvx zebbern-kali-mcp with no version reuses whatever environment uv already cached
for that command; restarting the MCP re-runs the same cached archive. The deployed client
sat on 1.0.5 through six releases while every check looked fine. It hid because
health returned the backend's /health verbatim and that version is the
backend's — nothing reported the client's own. The symptoms read as product bugs: a
tool missing entirely (job_list → "No such tool available"); a documented argument
silently ignored (tools_nmap(background=True) runs synchronously, because the 1.0.5
wrapper has no such parameter); /health saying the current version, so nothing looks
wrong. health now also returns client_version, version_match and a version_note
when they disagree — check that before believing a missing tool is a bug.
# what the running MCP actually is, not what PyPI has
ls "$LOCALAPPDATA/uv/cache/archive-v0/<hash>/Lib/site-packages" | grep dist-info--refresh is not sufficient, measured. Both configs carried it across a restart
taken minutes after 1.0.14 was on PyPI, and the client still reported 1.0.13. The flag
had genuinely worked — 1.0.14 was in uv/cache/archive-v0/ — but the server process came
up on the older archive anyway, refreshing the cache without changing what ran. Nothing
about that is visible except version_match. Pin instead:
uvx zebbern-kali-mcp@X.Y.Z resolves that exact version and nothing else. It must be
bumped by hand each release, and that is the point — forgetting leaves health reporting
version_match: false, a failure that announces itself, where --refresh fails
silently.
A correct pin is still not proof of what is running. At 1.0.17 both configs read
@1.0.17, the 1.0.17 archive was cached, 1.0.17 processes were alive — and health
reported client_version: 1.0.16 across three restarts. Four processes spawned before
the pin was fixed were still running and still held the session's connection; the app
starts new servers without stopping the old ones, so generations accumulate. Killing
exactly those four flipped version_match to true with no further restart. Everything
above pointed at uv and none of it applied, so ask the OS what is running before
touching the cache or the config again:
Get-CimInstance Win32_Process | ? { $_.CommandLine -like '*zebbern*' } |
Select ProcessId, CreationDate, CommandLineTwo generations in that listing, or a CreationDate older than the last config edit, is
the whole answer. The version in the argv is the version running.
claude_desktop_config.json is regenerated by the app; hand edits do not survive.
%APPDATA%\Claude\claude_desktop_config.json and ~/.claude.json both define
kali-tools and the desktop app reads its own. An edit there verified as @1.0.17, then
read @1.0.16 again after the next restart — which is what spawned the stale generation
above — while the same edit to ~/.claude.json held. Change it through the app's MCP
settings, or re-check the file after restarting.
Nothing in the test suite catches any of this: pytest, the live tests and
probe_tools.py all spawn mcp_server.py from the repo source, so they validate the
source and never the installed artifact.
Published-package checks run from a clean cwd
uvx --from pkg==X python -c "import mcp_tools..." run inside this repo imports the
local source, not the installed package, and will happily confirm a fix that was never
published. Run it from somewhere else and assert on site-packages in __file__. This
produced a false positive once.
Environment
Targeting the host from inside the container. Inside the container 127.0.0.1 is
the container's own loopback; the host and anything published on it (e.g. a crAPI lab
on 8888) is host.docker.internal. Scanning 127.0.0.1 finds an empty container and
looks exactly like a broken MCP server. Services on another compose network that are not
host-published (crAPI's crapi-identity:8080, crapi-community:6060) need the Kali
container attached to that network.
Windows: the backend cannot be imported. kali_server.py and api.routes pull in
metasploit_manager → pty → termios, absent on Windows. Import-safe: api/auth.py,
mcp_tools/*. For anything else, load the module by path
(importlib.util.spec_from_file_location) or assert on the source text — both
patterns are already in tests/.
Timeouts
A timeout here is a backstop for a hung process, not a budget for a slow one. A four-hour scan is the workload, not a bug.
Four independent deadlines stack on one synchronous tool call, smallest wins:
mcp_server --timeout -> mcp_tools/_client.py DEFAULT_REQUEST_TIMEOUT (90000)
requests read timeout, connect stays 10s
api/blueprints/* -> the route's own params.get("timeout", N)
core/tool_config.py -> TOOL_TIMEOUTS[tool], default 3600, max 86400
core/command_executor -> subprocess waitThere is a fifth deadline, it is the smallest, and it is not in that list: the MCP
harness abandons a tool call at roughly 60 seconds. It sits above every layer and
outside this repo, so nothing here raises it. Measured: a synchronous zebbern_exec
sleeping 310s came back as a harness-level Error: Request timed out — not our client's
{"error": "Request failed: ReadTimeout"} — while the container process was still alive
at 110s. exec_stream does not evade it; SSE runs between our client and the backend and
the harness only ever sees one request and one response, so it fails the same way at
70s. That makes tools_hydra's 86400s budget unreachable and turns an orphaned scan into
the normal outcome. To watch it: run the 65535-port background case in
tests/test_live_tools.py against a backend that does not honour the flag, then
docker exec zebbern-kali ps -eo pid,etime,cmd | grep nmap — the scan is still going
minutes after the client gave up, with nothing left to reach it by. A background job is
the only escape.
The client must always outlive the backend. Set below a backend budget it does not cap
that budget, it destroys the answer: requests raises ReadTimeout before the backend
can serialize its reply, safe_post returns {"error": "Request failed: ReadTimeout"},
and every byte of partial output is gone, making the timed_out/partial_results
contract unreachable. Worse, the backend does not notice — it keeps running the
subprocess with nobody listening, so the scan is orphaned rather than cancelled and its
output is unreachable forever. The shipped defaults satisfy the rule with margin — client
90000 (25h) > table max 86400 (hydra, john) — and
test_the_client_read_timeout_outlives_the_longest_tool_budget asserts
DEFAULT_REQUEST_TIMEOUT > max(TOOL_TIMEOUTS.values()) so the two release tracks cannot
drift back past each other. They already had: the client sat at 14400 while eight table
entries were at or above it. Raise the client whenever a table entry grows past it; never
shorten a tool's budget to fit under the client. The connect timeout stays 10s — an
unreachable server is a different failure and must fail fast.
That guard only sees TOOL_TIMEOUTS. The one backend deadline computed by formula is
ad_tools.password_spray's len(users) * 5, which a SecLists username file turns into
~41,500,000s. It is clamped to SPRAY_TIMEOUT_CEILING (86400), and clamping loses nothing
because the TimeoutExpired handler returns the partial spray and the credentials already
parsed — strictly more than the ReadTimeout path. Any future formula-derived deadline
needs the same ceiling and its own guard.
get_tool_timeout keys on a bare binary name; execute_command resolves it with
get_command_timeout, which strips sudo/timeout 4h/env FOO=1/an absolute path and
takes the longest budget across a pipeline. Before that, sudo nmap, /usr/bin/nmap and
echo x | waybackurls all missed their entry and silently dropped to the default.
The MSF chain is the exception to "smallest wins": msf_session_execute always puts
timeout in the request body, so the route's params.get("timeout", 14400) never fires
for an MCP caller and the outermost default decides. All three
(mcp_tools/metasploit.py, the route, MetasploitSession.execute) must be raised
together; the first is the only one on the wheel track, so it can regress in a PyPI-only
change that never touches the image.
success: True and timed_out: True coexist on purpose (rule 1): a truncated scan's
partial output is worth keeping, so CommandExecutor, /api/exec and
MetasploitSession.execute all report success with output present. Do not "fix" this by
flipping success. partial_results is a real bool from all four emitters — two used to
return the stdout string, truthy but not a bool, which a strict client reads as a type
change rather than a flag.
A scan is finished when it is finished, and nothing here times one. Output arriving only
at the end is not a defect: the inline wait hands back a job_id and the job keeps running,
the stdbuf wrap only changes flushing, and job_output's clamp bounds how long a poll
blocks, never the process. "Polling returns only the banner, it looks like a hang" is
answered by saying so — adding --stats-every to the tools_nmap wrapper was considered and
rejected, because a progress flag earns nothing job_status does not already give, and
anything that stops a scan to report on it returns a worse scan. Closed question.
The api/exec background branch resolves an omitted timeout — a narrowing of this file's
own "do not fix that in the route" directive. SETTLED: KEPT (2026-10-02). Decided by a
delegated agent (Fable 5.1) acting under the owner's standing grant of 2026-10-02 ("change or
rewrite anything as long as Fable 5.1 says it should be done"); the owner did not personally
review this specific change, so this is recorded as a delegated-agent decision, not an owner
decision — do not re-describe it as the owner's. Kept because it fixes a latent bug independent
of all other work (zebbern_exec sends no timeout on its default, so without this
zebbern_exec('hydra ...') was capped at 3600s and orphaned at one hour instead of inheriting
hydra's 86400 TOOL_TIMEOUTS tier), because it is faithful to the original "do not fix that in
the route" directive (which protects a caller who passed a number from being surprised — an
omitted timeout surprises no one), and because the typed-wrapper verdict independently names
exactly this change, with exactly this scope, as the necessary enabling fix. If a future change
reopens it, revert the get_command_timeout block in api/blueprints/command.py and this note
together. It used to hand params.get("timeout", 3600) straight to job_manager.start
with no get_command_timeout resolution, and this file told you to keep it that way — which
silently capped zebbern_exec('hydra ...') at one hour, because zebbern_exec omits timeout
on its default and so inherited 3600 instead of hydra's 86400 tier, a latent bug independent of
the collapse work. The narrowing: an omitted timeout now resolves
through get_command_timeout(command), so a background job inherits its command's
TOOL_TIMEOUTS tier exactly as execute_command does everywhere else. An explicit operator
timeout, and every direct-HTTP caller that passes a number, stay untouched — the "do not
surprise the caller" rule still holds for the number they sent. The one behaviour change for a
direct caller: background=True + an omitted timeout + a long tool now gets that tool's
longer backstop instead of 3600, which is the safer failure — the hydra run that was killed
and orphaned at one hour runs to its tier, and it matches execute_command. It has to live in
the route: the wheel cannot import TOOL_TIMEOUTS (core/tool_config.py ships only in the
image), so mcp_tools has no tier to resolve against.
Background jobs
background=True rides params into the runner, execute_command hands the command to
job_manager, and the job dict comes back through an unchanged route. Drive it with
job_status / job_output / job_cancel, and job_list when the id itself is gone.
Backgrounded jobs keep their table budget: execute_command passes the resolved timeout
into job_manager.start, which otherwise defaults to 3600 and would cap hydra at one hour
silently.
The if background: check must stay before the streaming branch in execute_command.
gobuster, nikto and bash are streaming-classified and both runners that reach them
always pass an on_output callback, so a check placed after that branch leaves exactly the
tools most likely to outrun the harness running in the foreground while the flag reads as
supported.
Seventeen wrappers auto-promote
Fourteen heavy tools_* wrappers plus api_nuclei_scan, api_ffuf_fuzz and
zebbern_exec go through run_promotable: the job starts first, then the client waits
inline for ZKM_INLINE_WAIT_SECONDS (default 50, floored at 1) and returns either the
finished result or a job_id handle. For these an incoming background is ignored on the
way in and background=True means only "do not wait". Starting the job before the wait
is the whole safety argument — a mis-tuned budget costs a poll, never the scan, because the
harness abort lands on the poll and job_list still finds the job. The other seven
backgroundable wrappers stay opt-in: their tiers are under 3600 and a poll round-trip would
cost more than it saves. _await_job's sleep starts at 0.25s and doubles to
ZKM_INLINE_POLL_SECONDS; a flat poll put a ~2s floor under every quick zebbern_exec
round-trip once it promoted on every call. Steady state for a long scan is unchanged, and
the backoff is shared by all seventeen.
PROMOTED_TOOLS holds exactly 14 keys and that is deliberate — only the tools_*
wrappers. api_nuclei_scan, api_ffuf_fuzz and zebbern_exec are deliberately absent:
run_promotable never reads the map (heavy and background are passed explicitly) so
behaviour is unaffected, but a non-tools_* key would falsify the "fourteen" sentences
above and break tests/test_autopromote_tier_guard.py. What must stay in step is each
tool's TOOL_TIMEOUTS tier, which that test guards case by case.
Three things that look like bugs and are not:
- The tools routes answer 200 with the job dict, not
/api/exec's 202. Keeps route edits at zero, andsafe_postreads the JSON either way. run_subzyleaks its temp targets file when backgrounded, on purpose. With an inlinetargetit writes aNamedTemporaryFileand unlinks it afterexecute_commandreturns; backgrounded that return is immediate, so the unlink would delete the target list out from under a job that has not read it yet. The guard isif target and not background; the OS temp reaper collects the rest.- The promoted shape drops
execution_timeand the echoedcommandand rebuilds stdout as"\n".join(ring lines), so a trailing newline no longer round-trips. Everytools_*wrapper already had that divergence; the exact-match live test andrun_smoke's nonce both useprintf <nonce>with no newline.
api_nuclei_scan and api_ffuf_fuzz needed their own answer because both runners build
an output_file, call subprocess.run directly rather than execute_command, and parse that
file afterwards — backgrounded, the parse never runs. Each has a background branch that drops
-o (and ffuf's -of) and lets the scanner's own structured output land on stdout:
nuclei -jsonl, ffuf -json, both newline-delimited JSON, teed 100% to the job log like any
other background job. Every other flag mirrors the synchronous branch, which is byte-for-byte
unchanged and still the path a direct HTTP caller gets.
zebbern_exec was the last exec-family tool that could orphan its own output — it was not
the last tool, and this sentence used to say it was. Three api_security wrappers —
api_rate_limit_test, api_fuzz_endpoint and api_graphql_fuzz — each post synchronously with
no read_timeout, no background and no job registration, and each loops in the Flask handler
(requests_count; params × 24 fuzz payloads) over requests calls bounded individually by
timeout=10. Their orphan window is now bounded, not closed: API_REQUEST_CEILING = 2000
and API_LOOP_BUDGET_SECONDS = 45 (both in zebbern-kali/core/api_security.py) break every one
of the three loops on a request-count ceiling (requests_capped) and a wall-clock deadline
(time_capped), and the handler then returns its accumulated partial findings with those two
flags set — before the ~60s harness abort can abandon the call. Not closed, because timeout=10
is requests' per-read/per-connect timeout, not a total: a byte-dribbling tarpit can stall one
in-flight request past it, so the true worst case is ~55s (the 45s budget is only checked between
requests, plus up to ~10s for the one request in flight when it trips) — still under the harness
abort, but not a hard 45s. What is still unfixed is only MID-RUN cancellability and disk
teeing: both need job_manager to run an in-process Python callable rather than a subprocess,
which it cannot today. That is deferred and does not orphan — the loop already returns on its own
within the window above. Fixing it properly spans both release tracks, and the gate boots a
pinned published digest, so it cannot exercise the change pre-merge.
zebbern_exec itself posted synchronously to api/exec, whose foreground
branch is the one execution path in the repo that tees
nowhere — only the background branch reaches job_manager, which writes
$JOB_OUTPUT_DIR/<job_id>.log — so a command outrunning the ~60s harness abort left a
subprocess running with nobody listening and nothing on disk, and an operator who passed
timeout=300 had no way to see the value never mattered. It now goes through
run_promotable(heavy=False); heavy=False is deliberate, so it cannot become a
heavy_tool_post caller taking one of five semaphore slots for every whoami. Its timeout
bounds the job: an explicit value is the operator's number and the api/exec
background branch hands it to job_manager.start untouched, with no get_command_timeout
resolution — a direct HTTP caller must not be surprised by a timeout it did not ask for. An
omitted timeout is the case that changed on 2026-10-02 (see Timeouts): it now
resolves through get_command_timeout(command) like execute_command, so
zebbern_exec('hydra ...'), which sends no timeout on its default, inherits hydra's
TOOL_TIMEOUTS tier instead of being capped at 3600 and orphaned at one hour.
Any new heavy_tool_post caller must pass a read_timeout; without one it holds a slot
out of five for the full 90000s client timeout. The only remaining call site is inside
run_promotable, which always passes read_timeout=budget, capping the semaphore hold at
~50s even against a backend that ignores background.
api_kiterunner_scan and api_newman_run are two more api_security wrappers with
no bound — unlike the three loop scanners above, which are now bounded by a count ceiling and a
wall-clock deadline, these two carry no clamp at all — and they cannot orphan
today for a reason that is not in the code: kiterunner, kr
and newman are not installed in the image, so they fail immediately with "command not
found". Install any of them and they need the same treatment — and newman needs a different
answer, because its structured report goes to a --reporter-json-export file rather than
stdout.
Job output is teed to disk, and never pruned
Every background job's full stdout+stderr is written to $JOB_OUTPUT_DIR/<job_id>.log (the
image sets /app/tmp/jobs; from source without the env it falls back to the OS temp dir).
The in-memory ring that job_output/read_output return is only a bounded polling window
and still clips and evicts — but the file has 100%, so output_truncated no longer means
loss. output_logged=false is the one state that does: the log dir was not writable and
only the ring exists. These files are never rotated, capped or auto-deleted (rule 2);
cleanup is manual (rm /app/tmp/jobs/*.log) or by container recreate. A long engagement can
grow this without bound; accepted cost.
job_output clamps an over-max wait instead of rejecting it — it was an undocumented
HTTP 400 timeout cannot exceed 30 seconds, raised before the job was even looked up — and
reports wait_timeout, wait_capped and max_output_wait so it cannot lie about what it
waited. job_cancel on an already-terminal job is 200 with
canceled: false, already_terminal: true instead of HTTP 409. Genuinely bad input (negative
timeout, lines<1) still 400s and an unknown job still 404s; all four verified live.
A buffering fix can only be proved by a program that does not flush on its own.
Background jobs launch under stdbuf -oL -eL /bin/sh -c
(job_manager._line_buffered_launch) so a C-stdio tool line-buffers into its pipe instead of
holding ~4-8KB until exit. The obvious demonstration is worthless: seq 1 3; sleep 6 shows
all three lines mid-run with the wrap removed, because seq flushes at its own exit before
the sleep; ping and awk call setvbuf themselves. Measured wrapped against unwrapped, the
only thing that distinguishes them is a purpose-built printf/printf/sleep C binary with no
setvbuf: ["first","second"] wrapped, [] unwrapped.
The honest negative result: stdbuf has a narrower scope than "C-stdio tools" and is not
the fix for the nmap case. At equal sample times the wrap changed nothing for masscan,
hydra, gobuster or sqlmap — Go binaries, CPython and perl each run a buffering layer stdbuf
cannot reach, so job output arriving only at exit is not always buffering. For nmap, a
backgrounded scan sampled at 4s/8s/12s gave 1 stdout line each time with the wrap and 0
each time without it: the wrap gets the banner out immediately where an unmodified backend
showed nothing at all, and that banner is the whole of what it buys. No mid-scan progress
appeared at any sample — not even with the probe passing a progress flag to force the issue,
which is a measuring instrument for that one measurement and not a way to run a scan here.
Do not carry it into a wrapper, a default, or a suggestion to an operator.
Output integrity
Nothing is capped or truncated (rule 2). CommandExecutor accumulates into a list and
joins once — it used to do self.stdout_data += line, O(n^2) in line count, tolerable under
a 5-minute cap and not under 24 hours. MetasploitSession does the same for its PTY reader:
output_buffer is a property over a chunk list, with _output_len and a 512-char
_output_tail so the wait loop's per-poll work stays constant. 64MB of 4096-byte reads
measured at 131.3s by concatenation against 0.004s of appends plus one 0.016s join — roughly
half a megabyte a second, which a verbose module outruns. stdout_data, stderr_data and
output_buffer stay public strs holding every byte; the tail exists for the prompt match
only. Because those attributes are now derived, deleting a _finalize_output() call
makes every tool's output vanish while still reporting success: True, and the whole suite
stayed green through it — tests/test_command_executor_output.py runs the real class on real
processes for exactly that reason.
A window over a stream has to carry what it could not hand back, and the carry has to live
on the session. ReverseShellManager.read_output — the read half of the raw caught-shell
channel — held its remainder buffer and line surplus in locals, so every byte os.read
had already taken off the PTY and not returned died with the call: a newline-less remainder,
and every complete line past max_lines. That destroyed the exact case the channel exists
for — a REPL, su asking for a password, (gdb) all stop on a prompt with no newline, so the
operator saw an empty window, indistinguishable from a hung target. The discard was
pre-existing; the branch exposed the function as an MCP tool under a docstring promising
"anything left is returned by the next call ... Nothing is discarded to make room", and a
new docstring over old behaviour is a new false claim — a review found it where the suite
could not. Both carry-overs are now self._raw_read_buf / self._raw_pending_lines; a
newline-less remainder comes back in the window that read it rather than one call later (one
call late is useless to whoever waits on a password prompt, and the cost is a long line
arriving in two pieces, bytes and order intact); carry_over: {lines, bytes} reports what is
still held. Verified live: printf "Password: " comes back in the same window.
max_lines was a soft bound reported as a hard one — the ceiling was tested only on the outer
loop, so one os.read could append a whole burst past it while the route answered
window_limit: 100 beside lines_returned: 500. The tempting fix, breaking the inner loop at
the ceiling, discards complete lines already read off the PTY, so the surplus is carried
instead and the ceiling became hard at zero loss: a 12-line burst read with lines=4 returned
4/4/4/3 across four calls, in order, with carry_over draining 10 → 6 → 2 → 0. Reporting the
carry-over is not decoration — under a hard ceiling "exactly my limit" otherwise reads
identically to "that was everything", and an operator stops polling with lines still held.
Companion trap, in the test: a helper that builds the manager with object.__new__ has to set
the carry-over attributes itself, so the helper supplies the fix and the __init__ mutation
never goes red. __init__ opens no PTY, so build through the real constructor.
A signal exit used to be indistinguishable from a silent success. A shell killed by a
signal comes back as a negative return_code, empty stdout and success: False —
field-for-field what a command that ran and printed nothing looks like. The way to land there
is pkill -f <pattern> whose pattern matched the shell running it: that shell's argv contains
the command text, so the command kills itself and reports -15 with no explanation.
_note_signal_exit in mcp_tools/command_exec.py now names SIGTERM/SIGKILL/SIGINT. It is
additive only (setdefault, so it never clobbers the truncation note), touches no byte of
output, and annotates nothing when there is output, when timed_out is set (-1 is that
sentinel, not a signal), or on a still-running handoff.
A note that explains a failure must not assert a cause it did not observe. The note is in
two halves. The observed half — signal name, no output, and that an outside kill
(job_cancel, the OOM killer, a stopped backend) looks identical — stays unconditional. The
self-match clause was gated on "kill" in command.lower(), so kill -TERM 4567, a PID kill
that cannot self-match, was confidently told its pattern had killed its own shell when the
real cause was a job_cancel or the OOM killer; grep killer fired it too. It is now phrased
as a possibility to rule out, says outright that nothing observed what sent the signal, and is
attached only to commands that select victims indirectly: pkill -f/--full,
fuser -k/--kill, killall (_PATTERN_KILLERS), matched by token equality on the binary's
basename within one shell segment, so a flag in a later segment cannot be credited to it
(pkill nginx && echo -f). kill and pgrep are deliberately absent: one names PIDs, the
other kills nothing. Every entry in _SIGNAL_EXITS is exercised by a test parametrized over
the table itself, plus a second parametrization pinning the three signals by name so deleting
one goes red — a table-driven test alone just yields one case fewer.
The PTY fd lifecycle is now one helper, and only the mechanics moved. [Delegated-agent
decision under zebbern's standing authority grant, 2026-10-02.] pty.openpty() +
select.select + os.read/os.write on a master fd, plus the SIGTERM→SIGKILL→survivor-reap
group teardown, were implemented three times (reverse_shell_manager, metasploit_manager,
ssh_manager); they now live once in core/pty_session.PtySession, which owns the fd loop and
the strip-ANSI-for-match-only discipline — _ANSI_RE lives there and reverse_shell_manager
and metasploit_manager import it rather than each keeping a copy. read() keeps the
three-way None (nothing ready) / b'' (EOF) / bytes contract the inlined loops branched
on; strip_for_match strips for the MATCH only and never rewrites the bytes handed back
(rule 2). ssh_manager.stop() now delegates to PtySession.close() and so uses the same
killpg-group teardown the other two already had and it previously lacked — a bare
process.terminate() signalled only the setsid leader and could orphan an ssh control-master
or proxy child. The managers keep every byte of their own marker/prompt/capture logic; each
wires PtySession to its OWN module-level os/select names, so the golden-master recorder's
in-place patching still drives the extracted loop unchanged.
Session lifetime
A backend restart still destroys every live session — a PTY, a Popen and a socket do not
survive docker compose up -d --force-recreate. What no longer vanishes is the RECORD of
them. Jobs, reverse-shell listeners, SSH and MSF sessions now persist their metadata through
core/state_store.py (atomic temp + os.replace, generalized from network_pivot) and reload
after a restart as visibly dead: status='stopped'/'orphaned', restored=true, live-only
probes (shell_responsive, a job's return_code) as None. A reloaded entry carries NO live
handle — never poll() it, killpg it, or probe its old pid, which may now belong to an
unrelated process (the rule network_pivot already followed with pid=0). A reloaded job reads
its output from the surviving $JOB_OUTPUT_DIR/<job_id>.log, so a restart mid-scan no longer
loses what already ran. Persistence is metadata only — nothing is resurrected — and
best-effort: an unwritable state dir degrades to persisted=false exactly as a job's log
degrades to output_logged=false, and never fails a session operation. Passwords and key
contents are deliberately NOT persisted; a dead reloaded session has no use for them and
writing them would create a secret at rest that memory-only state never did.
[Delegated-agent decision under zebbern's standing authority grant, 2026-10-02: the prior rule
described the drop-everything behaviour as an accepted hazard; that was the state of the code,
not a decision to keep it, and it has now been fixed. The state dir for all four registries is
core/config.session_state_dir() — $ZKM_STATE_DIR, else the state sibling of
$JOB_OUTPUT_DIR on the durable kali-tmp volume, else the OS temp dir from source; MSF was
additionally moved onto that resolver (it had defaulted to a container-temp subdir a
force-recreate wipes) so all four land on the same durable volume.]
exec_stream registers no job and cannot be cancelled. On client disconnect the
finally in stream_command_execution only sets consumer_closed, which stops the queue;
the subprocess is never killed and runs to its full timeout, untracked. For anything you may
need to abort, use zebbern_exec(background=True) and job_cancel.
Invariants not to break
- Fail-open in
mcp_tools/__init__.py. A malformed, unknown-schema or unreachable capability manifest registers the full tool set. Core-module tools are never hidden, and a manifest hiding >50% of the surface is ignored. Hiding a tool is unrecoverable — discovery is a startup snapshot — while a broken-but-present tool just fails once. exec_stream's return contract:success,output,return_code,timed_out,streamed, plusincomplete/erroronly when no result frame arrived. A missing result frame must never report success.msf_session_executemust keep reportingtimed_outandconsole_exited. The wait loop's three exits — prompt reached, msfconsole died, budget expired — all fall through to one return, and before the flags existed a module that outran its timeout was indistinguishable from one that finished.timed_outstartsTrueand only the two early exits clear it; that is not inverted, it has been misread as inverted twice. It means "the budget expired" and nothing else. The death exit clears it too, so it needs its own flag:console_exitedis the difference between a console OOM-killed mid-exploit and one that reached a prompt, otherwise field-for-field identical dicts — and under rule 1 that made a crash read as a completed run. It feedspartial_results = bool((timed_out or console_exited) and output)and does not flipsuccessor cap the output. The death exit also clearsis_ready, honest but effectively unobservable throughmsf_session_list, which calls_cleanup_dead_sessions()first and evicts the session beforeis_readyis read. Nothing between the session and the MCP caller reshapes that dict — the route doesjsonify(result),safe_postdoesresponse.json()— so both fields survive on their own; keep it that way. Guarded semantically (not just by source substrings) intests/test_tool_timeouts.py, which drives the real loop with a stubbed process.- The MSF prompt test matches the trailing line, not the last 200 chars.
"msf" in buf[-200:] and ">" in buf[-200:]misses ameterpreteror shell prompt, i.e. exactly what you wait on after an exploit lands, and at a 14400 default that miss is a 4-hour uncancellable block rather than a 5-minute stall._ends_on_promptanchors on the last line and accepts msf/msf6, meterpreter, shell and generic>#$prompts. It strips ANSI for the match only — the buffer returned to the operator is never rewritten. - SSE frames: one JSON object per
data:line. Both emitters serialize throughjson.dumps; never addindent=, and never hand-build a frame that interpolates anything. (_helpers.pystill emits one hand-built heartbeat, but it is a constant literal with no interpolation, so it is safe.) - Defaults
API_LISTEN_HOST=0.0.0.0and an emptyKALI_API_TOKENare load bearing (the container needs0.0.0.0to be reachable through the loopback port publish). Do not "fix" the exposure warning by changing them.
The typed-wrapper verdict
The 135-vs-1 typed-wrappers question was judged, and the pilot ships as an instrument, not an
experiment (2026-10-02). Keep a capability typed iff its runner does one of HANDLE
(server-side state outliving the call), TRANSFORM (returns a field the command's own stdout
does not contain, excluding json.loads of the tool's own --json), ORCHESTRATE (a
data-dependent loop also routed through job_manager), or it is a remote HTTP API client.
Everything else reduces to return execute_command(f'...') and is ceremony the agent could
write itself through zebbern_exec; ~43 of 135 qualify as collapsible. The pilot does not
delete them — it ships an opt-in, default-OFF per-tool suppression via a ZKM_COLLAPSE_PILOT
env set feeding _CapabilityFilteringMCP in register_all. Deletion is the wrong lever:
discovery is a startup snapshot and a schema removal on the wheel track is unrecoverable (see
the fail-open manifest invariant), whereas the env switch is a one-line revert. Env-unset keeps
the surface at exactly 135, so no pin site moves and no count assertion changes; unknown env
names are ignored — fail-open, never raise. Widening the env set is gated on the
probe_tools.py falsifier: the model composes the collapsed command into zebbern_exec, and
the orphan / wrong-syntax / destructive rates are compared net of the wrappers' own measured
defects, not against zero. The falsifier has now been run, against a live 1.0.19 backend (2026-10-03). Sixteen
wrappers measured as thin projections — tools_nmap, masscan, sqlmap, nikto, gobuster,
wpscan, hydra, john, enum4linux, sslscan, ssh_audit, fierce, subzy, httpx plus
api_ffuf_fuzz and api_nuclei_scan — each a build-an-f-string-and-return-execute_command
runner meeting none of the four keep-tests. Both advantages a wrapper was assumed to buy are
gone: an api/exec job with an omitted timeout inherits the binary's tier
(api/blueprints/command.py), and run_promotable forces background: True unconditionally
(mcp_tools/_autopromote.py), so a collapsed command registers in job_list, tees 100% to
$JOB_OUTPUT_DIR and is cancellable. Two findings worth keeping: ssh_audit's typed route is a
bare subprocess.run with a 40s cap that ignores its own 1800s tier and tees nowhere, so
collapsing it is a strict upgrade; and api_ffuf_fuzz/api_nuclei_scan's output-file parse
branch is dead code for any MCP caller, because promotion forces background and the agent
already receives raw ndjson. The sheet and the env must widen in the SAME change — enabling a
suppression whose cheat-sheet line has not shipped strips the wrapper before the model gains
the guidance that replaces it. What a localhost-only run does NOT prove: that the model writes
good commands against real, diverse targets over many sessions. [Delegated-agent decision under
zebbern's standing authority grant, 2026-10-03.]
tools_nmap's footgun is fixed, not deferred — this paragraph used to say otherwise.
run_nmap now always appends -T4 -Pn and puts additional_args AFTER them, so asking for
--script vuln no longer drops -Pn; nmap honours the last -T template, so an operator's own
-Tn still wins, and -Pn is forced (to run host discovery, call zebbern_exec directly).
The capability cheat-sheet lives in the zebbern_exec docstring, not in a new tool (a
six-pin-site change plus a probe case and a baseline entry) and not in a README or an MCP
resource (neither is reliably in the model's runtime context): command_exec is a core module
and so is always in context. It is extended as the ZKM_COLLAPSE_PILOT env set widens — each
capability the pilot suppresses gains a line naming the command that replaces it.
Tests, and what they do not prove
.venv/Scripts/python.exe -m pytest -q # 1624 passed, 6 skipped, ~3m
.venv/Scripts/python.exe -m pytest -m live -q # 15 passed, 3 skipped; backend on :5000
python tests/integration/run_smoke.py --image <img> --expect-variant full --check-trim
python tests/integration/probe_tools.py # all 135 tools, needs a backendlive tests skip themselves when no backend answers, which is why CI stays green without
Docker — and why a green pytest -q alone proves nothing about tool execution. Two live
tests additionally skip without a web lab on host port 8888, and three skip against a backend
older than BACKGROUND_TOOLS_CONTRACT_VERSION — the same version gate the truncation cases
use, because the contract ships in the image while integration.yml pins the previous
digest. One of the six skips in a plain pytest -q run is Windows-only:
tests/test_job_manager.py skips its real-stdbuf case with "GNU stdbuf is absent on this
system"; its companion case asserts where the wrap lives and runs everywhere, so on Windows
the line-buffered launch is never executed, only located. Most other tests are
contract-level with a mocked client: they prove the client shapes the right request, not that
a tool runs.
probe_tools.py compares outcome categories, not output. A tool whose output format
drifts but still exits 0 passes, so "0 BROKEN" is not evidence that a tool still works. It is
the only thing that exercises the whole 135-tool surface: one call per tool, compared against
tests/integration/probe_baseline.json, so a run prints only what changed. Deliberately
manual and not collected by pytest — it runs real scanners, starts and stops real listeners,
and reaches the public internet for a handful of OSINT tools, which is why those are marked
best-effort in the baseline. A raw "BROKEN count" is not a pass criterion: a tool truthfully
reporting that no VPN is configured looks the same as one that regressed, and only the
baseline tells them apart. Re-record the baseline when a tool's expected outcome legitimately
changes. Two ways a BROKEN can be something other than the tool:
- The harness. The probe spawned
mcp_server.pywithtext=Trueand noencoding=, so the child's UTF-8 JSON was decoded withlocale.getpreferredencoding()— cp1252 on Windows. Any reply carrying a byte outside it raisedUnicodeDecodeErrorinsidereadline()and the tool was recorded BROKEN. Measured onapi_nuclei_scan(byte 0x90), and intermittent, because it depended on what the scan happened to find — the worst way for a baseline diff to be wrong, since the baseline exists so a human only reads what changed. Read the detail on a new BROKEN before believing it. - A changed wrapper signature. Making
ad_ldap_enum'sdc_iprequired meant the probe's existing call was rejected in the MCP layer before reaching the backend, which reads identically to the tool failing. Update the case, then re-record.
The tool count is pinned in six places, so adding one tool is a six-file change — the
count is 135 full / 125 trim, asserted in tests/test_tool_descriptions.py,
tests/test_tool_profiles.py (twice, including the trim count, and in two test names),
tests/test_integration_harness.py (eleven sites, two of them inside
pytest.raises(match=...) strings that embed the number),
tests/integration/run_smoke.py (FULL_TOOL_COUNT) and README.md; a new tool also needs a
tests/integration/probe_tools.py case and a tests/integration/probe_baseline.json entry. A
plan that says "add a tool" and lists only the wrapper file goes red in four test files it
never names — and in a parallel batch, in files another agent owns. Adding the two
reverse-shell tools did exactly that. Two README numbers were found stale independently of
that change — the web --exclude-module callback_catcher line said 57 against an actual and
long-asserted 58, and the ctf line said 75 against 78 — so the README counts had already
drifted from the suite.
Check whether a family is really untestable before writing it off. ctf_* was recorded as
unexecutable next to ad_* and vpn_* and is nothing of the sort: it is an HTTP client for
the CTFd v1 API, so a mock CTFd exercises all seven tools including both submit_flag outcomes
and a byte-identical file download, and they came back clean. Re-checking the rest on the
strength of that found the ad_smb_enum bug, so the wrong assumption cost a real defect left
in place. Genuinely unexecutable here: the ad_* attack tools, which need a live domain
controller, and vpn_connect, which needs a peer — but their status and failure paths are
still testable, and that is where ad_smb_enum was caught returning
success: true, null_session: true against a host running no SMB, a security claim asserted
from the auth mode chosen rather than any result.
A guard added to the siblings and not to the one that needed it most. impacket exits 0 on a
connection error and prints the reason as a [-] line, so _run_impacket's tool_errors is
the only thing that separates "reached the DC and found nothing" from "never reached the DC".
kerberoast and secretsdump were given a guard that reads it; asreproast was not, and it
answered success: true, hashes_obtained: 0 — a clean AS-REP roast invented out of a
connection error, the worst direction for this family to fail in. tests/test_ad_tool_claims.py
named only the siblings that had been fixed, so nothing pointed at the gap; a review found it
by reading the three implementations side by side. vpn_connect sat in the same blind spot and
was written off as "needs a peer" twice: core.vpn_manager imports clean on Windows and
tests/test_vpn_manager.py already monkeypatches its subprocess, so all three cases are
deterministic with no peer at all. When a fix lands on a family, re-read every member of it —
and check whether the "untestable" label survives an import attempt.
Two containers from one image, then diff the replies
The only real check is post-merge: rebuild, boot, call the tools. There is a cheaper one, and
it found a real regression on this branch where a green suite and a green mutation run did
not. Start two containers from the same published image, docker cp the changed
zebbern-kali/ files into one and restart it, leave the other untouched as a control, then
call the same endpoint on both and diff the replies. The backend runs from source, so the
patched container really is running the new code. It does not prove the image builds — a
Dockerfile change is still unverified by this — and it must not touch the operator's own
running container.
What it caught: the reverse-shell marker fix below made captured output strictly worse in
the common case. The old substring END test happened to fire on the PTY echo of the end-marker
command and break before that line was appended; the new exact-match test correctly does not
fire on the echo, so the loop ran past it, and the surviving append filter only skipped lines
literally starting with echo ', which a prompt-prefixed root@h:~# echo 'END_x' never does.
A live whoami returned 5 lines against the control's 4, the extra one being the harness's own
marker command. The full suite was green, 78/78 mutation guards were red, and every unit test
passed through all of it — the guards asserted the new boundary logic, which was correct;
nothing asserted the captured output against the old behaviour. So when a change rewrites
capture or boundary logic, diff the captured output against the previous behaviour, not just
against what the new logic intends: a guard written alongside the new logic agrees with it.
Two traps in how that was diagnosed:
- The first conclusion from the live reply was "the fixed branch never ran", because
end_marker_foundandshell_responsiveboth came back null rather than false from code that can only produce a bool. Wrong:end_marker_foundis nested indebug_infoandshell_responsiveonly exists on the status reply, so those were absent keys being read. A null from a reply is not evidence about a branch — check where the field actually lives before inferring control flow from it. - The real tell was
history_suppressed: true, emitted at exactly one place in the patched branch, which proved it had run.
The golden-master harness is the pre-merge gate the two-container method could not be.
[Delegated-agent decision under zebbern's standing authority grant, 2026-10-02.] When the
regression above was found, "the only real check is two containers from one image" was the
best tool available — but it is post-merge (it needs a published image to docker cp into)
and reaches a real PTY only on a live Linux backend this Windows dev host does not have. The
better pre-merge gate, now in place, is a golden master recorded FIRST: before the PtySession
extraction, tests/_pty_golden_recorder.py drove each real manager through the suite's pty
stub with a scripted os.read/select.select/time timeline and froze the exact
operator-facing bytes and flags to tests/fixtures/pty_golden/; the extraction then had to
reproduce them byte-identical (tests/test_pty_golden_master.py), and reverting the
_executed_marker fix to the old substring test turns a fixture red. Recording the fixtures
AFTER a change proves nothing — they would merely enshrine whatever the new code does, the
very trap the live diff caught — so the recording has to precede the change it guards. The
two-container live diff is NOT retired: it stays the POST-merge backstop for real-PTY timing a
scripted-timeline golden master cannot reach, and it is still the only thing that proves the
image builds. And the PtySession extraction is explicitly NOT a capture-logic rewrite — it
relocated only the fd mechanics (pty.openpty/select/os.read/os.write/group teardown)
into core/pty_session.py; every byte of each manager's marker, prompt and capture logic
stayed in the manager, which is why the frozen fixtures reproduced unchanged.
Defect shapes that keep recurring
Neither the suite nor the probe can tell you a tool works. Calling each tool through an
MCP client and reading the reply found roughly twenty defects across ~65 tools, every one of
them green in pytest and in the probe first; around a third answered success: true.
Nothing automated catches this class: the contract tests assert the request the client
builds and the client was usually right, and the probe compares outcome categories, where
"non-zero exit" was already expected. A docstring is not evidence either — several documented
arguments no code read. So: call the tool, read the reply, and check it says what that tool
should say. One call, one output. The shapes, worth checking first in anything new:
- An argument the wrapper sends and nothing reads.
pivot_add_pivot'smethod, the three SSH tunnels'password,api_fuzz_endpoint'sparameters(the route readparams),api_graphql_fuzz'svariables(absent entirely, so it sent zero requests and called the target clean),pivot_ligolo_start'sinterface(the route readtun_name),reverse_shell_listener_start'sauto_upgrade(no reader anywhere, and no TTY-upgrade code to be a reader), andpivot_chisel_client'sfingerprint— the only one where the dropped argument was the security control: an operator who pinned the server's host key got an unpinned tunnel.kali_upload'sencodingis the same shape and still ships:api/kali/uploadhands content toupload_to_kali_with_verification, which takes noencodingand always base64-decodes; documented as inert rather than removed, because removing it is a published-schema change. Audit mechanically, not by eye: walk every key each wrapper serialises against the code that receives it, remembering that most routes passparamsstraight to a runner, so the search has to reachcore/andtools/and not stop at the blueprint. - The mirror: the backend demands what the schema calls optional.
ad_ldap_enum(domain, username, password)andad_secretsdump(domain, username, password)both answered a 400 naming exactly what was missing — honest replies, butdc_ipandtargetcarried"default": ""in the published JSON schema, so the obvious minimal call was the one that always failed. Audit by finding every route that 400s on a missing key and checking it against the wrappers that post there. A signature cannot express "one of two", soad_secretsdumpchecks locally and returns the backend's own wording.ad_bloodhound_collectwas the third, found by a later sweep and worse than the other two: its docstring did not merely defaultdc_ipto"", it promised "auto-detected if empty" for detection code that exists nowhere. Fixing the two named above did not find it, because the audit was run against the routes already known to 400 rather than against every route that does. success: truefor work that did not happen.reverse_shell_commandagainst a dead shell,exploit_copycarrying "Could not find EDB-ID #" as its message, a chisel client already defunct,payload_generatewith an empty file. Check the thing the tool exists to produce, not the exit code.- A liveness check is not enough (rule 3). The fix for the defunct chisel client was
proc.poll()after 1.5s, and that is exactly what a failing client evades: chisel retries a failed handshake forever rather than exiting. A deliberately wrong--fingerprintansweredsuccess: true, fingerprint_pinned: truewith a tunnel id while the log looped on "Invalid fingerprint" — the one event pinning exists to catch, reported as a working client. It now reads the log: a mismatch fails and terminates the client (never transient, and never something to leave retrying against whatever answered), any other connection error keeps the process but reportsconnected: false. Note the shape: the fix that made pinning real is what made this reachable, found by driving the fix on the image it shipped in rather than by reviewing it. - The same gap from the server end.
pivot_list_tunnelsdetected a dead chisel server by pid, and a pid is the weaker half of the answer — a server whose control socket is gone keeps its pid and reads as "active", which is how an operator came to stack three clients on a dead tunnel. Every local-listener tunnel (chisel_server,socat,ssh_local,ssh_dynamic,ligolo_proxy—LOCAL_LISTENER_TYPESincore/network_pivot.py) now carrieslistening, on the same advisory contract asconnected.chisel_clientandssh_remotegetlistening: null, not false — their listener is on the far end, and a false there would be a false alarm in the one tool an operator consults when they already distrust the tunnel. Auto-restart stays deliberately absent: resurrecting a pentest tunnel could reattach to a changed target and would hide the instability. - A status read with side effects on what it reports (rule 3). That flag answered with a
real
socket.create_connectionfor every type inLOCAL_LISTENER_TYPES, and two of those are pure forwarders: socat runsfork,reuseaddr, so accepting forks a child that dialstarget_host:target_port, andssh -Lopens a channel to the forwarded host the moment it accepts. So read-onlypivot_list_tunnelsopened a TCP connection to e.g.10.0.0.5:445on every call. The set is split now:CONNECT_SAFE_LISTENER_TYPES(chisel_server,ssh_dynamic,ligolo_proxy) terminate the connect at their own endpoint and keep the 0.3s connect to127.0.0.1;FORWARDER_LISTENER_TYPES(socat,ssh_local) are answered from the kernel socket table instead (ss -ltn, falling back tonetstat -ltn, both in the image, fetched at most once per listing), proving the socket exists without dialling through it.LOCAL_LISTENER_TYPESis the union, so it still means what it did._listening_portsreturnsNonerather than an empty set when nothing can answer, so an unreadable table yieldslistening: Noneinstead of a confidentFalse, andlistening_method(connect/socket_table/pid/unavailable/None) says which answer you got and distinguishes the two kinds of null. Verified live:chisel_serverreportsmethod=connect, a socat forward with a dead downstream reportsmethod=socket_table, and a killed socat reportsstatus=stopped listening=False method=pid. The guards intests/test_pivot_listener_probe.pyassert the absence of the connection behaviourally — a real listening socket is handed to the test, nothing accepts from it, andselect()says whether a connection reached the accept queue — because an assertion about which helper was called would have passed against the defect. - A derived value that answers a different question than the one asked.
_get_local_ipUDP-connects to8.8.8.8and returns the default-route source, which inside the container is the docker bridge (172.17.0.2) — an address no target can reach, handed out as the advertised host. Preferring "the default route" is not the fix either: an operator hit this with tun0 up at10.10.17.215, because their.ovpndid not redirect the default gateway, so the VPN interface has to be consulted explicitly. The advertised host now comes back withadvertised_host_sourceand a note naming the trap when it is a guess. Separately, the advertisedconnect_commandused a bareR:socks, whose remote port defaults to 1080 — the portvpn_connect's own SOCKS already holds and reports assocks_proxy: {port: 1080, running: true}— producing "Server cannot listen on R:127.0.0.1:1080=>socks" in an endless retry loop. The reverse SOCKS port is now chosen, reported, and moved with a note when 1080 is taken. - Verification that confirms the wrong invariant. The upload checksum hashed what the caller sent and what landed, and down the utf-8 path those were the same base64 string — so it certified a faithful transfer of the wrong bytes.
- Boundary detection that matches a substring instead of the executed line.
reverse_shell_commandwraps the command inecho '<marker>'lines, and a PTY echoes what is written to it, somarker in textwas satisfied by the echo of the typed line with no shell behind it. On a live-but-silent caught shell that producedsuccess: true, lines_captured: 0. The dead-session (EOF) path was already guarded bysession_closed; the live-echo path was not, andsuccessrequiringnot session_closeddid not help because nothing had closed._executed_markernow takes equality on the line (ANSI stripped for the match only), and_executed_marker_spancarries the base64 branch — the span matters on its own, becausetext_buffer.find(marker)returns the FIRST occurrence, which is the echo, so theclean_contentoffsets stayed anchored on it after the boolean test had been fixed. Same shape as_ends_on_prompt: anchor on the line, strip ANSI for the match, never rewrite the buffer. - Markers landing in the target's shell history. An operator read
echo 'START_36892201'out of/home/worker/.bash_historyand briefly took their own markers for the target's. A prelude now setsHISTFILE=/dev/nullandset +o history, each command individually guarded so a dash/ash/busybox target lackingset -o historycannot error into the capture, and the prelude is drained to the first executed start marker so neither it nor its echo can enter output. It is not the forbidden redaction: it hides nothing from the operator, it keeps the operator's own injected markers out of the target's history.suppress_historydefaults True andhistory_suppressedreports only that the prelude was sent, never that the target honoured it — verified live against an unmodified control, which reported the real histfile andhistory onwhere the patched target reportedHISTFILE=[/dev/null]andhistory off. Caught shells also have a raw channel, which needs no markers at all:reverse_shell_send_input/reverse_shell_read_outputonapi/reverse-shell/<id>/send-raw(POST) and/read-output(GET). The genericsend_input/read_outputstill resolve throughjob_managerand still only servezebbern_execjobs; reverse shells live inactive_sessionsand the two sets stay disjoint. - A default that contradicts the docstring above it. Three upload tools documented base64
content and defaulted
encoding="utf-8";callback_waitdefaulted to 60s, exactly the harness abort.reverse_shell_commandhad the same 60 and lost the same race, so its owntimed_outand the partial capture under it never came back. 45 is measured, not round, and it is defaulted in three places across both release tracks (wrapper, route,ReverseShellManager.send_command), all now guarded strictly under 55. - Copy-paste output that does not run. Two of three
callback_generateDNS commands were malformed, and a lookup that never leaves the box looks exactly like a target that did not call back. - A tool reaching outside itself.
payload_host_startcalledos.chdir, which is process-wide, moving the cwd of every laterzebbern_execfrom the mounted volume to a container-layer directory. - A fix that only runs on a path no one takes. The cross-restart session persistence
(see Session lifetime) landed working for jobs, reverse shells and
SSH and did nothing for MSF on the one path that matters:
kali_server.py's SIGTERM handler calledmsf_manager.destroy_all_sessions(), which clearsself.sessionsand re-persists an EMPTY file, so every routinedocker restart/docker compose up -d --force-recreatewiped the just-persisted MSF records before the new process could reload them -- while reverse shells and SSH, whose handler callsmanager.stop(), survived.destroy_all_sessionsis correct as the operator toolmsf_session_destroy_all(the operator asked for the records gone), so the shutdown path got its ownMetasploitManager.shutdown()that stops each live process and leaves the registry, mirroringjob_manager.shutdown(). It survived 1619 green tests because the load-bearing half iskali_server.py's wiring, and that file cannot be imported on Windows (pty/termiosviaapi.routes), so the suite can only assert its source text and never drive the SIGTERM path; the end-to-end proof is a livedocker restartshowing the session reload as a dead stand-in rather than the list coming back empty. [Delegated-agent decision under zebbern's standing authority grant, 2026-10-03.]
The two disagreement shapes (an argument nothing reads; a 400 on a schema-optional key) are
the exception to "nothing automated catches this", and worth re-running as audits after any
change to the tool surface: they compare two artefacts that already exist rather than judging
behaviour, so a script can do it. The endpoint-and-verb check is now permanent in
tests/test_wrapper_endpoints_exist.py (240 call sites against 146 declared routes). The
key-reachability and 400-vs-optional audits stay manual, because both are noisy: routes that
hand params wholesale to a runner look like dropped keys, and a 400 naming what is missing
is often the honest answer.
Check that a guard fails when you break the thing
A test written alongside a fix passes whether or not it tests the fix. Prove it fails when the fix is reverted:
.venv/Scripts/python.exe scripts/mutation_check.py --spec tests/mutations.json \
--python .venv/Scripts/python.exeDo not do this by hand with str.replace. It was done that way three times in one session and
silently matched nothing every time — a CRLF file against an LF needle, an escaped backslash
mangled by a heredoc, a comment containing the same words as the code. The tests passed, and
"mutation-checked red" went into a commit message for a guard that had never been exercised.
The script refuses to call that a pass: it requires the target text to occur exactly the
expected number of times, the file to change on disk, the result to still parse, the tests to
fail, and the file to be restored byte-for-byte. A mutation that cannot be applied is the
loudest outcome, because that is the case that used to look like success. It has earned this
twice:
- Run across the guards written in one sweep, 22 of 26 verified and four did not: three
anchors that silently matched nothing, and one guard that genuinely did not catch its
mutation —
exploit_copy's post-copy file check, which the by-hand run had appeared to cover because it mutated two things at once and the other one carried the test. - A mutation entry is coupled to the source line it quotes. Merging this round's entries
made an existing one stale: the pivot listener fix moved the line the entry
pivot list: claim every listener is upanchored on, and the script saidexpected the target text 1x, found 0x. The mutation would not have applied, which is exactly the case that used to look like a pass.The entry was re-anchored. A later refactor of a quoted line silently invalidates that guard's proof until the script is re-run.
Add a mutation to tests/mutations.json whenever you add a guard. The spec holds 140
entries and the last full run was 140/140 guards verified red. An entry has exactly five
keys — name, file, old, new, tests. occurrences is a CLI parameter of the checker
that defaults to 1; no entry sets it, and adding it to one is a schema divergence that reads
as deliberate.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

