Files
lotherk 59b71ab3a1 apex-twin 1.100.0: auth_test over six protocols, SIGPIPE fix
Authentication testing in src/tools_auth.c (new file, 16th table): auth_test
speaks http Basic, ftp, smtp AUTH LOGIN, imap, pop3 and mysql
(mysql_native_password) against one in-scope service. The operator supplies
the wordlists (inline or file) and every limit - delay_ms, max_attempts,
stop_on_hit, lockout_limit, timeout_ms; the program adds none of its own.
auth_plan counts a run without connecting, auth_protocols lists the
protocols, auth_hits returns the credential findings with evidence paths.
A hit is the protocol's own accept answer; each accepted pair becomes a
critical finding with the pair and the answer in evidence, while the audit
log keeps the account and service and never the password.

Two real bugs found by the tests they came with:

- An HTTP answer below 400 counted as a hit, so a 404 or a 500 would have
  been reported as valid credentials. Only 2xx/3xx prove authentication
  now; two checks pin it and fail against the old logic.
- SIGPIPE killed the whole server when a target hung up mid-write: one
  dead target, one dead MCP server. Ignored once at startup, so the write
  returns EPIPE and the tool reports a failed connection. Five checks, one
  per protocol.

SHA1 for the MySQL scramble is written out in the file and checked against
the published vectors for "", "abc", "password" and a 1000-byte multi-block
input. The MySQL seed is read by counting handshake fields; a fixed offset
picked up the capability flags and made every login fail against a healthy
server, which the suite proves by neutralising the offset.

427 tools, 1637 end-to-end checks, 84.7% line coverage.
release-check exit 0, distcheck 1.100.0 passes 1637/1637 from the tarball.
2026-11-24 06:45:02 +00:00

337 lines
21 KiB
Markdown

