From 81589e02523316fed28452dadc5cd4eaa606937f Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 23 Nov 2026 16:51:27 +0000 Subject: [PATCH] apex-twin 1.94.0: opendkim and rspamd audits, Confluence probe Three new tools (406 total): - opendkim_audit (blue): opendkim.conf and /etc/opendkim - inet: milter socket reachable from the network, RequireSafeKeys no, Mode without "s" (verifies but never signs), Syslog debug leaking content and key paths. An empty tree reports no-config instead of missing Socket/Mode lines. - rspamd_audit (blue): UCL config and local.d fragments - bind_socket on *, 0.0.0.0 or :: with a port, clear-text password/enable_password and secure_ip 0.0.0.0/0 or ::/0 (password check skipped for every client). Fragments matched by .conf, .inc and .local; "*:port" counts as wildcard. - confluence_probe (red): /status plus /rest/api/space?limit=5 on 8090 without a token; the space list is saved as evidence, 401/403 is closed. Evidence: make test 1501/1501, test-asan 1501/1501, analyze 0 warnings, 240 fuzz cases clean, gate-audit 406 tools from 14 tables, distcheck 1.94.0 builds and passes from the tarball, release-check exit 0 (371 s). Red proof: with the Mode sign check disabled the opendkim check fails (1500 passed, 1 failed), then rolled back. --- CHANGELOG.md | 19 ++ README.md | 12 +- SECURITY.md | 2 +- docs/apex-twin.1 | 7 +- src/apex.h | 2 +- src/tools_blue.c | 417 ++++++++++++++++++++++++++++++++++++++++++++ src/tools_red.c | 98 +++++++++++ tests/gate_audit.py | 2 +- tests/run.py | 153 +++++++++++++++- 9 files changed, 700 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d59cb24..7f2afef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 1.94.0 - 2026-11-24 - this change + +- **opendkim** (`opendkim_audit`): `opendkim.conf` and `/etc/opendkim` under + the root prefix: a `Socket inet:` line (any host that reaches the port can + submit mail), `RequireSafeKeys no`, a `Mode` without `s` (mail is verified + but never signed) and a `Syslog ... debug` line that puts message content + and key paths into syslog. An empty tree reports `no-config`. +- **rspamd** (`rspamd_audit`): UCL config and `local.d` fragments: a + `bind_socket` on `*`, `0.0.0.0` or `::` with a port (the admin API answers + on every interface), a clear-text `password`/`enable_password` and a + `secure_ip` of `0.0.0.0/0` or `::/0` (the password check is skipped for + every client). Fragments are matched by `.conf`, `.inc` and `.local`. +- **Confluence** (`confluence_probe`): `/status` and + `/rest/api/space?limit=5` on 8090 without a token. A 2xx with content on the + space list means the anonymous user may read every space; the JSON list is + saved as evidence. `/status` answering alone is not counted as open. +- Checks: 1501 (was 1493). The red proof removes the `Mode` sign check and + the opendkim check turns red. + ## 1.93.0 - 2026-11-24 - this change - **seccomp** (`seccomp_audit`): unit files and `/etc/seccomp` profiles under diff --git a/README.md b/README.md index 62ee8c1..4bb77e1 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. -**403 tools · 1493 end-to-end checks · 240 fuzz cases · 85.1% line coverage · ~1041 KiB** +**406 tools · 1501 end-to-end checks · 240 fuzz cases · 85.1% line coverage · ~1041 KiB** ``` $ ./apex-twin --check -{"version":"1.93.0","tools":403,...,"scope":{"loaded":true,...}} +{"version":"1.94.0","tools":406,...,"scope":{"loaded":true,...}} ``` APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope @@ -245,6 +245,7 @@ uploads and secret-file reads. It does not execute anything. | `tempo_probe` | `/api/search/tags` on 3200 without auth; tag names as evidence | | `jaeger_probe` | `/api/services` on 16686 without auth; service list as evidence | | `solr_probe` | `/solr/admin/cores` on 8983 without auth; core list as evidence | +| `confluence_probe` | `/rest/api/space` on 8090 without a token; space list 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 | | `ollama_probe` | `/api/tags` on 11434 without auth; pulled model list as evidence | @@ -561,6 +562,8 @@ does. | `inetd_audit` | inetd.conf: shell services, legacy cleartext daemons, writable file | | `ld_so_conf_audit` | ld.so.conf: user-writable library path, world-writable dir | | `rc_local_audit` | rc.local: remote pipe, /tmp reference, missing exit | +| `opendkim_audit` | opendkim.conf: inet socket, RequireSafeKeys off, Mode without `s` | +| `rspamd_audit` | rspamd UCL: wildcard bind_socket, clear-text password, secure_ip 0.0.0.0/0 | | `crypttab_audit` | crypttab: readable key file, `none` key, discard | | `useradd_audit` | useradd defaults: empty INACTIVE, bad SHELL, writable skel | | `aide_audit` | AIDE: `!` on /etc or /bin, md5-only rules, db in /tmp | @@ -1100,7 +1103,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit, pam_env_audit, hosts_audit, dnf_repo_audit, anacrontab_audit, motd_audit, syslog_ng_audit, ntpd_audit, inetd_audit, - ld_so_conf_audit, rc_local_audit, nscd_audit, + ld_so_conf_audit, rc_local_audit, opendkim_audit, + rspamd_audit, nscd_audit, crypttab_audit, useradd_audit, aide_audit, faillock_audit, networkd_audit, namespace_audit, ssh_client_audit, ufw_audit, monit_audit, @@ -1156,7 +1160,7 @@ examples/ scope.json ## Status -1.93.0. Built and run: 403 tools, 1493 checks, 240 fuzz cases and 85.1% line +1.94.0. Built and run: 406 tools, 1501 checks, 240 fuzz cases and 85.1% 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 cedacc3..2f58c8e 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.93.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.94.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 bcb5315..d1a11f8 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.93.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.94.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, vault_probe, nomad_probe, coredns_probe, openbmc_probe, schema_registry_probe, loki_probe, tempo_probe, jaeger_probe, solr_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, nomad_probe, coredns_probe, openbmc_probe, schema_registry_probe, loki_probe, tempo_probe, jaeger_probe, solr_probe, confluence_probe, nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, @@ -88,7 +88,8 @@ fstab_audit, modprobe_audit, grub_audit, limits_audit, access_conf_audit, pwquality_audit, pam_env_audit, hosts_audit, dnf_repo_audit, anacrontab_audit, motd_audit, syslog_ng_audit, ntpd_audit, inetd_audit, -ld_so_conf_audit, rc_local_audit, crypttab_audit, useradd_audit, +ld_so_conf_audit, rc_local_audit, opendkim_audit, rspamd_audit, +crypttab_audit, useradd_audit, 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, diff --git a/src/apex.h b/src/apex.h index 0062ebb..2d43936 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.93.0" +#define APEX_VERSION "1.94.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 4b05440..0488d4d 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -31242,6 +31242,405 @@ static void t_systemd_socket_audit(mcp_conn *c, const mcp_json *args, mcp_buf_free(&findings); } +struct opendkim_state { + int files; + int has_socket; + int inet_socket; + int unsafe_keys; + int has_mode; + int no_sign; + int debug_log; +}; + +struct rspamd_state { + int files; + int wildcard_bind; + int plain_password; + int open_secure_ip; +}; + +/* ------------------------------------------------------------- opendkim_audit */ + +/* opendkim.conf is "Key value" with optional whitespace and # comments. The + * Milter socket matters most: a "Socket inet:..." line accepts every host that + * can reach the port, while a unix: socket is reachable only locally. Mode + * needs the "s" flag or the daemon verifies mail but never signs it. */ +static void opendkim_scan_file(mcp_buf *findings, int *first, int *count, + const char *path, struct opendkim_state *st) +{ + static char text[65536]; + char value[512]; + struct stat sb; + + if (read_text(path, text, sizeof(text)) < 0) + return; + st->files++; + if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) { + add_finding(findings, first, "world-writable", "high", + "%s is writable by anyone", path); + (*count)++; + } + if (conf_value(text, "Socket", value, sizeof(value))) { + st->has_socket = 1; + if (strncasecmp(value, "inet:", 5) == 0 || + strncasecmp(value, "inet6:", 6) == 0) { + st->inet_socket = 1; + add_finding(findings, first, "inet-socket", "medium", + "%s binds the milter to a network socket (%s), " + "so any host that reaches the port can submit mail", + path, value); + (*count)++; + } + } + if (conf_value(text, "RequireSafeKeys", value, sizeof(value)) && + strcasecmp(value, "no") == 0) { + st->unsafe_keys = 1; + add_finding(findings, first, "unsafe-keys", "medium", + "%s sets RequireSafeKeys no: a key file readable by " + "group or world is accepted", path); + (*count)++; + } + if (conf_value(text, "Mode", value, sizeof(value))) { + st->has_mode = 1; + if (strchr(value, 's') == NULL && strchr(value, 'S') == NULL) { + st->no_sign = 1; + add_finding(findings, first, "no-sign-mode", "low", + "%s has Mode %s without \"s\": outgoing mail is " + "never signed", path, value); + (*count)++; + } + } + if (conf_value(text, "Syslog", value, sizeof(value)) && + strstr(value, "debug") != NULL) { + st->debug_log = 1; + add_finding(findings, first, "debug-log", "low", + "%s logs at debug level: message content and key " + "paths end up in syslog", path); + (*count)++; + } +} + +static void opendkim_scan_dir(mcp_buf *findings, int *first, int *count, + const char *dir, struct opendkim_state *st, + int recurse) +{ + DIR *d = opendir(dir); + struct dirent *ent; + + if (d == NULL) + return; + while ((ent = readdir(d)) != NULL) { + char path[1024]; + struct stat sb; + + if (ent->d_name[0] == '.') + continue; + snprintf(path, sizeof(path), "%.800s/%.160s", dir, ent->d_name); + if (stat(path, &sb) != 0) + continue; + if (S_ISDIR(sb.st_mode)) { + if (recurse) + opendkim_scan_dir(findings, first, count, path, st, 0); + continue; + } + if (!S_ISREG(sb.st_mode)) + continue; + opendkim_scan_file(findings, first, count, path, st); + } + closedir(d); +} + +/* ---------------------------------------------------------------- rspamd_audit */ + +/* rspamd config is UCL: "key = value;" possibly nested in braces, with line + * and block comments. Only the controller block matters, so the scan is + * line-oriented: strip the "//" comment, split at the first '=', compare the + * key and look at the value. A nested "secure_ip = \"0.0.0.0/0\"" then still + * matches, which is what we want - it is a real trust hole wherever it sits. */ +static const char *ucl_key_value(const char *line, size_t *key_len, + const char **key) +{ + const char *eq; + const char *s = line; + size_t len; + + while (*s == ' ' || *s == '\t' || *s == '{' || *s == '}') + s++; + eq = strchr(s, '='); + if (eq == NULL) { + *key_len = 0; + return NULL; + } + len = (size_t)(eq - s); + while (len > 0 && (s[len - 1] == ' ' || s[len - 1] == '\t')) + len--; + *key_len = len; + *key = s; + return eq + 1; +} + +static void ucl_value(const char *rest, char *out, size_t n) +{ + size_t i = 0; + + while (*rest == ' ' || *rest == '\t') + rest++; + if (*rest == '"' || *rest == '\'') + rest++; + while (rest[i] != '\0' && rest[i] != ';' && rest[i] != '\n' && + rest[i] != '"' && rest[i] != '\'' && i + 1 < n) { + out[i] = rest[i]; + i++; + } + out[i] = '\0'; + while (i > 0 && (out[i - 1] == ' ' || out[i - 1] == '\t')) + out[--i] = '\0'; +} + +/* local.d holds .conf, .inc and .local fragments; anything else is ignored. */ +static int rs_conf_name(const char *name, size_t len) +{ + static const char *suffixes[] = { ".conf", ".inc", ".local", NULL }; + size_t i; + + for (i = 0; suffixes[i] != NULL; i++) { + size_t sl = strlen(suffixes[i]); + + if (len > sl && strcmp(name + len - sl, suffixes[i]) == 0) + return 1; + } + return 0; +} + +/* A bind_socket value is "addr:port" or "addr port"; only the address part + * decides whether the controller listens beyond loopback. */ +static int ucl_wildcard(const char *value) +{ + return strcmp(value, "*") == 0 || + strncmp(value, "*:", 2) == 0 || + strncmp(value, "0.0.0.0:", 8) == 0 || + strncmp(value, "0.0.0.0 ", 8) == 0 || + strcmp(value, "0.0.0.0") == 0 || + strncmp(value, "[::]:", 5) == 0 || + strncmp(value, ":::", 3) == 0 || + strcmp(value, "::") == 0 || strcmp(value, "[::]") == 0; +} + +static void rspamd_scan_file(mcp_buf *findings, int *first, int *count, + const char *path, struct rspamd_state *st) +{ + 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) { + add_finding(findings, first, "world-writable", "high", + "%s is writable by anyone", 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[1024]; + char *cut; + const char *rest; + const char *kptr; + size_t klen; + char key[128]; + char value[512]; + + if (len >= sizeof(line)) + len = sizeof(line) - 1; + memcpy(line, p, len); + line[len] = '\0'; + p = eol != NULL ? eol + 1 : NULL; + cut = strstr(line, "//"); + if (cut != NULL) + *cut = '\0'; + rest = ucl_key_value(line, &klen, &kptr); + if (rest == NULL || klen == 0 || klen >= sizeof(key)) + continue; + memcpy(key, kptr, klen); + key[klen] = '\0'; + ucl_value(rest, value, sizeof(value)); + if (strcmp(key, "bind_socket") == 0 && ucl_wildcard(value)) { + st->wildcard_bind = 1; + add_finding(findings, first, "wildcard-bind", "high", + "%s binds the controller to %s: the admin API " + "answers on every interface", path, value); + (*count)++; + } + if ((strcmp(key, "password") == 0 || + strcmp(key, "enable_password") == 0) && value[0] != '\0') { + st->plain_password = 1; + add_finding(findings, first, "plain-password", "medium", + "%s stores the controller password in clear text", + path); + (*count)++; + } + if (strcmp(key, "secure_ip") == 0 && + (strcmp(value, "0.0.0.0/0") == 0 || strcmp(value, "::/0") == 0)) { + st->open_secure_ip = 1; + add_finding(findings, first, "open-secure-ip", "high", + "%s trusts %s: the password check is skipped for " + "every client", path, value); + (*count)++; + } + } +} + +static void t_opendkim_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char base[512]; + char path[1024]; + size_t bl; + mcp_buf b; + mcp_buf findings; + struct opendkim_state st; + int count = 0; + int first = 1; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) >= sizeof(base) - 2) { + mcp_reply_error(c, "root path too long"); + return; + } + snprintf(base, sizeof(base), "%s", root); + bl = strlen(base); + while (bl > 0 && base[bl - 1] == '/') + base[--bl] = '\0'; + memset(&st, 0, sizeof(st)); + mcp_buf_init(&findings); + + snprintf(path, sizeof(path), "%s/etc/opendkim.conf", base); + opendkim_scan_file(&findings, &first, &count, path, &st); + snprintf(path, sizeof(path), "%s/etc/opendkim", base); + opendkim_scan_dir(&findings, &first, &count, path, &st, 1); + + if (st.files == 0) { + add_finding(&findings, &first, "no-config", "info", + "no opendkim configuration found"); + count = 1; + } else { + if (!st.has_socket) { + add_finding(&findings, &first, "no-socket", "info", + "no Socket line: the milter default socket " + "is used"); + count++; + } + if (!st.has_mode) { + add_finding(&findings, &first, "no-mode", "info", + "no Mode line: the daemon default mode is used"); + count++; + } + } + if (count == 0) { + add_finding(&findings, &first, "no-findings", "info", + "the DKIM configuration carries no weak setting"); + count = 1; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, base); + mcp_buf_printf(&b, ",\"files\":%d,\"inet_socket\":%s," + "\"unsafe_keys\":%s,\"no_sign_mode\":%s," + "\"debug_log\":%s,\"findings_count\":%d,\"findings\":[", + st.files, st.inet_socket ? "true" : "false", + st.unsafe_keys ? "true" : "false", + st.no_sign ? "true" : "false", + st.debug_log ? "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); +} + +static void t_rspamd_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + const char *root = mcp_arg_string(args, "root"); + char base[512]; + char path[1024]; + size_t bl; + mcp_buf b; + mcp_buf findings; + struct rspamd_state st; + int count = 0; + int first = 1; + DIR *d; + struct dirent *ent; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) >= sizeof(base) - 2) { + mcp_reply_error(c, "root path too long"); + return; + } + snprintf(base, sizeof(base), "%s", root); + bl = strlen(base); + while (bl > 0 && base[bl - 1] == '/') + base[--bl] = '\0'; + memset(&st, 0, sizeof(st)); + mcp_buf_init(&findings); + + snprintf(path, sizeof(path), "%s/etc/rspamd/rspamd.conf", base); + rspamd_scan_file(&findings, &first, &count, path, &st); + snprintf(path, sizeof(path), "%s/etc/rspamd/local.d", base); + d = opendir(path); + if (d != NULL) { + while ((ent = readdir(d)) != NULL) { + char file[1200]; + size_t nl = strlen(ent->d_name); + size_t pl = strlen(path); + + if (ent->d_name[0] == '.' || nl < 6) + continue; + if (!rs_conf_name(ent->d_name, nl)) + continue; + if (pl + nl + 2 > sizeof(file)) + continue; + memcpy(file, path, pl); + file[pl] = '/'; + memcpy(file + pl + 1, ent->d_name, nl + 1); + rspamd_scan_file(&findings, &first, &count, file, &st); + } + closedir(d); + } + if (count == 0) { + if (st.files == 0) + add_finding(&findings, &first, "no-config", "info", + "no rspamd configuration found"); + else + add_finding(&findings, &first, "no-findings", "info", + "the rspamd configuration carries no weak setting"); + count = 1; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, base); + mcp_buf_printf(&b, ",\"files\":%d,\"wildcard_bind\":%s," + "\"plain_password\":%s,\"open_secure_ip\":%s," + "\"findings_count\":%d,\"findings\":[", + st.files, st.wildcard_bind ? "true" : "false", + st.plain_password ? "true" : "false", + st.open_secure_ip ? "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, " @@ -32602,6 +33001,24 @@ const mcp_tool TOOLS_BLUE[] = { "{\"type\":\"object\",\"properties\":{" "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", t_ntpd_audit }, + { "opendkim_audit", + "Parse /etc/opendkim.conf and /etc/opendkim (root prefix): a milter " + "Socket on inet:/inet6: (any host that reaches the port can submit " + "mail), RequireSafeKeys no (a group- or world-readable key is " + "accepted), a Mode without \"s\" (outgoing mail is never signed), a " + "debug Syslog level and a world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_opendkim_audit }, + { "rspamd_audit", + "Parse /etc/rspamd/rspamd.conf and local.d/*.conf (root prefix): a " + "bind_socket on 0.0.0.0, * or ::, a controller password or " + "enable_password in clear text, a secure_ip of 0.0.0.0/0 or ::/0 " + "(the password check is skipped for every client) and a " + "world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_rspamd_audit }, { "inetd_audit", "Parse /etc/inetd.conf (root prefix): an enabled internal service " "(shell, login, exec, rsh, rexec) hands out a root shell over the " diff --git a/src/tools_red.c b/src/tools_red.c index c5984b9..244e45b 100644 --- a/src/tools_red.c +++ b/src/tools_red.c @@ -10459,6 +10459,92 @@ static void t_solr_probe(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&b); } +/* ---------------------------------------------------------- confluence_probe */ + +/* Confluence 7+ on 8090: /rest/api/space needs no token when the anonymous + * user has "Use Confluence" permission, and it returns every space with its + * key, name and homepage. The status endpoint answers even when the API is + * closed, so only a 2xx with content on the space list counts as open. */ +static void t_confluence_probe(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *paths[] = { "/status", + "/rest/api/space?limit=5", NULL }; + const char *target = mcp_arg_string(args, "target"); + int port = mcp_arg_int(args, "port", 8090); + 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 spaces_open = 0; + char *evidence = NULL; + char label[64]; + 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, "confluence_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 = 0; + int space = strcmp(paths[i], "/status") != 0; + + status[0] = '\0'; + if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL, + 8000, &resp, &len, status, sizeof(status)) == 0) { + tested++; + code = apex_status_code(status); + if (code >= 200 && code < 300 && resp != NULL && len > 0) { + open_count++; + if (space) + spaces_open = 1; + if (evidence == NULL && space) { + label[0] = '\0'; + snprintf(label, sizeof(label), "confluence-%d", i); + evidence = apex_evidence_save(label, 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}", code); + free(resp); + } + mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d," + "\"spaces_open\":%s,\"evidence\":", + tested, open_count, spaces_open ? "true" : "false"); + if (evidence != NULL) + apex_json_str(&b, evidence); + else + mcp_buf_puts(&b, "null"); + mcp_buf_puts(&b, "}"); + apex_audit("confluence_probe", target, port, !spaces_open, + spaces_open + ? "the Confluence space API answers without credentials" + : "the Confluence space API requires credentials", "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: " @@ -11399,6 +11485,18 @@ const mcp_tool TOOLS_RED[] = { "\"port\":{\"type\":\"integer\",\"description\":\"default 8080\"}}," "\"required\":[\"target\"]}", t_jira_probe }, + { "confluence_probe", + "Get /status and /rest/api/space?limit=5 without credentials on 8090. " + "A 2xx with content on the space list means anonymous users can read " + "every space name, key and homepage; the body is saved as evidence " + "and the open query API is recorded in the audit log. 401 and 403 " + "count as closed.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 8090\"}," + "\"tls\":{\"type\":\"boolean\"}}," + "\"required\":[\"target\"]}", + t_confluence_probe }, { "ollama_probe", "Query Ollama (default 11434) without credentials: /api/version, " "/api/tags and /api/ps. A 2xx on /api/tags lists every pulled model and " diff --git a/tests/gate_audit.py b/tests/gate_audit.py index 65b9bff..4d1eb28 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 = 403 +EXPECTED_TOOLS = 406 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 74be0d8..ddc24ab 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("403 tools registered", len(tools) == 403, len(tools)) +check("406 tools registered", len(tools) == 406, 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"]) == 403) + check("http tools/list", len(listing["result"]["tools"]) == 406) 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 @@ -18329,6 +18329,155 @@ for d in (sc_root, sc_good_root, sc_empty_root, ss_root, ss_good_root, ss_empty_root, cfg64_home): shutil.rmtree(d, ignore_errors=True) +# --- 1.94.0: opendkim and rspamd audits plus the Confluence probe --- +print("\n== opendkim, rspamd and Confluence ==") +dk_root = tempfile.mkdtemp(prefix="apex-dk-") +os.makedirs(os.path.join(dk_root, "etc", "opendkim")) +dk_bad = os.path.join(dk_root, "etc", "opendkim.conf") +with open(dk_bad, "w") as f: + f.write("Mode v\n") + f.write("Socket inet:8891@0.0.0.0\n") + f.write("RequireSafeKeys no\n") + f.write("Syslog yes debug\n") +os.chmod(dk_bad, 0o666) + +dk_good_root = tempfile.mkdtemp(prefix="apex-dkg-") +os.makedirs(os.path.join(dk_good_root, "etc", "opendkim")) +with open(os.path.join(dk_good_root, "etc", "opendkim.conf"), "w") as f: + f.write("Mode sv\n") + f.write("Socket local:/run/opendkim/opendkim.sock\n") + f.write("RequireSafeKeys yes\n") + f.write("Syslog yes\n") + +rm_root = tempfile.mkdtemp(prefix="apex-rm-") +os.makedirs(os.path.join(rm_root, "etc", "rspamd", "local.d")) +with open(os.path.join(rm_root, "etc", "rspamd", "rspamd.conf"), "w") as f: + f.write("worker \"controller\" {\n") + f.write(" bind_socket = \"*:11334\";\n") + f.write("}\n") +with open(os.path.join(rm_root, "etc", "rspamd", "local.d", + "worker-controller.inc"), "w") as f: + f.write("password = \"hunter2\";\n") + f.write("secure_ip = \"0.0.0.0/0\";\n") + +rm_good_root = tempfile.mkdtemp(prefix="apex-rmg-") +os.makedirs(os.path.join(rm_good_root, "etc", "rspamd", "local.d")) +with open(os.path.join(rm_good_root, "etc", "rspamd", "local.d", + "worker-controller.inc"), "w") as f: + f.write("bind_socket = \"127.0.0.1:11334\";\n") + f.write("secure_ip = \"127.0.0.1\";\n") + + +class _ConfluenceHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + path = urllib.parse.urlsplit(self.path).path + if path == "/status": + body = b'{"state":"RUNNING"}' + self.send_response(200) + elif path == "/rest/api/space": + body = (b'{"results":[{"key":"OPS","name":"Operations"},' + b'{"key":"DEV","name":"Development"}],"size":2}') + self.send_response(200) + else: + body = b'{"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 _ConfluenceAuthHandler(_ConfluenceHandler): + def do_GET(self): + body = b'{"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) + + +cf_srv = http.server.HTTPServer(("127.0.0.1", 0), _ConfluenceHandler) +cf_port = cf_srv.server_address[1] +cf_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _ConfluenceAuthHandler) +cf_auth_port = cf_auth_srv.server_address[1] +for _s in (cf_srv, cf_auth_srv): + threading.Thread(target=_s.serve_forever, daemon=True).start() + +cfg65_home = tempfile.mkdtemp(prefix="apex-cfg65-home-") +write_scope(cfg65_home, + {"label": "cfg65", "expires": "2099-01-01T00:00:00Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_port": [str(cf_port), str(cf_auth_port)]}) + +dk_empty_root = tempfile.mkdtemp(prefix="apex-dke-") +rm_empty_root = tempfile.mkdtemp(prefix="apex-rme-") +res, _ = run([ + call(1, "opendkim_audit", root=dk_root), + call(2, "opendkim_audit", root=dk_good_root), + call(3, "opendkim_audit", root=dk_empty_root), + call(4, "rspamd_audit", root=rm_root), + call(5, "rspamd_audit", root=rm_good_root), + call(6, "rspamd_audit", root=rm_empty_root), + call(7, "confluence_probe", target="127.0.0.1", port=cf_port, tls=False), + call(8, "confluence_probe", target="127.0.0.1", port=cf_auth_port, + tls=False), +], home=cfg65_home) +by_id = {r["id"]: r for r in res if "id" in r} + +dk = json.loads(text(by_id[1])) +dk_ids = {f["id"] for f in dk["findings"]} +check("opendkim_audit flags an inet socket, unsafe keys, unsigned mode and " + "debug logging", + {"world-writable", "inet-socket", "unsafe-keys", "no-sign-mode", + "debug-log"} <= dk_ids and dk["files"] == 1 and + dk["inet_socket"] is True and dk["unsafe_keys"] is True and + dk["no_sign_mode"] is True and dk["debug_log"] is True, dk) +dk_good = json.loads(text(by_id[2])) +check("opendkim_audit accepts a unix socket with safe keys and signing", + {f["id"] for f in dk_good["findings"]} == {"no-findings"} and + dk_good["inet_socket"] is False and dk_good["no_sign_mode"] is False, + dk_good) +dk_empty = json.loads(text(by_id[3])) +check("opendkim_audit reports an empty tree as no-config", + dk_empty["files"] == 0 and + [f["id"] for f in dk_empty["findings"]] == ["no-config"], dk_empty) + +rm = json.loads(text(by_id[4])) +rm_ids = {f["id"] for f in rm["findings"]} +check("rspamd_audit flags a wildcard binding, a clear-text password and an " + "open secure_ip", + {"wildcard-bind", "plain-password", "open-secure-ip"} <= rm_ids and + rm["files"] == 2 and rm["wildcard_bind"] is True and + rm["plain_password"] is True and rm["open_secure_ip"] is True, rm) +rm_good = json.loads(text(by_id[5])) +check("rspamd_audit accepts a loopback binding without a password", + {f["id"] for f in rm_good["findings"]} == {"no-findings"} and + rm_good["wildcard_bind"] is False and + rm_good["plain_password"] is False, rm_good) +rm_empty = json.loads(text(by_id[6])) +check("rspamd_audit reports an empty tree as no-config", + rm_empty["files"] == 0 and + [f["id"] for f in rm_empty["findings"]] == ["no-config"], rm_empty) + +cf = json.loads(text(by_id[7])) +check("confluence_probe finds an open space API and saves evidence", + cf["spaces_open"] is True and cf["open_count"] == 2 and + cf["evidence"] is not None and os.path.isfile(cf["evidence"]), cf) +cf_auth = json.loads(text(by_id[8])) +check("confluence_probe reports a closed space API as not open", + cf_auth["spaces_open"] is False and cf_auth["evidence"] is None and + all(e["status"] == 401 for e in cf_auth["endpoints"]), cf_auth) + +for _s in (cf_srv, cf_auth_srv): + _s.shutdown() +for d in (dk_root, dk_good_root, dk_empty_root, rm_root, rm_good_root, + rm_empty_root, cfg65_home): + shutil.rmtree(d, ignore_errors=True) + # --- 1.84.0: gated wrappers for external scanners (mock binaries) --- print("\n== external scanner wrappers ==\n")