diff --git a/CHANGELOG.md b/CHANGELOG.md index 3646319..7d3c7fc 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.47.0 — 2026-11-23 — this change +## 1.48.0 — 2026-11-23 — this change + +- **Avahi** (`avahi_audit`): `avahi-daemon.conf`: `publish-workstation`, + `publish-addresses`, a missing or wildcard `allow-interfaces` and a + world-writable file. +- **logind** (`logind_audit`): `logind.conf`: `IdleAction=ignore`, + `HandleLidSwitch=ignore`, `IdleActionSec=0`, `KillUserProcesses=no` and a + world-writable file. +- **tftpd-hpa** (`tftpd_hpa_audit`): the Debian defaults: `--create`, a + missing `--secure`, a TFTP directory of `/`, a world-writable directory and + a world-writable file. +- **ZooKeeper 4lw** (`zookeeper_4lw_probe`): sends the four-letter commands + `stat` and `mntr`; any answer without authentication leaks the version and + connection state. +- Tests with avahi/logind/tftpd trees and two ZooKeeper servers (commands + answered and refused). 1035 checks. Coverage 83.0%. + +## 1.47.0 — 2026-11-23 — 5c028a6 - **pgbouncer** (`pgbouncer_audit`): `pgbouncer.ini`: `auth_type` trust or plain, `listen_addr` on every interface, an `auth_file` readable beyond its diff --git a/README.md b/README.md index 7c94f9a..17c135f 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. -**226 tools · 1023 end-to-end checks · 340 fuzz cases · 83.0% line coverage · ~838 KiB** +**230 tools · 1035 end-to-end checks · 340 fuzz cases · 83.0% line coverage · ~842 KiB** ``` $ ./apex-twin --check -{"version":"1.47.0","tools":226,...,"scope":{"loaded":true,...}} +{"version":"1.48.0","tools":230,...,"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 (226) +## Tools (230) ### Scope and bookkeeping @@ -206,6 +206,7 @@ uploads and secret-file reads. It does not execute anything. | `hsts_audit` | HSTS max-age, includeSubDomains and preload, or a missing header | | `tls_hostname_check` | SAN/CN wildcard match for the requested SNI name | | `ftp_tls_probe` | `AUTH TLS` -> 234 means explicit FTPS; otherwise cleartext | +| `zookeeper_4lw_probe` | `stat`/`mntr` answered without auth leaks version and state | | `cookie_audit` | Secure/HttpOnly/SameSite per cookie, incl. `SameSite=None` without Secure | | `http_options` | `Allow`/`Public`; flags TRACE, PUT, DELETE | | `sqli_probe` | Quote and boolean payloads; differing answers are a **lead**, not proof | @@ -423,6 +424,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack. | `pgbouncer_audit` | pgbouncer.ini: trust auth, wildcard listen, readable auth file | | `xinetd_audit` | xinetd: telnet/ftp/rsh enabled, no only_from, service as root | | `sssd_audit` | sssd.conf: enumerate, cache_credentials, StartTLS off, reqcert never | +| `avahi_audit` | avahi-daemon.conf: workstation/address publication, no interface limit | +| `logind_audit` | logind.conf: idle ignore, lid ignore, IdleActionSec=0 | +| `tftpd_hpa_audit` | tftpd-hpa: `--create`, missing `--secure`, root directory | ### ESP32 @@ -705,6 +709,8 @@ The full threat model, trust boundaries and a hardening checklist are in | TLS hostname | one handshake with the name as SNI | | pgbouncer/xinetd/sssd | config reads only; optional root prefix | | FTP TLS | banner plus one AUTH TLS command, no login | +| avahi/logind/tftpd-hpa | config reads only; optional root prefix | +| ZooKeeper 4lw | two four-byte commands, no auth, no data | | USB audit | 200 devices, sysfs reads only | --- @@ -716,7 +722,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus ```sh make # apex-twin -make test # version check + gate audit + 1023 end-to-end checks +make test # version check + gate audit + 1035 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 @@ -839,7 +845,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery, dns_dangling_cname, http_redirect_audit, websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, - tls_hostname_check, ftp_tls_probe + tls_hostname_check, ftp_tls_probe, + zookeeper_4lw_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, @@ -882,7 +889,7 @@ examples/ scope.json ## Status -1.47.0. Built and run: 226 tools, 1023 checks, 340 fuzz cases and 83.0% line +1.48.0. Built and run: 230 tools, 1035 checks, 340 fuzz cases and 83.0% 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 bcb3489..f8931c5 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.47.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.48.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current line. The 1.0 line promises that the on-disk JSON formats for findings, assets and traffic only gain fields, so state stays readable; older builds are still rebuilt rather than patched in place. @@ -66,6 +66,8 @@ only narrow what the proxy does (the scope gate still runs first). - **Firmware writing needs an explicit confirmation.** `esp_flash` refuses without `confirm=true`, validates an absolute image path and audits the attempt; it exists to provision the operator's own board. +- **Avahi, logind and tftpd-hpa audits read local files.** The ZooKeeper + probe sends only the stat and mntr four-letter commands, no data. - **pgbouncer, xinetd and SSSD audits read local files.** The FTP TLS probe reads the banner and sends AUTH TLS without logging in. - **dnsmasq, nsswitch and Jenkins audits read local files.** The TLS diff --git a/docs/apex-twin.1 b/docs/apex-twin.1 index c07616b..66d0a46 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.47.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.48.0" "User Commands" .SH NAME apex-twin \- scope\-gated offensive\-security MCP server .SH SYNOPSIS @@ -46,7 +46,7 @@ sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk, ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe, dns_ns_consistency, dns_dangling_cname, http_redirect_audit, websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit, -websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe), +websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, integrity_baseline, mitre_map, process_snapshot, persistence_audit, @@ -68,7 +68,8 @@ ipsec_config_audit, openldap_config_audit, cron_audit, fail2ban_audit, chrony_co apt_config_audit, login_defs_audit, pg_hba_audit, polkit_audit, ldap_client_audit, ssl_cert_audit, timesyncd_audit, resolv_conf_audit, journald_audit, coredump_audit, nftables_audit, dnsmasq_audit, nsswitch_audit, -jenkins_audit, pgbouncer_audit, xinetd_audit, sssd_audit) +jenkins_audit, pgbouncer_audit, xinetd_audit, sssd_audit, avahi_audit, logind_audit, +tftpd_hpa_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). diff --git a/src/apex.h b/src/apex.h index 6d087d4..6e8c723 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.47.0" +#define APEX_VERSION "1.48.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 1c676d4..623b334 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -14057,6 +14057,268 @@ static void t_sssd_audit(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&findings); } +/* ---------------------------------------------------------------- avahi_audit */ + +static void t_avahi_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + static char text[65536]; + char value[128]; + char allow[256]; + struct stat st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int workstation = 0; + int addresses = 0; + int no_allow = 0; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + snprintf(path, sizeof(path), "%s/etc/avahi/avahi-daemon.conf", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read avahi-daemon.conf"); + return; + } + allow[0] = '\0'; + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "avahi-daemon.conf is writable by anyone"); + count++; + } + if (ini_value(text, "server", "publish-workstation", value, + sizeof(value)) && + strcasecmp(value, "yes") == 0) { + workstation = 1; + add_finding(&findings, &first, "publish-workstation", "low", + "the workstation name is announced over mDNS"); + count++; + } + if (ini_value(text, "server", "publish-addresses", value, + sizeof(value)) && + strcasecmp(value, "yes") == 0) { + addresses = 1; + add_finding(&findings, &first, "publish-addresses", "low", + "every interface address is announced"); + count++; + } + if (ini_value(text, "server", "allow-interfaces", allow, + sizeof(allow))) { + if (strcmp(allow, "*") == 0) { + no_allow = 1; + add_finding(&findings, &first, "no-allow-interfaces", + "medium", + "mDNS is allowed on every interface"); + count++; + } + } else { + no_allow = 1; + add_finding(&findings, &first, "no-allow-interfaces", "medium", + "no allow-interfaces restriction is configured"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"publish_workstation\":%s," + "\"publish_addresses\":%s,\"interfaces_restricted\":%s," + "\"findings_count\":%d,\"findings\":[", + workstation ? "true" : "false", + addresses ? "true" : "false", + no_allow ? "false" : "true", 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); +} + +/* --------------------------------------------------------------- logind_audit */ + +static void t_logind_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + static char text[65536]; + char value[64]; + struct stat st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int idle_ignore = 0; + int lid_ignore = 0; + int idle_zero = 0; + int kill_no = 0; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + snprintf(path, sizeof(path), "%s/etc/systemd/logind.conf", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read logind.conf"); + return; + } + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "logind.conf is writable by anyone"); + count++; + } + if (ini_value(text, "Login", "IdleAction", value, sizeof(value)) && + strcasecmp(value, "ignore") == 0) { + idle_ignore = 1; + add_finding(&findings, &first, "idle-action", "low", + "an idle session is never locked"); + count++; + } + if (ini_value(text, "Login", "HandleLidSwitch", value, + sizeof(value)) && + strcasecmp(value, "ignore") == 0) { + lid_ignore = 1; + add_finding(&findings, &first, "lid-switch", "low", + "closing the lid does not suspend"); + count++; + } + if (ini_value(text, "Login", "IdleActionSec", value, + sizeof(value)) && + (strcmp(value, "0") == 0 || strcmp(value, "0s") == 0)) { + idle_zero = 1; + add_finding(&findings, &first, "idle-sec", "low", + "IdleActionSec is zero"); + count++; + } + if (ini_value(text, "Login", "KillUserProcesses", value, + sizeof(value)) && + strcasecmp(value, "no") == 0) { + kill_no = 1; + add_finding(&findings, &first, "kill-user-processes", "low", + "processes survive a logout"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"idle_ignore\":%s,\"lid_ignore\":%s," + "\"idle_sec_zero\":%s,\"kill_user_processes\":%s," + "\"findings_count\":%d,\"findings\":[", + idle_ignore ? "true" : "false", + lid_ignore ? "true" : "false", + idle_zero ? "true" : "false", + kill_no ? "false" : "true", 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); +} + +/* ------------------------------------------------------------ tftpd_hpa_audit */ + +static void t_tftpd_hpa_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + char dir_path[1200]; + static char text[65536]; + char directory[512]; + char options[512]; + struct stat st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int create = 0; + int no_secure = 0; + int root_dir = 0; + int writable_dir = 0; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + snprintf(path, sizeof(path), "%s/etc/default/tftpd-hpa", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read tftpd-hpa defaults"); + return; + } + directory[0] = options[0] = '\0'; + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "the tftpd-hpa defaults are writable by anyone"); + count++; + } + conf_value(text, "TFTP_DIRECTORY", directory, sizeof(directory)); + conf_value(text, "TFTP_OPTIONS", options, sizeof(options)); + if (strstr(options, "--create") != NULL) { + create = 1; + add_finding(&findings, &first, "create-enabled", "high", + "clients may create new files"); + count++; + } + if (strstr(options, "--secure") == NULL) { + no_secure = 1; + add_finding(&findings, &first, "no-secure", "medium", + "TFTP runs without --secure"); + count++; + } + if (directory[0] == '\0' || strcmp(directory, "/") == 0) { + root_dir = 1; + add_finding(&findings, &first, "root-directory", "high", + "the TFTP root is the filesystem root"); + count++; + } else if (directory[0] == '/') { + snprintf(dir_path, sizeof(dir_path), "%.400s%s", root, + directory); + if (stat(dir_path, &st) == 0 && S_ISDIR(st.st_mode) && + (st.st_mode & 0002) != 0) { + writable_dir = 1; + add_finding(&findings, &first, "writable-directory", + "high", + "the TFTP directory is writable by anyone"); + count++; + } + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_puts(&b, ",\"directory\":"); + apex_json_str(&b, directory); + mcp_buf_puts(&b, ",\"options\":"); + apex_json_str(&b, options); + mcp_buf_printf(&b, ",\"create\":%s,\"secure\":%s,\"root_dir\":%s," + "\"writable_dir\":%s,\"findings_count\":%d," + "\"findings\":[", + create ? "true" : "false", + no_secure ? "false" : "true", + root_dir ? "true" : "false", + writable_dir ? "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, " @@ -14822,6 +15084,27 @@ const mcp_tool TOOLS_BLUE[] = { "{\"type\":\"object\",\"properties\":{" "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", t_sssd_audit }, + { "avahi_audit", + "Parse avahi-daemon.conf (root prefix): publish-workstation, " + "publish-addresses, a missing or wildcard allow-interfaces and a " + "world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_avahi_audit }, + { "logind_audit", + "Parse logind.conf (root prefix): IdleAction=ignore, " + "HandleLidSwitch=ignore, IdleActionSec=0, KillUserProcesses=no and a " + "world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_logind_audit }, + { "tftpd_hpa_audit", + "Parse tftpd-hpa defaults (root prefix): --create, a missing --secure, " + "a filesystem-root TFTP directory, a world-writable directory and a " + "world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_tftpd_hpa_audit }, }; const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]); diff --git a/src/tools_proto.c b/src/tools_proto.c index 1d18efb..a887cc1 100644 --- a/src/tools_proto.c +++ b/src/tools_proto.c @@ -6004,6 +6004,112 @@ static void t_ftp_tls_probe(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&b); } +/* ------------------------------------------------------- zookeeper_4lw_probe */ + +static int zk_read_once(int fd, char *buf, size_t cap) +{ + struct timeval tv; + ssize_t r; + + tv.tv_sec = 2; + tv.tv_usec = 0; + setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + r = recv(fd, buf, cap - 1, 0); + if (r <= 0) { + buf[0] = '\0'; + return 0; + } + buf[r] = '\0'; + return (int)r; +} + +static void t_zookeeper_4lw_probe(mcp_conn *c, const mcp_json *args, + void *user) +{ + const char *target = mcp_arg_string(args, "target"); + int port = mcp_arg_int(args, "port", 2181); + char stat[4096]; + char mntr[4096]; + char version[128]; + int stat_len; + int mntr_len; + int open; + int fd; + mcp_buf b; + + (void)user; + if (target == NULL || *target == '\0') { + mcp_reply_error(c, "target is required"); + return; + } + if (port <= 0 || port > 65535) { + mcp_reply_error(c, "port out of range"); + return; + } + if (!gated(c, "zookeeper_4lw_probe", target, port)) + return; + fd = tcp_connect_host(target, port, 8000); + if (fd < 0) { + mcp_reply_error(c, "cannot connect to the ZooKeeper client port"); + return; + } + stat[0] = mntr[0] = version[0] = '\0'; + stat_len = mntr_len = 0; + if (write_all(fd, "stat") == 0) + stat_len = zk_read_once(fd, stat, sizeof(stat)); + if (write_all(fd, "mntr") == 0) + mntr_len = zk_read_once(fd, mntr, sizeof(mntr)); + close(fd); + open = stat_len > 0 || mntr_len > 0; + { + const char *p = strstr(stat, "Zookeeper version:"); + + if (p != NULL) { + const char *v = p + 18; + size_t k = 0; + + while (*v == ' ' || *v == '\t') + v++; + while (v[k] != '\0' && v[k] != '\n' && v[k] != '\r' && + k + 1 < sizeof(version)) { + version[k] = v[k]; + k++; + } + version[k] = '\0'; + } + if (version[0] == '\0') { + p = strstr(mntr, "zk_version\t"); + + if (p != NULL) { + const char *v = p + 11; + size_t k = 0; + + while (v[k] != '\0' && v[k] != '\n' && + v[k] != '\r' && k + 1 < sizeof(version)) { + version[k] = v[k]; + k++; + } + version[k] = '\0'; + } + } + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"target\":"); + apex_json_str(&b, target); + mcp_buf_printf(&b, ",\"port\":%d,\"stat_bytes\":%d," + "\"mntr_bytes\":%d,\"version\":", port, stat_len, + mntr_len); + apex_json_str(&b, version); + mcp_buf_printf(&b, ",\"four_letter_open\":%s}", + open ? "true" : "false"); + apex_audit("zookeeper_4lw_probe", target, port, !open, + open ? "stat/mntr answer without authentication" + : "four-letter commands are not exposed", + "stat and mntr"); + mcp_reply_json(c, b.p); + mcp_buf_free(&b); +} + const mcp_tool TOOLS_PROTO[] = { { "ftp_probe", "One-connection FTP check: read the 220 banner, ask FEAT, then try the " @@ -6025,6 +6131,15 @@ const mcp_tool TOOLS_PROTO[] = { "\"port\":{\"type\":\"integer\",\"description\":\"default 21\"}}," "\"required\":[\"target\"]}", t_ftp_tls_probe }, + { "zookeeper_4lw_probe", + "Open the ZooKeeper client port and send the four-letter commands stat " + "and mntr. Any answer without authentication leaks the version and " + "connection state. Gate: the target.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 2181\"}}," + "\"required\":[\"target\"]}", + t_zookeeper_4lw_probe }, { "smtp_probe", "One-connection SMTP check: read the 220 banner, send EHLO and list the " "advertised extensions (STARTTLS, AUTH, SIZE, ...), then VRFY a small " diff --git a/tests/gate_audit.py b/tests/gate_audit.py index 4291742..86b3db3 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 = 226 +EXPECTED_TOOLS = 230 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 2ca6085..04454d6 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("226 tools registered", len(tools) == 226, len(tools)) +check("230 tools registered", len(tools) == 230, 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"]) == 226) + check("http tools/list", len(listing["result"]["tools"]) == 230) 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 @@ -10403,6 +10403,161 @@ shutil.rmtree(sssd_root, ignore_errors=True) shutil.rmtree(sssd_good_root, ignore_errors=True) shutil.rmtree(cfg19_home, ignore_errors=True) +print("\n== avahi, logind, tftpd-hpa and ZooKeeper 4lw ==\n") + +av_root = tempfile.mkdtemp(prefix="apex-av-") +os.makedirs(os.path.join(av_root, "etc", "avahi")) +av_bad = os.path.join(av_root, "etc", "avahi", "avahi-daemon.conf") +with open(av_bad, "w") as f: + f.write("[server]\n") + f.write("publish-workstation=yes\n") + f.write("publish-addresses=yes\n") +os.chmod(av_bad, 0o666) +av_good_root = tempfile.mkdtemp(prefix="apex-avg-") +os.makedirs(os.path.join(av_good_root, "etc", "avahi")) +with open(os.path.join(av_good_root, "etc", "avahi", "avahi-daemon.conf"), + "w") as f: + f.write("[server]\n") + f.write("allow-interfaces=eth0\n") + f.write("publish-workstation=no\n") + f.write("publish-addresses=no\n") + +lg_root = tempfile.mkdtemp(prefix="apex-lg-") +os.makedirs(os.path.join(lg_root, "etc", "systemd")) +lg_bad = os.path.join(lg_root, "etc", "systemd", "logind.conf") +with open(lg_bad, "w") as f: + f.write("[Login]\n") + f.write("IdleAction=ignore\n") + f.write("HandleLidSwitch=ignore\n") + f.write("IdleActionSec=0\n") + f.write("KillUserProcesses=no\n") +os.chmod(lg_bad, 0o666) +lg_good_root = tempfile.mkdtemp(prefix="apex-lgg-") +os.makedirs(os.path.join(lg_good_root, "etc", "systemd")) +with open(os.path.join(lg_good_root, "etc", "systemd", "logind.conf"), + "w") as f: + f.write("[Login]\n") + f.write("IdleAction=lock\n") + f.write("HandleLidSwitch=suspend\n") + f.write("IdleActionSec=300\n") + f.write("KillUserProcesses=yes\n") + +tf_root = tempfile.mkdtemp(prefix="apex-tf-") +os.makedirs(os.path.join(tf_root, "etc", "default")) +tf_bad = os.path.join(tf_root, "etc", "default", "tftpd-hpa") +with open(tf_bad, "w") as f: + f.write('TFTP_USERNAME="tftp"\n') + f.write('TFTP_DIRECTORY="/"\n') + f.write('TFTP_OPTIONS="--create"\n') +os.chmod(tf_bad, 0o666) +tf_good_root = tempfile.mkdtemp(prefix="apex-tfg-") +os.makedirs(os.path.join(tf_good_root, "etc", "default")) +os.makedirs(os.path.join(tf_good_root, "srv", "tftp")) +with open(os.path.join(tf_good_root, "etc", "default", "tftpd-hpa"), + "w") as f: + f.write('TFTP_DIRECTORY="/srv/tftp"\n') + f.write('TFTP_OPTIONS="--secure"\n') + + +def zk_handler(exposed): + def handle(conn): + while True: + cmd = conn.recv(4) + if len(cmd) < 4: + return + if not exposed: + return + if cmd == b"stat": + conn.sendall(b"Zookeeper version: 3.8.0-test\n" + b"Clients:\n\nLatency min/avg/max: 0/0/0\n") + elif cmd == b"mntr": + conn.sendall(b"zk_version\t3.8.0-test\n" + b"zk_avg_latency\t0\n") + else: + conn.sendall(b"unknown\n") + return handle + + +zk_open_srv, zk_open_port = start_line_server(zk_handler(True)) +zk_closed_srv, zk_closed_port = start_line_server(zk_handler(False)) + +cfg20_home = tempfile.mkdtemp(prefix="apex-cfg20-home-") +write_scope(cfg20_home, {"label": "cfg20", "expires": "2099-12-31T23:59:59Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_port": [str(zk_open_port), + str(zk_closed_port)]}) +res, _ = run([ + call(1, "avahi_audit", root=av_root), + call(2, "avahi_audit", root=av_good_root), + call(3, "logind_audit", root=lg_root), + call(4, "logind_audit", root=lg_good_root), + call(5, "tftpd_hpa_audit", root=tf_root), + call(6, "tftpd_hpa_audit", root=tf_good_root), + call(7, "zookeeper_4lw_probe", target="127.0.0.1", port=zk_open_port), + call(8, "zookeeper_4lw_probe", target="127.0.0.1", port=zk_closed_port), + call(9, "zookeeper_4lw_probe", target="198.51.100.9", port=2181), + call(10, "avahi_audit", root="/nonexistent-av"), + call(11, "logind_audit", root="/nonexistent-lg"), + call(12, "tftpd_hpa_audit", root="/nonexistent-tf"), +], home=cfg20_home) +by_id = {r.get("id"): r for r in res} +av = json.loads(text(by_id[1])) +av_kinds = {f["id"] for f in av["findings"]} +check("avahi_audit flags publication and a wildcard interface", + {"world-writable", "publish-workstation", "publish-addresses", + "no-allow-interfaces"} <= av_kinds and + av["interfaces_restricted"] is False, av) +av_good = json.loads(text(by_id[2])) +check("avahi_audit accepts a restricted daemon", + av_good["findings_count"] == 0 and + av_good["publish_workstation"] is False and + av_good["interfaces_restricted"] is True, av_good) +lg = json.loads(text(by_id[3])) +lg_kinds = {f["id"] for f in lg["findings"]} +check("logind_audit flags idle, lid and process settings", + {"world-writable", "idle-action", "lid-switch", "idle-sec", + "kill-user-processes"} <= lg_kinds and lg["idle_ignore"] is True, + lg) +lg_good = json.loads(text(by_id[4])) +check("logind_audit accepts a hardening config", + lg_good["findings_count"] == 0 and lg_good["idle_ignore"] is False and + lg_good["kill_user_processes"] is True, lg_good) +tf = json.loads(text(by_id[5])) +tf_kinds = {f["id"] for f in tf["findings"]} +check("tftpd_hpa_audit flags create and the root directory", + {"world-writable", "create-enabled", "no-secure", "root-directory"} <= + tf_kinds and tf["create"] is True and tf["secure"] is False, tf) +tf_good = json.loads(text(by_id[6])) +check("tftpd_hpa_audit accepts a secure directory", + tf_good["findings_count"] == 0 and tf_good["secure"] is True and + tf_good["root_dir"] is False, tf_good) +zk = json.loads(text(by_id[7])) +check("zookeeper_4lw_probe detects exposed stat and mntr", + zk["four_letter_open"] is True and zk["stat_bytes"] > 0 and + zk["mntr_bytes"] > 0 and "3.8.0" in zk["version"], zk) +zk_closed = json.loads(text(by_id[8])) +check("zookeeper_4lw_probe stays quiet when commands are refused", + zk_closed["four_letter_open"] is False and + zk_closed["stat_bytes"] == 0 and zk_closed["mntr_bytes"] == 0, + zk_closed) +check("zookeeper_4lw_probe refuses an out-of-scope target", err(by_id[9]), + text(by_id[9])) +check("avahi_audit reports a missing config", err(by_id[10]), + text(by_id[10])) +check("logind_audit reports a missing config", err(by_id[11]), + text(by_id[11])) +check("tftpd_hpa_audit reports a missing config", err(by_id[12]), + text(by_id[12])) +zk_open_srv.close() +zk_closed_srv.close() +shutil.rmtree(av_root, ignore_errors=True) +shutil.rmtree(av_good_root, ignore_errors=True) +shutil.rmtree(lg_root, ignore_errors=True) +shutil.rmtree(lg_good_root, ignore_errors=True) +shutil.rmtree(tf_root, ignore_errors=True) +shutil.rmtree(tf_good_root, ignore_errors=True) +shutil.rmtree(cfg20_home, ignore_errors=True) + print("\n== esp32 tools ==") @@ -10412,6 +10567,7 @@ print("\n== esp32 tools ==") + esp_home = tempfile.mkdtemp(prefix="apex-esp-") write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"}) esp_m, esp_s = pty.openpty()