From 7179772face3a1eb343279a819654ce07433331d Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 23 Nov 2026 11:30:32 +0000 Subject: [PATCH] apex-twin 1.83.0: PHP-FPM, uWSGI and lighttpd audits, Superset probe Three blue config audits: php_fpm_audit (pool files in /etc/php-fpm.d, /etc/php//fpm/pool.d and /etc/php-fpm.conf - root pool user, a 0666 listen.mode socket, display_errors in php_admin_value), uwsgi_audit (uid/gid 0, empty module list, world-writable ini) and lighttpd_audit (document-root /, no SSL engine, dir-listing, world-writable config). One red probe: superset_probe reads /api/v1/dashboard and /login without a token and saves the dashboard list as evidence. Verified: make test 1407/1407, test-asan 1407/1407, gate-audit 366 tools OK, analyze 0 warnings, 240 fuzz cases, coverage 85.0%, release-check exit 0 (348 s, distcheck from the tarball included). Counter-proof: removing the root-pool check turns the php_fpm test red, restoring it green. --- CHANGELOG.md | 21 ++ README.md | 15 +- SECURITY.md | 2 +- docs/apex-twin.1 | 7 +- src/apex.h | 2 +- src/tools_blue.c | 717 ++++++++++++++++++++++++++++++++++++++++++++ src/tools_red.c | 100 ++++++ tests/gate_audit.py | 2 +- tests/run.py | 190 +++++++++++- 9 files changed, 1043 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 712df42..dd5fe0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## 1.83.0 - 2026-11-24 - this change + +- **PHP-FPM** (`php_fpm_audit`): pool files in `/etc/php-fpm.d`, + `/etc/php//pool.d` and `/etc/php//fpm/pool.d`. Flags a pool that + runs with `user = root`, a `listen.mode` of 0666/777 (any local user can + talk to the FastCGI socket) or any mode that is not 0660, a `listen` value + without a path (TCP instead of a unix socket), `display_errors = On` and + `allow_url_include = On` in the pool's `php_admin_value[...]` keys, a + cleared `disable_functions`, and a writable pool file. +- **uWSGI** (`uwsgi_audit`): `/etc/uwsgi.ini`, `/etc/uwsgi/uwsgi.ini` and + `apps-enabled/*.{ini,conf}`. Flags `uid`/`gid` 0, `chmod-socket` 666/777, + `chdir = /`, `master = false` and a writable ini. +- **lighttpd** (`lighttpd_audit`): `lighttpd.conf` and `conf-enabled/*`. + Flags `server.document-root = "/"`, a missing or disabled `ssl.engine`, + `dir-listing.activate = "enable"`, `server.username`/`server.groupname` + root, and a writable config. +- **Superset** (`superset_probe`): `/health`, `/login` and + `/api/v1/dashboard/` on 8088 without a session. A 2xx dashboard list with + a `result` array is an unauthenticated instance; the list is saved as + evidence. + ## 1.82.0 - 2026-11-24 - this change - **apt auth** (`apt_auth_audit`): `/etc/apt/auth.conf` and diff --git a/README.md b/README.md index 8fe212f..99cde96 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. -**362 tools · 1398 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB** +**366 tools · 1407 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB** ``` $ ./apex-twin --check -{"version":"1.82.0","tools":362,...,"scope":{"loaded":true,...}} +{"version":"1.83.0","tools":366,...,"scope":{"loaded":true,...}} ``` APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope @@ -239,6 +239,7 @@ uploads and secret-file reads. It does not execute anything. | `ollama_probe` | `/api/tags` on 11434 without auth; pulled model list as evidence | | `cadvisor_probe` | `/api/v1/containers` on 8080 without auth; container list as evidence | | `teamcity_probe` | `/app/rest/projects` and `/app/rest/users` without auth; project and user list as evidence | +| `superset_probe` | `/api/v1/dashboard/` on 8088 without a session; dashboard list 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 | @@ -544,6 +545,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack. | `apt_auth_audit` | apt auth.conf: credentials over plain HTTP, world-readable/writable file | | `aliases_audit` | aliases: mail piped into a command, root mail forwarded to another account | | `netgroup_audit` | netgroup: member with an empty host field (matches any host) | +| `php_fpm_audit` | PHP-FPM pools: user root, `listen.mode` 0666/777, display_errors, allow_url_include | +| `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 | | `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 | @@ -1027,7 +1031,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery, keycloak_probe, rundeck_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, - argocd_probe, kafka_connect_probe + superset_probe, argocd_probe, kafka_connect_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, @@ -1047,7 +1051,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit, clamav_audit, modules_load_audit, depmod_audit, adduser_conf_audit, nfs_conf_audit, idmapd_audit, netplan_audit, - apt_auth_audit, aliases_audit, netgroup_audit) + apt_auth_audit, aliases_audit, netgroup_audit, + php_fpm_audit, uwsgi_audit, lighttpd_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 @@ -1084,7 +1089,7 @@ examples/ scope.json ## Status -1.82.0. Built and run: 362 tools, 1398 checks, 240 fuzz cases and 85.0% line +1.83.0. Built and run: 366 tools, 1407 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 7bca694..0e3159b 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.82.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.83.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 c8ec610..921cea0 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.82.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.83.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, 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, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe), +websocket_origin_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, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, integrity_baseline, mitre_map, process_snapshot, persistence_audit, @@ -93,7 +93,8 @@ aide_audit, nscd_audit, faillock_audit, networkd_audit, namespace_audit, ssh_client_audit, ufw_audit, monit_audit, clamav_audit, modules_load_audit, depmod_audit, adduser_conf_audit, nfs_conf_audit, idmapd_audit, netplan_audit, -apt_auth_audit, aliases_audit, netgroup_audit) +apt_auth_audit, aliases_audit, netgroup_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, esp_app_info, esp_image_verify). diff --git a/src/apex.h b/src/apex.h index b11d94a..05f9530 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.82.0" +#define APEX_VERSION "1.83.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 182088d..2149eda 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -27099,6 +27099,693 @@ static void t_netgroup_audit(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&findings); } +/* ------------------------------------------------------------- php_fpm_audit */ + +/* PHP-FPM reads one [pool] section per .conf file in php-fpm.d and + * /etc/php-fpm.d. The pool user decides which account runs the scripts, the + * listen value decides who can talk to the socket, and php_admin_value flags + * turn php.ini settings off inside the pool. A pool that runs as root, a unix + * socket any local user can write to, and display_errors switched on all hand + * out more than the site intends. */ +typedef struct { + int files; + int pools; + int root_user; + int world_writable_socket; + int tcp_socket; + int display_errors; + int url_include; + int disabled_functions_cleared; + int world_writable; +} fpm_state; + +/* Strip the surrounding quotes PHP allows around a value, then trailing + * blanks. The result points into the same buffer. */ +static char *fpm_clean_value(char *v) +{ + size_t n; + + while (*v == ' ' || *v == '\t') + v++; + n = strlen(v); + while (n > 0 && (v[n - 1] == ' ' || v[n - 1] == '\t' || + v[n - 1] == '\r')) + v[--n] = '\0'; + if (n >= 2 && (v[0] == '"' || v[0] == '\'') && v[n - 1] == v[0]) { + v[n - 1] = '\0'; + v++; + } + return v; +} + +static int fpm_scan_file(fpm_state *st, const char *path, + mcp_buf *findings, int *first, int *count) +{ + static char text[65536]; + struct stat sb; + const char *p; + int in_pool = 0; + + if (read_text(path, text, sizeof(text)) <= 0) + return 0; + 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; a pool definition " + "decides which account runs PHP", path); + (*count)++; + } + p = text; + while (p != NULL && *p != '\0') { + const char *eol = strchr(p, '\n'); + size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p); + char line[2048]; + char *s; + char *eq; + + if (len >= sizeof(line)) + len = sizeof(line) - 1; + memcpy(line, p, len); + line[len] = '\0'; + p = eol != NULL ? eol + 1 : NULL; + s = line; + while (*s == ' ' || *s == '\t') + s++; + if (*s == '[') { + char *close = strchr(s, ']'); + + /* Debian and upstream both allow [www] as well as + * [pool www]; only [global] is not a pool. */ + in_pool = close != NULL && + strncasecmp(s + 1, "global", 6) != 0; + if (in_pool) + st->pools++; + continue; + } + if (!in_pool || *s == ';' || *s == '#' || *s == '\0') + continue; + eq = strchr(s, '='); + if (eq == NULL) + continue; + *eq = '\0'; + { + char *k = s; + size_t ke = strlen(k); + + while (ke > 0 && (k[ke - 1] == ' ' || k[ke - 1] == '\t')) + k[--ke] = '\0'; + { + char *v = fpm_clean_value(eq + 1); + + if (strcasecmp(k, "user") == 0 && + (strcmp(v, "root") == 0 || + strcmp(v, "0") == 0)) + st->root_user++; + else if (strcasecmp(k, "listen") == 0) { + if (strchr(v, '/') == NULL) + st->tcp_socket++; + } else if (strcasecmp(k, "listen.mode") == 0) { + /* The socket only exists while FPM + * runs, so the mode line is what + * decides who may connect. */ + if (strstr(v, "666") != NULL || + strstr(v, "777") != NULL || + strstr(v, "660") == NULL) + st->world_writable_socket++; + } else if ((strcasecmp(k, "php_admin_value") == 0 || + strcasecmp(k, "php_value") == 0) && + strstr(v, "disable_functions") != NULL) { + char *bar = strchr(v, '='); + + if (bar != NULL && + fpm_clean_value(bar + 1)[0] == '\0') + st->disabled_functions_cleared++; + } else if (strncmp(k, "php_admin_value[", 16) == 0 || + strncmp(k, "php_value[", 10) == 0) { + /* The setting name sits in the key: + * php_admin_value[display_errors] = On */ + const char *open = strchr(k, '['); + const char *close = strrchr(k, ']'); + char name[64]; + + if (open != NULL && close != NULL && + close > open && + (size_t)(close - open - 1) < + sizeof(name)) { + size_t nl = + (size_t)(close - open - 1); + + memcpy(name, open + 1, nl); + name[nl] = '\0'; + if (strcasecmp(name, + "display_errors") == 0 && + (strcasecmp(v, "on") == 0 || + strcmp(v, "1") == 0 || + strcasecmp(v, "true") == 0)) + st->display_errors++; + else if (strcasecmp(name, + "allow_url_include") == 0 && + (strcasecmp(v, "on") == 0 || + strcmp(v, "1") == 0 || + strcasecmp(v, "true") == 0)) + st->url_include++; + } + } + } + } + } + return 1; +} + +static void fpm_scan_dir(fpm_state *st, const char *dir, mcp_buf *findings, + int *first, int *count) +{ + DIR *d = opendir(dir); + + if (d == NULL) + return; + for (;;) { + struct dirent *ent = readdir(d); + char full[1200]; + size_t nl; + + if (ent == NULL) + break; + if (ent->d_name[0] == '.') + continue; + nl = strlen(ent->d_name); + if (nl < 6 || strcmp(ent->d_name + nl - 5, ".conf") != 0) + continue; + snprintf(full, sizeof(full), "%.900s/%.200s", dir, ent->d_name); + fpm_scan_file(st, full, findings, first, count); + } + closedir(d); +} + +static void t_php_fpm_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char path[1200]; + fpm_state st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + + (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); + snprintf(path, sizeof(path), "%.400s/etc/php-fpm.conf", root); + fpm_scan_file(&st, path, &findings, &first, &count); + snprintf(path, sizeof(path), "%.400s/etc/php-fpm.d", root); + fpm_scan_dir(&st, path, &findings, &first, &count); + snprintf(path, sizeof(path), "%.400s/etc/php", root); + { + DIR *d = opendir(path); + + if (d != NULL) { + for (;;) { + struct dirent *ver = readdir(d); + char vd[1200]; + + if (ver == NULL) + break; + if (ver->d_name[0] == '.') + continue; + snprintf(vd, sizeof(vd), "%.900s/%.200s", path, + ver->d_name); + snprintf(path, sizeof(path), "%.1000s/pool.d", vd); + fpm_scan_dir(&st, path, &findings, &first, + &count); + snprintf(path, sizeof(path), "%.1000s/fpm/pool.d", + vd); + fpm_scan_dir(&st, path, &findings, &first, + &count); + snprintf(path, sizeof(path), "%.400s/etc/php", + root); + } + closedir(d); + } + } + if (st.files == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read /etc/php-fpm.d, /etc/php-fpm.conf " + "or /etc/php/*/pool.d below the root prefix"); + return; + } + if (st.root_user > 0) { + add_finding(&findings, &first, "pool-user-root", "high", + "%d pool(s) run as root; a PHP bug then writes with " + "full privileges", st.root_user); + count++; + } + if (st.world_writable_socket > 0) { + add_finding(&findings, &first, "world-writable-socket", "high", + "%d unix socket(s) are writable by any local user; " + "anyone can speak FPM there", + st.world_writable_socket); + count++; + } + if (st.tcp_socket > 0) { + add_finding(&findings, &first, "tcp-socket", "medium", + "%d pool(s) listen on TCP instead of a unix socket; " + "the FastCGI port is reachable from the network", + st.tcp_socket); + count++; + } + if (st.display_errors > 0) { + add_finding(&findings, &first, "display-errors", "medium", + "%d pool(s) turn display_errors on; PHP warnings leak " + "paths and query fragments to the visitor", + st.display_errors); + count++; + } + if (st.disabled_functions_cleared > 0) { + add_finding(&findings, &first, "disabled-functions-cleared", + "medium", + "%d pool(s) clear disable_functions; exec, system and " + "shell hooks are available to the scripts", + st.disabled_functions_cleared); + count++; + } + if (st.url_include > 0) { + add_finding(&findings, &first, "url-include", "high", + "%d pool(s) enable allow_url_include; a remote file " + "becomes includable code", st.url_include); + count++; + } + if (count == 0) + add_finding(&findings, &first, "no-findings", "info", + "the pools run unprivileged, listen on a protected unix " + "socket and keep errors out of the response"); + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"pools\":%d,\"root_user\":%d," + "\"world_writable_socket\":%d,\"tcp_socket\":%d," + "\"display_errors\":%d,\"url_include\":%d," + "\"disabled_functions_cleared\":%d," + "\"world_writable\":%d,\"findings_count\":%d," + "\"findings\":[", + st.files, st.pools, st.root_user, + st.world_writable_socket, st.tcp_socket, + st.display_errors, st.url_include, + st.disabled_functions_cleared, + 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); +} + +/* ---------------------------------------------------------------- uwsgi_audit */ + +/* A uWSGI ini is flat "key = value" under an optional [uwsgi] header. The + * interesting keys are uid/gid (0 means the worker keeps root), chmod-socket + * (a socket every local user can talk to), chdir (serving from /), and a + * master process that was switched off. */ +typedef struct { + int files; + int root_uid; + int root_gid; + int world_socket; + int serve_root; + int world_writable; + int no_master; +} uwsgi_state; + +static void uwsgi_scan_file(uwsgi_state *st, const char *path, + mcp_buf *findings, int *first, int *count) +{ + static char text[65536]; + struct stat sb; + const char *p; + + 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 " + "code the app server loads", path); + (*count)++; + } + p = text; + while (p != NULL && *p != '\0') { + const char *eol = strchr(p, '\n'); + size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p); + char line[2048]; + char *s; + char *eq; + + if (len >= sizeof(line)) + len = sizeof(line) - 1; + memcpy(line, p, len); + line[len] = '\0'; + p = eol != NULL ? eol + 1 : NULL; + s = line; + while (*s == ' ' || *s == '\t') + s++; + if (*s == '[' || *s == ';' || *s == '#' || *s == '\0') + continue; + eq = strchr(s, '='); + if (eq == NULL) + continue; + *eq = '\0'; + { + char *k = s; + size_t ke = strlen(k); + char *v; + + while (ke > 0 && (k[ke - 1] == ' ' || k[ke - 1] == '\t')) + k[--ke] = '\0'; + v = fpm_clean_value(eq + 1); + if (strcasecmp(k, "uid") == 0 && strcmp(v, "0") == 0) + st->root_uid++; + else if (strcasecmp(k, "gid") == 0 && strcmp(v, "0") == 0) + st->root_gid++; + else if (strcasecmp(k, "chmod-socket") == 0 && + (strstr(v, "666") != NULL || + strstr(v, "777") != NULL)) + st->world_socket++; + else if (strcasecmp(k, "chdir") == 0 && + strcmp(v, "/") == 0) + st->serve_root++; + else if (strcasecmp(k, "master") == 0 && + (strcmp(v, "false") == 0 || + strcmp(v, "0") == 0)) + st->no_master++; + } + } +} + +static void uwsgi_scan_dir(uwsgi_state *st, const char *dir, + mcp_buf *findings, int *first, int *count) +{ + DIR *d = opendir(dir); + + if (d == NULL) + return; + for (;;) { + struct dirent *ent = readdir(d); + char full[1200]; + size_t nl; + + if (ent == NULL) + break; + if (ent->d_name[0] == '.') + continue; + nl = strlen(ent->d_name); + if (nl < 5) + continue; + if (strcmp(ent->d_name + nl - 5, ".conf") != 0 && + strcmp(ent->d_name + nl - 4, ".ini") != 0) + continue; + snprintf(full, sizeof(full), "%.900s/%.200s", dir, ent->d_name); + uwsgi_scan_file(st, full, findings, first, count); + } + closedir(d); +} + +static void t_uwsgi_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *names[] = { "/etc/uwsgi.ini", "/etc/uwsgi/uwsgi.ini", + "/etc/uwsgi/apps-enabled", NULL }; + const char *root = mcp_arg_string(args, "root"); + char path[1200]; + uwsgi_state st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int i; + + (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; names[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, names[i]); + if (strcmp(names[i], "/etc/uwsgi/apps-enabled") == 0) + uwsgi_scan_dir(&st, path, &findings, &first, &count); + else + uwsgi_scan_file(&st, path, &findings, &first, &count); + } + if (st.files == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read /etc/uwsgi.ini, " + "/etc/uwsgi/uwsgi.ini or /etc/uwsgi/apps-enabled " + "below the root prefix"); + return; + } + if (st.root_uid > 0 || st.root_gid > 0) { + add_finding(&findings, &first, "runs-as-root", "high", + "%d setting(s) keep the workers on uid or gid 0; the " + "app server then runs with full privileges", + st.root_uid + st.root_gid); + count++; + } + if (st.world_socket > 0) { + add_finding(&findings, &first, "world-socket", "high", + "%d socket(s) are created with mode 666 or 777; any " + "local user can speak to the app", st.world_socket); + count++; + } + if (st.serve_root > 0) { + add_finding(&findings, &first, "serve-root", "medium", + "%d instance(s) chdir to /; the whole filesystem is in " + "reach of the app", st.serve_root); + count++; + } + if (st.no_master > 0) { + add_finding(&findings, &first, "no-master", "low", + "%d instance(s) disable the master process; a crash " + "takes the whole worker pool down", st.no_master); + count++; + } + if (count == 0) + add_finding(&findings, &first, "no-findings", "info", + "the workers drop privileges, keep the socket private " + "and run under a master process"); + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"root_uid\":%d,\"root_gid\":%d," + "\"world_socket\":%d,\"serve_root\":%d," + "\"no_master\":%d,\"world_writable\":%d," + "\"findings_count\":%d,\"findings\":[", + st.files, st.root_uid, st.root_gid, st.world_socket, + st.serve_root, st.no_master, 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); +} + +/* ------------------------------------------------------------- lighttpd_audit */ + +/* lighttpd.conf is a nested config: "key => value" lines, blocks in braces + * and include lines. The interesting settings are server.document-root + * (serving / exposes the whole filesystem), a disabled ssl.engine, an + * activated dir-listing, server.username/server.groupname set to root, and a + * writable configuration file. */ +typedef struct { + int files; + int serve_root; + int ssl_off; + int dir_listing; + int run_as_root; + int world_writable; +} lighttpd_state; + +static void lighttpd_scan_file(lighttpd_state *st, const char *path, + mcp_buf *findings, int *first, int *count) +{ + static char text[65536]; + struct stat sb; + const char *p; + int ssl_seen = 0; + + 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 what the " + "web server serves", path); + (*count)++; + } + p = text; + while (p != NULL && *p != '\0') { + const char *eol = strchr(p, '\n'); + size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p); + char line[2048]; + char *s; + char *arrow; + + if (len >= sizeof(line)) + len = sizeof(line) - 1; + memcpy(line, p, len); + line[len] = '\0'; + p = eol != NULL ? eol + 1 : NULL; + s = line; + while (*s == ' ' || *s == '\t') + s++; + if (*s == '#' || *s == '\0') + continue; + arrow = strchr(s, '='); + if (arrow == NULL) + continue; + /* lighttpd writes both "key => value" and "key = value"; only + * the first '=' separates the key, an optional '>' is skipped + * by fpm_clean_value's leading-blank trim. */ + *arrow = '\0'; + { + char *k = s; + size_t ke = strlen(k); + char *v; + + while (ke > 0 && (k[ke - 1] == ' ' || k[ke - 1] == '\t')) + k[--ke] = '\0'; + v = arrow + 1; + if (*v == '>') + v++; + v = fpm_clean_value(v); + if (strcasecmp(k, "server.document-root") == 0 && + strcmp(v, "/") == 0) + st->serve_root++; + else if (strcasecmp(k, "ssl.engine") == 0) { + ssl_seen = 1; + if (strcasecmp(v, "disable") == 0 || + strcmp(v, "0") == 0) + st->ssl_off++; + } else if (strcasecmp(k, "dir-listing.activate") == 0 && + strcasecmp(v, "enable") == 0) + st->dir_listing++; + else if ((strcasecmp(k, "server.username") == 0 || + strcasecmp(k, "server.groupname") == 0) && + strcmp(v, "root") == 0) + st->run_as_root++; + } + } + if (!ssl_seen) + st->ssl_off++; +} + +static void t_lighttpd_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *names[] = { "/etc/lighttpd/lighttpd.conf", + "/etc/lighttpd/conf-enabled", NULL }; + const char *root = mcp_arg_string(args, "root"); + char path[1200]; + lighttpd_state st; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int i; + + (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; names[i] != NULL; i++) { + snprintf(path, sizeof(path), "%.400s%s", root, names[i]); + if (strcmp(names[i], "/etc/lighttpd/conf-enabled") == 0) { + DIR *d = opendir(path); + struct dirent *ent; + + if (d == NULL) + continue; + while ((ent = readdir(d)) != NULL) { + char full[1200]; + + if (ent->d_name[0] == '.') + continue; + snprintf(full, sizeof(full), "%.900s/%.200s", path, + ent->d_name); + lighttpd_scan_file(&st, full, &findings, &first, + &count); + } + closedir(d); + } else { + lighttpd_scan_file(&st, path, &findings, &first, &count); + } + } + if (st.files == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read /etc/lighttpd/lighttpd.conf or " + "/etc/lighttpd/conf-enabled below the root prefix"); + return; + } + if (st.serve_root > 0) { + add_finding(&findings, &first, "serve-root", "high", + "%d setting(s) use / as document root; every readable " + "file on the host is served", st.serve_root); + count++; + } + if (st.ssl_off > 0) { + add_finding(&findings, &first, "no-tls", "medium", + "ssl.engine is missing or disabled in %d place(s); the " + "site is served over plain HTTP", st.ssl_off); + count++; + } + if (st.dir_listing > 0) { + add_finding(&findings, &first, "dir-listing", "medium", + "dir-listing.activate is enabled in %d place(s); every " + "directory without an index is listed", st.dir_listing); + count++; + } + if (st.run_as_root > 0) { + add_finding(&findings, &first, "runs-as-root", "high", + "%d setting(s) run the server as root; a bug in a module " + "is a root bug", st.run_as_root); + count++; + } + if (count == 0) + add_finding(&findings, &first, "no-findings", "info", + "the document root is scoped, TLS is on, directory " + "listing is off and the server drops privileges"); + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"serve_root\":%d,\"ssl_off\":%d," + "\"dir_listing\":%d,\"run_as_root\":%d," + "\"world_writable\":%d,\"findings_count\":%d," + "\"findings\":[", + st.files, st.serve_root, st.ssl_off, st.dir_listing, + st.run_as_root, 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); +} + const mcp_tool TOOLS_BLUE[] = { { "hardening_audit", "Read-only posture audit of the local host: sshd_config (root login, " @@ -28610,6 +29297,36 @@ const mcp_tool TOOLS_BLUE[] = { "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " "empty\"}}}", t_netgroup_audit }, + { "php_fpm_audit", + "Parse PHP-FPM pool definitions (root prefix): /etc/php-fpm.conf, " + "/etc/php-fpm.d/*.conf and /etc/php/*/pool.d/*.conf. Flags a pool " + "that runs as root, a unix socket any local user can write to, a " + "pool listening on TCP, display_errors switched on in the pool, a " + "cleared disable_functions, and a writable pool file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " + "empty\"}}}", + t_php_fpm_audit }, + { "uwsgi_audit", + "Parse uWSGI configuration (root prefix): /etc/uwsgi.ini, " + "/etc/uwsgi/uwsgi.ini and /etc/uwsgi/apps-enabled/*.{ini,conf}. " + "Flags workers that keep uid or gid 0, a socket created with mode " + "666/777, a chdir of / and a switched-off master process, plus a " + "writable configuration file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " + "empty\"}}}", + t_uwsgi_audit }, + { "lighttpd_audit", + "Parse lighttpd configuration (root prefix): lighttpd.conf and " + "conf-enabled/*. Flags server.document-root /, a missing or disabled " + "ssl.engine, dir-listing.activate = enable and server.username/" + "server.groupname root, plus a writable configuration file. " + "Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default " + "empty\"}}}", + t_lighttpd_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 8a4f734..f94c89b 100644 --- a/src/tools_red.c +++ b/src/tools_red.c @@ -9353,6 +9353,95 @@ static void t_ollama_probe(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&b); } +/* --------------------------------------------------------------- superset_probe */ + +/* Superset on 8088: /api/v1/dashboard/ answers 200 with a result list even + * for an anonymous visitor when PUBLIC_ROLE_LIKE is set or the login page + * was left open. /login and /health are the liveness markers, the dashboard + * list is the exposure and the evidence. */ +static void t_superset_probe(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *paths[] = { "/health", "/login", + "/api/v1/dashboard/", NULL }; + const char *target = mcp_arg_string(args, "target"); + int port = mcp_arg_int(args, "port", 8088); + 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 data_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, "superset_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 data = strstr(paths[i], "/api/v1/") != 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 && + (resp == NULL || strstr(resp, "\"errors\"") == NULL); + if (open) + open_count++; + if (open && data && resp != NULL && + strstr(resp, "\"result\"") != NULL) { + data_open = 1; + if (evidence == NULL) + evidence = apex_evidence_save("superset-dashboards", + 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," + "\"data_open\":%s,\"evidence\":", + tested, open_count, data_open ? "true" : "false"); + if (evidence != NULL) + apex_json_str(&b, evidence); + else + mcp_buf_puts(&b, "null"); + mcp_buf_puts(&b, "}"); + apex_audit("superset_probe", target, port, !data_open, + data_open + ? "Superset lists dashboards without a session" + : "Superset requires a session for the dashboard list", "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: " @@ -10098,6 +10187,17 @@ const mcp_tool TOOLS_RED[] = { "\"tls\":{\"type\":\"boolean\"}}," "\"required\":[\"target\"]}", t_teamcity_probe }, + { "superset_probe", + "Get /health, /login and /api/v1/dashboard/ without a session. A 2xx " + "on the dashboard list with a result array is an unauthenticated " + "Superset and is saved as evidence. Reports every endpoint's status.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\",\"description\":\"host or IP in " + "scope\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 8088\"}," + "\"tls\":{\"type\":\"boolean\"}}," + "\"required\":[\"target\"]}", + t_superset_probe }, { "cadvisor_probe", "Query cAdvisor on 8080 for /healthz, /api/v1/containers and " "/api/v2.0/attributes without credentials. A 2xx on the container " diff --git a/tests/gate_audit.py b/tests/gate_audit.py index bb9e12d..3a2c75d 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 = 362 +EXPECTED_TOOLS = 366 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 94c2d46..951a936 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("362 tools registered", len(tools) == 362, len(tools)) +check("366 tools registered", len(tools) == 366, 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"]) == 362) + check("http tools/list", len(listing["result"]["tools"]) == 366) 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 @@ -16506,6 +16506,192 @@ for d in (aa_root, aa_good_root, al_root, al_good_root, ng_root, ng_good_root, cfg54_home): shutil.rmtree(d, ignore_errors=True) +# --- 1.83.0: php-fpm, uwsgi and lighttpd audits plus the Superset probe --- +print("\n== php-fpm, uWSGI, lighttpd and Superset ==") + +fpm_root = tempfile.mkdtemp(prefix="apex-fpm-") +os.makedirs(os.path.join(fpm_root, "etc", "php", "8.2", "fpm", "pool.d")) +fpm_bad = os.path.join(fpm_root, "etc", "php", "8.2", "fpm", "pool.d", + "www.conf") +with open(fpm_bad, "w") as f: + f.write("[www]\n") + f.write("user = root\n") + f.write("group = root\n") + f.write("listen = /run/php/www.sock\n") + f.write("listen.mode = 0666\n") + f.write("php_admin_value[display_errors] = On\n") + f.write("php_admin_flag[allow_url_include] = on\n") +os.chmod(fpm_bad, 0o666) + +fpm_good_root = tempfile.mkdtemp(prefix="apex-fpmg-") +os.makedirs(os.path.join(fpm_good_root, "etc", "php", "8.2", "fpm", + "pool.d")) +with open(os.path.join(fpm_good_root, "etc", "php", "8.2", "fpm", "pool.d", + "www.conf"), "w") as f: + f.write("[www]\n") + f.write("user = www-data\n") + f.write("group = www-data\n") + f.write("listen = /run/php/www.sock\n") + f.write("listen.mode = 0660\n") + f.write("php_admin_value[display_errors] = Off\n") + +uw_root = tempfile.mkdtemp(prefix="apex-uw-") +os.makedirs(os.path.join(uw_root, "etc", "uwsgi", "apps-enabled")) +uw_bad = os.path.join(uw_root, "etc", "uwsgi", "apps-enabled", "app.ini") +with open(uw_bad, "w") as f: + f.write("[uwsgi]\n") + f.write("uid = 0\n") + f.write("gid = 0\n") + f.write("chmod-socket = 666\n") + f.write("chdir = /\n") + f.write("master = false\n") +os.chmod(uw_bad, 0o666) + +uw_good_root = tempfile.mkdtemp(prefix="apex-uwg-") +os.makedirs(os.path.join(uw_good_root, "etc", "uwsgi", "apps-enabled")) +with open(os.path.join(uw_good_root, "etc", "uwsgi", "apps-enabled", + "app.ini"), "w") as f: + f.write("[uwsgi]\n") + f.write("uid = www-data\n") + f.write("gid = www-data\n") + f.write("chmod-socket = 660\n") + f.write("chdir = /srv/app\n") + f.write("master = true\n") + +lt_root = tempfile.mkdtemp(prefix="apex-lt-") +os.makedirs(os.path.join(lt_root, "etc", "lighttpd", "conf-enabled")) +with open(os.path.join(lt_root, "etc", "lighttpd", "lighttpd.conf"), + "w") as f: + f.write('server.document-root = "/"\n') + f.write('server.username = "root"\n') + f.write('ssl.engine = "disable"\n') + f.write('dir-listing.activate = "enable"\n') + +lt_good_root = tempfile.mkdtemp(prefix="apex-ltg-") +os.makedirs(os.path.join(lt_good_root, "etc", "lighttpd")) +with open(os.path.join(lt_good_root, "etc", "lighttpd", "lighttpd.conf"), + "w") as f: + f.write('server.document-root = "/var/www/html"\n') + f.write('server.username = "www-data"\n') + f.write('ssl.engine = "enable"\n') + f.write('dir-listing.activate = "disable"\n') + +class _SupersetHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + path = urllib.parse.urlsplit(self.path).path + if path == "/health": + body = b'{"status":"OK"}' + self.send_response(200) + elif path == "/login": + body = b'login' + self.send_response(200) + elif path == "/api/v1/dashboard/": + body = b'{"result":[{"id":1,"dashboard_title":"Finance"}]}' + self.send_response(200) + else: + body = b'{"errors":[{"message":"not found"}]}' + self.send_response(404) + 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 _SupersetClosedHandler(_SupersetHandler): + def do_GET(self): + body = b'{"errors":[{"message":"Unauthorized"}]}' + self.send_response(401) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + +ss_srv = http.server.HTTPServer(("127.0.0.1", 0), _SupersetHandler) +ss_port = ss_srv.server_address[1] +threading.Thread(target=ss_srv.serve_forever, daemon=True).start() +ss_closed_srv = http.server.HTTPServer(("127.0.0.1", 0), + _SupersetClosedHandler) +ss_closed_port = ss_closed_srv.server_address[1] +threading.Thread(target=ss_closed_srv.serve_forever, daemon=True).start() + +cfg55_home = tempfile.mkdtemp(prefix="apex-cfg55-home-") +write_scope(cfg55_home, + {"label": "cfg55", "expires": "2099-01-01T00:00:00Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_port": [str(ss_port), str(ss_closed_port)]}) + +res, _ = run([ + call(1, "php_fpm_audit", root=fpm_root), + call(2, "php_fpm_audit", root=fpm_good_root), + call(3, "uwsgi_audit", root=uw_root), + call(4, "uwsgi_audit", root=uw_good_root), + call(5, "lighttpd_audit", root=lt_root), + call(6, "lighttpd_audit", root=lt_good_root), + call(7, "superset_probe", target="127.0.0.1", port=ss_port, tls=False), + call(8, "superset_probe", target="127.0.0.1", port=ss_closed_port, + tls=False), + call(9, "superset_probe", target="198.51.100.9", port=ss_port, tls=False), +], home=cfg55_home) +by_id = {r.get("id"): r for r in res} + +fpm = json.loads(text(by_id[1])) +fpm_kinds = {f["id"] for f in fpm["findings"]} +check("php_fpm_audit flags a root pool, a 0666 socket and display_errors", + {"world-writable", "pool-user-root", "world-writable-socket", + "display-errors"} <= fpm_kinds and fpm["pools"] == 1 and + fpm["root_user"] == 1 and fpm["display_errors"] == 1, fpm) +fpm_good = json.loads(text(by_id[2])) +check("php_fpm_audit accepts an unprivileged pool with a 0660 socket", + fpm_good["root_user"] == 0 and fpm_good["world_writable_socket"] == 0 + and fpm_good["display_errors"] == 0 and + fpm_good["findings"][0]["id"] == "no-findings", fpm_good) + +uw = json.loads(text(by_id[3])) +uw_kinds = {f["id"] for f in uw["findings"]} +check("uwsgi_audit flags uid/gid 0, a 666 socket and chdir /", + {"world-writable", "runs-as-root", "world-socket", "serve-root", + "no-master"} <= uw_kinds and uw["root_uid"] == 1 and + uw["root_gid"] == 1 and uw["world_socket"] == 1, uw) +uw_good = json.loads(text(by_id[4])) +check("uwsgi_audit accepts a dropped uid and a private socket", + uw_good["root_uid"] == 0 and uw_good["world_socket"] == 0 and + uw_good["serve_root"] == 0 and uw_good["no_master"] == 0, uw_good) + +lt = json.loads(text(by_id[5])) +lt_kinds = {f["id"] for f in lt["findings"]} +check("lighttpd_audit flags document-root /, no TLS and dir listing", + {"serve-root", "no-tls", "dir-listing", "runs-as-root"} <= lt_kinds + and lt["serve_root"] == 1 and lt["ssl_off"] == 1 and + lt["dir_listing"] == 1, lt) +lt_good = json.loads(text(by_id[6])) +check("lighttpd_audit accepts a scoped root with TLS and no listing", + lt_good["serve_root"] == 0 and lt_good["ssl_off"] == 0 and + lt_good["dir_listing"] == 0 and lt_good["run_as_root"] == 0, + lt_good) + +ss = json.loads(text(by_id[7])) +check("superset_probe finds an open dashboard API and saves evidence", + ss["data_open"] is True and ss["open_count"] == 3 and + os.path.isfile(ss["evidence"]), ss) +ss_closed = json.loads(text(by_id[8])) +check("superset_probe reports a 401 dashboard API as not open", + ss_closed["data_open"] is False and ss_closed["open_count"] == 0, + ss_closed) +ss_out = by_id[9] +check("superset_probe refuses an out-of-scope target", bool(err(ss_out)), + ss_out) + +ss_srv.shutdown() +ss_closed_srv.shutdown() + +for d in (fpm_root, fpm_good_root, uw_root, uw_good_root, lt_root, + lt_good_root, cfg55_home): + shutil.rmtree(d, ignore_errors=True) + print("%d passed, %d failed" % (passes, len(fails))) if fails: print("failed: " + ", ".join(fails))