lotherk d7bc372208 apex-twin 0.1.0: C99/POSIX offensive-security MCP server
Scope gate is the product: deny-by-default, deny beats allow, DNS answers
must stay inside allow_ip, port and radio-transmission are separate switches.
27 tools over libmcp: recon (in-process portscan, nmap, dns, tls, banner),
web (http_request, header audit, path discovery, sqli/xss leads), ESP32
Marauder serial bridge, findings with evidence, and 12 method playbooks.

56 end-to-end checks, seen red with the no-scope branch disabled.
Not yet wired into systemd or a fleet router.
2026-11-20 21:59:09 +00:00

APEX TWIN

An offensive-security MCP server in C99 + POSIX. One static binary, libc only, no Python in the serving path. It gives an agent real reconnaissance and real web testing behind a scope gate that refuses everything until a rules-of-engagement file says otherwise.

Derived from ARTEX's ideas (scope gates, findings with evidence, budgets) but written from nothing in C, with the fleet's libmcp transport and the ESP32 Marauder serial CLI folded in.

What it is not: an exploit framework. There is no payload that reads a database, no shell, no post-exploitation. Every tool either observes (scan, fetch, capture) or proves (headers, certificate, reflected payload). Transmission is a separate, explicitly armed switch.

Build

make            # apex-twin, 136 kB static-ish binary, zero warnings under -Werror
make test       # 56 end-to-end checks, no mocks
make install    # /usr/local/bin/apex-twin

Flags are fixed: -std=c99 -Wall -Wextra -Wpedantic -Werror plus -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE.

The gate is the product

Every tool that can touch something calls apex_scope_check() before it opens a socket or spawns a process, and appends the decision to audit.log before the action. The rules, in the order they are applied:

# Rule Result
1 no scope file deny everything
2 scope expired deny everything
3 target in deny_ip deny (deny beats allow)
4 port not in allow_port deny (empty list = all ports)
5 target in neither allow_ip nor allow_domain deny
6 private/loopback/link-local and allow_private is false deny
7 a name that resolves partly outside allow_ip deny

Rule 7 exists because of DNS rebinding: an allow-listed name that resolves to an internal address would otherwise be a way in. Every address a name returns must be inside the scope, and an unresolvable name is refused rather than waved through.

Radio transmission is gated a second time: serial_tx must be true and the command must be on the allowlist. A receiver is a scanner; a transmitter is an attack.

Scope file

$APEX_HOME/scope.json, default ~/.local/state/apex-twin/scope.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"]
}

"*.acme.example" matches subdomains only; "acme.example" matches the apex and below. expires accepts YYYY-MM-DD or full ISO-8601.

No scope file means no engagement. That is deliberate: a default that scans something is a liability, not a convenience.

Tools (27)

Scope and bookkeeping — scope_show, scope_reload, capabilities, audit_log, evidence_save

Network recon — portscan (in-process TCP connect, no nmap needed), nmap (profiles quick/default/full/udp/vuln/http), dns (dig), tls_cert (openssl), banner, http_head

Web — http_request (any method, body, headers), http_headers (HSTS/CSP/ frame/nosniff/referrer/permissions audit), http_paths (built-in wordlist: .git, .env, actuator, swagger, backups), sqli_probe (quote + boolean pair, reports differing answers as a lead), xss_probe (marked payload, returns the reflection context), curl

Radio — marauder_info, marauder_commands, marauder_cmd, marauder_scan

Method — method_techniques, method_playbook, method_tool

Findings — finding_add, finding_list, finding_read

Method is not decoration. method_playbook returns the ordered steps for a technique, the check that turns a lead into a finding, and the mistake that wastes an engagement — 12 techniques across recon, enum, web, creds, AD, wifi and report, plus a note per tool on what people get wrong with it.

Transport

apex-twin                 # MCP over stdin/stdout (one JSON-RPC line each way)
apex-twin --http 8797     # MCP over HTTP on 127.0.0.1:8797, POST /mcp
apex-twin --check         # scope, tool count and state dir as JSON, then exit

HTTP binds loopback only. A service that can scan and transmit must not appear on a LAN by accident; reach it through a tunnel.

The radio

The Marauder bridge speaks the firmware CLI at 115200 baud, and it refuses to talk to something that is not a radio. Before the first command it sends a bare CRLF: a console answers that with its login prompt, a Marauder either stays quiet or prints a prompt of its own. On this machine /dev/ttyACM0 is an Espressif USB JTAG unit running a Mikronix console, and typing scanall into it produced login: scanall: no such user and then 3 incorrect attempts, giving up. The guard now refuses it by name instead.

Scans always end with stopscan, so the next command meets a clean device.

APEX_SERIAL=/dev/ttyACM0  APEX_BAUD=115200

Environment

Variable Default Meaning
APEX_HOME ~/.local/state/apex-twin state dir (0700)
APEX_SCOPE $APEX_HOME/scope.json scope file
APEX_SERIAL /dev/ttyACM0 Marauder tty
APEX_BAUD 115200 serial baud
APEX_DRY_RUN unset 1 prints commands, runs none
APEX_DEFAULT_TIMEOUT_MS 60000 per-tool default
APEX_MAX_TIMEOUT_MS 900000 hard cap

Files it writes

$APEX_HOME/
  scope.json                 the rules of engagement
  audit.log                  one JSON line per decision, append-only
  findings/f0001.json        one finding per file
  evidence/<ts>-<label>.bin  raw proof, 0600

The audit line is written before the action, so a process that dies mid-scan still left its intent on disk.

Tests

make test

56 checks, real binary, real DNS, real files written; no mocks. The suite was seen red on purpose: with the "no scope" branch disabled by if (0 && ...), three checks fail, because they assert the reason and not merely that an error came back — a gate that falls through to the next deny branch looks identical from isError alone.

A port is never assumed: an earlier version of the HTTP test used 18797, which on this host is an SSH forward to another machine, and a foreign server answered {"serverInfo":{"name":"koder"}} while the suite was green.

Status

0.1.0. Built and run. Not yet wired into a systemd unit or a fleet router.

Licence: AGPL-3.0, same as ARTEX.

S
Description
Scope-gated offensive-security MCP server in C99/POSIX
Readme
33 MiB
0 Stars 3 Watchers 0 Forks
Languages
C 68.5%
Python 31.3%
Makefile 0.2%