diff --git a/CHANGELOG.md b/CHANGELOG.md index 545cb42..dcf6a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 1.86.0 - 2026-11-24 - this change + +- **dhclient** (`dhclient_audit`): `dhclient.conf` that takes + `domain-name-servers` from the DHCP offer, a `supersede` or `prepend` + `domain-name-servers`/`domain-name`/`domain-search` override, and a hook in + `dhclient-enter-hooks.d` that runs as root and is writable by any local + user. +- **journal upload** (`journal_upload_audit`): an `Upload` `URL` over plain + `http`, a missing `ServerKeyFile` and a writable `journal-upload.conf`. +- **fwupd** (`fwupd_audit`): `OnlyTrusted` set to false (firmware with an + unverified signature is installed), an empty `DisabledPlugins` list that + loads every plugin, and a writable `daemon.conf`. +- **Vault** (`vault_probe`, red): `/v1/sys/seal-status` and `/v1/sys/mounts` + without a token. A 2xx on the mount list means every secret engine path is + readable without authentication; the body is saved as evidence and the seal + state is reported. + +378 tools, 1437 checks. + ## 1.85.0 - 2026-11-24 - this change - **Jetty** (`jetty_audit`): `jetty.xml`, `jetty-ssl.xml` and the `start.d` diff --git a/README.md b/README.md index a6c7685..e78b51b 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. -**374 tools · 1429 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB** +**378 tools · 1437 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB** ``` $ ./apex-twin --check -{"version":"1.85.0","tools":374,...,"scope":{"loaded":true,...}} +{"version":"1.86.0","tools":378,...,"scope":{"loaded":true,...}} ``` APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope @@ -235,6 +235,7 @@ uploads and secret-file reads. It does not execute anything. | `rundeck_probe` | `/api/14/projects` without a token; project list as evidence | | `zabbix_probe` | `user.login` with the default Admin/zabbix pair; response as evidence | | `datasette_probe` | `/-/databases.json` without a token; database list as evidence | +| `vault_probe` | `/v1/sys/mounts` on 8200 without a token; mount list as evidence | | `airflow_probe` | `/api/v1/dags` without auth; DAG inventory as evidence | | `jupyter_probe` | `/api/kernels` on 8888 without a token; sessions as evidence | | `jira_probe` | `/rest/api/2/project` on 8080 without auth; project list as evidence | @@ -571,6 +572,9 @@ does. | `uwsgi_audit` | uWSGI ini: uid/gid 0, `chmod-socket` 666/777, `chdir = /`, master off | | `lighttpd_audit` | lighttpd.conf: document-root `/`, ssl.engine off, dir-listing, runs as root | | `jetty_audit` | jetty.xml + start.d: connector on 0.0.0.0 without TLS, literal password, MD5 | +| `dhclient_audit` | dhclient.conf + hooks: DHCP resolver, supersede override, writable hook | +| `journal_upload_audit` | journal-upload.conf: plain http URL, missing client key | +| `fwupd_audit` | fwupd daemon.conf: OnlyTrusted off, empty DisabledPlugins | | `networkd_audit` | systemd-networkd: [Match] without Name/MAC/Type, DHCP DNS without UseDNS=no, public resolver | | `namespace_audit` | namespace.conf: no /tmp entry, empty/unknown method, `~` user list | | `ssh_client_audit` | ssh_config: StrictHostKeyChecking no, known_hosts /dev/null, ssh-rsa | @@ -1055,7 +1059,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, argocd_probe, kafka_connect_probe, - zabbix_probe, datasette_probe + zabbix_probe, datasette_probe, vault_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, @@ -1077,7 +1081,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit, nfs_conf_audit, idmapd_audit, netplan_audit, apt_auth_audit, aliases_audit, netgroup_audit, php_fpm_audit, uwsgi_audit, lighttpd_audit, - jetty_audit) + jetty_audit, dhclient_audit, + journal_upload_audit, fwupd_audit) src/tools_esp.c esp_info, esp_monitor, esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan, esp_app_info, esp_image_verify @@ -1116,7 +1121,7 @@ examples/ scope.json ## Status -1.85.0. Built and run: 374 tools, 1429 checks, 240 fuzz cases and 85.0% line +1.86.0. Built and run: 378 tools, 1437 checks, 240 fuzz cases and 85.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 6623e37..ec337ba 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.85.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.86.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. diff --git a/docs/apex-twin.1 b/docs/apex-twin.1 index 42136b3..f0b301b 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-24" "apex-twin 1.85.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.86.0" "User Commands" .SH NAME apex-twin \- scope\-gated offensive\-security MCP server .SH SYNOPSIS @@ -45,7 +45,7 @@ graphql_probe, docker_api_probe, elasticsearch_probe, imap_probe, pop3_probe, sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk, ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, 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, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, +websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, @@ -94,6 +94,7 @@ networkd_audit, namespace_audit, ssh_client_audit, ufw_audit, monit_audit, clama modules_load_audit, depmod_audit, adduser_conf_audit, nfs_conf_audit, idmapd_audit, netplan_audit, apt_auth_audit, aliases_audit, netgroup_audit, jetty_audit, +dhclient_audit, journal_upload_audit, fwupd_audit, php_fpm_audit, uwsgi_audit, lighttpd_audit) and ESP32 board tools (esp_info, esp_monitor, esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan, diff --git a/src/apex.h b/src/apex.h index 1085508..1ad6738 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.85.0" +#define APEX_VERSION "1.86.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 8a26858..29731db 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -27968,6 +27968,354 @@ static void t_jetty_audit(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&findings); } +/* ----------------------------------------------------------- dhclient_audit */ + +/* dhclient.conf is not INI and not shell: a statement runs until the + * semicolon, and the value is whatever follows the option name. Two of them + * hand the resolver to whoever answers the DHCP offer: "domain-name-servers" + * and "supersede domain-name-servers". A third, "domain-search" or + * "supersede domain-name", lets the offer rewrite the search domain. The + * enter-hooks.d directory is the other half: every script in it runs as root + * on every lease, so an unexpected file there is a local privilege path. */ +struct dhclient_state { + int files; + int dhcp_resolvers; + int superseded_resolvers; + int superseded_domain; + int hooks; + int writable_hooks; + int world_writable; +}; + +/* The statement text starts at "name" and ends at the next ';'. Does the + * option appear with a non-empty value inside it? */ +static int dh_statement_has_value(const char *text, const char *name) +{ + const char *p = text; + + while ((p = strstr(p, name)) != NULL) { + const char *semi = strchr(p, ';'); + const char *q = p + strlen(name); + + if (semi == NULL) + return 0; + /* An option name must not be the tail of a longer word. */ + if (p > text && (p[-1] == '-' || p[-1] == '_' || + (p[-1] >= 'a' && p[-1] <= 'z'))) + goto next; + while (q < semi && (*q == ' ' || *q == '\t' || *q == '\n')) + q++; + if (q < semi && *q != ';') + return 1; +next: + p = semi + 1; + } + return 0; +} + +static void dhclient_scan_conf(struct dhclient_state *st, const char *path, + mcp_buf *findings, int *first, int *count) +{ + static char text[65536]; + struct stat sb; + + if (read_text(path, text, sizeof(text)) <= 0) + return; + st->files++; + if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) { + st->world_writable++; + add_finding(findings, first, "world-writable", "high", + "%s is writable by any local user; it decides which " + "resolver the host uses", path); + (*count)++; + } + if (dh_statement_has_value(text, "supersede domain-name-servers") || + dh_statement_has_value(text, "prepend domain-name-servers")) { + st->superseded_resolvers++; + add_finding(findings, first, "superseded-resolver", "medium", + "%s overrides or prepends a DNS resolver locally; the " + "DHCP offer no longer decides where lookups go", path); + (*count)++; + } + if (dh_statement_has_value(text, "domain-name-servers")) { + st->dhcp_resolvers++; + add_finding(findings, first, "dhcp-resolver", "low", + "%s accepts domain-name-servers from the DHCP offer; " + "anyone who answers the lease picks the resolver", path); + (*count)++; + } + if (dh_statement_has_value(text, "supersede domain-name") || + dh_statement_has_value(text, "supersede domain-search")) { + st->superseded_domain++; + add_finding(findings, first, "superseded-domain", "low", + "%s overrides the search domain locally", path); + (*count)++; + } +} + +static void dhclient_scan_hooks(struct dhclient_state *st, const char *dir, + mcp_buf *findings, int *first, int *count) +{ + DIR *d = opendir(dir); + struct dirent *ent; + + if (d == NULL) + return; + while ((ent = readdir(d)) != NULL) { + char full[1400]; + struct stat sb; + + if (ent->d_name[0] == '.') + continue; + snprintf(full, sizeof(full), "%.1024s/%.255s", dir, ent->d_name); + if (stat(full, &sb) != 0 || !S_ISREG(sb.st_mode)) + continue; + st->hooks++; + if ((sb.st_mode & 0002) != 0) { + st->writable_hooks++; + add_finding(findings, first, "writable-hook", "high", + "%s runs as root on every DHCP lease and is " + "writable by any local user", full); + (*count)++; + } + } + closedir(d); +} + +static void t_dhclient_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + mcp_buf b; + mcp_buf findings; + struct dhclient_state st; + int first = 1; + int count = 0; + int i; + static const char *conf_files[] = { "/etc/dhcp/dhclient.conf", + "/etc/dhclient.conf", NULL }; + static const char *hook_dirs[] = { + "/etc/dhcp/dhclient-enter-hooks.d", + "/etc/dhclient-enter-hooks.d", NULL }; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + memset(&st, 0, sizeof(st)); + mcp_buf_init(&findings); + for (i = 0; conf_files[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, conf_files[i]); + dhclient_scan_conf(&st, path, &findings, &first, &count); + } + for (i = 0; hook_dirs[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, hook_dirs[i]); + dhclient_scan_hooks(&st, path, &findings, &first, &count); + } + if (st.files == 0 && st.hooks == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read a dhclient configuration"); + return; + } + if (count == 0) { + add_finding(&findings, &first, "no-findings", "info", + "no DHCP-supplied resolver, no local override and no " + "writable hook script"); + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"dhcp_resolvers\":%d," + "\"superseded_resolvers\":%d,\"superseded_domain\":%d," + "\"hooks\":%d,\"writable_hooks\":%d," + "\"world_writable\":%d,\"findings_count\":%d,\"findings\":[", + st.files, st.dhcp_resolvers, st.superseded_resolvers, + st.superseded_domain, st.hooks, st.writable_hooks, + st.world_writable, 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); +} + +/* ----------------------------------------------------- journal_upload_audit */ + +/* systemd-journal-upload.conf is INI with a single [Upload] section. The URL + * decides whether the journal leaves the host in the clear; a missing + * ServerKeyFile means the upload is not authenticated by a client key; and a + * writable file lets any local user point the journal at their own server. */ +static void t_journal_upload_audit(mcp_conn *c, const mcp_json *args, + void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + static char text[32768]; + struct stat sb; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int plain_http = 0; + int no_key = 0; + int world_writable = 0; + int have_url = 0; + + (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), "%.400s/etc/systemd/journal-upload.conf", + root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read journal-upload.conf"); + return; + } + if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) { + world_writable = 1; + add_finding(&findings, &first, "world-writable", "high", + "%s is writable by any local user; it decides where the " + "journal is sent", path); + count++; + } + { + char url[512]; + char key[512]; + + if (ini_value(text, "Upload", "URL", url, sizeof(url)) == 1 && + url[0] != '\0') { + have_url = 1; + if (strncmp(url, "http://", 7) == 0) { + plain_http = 1; + add_finding(&findings, &first, "plain-http", "medium", + "the journal is uploaded over plain http; " + "every log line and every field crosses the " + "network in the clear"); + count++; + } + } + if (ini_value(text, "Upload", "ServerKeyFile", key, + sizeof(key)) == 0 || + key[0] == '\0') { + no_key = 1; + add_finding(&findings, &first, "no-client-key", "medium", + "no ServerKeyFile is set; the upload is not " + "authenticated by a client key"); + count++; + } + } + if (count == 0) { + add_finding(&findings, &first, "no-findings", "info", + "the journal upload uses TLS, a client key and a " + "read-only configuration"); + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"url_set\":%s,\"plain_http\":%d," + "\"no_client_key\":%d,\"world_writable\":%d," + "\"findings_count\":%d,\"findings\":[", + have_url ? "true" : "false", plain_http, no_key, + world_writable, 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); +} + +/* --------------------------------------------------------------- fwupd_audit */ + +/* fwupd's daemon.conf is INI with a [fwupd] section. OnlyTrusted defaults to + * true; setting it to false makes the daemon install firmware whose signature + * it could not verify. DisabledPlugins is the only way to switch off the + * plugins that speak to the network or to the ESP; without it every plugin is + * live. A writable file decides what firmware runs in the next boot. */ +static void t_fwupd_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + static char text[32768]; + struct stat sb; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int untrusted = 0; + int no_plugins = 0; + int world_writable = 0; + char value[512]; + + (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), "%.400s/etc/fwupd/daemon.conf", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read fwupd daemon.conf"); + return; + } + if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) { + world_writable = 1; + add_finding(&findings, &first, "world-writable", "high", + "%s is writable by any local user; it decides which " + "firmware is installed", path); + count++; + } + value[0] = '\0'; + if (ini_value(text, "fwupd", "OnlyTrusted", value, sizeof(value)) == 1 && + (strcmp(value, "false") == 0 || strcmp(value, "0") == 0 || + strcmp(value, "no") == 0)) { + untrusted = 1; + add_finding(&findings, &first, "untrusted-firmware", "high", + "OnlyTrusted is off; fwupd installs firmware whose " + "signature it could not verify"); + count++; + } + value[0] = '\0'; + if (ini_value(text, "fwupd", "DisabledPlugins", value, + sizeof(value)) == 0 || + value[0] == '\0') { + no_plugins = 1; + add_finding(&findings, &first, "no-disabled-plugins", "low", + "DisabledPlugins is empty; every plugin, including the " + "ones that reach the network, stays active"); + count++; + } + if (count == 0) { + add_finding(&findings, &first, "no-findings", "info", + "fwupd trusts only signed firmware, disables plugins " + "and keeps a read-only configuration"); + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"untrusted_firmware\":%d,\"no_disabled_plugins\":%d," + "\"world_writable\":%d,\"findings_count\":%d,\"findings\":[", + untrusted, no_plugins, world_writable, 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, " @@ -29519,6 +29867,31 @@ const mcp_tool TOOLS_BLUE[] = { "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " "empty\"}}}", t_jetty_audit }, + { "dhclient_audit", + "Parse dhclient configuration (root prefix): dhclient.conf and " + "dhclient-enter-hooks.d. Flags a resolver taken from the DHCP offer, " + "a supersede/prepend domain-name-servers override, a superseded " + "domain-search, a hook script that runs as root and is writable, and " + "a writable configuration file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " + "empty\"}}}", + t_dhclient_audit }, + { "journal_upload_audit", + "Parse systemd-journal-upload.conf (root prefix): a URL over plain " + "http, a missing ServerKeyFile and a writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " + "empty\"}}}", + t_journal_upload_audit }, + { "fwupd_audit", + "Parse fwupd daemon.conf (root prefix): OnlyTrusted off (unsigned " + "firmware), an empty DisabledPlugins list and a writable file. " + "Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " + "empty\"}}}", + t_fwupd_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 99fe2a5..7ac68a2 100644 --- a/src/tools_red.c +++ b/src/tools_red.c @@ -9025,6 +9025,101 @@ static void t_datasette_probe(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&b); } +/* ---------------------------------------------------------------- vault_probe */ + +/* HashiCorp Vault on 8200. /v1/sys/seal-status answers without a token on + * every install, so it only proves that something is listening; the finding is + * /v1/sys/mounts answering 2xx, which means the mount list - every secret + * engine and its path - is readable without authentication. The response is + * saved as evidence, never the tokens inside it. */ +static void t_vault_probe(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *paths[] = { "/v1/sys/seal-status", + "/v1/sys/mounts", NULL }; + const char *target = mcp_arg_string(args, "target"); + int port = mcp_arg_int(args, "port", 8200); + 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 mounts_open = 0; + int sealed = -1; + 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, "vault_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 is_mounts = strstr(paths[i], "mounts") != NULL; + + 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) + open_count++; + if (open && strstr(paths[i], "seal-status") != NULL && resp != NULL) { + if (strstr(resp, "\"sealed\":true") != NULL) + sealed = 1; + else if (strstr(resp, "\"sealed\":false") != NULL) + sealed = 0; + } + if (open && is_mounts) { + mounts_open = 1; + if (evidence == NULL) + evidence = apex_evidence_save("vault-mounts", resp, len); + } + 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}", + code, (unsigned long)len, open ? "true" : "false"); + free(resp); + } + mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d," + "\"mounts_open\":%s,\"sealed\":%s,\"evidence\":", + tested, open_count, mounts_open ? "true" : "false", + sealed == 1 ? "true" : (sealed == 0 ? "false" : "null")); + if (evidence != NULL) + apex_json_str(&b, evidence); + else + mcp_buf_puts(&b, "null"); + mcp_buf_puts(&b, "}"); + apex_audit("vault_probe", target, port, !mounts_open, + mounts_open + ? "the Vault mount list answers without a token" + : "the Vault mount list requires a token", "list"); + mcp_reply_json(c, b.p); + free(evidence); + mcp_buf_free(&b); +} + /* -------------------------------------------------------------- rundeck_probe */ /* Rundeck on 4440. /api/1/system/info answers on many installs and is not @@ -10473,6 +10568,17 @@ const mcp_tool TOOLS_RED[] = { "\"tls\":{\"type\":\"boolean\"}}," "\"required\":[\"target\"]}", t_datasette_probe }, + { "vault_probe", + "Get /v1/sys/seal-status and /v1/sys/mounts without a token on 8200. " + "A 2xx on the mount list means every secret engine path is readable " + "without authentication; the body is saved as evidence. The seal " + "state is reported, tokens are never printed.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 8200\"}," + "\"tls\":{\"type\":\"boolean\"}}," + "\"required\":[\"target\"]}", + t_vault_probe }, { "airflow_probe", "Query Airflow on 8080 without credentials: /api/v1/version and " "/api/v1/dags. A 2xx on the DAG list means the whole DAG inventory is " diff --git a/tests/gate_audit.py b/tests/gate_audit.py index cae36b5..f180b56 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 = 374 +EXPECTED_TOOLS = 378 GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(") # Handlers may hand argv to a shared runner instead of calling the gate # themselves. That runner has to call the gate; both halves are checked diff --git a/tests/run.py b/tests/run.py index dbda7e3..2ad9721 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("374 tools registered", len(tools) == 374, len(tools)) +check("378 tools registered", len(tools) == 378, 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"]) == 374) + check("http tools/list", len(listing["result"]["tools"]) == 378) 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 @@ -16830,6 +16830,191 @@ for d in (jt_root, jt_good_root, cfg56_home): shutil.rmtree(d, ignore_errors=True) +# --- 1.86.0: dhclient, journal-upload and fwupd audits plus the Vault probe --- +print("\n== dhclient, journal-upload, fwupd and Vault ==") + +dh_root = tempfile.mkdtemp(prefix="apex-dh-") +os.makedirs(os.path.join(dh_root, "etc", "dhcp", "dhclient-enter-hooks.d")) +dh_conf = os.path.join(dh_root, "etc", "dhcp", "dhclient.conf") +with open(dh_conf, "w") as f: + f.write("option rfc3442-classless-static-routes code 121 = array of " + "unsigned integer 8;\n") + f.write("request subnet-mask, broadcast-address, routers,\n") + f.write(" domain-name-servers, domain-search;\n") + f.write("supersede domain-name-servers 10.0.0.53;\n") + f.write("supersede domain-name \"corp.example.test\";\n") +os.chmod(dh_conf, 0o666) +with open(os.path.join(dh_root, "etc", "dhcp", "dhclient-enter-hooks.d", + "evil"), "w") as f: + f.write("#!/bin/sh\ntouch /tmp/pwned\n") +os.chmod(os.path.join(dh_root, "etc", "dhcp", "dhclient-enter-hooks.d", + "evil"), 0o666) + +dh_good_root = tempfile.mkdtemp(prefix="apex-dhg-") +os.makedirs(os.path.join(dh_good_root, "etc", "dhcp", + "dhclient-enter-hooks.d")) +dhg_conf = os.path.join(dh_good_root, "etc", "dhcp", "dhclient.conf") +with open(dhg_conf, "w") as f: + f.write("send host-name = gethostname();\n") + f.write("request subnet-mask, broadcast-address, routers;\n") +os.chmod(dhg_conf, 0o644) +with open(os.path.join(dh_good_root, "etc", "dhcp", + "dhclient-enter-hooks.d", "local"), "w") as f: + f.write("#!/bin/sh\n:\n") +os.chmod(os.path.join(dh_good_root, "etc", "dhcp", + "dhclient-enter-hooks.d", "local"), 0o644) + +ju_root = tempfile.mkdtemp(prefix="apex-ju-") +os.makedirs(os.path.join(ju_root, "etc", "systemd")) +ju_conf = os.path.join(ju_root, "etc", "systemd", "journal-upload.conf") +with open(ju_conf, "w") as f: + f.write("[Upload]\n") + f.write("URL=http://logs.example.test:19532\n") +os.chmod(ju_conf, 0o666) + +ju_good_root = tempfile.mkdtemp(prefix="apex-jug-") +os.makedirs(os.path.join(ju_good_root, "etc", "systemd")) +jug_conf = os.path.join(ju_good_root, "etc", "systemd", + "journal-upload.conf") +with open(jug_conf, "w") as f: + f.write("[Upload]\n") + f.write("URL=https://logs.example.test:19532\n") + f.write("ServerKeyFile=/etc/ssl/private/journal-upload.pem\n") +os.chmod(jug_conf, 0o644) + +fw_root = tempfile.mkdtemp(prefix="apex-fw-") +os.makedirs(os.path.join(fw_root, "etc", "fwupd")) +fw_conf = os.path.join(fw_root, "etc", "fwupd", "daemon.conf") +with open(fw_conf, "w") as f: + f.write("[fwupd]\n") + f.write("OnlyTrusted=false\n") + f.write("DisabledPlugins=\n") +os.chmod(fw_conf, 0o666) + +fw_good_root = tempfile.mkdtemp(prefix="apex-fwg-") +os.makedirs(os.path.join(fw_good_root, "etc", "fwupd")) +fwg_conf = os.path.join(fw_good_root, "etc", "fwupd", "daemon.conf") +with open(fwg_conf, "w") as f: + f.write("[fwupd]\n") + f.write("OnlyTrusted=true\n") + f.write("DisabledPlugins=test,invalid\n") +os.chmod(fwg_conf, 0o644) + +print("fixtures written") + + +class _VaultHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + path = urllib.parse.urlsplit(self.path).path + if path == "/v1/sys/seal-status": + body = b'{"type":"shamir","initialized":true,"sealed":false}' + self.send_response(200) + elif path == "/v1/sys/mounts": + body = (b'{"secret/":{"type":"kv","description":"kv secrets"},' + b'"database/":{"type":"database"}}') + self.send_response(200) + else: + body = b'{"errors":["permission denied"]}' + self.send_response(403) + 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 _VaultClosedHandler(_VaultHandler): + def do_GET(self): + body = b'{"errors":["permission denied"]}' + self.send_response(403) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + +vl_srv = http.server.HTTPServer(("127.0.0.1", 0), _VaultHandler) +vl_port = vl_srv.server_address[1] +vl_closed_srv = http.server.HTTPServer(("127.0.0.1", 0), _VaultClosedHandler) +vl_closed_port = vl_closed_srv.server_address[1] +for _s in (vl_srv, vl_closed_srv): + threading.Thread(target=_s.serve_forever, daemon=True).start() + +cfg57_home = tempfile.mkdtemp(prefix="apex-cfg57-home-") +write_scope(cfg57_home, + {"label": "cfg57", "expires": "2099-01-01T00:00:00Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_port": ["1-65535"]}) + +res, _ = run([ + call(1, "dhclient_audit", root=dh_root), + call(2, "dhclient_audit", root=dh_good_root), + call(3, "journal_upload_audit", root=ju_root), + call(4, "journal_upload_audit", root=ju_good_root), + call(5, "fwupd_audit", root=fw_root), + call(6, "fwupd_audit", root=fw_good_root), + call(7, "vault_probe", target="127.0.0.1", port=vl_port, tls=False), + call(8, "vault_probe", target="127.0.0.1", port=vl_closed_port, + tls=False), +], home=cfg57_home) +by_id = {r["id"]: r for r in res if "id" in r} +dh = json.loads(text(by_id[1])) +dh_kinds = {f["id"] for f in dh["findings"]} +check("dhclient_audit flags a DHCP resolver, a superseded domain and a " + "writable hook", + {"world-writable", "superseded-resolver", "superseded-domain", + "dhcp-resolver", "writable-hook"} <= dh_kinds and + dh["writable_hooks"] == 1 and dh["hooks"] == 1, dh) +dh_good = json.loads(text(by_id[2])) +check("dhclient_audit accepts a plain request list and a read-only hook", + dh_good["findings_count"] == 0 and + dh_good["findings"][0]["id"] == "no-findings" and + dh_good["hooks"] == 1 and dh_good["writable_hooks"] == 0, dh_good) + +ju = json.loads(text(by_id[3])) +ju_kinds = {f["id"] for f in ju["findings"]} +check("journal_upload_audit flags plain http, a missing key and a writable " + "file", + {"plain-http", "no-client-key", "world-writable"} <= ju_kinds and + ju["plain_http"] == 1 and ju["url_set"] is True, ju) +ju_good = json.loads(text(by_id[4])) +check("journal_upload_audit accepts TLS with a client key", + ju_good["findings_count"] == 0 and + ju_good["findings"][0]["id"] == "no-findings" and + ju_good["plain_http"] == 0 and ju_good["no_client_key"] == 0, ju_good) + +fw = json.loads(text(by_id[5])) +fw_kinds = {f["id"] for f in fw["findings"]} +check("fwupd_audit flags untrusted firmware and an empty plugin list", + {"untrusted-firmware", "no-disabled-plugins", "world-writable"} <= + fw_kinds and fw["untrusted_firmware"] == 1, fw) +fw_good = json.loads(text(by_id[6])) +check("fwupd_audit accepts signed-only firmware with disabled plugins", + fw_good["findings_count"] == 0 and + fw_good["findings"][0]["id"] == "no-findings" and + fw_good["untrusted_firmware"] == 0, fw_good) + +vl = json.loads(text(by_id[7])) +check("vault_probe finds an open mount list and saves evidence", + vl["mounts_open"] is True and vl["open_count"] == 2 and + vl["sealed"] is False and + os.path.isfile(vl["evidence"]) and + "secret/" in open(vl["evidence"]).read(), vl) +vl_closed = json.loads(text(by_id[8])) +check("vault_probe reports a closed mount list as not open", + vl_closed["mounts_open"] is False and + vl_closed["evidence"] is None and + all(e["open"] is False for e in vl_closed["endpoints"]), vl_closed) + +vl_srv.shutdown() +vl_closed_srv.shutdown() +for d in (dh_root, dh_good_root, ju_root, ju_good_root, fw_root, + fw_good_root, cfg57_home): + shutil.rmtree(d, ignore_errors=True) + + # --- 1.84.0: gated wrappers for external scanners (mock binaries) --- print("\n== external scanner wrappers ==\n")