apex-twin 1.35.0: MongoDB, memcached and NTPD audits, wildcard DNS check
Blue: - mongodb_config_audit: mongod.conf: net.bindIp on every interface (absent counts as default), security.authorization disabled or missing, net.tls mode disabled and a world-writable config. - memcached_config_audit: memcached.conf: -l on every interface (absent counts), UDP left enabled when -U 0 is missing, a memory limit of 8 GiB or more and a world-writable config. - ntpd_config_audit: ntp.conf: missing or weak restrict default (no kod/limited), missing disable monitor (monlist), drift file in /tmp or /dev/shm and a world-writable config. Red: - dns_wildcard_check: one gated dig for a random label under an in-scope domain; an answer means wildcard DNS. Tests with vulnerable and hardened mongod/memcached/ntp trees and a DNS agent with and without a wildcard. 867 checks, ASan suite green, analyze clean, release-check green including distcheck 1.35.0.
This commit is contained in:
1 parent
4306da88ea
commit
3b1a88487a
9 files changed
+689
-15
No files matched your search
+18
-1
@@ -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.34.0 — 2026-11-21 — this change
|
||||
## 1.35.0 — 2026-11-21 — this change
|
||||
|
||||
- **MongoDB** (`mongodb_config_audit`): mongod.conf: net.bindIp on every
|
||||
interface (absent counts as the default), security.authorization disabled or
|
||||
missing, a net.tls mode of disabled and a world-writable config.
|
||||
- **memcached** (`memcached_config_audit`): memcached.conf: -l on every
|
||||
interface (absent counts as the default), UDP left enabled when -U 0 is
|
||||
missing, a memory limit of 8 GiB or more and a world-writable config.
|
||||
- **NTPD** (`ntpd_config_audit`): ntp.conf: a missing or weak restrict default
|
||||
(no kod/limited), a missing `disable monitor` (monlist), a drift file in
|
||||
/tmp or /dev/shm and a world-writable config.
|
||||
- **Wildcard DNS** (`dns_wildcard_check`): one gated dig for a random label
|
||||
under an in-scope domain; an answer means wildcard DNS, which would poison
|
||||
subdomain enumeration.
|
||||
- Tests with vulnerable and hardened mongod/memcached/ntp trees and a DNS
|
||||
agent with and without a wildcard. 867 checks. Coverage 81.7%.
|
||||
|
||||
## 1.34.0 — 2026-11-21 — 4306da8
|
||||
|
||||
- **rsync** (`rsync_audit`): rsyncd.conf (root prefix): missing or wildcard
|
||||
hosts allow, uid/gid 0, use chroot = no, a world-readable secrets file and a
|
||||
|
||||
@@ -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.
|
||||
|
||||
**175 tools · 855 end-to-end checks · 340 fuzz cases · 81.5% line coverage · ~693 KiB**
|
||||
**179 tools · 867 end-to-end checks · 340 fuzz cases · 81.7% line coverage · ~701 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.34.0","tools":175,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.35.0","tools":179,...,"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 (175)
|
||||
## Tools (179)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -298,6 +298,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `tls_ocsp_probe` | `s_client -status`: stapled or not, OCSP response and certificate status |
|
||||
| `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 |
|
||||
| `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 |
|
||||
@@ -372,6 +373,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `rsync_audit` | rsyncd.conf: wildcard hosts allow, uid/gid 0, no chroot, readable secrets |
|
||||
| `dhcpd_audit` | dhcpd.conf: authoritative, weak ddns, missing DNS option, range outside subnet |
|
||||
| `krb5_conf_audit` | krb5.conf: DNS lookup off, rdns on, legacy enctypes, writable config |
|
||||
| `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 |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -626,6 +630,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| ALPN | one handshake per protocol, no data |
|
||||
| rsync/dhcpd/krb5 | config reads only; optional root prefix |
|
||||
| WebDAV | one OPTIONS and one Depth:0 PROPFIND |
|
||||
| mongodb/memcached/ntpd | config reads only; optional root prefix |
|
||||
| Wildcard DNS | one dig query |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -637,7 +643,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 855 end-to-end checks
|
||||
make test # version check + gate audit + 867 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
|
||||
@@ -754,7 +760,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
|
||||
webdav_probe, dns_wildcard_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,
|
||||
@@ -797,7 +803,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.34.0. Built and run: 175 tools, 855 checks, 340 fuzz cases and 81.5% line
|
||||
1.35.0. Built and run: 179 tools, 867 checks, 340 fuzz cases and 81.7% 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
@@ -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.34.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.35.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.
|
||||
- **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.
|
||||
- **WebDAV is one OPTIONS and one PROPFIND.** `webdav_probe` sends a
|
||||
read-only `Depth: 0` property request and never writes a resource;
|
||||
rsync/dhcpd/krb5 audits read configuration files.
|
||||
|
||||
+5
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.34.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.35.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),
|
||||
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),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -56,7 +56,9 @@ usb_audit, docker_audit, www_audit, audit_rules, postfix_audit, nginx_audit,
|
||||
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) and ESP32 board tools (esp_info, esp_monitor,
|
||||
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,
|
||||
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
|
||||
esp_app_info, esp_image_verify).
|
||||
.SH MODES
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.34.0"
|
||||
#define APEX_VERSION "1.35.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -9234,6 +9234,348 @@ static void t_krb5_conf_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- mongodb_config_audit */
|
||||
|
||||
static void t_mongodb_config_audit(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
static char text[65536];
|
||||
char path[1024];
|
||||
char bind_ip[256];
|
||||
char auth[64];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int bind_all = 0;
|
||||
int auth_off = 0;
|
||||
int tls_disabled = 0;
|
||||
int in_tls = 0;
|
||||
int tls_indent = 0;
|
||||
struct stat st;
|
||||
|
||||
(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/mongod.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read mongod.conf");
|
||||
return;
|
||||
}
|
||||
bind_ip[0] = auth[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"mongod.conf is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
if (yaml_value(text, "bindIp", bind_ip, sizeof(bind_ip))) {
|
||||
if (conf_has_word(bind_ip, "0.0.0.0") ||
|
||||
conf_has_word(bind_ip, "::") ||
|
||||
conf_has_word(bind_ip, "*"))
|
||||
bind_all = 1;
|
||||
} else {
|
||||
bind_all = 1; /* MongoDB binds every interface by default */
|
||||
}
|
||||
if (yaml_value(text, "authorization", auth, sizeof(auth))) {
|
||||
if (strcasecmp(auth, "disabled") == 0)
|
||||
auth_off = 1;
|
||||
} else {
|
||||
auth_off = 1;
|
||||
}
|
||||
{
|
||||
char *copy = strdup(text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *t = line;
|
||||
int indent = 0;
|
||||
|
||||
while (*t == ' ' || *t == '\t') {
|
||||
indent++;
|
||||
t++;
|
||||
}
|
||||
if (*t != '#' && *t != '\0') {
|
||||
if (strncmp(t, "tls:", 4) == 0) {
|
||||
in_tls = 1;
|
||||
tls_indent = indent;
|
||||
} else if (in_tls &&
|
||||
indent <= tls_indent) {
|
||||
in_tls = 0;
|
||||
}
|
||||
if (in_tls &&
|
||||
strncmp(t, "mode:", 5) == 0 &&
|
||||
strstr(t, "disabled") != NULL)
|
||||
tls_disabled = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
if (bind_all) {
|
||||
add_finding(&findings, &first, "bind-all", "high",
|
||||
"MongoDB listens on every interface");
|
||||
count++;
|
||||
}
|
||||
if (auth_off) {
|
||||
add_finding(&findings, &first, "auth-off", "high",
|
||||
"authorization is disabled");
|
||||
count++;
|
||||
}
|
||||
if (tls_disabled) {
|
||||
add_finding(&findings, &first, "tls-off", "medium",
|
||||
"TLS is disabled for client connections");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"bind_ip\":");
|
||||
apex_json_str(&b, bind_ip);
|
||||
mcp_buf_puts(&b, ",\"authorization\":");
|
||||
apex_json_str(&b, auth);
|
||||
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);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- memcached_config_audit */
|
||||
|
||||
static void t_memcached_config_audit(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
static char text[65536];
|
||||
char path[1024];
|
||||
char listen_value[128];
|
||||
char memory[64];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int listen_all = 0;
|
||||
int udp_disabled = 0;
|
||||
int memory_large = 0;
|
||||
int memory_seen = 0;
|
||||
struct stat st;
|
||||
|
||||
(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/memcached.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read memcached.conf");
|
||||
return;
|
||||
}
|
||||
listen_value[0] = memory[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"memcached.conf is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
{
|
||||
char *copy = strdup(text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *t = line;
|
||||
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
if (*t == '-' && t[1] != '\0') {
|
||||
char option = t[1];
|
||||
char *v = t + 2;
|
||||
|
||||
while (*v == ' ' || *v == '\t')
|
||||
v++;
|
||||
if (option == 'l') {
|
||||
snprintf(listen_value,
|
||||
sizeof(listen_value),
|
||||
"%.100s", v);
|
||||
if (strstr(v, "0.0.0.0") != NULL ||
|
||||
strstr(v, "::") != NULL ||
|
||||
strchr(v, '*') != NULL)
|
||||
listen_all = 1;
|
||||
} else if (option == 'U') {
|
||||
if (strcmp(v, "0") == 0)
|
||||
udp_disabled = 1;
|
||||
} else if (option == 'm') {
|
||||
memory_seen = 1;
|
||||
snprintf(memory,
|
||||
sizeof(memory),
|
||||
"%.48s", v);
|
||||
if (atoi(v) >= 8192)
|
||||
memory_large = 1;
|
||||
}
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
if (!listen_all && listen_value[0] == '\0')
|
||||
listen_all = 1; /* memcached binds every interface by default */
|
||||
if (listen_all) {
|
||||
add_finding(&findings, &first, "listen-all", "high",
|
||||
"memcached listens on every interface");
|
||||
count++;
|
||||
}
|
||||
if (!udp_disabled) {
|
||||
add_finding(&findings, &first, "udp-enabled", "medium",
|
||||
"the UDP listener is enabled (-U 0 missing)");
|
||||
count++;
|
||||
}
|
||||
if (memory_seen && memory_large) {
|
||||
add_finding(&findings, &first, "memory-large", "low",
|
||||
"the memory limit is at least 8 GiB");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"listen\":");
|
||||
apex_json_str(&b, listen_value);
|
||||
mcp_buf_printf(&b, ",\"udp_disabled\":%s,\"memory_mb\":",
|
||||
udp_disabled ? "true" : "false");
|
||||
apex_json_str(&b, memory);
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- ntpd_config_audit */
|
||||
|
||||
static void t_ntpd_config_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
static char text[65536];
|
||||
char path[1024];
|
||||
char restrict_default[256];
|
||||
char driftfile[256];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int restrict_seen = 0;
|
||||
int restrict_weak = 0;
|
||||
int monitor_disabled = 0;
|
||||
int temp_path = 0;
|
||||
struct stat st;
|
||||
|
||||
(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/ntp.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read ntp.conf");
|
||||
return;
|
||||
}
|
||||
restrict_default[0] = driftfile[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"ntp.conf is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
conf_value(text, "driftfile", driftfile, sizeof(driftfile));
|
||||
{
|
||||
char *copy = strdup(text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *t = line;
|
||||
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
if (*t != '#' && *t != '\0') {
|
||||
if (strncmp(t, "restrict default", 16) ==
|
||||
0) {
|
||||
restrict_seen = 1;
|
||||
snprintf(restrict_default,
|
||||
sizeof(restrict_default),
|
||||
"%.200s", t + 16);
|
||||
if (strstr(t, "kod") == NULL &&
|
||||
strstr(t, "limited") == NULL)
|
||||
restrict_weak = 1;
|
||||
}
|
||||
if (strstr(t, "disable monitor") != NULL)
|
||||
monitor_disabled = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
if (!restrict_seen) {
|
||||
add_finding(&findings, &first, "no-restrict", "medium",
|
||||
"no restrict default rule is configured");
|
||||
count++;
|
||||
} else if (restrict_weak) {
|
||||
add_finding(&findings, &first, "restrict-weak", "medium",
|
||||
"restrict default has no kod or limited");
|
||||
count++;
|
||||
}
|
||||
if (!monitor_disabled) {
|
||||
add_finding(&findings, &first, "monitor-enabled", "medium",
|
||||
"disable monitor is missing (monlist amplification)");
|
||||
count++;
|
||||
}
|
||||
if (strncmp(driftfile, "/tmp", 4) == 0 ||
|
||||
strncmp(driftfile, "/dev/shm", 8) == 0) {
|
||||
add_finding(&findings, &first, "temp-path", "low",
|
||||
"the drift file lives in a temporary directory");
|
||||
temp_path = 1;
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"restrict_default\":");
|
||||
apex_json_str(&b, restrict_default);
|
||||
mcp_buf_printf(&b, ",\"monitor_disabled\":%s,\"temp_path\":%s,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
monitor_disabled ? "true" : "false",
|
||||
temp_path ? "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, "
|
||||
@@ -9738,6 +10080,27 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_krb5_conf_audit },
|
||||
{ "mongodb_config_audit",
|
||||
"Parse mongod.conf (root prefix): net.bindIp on every interface (absent "
|
||||
"counts), security.authorization disabled or missing, net.tls.mode "
|
||||
"disabled and a world-writable config. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_mongodb_config_audit },
|
||||
{ "memcached_config_audit",
|
||||
"Parse memcached.conf (root prefix): -l on every interface (absent "
|
||||
"counts), UDP left enabled (no -U 0), a memory limit of 8 GiB or more "
|
||||
"and a world-writable config. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_memcached_config_audit },
|
||||
{ "ntpd_config_audit",
|
||||
"Parse ntp.conf (root prefix): a missing or weak restrict default (no "
|
||||
"kod/limited), a missing 'disable monitor' (monlist), a drift file in "
|
||||
"/tmp or /dev/shm and a world-writable config. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_ntpd_config_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
+113
@@ -5302,6 +5302,109 @@ static void t_webdav_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
free(resp);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- dns_wildcard_check */
|
||||
|
||||
static void t_dns_wildcard_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 label[400];
|
||||
char *argv[12];
|
||||
int i = 0;
|
||||
apex_proc p;
|
||||
mcp_buf b;
|
||||
int first = 1;
|
||||
int count = 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;
|
||||
}
|
||||
snprintf(label, sizeof(label), "apex%ld%ld.%.280s", (long)getpid(),
|
||||
(long)time(NULL), domain);
|
||||
apex_audit("dns_wildcard_check", domain, 0, 1, "wildcard lookup",
|
||||
label);
|
||||
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++] = label;
|
||||
argv[i++] = "A";
|
||||
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, ",\"probe\":");
|
||||
apex_json_str(&b, label);
|
||||
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 < 10) {
|
||||
while (*line == ' ' || *line == '\t')
|
||||
line++;
|
||||
if (*line != '\0') {
|
||||
if (!first)
|
||||
mcp_buf_puts(&b, ",");
|
||||
first = 0;
|
||||
apex_json_str(&b, line);
|
||||
count++;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
apex_proc_free(&p);
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"answer_count\":%d,\"wildcard\":%s}",
|
||||
count, count > 0 ? "true" : "false");
|
||||
apex_audit("dns_wildcard_check", domain, 0, count == 0,
|
||||
count > 0 ? "wildcard DNS answers for a random label"
|
||||
: "no wildcard answer", label);
|
||||
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: "
|
||||
@@ -5758,6 +5861,16 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_webdav_probe },
|
||||
{ "dns_wildcard_check",
|
||||
"Query a random label under a domain (gated dig A) and report whether it "
|
||||
"resolves: an answer means wildcard DNS, which matters for subdomain "
|
||||
"enumeration. 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_wildcard_check },
|
||||
};
|
||||
|
||||
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 = 175
|
||||
EXPECTED_TOOLS = 179
|
||||
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.
|
||||
|
||||
+172
-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("175 tools registered", len(tools) == 175, len(tools))
|
||||
check("179 tools registered", len(tools) == 179, 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"]) == 175)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 179)
|
||||
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
|
||||
@@ -7893,6 +7893,176 @@ shutil.rmtree(kb_root, ignore_errors=True)
|
||||
shutil.rmtree(kb_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg6_home, ignore_errors=True)
|
||||
|
||||
print("\n== MongoDB, memcached, NTPD and wildcard DNS ==\n")
|
||||
|
||||
mg_root = tempfile.mkdtemp(prefix="apex-mg-")
|
||||
os.makedirs(os.path.join(mg_root, "etc"))
|
||||
mg_bad = os.path.join(mg_root, "etc", "mongod.conf")
|
||||
with open(mg_bad, "w") as f:
|
||||
f.write("net:\n")
|
||||
f.write(" bindIp: 0.0.0.0\n")
|
||||
f.write(" port: 27017\n")
|
||||
f.write(" tls:\n")
|
||||
f.write(" mode: disabled\n")
|
||||
f.write("security:\n")
|
||||
f.write(" authorization: disabled\n")
|
||||
os.chmod(mg_bad, 0o666)
|
||||
mg_good_root = tempfile.mkdtemp(prefix="apex-mgg-")
|
||||
os.makedirs(os.path.join(mg_good_root, "etc"))
|
||||
with open(os.path.join(mg_good_root, "etc", "mongod.conf"), "w") as f:
|
||||
f.write("net:\n")
|
||||
f.write(" bindIp: 127.0.0.1\n")
|
||||
f.write("security:\n")
|
||||
f.write(" authorization: enabled\n")
|
||||
|
||||
mc_root = tempfile.mkdtemp(prefix="apex-mc-")
|
||||
os.makedirs(os.path.join(mc_root, "etc"))
|
||||
mc_bad = os.path.join(mc_root, "etc", "memcached.conf")
|
||||
with open(mc_bad, "w") as f:
|
||||
f.write("-l 0.0.0.0\n")
|
||||
f.write("-m 16384\n")
|
||||
os.chmod(mc_bad, 0o666)
|
||||
mc_good_root = tempfile.mkdtemp(prefix="apex-mcg-")
|
||||
os.makedirs(os.path.join(mc_good_root, "etc"))
|
||||
with open(os.path.join(mc_good_root, "etc", "memcached.conf"), "w") as f:
|
||||
f.write("-l 127.0.0.1\n")
|
||||
f.write("-U 0\n")
|
||||
f.write("-m 512\n")
|
||||
|
||||
nt_root = tempfile.mkdtemp(prefix="apex-nt-")
|
||||
os.makedirs(os.path.join(nt_root, "etc"))
|
||||
nt_bad = os.path.join(nt_root, "etc", "ntp.conf")
|
||||
with open(nt_bad, "w") as f:
|
||||
f.write("restrict default nomodify nopeer noquery\n")
|
||||
f.write("driftfile /tmp/ntp.drift\n")
|
||||
os.chmod(nt_bad, 0o666)
|
||||
nt_good_root = tempfile.mkdtemp(prefix="apex-ntg-")
|
||||
os.makedirs(os.path.join(nt_good_root, "etc"))
|
||||
with open(os.path.join(nt_good_root, "etc", "ntp.conf"), "w") as f:
|
||||
f.write("restrict default kod limited nomodify nopeer noquery\n")
|
||||
f.write("disable monitor\n")
|
||||
f.write("driftfile /var/lib/ntp/ntp.drift\n")
|
||||
|
||||
|
||||
def wildcard_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 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]
|
||||
answer = b""
|
||||
if qtype == 1:
|
||||
if name.endswith("wild.test") and \
|
||||
not name.endswith("nowild.test"):
|
||||
answer = (b"\xc0\x0c" +
|
||||
struct.pack(">HHIH", 1, 1, 60, 4) +
|
||||
socket.inet_aton("203.0.113.7"))
|
||||
elif name == "www.nowild.test":
|
||||
answer = (b"\xc0\x0c" +
|
||||
struct.pack(">HHIH", 1, 1, 60, 4) +
|
||||
socket.inet_aton("203.0.113.8"))
|
||||
resp = (tid + struct.pack(">HHHHH", 0x8400, 1,
|
||||
1 if answer else 0, 0, 0) + question +
|
||||
answer)
|
||||
sock.sendto(resp, addr)
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return sock, port, stop
|
||||
|
||||
|
||||
wild_sock, wild_port, wild_stop = wildcard_agent()
|
||||
|
||||
cfg7_home = tempfile.mkdtemp(prefix="apex-cfg7-home-")
|
||||
write_scope(cfg7_home, {"label": "cfg7", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_domain": ["wild.test", "nowild.test"],
|
||||
"allow_port": [str(wild_port)]})
|
||||
res, _ = run([
|
||||
call(1, "mongodb_config_audit", root=mg_root),
|
||||
call(2, "mongodb_config_audit", root=mg_good_root),
|
||||
call(3, "memcached_config_audit", root=mc_root),
|
||||
call(4, "memcached_config_audit", root=mc_good_root),
|
||||
call(5, "ntpd_config_audit", root=nt_root),
|
||||
call(6, "ntpd_config_audit", root=nt_good_root),
|
||||
call(7, "dns_wildcard_check", domain="wild.test", resolver="127.0.0.1",
|
||||
port=wild_port),
|
||||
call(8, "dns_wildcard_check", domain="nowild.test", resolver="127.0.0.1",
|
||||
port=wild_port),
|
||||
call(9, "mongodb_config_audit", root="/nonexistent-mg"),
|
||||
call(10, "memcached_config_audit", root="/nonexistent-mc"),
|
||||
call(11, "ntpd_config_audit", root="/nonexistent-nt"),
|
||||
call(12, "dns_wildcard_check", domain="evil.test"),
|
||||
], home=cfg7_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
mg = json.loads(text(by_id[1]))
|
||||
mg_kinds = {f["id"] for f in mg["findings"]}
|
||||
check("mongodb_config_audit flags bind, auth and TLS",
|
||||
{"world-writable", "bind-all", "auth-off", "tls-off"} <= mg_kinds, mg)
|
||||
mg_good = json.loads(text(by_id[2]))
|
||||
check("mongodb_config_audit accepts a hardened config",
|
||||
mg_good["findings_count"] == 0 and
|
||||
mg_good["bind_ip"] == "127.0.0.1" and
|
||||
mg_good["authorization"] == "enabled", mg_good)
|
||||
mc = json.loads(text(by_id[3]))
|
||||
mc_kinds = {f["id"] for f in mc["findings"]}
|
||||
check("memcached_config_audit flags listen, UDP and memory",
|
||||
{"world-writable", "listen-all", "udp-enabled", "memory-large"} <=
|
||||
mc_kinds, mc)
|
||||
mc_good = json.loads(text(by_id[4]))
|
||||
check("memcached_config_audit accepts a hardened config",
|
||||
mc_good["findings_count"] == 0 and mc_good["udp_disabled"] is True and
|
||||
mc_good["listen"] == "127.0.0.1", mc_good)
|
||||
nt = json.loads(text(by_id[5]))
|
||||
nt_kinds = {f["id"] for f in nt["findings"]}
|
||||
check("ntpd_config_audit flags restrict, monitor and temp drift",
|
||||
{"world-writable", "restrict-weak", "monitor-enabled", "temp-path"} <=
|
||||
nt_kinds, nt)
|
||||
nt_good = json.loads(text(by_id[6]))
|
||||
check("ntpd_config_audit accepts a hardened config",
|
||||
nt_good["findings_count"] == 0 and
|
||||
nt_good["monitor_disabled"] is True, nt_good)
|
||||
wild = json.loads(text(by_id[7]))
|
||||
check("dns_wildcard_check detects the wildcard",
|
||||
wild["wildcard"] is True and wild["answer_count"] == 1 and
|
||||
wild["answers"] == ["203.0.113.7"], wild)
|
||||
nowild = json.loads(text(by_id[8]))
|
||||
check("dns_wildcard_check reports a domain without a wildcard",
|
||||
nowild["wildcard"] is False and nowild["answer_count"] == 0, nowild)
|
||||
check("mongodb_config_audit reports a missing config", err(by_id[9]),
|
||||
text(by_id[9]))
|
||||
check("memcached_config_audit reports a missing config", err(by_id[10]),
|
||||
text(by_id[10]))
|
||||
check("ntpd_config_audit reports a missing config", err(by_id[11]),
|
||||
text(by_id[11]))
|
||||
check("dns_wildcard_check refuses an out-of-scope domain", err(by_id[12]),
|
||||
text(by_id[12]))
|
||||
wild_stop.set()
|
||||
wild_sock.close()
|
||||
shutil.rmtree(mg_root, ignore_errors=True)
|
||||
shutil.rmtree(mg_good_root, ignore_errors=True)
|
||||
shutil.rmtree(mc_root, ignore_errors=True)
|
||||
shutil.rmtree(mc_good_root, ignore_errors=True)
|
||||
shutil.rmtree(nt_root, ignore_errors=True)
|
||||
shutil.rmtree(nt_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg7_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