apex-twin 1.52.0: Caddy, Traefik and autofs audits, CouchDB probe

Blue:
- caddy_audit: Caddyfile: a site on :80 or http://, auto_https off, tls
  internal and an admin API beyond localhost.
- traefik_audit: traefik.yml/yaml/toml: api insecure, an HTTP entry point
  without a redirect and no TLS section.
- autofs_audit: auto.master and auto.master.d plus the maps they reference:
  wildcard map keys, world-writable maps and --timeout=0.

Red:
- couchdb_probe: / and /_all_dbs without credentials; the database list is
  the decisive answer and is saved as evidence. The root welcome is reported
  but is public on protected servers too.

Tests with Caddy/Traefik/autofs trees and two CouchDB fixtures (open and 401
with a public welcome). 1084 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.52.0.
This commit is contained in:
lotherk committed 2026-11-22 12:11:51 +00:00
1 parent b221d26e35
commit d925e11b7b
9 files changed
+713 -15

No files matched your search

+16 -1
View File
@@ -8,7 +8,22 @@ 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.51.0 — 2026-11-23 — this change
## 1.52.0 — 2026-11-23 — this change
- **Caddy** (`caddy_audit`): `Caddyfile`: a site on `:80` or `http://`,
`auto_https off`, `tls internal` and an admin API beyond localhost.
- **Traefik** (`traefik_audit`): `traefik.yml`/`yaml`/`toml`:
`api: insecure: true`, an HTTP entry point without a redirect and no TLS
section.
- **autofs** (`autofs_audit`): `auto.master` and `auto.master.d` plus the
maps they reference: wildcard map keys, world-writable maps and
`--timeout=0`.
- **CouchDB** (`couchdb_probe`): `/` and `/_all_dbs` without credentials; the
database list is the decisive answer and is saved as evidence.
- Tests with Caddy/Traefik/autofs trees and two CouchDB HTTP fixtures (open
and 401 with a public welcome). 1084 checks. Coverage 83.4%.
## 1.51.0 — 2026-11-23 — b221d26
- **FreeRADIUS** (`freeradius_audit`): `clients.conf`, `radiusd.conf` and
`users`: a well-known shared secret, `require_message_authenticator = no`
+13 -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.
**242 tools · 1072 end-to-end checks · 340 fuzz cases · 83.3% line coverage · ~879 KiB**
**246 tools · 1084 end-to-end checks · 340 fuzz cases · 83.4% line coverage · ~883 KiB**
```
$ ./apex-twin --check
{"version":"1.51.0","tools":242,...,"scope":{"loaded":true,...}}
{"version":"1.52.0","tools":246,...,"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 (242)
## Tools (246)
### Scope and bookkeeping
@@ -210,6 +210,7 @@ uploads and secret-file reads. It does not execute anything.
| `etcd_api_probe` | `/version`, `/health`, `/v2/keys` without a token; 2xx is open access |
| `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 |
| `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 |
@@ -439,6 +440,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `freeradius_audit` | clients.conf/users: default secret, no message authenticator |
| `containerd_audit` | config.toml: TCP gRPC without TLS, unpinned sandbox image |
| `nats_audit` | nats-server.conf: no authorization/TLS, open monitoring port |
| `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 |
### ESP32
@@ -729,6 +733,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| registry | two unauthenticated GETs, catalog as evidence |
| freeradius/containerd/nats | config reads only; optional root prefix |
| 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 |
| USB audit | 200 devices, sysfs reads only |
---
@@ -740,7 +746,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1072 end-to-end checks
make test # version check + gate audit + 1084 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
@@ -865,7 +871,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
dns_soa_mname_check, hsts_audit,
tls_hostname_check, ftp_tls_probe,
zookeeper_4lw_probe, etcd_api_probe,
docker_registry_probe, consul_api_probe
docker_registry_probe, consul_api_probe,
couchdb_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,
@@ -908,7 +915,7 @@ examples/ scope.json
## Status
1.51.0. Built and run: 242 tools, 1072 checks, 340 fuzz cases and 83.3% line
1.52.0. Built and run: 246 tools, 1084 checks, 340 fuzz cases and 83.4% 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.51.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.52.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.
- **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
probe sends two unauthenticated GETs and saves the first answer as evidence.
- **Kafka, PowerDNS and Varnish audits read local files.** The registry probe
+4 -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.51.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.52.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),
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),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -70,7 +70,8 @@ ldap_client_audit, ssl_cert_audit, timesyncd_audit, resolv_conf_audit, journald_
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)
varnish_audit, freeradius_audit, containerd_audit, nats_audit, caddy_audit, traefik_audit,
autofs_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.51.0"
#define APEX_VERSION "1.52.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+391
View File
@@ -15366,6 +15366,379 @@ static void t_nats_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- caddy_audit */
static void t_caddy_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];
struct stat st;
char *copy;
char *save = NULL;
char *line;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int plain_http = 0;
int auto_https_off = 0;
int internal_tls = 0;
int admin_exposed = 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/caddy/Caddyfile", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read a Caddyfile");
return;
}
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"the Caddyfile is writable by anyone");
count++;
}
copy = strdup(text);
if (copy == NULL) {
mcp_buf_free(&findings);
mcp_reply_error(c, "out of memory");
return;
}
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s != '#' && *s != '\0') {
if (strncmp(s, ":80", 3) == 0 ||
strncmp(s, "http://", 7) == 0)
plain_http = 1;
if (strstr(s, "auto_https off") != NULL)
auto_https_off = 1;
if (strstr(s, "tls internal") != NULL)
internal_tls = 1;
if (strncmp(s, "admin ", 6) == 0) {
char *v = s + 6;
while (*v == ' ' || *v == '\t')
v++;
if (strncmp(v, "0.0.0.0", 7) == 0 || *v == ':')
admin_exposed = 1;
}
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
if (plain_http) {
add_finding(&findings, &first, "plain-http", "medium",
"a site is served over plain HTTP on port 80");
count++;
}
if (auto_https_off) {
add_finding(&findings, &first, "auto-https-off", "medium",
"automatic HTTPS is disabled");
count++;
}
if (internal_tls) {
add_finding(&findings, &first, "internal-tls", "low",
"a site uses Caddy's internal CA");
count++;
}
if (admin_exposed) {
add_finding(&findings, &first, "admin-exposed", "high",
"the admin API listens beyond localhost");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"plain_http\":%s,\"auto_https\":%s,"
"\"internal_tls\":%s,\"admin_local\":%s,"
"\"findings_count\":%d,\"findings\":[",
plain_http ? "true" : "false",
auto_https_off ? "false" : "true",
internal_tls ? "true" : "false",
admin_exposed ? "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);
}
/* ------------------------------------------------------------- traefik_audit */
static int traefik_tls_block(const char *text)
{
return strstr(text, "tls:") != NULL ||
strstr(text, "tls =") != NULL ||
strstr(text, "[entryPoints.websecure]") != NULL;
}
static void t_traefik_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/traefik/traefik.yml",
"/etc/traefik/traefik.yaml",
"/etc/traefik/traefik.toml", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int api_insecure = 0;
int no_redirect = 0;
int no_tls = 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 ((strstr(text, "insecure: true") != NULL ||
strstr(text, "insecure = true") != NULL) &&
strstr(text, "api:") != NULL)
api_insecure = 1;
if (strstr(text, "redirect") == NULL)
no_redirect = 1;
if (!traefik_tls_block(text))
no_tls = 1;
break;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Traefik configuration");
return;
}
if (api_insecure) {
add_finding(&findings, &first, "api-insecure", "high",
"the Traefik API is exposed insecurely");
count++;
}
if (no_redirect) {
add_finding(&findings, &first, "no-redirect", "medium",
"the HTTP entry point does not redirect to HTTPS");
count++;
}
if (no_tls) {
add_finding(&findings, &first, "no-tls", "medium",
"no TLS configuration is present");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"api_insecure\":%s,"
"\"redirect\":%s,\"tls\":%s,\"findings_count\":%d,"
"\"findings\":[",
files_read, api_insecure ? "true" : "false",
no_redirect ? "false" : "true",
no_tls ? "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);
}
/* -------------------------------------------------------------- autofs_audit */
static void autofs_scan_map(mcp_buf *findings, int *first, int *count,
const char *path, int *files, int *wildcard)
{
static char text[65536];
struct stat st;
char *copy;
char *save = NULL;
char *line;
if (read_text(path, text, sizeof(text)) <= 0)
return;
(*files)++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(findings, first, "writable-map", "high",
"%s is writable by anyone", path);
(*count)++;
}
copy = strdup(text);
if (copy == NULL)
return;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s == '*' && (s[1] == ' ' || s[1] == '\t')) {
if (!*wildcard) {
add_finding(findings, first, "wildcard-map",
"medium",
"%s maps every key with *", path);
(*count)++;
}
*wildcard = 1;
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
static void autofs_scan_master(mcp_buf *findings, int *first, int *count,
const char *root, const char *path,
int *files, int *wildcard, int *no_timeout)
{
static char text[65536];
struct stat st;
char *copy;
char *save = NULL;
char *line;
if (read_text(path, text, sizeof(text)) <= 0)
return;
(*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)++;
}
copy = strdup(text);
if (copy == NULL)
return;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
char mount[256];
char map[512];
char *tok;
char *rest;
while (*s == ' ' || *s == '\t')
s++;
if (*s == '#' || *s == '\0' || *s == '+') {
line = strtok_r(NULL, "\n", &save);
continue;
}
tok = strtok_r(s, " \t", &rest);
if (tok == NULL) {
line = strtok_r(NULL, "\n", &save);
continue;
}
snprintf(mount, sizeof(mount), "%.250s", tok);
tok = strtok_r(NULL, " \t", &rest);
if (tok == NULL) {
line = strtok_r(NULL, "\n", &save);
continue;
}
snprintf(map, sizeof(map), "%.500s", tok);
if (strstr(rest, "--timeout=0") != NULL)
*no_timeout = 1;
if (map[0] == '/') {
char mpath[1200];
struct stat mst;
snprintf(mpath, sizeof(mpath), "%.400s%s", root, map);
if (stat(mpath, &mst) == 0 && S_ISREG(mst.st_mode))
autofs_scan_map(findings, first, count, mpath,
files, wildcard);
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
static void t_autofs_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int wildcard = 0;
int no_timeout = 0;
DIR *d;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
snprintf(path, sizeof(path), "%s/etc/auto.master", root);
autofs_scan_master(&findings, &first, &count, root, path, &files,
&wildcard, &no_timeout);
snprintf(path, sizeof(path), "%s/etc/auto.master.d", root);
d = opendir(path);
if (d != NULL) {
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
char full[1200];
if (ent->d_name[0] == '.')
continue;
snprintf(full, sizeof(full), "%.900s/%.200s", path,
ent->d_name);
autofs_scan_master(&findings, &first, &count, root,
full, &files, &wildcard,
&no_timeout);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read an autofs master map");
return;
}
if (no_timeout) {
add_finding(&findings, &first, "no-timeout", "medium",
"an automount uses --timeout=0 and never unmounts");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"wildcard\":%s,"
"\"timeout\":%s,\"findings_count\":%d,\"findings\":[",
files, wildcard ? "true" : "false",
no_timeout ? "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);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -16215,6 +16588,24 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_nats_audit },
{ "caddy_audit",
"Parse a Caddyfile (root prefix): a site on :80 or http://, auto_https "
"off, tls internal and an admin API beyond localhost. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_caddy_audit },
{ "traefik_audit",
"Parse traefik.yml/yaml/toml (root prefix): api insecure, an HTTP entry "
"point without a redirect and a missing TLS section. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_traefik_audit },
{ "autofs_audit",
"Parse auto.master and auto.master.d (root prefix): wildcard map keys, "
"world-writable maps and --timeout=0. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_autofs_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+97
View File
@@ -6709,6 +6709,93 @@ static void t_consul_api_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ------------------------------------------------------------ couchdb_probe */
static void t_couchdb_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/", "/_all_dbs", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 5984);
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 databases_open = 0;
char *evidence = NULL;
int i;
(void)user;
if (target == NULL || *target == '\0') {
mcp_reply_error(c, "target is required");
return;
}
if (port <= 0 || port > 65535) {
mcp_reply_error(c, "port out of range");
return;
}
if (!gated(c, "couchdb_probe", target, port))
return;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port,
tls ? "true" : "false");
for (i = 0; paths[i] != NULL; i++) {
char status[256];
char *resp = NULL;
size_t len = 0;
int code;
int open;
int json = 0;
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 (resp != NULL && find_bytes(resp, len, "["))
json = 1;
if (open)
open_count++;
if (open && strcmp(paths[i], "/_all_dbs") == 0) {
databases_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("couchdb-databases",
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,"
"\"json_array\":%s}",
code, (unsigned long)len,
open ? "true" : "false", json ? "true" : "false");
free(resp);
}
mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d,"
"\"databases_open\":%s,\"evidence\":",
tested, open_count,
databases_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("couchdb_probe", target, port, !databases_open,
databases_open
? "the database list is readable without authentication"
: "the database list 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: "
@@ -7262,6 +7349,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_consul_api_probe },
{ "couchdb_probe",
"Query CouchDB without credentials: / and /_all_dbs. A 2xx on /_all_dbs "
"is an open database list; the answer is saved as evidence. The root "
"welcome is reported but is not proof on its own. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 5984\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_couchdb_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 = 242
EXPECTED_TOOLS = 246
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.
+187 -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("242 tools registered", len(tools) == 242, len(tools))
check("246 tools registered", len(tools) == 246, 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"]) == 242)
check("http tools/list", len(listing["result"]["tools"]) == 246)
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
@@ -11089,6 +11089,190 @@ shutil.rmtree(nt_root, ignore_errors=True)
shutil.rmtree(nt_good_root, ignore_errors=True)
shutil.rmtree(cfg23_home, ignore_errors=True)
print("\n== Caddy, Traefik, autofs and CouchDB ==\n")
cdy_root = tempfile.mkdtemp(prefix="apex-cdy-")
os.makedirs(os.path.join(cdy_root, "etc", "caddy"))
cdy_bad = os.path.join(cdy_root, "etc", "caddy", "Caddyfile")
with open(cdy_bad, "w") as f:
f.write("{\n")
f.write(" admin 0.0.0.0:2019\n")
f.write(" auto_https off\n")
f.write("}\n\n")
f.write(":80 {\n")
f.write(' respond "ok"\n')
f.write("}\n")
os.chmod(cdy_bad, 0o666)
cdy_good_root = tempfile.mkdtemp(prefix="apex-cdyg-")
os.makedirs(os.path.join(cdy_good_root, "etc", "caddy"))
with open(os.path.join(cdy_good_root, "etc", "caddy", "Caddyfile"),
"w") as f:
f.write("{\n admin 127.0.0.1:2019\n}\n\n")
f.write("example.test {\n reverse_proxy 127.0.0.1:8080\n}\n")
trf_root = tempfile.mkdtemp(prefix="apex-trf-")
os.makedirs(os.path.join(trf_root, "etc", "traefik"))
trf_bad = os.path.join(trf_root, "etc", "traefik", "traefik.yml")
with open(trf_bad, "w") as f:
f.write("api:\n insecure: true\n")
f.write("entryPoints:\n")
f.write(" web:\n address: \":80\"\n")
f.write(" websecure:\n address: \":443\"\n")
os.chmod(trf_bad, 0o666)
trf_good_root = tempfile.mkdtemp(prefix="apex-trfg-")
os.makedirs(os.path.join(trf_good_root, "etc", "traefik"))
with open(os.path.join(trf_good_root, "etc", "traefik", "traefik.yml"),
"w") as f:
f.write("api:\n insecure: false\n")
f.write("entryPoints:\n")
f.write(" web:\n address: \":80\"\n")
f.write(" http:\n redirections:\n entryPoint:\n")
f.write(" to: websecure\n scheme: https\n")
f.write(" websecure:\n address: \":443\"\n http:\n tls: {}\n")
af_root = tempfile.mkdtemp(prefix="apex-af-")
os.makedirs(os.path.join(af_root, "etc"))
af_bad = os.path.join(af_root, "etc", "auto.master")
with open(af_bad, "w") as f:
f.write("/home /etc/auto.home --timeout=0\n")
os.chmod(af_bad, 0o666)
with open(os.path.join(af_root, "etc", "auto.home"), "w") as f:
f.write("* -rw,sync server:/home/&\n")
af_good_root = tempfile.mkdtemp(prefix="apex-afg-")
os.makedirs(os.path.join(af_good_root, "etc"))
with open(os.path.join(af_good_root, "etc", "auto.master"), "w") as f:
f.write("/mnt /etc/auto.mnt --timeout=60\n")
with open(os.path.join(af_good_root, "etc", "auto.mnt"), "w") as f:
f.write("data -ro server:/data\n")
class _CouchHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
docs = {
"/": b'{"couchdb":"Welcome","version":"3.3.0"}',
"/_all_dbs": b'["_users","app"]',
}
body = docs.get(path, b'{"error":"not_found"}')
code = 200 if path in docs else 404
self.send_response(code)
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 _CouchAuthHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/":
body = b'{"couchdb":"Welcome","version":"3.3.0"}'
self.send_response(200)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
return
body = b'{"error":"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
couch_srv = http.server.HTTPServer(("127.0.0.1", 0), _CouchHandler)
couch_port = couch_srv.server_address[1]
threading.Thread(target=couch_srv.serve_forever, daemon=True).start()
couch_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
_CouchAuthHandler)
couch_auth_port = couch_auth_srv.server_address[1]
threading.Thread(target=couch_auth_srv.serve_forever, daemon=True).start()
cfg24_home = tempfile.mkdtemp(prefix="apex-cfg24-home-")
write_scope(cfg24_home, {"label": "cfg24", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(couch_port),
str(couch_auth_port)]})
res, _ = run([
call(1, "caddy_audit", root=cdy_root),
call(2, "caddy_audit", root=cdy_good_root),
call(3, "traefik_audit", root=trf_root),
call(4, "traefik_audit", root=trf_good_root),
call(5, "autofs_audit", root=af_root),
call(6, "autofs_audit", root=af_good_root),
call(7, "couchdb_probe", target="127.0.0.1", port=couch_port,
tls=False),
call(8, "couchdb_probe", target="127.0.0.1", port=couch_auth_port,
tls=False),
call(9, "couchdb_probe", target="198.51.100.9", port=5984),
call(10, "caddy_audit", root="/nonexistent-cdy"),
call(11, "traefik_audit", root="/nonexistent-trf"),
call(12, "autofs_audit", root="/nonexistent-af"),
], home=cfg24_home)
by_id = {r.get("id"): r for r in res}
cdy = json.loads(text(by_id[1]))
cdy_kinds = {f["id"] for f in cdy["findings"]}
check("caddy_audit flags port 80, auto_https off and the admin API",
{"world-writable", "plain-http", "auto-https-off",
"admin-exposed"} <= cdy_kinds and cdy["plain_http"] is True and
cdy["admin_local"] is False, cdy)
cdy_good = json.loads(text(by_id[2]))
check("caddy_audit accepts HTTPS with a local admin",
cdy_good["findings_count"] == 0 and
cdy_good["plain_http"] is False and cdy_good["admin_local"] is True,
cdy_good)
trf = json.loads(text(by_id[3]))
trf_kinds = {f["id"] for f in trf["findings"]}
check("traefik_audit flags api insecure, no redirect and no TLS",
{"world-writable", "api-insecure", "no-redirect", "no-tls"} <=
trf_kinds and trf["api_insecure"] is True, trf)
trf_good = json.loads(text(by_id[4]))
check("traefik_audit accepts a redirecting TLS setup",
trf_good["findings_count"] == 0 and trf_good["redirect"] is True and
trf_good["tls"] is True, trf_good)
af = json.loads(text(by_id[5]))
af_kinds = {f["id"] for f in af["findings"]}
check("autofs_audit flags a wildcard map and no timeout",
{"world-writable", "wildcard-map", "no-timeout"} <= af_kinds and
af["wildcard"] is True and af["timeout"] is False, af)
af_good = json.loads(text(by_id[6]))
check("autofs_audit accepts a scoped map",
af_good["findings_count"] == 0 and af_good["wildcard"] is False and
af_good["timeout"] is True, af_good)
couch = json.loads(text(by_id[7]))
check("couchdb_probe finds the open database list",
couch["databases_open"] is True and couch["open_count"] == 2 and
couch["evidence"] and os.path.isfile(couch["evidence"]), couch)
couch_auth = json.loads(text(by_id[8]))
check("couchdb_probe reports a protected database list",
couch_auth["databases_open"] is False and
all(e["status"] == 401 for e in couch_auth["endpoints"]
if e["path"] == "/_all_dbs"), couch_auth)
check("couchdb_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("caddy_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("traefik_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("autofs_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
couch_srv.shutdown()
couch_srv.server_close()
couch_auth_srv.shutdown()
couch_auth_srv.server_close()
shutil.rmtree(cdy_root, ignore_errors=True)
shutil.rmtree(cdy_good_root, ignore_errors=True)
shutil.rmtree(trf_root, ignore_errors=True)
shutil.rmtree(trf_good_root, ignore_errors=True)
shutil.rmtree(af_root, ignore_errors=True)
shutil.rmtree(af_good_root, ignore_errors=True)
shutil.rmtree(cfg24_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -11102,6 +11286,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()