From 997280b3d2b4bd560dc8a0ba75f55821bd736cf2 Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 23 Nov 2026 15:57:02 +0000 Subject: [PATCH] apex-twin 1.92.0: fluent-bit and Vector audits, Jaeger probe Three new tools in the observability family: - fluentbit_audit (blue): fluent-bit.conf plus conf.d fragments. Flags an [OUTPUT] with a non-loopback Host and no "tls On", a [SERVICE] with HTTP_Server On and HTTP_Listen 0.0.0.0, a debug/trace log level and a world-writable file. - vector_audit (blue): vector.toml, block by block. Flags a source bound to 0.0.0.0/::, a sink with an endpoint and no tls block (or tls.verify=false), the GraphQL api enabled beyond loopback, a missing sink and a world-writable file. - jaeger_probe (red): /api/services on 16686 without credentials; a 2xx with a data array is the finding, the body is saved as evidence and the audit log records it. A 401 counts as closed. Tests: make test 1485/1485, test-asan 1485/1485, analyze 0, 240 fuzz cases, coverage 85.0%, release-check (incl. distcheck from the tarball) exit 0. Red proof: breaking the "tls On" match turned the fluentbit check red and was rolled back. --- CHANGELOG.md | 17 ++ README.md | 15 +- SECURITY.md | 2 +- docs/apex-twin.1 | 7 +- src/apex.h | 2 +- src/tools_blue.c | 468 ++++++++++++++++++++++++++++++++++++++++++++ src/tools_red.c | 100 ++++++++++ tests/gate_audit.py | 2 +- tests/run.py | 178 ++++++++++++++++- 9 files changed, 778 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 681794d..24c08ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## 1.92.0 - 2026-11-24 - this change + +- **fluent-bit** (`fluentbit_audit`): `fluent-bit.conf` and the fragments + under `conf.d`: an `[OUTPUT]` section that talks to a non-loopback host + without `tls On` (logs and tokens leave in clear text), a `[SERVICE]` with + `HTTP_Server On` and `HTTP_Listen 0.0.0.0` (the metrics and health endpoint + on every interface), a log level of `debug`/`trace` (where request detail + ends up) and a world-writable configuration file. Read-only. +- **Vector** (`vector_audit`): `vector.toml`: a `[sources.*]` block with + `address` on `0.0.0.0`/`::`, a `[sinks.*]` with an endpoint and no `tls` + block or `tls.verify = false`, the GraphQL `[api]` enabled and bound beyond + loopback (it can read every component), a missing sink and a world-writable + file. Read-only. +- **Jaeger** (`jaeger_probe`): `/api/services` on 16686 without credentials + lists every service the collector has seen; the body is saved as evidence + and the audit log records the open query API. A 401 counts as closed. + ## 1.91.0 - 2026-11-24 - this change - **promtail** (`promtail_audit`): a positions block whose `filename` points diff --git a/README.md b/README.md index 5123699..349db35 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. -**397 tools · 1477 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB** +**400 tools · 1485 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB** ``` $ ./apex-twin --check -{"version":"1.91.0","tools":397,...,"scope":{"loaded":true,...}} +{"version":"1.92.0","tools":400,...,"scope":{"loaded":true,...}} ``` APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope @@ -243,6 +243,7 @@ uploads and secret-file reads. It does not execute anything. | `airflow_probe` | `/api/v1/dags` without auth; DAG inventory as evidence | | `loki_probe` | `/loki/api/v1/labels` on 3100 without auth; label names as evidence | | `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 | | `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 | @@ -593,6 +594,8 @@ does. | `falco_audit` | no rules_file, debug threshold, http webhook, writable rules | | `promtail_audit` | positions in /tmp or missing, no tenant_id, http client URL, writable config | | `otel_collector_audit` | exporters without tls, debug exporter, zpages/pprof, writable config | +| `fluentbit_audit` | remote output without `tls On`, HTTP on any interface, debug level, writable config | +| `vector_audit` | source on `0.0.0.0`, sink without tls, GraphQL API beyond loopback, writable config | | `tripwire_audit` | twcfg.txt: no site key, loose site key, no MAILTO | | `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 | @@ -1080,7 +1083,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery, superset_probe, argocd_probe, kafka_connect_probe, zabbix_probe, datasette_probe, vault_probe, nomad_probe, coredns_probe, openbmc_probe, - schema_registry_probe, loki_probe, tempo_probe + schema_registry_probe, loki_probe, tempo_probe, + jaeger_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, @@ -1108,7 +1112,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit, freshclam_audit, tripwire_audit, fapolicyd_audit, systemd_timer_audit, yara_audit, suricata_audit, icinga2_audit, falco_audit, - promtail_audit, otel_collector_audit) + promtail_audit, otel_collector_audit, + fluentbit_audit, vector_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 @@ -1147,7 +1152,7 @@ examples/ scope.json ## Status -1.91.0. Built and run: 397 tools, 1477 checks, 240 fuzz cases and 85.0% line +1.92.0. Built and run: 400 tools, 1485 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 eb1a7f2..4e50489 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.91.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current +is **1.92.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 cb394ba..acbfbd9 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.91.0" "User Commands" +.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.92.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, +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, nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan), defensive audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules, @@ -97,7 +97,8 @@ apt_auth_audit, aliases_audit, netgroup_audit, jetty_audit, dhclient_audit, journal_upload_audit, fwupd_audit, smartd_audit, tlog_audit, abrt_audit, freshclam_audit, tripwire_audit, fapolicyd_audit, systemd_timer_audit, yara_audit, suricata_audit, -promtail_audit, otel_collector_audit, icinga2_audit, falco_audit, +promtail_audit, otel_collector_audit, fluentbit_audit, vector_audit, +icinga2_audit, falco_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 8a1891d..3984a12 100644 --- a/src/apex.h +++ b/src/apex.h @@ -15,7 +15,7 @@ #include "mcp.h" -#define APEX_VERSION "1.91.0" +#define APEX_VERSION "1.92.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 9144b19..09619e4 100644 --- a/src/tools_blue.c +++ b/src/tools_blue.c @@ -30279,6 +30279,459 @@ static void t_otel_collector_audit(mcp_conn *c, const mcp_json *args, mcp_buf_free(&findings); } +/* ------------------------------------------------------------ fluentbit_audit */ + +/* fluent-bit.conf is INI with repeating [INPUT]/[FILTER]/[OUTPUT] sections and + * fragments under conf.d with the same grammar. Keys are case-insensitive and + * written as "Key value" (no '='), so the reader below splits on the first run + * of blanks instead of looking for '='. Only sections matter for the checks: + * an OUTPUT that talks to a non-loopback host without "tls On", a SERVICE + * block that opens the HTTP metrics endpoint on every interface, and a log + * level of debug/trace (which is where tokens and headers end up in the log). */ +struct fb_section { + char name[64]; + int has_host; + int non_local_host; + int tls_on; + int http_server_on; + int http_listen_any; + int log_debug; +}; + +static int fb_is_local_host(const char *host) +{ + if (host[0] == '\0') + return 1; + if (strcmp(host, "127.0.0.1") == 0 || strcasecmp(host, "localhost") == 0 || + strcmp(host, "::1") == 0 || strncmp(host, "127.", 4) == 0) + return 1; + return 0; +} + +static void fb_scan_text(const char *text, struct fb_section *cur, + int *have_cur, mcp_buf *findings, int *first, + int *count, int *outputs, int *outputs_no_tls, + int *http_any, int *debug_level) +{ + const char *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 *s; + + if (len >= sizeof(line)) + len = sizeof(line) - 1; + memcpy(line, p, len); + line[len] = '\0'; + s = line; + while (*s == ' ' || *s == '\t') + s++; + if (*s == '[') { + char *close = strchr(s, ']'); + + if (*have_cur && cur->non_local_host && !cur->tls_on && + strncasecmp(cur->name, "OUTPUT", 6) == 0) { + (*outputs_no_tls)++; + add_finding(findings, first, "output-no-tls", "medium", + "an [OUTPUT] section sends telemetry to a " + "remote host without \"tls On\""); + (*count)++; + } + if (*have_cur && strncasecmp(cur->name, "OUTPUT", 6) == 0) + (*outputs)++; + if (*have_cur && cur->http_server_on && cur->http_listen_any) + *http_any = 1; + if (*have_cur && cur->log_debug) + *debug_level = 1; + memset(cur, 0, sizeof(*cur)); + if (close != NULL) { + size_t n = (size_t)(close - s - 1); + + if (n >= sizeof(cur->name)) + n = sizeof(cur->name) - 1; + memcpy(cur->name, s + 1, n); + cur->name[n] = '\0'; + /* Trim a trailing section comment such as "[OUTPUT] x". */ + n = strlen(cur->name); + while (n > 0 && (cur->name[n - 1] == ' ' || + cur->name[n - 1] == '\t')) + cur->name[--n] = '\0'; + *have_cur = 1; + } + } else if (*s != '#' && *s != ';' && *s != '\0') { + char key[64]; + char *v = s; + size_t kl = 0; + + while (*v != '\0' && *v != ' ' && *v != '\t' && + kl + 1 < sizeof(key)) + key[kl++] = *v++; + key[kl] = '\0'; + while (*v == ' ' || *v == '\t') + v++; + trim_eol(v); + if (strcasecmp(key, "Host") == 0) { + cur->has_host = 1; + if (!fb_is_local_host(v)) + cur->non_local_host = 1; + } else if (strcasecmp(key, "TLS") == 0) { + if (strcasecmp(v, "on") == 0 || + strcasecmp(v, "true") == 0) + cur->tls_on = 1; + } else if (strcasecmp(key, "HTTP_Server") == 0) { + if (strcasecmp(v, "on") == 0 || + strcasecmp(v, "true") == 0) + cur->http_server_on = 1; + } else if (strcasecmp(key, "HTTP_Listen") == 0) { + if (strcmp(v, "0.0.0.0") == 0 || v[0] == '\0' || + strcmp(v, "::") == 0) + cur->http_listen_any = 1; + } else if (strcasecmp(key, "Log_Level") == 0) { + if (strcasecmp(v, "debug") == 0 || + strcasecmp(v, "trace") == 0) + cur->log_debug = 1; + } + } + if (eol == NULL) + break; + p = eol + 1; + } +} + +static void t_fluentbit_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static char text[131072]; + const char *root = mcp_arg_string(args, "root"); + char path[1200]; + char dir[1024]; + struct stat st; + struct fb_section cur; + int have_cur = 0; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int files = 0; + int outputs = 0; + int outputs_no_tls = 0; + int http_any = 0; + int debug_level = 0; + DIR *d; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + memset(&cur, 0, sizeof(cur)); + mcp_buf_init(&findings); + snprintf(path, sizeof(path), "%.400s/etc/fluent-bit/fluent-bit.conf", root); + if (read_text(path, text, sizeof(text)) > 0) { + files++; + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "%s is writable by anyone", path); + count++; + } + fb_scan_text(text, &cur, &have_cur, &findings, &first, &count, + &outputs, &outputs_no_tls, &http_any, &debug_level); + } + snprintf(dir, sizeof(dir), "%.400s/etc/fluent-bit/conf.d", root); + d = opendir(dir); + if (d != NULL) { + struct dirent *ent; + + while ((ent = readdir(d)) != NULL) { + size_t nl; + + if (ent->d_name[0] == '.') + continue; + nl = strlen(ent->d_name); + if (nl < 5 || strcmp(ent->d_name + nl - 5, ".conf") != 0) + continue; + snprintf(path, sizeof(path), "%.400s/%.400s", dir, + ent->d_name); + if (read_text(path, text, sizeof(text)) <= 0) + continue; + files++; + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "%s is writable by anyone", path); + count++; + } + fb_scan_text(text, &cur, &have_cur, &findings, &first, + &count, &outputs, &outputs_no_tls, &http_any, + &debug_level); + } + closedir(d); + } + if (have_cur && cur.non_local_host && !cur.tls_on && + strncasecmp(cur.name, "OUTPUT", 6) == 0) { + outputs_no_tls++; + add_finding(&findings, &first, "output-no-tls", "medium", + "an [OUTPUT] section sends telemetry to a remote host " + "without \"tls On\""); + count++; + } + if (have_cur && strncasecmp(cur.name, "OUTPUT", 6) == 0) + outputs++; + if (have_cur && cur.http_server_on && cur.http_listen_any) + http_any = 1; + if (have_cur && cur.log_debug) + debug_level = 1; + if (files == 0) { + mcp_buf_free(&findings); + mcp_reply_error(c, "cannot read a fluent-bit configuration"); + return; + } + if (http_any) { + add_finding(&findings, &first, "http-any-interface", "medium", + "[SERVICE] HTTP_Server is on and HTTP_Listen binds " + "every interface"); + count++; + } + if (debug_level) { + add_finding(&findings, &first, "debug-log-level", "low", + "Log_Level debug/trace writes request detail to the log"); + count++; + } + if (outputs == 0) { + add_finding(&findings, &first, "no-output", "low", + "no [OUTPUT] section: fluent-bit collects and drops"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"files\":%d,\"outputs\":%d," + "\"outputs_without_tls\":%d,\"http_any_interface\":%s," + "\"debug_level\":%s,\"findings_count\":%d,\"findings\":[", + files, outputs, outputs_no_tls, + http_any ? "true" : "false", + debug_level ? "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); +} + +/* --------------------------------------------------------------- vector_audit */ + +/* Vector's vector.toml is flat TOML with dotted keys: [sources.x], [sinks.y], + * [api]. A section header names the component type in its first segment, so the + * reader keeps a per-block view instead of one flat key/value map. Three checks + * matter in practice: a source that binds 0.0.0.0/:: (every collector port open + * to the network, usually without auth), a sink with an https/http URL but no + * tls block or an explicit tls.verify off, and api.enabled true with an + * address that is not loopback (the GraphQL API can read every component). */ +struct vector_block { + char header[128]; + int is_source; + int is_sink; + int is_api; + int address_any; + int has_endpoint; + int has_tls; + int tls_verify_off; + int enabled; +}; + +static int vec_addr_is_any(const char *v) +{ + if (strncmp(v, "0.0.0.0", 7) == 0 || strncmp(v, "[::]", 4) == 0 || + strncmp(v, "::", 2) == 0) + return 1; + return 0; +} + +static void vec_block_flush(struct vector_block *blk, mcp_buf *findings, + int *first, int *count, int *exposed_sources, + int *sinks_no_tls, int *api_open) +{ + if (blk->header[0] == '\0') + return; + if (blk->is_source && blk->address_any) { + (*exposed_sources)++; + add_finding(findings, first, "source-any-address", "medium", + "[%.80s] listens on every interface", blk->header); + (*count)++; + } + if (blk->is_sink && blk->has_endpoint && !blk->has_tls) { + (*sinks_no_tls)++; + add_finding(findings, first, "sink-no-tls", "medium", + "[%.80s] has no tls block: the sink ships in clear text " + "or does not verify", blk->header); + (*count)++; + } else if (blk->is_sink && blk->has_endpoint && blk->tls_verify_off) { + (*sinks_no_tls)++; + add_finding(findings, first, "sink-tls-no-verify", "medium", + "[%.80s] sets tls.verify off: the certificate is not " + "checked", blk->header); + (*count)++; + } + if (blk->is_api && blk->enabled && blk->address_any) { + *api_open = 1; + add_finding(findings, first, "api-any-address", "high", + "the GraphQL API is enabled and bound beyond loopback"); + (*count)++; + } +} + +static void t_vector_audit(mcp_conn *c, const mcp_json *args, void *user) +{ + static char text[131072]; + const char *root = mcp_arg_string(args, "root"); + char path[1024]; + struct stat st; + struct vector_block blk; + mcp_buf b; + mcp_buf findings; + int first = 1; + int count = 0; + int sources = 0; + int sinks = 0; + int exposed_sources = 0; + int sinks_no_tls = 0; + int api_open = 0; + const char *p; + + (void)user; + if (root == NULL) + root = ""; + if (strlen(root) > 400) { + mcp_reply_error(c, "root path too long"); + return; + } + snprintf(path, sizeof(path), "%.400s/etc/vector/vector.toml", root); + if (read_text(path, text, sizeof(text)) <= 0) { + mcp_reply_error(c, "cannot read vector.toml"); + return; + } + mcp_buf_init(&findings); + if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) { + add_finding(&findings, &first, "world-writable", "high", + "vector.toml is writable by anyone"); + count++; + } + /* The top-level [api] block is not a component; recognise it by name. */ + memset(&blk, 0, sizeof(blk)); + blk.is_api = 1; + 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; + + if (len >= sizeof(line)) + len = sizeof(line) - 1; + memcpy(line, p, len); + line[len] = '\0'; + s = line; + while (*s == ' ' || *s == '\t') + s++; + if (*s == '[') { + char *close = strchr(s, ']'); + char *name; + size_t n; + + vec_block_flush(&blk, &findings, &first, &count, + &exposed_sources, &sinks_no_tls, &api_open); + memset(&blk, 0, sizeof(blk)); + if (close != NULL) { + name = s + 1; + n = (size_t)(close - name); + if (n >= sizeof(blk.header)) + n = sizeof(blk.header) - 1; + memcpy(blk.header, name, n); + blk.header[n] = '\0'; + if (strncmp(blk.header, "sources.", 8) == 0) { + blk.is_source = 1; + sources++; + } else if (strncmp(blk.header, "sinks.", 6) == 0) { + blk.is_sink = 1; + sinks++; + } else if (strncmp(blk.header, "api", 3) == 0) { + blk.is_api = 1; + } + } + } else if (*s != '#' && *s != '\0') { + char *eq = strchr(s, '='); + + if (eq != NULL) { + char *v = eq + 1; + size_t kl; + size_t vl; + + *eq = '\0'; + kl = strlen(s); + while (kl > 0 && (s[kl - 1] == ' ' || + s[kl - 1] == '\t')) + s[--kl] = '\0'; + while (*v == ' ' || *v == '\t') + v++; + vl = strlen(v); + while (vl > 0 && (v[vl - 1] == ' ' || + v[vl - 1] == '\t' || + v[vl - 1] == '\r')) + v[--vl] = '\0'; + if (vl >= 2 && v[0] == '"' && v[vl - 1] == '"') { + v++; + vl -= 2; + v[vl] = '\0'; + } + if (strcmp(s, "endpoint") == 0 || + strcmp(s, "uri") == 0 || + strcmp(s, "url") == 0) + blk.has_endpoint = 1; + if (strcmp(s, "address") == 0 || + strcmp(s, "addresses") == 0) { + if (vec_addr_is_any(v)) + blk.address_any = 1; + } else if (strncmp(s, "tls", 3) == 0) { + blk.has_tls = 1; + if (strstr(s, "verify") != NULL && + strcasecmp(v, "false") == 0) + blk.tls_verify_off = 1; + } else if (strcmp(s, "enabled") == 0) { + if (strcasecmp(v, "true") == 0) + blk.enabled = 1; + } + } + } + if (eol == NULL) + break; + p = eol + 1; + } + vec_block_flush(&blk, &findings, &first, &count, &exposed_sources, + &sinks_no_tls, &api_open); + if (sinks == 0) { + add_finding(&findings, &first, "no-sink", "low", + "no [sinks.*] block: Vector reads and drops"); + count++; + } + mcp_buf_init(&b); + mcp_buf_puts(&b, "{\"root\":"); + apex_json_str(&b, root); + mcp_buf_printf(&b, ",\"sources\":%d,\"sinks\":%d," + "\"exposed_sources\":%d,\"sinks_without_tls\":%d," + "\"api_open\":%s,\"findings_count\":%d,\"findings\":[", + sources, sinks, exposed_sources, sinks_no_tls, + api_open ? "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, " @@ -31951,6 +32404,21 @@ const mcp_tool TOOLS_BLUE[] = { "{\"type\":\"object\",\"properties\":{" "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", t_otel_collector_audit }, + { "fluentbit_audit", + "Parse fluent-bit.conf and conf.d/*.conf (root prefix): an [OUTPUT] " + "with a non-loopback host and no \"tls On\", [SERVICE] HTTP_Server " + "on every interface, a debug log level and a world-writable file. " + "Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_fluentbit_audit }, + { "vector_audit", + "Parse vector.toml (root prefix): a source bound to 0.0.0.0 or ::, a " + "sink with an endpoint and no tls block or tls.verify off, the GraphQL " + "api enabled beyond loopback and a world-writable file. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}", + t_vector_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 02de532..f8ab3e4 100644 --- a/src/tools_red.c +++ b/src/tools_red.c @@ -10281,6 +10281,95 @@ static void t_tempo_probe(mcp_conn *c, const mcp_json *args, void *user) mcp_buf_free(&b); } +/* ------------------------------------------------------------- jaeger_probe */ + +/* Jaeger's query service on 16686 has no authentication: /api/services lists + * every service name the collector has ever seen, which is a map of the + * architecture (and of the language/team names behind it). A 2xx whose body + * carries a "data" array counts as open; that body becomes the evidence. + * /api/traces?service=... would return whole traces, so it is not fetched - + * the service list is enough to prove the point. */ +static void t_jaeger_probe(mcp_conn *c, const mcp_json *args, void *user) +{ + static const char *paths[] = { "/", "/api/services", NULL }; + const char *target = mcp_arg_string(args, "target"); + int port = mcp_arg_int(args, "port", 16686); + int tls = mcp_arg_bool(args, "tls", apex_looks_tls(16686)); + mcp_buf b; + int first = 1; + int tested = 0; + int open_count = 0; + int services_open = 0; + int service_count = 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, "jaeger_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; + + 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); + if (code >= 200 && code < 300) { + open_count++; + if (strcmp(paths[i], "/api/services") == 0 && + resp != NULL && strstr(resp, "\"data\"") != NULL) { + services_open = 1; + service_count = count_needle(resp, "\""); + if (evidence == NULL) + evidence = apex_evidence_save( + "open-jaeger-services", 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\":%zu}", code, len); + free(resp); + } + mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d," + "\"services_open\":%s,\"quote_chars\":%d,\"evidence\":", + tested, open_count, services_open ? "true" : "false", + service_count); + if (evidence != NULL) + apex_json_str(&b, evidence); + else + mcp_buf_puts(&b, "null"); + mcp_buf_puts(&b, "}"); + mcp_reply_json(c, b.p); + if (services_open) + apex_audit("jaeger_probe", target, port, 1, + "open Jaeger query API: service list readable without " + "credentials", "HTTP GET /api/services"); + free(evidence); + mcp_buf_free(&b); +} + const mcp_tool TOOLS_RED[] = { { "vuln_check", "Non-destructive verification of exposed artifacts on one web target: " @@ -11138,6 +11227,17 @@ const mcp_tool TOOLS_RED[] = { "\"tls\":{\"type\":\"boolean\"}}," "\"required\":[\"target\"]}", t_loki_probe }, + { "jaeger_probe", + "Query the Jaeger query service on 16686 without credentials: a 2xx on " + "/api/services that carries a data array lists every service the " + "collector has seen, saved as evidence. Also reports whether the UI " + "root answered. Read-only.", + "{\"type\":\"object\",\"properties\":{" + "\"target\":{\"type\":\"string\"}," + "\"port\":{\"type\":\"integer\",\"description\":\"default 16686\"}," + "\"tls\":{\"type\":\"boolean\"}}," + "\"required\":[\"target\"]}", + t_jaeger_probe }, { "tempo_probe", "Get /ready, /status/version and /api/search/tags without credentials; " "a 2xx on the tag search is an open trace API and the tag list is " diff --git a/tests/gate_audit.py b/tests/gate_audit.py index 8b2e119..f5e7923 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 = 397 +EXPECTED_TOOLS = 400 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 bb14821..2ff7f16 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("397 tools registered", len(tools) == 397, len(tools)) +check("400 tools registered", len(tools) == 400, 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"]) == 397) + check("http tools/list", len(listing["result"]["tools"]) == 400) 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 @@ -17977,6 +17977,180 @@ for d in (ptl_root, ptl_good_root, ptl_empty_root, otel_root, otel_good_root, otel_empty_root, cfg62_home): shutil.rmtree(d, ignore_errors=True) +# --- 1.92.0: fluent-bit and Vector audits plus the Jaeger probe --- +print("\n== fluent-bit, Vector and Jaeger ==") + +fb_root = tempfile.mkdtemp(prefix="apex-fb-") +os.makedirs(os.path.join(fb_root, "etc", "fluent-bit", "conf.d")) +fb_bad = os.path.join(fb_root, "etc", "fluent-bit", "fluent-bit.conf") +with open(fb_bad, "w") as f: + f.write("[SERVICE]\n") + f.write(" Flush 1\n") + f.write(" HTTP_Server On\n") + f.write(" HTTP_Listen 0.0.0.0\n") + f.write(" Log_Level debug\n") + f.write("\n[INPUT]\n") + f.write(" Name tail\n") + f.write(" Path /var/log/app.log\n") + f.write("\n[OUTPUT]\n") + f.write(" Name es\n") + f.write(" Host es.example.test\n") + f.write(" Port 9200\n") +os.chmod(fb_bad, 0o666) + +fb_good_root = tempfile.mkdtemp(prefix="apex-fbg-") +os.makedirs(os.path.join(fb_good_root, "etc", "fluent-bit")) +with open(os.path.join(fb_good_root, "etc", "fluent-bit", + "fluent-bit.conf"), "w") as f: + f.write("[SERVICE]\n") + f.write(" HTTP_Server On\n") + f.write(" HTTP_Listen 127.0.0.1\n") + f.write(" Log_Level info\n") + f.write("\n[OUTPUT]\n") + f.write(" Name es\n") + f.write(" Host es.example.test\n") + f.write(" TLS On\n") + +fb_empty_root = tempfile.mkdtemp(prefix="apex-fbe-") + +vec_root = tempfile.mkdtemp(prefix="apex-vec-") +os.makedirs(os.path.join(vec_root, "etc", "vector")) +vec_bad = os.path.join(vec_root, "etc", "vector", "vector.toml") +with open(vec_bad, "w") as f: + f.write("[api]\n") + f.write('enabled = true\n') + f.write('address = "0.0.0.0:8686"\n') + f.write("\n[sources.syslog]\n") + f.write('type = "syslog"\n') + f.write('address = "0.0.0.0:514"\n') + f.write("\n[sinks.out]\n") + f.write('type = "http"\n') + f.write('inputs = ["syslog"]\n') + f.write('uri = "http://loki.example.test:3100/loki/api/v1/push"\n') +os.chmod(vec_bad, 0o666) + +vec_good_root = tempfile.mkdtemp(prefix="apex-vecg-") +os.makedirs(os.path.join(vec_good_root, "etc", "vector")) +with open(os.path.join(vec_good_root, "etc", "vector", "vector.toml"), + "w") as f: + f.write("[api]\n") + f.write('enabled = true\n') + f.write('address = "127.0.0.1:8686"\n') + f.write("\n[sources.syslog]\n") + f.write('type = "syslog"\n') + f.write('address = "127.0.0.1:514"\n') + f.write("\n[sinks.out]\n") + f.write('type = "http"\n') + f.write('uri = "https://loki.example.test/loki/api/v1/push"\n') + f.write('tls.verify = true\n') + +vec_empty_root = tempfile.mkdtemp(prefix="apex-vece-") + + +class _JaegerHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + path = urllib.parse.urlsplit(self.path).path + if path == "/": + body = b"Jaeger UI" + self.send_response(200) + elif path == "/api/services": + body = (b'{"data":["jaeger-query","frontend","checkout",' + b'"payments"],"total":4,"limit":0,"offset":0,"errors":null}') + self.send_response(200) + else: + body = b'{"errors":[{"code":404,"msg":"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 _JaegerAuthHandler(_JaegerHandler): + def do_GET(self): + body = b'{"errors":[{"code":401,"msg":"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) + + +jgr_srv = http.server.HTTPServer(("127.0.0.1", 0), _JaegerHandler) +jgr_port = jgr_srv.server_address[1] +jgr_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _JaegerAuthHandler) +jgr_auth_port = jgr_auth_srv.server_address[1] +for _s in (jgr_srv, jgr_auth_srv): + threading.Thread(target=_s.serve_forever, daemon=True).start() + +cfg63_home = tempfile.mkdtemp(prefix="apex-cfg63-home-") +write_scope(cfg63_home, + {"label": "cfg63", "expires": "2099-01-01T00:00:00Z", + "allow_private": True, "allow_ip": ["127.0.0.1"], + "allow_domain": ["example.test"], + "allow_port": [str(jgr_port), str(jgr_auth_port)]}) + +res, _ = run([ + call(1, "fluentbit_audit", root=fb_root), + call(2, "fluentbit_audit", root=fb_good_root), + call(3, "fluentbit_audit", root=fb_empty_root), + call(4, "vector_audit", root=vec_root), + call(5, "vector_audit", root=vec_good_root), + call(6, "vector_audit", root=vec_empty_root), + call(7, "jaeger_probe", target="127.0.0.1", port=jgr_port, tls=False), + call(8, "jaeger_probe", target="127.0.0.1", port=jgr_auth_port, tls=False), +], home=cfg63_home) +by_id = {r["id"]: r for r in res if "id" in r} + +fb = json.loads(text(by_id[1])) +fb_kinds = {f["id"] for f in fb["findings"]} +check("fluentbit_audit flags a remote output without TLS, HTTP on any " + "interface, debug level and a writable file", + {"output-no-tls", "http-any-interface", "debug-log-level", + "world-writable"} <= fb_kinds and fb["outputs"] == 1 and + fb["outputs_without_tls"] == 1 and fb["http_any_interface"] is True and + fb["debug_level"] is True, fb) +fb_good = json.loads(text(by_id[2])) +check("fluentbit_audit accepts a loopback HTTP listener and a TLS output", + fb_good["findings_count"] == 0 and fb_good["http_any_interface"] is False + and fb_good["outputs_without_tls"] == 0 and + fb_good["debug_level"] is False and fb_good["files"] == 1, fb_good) +check("fluentbit_audit reports a missing configuration", err(by_id[3]), + text(by_id[3])) + +vc = json.loads(text(by_id[4])) +vc_kinds = {f["id"] for f in vc["findings"]} +check("vector_audit flags a source on every address, a sink without TLS, " + "an open API and a writable file", + {"source-any-address", "sink-no-tls", "api-any-address", + "world-writable"} <= vc_kinds and vc["exposed_sources"] == 1 and + vc["sinks_without_tls"] == 1 and vc["api_open"] is True, vc) +vc_good = json.loads(text(by_id[5])) +check("vector_audit accepts loopback sources, a TLS sink and a loopback API", + vc_good["findings_count"] == 0 and vc_good["exposed_sources"] == 0 and + vc_good["sinks_without_tls"] == 0 and vc_good["api_open"] is False and + vc_good["sinks"] == 1, vc_good) +check("vector_audit reports a missing configuration", err(by_id[6]), + text(by_id[6])) + +jgr = json.loads(text(by_id[7])) +check("jaeger_probe finds an open service list and saves evidence", + jgr["services_open"] is True and jgr["open_count"] == 2 and + jgr["evidence"] is not None and os.path.isfile(jgr["evidence"]), jgr) +jgr_auth = json.loads(text(by_id[8])) +check("jaeger_probe reports a closed service list as not open", + jgr_auth["services_open"] is False and jgr_auth["evidence"] is None and + all(e["status"] == 401 for e in jgr_auth["endpoints"]), jgr_auth) + +for _s in (jgr_srv, jgr_auth_srv): + _s.shutdown() +for d in (fb_root, fb_good_root, fb_empty_root, vec_root, vec_good_root, + vec_empty_root, cfg63_home): + shutil.rmtree(d, ignore_errors=True) + # --- 1.84.0: gated wrappers for external scanners (mock binaries) --- print("\n== external scanner wrappers ==\n")