diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc1736..196ec83 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.49.0 — 2026-11-23 — this change +## 1.50.0 — 2026-11-23 — this change + +- **Kafka** (`kafka_audit`): `server.properties`: a `PLAINTEXT` listener on + `0.0.0.0`, a missing `authorizer.class.name`, + `auto.create.topics.enable=true` and a world-writable file. +- **PowerDNS** (`powerdns_audit`): `pdns.conf` and `recursor.conf`: + `allow-from 0.0.0.0/0`, `webserver=yes`, an API key stored in the file and + `security-polling=no`. +- **Varnish** (`varnish_audit`): `default.vcl` and the daemon defaults: an + `acl purge` covering `0.0.0.0/0`, a management interface on `0.0.0.0` and + world-writable files. +- **Registry** (`docker_registry_probe`): `/v2/` and `/v2/_catalog` without + credentials; a catalog listing is an open registry and is saved as + evidence. +- Tests with Kafka/PowerDNS/Varnish trees and two registry HTTP fixtures + (open and 401). 1060 checks. Coverage 83.2%. + +## 1.49.0 — 2026-11-23 — 185aa07 - **iSCSI** (`iscsi_audit`): `iscsid.conf`: `node.startup=automatic`, a session or discovery authentication method of `None` (or missing) and a diff --git a/README.md b/README.md index 08861ae..3d1ebf4 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. -**234 tools · 1048 end-to-end checks · 340 fuzz cases · 83.1% line coverage · ~854 KiB** +**238 tools · 1060 end-to-end checks · 340 fuzz cases · 83.2% line coverage · ~863 KiB** ``` $ ./apex-twin --check -{"version":"1.49.0","tools":234,...,"scope":{"loaded":true,...}} +{"version":"1.50.0","tools":238,...,"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 (234) +## Tools (238) ### Scope and bookkeeping @@ -208,6 +208,7 @@ uploads and secret-file reads. It does not execute anything. | `ftp_tls_probe` | `AUTH TLS` -> 234 means explicit FTPS; otherwise cleartext | | `zookeeper_4lw_probe` | `stat`/`mntr` answered without auth leaks version and state | | `etcd_api_probe` | `/version`, `/health`, `/v2/keys` without a token; 2xx is open access | +| `docker_registry_probe` | `/v2/` and `/v2/_catalog` without auth; catalog saved as evidence | | `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 | @@ -431,6 +432,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack. | `iscsi_audit` | iscsid.conf: auto startup, no session/discovery CHAP | | `rpcbind_audit` | rpcbind: `-w`, `-i`, no `-l` bind address | | `kdump_audit` | kdump: remote target, no `-c`, shell/dump_to_rootfs action | +| `kafka_audit` | server.properties: PLAINTEXT listener, no authorizer, auto topics | +| `powerdns_audit` | pdns/recursor: open recursor, webserver, API key in the file | +| `varnish_audit` | VCL: open `acl purge`, management on 0.0.0.0 | ### ESP32 @@ -717,6 +721,8 @@ The full threat model, trust boundaries and a hardening checklist are in | ZooKeeper 4lw | two four-byte commands, no auth, no data | | iscsi/rpcbind/kdump | config reads only; optional root prefix | | etcd API | three unauthenticated GETs, first answers as evidence | +| kafka/powerdns/varnish | config reads only; optional root prefix | +| registry | two unauthenticated GETs, catalog as evidence | | USB audit | 200 devices, sysfs reads only | --- @@ -728,7 +734,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus ```sh make # apex-twin -make test # version check + gate audit + 1048 end-to-end checks +make test # version check + gate audit + 1060 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 @@ -852,7 +858,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery, websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, tls_hostname_check, ftp_tls_probe, - zookeeper_4lw_probe, etcd_api_probe + zookeeper_4lw_probe, etcd_api_probe, + docker_registry_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, @@ -895,7 +902,7 @@ examples/ scope.json ## Status -1.49.0. Built and run: 234 tools, 1048 checks, 340 fuzz cases and 83.1% line +1.50.0. Built and run: 238 tools, 1060 checks, 340 fuzz cases and 83.2% 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 e8b3191..3c98486 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.49.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.50.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. +- **Kafka, PowerDNS and Varnish audits read local files.** The registry probe + sends two unauthenticated GETs and saves the catalog as evidence. - **iSCSI, rpcbind and kdump audits read local files.** The etcd probe sends three unauthenticated GETs and saves the first answers as evidence. - **Avahi, logind and tftpd-hpa audits read local files.** The ZooKeeper diff --git a/docs/apex-twin.1 b/docs/apex-twin.1 index fb98cb5..da110c3 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.49.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.50.0" "User Commands" .SH NAME apex-twin \- scope\-gated offensive\-security MCP server .SH SYNOPSIS @@ -46,7 +46,7 @@ sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk, ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe, dns_ns_consistency, dns_dangling_cname, http_redirect_audit, websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit, -websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe), +websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, integrity_baseline, mitre_map, process_snapshot, persistence_audit, @@ -69,7 +69,8 @@ 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, avahi_audit, logind_audit, -tftpd_hpa_audit, iscsi_audit, rpcbind_audit, kdump_audit) +tftpd_hpa_audit, iscsi_audit, rpcbind_audit, kdump_audit, kafka_audit, powerdns_audit, +varnish_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 b6da457..ed3dfb0 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.49.0" +#define APEX_VERSION "1.50.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 74293f5..6e8b9f3 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -14614,6 +14614,309 @@ static void t_kdump_audit(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&findings); } +/* --------------------------------------------------------------- kafka_audit */ + +static void t_kafka_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *files[] = { "/etc/kafka/server.properties", + "/opt/kafka/config/server.properties", + NULL }; + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + static char text[65536]; + char value[512]; + struct stat st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int files_read = 0; + int plaintext = 0; + int no_authorizer = 0; + int auto_create = 0; + int i; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + mcp_buf_init(&findings); + for (i = 0; files[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, files[i]); + if (read_text(path, text, sizeof(text)) <= 0) + continue; + files_read++; + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "%s is writable by anyone", path); + count++; + } + if (conf_value(text, "listeners", value, sizeof(value)) && + strstr(value, "PLAINTEXT://") != NULL && + strstr(value, "0.0.0.0") != NULL) + plaintext = 1; + if (conf_value(text, "advertised.listeners", value, + sizeof(value)) && + strstr(value, "PLAINTEXT://") != NULL) + plaintext = 1; + if (!conf_value(text, "authorizer.class.name", value, + sizeof(value)) || value[0] == '\0') + no_authorizer = 1; + if (conf_value(text, "auto.create.topics.enable", value, + sizeof(value)) && + strcasecmp(value, "true") == 0) + auto_create = 1; + } + if (files_read == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read a Kafka server.properties"); + return; + } + if (plaintext) { + add_finding(&findings, &first, "plaintext-listener", "high", + "a listener is PLAINTEXT on every interface"); + count++; + } + if (no_authorizer) { + add_finding(&findings, &first, "no-authorizer", "medium", + "no authorizer is configured"); + count++; + } + if (auto_create) { + add_finding(&findings, &first, "auto-create-topics", "low", + "any client may create topics"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"plaintext_listener\":%s," + "\"authorizer\":%s,\"auto_create_topics\":%s," + "\"findings_count\":%d,\"findings\":[", + files_read, plaintext ? "true" : "false", + no_authorizer ? "false" : "true", + auto_create ? "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); +} + +/* ------------------------------------------------------------- powerdns_audit */ + +static void powerdns_scan_file(mcp_buf *findings, int *first, int *count, + const char *path, int *files, int *open_rec, + int *webserver, int *api_key, + int *no_polling) +{ + static char text[65536]; + struct stat st; + char value[512]; + + if (read_text(path, text, sizeof(text)) <= 0) + return; + (*files)++; + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(findings, first, "world-writable", "high", + "%s is writable by anyone", path); + (*count)++; + } + if (conf_value(text, "allow-from", value, sizeof(value)) && + (strstr(value, "0.0.0.0/0") != NULL || + strstr(value, "::/0") != NULL)) + *open_rec = 1; + if (conf_value(text, "webserver", value, sizeof(value)) && + strcasecmp(value, "yes") == 0) + *webserver = 1; + if (conf_value(text, "api-key", value, sizeof(value)) && + value[0] != '\0') { + if (!*api_key) { + add_finding(findings, first, "api-key", + stat(path, &st) == 0 && + (st.st_mode & 0044) != 0 ? "high" : "medium", + "the API key is stored in %s", path); + (*count)++; + } + *api_key = 1; + } + if (conf_value(text, "security-polling", value, sizeof(value)) && + strcasecmp(value, "no") == 0) + *no_polling = 1; +} + +static void t_powerdns_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *files[] = { "/etc/powerdns/pdns.conf", + "/etc/powerdns/recursor.conf", + "/etc/pdns/pdns.conf", + "/etc/pdns/recursor.conf", NULL }; + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int files_read = 0; + int open_rec = 0; + int webserver = 0; + int api_key = 0; + int no_polling = 0; + int i; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + mcp_buf_init(&findings); + for (i = 0; files[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, files[i]); + powerdns_scan_file(&findings, &first, &count, path, &files_read, + &open_rec, &webserver, &api_key, + &no_polling); + } + if (files_read == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read a PowerDNS configuration"); + return; + } + if (open_rec) { + add_finding(&findings, &first, "open-recursor", "high", + "allow-from covers every address"); + count++; + } + if (webserver) { + add_finding(&findings, &first, "webserver", "medium", + "the PowerDNS web server is enabled"); + count++; + } + if (no_polling) { + add_finding(&findings, &first, "no-security-polling", "low", + "security polling is disabled"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"open_recursor\":%s," + "\"webserver\":%s,\"api_key\":%s," + "\"security_polling\":%s,\"findings_count\":%d," + "\"findings\":[", + files_read, open_rec ? "true" : "false", + webserver ? "true" : "false", + api_key ? "true" : "false", + no_polling ? "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); +} + +/* -------------------------------------------------------------- varnish_audit */ + +static void varnish_scan_mgmt(mcp_buf *findings, int *first, int *count, + const char *path, int *files, int *open_mgmt) +{ + static char text[65536]; + struct stat st; + + if (read_text(path, text, sizeof(text)) <= 0) + return; + (*files)++; + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(findings, first, "world-writable", "high", + "%s is writable by anyone", path); + (*count)++; + } + if (strstr(text, "-T 0.0.0.0") != NULL || + strstr(text, "-T :") != NULL || + strstr(text, "-T [::]") != NULL) + *open_mgmt = 1; +} + +static void t_varnish_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *mgmt_files[] = { "/etc/varnish/varnish.params", + "/etc/default/varnish", NULL }; + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + static char text[65536]; + struct stat st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int files = 0; + int open_purge = 0; + int open_mgmt = 0; + int i; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + mcp_buf_init(&findings); + snprintf(path, sizeof(path), "%s/etc/varnish/default.vcl", root); + if (read_text(path, text, sizeof(text)) > 0) { + files++; + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "%s is writable by anyone", path); + count++; + } + if (strstr(text, "acl purge") != NULL && + (strstr(text, "\"0.0.0.0\"/0") != NULL || + strstr(text, "\"any\"") != NULL)) + open_purge = 1; + } + for (i = 0; mgmt_files[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, mgmt_files[i]); + varnish_scan_mgmt(&findings, &first, &count, path, &files, + &open_mgmt); + } + if (files == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read a Varnish configuration"); + return; + } + if (open_purge) { + add_finding(&findings, &first, "open-purge", "high", + "any client may purge the cache"); + count++; + } + if (open_mgmt) { + add_finding(&findings, &first, "open-management", "high", + "the management interface listens beyond localhost"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"open_purge\":%s," + "\"open_management\":%s,\"findings_count\":%d," + "\"findings\":[", + files, open_purge ? "true" : "false", + open_mgmt ? "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, " @@ -15421,6 +15724,27 @@ const mcp_tool TOOLS_BLUE[] = { "{\"type\":\"object\",\"properties\":{" "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", t_kdump_audit }, + { "kafka_audit", + "Parse Kafka server.properties (root prefix, two usual paths): a " + "PLAINTEXT listener on 0.0.0.0, a missing authorizer.class.name, " + "auto.create.topics.enable and a world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_kafka_audit }, + { "powerdns_audit", + "Parse pdns.conf and recursor.conf (root prefix, four usual paths): " + "allow-from 0.0.0.0/0, webserver=yes, an API key in the file and " + "security-polling=no. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_powerdns_audit }, + { "varnish_audit", + "Parse default.vcl and the daemon defaults (root prefix): an acl purge " + "that covers every address, a management interface on 0.0.0.0 and " + "world-writable files. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_varnish_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 62d36a4..ba7009c 100644 --- a/src/tools_red.c +++ b/src/tools_red.c @@ -6531,6 +6531,97 @@ static void t_etcd_api_probe(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&b); } +/* ------------------------------------------------------ docker_registry_probe */ + +static void t_docker_registry_probe(mcp_conn *c, const mcp_json *args, + void *user) +{ + static const char *paths[] = { "/v2/", "/v2/_catalog", NULL }; + const char *target = mcp_arg_string(args, "target"); + int port = mcp_arg_int(args, "port", 5000); + int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port)); + mcp_buf b; + int first = 1; + int tested = 0; + int open_count = 0; + int catalog_open = 0; + char *evidence = NULL; + int i; + + (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, "docker_registry_probe", target, port)) + return; + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"target\":"); + apex_json_str(&b, target); + mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port, + tls ? "true" : "false"); + for (i = 0; paths[i] != NULL; i++) { + char status[256]; + char *resp = NULL; + size_t len = 0; + int code; + int open; + int catalog = 0; + + status[0] = '\0'; + if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL, + 8000, &resp, &len, status, + sizeof(status)) != 0) + continue; + tested++; + code = apex_status_code(status); + open = code >= 200 && code < 300; + if (open && strcmp(paths[i], "/v2/_catalog") == 0 && + resp != NULL && find_bytes(resp, len, "repositories")) { + catalog = 1; + catalog_open = 1; + if (evidence == NULL) + evidence = apex_evidence_save("registry-catalog", + resp, len); + } + if (open) + open_count++; + if (!first) + mcp_buf_puts(&b, ","); + first = 0; + mcp_buf_puts(&b, "{\"path\":"); + apex_json_str(&b, paths[i]); + mcp_buf_printf(&b, ",\"status\":%d,\"bytes\":%lu,\"open\":%s," + "\"catalog\":%s}", + code, (unsigned long)len, + open ? "true" : "false", + catalog ? "true" : "false"); + free(resp); + } + mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d," + "\"catalog_open\":%s,\"evidence\":", + tested, open_count, catalog_open ? "true" : "false"); + if (evidence != NULL) + apex_json_str(&b, evidence); + else + mcp_buf_puts(&b, "null"); + mcp_buf_puts(&b, "}"); + apex_audit("docker_registry_probe", target, port, open_count == 0, + open_count == 0 + ? "the registry requires authentication" + : catalog_open + ? "the registry answers and lists repositories without auth" + : "the registry API answers without authentication", + "list"); + mcp_reply_json(c, b.p); + free(evidence); + mcp_buf_free(&b); +} + const mcp_tool TOOLS_RED[] = { { "vuln_check", "Non-destructive verification of exposed artifacts on one web target: " @@ -7064,6 +7155,16 @@ const mcp_tool TOOLS_RED[] = { "\"tls\":{\"type\":\"boolean\"}}," "\"required\":[\"target\"]}", t_etcd_api_probe }, + { "docker_registry_probe", + "Query a Docker registry without credentials: /v2/ and /v2/_catalog. A " + "2xx on the catalog with repositories is an open registry; the catalog " + "is saved as evidence. Gate: the target.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 5000\"}," + "\"tls\":{\"type\":\"boolean\"}}," + "\"required\":[\"target\"]}", + t_docker_registry_probe }, { "dns_ns_consistency", "Fetch NS records for a domain from the parent resolver and from its own " "first nameserver (resolved to an address), then report names present on " diff --git a/tests/gate_audit.py b/tests/gate_audit.py index dab7f18..1606622 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 = 234 +EXPECTED_TOOLS = 238 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 17ecd94..248a198 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("234 tools registered", len(tools) == 234, len(tools)) +check("238 tools registered", len(tools) == 238, 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"]) == 234) + check("http tools/list", len(listing["result"]["tools"]) == 238) 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 @@ -10724,6 +10724,182 @@ shutil.rmtree(kd_root, ignore_errors=True) shutil.rmtree(kd_good_root, ignore_errors=True) shutil.rmtree(cfg21_home, ignore_errors=True) +print("\n== Kafka, PowerDNS, Varnish and registry ==\n") + +kf_root = tempfile.mkdtemp(prefix="apex-kf-") +os.makedirs(os.path.join(kf_root, "etc", "kafka")) +kf_bad = os.path.join(kf_root, "etc", "kafka", "server.properties") +with open(kf_bad, "w") as f: + f.write("broker.id=1\n") + f.write("listeners=PLAINTEXT://0.0.0.0:9092\n") + f.write("auto.create.topics.enable=true\n") +os.chmod(kf_bad, 0o666) +kf_good_root = tempfile.mkdtemp(prefix="apex-kfg-") +os.makedirs(os.path.join(kf_good_root, "etc", "kafka")) +with open(os.path.join(kf_good_root, "etc", "kafka", + "server.properties"), "w") as f: + f.write("broker.id=1\n") + f.write("listeners=SASL_SSL://127.0.0.1:9093\n") + f.write("authorizer.class.name=kafka.security.authorizer.AclAuthorizer\n") + f.write("auto.create.topics.enable=false\n") + +pd_root = tempfile.mkdtemp(prefix="apex-pd-") +os.makedirs(os.path.join(pd_root, "etc", "powerdns")) +pd_bad = os.path.join(pd_root, "etc", "powerdns", "recursor.conf") +with open(pd_bad, "w") as f: + f.write("allow-from=0.0.0.0/0\n") + f.write("webserver=yes\n") + f.write("api-key=secret\n") + f.write("security-polling=no\n") +os.chmod(pd_bad, 0o666) +pd_good_root = tempfile.mkdtemp(prefix="apex-pdg-") +os.makedirs(os.path.join(pd_good_root, "etc", "powerdns")) +with open(os.path.join(pd_good_root, "etc", "powerdns", "recursor.conf"), + "w") as f: + f.write("allow-from=10.0.0.0/8\n") + f.write("webserver=no\n") + f.write("security-polling=yes\n") + +vr_root = tempfile.mkdtemp(prefix="apex-vr-") +os.makedirs(os.path.join(vr_root, "etc", "varnish")) +os.makedirs(os.path.join(vr_root, "etc", "default")) +vr_bad = os.path.join(vr_root, "etc", "varnish", "default.vcl") +with open(vr_bad, "w") as f: + f.write('acl purge {\n "0.0.0.0"/0;\n}\n') +os.chmod(vr_bad, 0o666) +with open(os.path.join(vr_root, "etc", "default", "varnish"), "w") as f: + f.write('DAEMON_OPTS="-a :80 -T 0.0.0.0:6082"\n') +vr_good_root = tempfile.mkdtemp(prefix="apex-vrg-") +os.makedirs(os.path.join(vr_good_root, "etc", "varnish")) +os.makedirs(os.path.join(vr_good_root, "etc", "default")) +with open(os.path.join(vr_good_root, "etc", "varnish", "default.vcl"), + "w") as f: + f.write('acl purge {\n "127.0.0.1";\n}\n') +with open(os.path.join(vr_good_root, "etc", "default", "varnish"), + "w") as f: + f.write('DAEMON_OPTS="-a :80 -T 127.0.0.1:6082"\n') + + +class _RegistryHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + path = urllib.parse.urlsplit(self.path).path + docs = { + "/v2/": b"{}", + "/v2/_catalog": b'{"repositories":["app/web"]}', + } + body = docs.get(path, b'{"errors":[]}') + code = 200 if path in docs else 404 + self.send_response(code) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +class _RegistryAuthHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + body = b'{"errors":[{"code":"UNAUTHORIZED"}]}' + self.send_response(401) + self.send_header("WWW-Authenticate", 'Bearer realm="https://auth"') + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +reg_srv = http.server.HTTPServer(("127.0.0.1", 0), _RegistryHandler) +reg_port = reg_srv.server_address[1] +threading.Thread(target=reg_srv.serve_forever, daemon=True).start() +reg_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), + _RegistryAuthHandler) +reg_auth_port = reg_auth_srv.server_address[1] +threading.Thread(target=reg_auth_srv.serve_forever, daemon=True).start() + +cfg22_home = tempfile.mkdtemp(prefix="apex-cfg22-home-") +write_scope(cfg22_home, {"label": "cfg22", "expires": "2099-12-31T23:59:59Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_port": [str(reg_port), str(reg_auth_port)]}) +res, _ = run([ + call(1, "kafka_audit", root=kf_root), + call(2, "kafka_audit", root=kf_good_root), + call(3, "powerdns_audit", root=pd_root), + call(4, "powerdns_audit", root=pd_good_root), + call(5, "varnish_audit", root=vr_root), + call(6, "varnish_audit", root=vr_good_root), + call(7, "docker_registry_probe", target="127.0.0.1", port=reg_port, + tls=False), + call(8, "docker_registry_probe", target="127.0.0.1", port=reg_auth_port, + tls=False), + call(9, "docker_registry_probe", target="198.51.100.9", port=5000), + call(10, "kafka_audit", root="/nonexistent-kf"), + call(11, "powerdns_audit", root="/nonexistent-pd"), + call(12, "varnish_audit", root="/nonexistent-vr"), +], home=cfg22_home) +by_id = {r.get("id"): r for r in res} +kf = json.loads(text(by_id[1])) +kf_kinds = {f["id"] for f in kf["findings"]} +check("kafka_audit flags PLAINTEXT, no authorizer and auto topics", + {"world-writable", "plaintext-listener", "no-authorizer", + "auto-create-topics"} <= kf_kinds and + kf["plaintext_listener"] is True and kf["authorizer"] is False, kf) +kf_good = json.loads(text(by_id[2])) +check("kafka_audit accepts SASL_SSL with an authorizer", + kf_good["findings_count"] == 0 and + kf_good["plaintext_listener"] is False and + kf_good["authorizer"] is True, kf_good) +pd = json.loads(text(by_id[3])) +pd_kinds = {f["id"] for f in pd["findings"]} +check("powerdns_audit flags an open recursor and the API key", + {"world-writable", "open-recursor", "webserver", "api-key", + "no-security-polling"} <= pd_kinds and + pd["open_recursor"] is True and pd["api_key"] is True, pd) +pd_good = json.loads(text(by_id[4])) +check("powerdns_audit accepts a scoped recursor", + pd_good["findings_count"] == 0 and + pd_good["open_recursor"] is False and pd_good["webserver"] is False, + pd_good) +vr = json.loads(text(by_id[5])) +vr_kinds = {f["id"] for f in vr["findings"]} +check("varnish_audit flags open purge and management", + {"world-writable", "open-purge", "open-management"} <= vr_kinds and + vr["open_purge"] is True and vr["open_management"] is True, vr) +vr_good = json.loads(text(by_id[6])) +check("varnish_audit accepts loopback purge and management", + vr_good["findings_count"] == 0 and vr_good["open_purge"] is False and + vr_good["open_management"] is False, vr_good) +reg = json.loads(text(by_id[7])) +check("docker_registry_probe finds the open catalog", + reg["open_count"] == 2 and reg["catalog_open"] is True and + reg["evidence"] and os.path.isfile(reg["evidence"]), reg) +reg_auth = json.loads(text(by_id[8])) +check("docker_registry_probe reports a protected registry", + reg_auth["open_count"] == 0 and reg_auth["catalog_open"] is False and + all(e["status"] == 401 for e in reg_auth["endpoints"]), reg_auth) +check("docker_registry_probe refuses an out-of-scope target", + err(by_id[9]), text(by_id[9])) +check("kafka_audit reports a missing config", err(by_id[10]), + text(by_id[10])) +check("powerdns_audit reports a missing config", err(by_id[11]), + text(by_id[11])) +check("varnish_audit reports a missing config", err(by_id[12]), + text(by_id[12])) +reg_srv.shutdown() +reg_srv.server_close() +reg_auth_srv.shutdown() +reg_auth_srv.server_close() +shutil.rmtree(kf_root, ignore_errors=True) +shutil.rmtree(kf_good_root, ignore_errors=True) +shutil.rmtree(pd_root, ignore_errors=True) +shutil.rmtree(pd_good_root, ignore_errors=True) +shutil.rmtree(vr_root, ignore_errors=True) +shutil.rmtree(vr_good_root, ignore_errors=True) +shutil.rmtree(cfg22_home, ignore_errors=True) + print("\n== esp32 tools ==") @@ -10735,6 +10911,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()