apex-twin 1.91.0: promtail and otel collector audits, Loki and Tempo probes

Two blue config audits and two red API probes for the observability stack.

promtail_audit (blue): positions.filename missing or under /tmp, a client
without tenant_id, a plain http push URL and a world-writable config.
otel_collector_audit (blue): an exporters block without tls, a debug
exporter, zpages/pprof and a world-writable config.
loki_probe (red): /loki/api/v1/labels without credentials; the label list
is saved as evidence.
tempo_probe (red): /api/search/tags without credentials; the tag list is
saved as evidence.

Verified: 1477/1477 checks (make test and test-asan), gate-audit 397 tools
from 14 tables, analyze 0 warnings, 240 fuzz cases, distcheck from the
tarball, coverage 85.0%. Red proof: disabling the tmp-positions check in
promtail_audit turns the fixture check red (1476/1), restored afterwards.
This commit is contained in:
lotherk committed 2026-11-23 15:33:59 +00:00
1 parent 2a0d5e5833
commit 41eac32f53
9 files changed
+700 -13

No files matched your search

+18
View File
@@ -1,5 +1,23 @@
# Changelog
## 1.91.0 - 2026-11-24 - this change
- **promtail** (`promtail_audit`): a positions block whose `filename` points
into `/tmp` or `/var/tmp` (tmpwatch deletes it and every log line arrives
twice), a config without `positions.filename` at all (the offset lives only
in memory), a `clients:` entry without `tenant_id` (all tenants share one
Loki stream), an `http://` push URL and a world-writable config.
- **OpenTelemetry collector** (`otel_collector_audit`): an `exporters:` block
without any `tls:` child and without `insecure: false`, a `debug:`
exporter left in a pipeline (every span goes to stdout and the journal),
the `zpages`/`pprof` extensions and a world-writable config.
- **Loki** (`loki_probe`): `/ready`, `/metrics`, `/loki/api/v1/labels` and
`/loki/api/v1/status/buildinfo` without credentials; a 2xx on the labels
endpoint is an open log query API and the label list is saved as evidence.
- **Tempo** (`tempo_probe`): `/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 saved as evidence.
## 1.90.0 - 2026-11-24 - this change
- **Suricata** (`suricata_audit`): `rule-files:` left empty (the sensor runs
+10 -5
View File
@@ -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.
**393 tools · 1467 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
**397 tools · 1477 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.90.0","tools":393,...,"scope":{"loaded":true,...}}
{"version":"1.91.0","tools":397,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -241,6 +241,8 @@ uploads and secret-file reads. It does not execute anything.
| `openbmc_probe` | xyz.openbmc_project control tree on 443 without a session; power policy as evidence |
| `schema_registry_probe` | `/subjects` on 8081 without auth; subject list as evidence |
| `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 |
| `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 |
@@ -589,6 +591,8 @@ does.
| `suricata_audit` | suricata.yaml: empty rule-files, disabled engine, world-writable rules |
| `icinga2_audit` | API bound beyond localhost, accept_config, run_as_root commands, writable config |
| `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 |
| `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 |
@@ -1076,7 +1080,7 @@ 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
schema_registry_probe, loki_probe, tempo_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,
@@ -1103,7 +1107,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
smartd_audit, tlog_audit, abrt_audit,
freshclam_audit, tripwire_audit, fapolicyd_audit,
systemd_timer_audit, yara_audit,
suricata_audit, icinga2_audit, falco_audit)
suricata_audit, icinga2_audit, falco_audit,
promtail_audit, otel_collector_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
@@ -1142,7 +1147,7 @@ examples/ scope.json
## Status
1.90.0. Built and run: 393 tools, 1467 checks, 240 fuzz cases and 85.0% line
1.91.0. Built and run: 397 tools, 1477 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
+1 -1
View File
@@ -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.90.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.91.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.
+3 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.90.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.91.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,
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,
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,7 @@ 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,
icinga2_audit, falco_audit,
promtail_audit, otel_collector_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,
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.90.0"
#define APEX_VERSION "1.91.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+237
View File
@@ -30057,6 +30057,228 @@ static void t_falco_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* ------------------------------------------------------------- promtail_audit */
/* Promtail is Grafana's log shipper. Its config is YAML with a positions block
* and a clients list. Three things break a deployment quietly: positions that
* point into /tmp (every restart re-reads every log, so lines arrive twice and
* gaps appear), a client without tenant_id (all tenants share one stream), and
* a client over plain http without a tls_config (labels and log bodies travel
* in clear text). */
struct promtail_state {
int files;
int no_positions;
int tmp_positions;
int no_tenant;
int plain_http;
int writable;
};
static int promtail_has_line(const char *text, const char *needle)
{
return strcasestr(text, needle) != NULL;
}
static void t_promtail_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1200];
static char text[131072];
char value[512];
mcp_buf b;
mcp_buf findings;
struct promtail_state st;
struct stat sb;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/promtail/config.yml",
"/etc/promtail/config.yaml",
"/etc/promtail/promtail.yml", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 300) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
st.files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st.writable++;
add_finding(&findings, &first, "writable-config", "high",
"%s is writable by any local user; anyone can "
"redirect the log stream", path);
count++;
}
if (yaml_value(text, "filename", value, sizeof(value)) != 1) {
st.no_positions++;
add_finding(&findings, &first, "no-positions", "medium",
"%s has no positions.filename; promtail keeps "
"its offset only in memory and re-reads every "
"log after a restart", path);
count++;
} else if (strncmp(value, "/tmp/", 5) == 0 ||
strncmp(value, "/var/tmp/", 9) == 0) {
st.tmp_positions++;
add_finding(&findings, &first, "tmp-positions", "medium",
"positions live in %.200s; tmpwatch deletes the "
"file and every log line arrives twice", value);
count++;
}
if (!promtail_has_line(text, "tenant_id") &&
promtail_has_line(text, "clients:")) {
st.no_tenant++;
add_finding(&findings, &first, "no-tenant", "medium",
"%s sends to a client without tenant_id; every "
"tenant shares one Loki stream", path);
count++;
}
if (promtail_has_line(text, "url: http://")) {
st.plain_http++;
add_finding(&findings, &first, "plain-http", "high",
"%s ships logs over plain http; labels and log "
"bodies are readable on the wire", path);
count++;
}
}
if (count == 0 && st.files == 0)
add_finding(&findings, &first, "no-config", "info",
"no readable promtail config under %.300s", root);
else if (count == 0)
add_finding(&findings, &first, "no-findings", "info",
"positions persist, each client carries a tenant and "
"the endpoint uses https");
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"no_positions\":%d,"
"\"tmp_positions\":%d,\"no_tenant\":%d,"
"\"plain_http\":%d,\"writable\":%d,"
"\"findings_count\":%d,\"findings\":[",
st.files, st.no_positions, st.tmp_positions,
st.no_tenant, st.plain_http, st.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);
}
/* -------------------------------------------------------- otel_collector_audit */
/* The OpenTelemetry collector has an exporters block and a service.pipelines
* block. An exporter without a tls block sends telemetry in clear text, a
* debug exporter left in an active pipeline writes every span to stdout (and
* on to the journal), and zpages or pprof expose an internal control surface. */
struct otel_state {
int files;
int plain_exporters;
int debug_exporters;
int zpages;
int writable;
};
static void t_otel_collector_audit(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *files[] = { "/etc/otelcol/config.yaml",
"/etc/otelcol-contrib/config.yaml",
"/etc/otel-collector/config.yaml",
"/etc/otel/config.yaml", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1200];
static char text[131072];
mcp_buf b;
mcp_buf findings;
struct otel_state st;
struct stat sb;
int first = 1;
int count = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 300) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
st.files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st.writable++;
add_finding(&findings, &first, "writable-config", "high",
"%s is writable by any local user; anyone can "
"add an exporter", path);
count++;
}
/* An exporter definition without any tls: child sends plaintext.
* Only report it when exporters exist at all. */
if (strcasestr(text, "exporters:") != NULL &&
strcasestr(text, "tls:") == NULL &&
strcasestr(text, "insecure: false") == NULL) {
st.plain_exporters++;
add_finding(&findings, &first, "no-tls", "high",
"%s defines exporters without a tls block; "
"spans, metrics and logs leave in clear text",
path);
count++;
}
if (strcasestr(text, "debug:") != NULL) {
st.debug_exporters++;
add_finding(&findings, &first, "debug-exporter", "low",
"%s keeps a debug exporter; every span is "
"written to stdout and the journal", path);
count++;
}
if (strcasestr(text, "zpages:") != NULL ||
strcasestr(text, "pprof:") != NULL) {
st.zpages++;
add_finding(&findings, &first, "control-surface", "medium",
"%s enables zpages or pprof; the collector "
"exposes internal state and a heap profile",
path);
count++;
}
}
if (count == 0 && st.files == 0)
add_finding(&findings, &first, "no-config", "info",
"no readable collector config under %.300s", root);
else if (count == 0)
add_finding(&findings, &first, "no-findings", "info",
"every exporter carries tls, no debug exporter and no "
"zpages or pprof extension");
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"no_tls\":%d,"
"\"debug_exporters\":%d,\"control_surface\":%d,"
"\"writable\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.plain_exporters, st.debug_exporters,
st.zpages, st.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, "
@@ -31714,6 +31936,21 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_falco_audit },
{ "promtail_audit",
"Parse a promtail config (root prefix): a missing positions.filename "
"(offsets kept only in memory), positions under /tmp (deleted and "
"re-read), a client without tenant_id and a plain-http client URL. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_promtail_audit },
{ "otel_collector_audit",
"Parse an OpenTelemetry collector config (root prefix): exporters "
"without a tls block, a debug exporter left in a pipeline and the "
"zpages/pprof control surfaces. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_otel_collector_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+196
View File
@@ -10106,6 +10106,181 @@ static void t_superset_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* --------------------------------------------------------------- loki_probe */
/* Loki on 3100 has no authentication of its own: /ready answers for anyone,
* but the interesting endpoints are the query API. /loki/api/v1/labels and
* /loki/api/v1/label/... list every label name the instance has ever seen,
* which is a map of the environment (jobs, pods, instances). A 2xx on
* /loki/api/v1/labels is the finding; the label list is the evidence. */
static void t_loki_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/ready", "/metrics",
"/loki/api/v1/labels",
"/loki/api/v1/status/buildinfo", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 3100);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(3100));
mcp_buf b;
int first = 1;
int tested = 0;
int open_count = 0;
int labels_open = 0;
int label_chars = 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, "loki_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], "/loki/api/v1/labels") == 0) {
labels_open = 1;
label_chars = count_needle(resp, "\"");
if (evidence == NULL)
evidence = apex_evidence_save(
"open-loki-labels", 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,"
"\"labels_open\":%s,\"label_chars\":%d,\"evidence\":",
tested, open_count, labels_open ? "true" : "false",
label_chars);
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 (labels_open)
apex_audit("loki_probe", target, port, 1,
"open Loki query API: label names readable without "
"credentials", "HTTP GET /loki/api/v1/labels");
free(evidence);
mcp_buf_free(&b);
}
/* --------------------------------------------------------------- tempo_probe */
/* Tempo on 3200 answers /ready for anyone and needs no credentials for
* /api/search/tags and /api/search/tag/<name>/values. Those two turn a trace
* backend into a list of every service and span attribute it stores. */
static void t_tempo_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/ready", "/status/version",
"/api/search/tags", "/api/echo", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 3200);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(3200));
mcp_buf b;
int first = 1;
int tested = 0;
int open_count = 0;
int tags_open = 0;
int tag_chars = 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, "tempo_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/search/tags") == 0) {
tags_open = 1;
tag_chars = count_needle(resp, "\"");
if (evidence == NULL)
evidence = apex_evidence_save(
"open-tempo-tags", 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,"
"\"tags_open\":%s,\"tag_chars\":%d,\"evidence\":",
tested, open_count, tags_open ? "true" : "false",
tag_chars);
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 (tags_open)
apex_audit("tempo_probe", target, port, 1,
"open Tempo search API: tag names readable without "
"credentials", "HTTP GET /api/search/tags");
free(evidence);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_RED[] = {
{ "vuln_check",
"Non-destructive verification of exposed artifacts on one web target: "
@@ -10953,6 +11128,27 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_schema_registry_probe },
{ "loki_probe",
"Get /ready, /metrics and /loki/api/v1/labels without credentials; a "
"2xx on the labels endpoint is an open log query API and the label "
"list is saved as evidence.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 3100\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_loki_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 "
"saved as evidence.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 3200\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_tempo_probe },
{ "openbmc_probe",
"Get the Redfish root and the xyz.openbmc_project tree on 443 without a "
"session. A 2xx on the host control tree means power control and "
+1 -1
View File
@@ -21,7 +21,7 @@ import re
import sys
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXPECTED_TOOLS = 393
EXPECTED_TOOLS = 397
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
+233 -2
View File
@@ -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("393 tools registered", len(tools) == 393, len(tools))
check("397 tools registered", len(tools) == 397, 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"]) == 393)
check("http tools/list", len(listing["result"]["tools"]) == 397)
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
@@ -17746,6 +17746,237 @@ for d in (sr_root, sr_good_root, ic_root, ic_good_root, fc_root,
fc_good_root, cfg61_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.91.0: promtail and otel collector audits, Loki and Tempo probes ---
print("\n== promtail, otel collector, Loki and Tempo ==")
ptl_root = tempfile.mkdtemp(prefix="apex-ptl-")
os.makedirs(os.path.join(ptl_root, "etc", "promtail"))
ptl_bad = os.path.join(ptl_root, "etc", "promtail", "config.yml")
with open(ptl_bad, "w") as f:
f.write("server:\n")
f.write(" http_listen_port: 9080\n")
f.write("positions:\n")
f.write(" filename: /tmp/positions.yaml\n")
f.write("clients:\n")
f.write(" - url: http://loki.example.test:3100/loki/api/v1/push\n")
os.chmod(ptl_bad, 0o666)
ptl_good_root = tempfile.mkdtemp(prefix="apex-ptlg-")
os.makedirs(os.path.join(ptl_good_root, "etc", "promtail"))
with open(os.path.join(ptl_good_root, "etc", "promtail", "config.yml"),
"w") as f:
f.write("positions:\n")
f.write(" filename: /var/lib/promtail/positions.yaml\n")
f.write("clients:\n")
f.write(" - url: https://loki.example.test/loki/api/v1/push\n")
f.write(" tenant_id: team-a\n")
ptl_empty_root = tempfile.mkdtemp(prefix="apex-ptle-")
otel_root = tempfile.mkdtemp(prefix="apex-otel-")
os.makedirs(os.path.join(otel_root, "etc", "otelcol"))
otel_bad = os.path.join(otel_root, "etc", "otelcol", "config.yaml")
with open(otel_bad, "w") as f:
f.write("receivers:\n")
f.write(" otlp:\n")
f.write(" protocols:\n")
f.write(" grpc:\n")
f.write("exporters:\n")
f.write(" otlp:\n")
f.write(" endpoint: collector.example.test:4317\n")
f.write(" debug:\n")
f.write(" verbosity: detailed\n")
f.write("extensions:\n")
f.write(" zpages:\n")
f.write("service:\n")
f.write(" pipelines:\n")
f.write(" traces:\n")
f.write(" exporters: [otlp, debug]\n")
os.chmod(otel_bad, 0o666)
otel_good_root = tempfile.mkdtemp(prefix="apex-otelg-")
os.makedirs(os.path.join(otel_good_root, "etc", "otelcol"))
with open(os.path.join(otel_good_root, "etc", "otelcol", "config.yaml"),
"w") as f:
f.write("receivers:\n")
f.write(" otlp:\n")
f.write(" protocols:\n")
f.write(" grpc:\n")
f.write("exporters:\n")
f.write(" otlp:\n")
f.write(" endpoint: collector.example.test:4317\n")
f.write(" tls:\n")
f.write(" insecure: false\n")
f.write("service:\n")
f.write(" pipelines:\n")
f.write(" traces:\n")
f.write(" exporters: [otlp]\n")
otel_empty_root = tempfile.mkdtemp(prefix="apex-otele-")
class _LokiHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/ready":
body = b"ready\n"
self.send_response(200)
elif path == "/loki/api/v1/labels":
body = b'{"status":"success","data":["job","instance","pod"]}'
self.send_response(200)
elif path == "/loki/api/v1/status/buildinfo":
body = b'{"version":"2.9.1"}'
self.send_response(200)
else:
body = b'{"status":"error","error":"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 _LokiAuthHandler(_LokiHandler):
def do_GET(self):
body = b'{"status":"error","error":"no org id"}'
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)
class _TempoHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/ready":
body = b"ready\n"
self.send_response(200)
elif path == "/status/version":
body = b'{"version":"2.3.1","revision":"abc"}'
self.send_response(200)
elif path == "/api/search/tags":
body = b'{"tagNames":["service.name","http.status_code","span.kind"]}'
self.send_response(200)
else:
body = b'{"error":"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 _TempoAuthHandler(_TempoHandler):
def do_GET(self):
body = b'{"error":"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)
loki_srv = http.server.HTTPServer(("127.0.0.1", 0), _LokiHandler)
loki_port = loki_srv.server_address[1]
loki_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _LokiAuthHandler)
loki_auth_port = loki_auth_srv.server_address[1]
tempo_srv = http.server.HTTPServer(("127.0.0.1", 0), _TempoHandler)
tempo_port = tempo_srv.server_address[1]
tempo_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _TempoAuthHandler)
tempo_auth_port = tempo_auth_srv.server_address[1]
for _s in (loki_srv, loki_auth_srv, tempo_srv, tempo_auth_srv):
threading.Thread(target=_s.serve_forever, daemon=True).start()
cfg62_home = tempfile.mkdtemp(prefix="apex-cfg62-home-")
write_scope(cfg62_home,
{"label": "cfg62", "expires": "2099-01-01T00:00:00Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": ["1-65535"]})
res, _ = run([
call(1, "promtail_audit", root=ptl_root),
call(2, "promtail_audit", root=ptl_good_root),
call(3, "otel_collector_audit", root=otel_root),
call(4, "otel_collector_audit", root=otel_good_root),
call(5, "promtail_audit", root=ptl_empty_root),
call(6, "otel_collector_audit", root=otel_empty_root),
call(7, "loki_probe", target="127.0.0.1", port=loki_port, tls=False),
call(8, "loki_probe", target="127.0.0.1", port=loki_auth_port, tls=False),
call(9, "tempo_probe", target="127.0.0.1", port=tempo_port, tls=False),
call(10, "tempo_probe", target="127.0.0.1", port=tempo_auth_port,
tls=False),
], home=cfg62_home)
by_id = {r["id"]: r for r in res if "id" in r}
ptla = json.loads(text(by_id[1]))
ptla_kinds = {f["id"] for f in ptla["findings"]}
check("promtail_audit flags tmp positions, no tenant, plain http and a "
"writable config",
{"tmp-positions", "no-tenant", "plain-http",
"writable-config"} <= ptla_kinds and
ptla["tmp_positions"] == 1 and ptla["no_tenant"] == 1 and
ptla["plain_http"] == 1 and ptla["writable"] == 1, ptla)
ptla_good = json.loads(text(by_id[2]))
check("promtail_audit accepts persistent positions and a tenant over https",
ptla_good["findings"][0]["id"] == "no-findings" and
ptla_good["tmp_positions"] == 0 and ptla_good["no_tenant"] == 0 and
ptla_good["plain_http"] == 0, ptla_good)
otela = json.loads(text(by_id[3]))
otela_kinds = {f["id"] for f in otela["findings"]}
check("otel_collector_audit flags missing tls, a debug exporter, zpages and "
"a writable config",
{"no-tls", "debug-exporter", "control-surface",
"writable-config"} <= otela_kinds and otela["no_tls"] == 1 and
otela["debug_exporters"] == 1 and otela["control_surface"] == 1 and
otela["writable"] == 1, otela)
otela_good = json.loads(text(by_id[4]))
check("otel_collector_audit accepts a tls exporter without debug and zpages",
otela_good["findings"][0]["id"] == "no-findings" and
otela_good["no_tls"] == 0 and otela_good["debug_exporters"] == 0 and
otela_good["control_surface"] == 0, otela_good)
ptla_empty = json.loads(text(by_id[5]))
check("promtail_audit reports a missing configuration",
ptla_empty["files"] == 0 and
ptla_empty["findings"][0]["id"] == "no-config", ptla_empty)
otela_empty = json.loads(text(by_id[6]))
check("otel_collector_audit reports a missing configuration",
otela_empty["files"] == 0 and
otela_empty["findings"][0]["id"] == "no-config", otela_empty)
lka = json.loads(text(by_id[7]))
check("loki_probe finds an open label API and saves evidence",
lka["labels_open"] is True and lka["open_count"] == 3 and
lka["evidence"] is not None and os.path.isfile(lka["evidence"]), lka)
lka_auth = json.loads(text(by_id[8]))
check("loki_probe reports a closed label API as not open",
lka_auth["labels_open"] is False and lka_auth["evidence"] is None and
all(e["status"] == 401 for e in lka_auth["endpoints"]), lka_auth)
tpa = json.loads(text(by_id[9]))
check("tempo_probe finds an open tag search and saves evidence",
tpa["tags_open"] is True and tpa["open_count"] == 3 and
tpa["evidence"] is not None and os.path.isfile(tpa["evidence"]), tpa)
tpa_auth = json.loads(text(by_id[10]))
check("tempo_probe reports a closed tag search as not open",
tpa_auth["tags_open"] is False and tpa_auth["evidence"] is None and
all(e["status"] == 401 for e in tpa_auth["endpoints"]), tpa_auth)
for _s in (loki_srv, loki_auth_srv, tempo_srv, tempo_auth_srv):
_s.shutdown()
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.84.0: gated wrappers for external scanners (mock binaries) ---
print("\n== external scanner wrappers ==\n")