apex-twin 0.20.0: operations run book, security policy, release tarball

docs/operations.md is the run book: install with DESTDIR/PREFIX, the two
systemd units and their hardening, the state directory and what to back up,
scope lifecycle and rule order, proxy/rewrite/webhook operation, upgrade and
rollback, limits (8 MiB MCP body, 1 MiB proxy body/response, 1024 findings per
report) and troubleshooting by refusal reason.

SECURITY.md states the trust boundaries and the threat model: the scope file and
webhook URL are operator-owned, loopback listeners have no auth, CONNECT is a
blind tunnel, target content is data, and a missing gate is the highest severity
report. It includes a hardening checklist and the non-goals.

make dist reads APEX_VERSION from src/apex.h and writes apex-twin-<version>.tar.gz
with Makefile, README, SECURITY, .gitignore, src/, vendor/, tests/, docs/,
examples/ and systemd/; object files, gcov data, __pycache__, build dirs, the
binary and .git are excluded. 48 entries, no forbidden path.

Verified: make dist -> 0.20.0 tarball; extract to /tmp, make, full suite 298/298;
repo suite 298/298; analyze 0 warnings. README links the new docs.
This commit is contained in:
lotherk committed 2026-11-21 08:14:26 +00:00
1 parent adf65477a4
commit 6b52bcc547
6 files changed
+354 -3

No files matched your search

