From 4306da88ea0cac727bba20b687e3d0de0677e3be Mon Sep 17 00:00:00 2001 From: lotherk Date: Sat, 21 Nov 2026 21:08:07 +0000 Subject: [PATCH] apex-twin 1.34.0: rsync, DHCPD and Kerberos audits, WebDAV probe Blue: - rsync_audit: rsyncd.conf (root prefix): missing or wildcard hosts allow, uid/gid 0, use chroot = no, a world-readable secrets file and a world-writable config. - dhcpd_audit: dhcpd.conf: authoritative, ddns-update-style none/ad-hoc, missing domain-name-servers, a range outside its subnet and a world-writable config. - krb5_conf_audit: krb5.conf: missing default_realm, dns_lookup_kdc false, rdns true, des/arcfour/rc4 enctypes and a world-writable config. Red: - webdav_probe: OPTIONS plus a Depth: 0 PROPFIND; 207 Multistatus means WebDAV is enabled, the Allow list shows DAV methods, evidence on a hit. Tests with vulnerable and hardened rsync/dhcpd/krb5 trees and a WebDAV HTTP fixture. 855 checks, ASan suite green, analyze clean, release-check green including distcheck 1.34.0. --- CHANGELOG.md | 19 ++- README.md | 19 ++- SECURITY.md | 5 +- docs/apex-twin.1 | 6 +- src/apex.h | 2 +- src/tools_blue.c | 342 ++++++++++++++++++++++++++++++++++++++++++++ src/tools_red.c | 112 +++++++++++++++ tests/gate_audit.py | 2 +- tests/run.py | 173 +++++++++++++++++++++- 9 files changed, 665 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00bf8f4..eb7bdec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.33.0 — 2026-11-21 — this change +## 1.34.0 — 2026-11-21 — this change + +- **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 + world-writable config. +- **DHCP** (`dhcpd_audit`): dhcpd.conf: authoritative, ddns-update-style + none/ad-hoc, missing domain-name-servers, a range that does not belong to its + subnet and a world-writable config. +- **Kerberos** (`krb5_conf_audit`): krb5.conf: missing default_realm, + dns_lookup_kdc false, rdns true, des/arcfour/rc4 enctypes and a + world-writable config. +- **WebDAV** (`webdav_probe`): OPTIONS plus a Depth: 0 PROPFIND; a 207 + Multistatus means WebDAV is enabled, and the Allow list shows the DAV + methods. Evidence is saved on a hit. +- Tests with vulnerable and hardened rsync/dhcpd/krb5 trees and a WebDAV + HTTP fixture. 855 checks. Coverage 81.5%. + +## 1.33.0 — 2026-11-21 — cb8b4ac - **Squid** (`squid_audit`): squid.conf (root prefix): http_access allow all, an http_port on every interface, a cache_dir in /tmp or /dev/shm and a diff --git a/README.md b/README.md index ffccd51..5efc1b9 100644 --- a/README.md +++ b/README.md @@ -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. -**171 tools · 842 end-to-end checks · 340 fuzz cases · 81.4% line coverage · ~680 KiB** +**175 tools · 855 end-to-end checks · 340 fuzz cases · 81.5% line coverage · ~693 KiB** ``` $ ./apex-twin --check -{"version":"1.33.0","tools":171,...,"scope":{"loaded":true,...}} +{"version":"1.34.0","tools":175,...,"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 (171) +## Tools (175) ### Scope and bookkeeping @@ -297,6 +297,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack. | `smtp_starttls_probe` | EHLO/STARTTLS and a real TLS upgrade via openssl s_client -starttls smtp | | `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 | | `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 | @@ -368,6 +369,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack. | `squid_audit` | squid.conf: http_access allow all, open http_port, cache in /tmp, writable config | | `unbound_audit` | unbound.conf: interface all, access-control allow all, missing DNSSEC anchor | | `cups_audit` | cupsd.conf: Listen all, Browsing On, Location Allow All, writable config | +| `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 | ### ESP32 @@ -620,6 +624,8 @@ The full threat model, trust boundaries and a hardening checklist are in | OCSP | one TLS handshake, no responder call | | squid/unbound/cups | config reads only; optional root prefix | | ALPN | one handshake per protocol, no data | +| rsync/dhcpd/krb5 | config reads only; optional root prefix | +| WebDAV | one OPTIONS and one Depth:0 PROPFIND | | USB audit | 200 devices, sysfs reads only | --- @@ -631,7 +637,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus ```sh make # apex-twin -make test # version check + gate audit + 842 end-to-end checks +make test # version check + gate audit + 855 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 @@ -747,7 +753,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery, crlf_probe, dns_version_bind, oidc_discovery, security_txt, http2_probe, ssh_hostkey_fingerprint, kerberos_discovery, winrm_probe, dnssec_check, - smtp_starttls_probe, tls_ocsp_probe, alpn_probe + smtp_starttls_probe, tls_ocsp_probe, alpn_probe, + webdav_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, @@ -790,7 +797,7 @@ examples/ scope.json ## Status -1.33.0. Built and run: 171 tools, 842 checks, 340 fuzz cases and 81.4% line +1.34.0. Built and run: 175 tools, 855 checks, 340 fuzz cases and 81.5% 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 diff --git a/SECURITY.md b/SECURITY.md index 154dd84..c6928e6 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -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.33.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.34.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. +- **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. - **ALPN is one handshake per protocol.** `alpn_probe` never sends application data; squid/unbound/CUPS audits read configuration files. - **OCSP is read from one handshake.** `tls_ocsp_probe` opens one TLS diff --git a/docs/apex-twin.1 b/docs/apex-twin.1 index 3af1a00..85943db 100644 --- a/docs/apex-twin.1 +++ b/docs/apex-twin.1 @@ -1,5 +1,5 @@ .\" apex-twin.1 - manual page for APEX TWIN -.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.33.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.34.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), +ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, integrity_baseline, mitre_map, process_snapshot, persistence_audit, @@ -56,7 +56,7 @@ 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) and ESP32 board tools (esp_info, esp_monitor, +cups_audit, rsync_audit, dhcpd_audit, krb5_conf_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 diff --git a/src/apex.h b/src/apex.h index c785907..66c2644 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.33.0" +#define APEX_VERSION "1.34.0" #define APEX_MAX_OUT (1u << 20) #define APEX_PATH_MAX 512 #define APEX_PATH_FULL 1024 diff --git a/src/tools_blue.c b/src/tools_blue.c index 63393aa..0422f9d 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -8913,6 +8913,327 @@ static void t_cups_audit(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&findings); } +/* ---------------------------------------------------------------- rsync_audit */ + +static void t_rsync_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 hosts_allow[256]; + char uid_value[64]; + char gid_value[64]; + char chroot_value[32]; + char secrets[512]; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int hosts_all = 0; + int secrets_readable = 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/rsyncd.conf", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read rsyncd.conf"); + return; + } + hosts_allow[0] = uid_value[0] = gid_value[0] = chroot_value[0] = '\0'; + secrets[0] = '\0'; + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "rsyncd.conf is writable by anyone"); + count++; + } + if (conf_value(text, "hosts allow", hosts_allow, + sizeof(hosts_allow))) { + if (conf_has_word(hosts_allow, "*") || + strcmp(hosts_allow, "*") == 0) + hosts_all = 1; + } else { + hosts_all = 1; + } + conf_value(text, "uid", uid_value, sizeof(uid_value)); + conf_value(text, "gid", gid_value, sizeof(gid_value)); + conf_value(text, "use chroot", chroot_value, sizeof(chroot_value)); + conf_value(text, "secrets file", secrets, sizeof(secrets)); + if (hosts_all) { + add_finding(&findings, &first, "hosts-allow-all", "high", + "rsync accepts every host (no hosts allow)"); + count++; + } + if (strcmp(uid_value, "0") == 0 || strcmp(uid_value, "root") == 0) { + add_finding(&findings, &first, "uid-root", "high", + "the rsync daemon runs as root"); + count++; + } + if (strcmp(gid_value, "0") == 0 || strcmp(gid_value, "root") == 0) { + add_finding(&findings, &first, "gid-root", "high", + "the rsync daemon runs with the root group"); + count++; + } + if (strcasecmp(chroot_value, "no") == 0) { + add_finding(&findings, &first, "no-chroot", "medium", + "use chroot is disabled"); + count++; + } + if (secrets[0] != '\0') { + char spath[1024]; + struct stat sst; + + if (secrets[0] == '/') + snprintf(spath, sizeof(spath), "%.400s%.500s", root, + secrets); + else + snprintf(spath, sizeof(spath), "%.400s/etc/%.400s", root, + secrets); + if (stat(spath, &sst) == 0 && (sst.st_mode & 0004) != 0) { + add_finding(&findings, &first, "secrets-readable", "high", + "the secrets file is readable by every user"); + secrets_readable = 1; + count++; + } + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_puts(&b, ",\"hosts_allow\":"); + apex_json_str(&b, hosts_allow); + mcp_buf_puts(&b, ",\"uid\":"); + apex_json_str(&b, uid_value); + mcp_buf_puts(&b, ",\"gid\":"); + apex_json_str(&b, gid_value); + mcp_buf_printf(&b, ",\"secrets_readable\":%s,\"findings_count\":%d," + "\"findings\":[", + secrets_readable ? "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); +} + +/* ---------------------------------------------------------------- dhcpd_audit */ + +static void t_dhcpd_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 ddns[64]; + char subnet[64]; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int authoritative = 0; + int no_dns = 1; + int range_mismatch = 0; + int have_subnet = 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/dhcp/dhcpd.conf", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read dhcpd.conf"); + return; + } + ddns[0] = subnet[0] = '\0'; + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "dhcpd.conf is writable by anyone"); + count++; + } + conf_value(text, "ddns-update-style", ddns, sizeof(ddns)); + conf_value(text, "subnet", subnet, sizeof(subnet)); + { + char *copy = strdup(text); + char *save = NULL; + char *line; + char current[64]; + + current[0] = '\0'; + 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, "authoritative", 13) == 0) + authoritative = 1; + if (strstr(t, "option domain-name-servers") != + NULL) + no_dns = 0; + if (strncmp(t, "subnet ", 7) == 0) { + snprintf(current, + sizeof(current), + "%.48s", t + 7); + have_subnet = 1; + } + if (strncmp(t, "range ", 6) == 0 && + have_subnet && + current[0] != '\0') { + char first_ip[64]; + int a1, b1, c1; + int a2, b2, c2; + + if (sscanf(t + 6, + "%63s", + first_ip) == 1 && + sscanf(current, + "%d.%d.%d", + &a1, &b1, &c1) == 3 && + sscanf(first_ip, + "%d.%d.%d", + &a2, &b2, &c2) == 3 && + (a1 != a2 || b1 != b2 || + c1 != c2)) + range_mismatch = 1; + } + } + line = strtok_r(NULL, "\n", &save); + } + free(copy); + } + } + if (authoritative) { + add_finding(&findings, &first, "authoritative", "low", + "the server is authoritative for this network"); + count++; + } + if (strcasecmp(ddns, "none") == 0 || strcasecmp(ddns, "ad-hoc") == 0) { + add_finding(&findings, &first, "ddns-weak", "low", + "dynamic DNS updates are disabled or ad-hoc"); + count++; + } + if (no_dns) { + add_finding(&findings, &first, "no-dns-option", "low", + "no domain-name-servers option is set"); + count++; + } + if (range_mismatch) { + add_finding(&findings, &first, "range-mismatch", "medium", + "a range does not belong to its subnet"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"authoritative\":%s,\"ddns_update_style\":", + authoritative ? "true" : "false"); + apex_json_str(&b, ddns); + 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); +} + +/* ----------------------------------------------------------- krb5_conf_audit */ + +static void t_krb5_conf_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 realm[256]; + char dns_lookup[32]; + char rdns[32]; + char enctypes[512]; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int weak_enctype = 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/krb5.conf", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read krb5.conf"); + return; + } + realm[0] = dns_lookup[0] = rdns[0] = enctypes[0] = '\0'; + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "krb5.conf is writable by anyone"); + count++; + } + conf_value(text, "default_realm", realm, sizeof(realm)); + conf_value(text, "dns_lookup_kdc", dns_lookup, sizeof(dns_lookup)); + conf_value(text, "rdns", rdns, sizeof(rdns)); + conf_value(text, "default_tgs_enctypes", enctypes, sizeof(enctypes)); + if (realm[0] == '\0') { + add_finding(&findings, &first, "no-realm", "low", + "no default_realm is configured"); + count++; + } + if (strcasecmp(dns_lookup, "false") == 0) { + add_finding(&findings, &first, "dns-lookup-off", "medium", + "KDC discovery through DNS is disabled"); + count++; + } + if (strcasecmp(rdns, "true") == 0) { + add_finding(&findings, &first, "rdns-on", "low", + "reverse DNS lookups are enabled"); + count++; + } + if (enctypes[0] != '\0' && + (strstr(enctypes, "des") != NULL || + strstr(enctypes, "arcfour") != NULL || + strstr(enctypes, "rc4") != NULL)) { + add_finding(&findings, &first, "weak-enctype", "high", + "legacy Kerberos encryption types are enabled"); + weak_enctype = 1; + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_puts(&b, ",\"default_realm\":"); + apex_json_str(&b, realm); + mcp_buf_puts(&b, ",\"dns_lookup_kdc\":"); + apex_json_str(&b, dns_lookup); + mcp_buf_puts(&b, ",\"rdns\":"); + apex_json_str(&b, rdns); + mcp_buf_printf(&b, ",\"weak_enctype\":%s,\"findings_count\":%d," + "\"findings\":[", + weak_enctype ? "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, " @@ -9396,6 +9717,27 @@ const mcp_tool TOOLS_BLUE[] = { "{\"type\":\"object\",\"properties\":{" "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", t_cups_audit }, + { "rsync_audit", + "Parse rsyncd.conf (root prefix): missing or wildcard hosts allow, " + "uid/gid 0, use chroot = no, a world-readable secrets file and a " + "world-writable config. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_rsync_audit }, + { "dhcpd_audit", + "Parse dhcpd.conf (root prefix): authoritative, ddns-update-style " + "none/ad-hoc, missing domain-name-servers, a range outside its subnet " + "and a world-writable config. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_dhcpd_audit }, + { "krb5_conf_audit", + "Parse krb5.conf (root prefix): missing default_realm, dns_lookup_kdc " + "false, rdns true, legacy enctypes (des/arcfour/rc4) and a " + "world-writable config. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_krb5_conf_audit }, }; const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]); diff --git a/src/tools_red.c b/src/tools_red.c index 883bbc0..9a31e59 100644 --- a/src/tools_red.c +++ b/src/tools_red.c @@ -5201,6 +5201,107 @@ static void t_dnssec_check(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&records); } +/* --------------------------------------------------------------- webdav_probe */ + +static void t_webdav_probe(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *target = mcp_arg_string(args, "target"); + const char *path = mcp_arg_string(args, "path"); + int port = mcp_arg_int(args, "port", 80); + int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port)); + static const char body[] = + "" + ""; + char status[256]; + char allow[512]; + char *resp = NULL; + size_t len = 0; + int options_code = 0; + int propfind_code = 0; + int dav = 0; + int allow_dav = 0; + char *evidence = NULL; + mcp_buf b; + + (void)user; + if (target == NULL || *target == '\0') { + mcp_reply_error(c, "target is required"); + return; + } + if (path == NULL || *path == '\0') + path = "/"; + if (path[0] != '/') { + mcp_reply_error(c, "path must start with /"); + return; + } + if (!gated(c, "webdav_probe", target, port)) + return; + allow[0] = '\0'; + status[0] = '\0'; + if (apex_http_once(target, port, tls, "OPTIONS", path, NULL, NULL, 8000, + &resp, &len, status, sizeof(status)) == 0) { + options_code = apex_status_code(status); + response_header(resp, len, "Allow", allow, sizeof(allow)); + if (allow_has(allow, "PROPFIND") || allow_has(allow, "MKCOL") || + allow_has(allow, "COPY")) + allow_dav = 1; + free(resp); + resp = NULL; + } + status[0] = '\0'; + if (apex_http_once(target, port, tls, "PROPFIND", path, body, + "Depth: 0\r\nContent-Type: application/xml\r\n", + 10000, &resp, &len, status, sizeof(status)) == 0) { + propfind_code = apex_status_code(status); + if (propfind_code == 207 || + find_bytes(resp, len, "multistatus")) + dav = 1; + if (dav) + evidence = apex_evidence_save("webdav", resp, len); + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"target\":"); + apex_json_str(&b, target); + mcp_buf_printf(&b, ",\"port\":%d,\"path\":", port); + apex_json_str(&b, path); + mcp_buf_printf(&b, ",\"options_status\":%d,\"propfind_status\":%d," + "\"webdav\":%s,\"allow_dav_methods\":%s,\"allow\":[", + options_code, propfind_code, dav ? "true" : "false", + allow_dav ? "true" : "false"); + { + char copy[512]; + char *save = NULL; + char *tok; + int first = 1; + + snprintf(copy, sizeof(copy), "%s", allow); + tok = strtok_r(copy, ",", &save); + while (tok != NULL) { + while (*tok == ' ' || *tok == '\t') + tok++; + if (*tok != '\0') { + if (!first) + mcp_buf_puts(&b, ","); + first = 0; + apex_json_str(&b, tok); + } + tok = strtok_r(NULL, ",", &save); + } + } + mcp_buf_puts(&b, "],\"evidence\":"); + if (evidence != NULL) + apex_json_str(&b, evidence); + else + mcp_buf_puts(&b, "null"); + mcp_buf_puts(&b, "}"); + apex_audit("webdav_probe", target, port, !dav, + dav ? "WebDAV is enabled" : "no WebDAV", path); + mcp_reply_json(c, b.p); + mcp_buf_free(&b); + free(evidence); + free(resp); +} + const mcp_tool TOOLS_RED[] = { { "vuln_check", "Non-destructive verification of exposed artifacts on one web target: " @@ -5646,6 +5747,17 @@ const mcp_tool TOOLS_RED[] = { "\"port\":{\"type\":\"integer\",\"description\":\"dig -p, default 0\"}}," "\"required\":[\"domain\"]}", t_dnssec_check }, + { "webdav_probe", + "Send OPTIONS and a Depth: 0 PROPFIND to one path: a 207 Multistatus or " + "a multistatus body means WebDAV is enabled; the Allow list shows " + "PROPFIND/MKCOL/COPY. Evidence is saved on a hit. Gate: target in scope.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 80\"}," + "\"path\":{\"type\":\"string\",\"description\":\"default /\"}," + "\"tls\":{\"type\":\"boolean\"}}," + "\"required\":[\"target\"]}", + t_webdav_probe }, }; const size_t TOOLS_RED_N = sizeof(TOOLS_RED) / sizeof(TOOLS_RED[0]); diff --git a/tests/gate_audit.py b/tests/gate_audit.py index c8e2866..4b74f24 100755 --- a/tests/gate_audit.py +++ b/tests/gate_audit.py @@ -21,7 +21,7 @@ import re import sys HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -EXPECTED_TOOLS = 171 +EXPECTED_TOOLS = 175 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. diff --git a/tests/run.py b/tests/run.py index 54d2977..7bc5c42 100755 --- a/tests/run.py +++ b/tests/run.py @@ -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("171 tools registered", len(tools) == 171, len(tools)) +check("175 tools registered", len(tools) == 175, 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"]) == 171) + check("http tools/list", len(listing["result"]["tools"]) == 175) 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 @@ -7724,6 +7724,175 @@ shutil.rmtree(cu_good_root, ignore_errors=True) shutil.rmtree(alpn_dir, ignore_errors=True) shutil.rmtree(cfg5_home, ignore_errors=True) +print("\n== rsync, DHCPD, Kerberos and WebDAV ==\n") + +rs_root = tempfile.mkdtemp(prefix="apex-rs-") +os.makedirs(os.path.join(rs_root, "etc")) +rs_bad = os.path.join(rs_root, "etc", "rsyncd.conf") +with open(rs_bad, "w") as f: + f.write("uid = 0\n") + f.write("gid = 0\n") + f.write("use chroot = no\n") + f.write("hosts allow = *\n") + f.write("secrets file = /etc/rsyncd.secrets\n") +os.chmod(rs_bad, 0o666) +with open(os.path.join(rs_root, "etc", "rsyncd.secrets"), "w") as f: + f.write("alice:secret\n") +os.chmod(os.path.join(rs_root, "etc", "rsyncd.secrets"), 0o644) +rs_good_root = tempfile.mkdtemp(prefix="apex-rsg-") +os.makedirs(os.path.join(rs_good_root, "etc")) +with open(os.path.join(rs_good_root, "etc", "rsyncd.conf"), "w") as f: + f.write("uid = nobody\n") + f.write("gid = nogroup\n") + f.write("use chroot = yes\n") + f.write("hosts allow = 127.0.0.1\n") + +dh_root = tempfile.mkdtemp(prefix="apex-dh-") +os.makedirs(os.path.join(dh_root, "etc", "dhcp")) +dh_bad = os.path.join(dh_root, "etc", "dhcp", "dhcpd.conf") +with open(dh_bad, "w") as f: + f.write("authoritative;\n") + f.write("ddns-update-style none;\n") + f.write("subnet 10.0.0.0 netmask 255.255.255.0 {\n") + f.write(" range 192.168.1.10 192.168.1.20;\n}\n") +os.chmod(dh_bad, 0o666) +dh_good_root = tempfile.mkdtemp(prefix="apex-dhg-") +os.makedirs(os.path.join(dh_good_root, "etc", "dhcp")) +with open(os.path.join(dh_good_root, "etc", "dhcp", "dhcpd.conf"), + "w") as f: + f.write("ddns-update-style interim;\n") + f.write("option domain-name-servers 10.0.0.53;\n") + f.write("subnet 10.0.0.0 netmask 255.255.255.0 {\n") + f.write(" range 10.0.0.10 10.0.0.20;\n}\n") + +kb_root = tempfile.mkdtemp(prefix="apex-kb-") +os.makedirs(os.path.join(kb_root, "etc")) +kb_bad = os.path.join(kb_root, "etc", "krb5.conf") +with open(kb_bad, "w") as f: + f.write("[libdefaults]\n") + f.write(" default_realm = EXAMPLE.TEST\n") + f.write(" dns_lookup_kdc = false\n") + f.write(" rdns = true\n") + f.write(" default_tgs_enctypes = des3-cbc-sha1 arcfour-hmac\n") +os.chmod(kb_bad, 0o666) +kb_good_root = tempfile.mkdtemp(prefix="apex-kbg-") +os.makedirs(os.path.join(kb_good_root, "etc")) +with open(os.path.join(kb_good_root, "etc", "krb5.conf"), "w") as f: + f.write("[libdefaults]\n") + f.write(" default_realm = EXAMPLE.TEST\n") + f.write(" dns_lookup_kdc = true\n") + f.write(" rdns = false\n") + f.write(" default_tgs_enctypes = aes256-cts-hmac-sha1-96\n") + + +class _DavHandler(http.server.BaseHTTPRequestHandler): + def do_OPTIONS(self): + path = urllib.parse.urlsplit(self.path).path + self.send_response(200) + if path == "/dav": + self.send_header("Allow", "OPTIONS, PROPFIND, GET, MKCOL") + else: + self.send_header("Allow", "GET, HEAD") + self.send_header("Content-Length", "0") + self.end_headers() + + def do_PROPFIND(self): + path = urllib.parse.urlsplit(self.path).path + if path == "/dav": + body = (b'') + self.send_response(207) + else: + body = b"method not allowed" + self.send_response(405) + self.send_header("Content-Type", "application/xml") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +dav_srv = http.server.HTTPServer(("127.0.0.1", 0), _DavHandler) +dav_port = dav_srv.server_address[1] +threading.Thread(target=dav_srv.serve_forever, daemon=True).start() + +cfg6_home = tempfile.mkdtemp(prefix="apex-cfg6-home-") +write_scope(cfg6_home, {"label": "cfg6", "expires": "2099-12-31T23:59:59Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_port": [str(dav_port)]}) +res, _ = run([ + call(1, "rsync_audit", root=rs_root), + call(2, "rsync_audit", root=rs_good_root), + call(3, "dhcpd_audit", root=dh_root), + call(4, "dhcpd_audit", root=dh_good_root), + call(5, "krb5_conf_audit", root=kb_root), + call(6, "krb5_conf_audit", root=kb_good_root), + call(7, "webdav_probe", target="127.0.0.1", port=dav_port, + path="/dav", tls=False), + call(8, "webdav_probe", target="127.0.0.1", port=dav_port, + path="/plain", tls=False), + call(9, "rsync_audit", root="/nonexistent-rs"), + call(10, "dhcpd_audit", root="/nonexistent-dh"), + call(11, "krb5_conf_audit", root="/nonexistent-kb"), + call(12, "webdav_probe", target="198.51.100.9", port=80, path="/dav"), +], home=cfg6_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("rsync_audit flags root, wildcard hosts and secrets", + {"uid-root", "gid-root", "hosts-allow-all", "no-chroot", + "secrets-readable", "world-writable"} <= rs_kinds, rs) +rs_good = json.loads(text(by_id[2])) +check("rsync_audit accepts a hardened config", + rs_good["findings_count"] == 0 and rs_good["hosts_allow"] == "127.0.0.1", + rs_good) +dh = json.loads(text(by_id[3])) +dh_kinds = {f["id"] for f in dh["findings"]} +check("dhcpd_audit flags authoritative, ddns, DNS and range", + {"authoritative", "ddns-weak", "no-dns-option", "range-mismatch", + "world-writable"} <= dh_kinds, dh) +dh_good = json.loads(text(by_id[4])) +check("dhcpd_audit accepts a hardened config", + dh_good["findings_count"] == 0 and + dh_good["ddns_update_style"] == "interim", dh_good) +kb = json.loads(text(by_id[5])) +kb_kinds = {f["id"] for f in kb["findings"]} +check("krb5_conf_audit flags DNS lookup, rdns and legacy enctypes", + {"dns-lookup-off", "rdns-on", "weak-enctype", "world-writable"} <= + kb_kinds, kb) +kb_good = json.loads(text(by_id[6])) +check("krb5_conf_audit accepts a hardened config", + kb_good["findings_count"] == 0 and + kb_good["weak_enctype"] is False, kb_good) +dav = json.loads(text(by_id[7])) +check("webdav_probe detects WebDAV", + dav["webdav"] is True and dav["propfind_status"] == 207 and + dav["allow_dav_methods"] is True, dav) +check("webdav_probe keeps the 207 response as evidence", + dav["evidence"] and os.path.isfile(dav["evidence"]), dav) +dav_plain = json.loads(text(by_id[8])) +check("webdav_probe stays quiet on a plain endpoint", + dav_plain["webdav"] is False and dav_plain["propfind_status"] == 405, + dav_plain) +check("rsync_audit reports a missing config", err(by_id[9]), text(by_id[9])) +check("dhcpd_audit reports a missing config", err(by_id[10]), + text(by_id[10])) +check("krb5_conf_audit reports a missing config", err(by_id[11]), + text(by_id[11])) +check("webdav_probe refuses an out-of-scope target", err(by_id[12]), + text(by_id[12])) +dav_srv.shutdown() +dav_srv.server_close() +shutil.rmtree(rs_root, ignore_errors=True) +shutil.rmtree(rs_good_root, ignore_errors=True) +shutil.rmtree(dh_root, ignore_errors=True) +shutil.rmtree(dh_good_root, ignore_errors=True) +shutil.rmtree(kb_root, ignore_errors=True) +shutil.rmtree(kb_good_root, ignore_errors=True) +shutil.rmtree(cfg6_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"})