apex-twin 0.18.0: a PTY Marauder for positive radio tests
tests/run.py now carries a simulator on a pty pair, addressed through APEX_SERIAL, so the radio paths are tested without hardware: - answers the guard's bare CRLF with a benign prompt (no console marker); - info -> firmware/board, help -> command list, list -> APs, scanall -> APs, stopscan -> stopped, attack -> started; - records every command in order. Tests: marauder_info reads firmware and help; marauder_commands works with a device; marauder_cmd sends list; marauder_scan returns APs and the command log proves scanall is followed by stopscan; a console simulator that answers the blank line with 'login: ' is still refused; serial_tx=true lets 'attack' through and the radio sees it. Coverage: tools_radio.c 31.7% -> 76.2%, total 74.1% -> 76.4%. Red proof: removing 'login:' from the deny list and skipping the stopscan send turned three checks red (login refusal twice, stopscan order once). 287 checks.
This commit is contained in:
1 parent
a00bcdb90c
commit
e1e46704ea
3 files changed
+157
-13
No files matched your search
@@ -18,7 +18,7 @@ separate, explicitly armed switch.
|
||||
|
||||
```sh
|
||||
make # apex-twin, ~239 kB static-ish binary, zero warnings under -Werror
|
||||
make test # 276 end-to-end checks, no mocks
|
||||
make test # 287 end-to-end checks, no mocks
|
||||
make asan # apex-twin-asan with ASan + UBSan
|
||||
make test-asan # the whole suite against the sanitizer binary
|
||||
make analyze # gcc -fanalyzer over every translation unit
|
||||
@@ -338,7 +338,7 @@ finding and the next report no longer mentions it.
|
||||
make test
|
||||
```
|
||||
|
||||
276 checks, real binary, real DNS, real files written; no mocks. The suite was
|
||||
287 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
|
||||
@@ -369,7 +369,7 @@ this host is an SSH forward to another machine, and a foreign server answered
|
||||
`{"serverInfo":{"name":"koder"}}` while the suite was green.
|
||||
|
||||
The suite is also run against `apex-twin-asan` (`make test-asan`), built with
|
||||
`-fsanitize=address,undefined`. All 276 checks pass with no ASan or UBSan report,
|
||||
`-fsanitize=address,undefined`. All 287 checks pass with no ASan or UBSan report,
|
||||
and a separate batch of error paths, network captures and report generation was
|
||||
run with leak detection on: no leaks. `make analyze` runs `gcc -fanalyzer` over
|
||||
every translation unit; it was red first on `vendor/libmcp/mcp.h`, where
|
||||
@@ -409,16 +409,19 @@ head) is rejected 2/2 with the exact `apex-twin.c` UBSan line.
|
||||
|
||||
`make coverage` builds `apex-twin-cov` with `-O0 --coverage`, runs the suite and
|
||||
prints per-file line coverage (`tests/coverage.py`, gcov only, no extra tools).
|
||||
The first measured pass was 55.9%; the gap tests brought it to **74.1%** —
|
||||
The first measured pass was 55.9%; the gap tests brought it to **76.4%** —
|
||||
`tools_kb.c` 100%, `tools_traffic.c` 81.8%, `tools_web.c` 71.6%,
|
||||
`tools_recon.c` 68.0%. `tools_radio.c` stays lowest (31.7%) because the radio
|
||||
paths need the hardware; that is a limit of the host, not a missing test. The
|
||||
`tools_recon.c` 68.0%. A PTY-based Marauder simulator then raised
|
||||
`tools_radio.c` from 31.7% to 76.2% without hardware: firmware `info`/`help`,
|
||||
`list`, a `scanall` that ends in `stopscan`, a login-prompt refusal and a
|
||||
`serial_tx=true` transmit are all tested. The lowest files now are `proc.c`
|
||||
(fork/exec error paths) and `tools_recon.c` (external binaries). The
|
||||
`-O0` build also proved a truncation warning in `guard.c` that `-O2` had not:
|
||||
the copied scope reason is now bounded with a precision, not left to snprintf.
|
||||
|
||||
## Status
|
||||
|
||||
0.17.0. Built and run: 45 tools, 276 checks, 340 fuzz cases and 74.1% line
|
||||
0.18.0. Built and run: 45 tools, 287 checks, 340 fuzz cases and 76.4% 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
|
||||
@@ -427,10 +430,12 @@ CSV file, and `evidence_read`/`traffic_read` get the proof back. `--proxy` puts
|
||||
the same gate in front of curl and a browser, forwards chunked and
|
||||
Content-Length bodies, and takes rewrite rules that can set or remove a header
|
||||
or block a path; `APEX_WEBHOOK` wakes someone when the severity floor is
|
||||
crossed. `make install` ships the binary, this README and both units; `--check`
|
||||
reports the operational state without starting a server. The whole suite also
|
||||
runs under ASan/UBSan, `make analyze` is clean, all three fuzzers reject a
|
||||
deliberately broken build, and `make coverage` keeps the gaps visible. Not yet
|
||||
wired into a fleet router.
|
||||
crossed. The radio is tested against a PTY Marauder (firmware info, scans that
|
||||
end in `stopscan`, a login prompt that is refused, `serial_tx` gating).
|
||||
`make install` ships the binary, this README and both units; `--check` reports
|
||||
the operational state without starting a server. The whole suite also runs under
|
||||
ASan/UBSan, `make analyze` is clean, all three fuzzers reject a deliberately
|
||||
broken build, and `make coverage` keeps the gaps visible. Not yet wired into a
|
||||
fleet router.
|
||||
|
||||
Licence: AGPL-3.0, same as ARTEX.
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "0.17.0"
|
||||
#define APEX_VERSION "0.18.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
+139
@@ -10,6 +10,8 @@ import base64
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import pty
|
||||
import select
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
@@ -944,6 +946,143 @@ res, _ = run([
|
||||
check("marauder_cmd fails loudly without a radio", err(res[0]), text(res[0]))
|
||||
check("marauder_scan fails loudly without a radio", err(res[1]), text(res[1]))
|
||||
|
||||
print("\n== marauder on a pty ==")
|
||||
|
||||
|
||||
class MarauderSim:
|
||||
"""A PTY that answers like a Marauder CLI and records what it was sent."""
|
||||
|
||||
def __init__(self, console=False):
|
||||
self.master, self.slave = pty.openpty()
|
||||
self.path = os.ttyname(self.slave)
|
||||
self.console = console
|
||||
self.commands = []
|
||||
self.buf = b""
|
||||
self.lock = threading.Lock()
|
||||
self.stop = False
|
||||
self.thread = threading.Thread(target=self._run, daemon=True)
|
||||
self.thread.start()
|
||||
|
||||
def _send(self, text):
|
||||
try:
|
||||
os.write(self.master, text.encode())
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def _handle(self, cmd):
|
||||
with self.lock:
|
||||
self.commands.append(cmd)
|
||||
if self.console and cmd == "":
|
||||
self._send("login: ")
|
||||
return
|
||||
if cmd == "":
|
||||
self._send("Marauder>\r\n")
|
||||
elif cmd == "info":
|
||||
self._send("Marauder v1.0 (ESP32)\r\nBoard: ESP32-DEVKIT\r\n")
|
||||
elif cmd == "help":
|
||||
self._send("scanall sniffbeacon recon stopscan list\r\n")
|
||||
elif cmd == "list":
|
||||
self._send("1: TestAP -40\r\n2: Other -55\r\n")
|
||||
elif cmd in ("scanall", "sniffbeacon", "recon"):
|
||||
self._send("1: TestAP -40\r\n2: Other -55\r\n")
|
||||
elif cmd == "stopscan":
|
||||
self._send("stopped\r\n")
|
||||
elif cmd.startswith("attack"):
|
||||
self._send("attack started\r\n")
|
||||
else:
|
||||
self._send("ok\r\n")
|
||||
|
||||
def _run(self):
|
||||
while not self.stop:
|
||||
try:
|
||||
ready, _, _ = select.select([self.master], [], [], 0.2)
|
||||
except OSError:
|
||||
break
|
||||
if not ready:
|
||||
continue
|
||||
try:
|
||||
data = os.read(self.master, 4096)
|
||||
except OSError:
|
||||
break
|
||||
if not data:
|
||||
break
|
||||
self.buf += data
|
||||
while b"\n" in self.buf:
|
||||
line, self.buf = self.buf.split(b"\n", 1)
|
||||
self._handle(line.strip(b"\r").decode("utf-8", "replace").strip())
|
||||
|
||||
def close(self):
|
||||
self.stop = True
|
||||
time.sleep(0.1)
|
||||
for fd in (self.master, self.slave):
|
||||
try:
|
||||
os.close(fd)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
sim = MarauderSim()
|
||||
radio_home = tempfile.mkdtemp(prefix="apex-radio-")
|
||||
write_scope(radio_home, {"label": "radio", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"serial_tx": False})
|
||||
res, _ = run([
|
||||
call(1, "marauder_info"),
|
||||
call(2, "marauder_commands"),
|
||||
call(3, "marauder_cmd", command="list"),
|
||||
call(4, "marauder_scan", command="scanall", seconds=3),
|
||||
], home=radio_home, extra_env={"APEX_SERIAL": sim.path})
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
info = json.loads(text(by_id[1]))
|
||||
check("marauder_info opens the pty and reads the firmware",
|
||||
info["port"] == sim.path and "Marauder v1.0" in info["info"], info)
|
||||
check("marauder_info reads the help text",
|
||||
"scanall" in info["help"], info)
|
||||
radio = json.loads(text(by_id[2]))
|
||||
check("marauder_commands works with a device present",
|
||||
len(radio["commands"]) > 10, radio)
|
||||
cmd = text(by_id[3])
|
||||
check("marauder_cmd sends an allowlisted command", "TestAP" in cmd, cmd)
|
||||
scan = text(by_id[4])
|
||||
check("marauder_scan returns the scan output",
|
||||
"TestAP" in scan and "then stopscan" in scan, scan)
|
||||
with sim.lock:
|
||||
order = list(sim.commands)
|
||||
check("a scan always ends with stopscan",
|
||||
"scanall" in order and "stopscan" in order and
|
||||
order.index("scanall") < order.index("stopscan"), order)
|
||||
check("the simulator saw info and help", "info" in order and "help" in order,
|
||||
order)
|
||||
sim.close()
|
||||
shutil.rmtree(radio_home, ignore_errors=True)
|
||||
|
||||
console = MarauderSim(console=True)
|
||||
console_home = tempfile.mkdtemp(prefix="apex-console-")
|
||||
write_scope(console_home, {"label": "console", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"]})
|
||||
res, _ = run([call(1, "marauder_info")], home=console_home,
|
||||
extra_env={"APEX_SERIAL": console.path})
|
||||
check("a console login prompt is still refused", err(res[0]), text(res[0]))
|
||||
check("the refusal names the login prompt", "login:" in text(res[0]),
|
||||
text(res[0])[:200])
|
||||
console.close()
|
||||
shutil.rmtree(console_home, ignore_errors=True)
|
||||
|
||||
tx_sim = MarauderSim()
|
||||
tx_home = tempfile.mkdtemp(prefix="apex-tx-")
|
||||
write_scope(tx_home, {"label": "tx", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"serial_tx": True})
|
||||
res, _ = run([call(1, "marauder_cmd", command="attack")], home=tx_home,
|
||||
extra_env={"APEX_SERIAL": tx_sim.path})
|
||||
check("serial_tx=true allows a transmitting command",
|
||||
not err(res[0]) and "attack started" in text(res[0]), text(res[0])[:160])
|
||||
with tx_sim.lock:
|
||||
sent = list(tx_sim.commands)
|
||||
check("the transmitting command reached the radio", "attack" in sent, sent)
|
||||
tx_sim.close()
|
||||
shutil.rmtree(tx_home, ignore_errors=True)
|
||||
|
||||
print("\n== dry run and dns ==")
|
||||
res, _ = run([
|
||||
call(1, "nmap", target="192.0.2.5", profile="quick"),
|
||||
|
||||
Reference in new issue
Block a user