+2
View File
@@ -11,3 +11,5 @@ build-fuzzbug-http/
apex-twin-cov
build-cov/
*.gcov
apex-twin-*.tar.gz
/apex-twin-*/
+18 -1
View File
@@ -20,6 +20,9 @@ FUZZBUG_HTTP_OBJ := $(SRC:src/%.c=build-fuzzbug-http/%.o)
COV_BIN := apex-twin-cov
COV_OBJ := $(SRC:src/%.c=build-cov/%.o)
COV_FLAGS := -g -O0 --coverage
VERSION := $(shell sed -n 's/^#define APEX_VERSION "\(.*\)"/\1/p' src/apex.h)
DISTNAME := apex-twin-$(VERSION)
DIST := $(DISTNAME).tar.gz
all: apex-twin
@@ -142,6 +145,19 @@ analyze:
$(CC) $(CFLAGS) -fanalyzer -I$(LIBDIR) -Isrc -c -o /dev/null $$f || exit 1; \
done
dist:
@test -n "$(VERSION)" || { echo "dist: cannot read APEX_VERSION"; exit 1; }
rm -rf $(DISTNAME) $(DIST)
mkdir -p $(DISTNAME)
cp Makefile README.md SECURITY.md .gitignore $(DISTNAME)/
cp -a src vendor tests docs examples systemd $(DISTNAME)/
find $(DISTNAME) -type f \( -name '*.o' -o -name '*.gcda' -o -name '*.gcno' \
-o -name '*.gcov' \) -delete
find $(DISTNAME) -type d -name '__pycache__' -prune -exec rm -rf {} +
tar -czf $(DIST) $(DISTNAME)
rm -rf $(DISTNAME)
@echo "built $(DIST)"
install: apex-twin
mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(DOCDIR) $(DESTDIR)$(UNITDIR)
install -m 0755 apex-twin $(DESTDIR)$(BINDIR)/apex-twin
@@ -155,5 +171,6 @@ clean:
rm -rf build-asan build-fuzzbug build-fuzzbug-proxy build-fuzzbug-http \
build-cov
rm -f *.gcov
rm -rf $(DISTNAME) $(DIST)
.PHONY: all test asan test-asan fuzz fuzz-selftest fuzz-red fuzz-proxy fuzz-proxy-red fuzz-http fuzz-http-red coverage analyze install clean
.PHONY: all test asan test-asan fuzz fuzz-selftest fuzz-red fuzz-proxy fuzz-proxy-red fuzz-http fuzz-http-red coverage analyze dist install clean
+12 -1
View File
@@ -14,6 +14,16 @@ database, no shell, no post-exploitation. Every tool either observes (scan, fetc
capture) or proves (headers, certificate, reflected payload). Transmission is a
separate, explicitly armed switch.
## Documentation
- [docs/operations.md](docs/operations.md) — install, state directory and
backup, scope lifecycle, systemd, proxy and rewrite rules, webhook, upgrade,
troubleshooting, limits.
- [docs/artex-port.md](docs/artex-port.md) — what was ported from ARTEX and what
was deliberately left out.
- [SECURITY.md](SECURITY.md) — threat model, trust boundaries, hardening
checklist and how to report a problem.
## Build
```sh
@@ -28,6 +38,7 @@ make fuzz-red # builds a deliberately broken binary; fuzz must reject it
make fuzz-proxy # mutated raw requests against the ASan proxy
make fuzz-http # mutated raw HTTP against the ASan MCP HTTP face
make install # binary, README and both systemd units (DESTDIR/PREFIX respected)
make dist # apex-twin-<version>.tar.gz: source, tests, docs, units
```
`make install` puts the binary in `$PREFIX/bin`, the README in
@@ -425,7 +436,7 @@ the copied scope reason is now bounded with a precision, not left to snprintf.
## Status
0.19.0. Built and run: 45 tools, 298 checks, 340 fuzz cases and 76.7% line
0.20.0. Built and run: 45 tools, 298 checks, 340 fuzz cases and 76.7% line
coverage. The loop closes: a probe captures the exchange as a pair, a finding
points at it, `finding_update` gives it a state, an asset records the host it
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
+104
View File
@@ -0,0 +1,104 @@
# Security policy and threat model
APEX TWIN is a scope-gated offensive-security MCP server. It is built to be
runnable by one operator on one machine, with the gate as the product. This page
states what that means, what it does not protect against, and how to report a
problem.
## Supported versions
The current release line is **0.19.x** (`src/apex.h`, `APEX_VERSION`). Security
fixes land on the current line; older builds are expected to be rebuilt from
the current tree rather than patched in place.
## Reporting a vulnerability
Report privately to the owner of the copy you run (the repository owner), not
in a public issue, and do not attach live credentials, tokens, customer data or
engagement evidence. The state directory contains all of those. Include the
version (`apex-twin --version`), the scope shape that reproduces it (redact
targets), the exact tool call or proxy request, and the audit lines around it.
Expect an acknowledgement, a reproduction check against the current tree, and a
fix plus a test that fails without it. Reports that show a *missing gate* are
treated as the highest severity: the gate is the reason this program exists.
## Trust boundaries
| Boundary | Inside | Outside |
|---|---|---|
| Operator | scope file, environment, webhook URL, rewrite rules | — |
| Target | whatever the scope names | everything else |
| Listener | loopback (127.0.0.1) HTTP and proxy | LAN/WAN |
| State | `$APEX_HOME`, mode 0700, files 0600 | other users |
The scope file is trusted input: whoever can write it can widen the engagement.
Protect it like the rest of the state. The webhook URL is trusted configuration;
it is never taken from a target. Rewrite rules are trusted configuration and can
only narrow what the proxy does (the scope gate still runs first).
## What the design defends against
- **Acting outside the engagement.** Every tool that names a target calls one
gate function; there is no second path that opens a socket or spawns a process.
A missing scope refuses everything. A name outside `allow_domain` must resolve
entirely inside `allow_ip`, and a listed name may not resolve private while
`allow_private` is false — DNS rebinding without a scope change.
- **Ambiguous actions.** Deny rules run before the scope in `guard_check`; a
destructive command is refused for what it is, not for a URL that happens to
sit in the same line.
- **Radio transmission.** `serial_tx` in the scope *and* the command allowlist
must both pass. A receiver is a scanner; a transmitter is an attack.
- **Silent actions.** The audit line is written before the action, so a crash
mid-scan still leaves the intent on disk.
- **Accidental exposure.** Both listeners bind loopback only; the HTTP face and
the proxy do not authenticate.
- **Memory-unsafe parsing.** Scope, rewrite, HTTP and proxy parsers are fuzzed
under ASan/UBSan and `gcc -fanalyzer`; a sanitizer report is a test failure.
## What it does not defend against
- **Local users on the same host.** Loopback listeners have no authentication.
Any local user who can reach the port can use the MCP server or the proxy
within the loaded scope, and can read `audit.log` only if file permissions let
them. Run it as a dedicated user on a host you control, or reach it through a
tunnel that terminates on the same account.
- **A malicious scope or rewrite file.** These are operator-owned. Writing them
is equivalent to being the operator.
- **A malicious target.** Responses are data, not instructions; evidence is
stored as bytes. The program does not execute target content.
- **TLS interception.** `CONNECT` is a blind tunnel; nothing inside TLS is
inspected, logged or rewritten. That is deliberate (no TLS stack is linked).
- **Denial of service from a local client.** The proxy is serial; a client that
holds a connection can delay the next one. Timeouts bound it, not isolate it.
- **Compromised operator credentials.** A stolen shell or SSH key can run the
binary against the scope. The audit records what was asked, not who asked.
- **Webhook confidentiality.** Evidence titles and targets are POSTed to the
configured URL. Use an endpoint you trust and TLS where the transport matters.
## Hardening checklist
- Run as a dedicated, unprivileged user; keep `$APEX_HOME` at 0700 and never on
a shared filesystem.
- Keep both listeners on loopback. Tunnel in; do not expose them.
- Write the narrowest scope that answers the question, with an `expires` date
and `allow_private: false` unless the engagement is inside a private net.
- Leave `serial_tx: false` unless the rules of engagement authorise
transmission.
- Set `APEX_WEBHOOK_MIN_SEVERITY` where you want the wake-up; the default is
`critical`.
- Put secrets in `~/.config/apex-twin/env` or the service environment, not in
the unit file or in the repository.
- Back up `audit.log` and `evidence/` before deleting a state directory; both may
contain sensitive engagement data. Encrypt the backup.
- Rebuild and re-run `make test` after every upgrade; `make analyze` and
`make fuzz` are the cheap regression checks for parser changes.
## Non-goals
APEX TWIN is not an exploit framework, a post-exploitation toolkit, a database
reader, a TLS interceptor, a multi-user service, or an agent loop. A feature
that adds a shell, reads target data it was not asked to prove, or widens the
scope without an operator edit is out of scope by design.
Licence: AGPL-3.0, same as ARTEX.
+217
View File
@@ -0,0 +1,217 @@
# Operating APEX TWIN
This is the run book: how to install it, what it writes, how the scope behaves,
how to run the proxy and the webhook, how to back up and upgrade, and what to
check when something refuses.
## What runs
| Mode | Command | Listener |
|---|---|---|
| MCP over stdio | `apex-twin` | none |
| MCP over HTTP | `apex-twin --http 8797` | 127.0.0.1:8797, `POST /mcp` |
| Forward proxy | `apex-twin --proxy 8798` | 127.0.0.1:8798 |
| Diagnostics | `apex-twin --check` | none, prints JSON and exits |
Both listeners bind loopback only on purpose. Reach them through an SSH tunnel
or a VPN; never put them on a LAN interface.
## Install
```sh
make # build, zero warnings under -Werror
make test # 298 end-to-end checks
make install # binary, README and both systemd units
make install DESTDIR=/tmp/pkg PREFIX=/usr
```
`make install` writes:
```
$PREFIX/bin/apex-twin
$PREFIX/share/doc/apex-twin/README.md
$PREFIX/lib/systemd/system/apex-twin.service
$PREFIX/lib/systemd/system/apex-twin-proxy.service
```
The units hardcode `User=lotherk` and
`APEX_HOME=/home/lotherk/stack/data/apex-twin`; edit them before installing for
another account. `EnvironmentFile=-/home/lotherk/.config/apex-twin/env` is
optional and is the right place for `APEX_WEBHOOK`, `APEX_REWRITE` and the time
outs — keep secrets out of the unit file.
The radio unit adds `SupplementaryGroups=dialout`; the proxy unit does not, and
neither unit gets `CAP_NET_RAW` (connect scans need no privilege).
```sh
systemctl daemon-reload
systemctl enable --now apex-twin.service apex-twin-proxy.service
journalctl -u apex-twin -f
```
## State
Everything lives under `$APEX_HOME` (default
`~/.local/state/apex-twin`), created 0700:
```
scope.json the rules of engagement
audit.log one JSON line per decision, append-only
findings/f0001.json one finding per file, rewritten atomically on update
evidence/<ts>-<label>.bin raw proof, 0600
reports/report-<ts>.* md / csv / json, never overwritten
assets/a0001.json one record per target, merged on the next look
traffic/t0001.json|.http one capture: metadata plus the raw pair
rewrite.json proxy rules, read at start and on SIGHUP (optional)
```
`audit.log` is written **before** an action, so a process that dies mid-scan
still left its intent on disk. Findings, assets and reports are written beside
their target and renamed; a reader never sees half a file.
## Scope lifecycle
Write `scope.json` before the first run. Start from `examples/scope.json`:
```json
{
"label": "acme-q1",
"expires": "2026-03-31T23:59:59Z",
"allow_private": false,
"serial_tx": false,
"allow_ip": ["203.0.113.0/24", "198.51.100.7"],
"deny_ip": ["203.0.113.66"],
"allow_domain": ["app.acme.example", "*.acme.example"],
"allow_port": ["80", "443", "8000-8100"]
}
```
Rules are applied in this order: no scope / expired / `deny_ip` / `allow_port` /
neither `allow_ip` nor `allow_domain` / private or loopback without
`allow_private` / a name outside `allow_domain` that does not resolve entirely
inside `allow_ip`. `deny_ip` beats `allow_ip`. A name in `allow_domain` is
trusted for its addresses but may not resolve private while `allow_private` is
false.
Before an engagement:
```sh
apex-twin --check # loaded? expired? tool count?
```
Ask the gate without touching the target (MCP tool `scope_check`):
```json
{"name":"scope_check","arguments":{"target":"203.0.113.9","port":443}}
```
Edit the file while the server runs and call `scope_reload` (or restart). The
proxy's rewrite rules are separate and reload on `kill -HUP`.
## Backup and restore
Stop the services, then copy the whole state directory:
```sh
systemctl stop apex-twin.service apex-twin-proxy.service
rsync -a ~/.local/state/apex-twin/ /backup/apex-twin-$(date +%F)/
systemctl start apex-twin.service apex-twin-proxy.service
```
Restore is the reverse. Reports are derivable from findings and assets;
`audit.log` and `evidence/` are not. Evidence and audit may contain credentials,
tokens or personal data from an engagement — treat the backup as sensitive.
## Proxy
```sh
curl -x http://127.0.0.1:8798 http://target.example/
```
Every request passes the scope gate before a socket opens. Plain HTTP is
forwarded and captured under `traffic/`. `CONNECT` is tunnelled blind and only
recorded as metadata: the binary links no TLS stack, so it does not inspect TLS.
`rewrite.json` can set or remove headers and block a path; first match wins:
```json
{"rules": [
{"match_host": "app.example.com", "match_path_prefix": "/api",
"set": [{"name": "X-Test", "value": "1"}],
"remove": ["User-Agent"], "note": "mark the request"},
{"match_host": "*", "match_path_prefix": "/admin",
"block": true, "note": "not part of this engagement"}
]}
```
`kill -HUP <pid>` reloads. An invalid file is rejected whole; the previous rules
stay active. Bodies: `Content-Length` and `Transfer-Encoding: chunked` are
forwarded; chunked payload is capped at 1 MiB (413 over), malformed framing is
400 and is decided before the origin is opened. Responses are capped at 1 MiB
per capture.
## Webhook
```sh
APEX_WEBHOOK=https://hooks.example/apex \
APEX_WEBHOOK_MIN_SEVERITY=high \
apex-twin
```
A finding at or above the floor is POSTed as JSON after it is on disk, and so is
the transition of a finding into `confirmed`. `notify_test` sends one event.
The webhook is operator infrastructure, not a target: it is **not** put through
the scope gate, and a failing webhook never fails the finding. The URL is read
from the environment; `--check` reports only `webhook_configured: true/false`.
## Upgrade and rollback
```sh
git pull
make && make test
make install
systemctl restart apex-twin.service apex-twin-proxy.service
```
State is forward compatible: older findings without `status` are read as
`open`, and the JSON formats only ever gained fields. To roll back, install the
previous binary and keep the state directory; if a newer build wrote a field the
older one does not know, the older build ignores it but will drop it on rewrite
of that file — back up first.
## Limits worth knowing
| Limit | Value |
|---|---|
| HTTP MCP request body | 8 MiB (`413` over) |
| Proxy request body (chunked) | 1 MiB payload |
| Proxy response per capture | 1 MiB (marked truncated) |
| Findings per report | 1024 |
| Default tool timeout | 60 s (hard cap 900 s) |
| Radio scan | 3–300 s, always ends with `stopscan` |
## Troubleshooting
- **Everything is refused.** No scope file, an expired scope, or a rule that
does not match. `apex-twin --check` and `scope_check` name the reason; the
refusal string is the contract, not just `isError`.
- **Port refused but host allowed.** `allow_port` is enforced for single-port
actions. `port <= 0` means "the caller enumerates ports", used by `portscan`.
- **A name resolves into a private net.** `allow_private` is false; either set
it or scope the name to public addresses.
- **The radio refuses to talk.** `/dev/ttyACM0` may be a console, not a
Marauder: the guard sends a bare CRLF and refuses on `login:`, `password:`,
`console (`, `mikronix`, `busybox`, `root@`. Set `APEX_SERIAL` to the real
device. Scans always send `stopscan`.
- **A gate decision is missing from the audit.** Look at `audit.log` ordering:
the deny line is written before the refusal; a missing line means the tool
never reached the gate, which is a bug worth reporting.
- **The webhook never fires.** `APEX_WEBHOOK` unset, severity below the floor, or
curl missing. `notify_test` says which; `audit.log` has `tool: notify` with the
curl exit code.
## What it does not do
No shell, no exploit, no post-exploitation, no database reads, no TLS
interception, no agent loop. The MCP client is the agent; this process is the
gate, the tools and the records.
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "0.19.0"
#define APEX_VERSION "0.20.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024