apex-twin 1.24.0: NTP monlist, DNS version disclosure, USB audit
Red: - ntp_monlist_probe: 8-byte mode-7 MON_GETLIST; a mode-7 reply larger than the request means monlist is enabled, with entry estimate ((len-8)/72) and the amplification factor. One request. - dns_version_bind: gated dig for CHAOS TXT version.bind and hostname.bind; any answer is a version/hostname disclosure. Blue: - usb_audit: /sys/bus/usb/devices (root prefix): vendor/product IDs, manufacturer, product, serial and bInterfaceClass 08 (mass storage); storage devices are flagged, nothing is opened or mounted. Tests: mode-7 agent (active and silent), CHAOS TXT agent and USB sysfs tree. 737 checks, ASan suite green, analyze clean, release-check green including distcheck 1.24.0.
This commit is contained in:
1 parent
260fe8cac6
commit
2afb34eb89
10 files changed
+594
-15
No files matched your search
+16
-1
@@ -8,7 +8,22 @@ fields, and state from an older version is read by a newer one.
|
||||
There are no git tags. The hash next to a version is the commit that introduced
|
||||
it; the current entry is the commit that adds this section.
|
||||
|
||||
## 1.23.0 — 2026-11-21 — this change
|
||||
## 1.24.0 — 2026-11-21 — this change
|
||||
|
||||
- **NTP monlist** (`ntp_monlist_probe`): sends the 8-byte mode-7 MON_GETLIST
|
||||
request and reports a mode-7 reply larger than the request as monlist
|
||||
enabled, with an entry estimate ((len-8)/72) and the amplification factor.
|
||||
One request, no follow-up.
|
||||
- **DNS version** (`dns_version_bind`): gated dig for CHAOS TXT version.bind
|
||||
and hostname.bind; any answer is a version/hostname disclosure.
|
||||
- **Blue** (`usb_audit`): reads /sys/bus/usb/devices (root prefix): vendor and
|
||||
product IDs, manufacturer, product, serial, and whether any interface reports
|
||||
bInterfaceClass 08 (mass storage). Storage devices are flagged; nothing is
|
||||
opened or mounted.
|
||||
- Tests with a mode-7 agent (active and silent), a CHAOS TXT agent and a USB
|
||||
sysfs tree. 737 checks. Coverage 80.6%.
|
||||
|
||||
## 1.23.0 — 2026-11-21 — 260fe8c
|
||||
|
||||
- **ESP image** (`esp_image_verify`): walks the segment table (load address,
|
||||
length), XORs the segment data against the stored checksum, aligns to 16
|
||||
|
||||
@@ -5,11 +5,11 @@ no Python in the serving path. It gives an agent real reconnaissance and real we
|
||||
testing behind a scope gate that refuses everything until a rules-of-engagement
|
||||
file says otherwise.
|
||||
|
||||
**137 tools · 728 end-to-end checks · 340 fuzz cases · 80.5% line coverage · ~581 KiB**
|
||||
**140 tools · 737 end-to-end checks · 340 fuzz cases · 80.6% line coverage · ~585 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.23.0","tools":137,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.24.0","tools":140,...,"scope":{"loaded":true,...}}
|
||||
```
|
||||
|
||||
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
|
||||
@@ -149,7 +149,7 @@ closes a request whose head or body does not arrive within
|
||||
|
||||
---
|
||||
|
||||
## Tools (137)
|
||||
## Tools (140)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -285,6 +285,8 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `smtp_open_relay` | EHLO/MAIL/RCPT for an external recipient; open relay detection, no DATA |
|
||||
| `dns_open_resolver` | One recursive query against an in-scope resolver; answer means open |
|
||||
| `crlf_probe` | Encoded CRLF in one parameter; detects an injected response header |
|
||||
| `dns_version_bind` | CHAOS TXT version.bind/hostname.bind; reports version disclosure |
|
||||
| `ntp_monlist_probe` | Mode-7 MON_GETLIST; monlist enabled, entry estimate, amplification |
|
||||
| `imap_probe` | Banner, CAPABILITY list, STARTTLS and LOGINDISABLED; no LOGIN |
|
||||
| `pop3_probe` | Banner, CAPA list, STLS flag; no USER/PASS |
|
||||
| `sip_probe` | One UDP OPTIONS: status line, Server header, Allow methods |
|
||||
@@ -334,6 +336,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `apparmor_audit` | Profile list: enforce/complain counts, complain profiles named |
|
||||
| `selinux_audit` | enforce, SELINUX=/SELINUXTYPE=, boolean count; disabled/permissive findings |
|
||||
| `audit_rules` | audit.rules/rules.d: rule count, -e 2, execve, watches on passwd/shadow/sudoers/group |
|
||||
| `usb_audit` | sysfs USB devices: IDs, strings, serial, mass-storage interface flagged |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -567,6 +570,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| ESP verify | local image only, 32 MiB cap |
|
||||
| CRLF probe | one request, marker header only |
|
||||
| Audit rules | 100 files, read-only |
|
||||
| NTP/DNS version | one or two queries, no state |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
|
||||
@@ -577,7 +582,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 728 end-to-end checks
|
||||
make test # version check + gate audit + 737 end-to-end checks
|
||||
make version-check # the five places that carry a version must agree
|
||||
make gate-audit # static: every target-taking tool calls the gate
|
||||
make asan # apex-twin-asan with ASan + UBSan
|
||||
@@ -690,7 +695,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
rpc_probe, ntp_probe, api_auth_audit, cache_audit,
|
||||
tls_cipher_matrix, smb_null_session, smb_shares,
|
||||
email_security_audit, smtp_open_relay, dns_open_resolver,
|
||||
crlf_probe
|
||||
crlf_probe, dns_version_bind
|
||||
src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
|
||||
detect_rules, integrity_baseline, mitre_map,
|
||||
process_snapshot, persistence_audit, net_baseline,
|
||||
@@ -733,7 +738,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.23.0. Built and run: 137 tools, 728 checks, 340 fuzz cases and 80.5% line
|
||||
1.24.0. Built and run: 140 tools, 737 checks, 340 fuzz cases and 80.6% 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
|
||||
@@ -774,7 +779,8 @@ timeline; 1.20 added a TLS cipher matrix, SMB null-session check and Docker
|
||||
audit; 1.21 added SMB share probing, e-mail security checks and a web-root
|
||||
audit; 1.22 added SMTP relay and DNS resolver checks plus AppArmor/SELinux
|
||||
audits; 1.23 added ESP image verification, CRLF injection and audit-rule
|
||||
checks, again without changing an existing file format.
|
||||
checks; 1.24 added NTP monlist and DNS version disclosure checks plus a USB
|
||||
audit, again without changing an existing file format.
|
||||
|
||||
Not yet wired into a fleet router, and there is no TLS interception.
|
||||
|
||||
|
||||
+4
-1
@@ -9,7 +9,7 @@ problem.
|
||||
|
||||
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.23.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.24.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.
|
||||
@@ -66,6 +66,9 @@ only narrow what the proxy does (the scope gate still runs first).
|
||||
- **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.
|
||||
- **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.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.23.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.24.0" "User Commands"
|
||||
.SH NAME
|
||||
apex-twin \- scope\-gated offensive\-security MCP server
|
||||
.SH SYNOPSIS
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.23.0"
|
||||
#define APEX_VERSION "1.24.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -5532,6 +5532,175 @@ static void t_audit_rules(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ usb_audit */
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char vendor[16];
|
||||
char product_id[16];
|
||||
char manufacturer[128];
|
||||
char product[128];
|
||||
char serial[64];
|
||||
int storage;
|
||||
} usb_dev;
|
||||
|
||||
static void usb_read_field(const char *dir, const char *field, char *out,
|
||||
size_t n)
|
||||
{
|
||||
char path[1024];
|
||||
|
||||
out[0] = '\0';
|
||||
snprintf(path, sizeof(path), "%.800s/%.100s", dir, field);
|
||||
if (read_text(path, out, n) > 0)
|
||||
trim_eol(out);
|
||||
}
|
||||
|
||||
static void t_usb_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
int limit = mcp_arg_int(args, "limit", 200);
|
||||
char base[512];
|
||||
char dir[1024];
|
||||
DIR *d;
|
||||
struct dirent *ent;
|
||||
usb_dev *devs;
|
||||
int ndev = 0;
|
||||
int storage = 0;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int findings_count = 0;
|
||||
int i;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) >= sizeof(base) - 2) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(base, sizeof(base), "%s", root);
|
||||
snprintf(dir, sizeof(dir), "%s/sys/bus/usb/devices", base);
|
||||
if (limit <= 0 || limit > 1000)
|
||||
limit = 200;
|
||||
devs = calloc((size_t)limit, sizeof(*devs));
|
||||
if (devs == NULL) {
|
||||
mcp_reply_error(c, "out of memory");
|
||||
return;
|
||||
}
|
||||
d = opendir(dir);
|
||||
if (d == NULL) {
|
||||
free(devs);
|
||||
mcp_reply_error(c, "cannot read the USB device tree");
|
||||
return;
|
||||
}
|
||||
while ((ent = readdir(d)) != NULL && ndev < limit) {
|
||||
char devdir[1024];
|
||||
char path[1024];
|
||||
char cls[16];
|
||||
usb_dev *u;
|
||||
|
||||
if (ent->d_name[0] == '.' || strchr(ent->d_name, ':') != NULL)
|
||||
continue;
|
||||
if (strlen(ent->d_name) + 2 > sizeof(devdir))
|
||||
continue;
|
||||
snprintf(devdir, sizeof(devdir), "%.800s/%.100s", dir,
|
||||
ent->d_name);
|
||||
snprintf(path, sizeof(path), "%.900s/idVendor", devdir);
|
||||
if (read_text(path, cls, sizeof(cls)) <= 0)
|
||||
continue;
|
||||
u = &devs[ndev];
|
||||
snprintf(u->name, sizeof(u->name), "%.48s", ent->d_name);
|
||||
usb_read_field(devdir, "idVendor", u->vendor,
|
||||
sizeof(u->vendor));
|
||||
usb_read_field(devdir, "idProduct", u->product_id,
|
||||
sizeof(u->product_id));
|
||||
usb_read_field(devdir, "manufacturer", u->manufacturer,
|
||||
sizeof(u->manufacturer));
|
||||
usb_read_field(devdir, "product", u->product, sizeof(u->product));
|
||||
usb_read_field(devdir, "serial", u->serial, sizeof(u->serial));
|
||||
u->storage = 0;
|
||||
{
|
||||
DIR *sub = opendir(dir);
|
||||
struct dirent *se;
|
||||
|
||||
if (sub != NULL) {
|
||||
while ((se = readdir(sub)) != NULL) {
|
||||
char ifdir[1024];
|
||||
char ifpath[1024];
|
||||
char ifcls[16];
|
||||
size_t nl = strlen(ent->d_name);
|
||||
|
||||
if (strncmp(se->d_name, ent->d_name, nl) != 0 ||
|
||||
se->d_name[nl] != ':')
|
||||
continue;
|
||||
snprintf(ifdir, sizeof(ifdir), "%.800s/%.100s",
|
||||
dir, se->d_name);
|
||||
snprintf(ifpath, sizeof(ifpath),
|
||||
"%.900s/bInterfaceClass", ifdir);
|
||||
if (read_text(ifpath, ifcls, sizeof(ifcls)) > 0) {
|
||||
trim_eol(ifcls);
|
||||
if (strcmp(ifcls, "08") == 0)
|
||||
u->storage = 1;
|
||||
}
|
||||
}
|
||||
closedir(sub);
|
||||
}
|
||||
}
|
||||
if (u->storage)
|
||||
storage++;
|
||||
ndev++;
|
||||
}
|
||||
closedir(d);
|
||||
mcp_buf_init(&findings);
|
||||
for (i = 0; i < ndev; i++) {
|
||||
if (!devs[i].storage)
|
||||
continue;
|
||||
if (!first)
|
||||
mcp_buf_puts(&findings, ",");
|
||||
first = 0;
|
||||
findings_count++;
|
||||
mcp_buf_puts(&findings, "{\"id\":\"usb-storage\",\"severity\":"
|
||||
"\"medium\",\"path\":");
|
||||
apex_json_str(&findings, devs[i].name);
|
||||
mcp_buf_puts(&findings, ",\"detail\":");
|
||||
apex_json_str(&findings, "USB mass-storage interface present");
|
||||
mcp_buf_puts(&findings, "}");
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, base);
|
||||
mcp_buf_printf(&b, ",\"devices\":%d,\"storage\":%d,\"entries\":[", ndev,
|
||||
storage);
|
||||
for (i = 0; i < ndev; i++) {
|
||||
if (i > 0)
|
||||
mcp_buf_puts(&b, ",");
|
||||
mcp_buf_puts(&b, "{\"name\":");
|
||||
apex_json_str(&b, devs[i].name);
|
||||
mcp_buf_puts(&b, ",\"vendor\":");
|
||||
apex_json_str(&b, devs[i].vendor);
|
||||
mcp_buf_puts(&b, ",\"product_id\":");
|
||||
apex_json_str(&b, devs[i].product_id);
|
||||
mcp_buf_puts(&b, ",\"manufacturer\":");
|
||||
apex_json_str(&b, devs[i].manufacturer);
|
||||
mcp_buf_puts(&b, ",\"product\":");
|
||||
apex_json_str(&b, devs[i].product);
|
||||
mcp_buf_puts(&b, ",\"serial\":");
|
||||
apex_json_str(&b, devs[i].serial);
|
||||
mcp_buf_printf(&b, ",\"storage\":%s}",
|
||||
devs[i].storage ? "true" : "false");
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"findings_count\":%d,\"findings\":[",
|
||||
findings_count);
|
||||
if (findings.p != NULL)
|
||||
mcp_buf_add(&b, findings.p, findings.len);
|
||||
mcp_buf_puts(&b, "]}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
mcp_buf_free(&findings);
|
||||
free(devs);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_BLUE[] = {
|
||||
{ "hardening_audit",
|
||||
"Read-only posture audit of the local host: sshd_config (root login, "
|
||||
@@ -5856,6 +6025,16 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_audit_rules },
|
||||
{ "usb_audit",
|
||||
"Read /sys/bus/usb/devices (root prefix supported): vendor/product IDs, "
|
||||
"manufacturer, product, serial and whether an interface reports class 08 "
|
||||
"(mass storage). Storage devices are flagged; no device is opened or "
|
||||
"mounted. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"},"
|
||||
"\"limit\":{\"type\":\"integer\",\"description\":\"devices, default "
|
||||
"200\"}}}",
|
||||
t_usb_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
@@ -4872,6 +4872,105 @@ static void t_smtp_open_relay(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- ntp_monlist_probe */
|
||||
|
||||
static void t_ntp_monlist_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 123);
|
||||
unsigned char req[8];
|
||||
unsigned char resp[8192];
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res = NULL;
|
||||
struct addrinfo *use = NULL;
|
||||
struct addrinfo *rp;
|
||||
char service[16];
|
||||
int fd = -1;
|
||||
int attempt;
|
||||
ssize_t r = 0;
|
||||
int got = 0;
|
||||
int monlist = 0;
|
||||
int entries = 0;
|
||||
unsigned long amplification = 0;
|
||||
mcp_buf b;
|
||||
|
||||
(void)user;
|
||||
if (target == NULL || *target == '\0') {
|
||||
mcp_reply_error(c, "target is required");
|
||||
return;
|
||||
}
|
||||
if (port <= 0 || port > 65535) {
|
||||
mcp_reply_error(c, "port out of range");
|
||||
return;
|
||||
}
|
||||
if (!gated(c, "ntp_monlist_probe", target, port))
|
||||
return;
|
||||
memset(req, 0, sizeof(req));
|
||||
req[0] = 0x17; /* mode 7, version 2 */
|
||||
req[2] = 0x03;
|
||||
req[3] = 0x2a; /* MON_GETLIST_1 */
|
||||
snprintf(service, sizeof(service), "%d", port);
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
if (getaddrinfo(target, service, &hints, &res) != 0) {
|
||||
mcp_reply_error(c, "cannot resolve the target");
|
||||
return;
|
||||
}
|
||||
for (rp = res; rp != NULL; rp = rp->ai_next) {
|
||||
fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||
if (fd >= 0) {
|
||||
use = rp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (use == NULL) {
|
||||
freeaddrinfo(res);
|
||||
mcp_reply_error(c, "cannot open a UDP socket");
|
||||
return;
|
||||
}
|
||||
for (attempt = 0; attempt < 2 && !got; attempt++) {
|
||||
struct pollfd pfd;
|
||||
|
||||
if (sendto(fd, req, sizeof(req), 0, use->ai_addr,
|
||||
use->ai_addrlen) < 0)
|
||||
break;
|
||||
pfd.fd = fd;
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
if (poll(&pfd, 1, 2000) <= 0)
|
||||
continue;
|
||||
r = recv(fd, resp, sizeof(resp), 0);
|
||||
if (r > 0)
|
||||
got = 1;
|
||||
}
|
||||
close(fd);
|
||||
freeaddrinfo(res);
|
||||
if (!got) {
|
||||
mcp_reply_error(c, "no NTP mode 7 response");
|
||||
return;
|
||||
}
|
||||
if ((resp[0] & 0x07) == 7 && r > 8) {
|
||||
monlist = 1;
|
||||
if (r > 8)
|
||||
entries = (int)((r - 8) / 72);
|
||||
amplification = (unsigned long)r / 8UL;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"target\":");
|
||||
apex_json_str(&b, target);
|
||||
mcp_buf_printf(&b, ",\"port\":%d,\"responded\":true,\"mode\":%d,"
|
||||
"\"response_bytes\":%ld,\"monlist\":%s,\"entries\":%d,"
|
||||
"\"amplification\":%lu}", port, resp[0] & 0x07,
|
||||
(long)r, monlist ? "true" : "false", entries,
|
||||
amplification);
|
||||
apex_audit("ntp_monlist_probe", target, port, !monlist,
|
||||
monlist ? "NTP monlist answered (amplification)"
|
||||
: "NTP monlist not available", "mode 7");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_PROTO[] = {
|
||||
{ "ftp_probe",
|
||||
"One-connection FTP check: read the 220 banner, ask FEAT, then try the "
|
||||
@@ -5159,6 +5258,16 @@ const mcp_tool TOOLS_PROTO[] = {
|
||||
"postmaster@example.com\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_smtp_open_relay },
|
||||
{ "ntp_monlist_probe",
|
||||
"Send the NTP mode 7 MON_GETLIST request (8 bytes) and report whether the "
|
||||
"server answers: a mode 7 reply larger than 8 bytes means monlist is "
|
||||
"enabled and the host can be abused for amplification. Estimates the entry "
|
||||
"count and the amplification factor; no further requests. Gate: target.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 123\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_ntp_monlist_probe },
|
||||
};
|
||||
|
||||
const size_t TOOLS_PROTO_N = sizeof(TOOLS_PROTO) / sizeof(TOOLS_PROTO[0]);
|
||||
+111
-1
@@ -3881,7 +3881,7 @@ static void t_dns_open_resolver(mcp_conn *c, const mcp_json *args, void *user)
|
||||
char reason[512];
|
||||
char portstr[16];
|
||||
char at_server[300];
|
||||
char *argv[10];
|
||||
char *argv[12];
|
||||
int i = 0;
|
||||
apex_proc p;
|
||||
mcp_buf b;
|
||||
@@ -4068,6 +4068,107 @@ static void t_crlf_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
free(resp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- dns_version_bind */
|
||||
|
||||
static void t_dns_version_bind(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *names[] = { "version.bind", "hostname.bind", NULL };
|
||||
const char *server = mcp_arg_string(args, "server");
|
||||
int port = mcp_arg_int(args, "port", 53);
|
||||
char reason[512];
|
||||
char portstr[16];
|
||||
char at_server[300];
|
||||
char *argv[12];
|
||||
mcp_buf b;
|
||||
int first = 1;
|
||||
int disclosed = 0;
|
||||
int i;
|
||||
|
||||
(void)user;
|
||||
if (server == NULL || *server == '\0') {
|
||||
mcp_reply_error(c, "server is required");
|
||||
return;
|
||||
}
|
||||
if (port <= 0 || port > 65535) {
|
||||
mcp_reply_error(c, "port out of range");
|
||||
return;
|
||||
}
|
||||
if (!apex_scope_check(server, port, reason, sizeof(reason))) {
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_printf(&b, "REFUSED by scope gate: %s", reason);
|
||||
mcp_reply_error(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
return;
|
||||
}
|
||||
apex_audit("dns_version_bind", server, port, 1, "CHAOS TXT query",
|
||||
"version.bind");
|
||||
snprintf(portstr, sizeof(portstr), "%d", port);
|
||||
snprintf(at_server, sizeof(at_server), "@%.200s", server);
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"server\":");
|
||||
apex_json_str(&b, server);
|
||||
mcp_buf_printf(&b, ",\"port\":%d,\"queries\":[", port);
|
||||
for (i = 0; names[i] != NULL; i++) {
|
||||
apex_proc p;
|
||||
int k = 0;
|
||||
int count = 0;
|
||||
int query_disclosed = 0;
|
||||
|
||||
argv[k++] = "dig";
|
||||
argv[k++] = "+short";
|
||||
argv[k++] = "+time=3";
|
||||
argv[k++] = "+tries=1";
|
||||
argv[k++] = "-p";
|
||||
argv[k++] = portstr;
|
||||
argv[k++] = at_server;
|
||||
argv[k++] = (char *)names[i];
|
||||
argv[k++] = "CH";
|
||||
argv[k++] = "TXT";
|
||||
argv[k] = NULL;
|
||||
if (!first)
|
||||
mcp_buf_puts(&b, ",");
|
||||
first = 0;
|
||||
mcp_buf_puts(&b, "{\"name\":");
|
||||
apex_json_str(&b, names[i]);
|
||||
mcp_buf_puts(&b, ",\"answers\":[");
|
||||
if (apex_run(argv, 15000, 32 * 1024, &p) == 0) {
|
||||
if (p.out != NULL) {
|
||||
char *copy = strdup(p.out);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL && count < 5) {
|
||||
while (*line == ' ' || *line == '\t')
|
||||
line++;
|
||||
if (*line != '\0') {
|
||||
if (count > 0)
|
||||
mcp_buf_puts(&b, ",");
|
||||
apex_json_str(&b, line);
|
||||
count++;
|
||||
query_disclosed = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
apex_proc_free(&p);
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"disclosed\":%s}",
|
||||
query_disclosed ? "true" : "false");
|
||||
if (query_disclosed)
|
||||
disclosed = 1;
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"disclosed\":%s}", disclosed ? "true" : "false");
|
||||
apex_audit("dns_version_bind", server, port, !disclosed,
|
||||
disclosed ? "DNS server discloses version/hostname"
|
||||
: "no CHAOS TXT answer", "version.bind");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_RED[] = {
|
||||
{ "vuln_check",
|
||||
"Non-destructive verification of exposed artifacts on one web target: "
|
||||
@@ -4434,6 +4535,15 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\",\"param\"]}",
|
||||
t_crlf_probe },
|
||||
{ "dns_version_bind",
|
||||
"Query a DNS server for its CHAOS TXT version.bind and hostname.bind "
|
||||
"records with gated dig; an answer discloses the server software or host "
|
||||
"name. Two queries, gate on the server.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"server\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 53\"}},"
|
||||
"\"required\":[\"server\"]}",
|
||||
t_dns_version_bind },
|
||||
};
|
||||
|
||||
const size_t TOOLS_RED_N = sizeof(TOOLS_RED) / sizeof(TOOLS_RED[0]);
|
||||
+1
-1
@@ -21,7 +21,7 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 137
|
||||
EXPECTED_TOOLS = 140
|
||||
GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(")
|
||||
NET = ("http_once(", "tcp_connect_host(", "tcp_probe(", "apex_run(")
|
||||
# Tools whose "target" argument filters local records; they never touch it.
|
||||
|
||||
+159
-2
@@ -134,7 +134,7 @@ res, _ = run([
|
||||
], home=empty)
|
||||
check("tools/list answers", any(r.get("id") == 1 for r in res))
|
||||
tools = [r for r in res if r.get("id") == 1][0]["result"]["tools"]
|
||||
check("137 tools registered", len(tools) == 137, len(tools))
|
||||
check("140 tools registered", len(tools) == 140, len(tools))
|
||||
names = {t["name"] for t in tools}
|
||||
for need in ("portscan", "nmap", "http_request", "marauder_scan",
|
||||
"method_playbook", "finding_add", "finding_update", "scope_check",
|
||||
@@ -1560,7 +1560,7 @@ try:
|
||||
check("http initialize", init["result"]["serverInfo"]["name"] == "apex-twin",
|
||||
init)
|
||||
listing = post({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 137)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 140)
|
||||
shown = post(call(3, "scope_show"))
|
||||
check("http scope_show", '"loaded":true' in shown["result"]["content"][0]["text"])
|
||||
# the id must be the request's id, not one found inside the arguments
|
||||
@@ -6237,6 +6237,163 @@ shutil.rmtree(ar_root, ignore_errors=True)
|
||||
shutil.rmtree(ar_sparse, ignore_errors=True)
|
||||
shutil.rmtree(esp_home, ignore_errors=True)
|
||||
|
||||
print("\n== NTP monlist, DNS version and USB ==")
|
||||
|
||||
|
||||
def ntp_monlist_agent(active):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
sock.settimeout(0.2)
|
||||
port = sock.getsockname()[1]
|
||||
stop = threading.Event()
|
||||
|
||||
def loop():
|
||||
while not stop.is_set():
|
||||
try:
|
||||
data, addr = sock.recvfrom(512)
|
||||
except socket.timeout:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
if not active or len(data) < 4 or (data[0] & 7) != 7:
|
||||
continue
|
||||
resp = bytearray(8 + 2 * 72)
|
||||
resp[0] = 0x17
|
||||
resp[3] = 0x2a
|
||||
sock.sendto(bytes(resp), addr)
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return sock, port, stop
|
||||
|
||||
|
||||
def dns_chaos_agent():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
sock.settimeout(0.2)
|
||||
port = sock.getsockname()[1]
|
||||
stop = threading.Event()
|
||||
|
||||
def txt(value):
|
||||
raw = value.encode()
|
||||
return bytes([len(raw)]) + raw
|
||||
|
||||
def loop():
|
||||
while not stop.is_set():
|
||||
try:
|
||||
data, addr = sock.recvfrom(2048)
|
||||
except socket.timeout:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
if len(data) < 12:
|
||||
continue
|
||||
tid = data[:2]
|
||||
name, off = dns_name_decode(data, 12)
|
||||
if off + 4 > len(data):
|
||||
continue
|
||||
qtype, qclass = struct.unpack(">HH", data[off:off + 4])
|
||||
question = data[12:off + 4]
|
||||
answers = []
|
||||
if qtype == 16 and qclass == 3:
|
||||
if name == "version.bind":
|
||||
rdata = txt("BIND 9.18.1")
|
||||
elif name == "hostname.bind":
|
||||
rdata = txt("ns1.example.test")
|
||||
else:
|
||||
rdata = b""
|
||||
if rdata:
|
||||
answers.append(b"\xc0\x0c" +
|
||||
struct.pack(">HHIH", 16, 3, 0, len(rdata)) +
|
||||
rdata)
|
||||
resp = (tid + struct.pack(">HHHHH", 0x8400, 1, len(answers), 0, 0) +
|
||||
question + b"".join(answers))
|
||||
sock.sendto(resp, addr)
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return sock, port, stop
|
||||
|
||||
|
||||
mon_sock, mon_port, mon_stop = ntp_monlist_agent(True)
|
||||
mon_off_sock, mon_off_port, mon_off_stop = ntp_monlist_agent(False)
|
||||
chaos_sock, chaos_port, chaos_stop = dns_chaos_agent()
|
||||
|
||||
usb_root = tempfile.mkdtemp(prefix="apex-usb-")
|
||||
usb_dev = os.path.join(usb_root, "sys", "bus", "usb", "devices")
|
||||
os.makedirs(os.path.join(usb_dev, "1-1"))
|
||||
os.makedirs(os.path.join(usb_dev, "1-1:1.0"))
|
||||
os.makedirs(os.path.join(usb_dev, "1-2"))
|
||||
os.makedirs(os.path.join(usb_dev, "1-2:1.0"))
|
||||
with open(os.path.join(usb_dev, "1-1", "idVendor"), "w") as f:
|
||||
f.write("0781\n")
|
||||
with open(os.path.join(usb_dev, "1-1", "idProduct"), "w") as f:
|
||||
f.write("5567\n")
|
||||
with open(os.path.join(usb_dev, "1-1", "manufacturer"), "w") as f:
|
||||
f.write("SanDisk\n")
|
||||
with open(os.path.join(usb_dev, "1-1", "product"), "w") as f:
|
||||
f.write("Cruzer Blade\n")
|
||||
with open(os.path.join(usb_dev, "1-1", "serial"), "w") as f:
|
||||
f.write("4C530001\n")
|
||||
with open(os.path.join(usb_dev, "1-1:1.0", "bInterfaceClass"), "w") as f:
|
||||
f.write("08\n")
|
||||
with open(os.path.join(usb_dev, "1-2", "idVendor"), "w") as f:
|
||||
f.write("046d\n")
|
||||
with open(os.path.join(usb_dev, "1-2", "idProduct"), "w") as f:
|
||||
f.write("c31c\n")
|
||||
with open(os.path.join(usb_dev, "1-2:1.0", "bInterfaceClass"), "w") as f:
|
||||
f.write("03\n")
|
||||
|
||||
usb_home = tempfile.mkdtemp(prefix="apex-usb-home-")
|
||||
write_scope(usb_home, {"label": "usb", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": [str(mon_port), str(mon_off_port),
|
||||
str(chaos_port)]})
|
||||
res, _ = run([
|
||||
call(1, "ntp_monlist_probe", target="127.0.0.1", port=mon_port),
|
||||
call(2, "ntp_monlist_probe", target="127.0.0.1", port=mon_off_port),
|
||||
call(3, "dns_version_bind", server="127.0.0.1", port=chaos_port),
|
||||
call(4, "usb_audit", root=usb_root),
|
||||
call(5, "ntp_monlist_probe", target="198.51.100.9", port=123),
|
||||
call(6, "dns_version_bind", server="198.51.100.9", port=53),
|
||||
call(7, "usb_audit", root="/nonexistent-usb"),
|
||||
], home=usb_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
mon = json.loads(text(by_id[1]))
|
||||
check("ntp_monlist_probe detects monlist",
|
||||
mon["monlist"] is True and mon["entries"] == 2 and
|
||||
mon["amplification"] >= 10, mon)
|
||||
check("ntp_monlist_probe reports a quiet server", err(by_id[2]),
|
||||
text(by_id[2]))
|
||||
chaos = json.loads(text(by_id[3]))
|
||||
answers = chaos["queries"][0]["answers"]
|
||||
check("dns_version_bind reads the version",
|
||||
chaos["disclosed"] is True and
|
||||
any("BIND 9.18.1" in a for a in answers), chaos)
|
||||
check("dns_version_bind reads the hostname",
|
||||
chaos["queries"][1]["disclosed"] is True and
|
||||
any("ns1.example.test" in a for a in chaos["queries"][1]["answers"]),
|
||||
chaos["queries"][1])
|
||||
usb = json.loads(text(by_id[4]))
|
||||
check("usb_audit lists the devices and the storage flag",
|
||||
usb["devices"] == 2 and usb["storage"] == 1 and
|
||||
any(e["storage"] and e["vendor"] == "0781" for e in usb["entries"]),
|
||||
usb)
|
||||
check("usb_audit flags the mass-storage device",
|
||||
usb["findings_count"] == 1 and
|
||||
usb["findings"][0]["id"] == "usb-storage", usb["findings"])
|
||||
check("ntp_monlist_probe refuses an out-of-scope target", err(by_id[5]),
|
||||
text(by_id[5]))
|
||||
check("dns_version_bind refuses an out-of-scope server", err(by_id[6]),
|
||||
text(by_id[6]))
|
||||
check("usb_audit reports a missing tree", err(by_id[7]), text(by_id[7]))
|
||||
mon_stop.set()
|
||||
mon_sock.close()
|
||||
mon_off_stop.set()
|
||||
mon_off_sock.close()
|
||||
chaos_stop.set()
|
||||
chaos_sock.close()
|
||||
shutil.rmtree(usb_root, ignore_errors=True)
|
||||
shutil.rmtree(usb_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
|
||||
write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"})
|
||||
|
||||
Reference in new issue
Block a user