apex-twin 1.36.0: BIND, Tomcat and ProFTPD audits, CAA check

Blue:
- bind9_config_audit: named.conf plus .options/.local (root prefix):
  allow-query any, recursion yes without allow-recursion, allow-transfer any,
  a visible version and world-writable files.
- tomcat_audit: server.xml and tomcat-users.xml under /etc/tomcat*: an
  enabled shutdown port, a Connector on 0.0.0.0, manager/admin roles, a
  plaintext manager password and world-writable files.
- proftpd_audit: proftpd.conf: AllowAll, an Anonymous block without
  AnonReadOnly, RootLogin on, TLS not required and world-writable files.

Red:
- dns_caa_check: gated dig CAA; flags, tag and value per record, and whether
  issue/issuewild/iodef are present.

Tests with vulnerable and hardened BIND/Tomcat/ProFTPD trees and a DNS agent
serving CAA records. 880 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.36.0.
This commit is contained in:
lotherk committed 2026-11-21 21:45:28 +00:00
1 parent 3b1a88487a
commit b1165c5556
9 files changed
+850 -16

No files matched your search

+18 -1
View File
@@ -8,7 +8,24 @@ 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.35.0 — 2026-11-21 — this change
## 1.36.0 — 2026-11-21 — this change
- **BIND** (`bind9_config_audit`): named.conf plus .options/.local (root
prefix): allow-query any, recursion yes without allow-recursion,
allow-transfer any, a visible version and world-writable files.
- **Tomcat** (`tomcat_audit`): server.xml and tomcat-users.xml under
/etc/tomcat*: an enabled shutdown port, a Connector on 0.0.0.0,
manager-gui/manager-script/admin-gui roles, a plaintext manager password and
world-writable files.
- **ProFTPD** (`proftpd_audit`): proftpd.conf: AllowAll, an Anonymous block
without AnonReadOnly, RootLogin on, TLS not required and world-writable
files.
- **CAA** (`dns_caa_check`): gated dig CAA; reports flags, tag and value for
each record and whether issue/issuewild/iodef are present.
- Tests with vulnerable and hardened BIND/Tomcat/ProFTPD trees and a DNS
agent serving CAA records. 880 checks. Coverage 81.9%.
## 1.35.0 — 2026-11-21 — 3b1a884
- **MongoDB** (`mongodb_config_audit`): mongod.conf: net.bindIp on every
interface (absent counts as the default), security.authorization disabled or
+12 -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.
**179 tools · 867 end-to-end checks · 340 fuzz cases · 81.7% line coverage · ~701 KiB**
**183 tools · 880 end-to-end checks · 340 fuzz cases · 81.9% line coverage · ~717 KiB**
```
$ ./apex-twin --check
{"version":"1.35.0","tools":179,...,"scope":{"loaded":true,...}}
{"version":"1.36.0","tools":183,...,"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 (179)
## Tools (183)
### Scope and bookkeeping
@@ -299,6 +299,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `alpn_probe` | Per-protocol `s_client -alpn`: which of h2/http1.1/spdy3.1 the server selects |
| `webdav_probe` | OPTIONS + Depth:0 PROPFIND: 207 Multistatus means WebDAV is enabled |
| `dns_wildcard_check` | Random label under a domain; an answer means wildcard DNS |
| `dns_caa_check` | CAA records: flags, issue/issuewild/iodef tags and values |
| `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 |
@@ -376,6 +377,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `mongodb_config_audit` | mongod.conf: bindIp all, authorization off, TLS disabled |
| `memcached_config_audit` | memcached.conf: listen all, UDP enabled (no -U 0), 8 GiB+ memory |
| `ntpd_config_audit` | ntp.conf: weak/missing restrict, no disable monitor, drift in /tmp |
| `bind9_config_audit` | named.conf: allow-query any, open recursion, transfer any, visible version |
| `tomcat_audit` | server.xml/tomcat-users.xml: shutdown port, 0.0.0.0 connector, manager roles |
| `proftpd_audit` | proftpd.conf: AllowAll, anonymous without AnonReadOnly, RootLogin, TLS off |
### ESP32
@@ -632,6 +636,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| WebDAV | one OPTIONS and one Depth:0 PROPFIND |
| mongodb/memcached/ntpd | config reads only; optional root prefix |
| Wildcard DNS | one dig query |
| bind/tomcat/proftpd | config reads only; optional root prefix |
| CAA | one gated dig query |
| USB audit | 200 devices, sysfs reads only |
---
@@ -643,7 +649,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 867 end-to-end checks
make test # version check + gate audit + 880 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
@@ -760,7 +766,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
security_txt, http2_probe, ssh_hostkey_fingerprint,
kerberos_discovery, winrm_probe, dnssec_check,
smtp_starttls_probe, tls_ocsp_probe, alpn_probe,
webdav_probe, dns_wildcard_check
webdav_probe, dns_wildcard_check, dns_caa_check
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,
@@ -803,7 +809,7 @@ examples/ scope.json
## Status
1.35.0. Built and run: 179 tools, 867 checks, 340 fuzz cases and 81.7% line
1.36.0. Built and run: 183 tools, 880 checks, 340 fuzz cases and 81.9% 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
+4 -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.35.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.36.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.
- **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.
+4 -4
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.35.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.36.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -43,7 +43,7 @@ memcached_probe, param_fuzz, open_redirect, host_header_injection, ssti_probe,
xxe_probe, ldap_probe, rdp_probe, smb_probe, vnc_probe, mqtt_probe,
graphql_probe, docker_api_probe, elasticsearch_probe, imap_probe, pop3_probe,
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),
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),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -57,8 +57,8 @@ mysql_config_audit, apache_audit, haproxy_audit, redis_config_audit,
php_config_audit, dovecot_audit, openvpn_audit, postgresql_config_audit,
exim_audit, elasticsearch_config_audit, squid_audit, unbound_audit,
cups_audit, rsync_audit, dhcpd_audit, krb5_conf_audit,
mongodb_config_audit, memcached_config_audit, ntpd_config_audit) and ESP32
board tools (esp_info, esp_monitor,
mongodb_config_audit, memcached_config_audit, ntpd_config_audit,
bind9_config_audit, tomcat_audit, proftpd_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).
.SH MODES
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.35.0"
#define APEX_VERSION "1.36.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+453
View File
@@ -9576,6 +9576,438 @@ static void t_ntpd_config_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* -------------------------------------------------------------- bind9_config_audit */
static void bind_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files, int *query_any,
int *recursion_yes, int *allow_recursion,
int *transfer_any, int *version_seen,
int *version_hidden, char *version_value,
size_t version_n)
{
static char text[65536];
struct stat st;
char *copy;
char *save = NULL;
char *line;
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)++;
}
copy = strdup(text);
if (copy == NULL)
return;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *t = line;
while (*t == ' ' || *t == '\t')
t++;
if (*t != '#' && *t != '/' && *t != '\0') {
if (strstr(t, "allow-query") != NULL &&
strstr(t, "any") != NULL)
*query_any = 1;
if (strstr(t, "allow-transfer") != NULL &&
strstr(t, "any") != NULL)
*transfer_any = 1;
if (strstr(t, "allow-recursion") != NULL)
*allow_recursion = 1;
if (strstr(t, "recursion yes") != NULL)
*recursion_yes = 1;
if (strncmp(t, "version", 7) == 0) {
char *q = strchr(t, '"');
char *end;
*version_seen = 1;
if (q != NULL) {
q++;
end = strchr(q, '"');
if (end != NULL) {
size_t n = (size_t)(end - q);
if (n >= version_n)
n = version_n - 1;
memcpy(version_value, q, n);
version_value[n] = '\0';
if (strcasecmp(version_value,
"none") == 0 ||
strcasecmp(version_value,
"hidden") == 0) {
*version_hidden = 1;
version_value[0] = '\0';
}
}
}
}
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
static void t_bind9_config_audit(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *files[] = { "/etc/bind/named.conf",
"/etc/bind/named.conf.options",
"/etc/bind/named.conf.local",
"/etc/named.conf", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
char version_value[128];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int query_any = 0;
int recursion_yes = 0;
int allow_recursion = 0;
int transfer_any = 0;
int version_seen = 0;
int version_hidden = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
version_value[0] = '\0';
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (access(path, R_OK) == 0)
bind_scan_file(&findings, &first, &count, path,
&files_read, &query_any, &recursion_yes,
&allow_recursion, &transfer_any,
&version_seen, &version_hidden,
version_value, sizeof(version_value));
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a BIND configuration");
return;
}
if (query_any) {
add_finding(&findings, &first, "allow-query-any", "high",
"allow-query accepts every client");
count++;
}
if (recursion_yes && !allow_recursion) {
add_finding(&findings, &first, "open-recursion", "high",
"recursion is on without an allow-recursion limit");
count++;
}
if (transfer_any) {
add_finding(&findings, &first, "transfer-any", "high",
"allow-transfer accepts every client");
count++;
}
if (!version_hidden) {
add_finding(&findings, &first, "version-visible", "low",
version_seen ? "the BIND version is disclosed"
: "no version is hidden; BIND answers "
"with its default version");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"query_any\":%s,\"recursion\":%s,"
"\"allow_recursion\":%s,\"version\":",
files_read, query_any ? "true" : "false",
recursion_yes ? "true" : "false",
allow_recursion ? "true" : "false");
apex_json_str(&b, version_value);
mcp_buf_printf(&b, ",\"findings_count\":%d,\"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);
}
/* ----------------------------------------------------------------- tomcat_audit */
static void tomcat_scan_dir(mcp_buf *findings, int *first, int *count,
const char *confdir, int *files,
int *shutdown_bad, int *connector_all,
int *manager_roles, int *plain_password)
{
char path[1024];
static char text[65536];
struct stat st;
snprintf(path, sizeof(path), "%.800s/server.xml", confdir);
if (read_text(path, text, sizeof(text)) > 0) {
char *copy = strdup(text);
char *save = NULL;
char *line;
(*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 (copy != NULL) {
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
if (strstr(line, "<Server") != NULL &&
strstr(line, "port=") != NULL &&
strstr(line, "port=\"-1\"") == NULL)
*shutdown_bad = 1;
if (strstr(line, "<Connector") != NULL &&
strstr(line, "address=\"0.0.0.0\"") != NULL)
*connector_all = 1;
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
}
snprintf(path, sizeof(path), "%.800s/tomcat-users.xml", confdir);
if (read_text(path, text, sizeof(text)) > 0) {
char *copy = strdup(text);
char *save = NULL;
char *line;
int roles = 0;
int passwords = 0;
(*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 (copy != NULL) {
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
if (strstr(line, "manager-gui") != NULL ||
strstr(line, "manager-script") != NULL ||
strstr(line, "admin-gui") != NULL)
roles = 1;
if (strstr(line, "password=") != NULL)
passwords = 1;
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
if (roles)
*manager_roles = 1;
if (roles && passwords)
*plain_password = 1;
}
}
static void t_tomcat_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char etcdir[1024];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int shutdown_bad = 0;
int connector_all = 0;
int manager_roles = 0;
int plain_password = 0;
DIR *d;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
snprintf(etcdir, sizeof(etcdir), "%s/etc", root);
d = opendir(etcdir);
if (d != NULL) {
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
char confdir[1024];
if (strncmp(ent->d_name, "tomcat", 6) != 0)
continue;
snprintf(confdir, sizeof(confdir), "%.800s/%.160s",
etcdir, ent->d_name);
tomcat_scan_dir(&findings, &first, &count, confdir,
&files, &shutdown_bad, &connector_all,
&manager_roles, &plain_password);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Tomcat configuration");
return;
}
if (shutdown_bad) {
add_finding(&findings, &first, "shutdown-port", "medium",
"the shutdown port is enabled");
count++;
}
if (connector_all) {
add_finding(&findings, &first, "connector-all", "high",
"a Connector listens on every interface");
count++;
}
if (manager_roles) {
add_finding(&findings, &first, "manager-roles", "high",
"manager-gui/manager-script/admin-gui roles exist");
count++;
}
if (plain_password) {
add_finding(&findings, &first, "plain-password", "medium",
"a manager user stores a plaintext password");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"shutdown_enabled\":%s,"
"\"manager_roles\":%s,\"findings_count\":%d,"
"\"findings\":[",
files, shutdown_bad ? "true" : "false",
manager_roles ? "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);
}
/* --------------------------------------------------------------- proftpd_audit */
static void t_proftpd_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/proftpd/proftpd.conf",
"/etc/proftpd.conf", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
char root_login[32];
char tls_required[32];
char anon_readonly[32];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int allow_all = 0;
int anonymous = 0;
int i;
struct stat st;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
root_login[0] = tls_required[0] = anon_readonly[0] = '\0';
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
static char text[65536];
char *copy;
char *save = NULL;
char *line;
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++;
}
conf_value(text, "RootLogin", root_login,
sizeof(root_login));
conf_value(text, "TLSRequired", tls_required,
sizeof(tls_required));
conf_value(text, "AnonReadOnly", anon_readonly,
sizeof(anon_readonly));
copy = strdup(text);
if (copy == NULL)
continue;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *t = line;
while (*t == ' ' || *t == '\t')
t++;
if (*t != '#' && *t != '\0') {
if (strncmp(t, "AllowAll", 8) == 0)
allow_all = 1;
if (strncmp(t, "<Anonymous", 10) == 0)
anonymous = 1;
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a ProFTPD configuration");
return;
}
if (allow_all) {
add_finding(&findings, &first, "allow-all", "high",
"AllowAll grants every client access");
count++;
}
if (anonymous) {
add_finding(&findings, &first, "anonymous", "medium",
"an Anonymous block is defined");
count++;
if (anon_readonly[0] == '\0' ||
strcasecmp(anon_readonly, "on") != 0) {
add_finding(&findings, &first, "anonymous-writable",
"high",
"the Anonymous block is not read-only");
count++;
}
}
if (strcasecmp(root_login, "on") == 0) {
add_finding(&findings, &first, "root-login", "high",
"root may log in over FTP");
count++;
}
if (strcasecmp(tls_required, "on") != 0) {
add_finding(&findings, &first, "tls-not-required", "medium",
"TLS is not required");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"root_login\":", files_read);
apex_json_str(&b, root_login);
mcp_buf_puts(&b, ",\"tls_required\":");
apex_json_str(&b, tls_required);
mcp_buf_printf(&b, ",\"findings_count\":%d,\"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);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -10101,6 +10533,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_ntpd_config_audit },
{ "bind9_config_audit",
"Parse named.conf, named.conf.options and named.conf.local (root prefix): "
"allow-query any, recursion without allow-recursion, allow-transfer any, "
"a visible version and world-writable files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_bind9_config_audit },
{ "tomcat_audit",
"Parse server.xml and tomcat-users.xml under /etc/tomcat* (root prefix): "
"an enabled shutdown port, a Connector on 0.0.0.0, manager/admin roles, "
"a plaintext manager password and world-writable files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_tomcat_audit },
{ "proftpd_audit",
"Parse proftpd.conf (root prefix): AllowAll, an Anonymous block without "
"AnonReadOnly, RootLogin on, TLS not required and world-writable files. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_proftpd_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+161
View File
@@ -5405,6 +5405,156 @@ static void t_dns_wildcard_check(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* ----------------------------------------------------------------- dns_caa_check */
static void t_dns_caa_check(mcp_conn *c, const mcp_json *args, void *user)
{
const char *domain = mcp_arg_string(args, "domain");
const char *resolver = mcp_arg_string(args, "resolver");
int port = mcp_arg_int(args, "port", 0);
char reason[512];
char portstr[16];
char at_server[300];
char *argv[12];
int i = 0;
apex_proc p;
mcp_buf b;
int first = 1;
int count = 0;
int issue = 0;
int issuewild = 0;
int iodef = 0;
(void)user;
if (domain == NULL || *domain == '\0') {
mcp_reply_error(c, "domain is required");
return;
}
if (port < 0 || port > 65535) {
mcp_reply_error(c, "port out of range");
return;
}
if (!apex_scope_check(domain, 0, 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;
}
if (resolver != NULL && *resolver != '\0' &&
!apex_scope_check(resolver, port, reason, sizeof(reason))) {
mcp_buf_init(&b);
mcp_buf_printf(&b, "resolver is outside the scope: %s", reason);
mcp_reply_error(c, b.p);
mcp_buf_free(&b);
return;
}
apex_audit("dns_caa_check", domain, 0, 1, "CAA lookup", "dig CAA");
snprintf(portstr, sizeof(portstr), "%d", port > 0 ? port : 53);
snprintf(at_server, sizeof(at_server), "@%.200s",
resolver != NULL ? resolver : "");
argv[i++] = "dig";
argv[i++] = "+short";
argv[i++] = "+time=3";
argv[i++] = "+tries=1";
argv[i++] = "-p";
argv[i++] = portstr;
if (resolver != NULL && *resolver != '\0')
argv[i++] = at_server;
argv[i++] = (char *)domain;
argv[i++] = "CAA";
argv[i] = NULL;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"domain\":");
apex_json_str(&b, domain);
mcp_buf_puts(&b, ",\"resolver\":");
apex_json_str(&b, resolver != NULL ? resolver : "");
mcp_buf_puts(&b, ",\"records\":[");
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 < 10) {
int flags = 0;
char tag[64];
char raw[256];
char value[256];
size_t w = 0;
size_t rl;
while (*line == ' ' ||
*line == '\t')
line++;
if (*line == '\0') {
line = strtok_r(NULL, "\n",
&save);
continue;
}
if (sscanf(line, "%d %63s %255[^\n]",
&flags, tag, raw) != 3) {
line = strtok_r(NULL, "\n",
&save);
continue;
}
rl = strlen(raw);
while (rl > 0 &&
(raw[rl - 1] == ' ' ||
raw[rl - 1] == '\t'))
raw[--rl] = '\0';
if (raw[0] == '"')
memmove(raw, raw + 1, strlen(raw));
rl = strlen(raw);
if (rl > 0 && raw[rl - 1] == '"')
raw[rl - 1] = '\0';
{
const char *v = raw;
while (*v != '\0' && w + 1 <
sizeof(value))
value[w++] = *v++;
value[w] = '\0';
}
if (strcasecmp(tag, "issue") == 0)
issue = 1;
else if (strcasecmp(tag, "issuewild") == 0)
issuewild = 1;
else if (strcasecmp(tag, "iodef") == 0)
iodef = 1;
if (!first)
mcp_buf_puts(&b, ",");
first = 0;
mcp_buf_printf(&b,
"{\"flags\":%d,\"tag\":",
flags);
apex_json_str(&b, tag);
mcp_buf_puts(&b, ",\"value\":");
apex_json_str(&b, value);
mcp_buf_puts(&b, "}");
count++;
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
}
apex_proc_free(&p);
}
mcp_buf_printf(&b, "],\"count\":%d,\"caa_present\":%s,\"has_issue\":%s,"
"\"has_issuewild\":%s,\"has_iodef\":%s}",
count, count > 0 ? "true" : "false",
issue ? "true" : "false", issuewild ? "true" : "false",
iodef ? "true" : "false");
apex_audit("dns_caa_check", domain, 0, count > 0,
count > 0 ? "CAA records published"
: "no CAA records (any CA may issue)",
"dig CAA");
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: "
@@ -5871,6 +6021,17 @@ const mcp_tool TOOLS_RED[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"dig -p, default 0\"}},"
"\"required\":[\"domain\"]}",
t_dns_wildcard_check },
{ "dns_caa_check",
"Query the CAA records of an in-scope domain with gated dig and report "
"the flags, tag (issue/issuewild/iodef) and value of each record. No "
"records means any CA may issue certificates for it. Gate: the domain "
"(and resolver).",
"{\"type\":\"object\",\"properties\":{"
"\"domain\":{\"type\":\"string\"},"
"\"resolver\":{\"type\":\"string\",\"description\":\"optional DNS server\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"dig -p, default 0\"}},"
"\"required\":[\"domain\"]}",
t_dns_caa_check },
};
const size_t TOOLS_RED_N = sizeof(TOOLS_RED) / sizeof(TOOLS_RED[0]);
+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 = 179
EXPECTED_TOOLS = 183
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.
+196 -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("179 tools registered", len(tools) == 179, len(tools))
check("183 tools registered", len(tools) == 183, 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"]) == 179)
check("http tools/list", len(listing["result"]["tools"]) == 183)
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
@@ -8063,6 +8063,200 @@ shutil.rmtree(nt_root, ignore_errors=True)
shutil.rmtree(nt_good_root, ignore_errors=True)
shutil.rmtree(cfg7_home, ignore_errors=True)
print("\n== BIND, Tomcat, ProFTPD and CAA ==\n")
bd_root = tempfile.mkdtemp(prefix="apex-bd-")
os.makedirs(os.path.join(bd_root, "etc", "bind"))
bd_bad = os.path.join(bd_root, "etc", "bind", "named.conf")
with open(bd_bad, "w") as f:
f.write("options {\n")
f.write(" allow-query { any; };\n")
f.write(" allow-transfer { any; };\n")
f.write(" recursion yes;\n")
f.write(' version "9.18.1";\n')
f.write("};\n")
os.chmod(bd_bad, 0o666)
bd_good_root = tempfile.mkdtemp(prefix="apex-bdg-")
os.makedirs(os.path.join(bd_good_root, "etc", "bind"))
with open(os.path.join(bd_good_root, "etc", "bind", "named.conf"),
"w") as f:
f.write("options {\n")
f.write(" allow-query { 127.0.0.0/8; };\n")
f.write(" allow-transfer { none; };\n")
f.write(" allow-recursion { 127.0.0.0/8; };\n")
f.write(" recursion yes;\n")
f.write(' version "none";\n')
f.write("};\n")
tc_root = tempfile.mkdtemp(prefix="apex-tc-")
os.makedirs(os.path.join(tc_root, "etc", "tomcat9"))
tc_server = os.path.join(tc_root, "etc", "tomcat9", "server.xml")
with open(tc_server, "w") as f:
f.write('<Server port="8005" shutdown="SHUTDOWN">\n')
f.write(' <Connector port="8080" address="0.0.0.0" />\n')
f.write("</Server>\n")
os.chmod(tc_server, 0o666)
with open(os.path.join(tc_root, "etc", "tomcat9", "tomcat-users.xml"),
"w") as f:
f.write("<tomcat-users>\n")
f.write(' <role rolename="manager-gui"/>\n')
f.write(' <user username="admin" password="admin" '
'roles="manager-gui"/>\n')
f.write("</tomcat-users>\n")
tc_good_root = tempfile.mkdtemp(prefix="apex-tcg-")
os.makedirs(os.path.join(tc_good_root, "etc", "tomcat9"))
with open(os.path.join(tc_good_root, "etc", "tomcat9", "server.xml"),
"w") as f:
f.write('<Server port="-1" shutdown="SHUTDOWN">\n')
f.write(' <Connector port="8080" address="127.0.0.1" />\n')
f.write("</Server>\n")
with open(os.path.join(tc_good_root, "etc", "tomcat9",
"tomcat-users.xml"), "w") as f:
f.write("<tomcat-users>\n")
f.write(' <role rolename="user"/>\n')
f.write(' <user username="app" password="secret" roles="user"/>\n')
f.write("</tomcat-users>\n")
pf_root = tempfile.mkdtemp(prefix="apex-pf2-")
os.makedirs(os.path.join(pf_root, "etc", "proftpd"))
pf_bad = os.path.join(pf_root, "etc", "proftpd", "proftpd.conf")
with open(pf_bad, "w") as f:
f.write("AllowAll\n")
f.write("RootLogin on\n")
f.write("TLSRequired off\n")
f.write("<Anonymous ~ftp>\n User ftp\n</Anonymous>\n")
os.chmod(pf_bad, 0o666)
pf_good_root = tempfile.mkdtemp(prefix="apex-pf2g-")
os.makedirs(os.path.join(pf_good_root, "etc", "proftpd"))
with open(os.path.join(pf_good_root, "etc", "proftpd", "proftpd.conf"),
"w") as f:
f.write("RootLogin off\n")
f.write("TLSRequired on\n")
f.write("User ftpuser\nGroup ftpgroup\n")
def caa_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 rdata(tag, value):
return bytes([0, len(tag)]) + tag.encode() + value.encode()
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 = struct.unpack(">H", data[off:off + 2])[0]
question = data[12:off + 4]
answers = []
if qtype == 257 and name == "caa.test":
for rrdata in (rdata("issue", "letsencrypt.org"),
rdata("iodef", "mailto:security@example.test")):
answers.append(b"\xc0\x0c" +
struct.pack(">HHIH", 257, 1, 300,
len(rrdata)) + rrdata)
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
caa_sock, caa_port, caa_stop = caa_agent()
cfg8_home = tempfile.mkdtemp(prefix="apex-cfg8-home-")
write_scope(cfg8_home, {"label": "cfg8", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_domain": ["caa.test", "nocaa.test"],
"allow_port": [str(caa_port)]})
res, _ = run([
call(1, "bind9_config_audit", root=bd_root),
call(2, "bind9_config_audit", root=bd_good_root),
call(3, "tomcat_audit", root=tc_root),
call(4, "tomcat_audit", root=tc_good_root),
call(5, "proftpd_audit", root=pf_root),
call(6, "proftpd_audit", root=pf_good_root),
call(7, "dns_caa_check", domain="caa.test", resolver="127.0.0.1",
port=caa_port),
call(8, "dns_caa_check", domain="nocaa.test", resolver="127.0.0.1",
port=caa_port),
call(9, "bind9_config_audit", root="/nonexistent-bd"),
call(10, "tomcat_audit", root="/nonexistent-tc"),
call(11, "proftpd_audit", root="/nonexistent-pf2"),
call(12, "dns_caa_check", domain="evil.test"),
], home=cfg8_home)
by_id = {r.get("id"): r for r in res}
bd = json.loads(text(by_id[1]))
bd_kinds = {f["id"] for f in bd["findings"]}
check("bind9_config_audit flags query, recursion, transfer and version",
{"allow-query-any", "open-recursion", "transfer-any",
"version-visible", "world-writable"} <= bd_kinds, bd)
bd_good = json.loads(text(by_id[2]))
check("bind9_config_audit accepts a hardened config",
bd_good["findings_count"] == 0 and bd_good["query_any"] is False and
bd_good["allow_recursion"] is True, bd_good)
tc = json.loads(text(by_id[3]))
tc_kinds = {f["id"] for f in tc["findings"]}
check("tomcat_audit flags shutdown, connector, roles and passwords",
{"world-writable", "shutdown-port", "connector-all", "manager-roles",
"plain-password"} <= tc_kinds, tc)
tc_good = json.loads(text(by_id[4]))
check("tomcat_audit accepts a hardened config",
tc_good["findings_count"] == 0 and
tc_good["shutdown_enabled"] is False, tc_good)
pf = json.loads(text(by_id[5]))
pf_kinds = {f["id"] for f in pf["findings"]}
check("proftpd_audit flags AllowAll, anonymous and root",
{"allow-all", "anonymous", "root-login", "tls-not-required",
"world-writable"} <= pf_kinds, pf)
pf_good = json.loads(text(by_id[6]))
check("proftpd_audit accepts a hardened config",
pf_good["findings_count"] == 0 and
pf_good["tls_required"] == "on", pf_good)
caa = json.loads(text(by_id[7]))
caa_tags = {r["tag"]: r["value"] for r in caa["records"]}
check("dns_caa_check reads the CAA records",
caa["caa_present"] is True and caa["count"] == 2 and
caa["has_issue"] is True and caa["has_iodef"] is True, caa)
check("dns_caa_check reports tag values",
caa_tags.get("issue") == "letsencrypt.org" and
caa_tags.get("iodef") == "mailto:security@example.test", caa_tags)
nocaa = json.loads(text(by_id[8]))
check("dns_caa_check reports a domain without CAA",
nocaa["caa_present"] is False and nocaa["count"] == 0, nocaa)
check("bind9_config_audit reports a missing config", err(by_id[9]),
text(by_id[9]))
check("tomcat_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("proftpd_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("dns_caa_check refuses an out-of-scope domain", err(by_id[12]),
text(by_id[12]))
caa_stop.set()
caa_sock.close()
shutil.rmtree(bd_root, ignore_errors=True)
shutil.rmtree(bd_good_root, ignore_errors=True)
shutil.rmtree(tc_root, ignore_errors=True)
shutil.rmtree(tc_good_root, ignore_errors=True)
shutil.rmtree(pf_root, ignore_errors=True)
shutil.rmtree(pf_good_root, ignore_errors=True)
shutil.rmtree(cfg8_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"})