# 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 supported line is the one printed by `apex-twin --version` for the tree you
built; this document ships with that same tree. At the time of writing the line
is **1.100.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
line. The 1.0 line promises that the on-disk JSON formats for findings, assets
and traffic only gain fields, so state stays readable; older builds are still
rebuilt 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.
- **A target that hangs up.** `SIGPIPE` is ignored once at startup, so a peer
that closes the connection mid-write returns `EPIPE` to the tool that wrote
and is reported as a failed connection. Without it, one dead target would end
the whole server — the failure mode every network tool would share.
- **Credential guessing.** `cred_test` is the small built-in check: HTTP Basic
only, at most 20 attempts, 200 ms apart. `auth_test` is the real one and has
no built-in rate or attempt limit beyond what the operator passes: the
wordlists, `delay_ms`, `max_attempts`, `stop_on_hit` and `lockout_limit` are
the operator's settings, not the program's opinion. What the program does
guarantee is that every attempt is one gated connection to one in-scope
target, that a hit is the protocol's own accept answer rather than a guess,
and that the password never reaches the audit log. How hard to push, and what
a lockout on the target would cost, is the operator's call.
- **SSRF probing only calls your collector.** `ssrf_probe` injects URLs that
point at its own loopback listener (or `callback_base` you supply). It never
injects cloud metadata addresses and never reads what the target fetches.
- **Firmware writing needs an explicit confirmation.** `esp_flash` refuses
without `confirm=true`, validates an absolute image path and audits the
attempt; it exists to provision the operator's own board.
- **git/npm/pip config audits read local files.** The Harbor probe sends two
unauthenticated GETs and saves the project list.
- **passwd/authorized_keys/ld.so.preload audits read local files.** The
Gitea probe sends two unauthenticated GETs and saves the admin list.
- **Bluetooth/NetworkManager/D-Bus audits read local files.** The Nexus
probe sends two unauthenticated GETs and saves the repository list.
- **USBGuard/certbot/WPA audits read local files.** The Jenkins API probe
sends two unauthenticated GETs and saves the job list.
- **resolved/udev/issue audits read local files.** The SMTP AUTH probe reads
the banner and EHLO features; no login is attempted.
- **OpenSSL/curl/wget configuration audits read local files.** The TLS
chain probe performs one handshake and reads the presented certificates.
- **Compose, manifest and Dockerfile audits read one local file each.** The
AMQP probe reads Connection.Start and never sends credentials.
- **atd, securetty and tmpfiles audits read local files.** The Logstash node
probe sends two unauthenticated GETs and saves the stats answer.
- **sshd_config, hosts_access and profile audits read local files.** The
Kibana probe sends two unauthenticated GETs and saves the saved-objects
answer.
- **Telegraf, Graylog and Netdata audits read local files.** The ClickHouse
probe sends two unauthenticated GETs and saves the query answer.
- **Logstash, Filebeat and Fluentd audits read local files.** The InfluxDB
probe sends two unauthenticated GETs and saves the query answer.
- **Kibana, Nagios and Synapse audits read local files.** The NATS
monitoring probe sends two unauthenticated GETs and saves the varz answer.
- **Webmin, Cockpit and phpMyAdmin audits read local files.** The MinIO
probe sends two unauthenticated GETs and saves the admin answer.
- **GitLab, Vaultwarden and keepalived audits read local files.** The Grafana
probe sends three unauthenticated GETs and saves the datasource list.
- **Zabbix, NRPE and unattended-upgrades audits read local files.** The
RabbitMQ probe sends two unauthenticated GETs and saves the overview.
- **Gitea, MinIO and Nextcloud audits read local files.** The Prometheus
probe sends two unauthenticated GETs and saves the query answer as evidence.
- **Caddy, Traefik and autofs audits read local files.** The CouchDB probe
sends two unauthenticated GETs and saves the database list as evidence.
- **FreeRADIUS, containerd and NATS audits read local files.** The Consul
probe sends two unauthenticated GETs and saves the first answer as evidence.
- **Kafka, PowerDNS and Varnish audits read local files.** The registry probe
sends two unauthenticated GETs and saves the catalog as evidence.
- **iSCSI, rpcbind and kdump audits read local files.** The etcd probe sends
three unauthenticated GETs and saves the first answers as evidence.
- **Avahi, logind and tftpd-hpa audits read local files.** The ZooKeeper
probe sends only the stat and mntr four-letter commands, no data.
- **pgbouncer, xinetd and SSSD audits read local files.** The FTP TLS probe
reads the banner and sends AUTH TLS without logging in.
- **dnsmasq, nsswitch and Jenkins audits read local files.** The TLS
hostname check is one handshake with the name as SNI.
- **journald, coredump and nftables audits read local files.** The HSTS
check makes one TLS GET.
- **Certificate, timesyncd and resolv.conf audits read local files.** The
certificate audit parses each file with `openssl x509`; no network is used.
- **pg_hba, polkit and LDAP client audits read local configuration.** The
FCrDNS check performs a PTR lookup and then forward A/AAAA lookups.
- **Chrony, APT and login.defs audits read local configuration.** The
WebSocket origin check performs two upgrade handshakes and opens no data
frames.
- **Cron and fail2ban audits read local configuration; the redirect check
makes GETs.** `http_redirect_audit` follows up to five redirects and
re-checks the scope of every hop before following it.
- **WireGuard, IPsec and OpenLDAP audits read local configuration.** They
never touch a tunnel, a key exchange or a directory. The dangling-CNAME check
follows a chain with `dig`.
- **Kubernetes and NS checks are unauthenticated reads.** `kubernetes_api_probe`
sends four GETs without a token; `dns_ns_consistency` queries NS/A records.
Grafana and Prometheus audits read configuration files.
- **mTLS detection is one handshake.** `tls_client_auth_probe` reads the
CertificateRequest from `s_client -msg` and presents no certificate. Consul,
Vault and ZooKeeper audits read configuration files.
- **SNI checks are TLS handshakes only.** `sni_vhost_check` connects once per
in-scope name and reads the certificate; Kubernetes, etcd and RabbitMQ
audits read configuration files.
- **CAA is one DNS query.** `dns_caa_check` reads the CAA records of an
in-scope domain; it does not request a certificate. BIND, Tomcat and
ProFTPD audits read configuration files.
- **Wildcard DNS is one query.** `dns_wildcard_check` resolves a random label
under an in-scope domain and reads the answer. The MongoDB, memcached and
NTPD audits read configuration files.
- **WebDAV is one OPTIONS and one PROPFIND.** `webdav_probe` sends a
read-only `Depth: 0` property request and never writes a resource;
rsync/dhcpd/krb5 audits read configuration files.
- **ALPN is one handshake per protocol.** `alpn_probe` never sends
application data; squid/unbound/CUPS audits read configuration files.
- **OCSP is read from one handshake.** `tls_ocsp_probe` opens one TLS
connection with `openssl s_client -status` and reads the stapled response;
it does not contact the OCSP responder itself.
- **STARTTLS is a handshake, not a login.** `smtp_starttls_probe` sends EHLO,
STARTTLS and reads the TLS handshake; it never authenticates and never sends
mail. PHP, Dovecot and OpenVPN audits read configuration files.
- **DNSSEC checks are two DNS queries.** `dnssec_check` asks for DNSKEY and
DS records of an in-scope domain and decodes the public key size; it never
validates a chain or contacts a registrar.
- **Daemon configs are audited read-only.** `postfix_audit`, `nginx_audit`
and `redis_config_audit` parse their configuration files and never signal,
reload or talk to the daemon. Redis passwords are reported as present or
absent, never echoed.
- **Config audits are local reads.** `snmpd_audit` and `rsyslog_audit` parse
configuration files; `winrm_probe` issues one unauthenticated GET to /wsman.
- **Exports and Samba checks are local reads.** `nfs_exports_audit` and
`samba_audit` parse configuration files; `kerberos_discovery` only queries
DNS SRV records for an in-scope domain.
- **Protocol and key checks stay read-only.** `http2_probe` performs one ALPN
handshake or one h2c preface; `ssh_hostkey_fingerprint` runs ssh-keyscan or
parses a saved output; `logrotate_audit` reads config files.
- **Metadata fetches are plain GETs.** `oidc_discovery` and `security_txt`
request their well-known paths without credentials; `ssh_known_hosts_audit`
reads local key files.
- **NTP and DNS version checks are single queries.** `ntp_monlist_probe` sends
one mode-7 GETLIST and reports the reply size; `dns_version_bind` sends two
CHAOS TXT queries; `usb_audit` reads sysfs.
- **Header-injection probes do not persist anything.** `crlf_probe` sends one
encoded CRLF in a parameter and reads the response; `esp_image_verify` and
`audit_rules` are offline file reads.
- **Relay checks never send mail.** `smtp_open_relay` stops after RCPT and
never issues DATA; `dns_open_resolver` sends one recursive query;
`apparmor_audit` and `selinux_audit` read kernel/config state only.
- **SMB share probing stops at TREE_CONNECT.** `smb_shares` tries a fixed list
of share names over the anonymous session and reports status codes; it never
lists a directory or reads a file. `email_security_audit` only queries DNS
TXT/MX records for an in-scope domain.
- **SMB stays at the session and IPC$.** `smb_null_session` negotiates SMB
2.1, tries an anonymous session setup and only connects to IPC$; it does not
enumerate shares or read files. `tls_cipher_matrix` performs one handshake
per cipher; `docker_audit` reads files and never calls the daemon.
- **API and cache probes are unauthenticated GETs.** `api_auth_audit` requests
a caller-supplied endpoint list without credentials, `cache_audit` fetches a
path twice, and `log_timeline` merges two local logs (restricted paths).
- **RPC and NTP are single queries.** `rpc_probe` sends one portmapper DUMP and
`ntp_probe` one client packet; neither mounts an export, changes a clock or
requests a monlist. `ssh_config_audit` and `pam_audit` read config files.
- **Form and local audits are reads.** `csrf_audit` fetches one page and parses
its forms; `kernel_hardening`, `sudoers_audit` and `auditd_audit` read local
files, with the audit log restricted to /var/log and the state directory.
- **Directory and walk probes are bounded reads.** `snmp_walk` issues at most
30 GETNEXT requests for the system group; `ldap_search` binds anonymously and
stops after 20 entries; `openapi_discovery` fetches six documents;
`systemd_audit` reads unit files. None writes or authenticates with a
credential.
- **Method and protocol probes stay read-only.** `http_methods` sends OPTIONS
and TRACE but never PUT/DELETE; `websocket_probe` performs the handshake and
sends no frame; `ike_probe` sends one SA_INIT with no credentials or PSK;
`firewall_audit` reads the local ruleset.
- **Firmware analysis reads local files only.** `esp_partition_table`,
`esp_nvs_parse` and `firmware_scan` open a dump the operator supplies, cap it
at 8/16/32 MiB and never touch a device. `mount_audit` reads a mount table
(the live one or a saved copy).
- **Mail and telephony probes stop at the greeting.** `pop3_probe` reads the
banner and CAPA and quits; `sip_probe` sends one OPTIONS and reads the answer;
`telnet_probe` sends nothing at all. `package_integrity` verifies installed
files locally with the package manager and never uses the network.
- **Container, search and IMAP probes issue reads only.** `docker_api_probe`
asks `/version` and `/containers/json`; `elasticsearch_probe` asks `/`,
cluster health and the index list; `imap_probe` reads CAPABILITY and logs
out. None authenticates, starts a container, runs a query against user data
or logs into a mailbox.
- **VNC and MQTT stop at the handshake.** `vnc_probe` reads the offered
security types and never authenticates; `mqtt_probe` sends one CONNECT with
no credentials, reads CONNACK and disconnects. `graphql_probe` sends only an
introspection query, and `cap_baseline` only reads the capability xattr.
- **RDP and SMB speak only the negotiation.** `rdp_probe` sends one X.224
request and reads the selected protocol; `smb_probe` sends one SMB2
NEGOTIATE and reads the dialect and signing flags. Neither creates a
session, authenticates or touches a share.
- **SSTI and XXE probes prove evaluation, then stop.** `ssti_probe` sends
arithmetic expressions and only looks for their result; `xxe_probe` points
the external entity at its own loopback listener and never at a file or a
third party. `ldap_probe` sends an anonymous bind and a rootDSE read, not
credentials. `ssh_key_audit` only reads key files the operator can read.
- **Web input probes send markers, not exploits.** `param_fuzz` injects a
unique marker, a single quote and `{{1337*7}}`, then looks for reflection and
error signatures; `open_redirect` sends a URL on example.com; `host_header_-
injection` sends a `.invalid` canary. None extracts data or executes code.
- **Database probes read one greeting, never a password.** `mysql_probe`
reads the initial handshake, `postgres_probe` sends one StartupMessage with
no password and reports the auth method, `mongo_probe` sends `isMaster` and
`memcached_probe` sends `stats`. None of them writes, guesses or replays a
credential; a trust/SCRAM offer is reported, not logged into.
- **TLS, Redis, SNMP and AXFR stay read-only.** `tls_audit` performs TLS
handshakes and reads the certificate; `redis_probe` sends PING, INFO and
DBSIZE only; `snmp_probe` sends a GET for sysDescr.0; `dns_zone_transfer`
asks one nameserver for one in-scope zone. No writes, no password guessing,
no payloads.
- **Service probes are handshakes, not attacks.** `ftp_probe` tries only the
literal anonymous FTP pair, `smtp_probe` sends EHLO and at most 8 VRFY
commands, and `ssh_audit` reads one KEXINIT and never authenticates. Each
opens one connection to an in-scope host; nothing is brute-forced and nothing
is written on the service.
- **Offline analysis stays offline.** `jwt_audit` and `hash_id` parse a value
the operator supplies; the JWT signature check is local HMAC-SHA256 and no
hash is cracked. `process_snapshot` only reads `/proc`.
- **Local reads.** `hardening_audit` and `ioc_scan` read files the operator can
already read; `log_audit` only accepts paths under `/var/log/` or the state
directory. None of them change anything.
- **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.
- **The consequences of an exploit module.** `exploit_run` carries whatever the
operator supplies — a command, a script, a file name, a console handle, a
config value — and reports what came back. What is run, what is written and
what a confirmed hit means is the operator's decision and the operator's
responsibility. The gate decides reachability, not appropriateness.
- **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).
- **PAM restriction and firewalld audits read local files.**
`pam_restrict_audit` parses `/etc/security/group.conf` and `time.conf`,
`pwhistory_audit` parses `pwhistory.conf` and `sepermit.conf`, and
`firewalld_audit` reads `/etc/firewalld` including the zone XML; none of them
changes a rule, reloads a daemon or contacts firewalld's D-Bus. The Cassandra
probe opens one CQL connection, sends OPTIONS and STARTUP and never a query.
- **Denial of service from a local client.** The proxy and the HTTP face fork a
child per connection and cap them (`APEX_PROXY_MAX_CHILDREN` and
`APEX_HTTP_MAX_CHILDREN`, default 64 each, max 1024); beyond that they answer
503 and audit. The HTTP face also enforces a head/body deadline
(`APEX_HTTP_HEAD_TIMEOUT_MS`, default 20 s) so half a request cannot hold a
child forever. `evidence_save` is capped by `APEX_EVIDENCE_MAX_BYTES` (default
16 MiB) so one call cannot fill the disk; the cap is audited when it refuses. Per-stage timeouts bound each request,
but there is no authentication, so a local client can still consume the
allowed slots.
- **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 a multi-user service or an agent loop, and it does not decide
for the operator what is worth doing. A feature that widens the scope without
an operator edit is out of scope by design; the scope gate is a technical
boundary, not a judgement.
Licence: CNCL 1.1 - Could Not Care Less License; see LICENSE.