apex-twin 1.53.0: Gitea, MinIO and Nextcloud audits, Prometheus probe

Blue:
- gitea_audit: app.ini from three homes: PROTOCOL=http, INSTALL_LOCK=false,
  an empty or default SECRET_KEY, REQUIRE_SIGNIN_VIEW=false.
- minio_audit: /etc/default/minio: default or missing root credentials,
  MINIO_BROWSER=on and a plain-HTTP MINIO_SERVER_URL.
- nextcloud_audit: config.php: debug=true, a wildcard trusted domain,
  missing/HTTP overwriteprotocol and a world-writable data directory.

Red:
- prometheus_api_probe: /-/ready and /api/v1/query?query=up without
  credentials; a 2xx query is an open API and is saved as evidence.

Tests with Gitea/MinIO/Nextcloud trees and two Prometheus fixtures (open and
401). 1096 checks, ASan suite green, analyze clean, release-check green
including distcheck 1.53.0.
This commit is contained in:
lotherk committed 2026-11-22 12:33:09 +00:00
1 parent d925e11b7b
commit 34ac87b20f
9 files changed
+697 -15

No files matched your search

+18 -1
View File
@@ -8,7 +8,24 @@ fields, and state from an older version is read by a newer one.
There are no git tags. The hash next to a version is the commit that introduced
it; the current entry is the commit that adds this section.
## 1.52.0 — 2026-11-23 — this change
## 1.53.0 — 2026-11-23 — this change
- **Gitea** (`gitea_audit`): `app.ini` from three homes: `PROTOCOL = http`,
`INSTALL_LOCK = false`, an empty or default `SECRET_KEY`,
`REQUIRE_SIGNIN_VIEW = false` and a world-writable file.
- **MinIO** (`minio_audit`): `/etc/default/minio`: default or missing root
credentials, `MINIO_BROWSER=on`, a plain-HTTP `MINIO_SERVER_URL` and a
world-writable file.
- **Nextcloud** (`nextcloud_audit`): `config.php`: `debug = true`, a wildcard
`trusted_domains` entry, missing or HTTP `overwriteprotocol`, a
world-writable data directory and file.
- **Prometheus** (`prometheus_api_probe`): `/-/ready` and
`/api/v1/query?query=up` without credentials; a 2xx query is an open API
and is saved as evidence.
- Tests with Gitea/MinIO/Nextcloud trees and two Prometheus HTTP fixtures
(open and 401). 1096 checks. Coverage 83.5%.
## 1.52.0 — 2026-11-23 — d925e11
- **Caddy** (`caddy_audit`): `Caddyfile`: a site on `:80` or `http://`,
`auto_https off`, `tls internal` and an admin API beyond localhost.
+12 -6
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.
**246 tools · 1084 end-to-end checks · 340 fuzz cases · 83.4% line coverage · ~883 KiB**
**250 tools · 1096 end-to-end checks · 340 fuzz cases · 83.5% line coverage · ~896 KiB**
```
$ ./apex-twin --check
{"version":"1.52.0","tools":246,...,"scope":{"loaded":true,...}}
{"version":"1.53.0","tools":250,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -149,7 +149,7 @@ closes a request whose head or body does not arrive within
---
## Tools (246)
## Tools (250)
### Scope and bookkeeping
@@ -211,6 +211,7 @@ uploads and secret-file reads. It does not execute anything.
| `docker_registry_probe` | `/v2/` and `/v2/_catalog` without auth; catalog saved as evidence |
| `consul_api_probe` | `/v1/agent/self` and `/v1/catalog/services` without a token |
| `couchdb_probe` | `/` welcome and `/_all_dbs` without auth; database list as evidence |
| `prometheus_api_probe` | `/-/ready` and `/api/v1/query` without auth; query answer as evidence |
| `cookie_audit` | Secure/HttpOnly/SameSite per cookie, incl. `SameSite=None` without Secure |
| `http_options` | `Allow`/`Public`; flags TRACE, PUT, DELETE |
| `sqli_probe` | Quote and boolean payloads; differing answers are a **lead**, not proof |
@@ -443,6 +444,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `caddy_audit` | Caddyfile: `:80`, auto_https off, tls internal, exposed admin |
| `traefik_audit` | traefik.yml: api insecure, no redirect, no TLS |
| `autofs_audit` | auto.master: wildcard maps, writable maps, timeout=0 |
| `gitea_audit` | app.ini: HTTP, open installer, empty SECRET_KEY |
| `minio_audit` | minio defaults: default root credentials, browser, HTTP |
| `nextcloud_audit` | config.php: debug, wildcard domain, HTTP, writable data |
### ESP32
@@ -735,6 +739,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| Consul API | two unauthenticated GETs, first answer as evidence |
| caddy/traefik/autofs | config reads only; optional root prefix |
| CouchDB | two unauthenticated GETs, database list as evidence |
| gitea/minio/nextcloud | config reads only; optional root prefix |
| Prometheus API | two unauthenticated GETs, query answer as evidence |
| USB audit | 200 devices, sysfs reads only |
---
@@ -746,7 +752,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1084 end-to-end checks
make test # version check + gate audit + 1096 end-to-end checks
make version-check # the five places that carry a version must agree
make gate-audit # static: every target-taking tool calls the gate
make asan # apex-twin-asan with ASan + UBSan
@@ -872,7 +878,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
tls_hostname_check, ftp_tls_probe,
zookeeper_4lw_probe, etcd_api_probe,
docker_registry_probe, consul_api_probe,
couchdb_probe
couchdb_probe, prometheus_api_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,
@@ -915,7 +921,7 @@ examples/ scope.json
## Status
1.52.0. Built and run: 246 tools, 1084 checks, 340 fuzz cases and 83.4% line
1.53.0. Built and run: 250 tools, 1096 checks, 340 fuzz cases and 83.5% 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
+3 -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.52.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.53.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.
@@ -66,6 +66,8 @@ only narrow what the proxy does (the scope gate still runs first).
- **Firmware writing needs an explicit confirmation.** `esp_flash` refuses
without `confirm=true`, validates an absolute image path and audits the
attempt; it exists to provision the operator's own board.
- **Gitea, MinIO and Nextcloud audits read local files.** The Prometheus
probe sends two unauthenticated GETs and saves the query answer as evidence.
- **Caddy, Traefik and autofs audits read local files.** The CouchDB probe
sends two unauthenticated GETs and saves the database list as evidence.
- **FreeRADIUS, containerd and NATS audits read local files.** The Consul
+3 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.52.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.53.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -46,7 +46,7 @@ sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe,
dns_ns_consistency, dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit,
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe),
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -71,7 +71,7 @@ coredump_audit, nftables_audit, dnsmasq_audit, nsswitch_audit,
jenkins_audit, pgbouncer_audit, xinetd_audit, sssd_audit, avahi_audit, logind_audit,
tftpd_hpa_audit, iscsi_audit, rpcbind_audit, kdump_audit, kafka_audit, powerdns_audit,
varnish_audit, freeradius_audit, containerd_audit, nats_audit, caddy_audit, traefik_audit,
autofs_audit)
autofs_audit, gitea_audit, minio_audit, nextcloud_audit)
and ESP32 board tools (esp_info, esp_monitor,
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
esp_app_info, esp_image_verify).
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.52.0"
#define APEX_VERSION "1.53.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+368
View File
@@ -15739,6 +15739,353 @@ static void t_autofs_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- gitea_audit */
static void t_gitea_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/gitea/app.ini",
"/var/lib/gitea/custom/conf/app.ini",
"/var/lib/gitea/conf/app.ini", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[65536];
char protocol[64];
char install[64];
char secret[256];
char signin[64];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int plain_http = 0;
int install_open = 0;
int default_secret = 0;
int public_repos = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
files_read++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by anyone", path);
count++;
}
protocol[0] = install[0] = secret[0] = signin[0] = '\0';
ini_value(text, "server", "PROTOCOL", protocol,
sizeof(protocol));
ini_value(text, "security", "INSTALL_LOCK", install,
sizeof(install));
ini_value(text, "security", "SECRET_KEY", secret, sizeof(secret));
ini_value(text, "service", "REQUIRE_SIGNIN_VIEW", signin,
sizeof(signin));
if (strcasecmp(protocol, "http") == 0)
plain_http = 1;
if (strcasecmp(install, "false") == 0)
install_open = 1;
if (secret[0] == '\0' || strcasecmp(secret, "changeme") == 0)
default_secret = 1;
if (strcasecmp(signin, "false") == 0)
public_repos = 1;
break;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Gitea app.ini");
return;
}
if (plain_http) {
add_finding(&findings, &first, "plain-http", "medium",
"Gitea serves over plain HTTP");
count++;
}
if (install_open) {
add_finding(&findings, &first, "install-open", "high",
"the installer is still reachable");
count++;
}
if (default_secret) {
add_finding(&findings, &first, "default-secret", "high",
"SECRET_KEY is empty or a known default");
count++;
}
if (public_repos) {
add_finding(&findings, &first, "public-repos", "low",
"repositories are visible without signing in");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"plain_http\":%s,"
"\"install_locked\":%s,\"secret_key\":%s,"
"\"signin_required\":%s,\"findings_count\":%d,"
"\"findings\":[",
files_read, plain_http ? "true" : "false",
install_open ? "false" : "true",
default_secret ? "false" : "true",
public_repos ? "false" : "true", 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);
}
/* --------------------------------------------------------------- minio_audit */
static int minio_weak_password(const char *value)
{
static const char *weak[] = { "minioadmin", "password", "changeme",
"12345678", "admin", "secret", NULL };
int i;
for (i = 0; weak[i] != NULL; i++)
if (strcasecmp(value, weak[i]) == 0)
return 1;
return 0;
}
static void t_minio_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[65536];
char root_user[256];
char password[256];
char browser[64];
char url[512];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int default_creds = 0;
int no_creds = 0;
int browser_on = 0;
int plain_http = 0;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
snprintf(path, sizeof(path), "%s/etc/default/minio", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read the MinIO defaults");
return;
}
root_user[0] = password[0] = browser[0] = url[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"the MinIO defaults are writable by anyone");
count++;
}
conf_value(text, "MINIO_ROOT_USER", root_user, sizeof(root_user));
conf_value(text, "MINIO_ROOT_PASSWORD", password, sizeof(password));
conf_value(text, "MINIO_BROWSER", browser, sizeof(browser));
conf_value(text, "MINIO_SERVER_URL", url, sizeof(url));
if (root_user[0] == '\0' && password[0] == '\0') {
no_creds = 1;
add_finding(&findings, &first, "no-credentials", "high",
"no root credentials are configured");
count++;
} else if (strcasecmp(root_user, "minioadmin") == 0 ||
minio_weak_password(password)) {
default_creds = 1;
add_finding(&findings, &first, "default-credentials", "high",
"the root credentials are a known default");
count++;
}
if (strcasecmp(browser, "on") == 0) {
browser_on = 1;
add_finding(&findings, &first, "browser-on", "low",
"the MinIO browser console is enabled");
count++;
}
if (strncmp(url, "http://", 7) == 0) {
plain_http = 1;
add_finding(&findings, &first, "plain-http", "medium",
"MINIO_SERVER_URL uses plain HTTP");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"default_credentials\":%s,"
"\"credentials\":%s,\"browser\":%s,\"https\":%s,"
"\"findings_count\":%d,\"findings\":[",
default_creds ? "true" : "false",
no_creds ? "false" : "true",
browser_on ? "true" : "false",
plain_http ? "false" : "true", 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);
}
/* ----------------------------------------------------------- nextcloud_audit */
static int php_value(const char *text, const char *key, char *out, size_t n)
{
char needle[64];
const char *p;
const char *v;
size_t w = 0;
snprintf(needle, sizeof(needle), "'%s'", key);
out[0] = '\0';
p = strstr(text, needle);
if (p == NULL)
return 0;
p = strstr(p, "=>");
if (p == NULL)
return 0;
v = p + 2;
while (*v == ' ' || *v == '\t')
v++;
if (*v == '\'') {
v++;
while (*v != '\0' && *v != '\'' && w + 1 < n)
out[w++] = *v++;
out[w] = '\0';
return 1;
}
while (*v != '\0' && *v != ',' && *v != ')' && *v != '\n' &&
*v != '\r' && w + 1 < n)
out[w++] = *v++;
while (w > 0 && (out[w - 1] == ' ' || out[w - 1] == '\t'))
w--;
out[w] = '\0';
return 1;
}
static void t_nextcloud_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = {
"/var/www/nextcloud/config/config.php",
"/var/www/html/nextcloud/config/config.php",
"/var/www/html/config/config.php", NULL
};
const char *root = mcp_arg_string(args, "root");
char path[1024];
char data_path[1200];
static char text[131072];
char value[256];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int debug = 0;
int wildcard = 0;
int no_https = 0;
int writable_data = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
files_read++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by anyone", path);
count++;
}
if (php_value(text, "debug", value, sizeof(value)) &&
strcasecmp(value, "true") == 0)
debug = 1;
if (strstr(text, "trusted_domains") != NULL &&
strstr(text, "=> '*'") != NULL)
wildcard = 1;
if (!php_value(text, "overwriteprotocol", value,
sizeof(value)) ||
strcasecmp(value, "http") == 0)
no_https = 1;
if (php_value(text, "datadirectory", value, sizeof(value)) &&
value[0] == '/') {
snprintf(data_path, sizeof(data_path), "%.400s%s", root,
value);
if (stat(data_path, &st) == 0 && S_ISDIR(st.st_mode) &&
(st.st_mode & 0002) != 0)
writable_data = 1;
}
break;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Nextcloud config.php");
return;
}
if (debug) {
add_finding(&findings, &first, "debug", "medium",
"debug mode leaks stack traces");
count++;
}
if (wildcard) {
add_finding(&findings, &first, "wildcard-trusted-domain",
"medium",
"trusted_domains accepts any host header");
count++;
}
if (no_https) {
add_finding(&findings, &first, "no-https", "medium",
"overwriteprotocol is missing or HTTP");
count++;
}
if (writable_data) {
add_finding(&findings, &first, "writable-data", "high",
"the data directory is writable by anyone");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"debug\":%s,"
"\"trusted_domains_wildcard\":%s,\"https\":%s,"
"\"data_writable\":%s,\"findings_count\":%d,"
"\"findings\":[",
files_read, debug ? "true" : "false",
wildcard ? "true" : "false",
no_https ? "false" : "true",
writable_data ? "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, "
@@ -16606,6 +16953,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_autofs_audit },
{ "gitea_audit",
"Parse app.ini (root prefix, three usual paths): PROTOCOL=http, "
"INSTALL_LOCK=false, an empty or default SECRET_KEY, "
"REQUIRE_SIGNIN_VIEW=false and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_gitea_audit },
{ "minio_audit",
"Parse /etc/default/minio (root prefix): default or missing root "
"credentials, MINIO_BROWSER=on, a plain-HTTP server URL and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_minio_audit },
{ "nextcloud_audit",
"Parse config.php (root prefix, three usual paths): debug=true, a "
"wildcard trusted domain, missing or HTTP overwriteprotocol, a "
"world-writable data directory and file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_nextcloud_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+98
View File
@@ -6796,6 +6796,94 @@ static void t_couchdb_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ------------------------------------------------------- prometheus_api_probe */
static void t_prometheus_api_probe(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *paths[] = { "/-/ready", "/api/v1/query?query=up",
NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 9090);
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 query_open = 0;
int ready = 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, "prometheus_api_probe", target, port))
return;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port,
tls ? "true" : "false");
for (i = 0; paths[i] != NULL; i++) {
char status[256];
char *resp = NULL;
size_t len = 0;
int code;
int open;
status[0] = '\0';
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
8000, &resp, &len, status,
sizeof(status)) != 0)
continue;
tested++;
code = apex_status_code(status);
open = code >= 200 && code < 300;
if (open)
open_count++;
if (open && strcmp(paths[i], "/-/ready") == 0)
ready = 1;
if (open && strncmp(paths[i], "/api/v1/query", 13) == 0) {
query_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("prometheus-query",
resp, len);
}
if (!first)
mcp_buf_puts(&b, ",");
first = 0;
mcp_buf_puts(&b, "{\"path\":");
apex_json_str(&b, paths[i]);
mcp_buf_printf(&b, ",\"status\":%d,\"bytes\":%lu,\"open\":%s}",
code, (unsigned long)len,
open ? "true" : "false");
free(resp);
}
mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d,"
"\"ready\":%s,\"query_open\":%s,\"evidence\":",
tested, open_count, ready ? "true" : "false",
query_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("prometheus_api_probe", target, port, !query_open,
query_open
? "the PromQL API answers without authentication"
: "the PromQL API requires authentication", "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: "
@@ -7359,6 +7447,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_couchdb_probe },
{ "prometheus_api_probe",
"Query Prometheus without credentials: /-/ready and "
"/api/v1/query?query=up. A 2xx on the query API means anyone can read "
"every metric; the answer is saved as evidence. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 9090\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_prometheus_api_probe },
{ "dns_ns_consistency",
"Fetch NS records for a domain from the parent resolver and from its own "
"first nameserver (resolved to an address), then report names present on "
+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 = 246
EXPECTED_TOOLS = 250
GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(")
NET = ("http_once(", "tcp_connect_host(", "tcp_probe(", "apex_run(")
# Tools whose "target" argument filters local records; they never touch it.
+193 -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("246 tools registered", len(tools) == 246, len(tools))
check("250 tools registered", len(tools) == 250, 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"]) == 246)
check("http tools/list", len(listing["result"]["tools"]) == 250)
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
@@ -11273,6 +11273,196 @@ shutil.rmtree(af_root, ignore_errors=True)
shutil.rmtree(af_good_root, ignore_errors=True)
shutil.rmtree(cfg24_home, ignore_errors=True)
print("\n== Gitea, MinIO, Nextcloud and Prometheus ==\n")
gt_root = tempfile.mkdtemp(prefix="apex-gt-")
os.makedirs(os.path.join(gt_root, "etc", "gitea"))
gt_bad = os.path.join(gt_root, "etc", "gitea", "app.ini")
with open(gt_bad, "w") as f:
f.write("[server]\nPROTOCOL = http\n")
f.write("[security]\nINSTALL_LOCK = false\nSECRET_KEY =\n")
f.write("[service]\nREQUIRE_SIGNIN_VIEW = false\n")
os.chmod(gt_bad, 0o666)
gt_good_root = tempfile.mkdtemp(prefix="apex-gtg-")
os.makedirs(os.path.join(gt_good_root, "etc", "gitea"))
with open(os.path.join(gt_good_root, "etc", "gitea", "app.ini"),
"w") as f:
f.write("[server]\nPROTOCOL = https\n")
f.write("[security]\nINSTALL_LOCK = true\n")
f.write("SECRET_KEY = a-very-long-random-secret\n")
f.write("[service]\nREQUIRE_SIGNIN_VIEW = true\n")
mn_root = tempfile.mkdtemp(prefix="apex-mn-")
os.makedirs(os.path.join(mn_root, "etc", "default"))
mn_bad = os.path.join(mn_root, "etc", "default", "minio")
with open(mn_bad, "w") as f:
f.write('MINIO_ROOT_USER="minioadmin"\n')
f.write('MINIO_ROOT_PASSWORD="minioadmin"\n')
f.write('MINIO_BROWSER="on"\n')
f.write('MINIO_SERVER_URL="http://minio.example.test:9000"\n')
os.chmod(mn_bad, 0o666)
mn_good_root = tempfile.mkdtemp(prefix="apex-mng-")
os.makedirs(os.path.join(mn_good_root, "etc", "default"))
with open(os.path.join(mn_good_root, "etc", "default", "minio"), "w") as f:
f.write('MINIO_ROOT_USER="ops"\n')
f.write('MINIO_ROOT_PASSWORD="a-very-long-random-password"\n')
f.write('MINIO_BROWSER="off"\n')
f.write('MINIO_SERVER_URL="https://minio.example.test:9000"\n')
nc_root = tempfile.mkdtemp(prefix="apex-nc-")
os.makedirs(os.path.join(nc_root, "var", "www", "nextcloud", "config"))
nc_bad = os.path.join(nc_root, "var", "www", "nextcloud", "config",
"config.php")
with open(nc_bad, "w") as f:
f.write("<?php\n$CONFIG = array (\n")
f.write(" 'debug' => true,\n")
f.write(" 'trusted_domains' =>\n array (\n 0 => '*',\n ),\n")
f.write(" 'overwriteprotocol' => 'http',\n")
f.write(" 'datadirectory' => '/var/www/nextcloud/data',\n")
f.write(");\n")
os.chmod(nc_bad, 0o666)
nc_data = os.path.join(nc_root, "var", "www", "nextcloud", "data")
os.makedirs(nc_data)
os.chmod(nc_data, 0o777)
nc_good_root = tempfile.mkdtemp(prefix="apex-ncg-")
os.makedirs(os.path.join(nc_good_root, "var", "www", "nextcloud", "config"))
os.makedirs(os.path.join(nc_good_root, "var", "www", "nextcloud", "data"))
with open(os.path.join(nc_good_root, "var", "www", "nextcloud", "config",
"config.php"), "w") as f:
f.write("<?php\n$CONFIG = array (\n")
f.write(" 'debug' => false,\n")
f.write(" 'trusted_domains' =>\n array (\n 0 => "
"'cloud.example.test',\n ),\n")
f.write(" 'overwriteprotocol' => 'https',\n")
f.write(" 'datadirectory' => '/var/www/nextcloud/data',\n")
f.write(");\n")
class _PromHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/-/ready":
body = b"Prometheus Server is Ready."
self.send_response(200)
elif path == "/api/v1/query":
body = b'{"status":"success","data":{"resultType":"vector"}}'
self.send_response(200)
else:
body = b"not found"
self.send_response(404)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
class _PromAuthHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
body = b"Unauthorized"
self.send_response(401)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
prom_srv = http.server.HTTPServer(("127.0.0.1", 0), _PromHandler)
prom_port = prom_srv.server_address[1]
threading.Thread(target=prom_srv.serve_forever, daemon=True).start()
prom_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
_PromAuthHandler)
prom_auth_port = prom_auth_srv.server_address[1]
threading.Thread(target=prom_auth_srv.serve_forever, daemon=True).start()
cfg25_home = tempfile.mkdtemp(prefix="apex-cfg25-home-")
write_scope(cfg25_home, {"label": "cfg25", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(prom_port),
str(prom_auth_port)]})
res, _ = run([
call(1, "gitea_audit", root=gt_root),
call(2, "gitea_audit", root=gt_good_root),
call(3, "minio_audit", root=mn_root),
call(4, "minio_audit", root=mn_good_root),
call(5, "nextcloud_audit", root=nc_root),
call(6, "nextcloud_audit", root=nc_good_root),
call(7, "prometheus_api_probe", target="127.0.0.1", port=prom_port,
tls=False),
call(8, "prometheus_api_probe", target="127.0.0.1", port=prom_auth_port,
tls=False),
call(9, "prometheus_api_probe", target="198.51.100.9", port=9090),
call(10, "gitea_audit", root="/nonexistent-gt"),
call(11, "minio_audit", root="/nonexistent-mn"),
call(12, "nextcloud_audit", root="/nonexistent-nc"),
], home=cfg25_home)
by_id = {r.get("id"): r for r in res}
gt = json.loads(text(by_id[1]))
gt_kinds = {f["id"] for f in gt["findings"]}
check("gitea_audit flags HTTP, open install and an empty secret",
{"world-writable", "plain-http", "install-open", "default-secret",
"public-repos"} <= gt_kinds and gt["install_locked"] is False and
gt["secret_key"] is False, gt)
gt_good = json.loads(text(by_id[2]))
check("gitea_audit accepts a locked HTTPS instance",
gt_good["findings_count"] == 0 and gt_good["install_locked"] is True
and gt_good["plain_http"] is False, gt_good)
mn = json.loads(text(by_id[3]))
mn_kinds = {f["id"] for f in mn["findings"]}
check("minio_audit flags default root credentials and HTTP",
{"world-writable", "default-credentials", "browser-on",
"plain-http"} <= mn_kinds and
mn["default_credentials"] is True, mn)
mn_good = json.loads(text(by_id[4]))
check("minio_audit accepts strong credentials over HTTPS",
mn_good["findings_count"] == 0 and
mn_good["default_credentials"] is False and
mn_good["https"] is True, mn_good)
nc = json.loads(text(by_id[5]))
nc_kinds = {f["id"] for f in nc["findings"]}
check("nextcloud_audit flags debug, wildcard and writable data",
{"world-writable", "debug", "wildcard-trusted-domain", "no-https",
"writable-data"} <= nc_kinds and nc["debug"] is True and
nc["data_writable"] is True, nc)
nc_good = json.loads(text(by_id[6]))
check("nextcloud_audit accepts a hardened config",
nc_good["findings_count"] == 0 and nc_good["debug"] is False and
nc_good["https"] is True and nc_good["data_writable"] is False,
nc_good)
prom = json.loads(text(by_id[7]))
check("prometheus_api_probe finds an open query API",
prom["query_open"] is True and prom["open_count"] == 2 and
prom["ready"] is True and prom["evidence"] and
os.path.isfile(prom["evidence"]), prom)
prom_auth = json.loads(text(by_id[8]))
check("prometheus_api_probe reports a protected API",
prom_auth["query_open"] is False and
all(e["status"] == 401 for e in prom_auth["endpoints"]
if e["path"].startswith("/api")), prom_auth)
check("prometheus_api_probe refuses an out-of-scope target",
err(by_id[9]), text(by_id[9]))
check("gitea_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("minio_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("nextcloud_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
prom_srv.shutdown()
prom_srv.server_close()
prom_auth_srv.shutdown()
prom_auth_srv.server_close()
shutil.rmtree(gt_root, ignore_errors=True)
shutil.rmtree(gt_good_root, ignore_errors=True)
shutil.rmtree(mn_root, ignore_errors=True)
shutil.rmtree(mn_good_root, ignore_errors=True)
shutil.rmtree(nc_root, ignore_errors=True)
shutil.rmtree(nc_good_root, ignore_errors=True)
shutil.rmtree(cfg25_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -11287,6 +11477,7 @@ print("\n== esp32 tools ==")
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"})
esp_m, esp_s = pty.openpty()