apex-twin 1.93.0: seccomp and systemd socket audits, Solr probe

Three new tools: seccomp_audit and systemd_socket_audit (blue) and
solr_probe (red).

seccomp_audit reads unit files and /etc/seccomp/*.json under the root
prefix and flags an empty SystemCallFilter= (present but removes nothing),
a filter whose tokens are all "~" denials (the allowlist is the whole
syscall table), a root service with NoNewPrivileges=no or without the
setting at all, and a profile with SCMP_ACT_ALLOW or no defaultAction.

systemd_socket_audit reads .socket units: ListenStream on 0.0.0.0, [::]
or :::, a SocketMode with the world bit, Accept=yes without
MaxConnections= and a world-writable unit.

solr_probe asks /solr/, /solr/admin/cores?action=STATUS and
/solr/admin/info/system on 8983 without credentials; a 2xx with core
entries means the index inventory is public and the body becomes
evidence.

Evidence: make test 1493/1493, test-asan 1493/1493, analyze 0 warnings,
240 fuzz cases without a sanitizer report, release-check exit 0 (366 s)
including distcheck from the tarball, coverage 85.1% (README updated),
fresh clone of the previous tree green. The red proof for both blue
audits was run (check went red, then rolled back).
This commit is contained in:
lotherk committed 2026-11-23 16:31:26 +00:00
1 parent 997280b3d2
commit 369915ae06
9 files changed
+835 -11

No files matched your search

+17
View File
@@ -1,5 +1,22 @@
# Changelog
## 1.93.0 - 2026-11-24 - this change
- **seccomp** (`seccomp_audit`): unit files and `/etc/seccomp` profiles under
the root prefix: an empty `SystemCallFilter=` (present but removes nothing),
a filter whose every token is a `~` denial (the allowlist is the whole
syscall table), a root service that sets `NoNewPrivileges=no` or omits it,
a profile with `"defaultAction":"SCMP_ACT_ALLOW"` or no `defaultAction` at
all, and a world-writable unit. Read-only.
- **systemd sockets** (`systemd_socket_audit`): `.socket` units: a
`ListenStream=` on `0.0.0.0`, `[::]` or bare `:::`, a `SocketMode=` with the
world bit (any local user connects), `Accept=yes` without `MaxConnections=`
(one process per connection, no ceiling) and a world-writable unit.
- **Solr** (`solr_probe`): `/solr/`, `/solr/admin/cores?action=STATUS` and
`/solr/admin/info/system` on 8983 without credentials. A 2xx with core
entries means the whole index inventory is public; the body is saved as
evidence and the audit log records the open admin API.
## 1.92.0 - 2026-11-24 - this change
- **fluent-bit** (`fluentbit_audit`): `fluent-bit.conf` and the fragments
+8 -4
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.
**400 tools · 1485 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
**403 tools · 1493 end-to-end checks · 240 fuzz cases · 85.1% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.92.0","tools":400,...,"scope":{"loaded":true,...}}
{"version":"1.93.0","tools":403,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -244,6 +244,7 @@ uploads and secret-file reads. It does not execute anything.
| `loki_probe` | `/loki/api/v1/labels` on 3100 without auth; label names as evidence |
| `tempo_probe` | `/api/search/tags` on 3200 without auth; tag names as evidence |
| `jaeger_probe` | `/api/services` on 16686 without auth; service list as evidence |
| `solr_probe` | `/solr/admin/cores` on 8983 without auth; core list as evidence |
| `jupyter_probe` | `/api/kernels` on 8888 without a token; sessions as evidence |
| `jira_probe` | `/rest/api/2/project` on 8080 without auth; project list as evidence |
| `ollama_probe` | `/api/tags` on 11434 without auth; pulled model list as evidence |
@@ -596,6 +597,8 @@ does.
| `otel_collector_audit` | exporters without tls, debug exporter, zpages/pprof, writable config |
| `fluentbit_audit` | remote output without `tls On`, HTTP on any interface, debug level, writable config |
| `vector_audit` | source on `0.0.0.0`, sink without tls, GraphQL API beyond loopback, writable config |
| `seccomp_audit` | empty or only-negating `SystemCallFilter`, root service without `NoNewPrivileges`, `SCMP_ACT_ALLOW` profile |
| `systemd_socket_audit` | `ListenStream` on every interface, world `SocketMode`, `Accept=yes` without `MaxConnections` |
| `tripwire_audit` | twcfg.txt: no site key, loose site key, no MAILTO |
| `networkd_audit` | systemd-networkd: [Match] without Name/MAC/Type, DHCP DNS without UseDNS=no, public resolver |
| `namespace_audit` | namespace.conf: no /tmp entry, empty/unknown method, `~` user list |
@@ -1113,7 +1116,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
systemd_timer_audit, yara_audit,
suricata_audit, icinga2_audit, falco_audit,
promtail_audit, otel_collector_audit,
fluentbit_audit, vector_audit)
fluentbit_audit, vector_audit, seccomp_audit,
systemd_socket_audit)
src/tools_esp.c esp_info, esp_monitor, esp_read_flash, esp_flash,
esp_partition_table, esp_nvs_parse, firmware_scan,
esp_app_info, esp_image_verify
@@ -1152,7 +1156,7 @@ examples/ scope.json
## Status
1.92.0. Built and run: 400 tools, 1485 checks, 240 fuzz cases and 85.0% line
1.93.0. Built and run: 403 tools, 1493 checks, 240 fuzz cases and 85.1% line
coverage. The loop closes: a probe captures the exchange as a pair, a finding
points at it, `finding_update` gives it a state, an asset records the host it
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
+1 -1
View File
@@ -9,7 +9,7 @@ problem.
The supported line is the one printed by `apex-twin --version` for the tree you
built; this document ships with that same tree. At the time of writing the line
is **1.92.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.93.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
line. The 1.0 line promises that the on-disk JSON formats for findings, assets
and traffic only gain fields, so state stays readable; older builds are still
rebuilt rather than patched in place.
+3 -2
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.92.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.93.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -45,7 +45,7 @@ graphql_probe, docker_api_probe, elasticsearch_probe, imap_probe, pop3_probe,
sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe,
dns_ns_consistency, dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nomad_probe, coredns_probe, openbmc_probe, schema_registry_probe, loki_probe, tempo_probe, jaeger_probe,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nomad_probe, coredns_probe, openbmc_probe, schema_registry_probe, loki_probe, tempo_probe, jaeger_probe, solr_probe,
nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
@@ -98,6 +98,7 @@ dhclient_audit, journal_upload_audit, fwupd_audit,
smartd_audit, tlog_audit, abrt_audit, freshclam_audit, tripwire_audit,
fapolicyd_audit, systemd_timer_audit, yara_audit, suricata_audit,
promtail_audit, otel_collector_audit, fluentbit_audit, vector_audit,
seccomp_audit, systemd_socket_audit,
icinga2_audit, falco_audit,
php_fpm_audit, uwsgi_audit, lighttpd_audit)
and ESP32 board tools (esp_info, esp_monitor,
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.92.0"
#define APEX_VERSION "1.93.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+525
View File
@@ -30732,6 +30732,516 @@ static void t_vector_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* ------------------------------------------------------------- seccomp_audit */
/* Two places describe a syscall filter: unit files (SystemCallFilter=) and
* seccomp profile JSON (defaultAction). A filter that is present but empty, or
* only names a negation such as ~@privileged, allows every syscall it does not
* remove; a root service without NoNewPrivileges keeps setuid escalation open. */
typedef struct {
mcp_buf *b;
int first;
int count;
int units;
int profiles;
int filtered;
} sc_ctx;
static void sc_finding(sc_ctx *ctx, const char *path, const char *kind,
const char *severity, const char *detail)
{
if (ctx->count >= 100)
return;
if (!ctx->first)
mcp_buf_puts(ctx->b, ",");
ctx->first = 0;
ctx->count++;
mcp_buf_puts(ctx->b, "{\"path\":");
apex_json_str(ctx->b, path);
mcp_buf_puts(ctx->b, ",\"kind\":");
apex_json_str(ctx->b, kind);
mcp_buf_puts(ctx->b, ",\"severity\":");
apex_json_str(ctx->b, severity);
mcp_buf_puts(ctx->b, ",\"detail\":");
apex_json_str(ctx->b, detail);
mcp_buf_puts(ctx->b, "}");
}
/* Value of one "Key=" line inside a unit, first match, right-trimmed. */
static int sc_unit_value(const char *text, const char *key, char *out, size_t n)
{
size_t kl = strlen(key);
const char *p = text;
while (p != NULL && *p != '\0') {
const char *eol = strchr(p, '\n');
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
if (len > kl && strncmp(p, key, kl) == 0 && p[kl] == '=') {
size_t vl = len - kl - 1;
while (vl > 0 && (p[kl + 1 + vl - 1] == ' ' ||
p[kl + 1 + vl - 1] == '\t' ||
p[kl + 1 + vl - 1] == '\r'))
vl--;
if (vl >= n)
vl = n - 1;
memcpy(out, p + kl + 1, vl);
out[vl] = '\0';
return 1;
}
p = eol != NULL ? eol + 1 : NULL;
}
return 0;
}
/* Does name end with suffix? */
static int sc_unit_suffix(const char *name)
{
static const char *suffixes[] = { ".service", ".socket", ".timer", NULL };
size_t nl = strlen(name);
int i;
for (i = 0; suffixes[i] != NULL; i++) {
size_t sl = strlen(suffixes[i]);
if (nl > sl && strcmp(name + nl - sl, suffixes[i]) == 0)
return 1;
}
return 0;
}
/* Does path end with suffix? */
static int unit_has_suffix(const char *path, const char *suffix)
{
size_t pl = strlen(path);
size_t sl = strlen(suffix);
return pl > sl && strcmp(path + pl - sl, suffix) == 0;
}
/* A filter that only denies names leaves every other syscall allowed. A bare
* @group is an allowlist; only a leading ~ turns a token into a denial. */
static int sc_filter_is_negative_only(const char *value)
{
const char *p = value;
int seen = 0;
while (*p != '\0') {
while (*p == ' ' || *p == '\t')
p++;
if (*p == '\0')
break;
if (*p != '~')
return 0;
seen = 1;
p++;
if (*p == '\0' || *p == ' ' || *p == '\t')
return 0;
while (*p != '\0' && *p != ' ' && *p != '\t')
p++;
}
return seen;
}
static void sc_scan_unit(sc_ctx *ctx, const char *path)
{
static char text[65536];
struct stat st;
char filter[512];
char nnp[64];
char user[128];
int is_service;
if (stat(path, &st) != 0 || !S_ISREG(st.st_mode))
return;
if (ctx->units >= 2000)
return;
is_service = unit_has_suffix(path, ".service");
ctx->units++;
if (read_text(path, text, sizeof(text)) < 0)
return;
if ((st.st_mode & 0002) != 0)
sc_finding(ctx, path, "world-writable-unit", "high",
"unit file is writable by anyone");
filter[0] = '\0';
if (sc_unit_value(text, "SystemCallFilter", filter, sizeof(filter))) {
ctx->filtered++;
if (filter[0] == '\0')
sc_finding(ctx, path, "empty-syscall-filter", "medium",
"SystemCallFilter= is set but empty");
else if (sc_filter_is_negative_only(filter))
sc_finding(ctx, path, "negative-only-filter", "medium",
"the filter only denies a set; every other syscall stays allowed");
}
if (!is_service)
return;
user[0] = '\0';
sc_unit_value(text, "User", user, sizeof(user));
nnp[0] = '\0';
if (sc_unit_value(text, "NoNewPrivileges", nnp, sizeof(nnp))) {
if (strcasecmp(nnp, "yes") != 0 && strcasecmp(nnp, "true") != 0 &&
strcmp(nnp, "1") != 0)
sc_finding(ctx, path, "no-new-privileges-off", "medium",
"NoNewPrivileges= is explicitly off");
} else if (user[0] == '\0' || strcmp(user, "root") == 0) {
sc_finding(ctx, path, "no-new-privileges-missing", "low",
"root service without NoNewPrivileges");
}
}
static void sc_scan_dir(sc_ctx *ctx, const char *dir)
{
DIR *d = opendir(dir);
struct dirent *ent;
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL && ctx->units < 2000) {
char path[1024];
struct stat st;
size_t dl = strlen(dir);
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (dl + nl + 2 > sizeof(path))
continue;
memcpy(path, dir, dl);
path[dl] = '/';
memcpy(path + dl + 1, ent->d_name, nl + 1);
if (lstat(path, &st) != 0)
continue;
if (!S_ISREG(st.st_mode))
continue;
if (strstr(path, ".wants/") != NULL ||
strstr(path, ".requires/") != NULL)
continue;
if (!sc_unit_suffix(ent->d_name))
continue;
sc_scan_unit(ctx, path);
}
closedir(d);
}
/* A profile with "defaultAction":"SCMP_ACT_ALLOW" or one without any
* defaultAction allows everything it does not name. */
static void sc_scan_profile(sc_ctx *ctx, const char *path)
{
static char text[65536];
char action[40];
const char *def;
const char *syscalls;
if (read_text(path, text, sizeof(text)) <= 0)
return;
ctx->profiles++;
def = strstr(text, "\"defaultAction\"");
if (def == NULL) {
sc_finding(ctx, path, "no-default-action", "high",
"profile has no defaultAction; every syscall is allowed");
return;
}
def += strlen("\"defaultAction\"");
while (*def == ' ' || *def == '\t' || *def == ':')
def++;
if (*def == '"') {
const char *end = strchr(def + 1, '"');
if (end != NULL) {
size_t len = (size_t)(end - def - 1);
if (len >= sizeof(action))
len = sizeof(action) - 1;
memcpy(action, def + 1, len);
action[len] = '\0';
if (strcasecmp(action, "SCMP_ACT_ALLOW") == 0)
sc_finding(ctx, path, "default-allow", "high",
"defaultAction is SCMP_ACT_ALLOW");
}
}
syscalls = strstr(text, "\"syscalls\"");
if (syscalls == NULL)
sc_finding(ctx, path, "no-syscalls", "medium",
"profile names no syscall list");
}
static void t_seccomp_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char base[512];
char path[1024];
size_t bl;
mcp_buf b;
mcp_buf findings;
sc_ctx ctx;
DIR *d;
struct dirent *ent;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) >= sizeof(base) - 2) {
mcp_reply_error(c, "root path too long");
return;
}
snprintf(base, sizeof(base), "%s", root);
bl = strlen(base);
while (bl > 0 && base[bl - 1] == '/')
base[--bl] = '\0';
mcp_buf_init(&findings);
memset(&ctx, 0, sizeof(ctx));
ctx.b = &findings;
ctx.first = 1;
snprintf(path, sizeof(path), "%s/etc/systemd/system", base);
sc_scan_dir(&ctx, path);
snprintf(path, sizeof(path), "%s/usr/lib/systemd/system", base);
sc_scan_dir(&ctx, path);
snprintf(path, sizeof(path), "%s/etc/seccomp", base);
d = opendir(path);
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char file[1200];
size_t nl = strlen(ent->d_name);
size_t pl = strlen(path);
if (ent->d_name[0] == '.' || nl < 6)
continue;
if (strcmp(ent->d_name + nl - 5, ".json") != 0)
continue;
if (pl + nl + 2 > sizeof(file))
continue;
memcpy(file, path, pl);
file[pl] = '/';
memcpy(file + pl + 1, ent->d_name, nl + 1);
sc_scan_profile(&ctx, file);
}
closedir(d);
}
if (ctx.count == 0) {
if (ctx.units == 0 && ctx.profiles == 0)
sc_finding(&ctx, path, "no-config", "info",
"no unit files or seccomp profiles found");
else
sc_finding(&ctx, path, "no-findings", "info",
"units and profiles carry no weak syscall filter");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, base);
mcp_buf_printf(&b, ",\"units\":%d,\"profiles\":%d,\"filtered_units\":%d,"
"\"findings_count\":%d,\"findings\":[",
ctx.units, ctx.profiles, ctx.filtered, ctx.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);
}
/* -------------------------------------------------------- systemd_socket_audit */
/* A .socket unit is the listening half of a service. ListenStream=0.0.0.0:PORT
* or [::]:PORT publishes it on every interface, SocketMode=0666 lets any local
* user connect, and Accept=yes without MaxConnections= starts one process per
* connection with no ceiling. */
typedef struct {
mcp_buf *b;
int first;
int count;
int sockets;
int listening;
int wide;
} ss_ctx;
static void ss_finding(ss_ctx *ctx, const char *path, const char *kind,
const char *severity, const char *detail)
{
if (ctx->count >= 100)
return;
if (!ctx->first)
mcp_buf_puts(ctx->b, ",");
ctx->first = 0;
ctx->count++;
mcp_buf_puts(ctx->b, "{\"path\":");
apex_json_str(ctx->b, path);
mcp_buf_puts(ctx->b, ",\"kind\":");
apex_json_str(ctx->b, kind);
mcp_buf_puts(ctx->b, ",\"severity\":");
apex_json_str(ctx->b, severity);
mcp_buf_puts(ctx->b, ",\"detail\":");
apex_json_str(ctx->b, detail);
mcp_buf_puts(ctx->b, "}");
}
/* Is addr one that listens on every interface? */
static int ss_addr_is_wide(const char *addr)
{
if (strncmp(addr, "0.0.0.0:", 8) == 0)
return 1;
if (strncmp(addr, "[::]:", 5) == 0)
return 1;
if (strncmp(addr, ":::", 3) == 0)
return 1;
if (strcmp(addr, "0.0.0.0") == 0 || strcmp(addr, "[::]") == 0)
return 1;
return 0;
}
static void ss_scan_file(ss_ctx *ctx, const char *path)
{
static char text[65536];
struct stat st;
char mode[32];
char accept[16];
char maxconn[32];
int has_stream = 0;
const char *p;
if (stat(path, &st) != 0 || !S_ISREG(st.st_mode))
return;
if (ctx->sockets >= 2000)
return;
ctx->sockets++;
if (read_text(path, text, sizeof(text)) < 0)
return;
if ((st.st_mode & 0002) != 0)
ss_finding(ctx, path, "world-writable-unit", "high",
"socket unit is writable by anyone");
p = text;
while (p != NULL && *p != '\0') {
const char *eol = strchr(p, '\n');
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
char line[1024];
if (len < sizeof(line)) {
memcpy(line, p, len);
line[len] = '\0';
if (strncmp(line, "ListenStream", 12) == 0) {
const char *v = line + 12;
while (*v == '=' || *v == ' ' || *v == '\t')
v++;
has_stream = 1;
ctx->listening++;
if (ss_addr_is_wide(v)) {
ctx->wide++;
ss_finding(ctx, path, "listen-all-interfaces",
"medium",
"ListenStream binds every interface");
}
}
}
p = eol != NULL ? eol + 1 : NULL;
}
if (!has_stream)
return;
mode[0] = '\0';
if (sc_unit_value(text, "SocketMode", mode, sizeof(mode))) {
unsigned long m = strtoul(mode, NULL, 8);
if ((m & 0002) != 0)
ss_finding(ctx, path, "socket-mode-world", "high",
"SocketMode lets any local user connect");
}
accept[0] = '\0';
if (sc_unit_value(text, "Accept", accept, sizeof(accept)) &&
(strcasecmp(accept, "yes") == 0 || strcmp(accept, "1") == 0)) {
maxconn[0] = '\0';
if (!sc_unit_value(text, "MaxConnections", maxconn,
sizeof(maxconn)))
ss_finding(ctx, path, "accept-no-max", "medium",
"Accept=yes without MaxConnections starts one process per connection");
}
}
static void ss_scan_dir(ss_ctx *ctx, const char *dir)
{
DIR *d = opendir(dir);
struct dirent *ent;
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL && ctx->sockets < 2000) {
char path[1024];
struct stat st;
size_t dl = strlen(dir);
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (dl + nl + 2 > sizeof(path))
continue;
memcpy(path, dir, dl);
path[dl] = '/';
memcpy(path + dl + 1, ent->d_name, nl + 1);
if (lstat(path, &st) != 0 || !S_ISREG(st.st_mode))
continue;
if (strstr(path, ".wants/") != NULL ||
strstr(path, ".requires/") != NULL)
continue;
if (!unit_has_suffix(ent->d_name, ".socket"))
continue;
ss_scan_file(ctx, path);
}
closedir(d);
}
static void t_systemd_socket_audit(mcp_conn *c, const mcp_json *args,
void *user)
{
const char *root = mcp_arg_string(args, "root");
char base[512];
char path[1024];
size_t bl;
mcp_buf b;
mcp_buf findings;
ss_ctx ctx;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) >= sizeof(base) - 2) {
mcp_reply_error(c, "root path too long");
return;
}
snprintf(base, sizeof(base), "%s", root);
bl = strlen(base);
while (bl > 0 && base[bl - 1] == '/')
base[--bl] = '\0';
mcp_buf_init(&findings);
memset(&ctx, 0, sizeof(ctx));
ctx.b = &findings;
ctx.first = 1;
snprintf(path, sizeof(path), "%s/etc/systemd/system", base);
ss_scan_dir(&ctx, path);
snprintf(path, sizeof(path), "%s/usr/lib/systemd/system", base);
ss_scan_dir(&ctx, path);
if (ctx.count == 0) {
if (ctx.sockets == 0)
ss_finding(&ctx, path, "no-config", "info",
"no socket units found");
else
ss_finding(&ctx, path, "no-findings", "info",
"socket units do not publish wide or unguarded endpoints");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, base);
mcp_buf_printf(&b, ",\"sockets\":%d,\"listening\":%d,\"wide\":%d,"
"\"findings_count\":%d,\"findings\":[",
ctx.sockets, ctx.listening, ctx.wide, ctx.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, "
@@ -32419,6 +32929,21 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_vector_audit },
{ "seccomp_audit",
"Parse systemd units and /etc/seccomp profiles (root prefix): an empty "
"or only-negating SystemCallFilter, a root service without "
"NoNewPrivileges, a profile whose defaultAction is SCMP_ACT_ALLOW, and "
"a world-writable unit. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_seccomp_audit },
{ "systemd_socket_audit",
"Parse .socket units (root prefix): ListenStream on 0.0.0.0 or [::], a "
"SocketMode that lets anyone connect, Accept=yes without "
"MaxConnections, and a world-writable unit. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_systemd_socket_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+99
View File
@@ -10370,6 +10370,95 @@ static void t_jaeger_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* -------------------------------------------------------------- solr_probe */
/* Solr on 8983 protects nothing by default. /solr/ answers with the admin UI
* and /solr/admin/cores?action=STATUS lists every core; a 2xx with core
* entries means the index inventory is public and the body is saved as
* evidence. The wt=json parameter is set so the answer stays parseable. */
static void t_solr_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/solr/",
"/solr/admin/cores?action=STATUS&wt=json",
"/solr/admin/info/system?wt=json", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 8983);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(8983));
mcp_buf b;
int first = 1;
int tested = 0;
int open_count = 0;
int cores_open = 0;
int core_count = 0;
char *evidence = NULL;
int i;
(void)user;
if (target == NULL || *target == '\0') {
mcp_reply_error(c, "target is required");
return;
}
if (port <= 0 || port > 65535) {
mcp_reply_error(c, "port out of range");
return;
}
if (!gated(c, "solr_probe", target, port))
return;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port,
tls ? "true" : "false");
for (i = 0; paths[i] != NULL; i++) {
char status[256];
char *resp = NULL;
size_t len = 0;
int code;
status[0] = '\0';
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
8000, &resp, &len, status,
sizeof(status)) != 0)
continue;
tested++;
code = apex_status_code(status);
if (code >= 200 && code < 300) {
open_count++;
if (strstr(paths[i], "action=STATUS") != NULL &&
resp != NULL && strstr(resp, "\"status\"") != NULL) {
cores_open = 1;
core_count = count_needle(resp, "\"name\"");
if (evidence == NULL)
evidence = apex_evidence_save(
"open-solr-cores", resp, len);
}
}
if (!first)
mcp_buf_puts(&b, ",");
first = 0;
mcp_buf_puts(&b, "{\"path\":");
apex_json_str(&b, paths[i]);
mcp_buf_printf(&b, ",\"status\":%d,\"bytes\":%zu}", code, len);
free(resp);
}
mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d,"
"\"cores_open\":%s,\"core_count\":%d,\"evidence\":",
tested, open_count, cores_open ? "true" : "false",
core_count);
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
mcp_reply_json(c, b.p);
if (cores_open)
apex_audit("solr_probe", target, port, 1,
"open Solr admin API: core list readable without "
"credentials", "HTTP GET /solr/admin/cores");
free(evidence);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_RED[] = {
{ "vuln_check",
"Non-destructive verification of exposed artifacts on one web target: "
@@ -11269,6 +11358,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_coredns_probe },
{ "solr_probe",
"Get /solr/ and /solr/admin/cores?action=STATUS without credentials on "
"8983. A 2xx with core entries means the whole index inventory is "
"public; the body is saved as evidence.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 8983\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_solr_probe },
{ "nomad_probe",
"Get /v1/agent/self, /v1/jobs and /v1/nodes without a token on 4646. "
"A 2xx on the job list means the whole Nomad job inventory is public "
+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 = 400
EXPECTED_TOOLS = 403
GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(")
# Handlers may hand argv to a shared runner instead of calling the gate
# themselves. That runner has to call the gate; both halves are checked
+180 -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("400 tools registered", len(tools) == 400, len(tools))
check("403 tools registered", len(tools) == 403, 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"]) == 400)
check("http tools/list", len(listing["result"]["tools"]) == 403)
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
@@ -18151,6 +18151,184 @@ for d in (fb_root, fb_good_root, fb_empty_root, vec_root, vec_good_root,
vec_empty_root, cfg63_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.93.0: seccomp and systemd socket audits plus the Solr probe ---
print("\n== seccomp, systemd sockets and Solr ==")
sc_root = tempfile.mkdtemp(prefix="apex-sc-")
os.makedirs(os.path.join(sc_root, "etc", "systemd", "system"))
os.makedirs(os.path.join(sc_root, "etc", "seccomp"))
with open(os.path.join(sc_root, "etc", "systemd", "system", "loud.service"),
"w") as f:
f.write("[Service]\n")
f.write("ExecStart=/usr/local/bin/loud\n")
f.write("SystemCallFilter=~@privileged\n")
sc_sc = os.path.join(sc_root, "etc", "systemd", "system", "loud.service")
os.chmod(sc_sc, 0o666)
with open(os.path.join(sc_root, "etc", "systemd", "system", "open.service"),
"w") as f:
f.write("[Service]\n")
f.write("ExecStart=/usr/local/bin/open\n")
f.write("SystemCallFilter=\n")
f.write("User=root\n")
f.write("NoNewPrivileges=no\n")
with open(os.path.join(sc_root, "etc", "seccomp", "loose.json"), "w") as f:
f.write('{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[]}\n')
with open(os.path.join(sc_root, "etc", "seccomp", "bare.json"), "w") as f:
f.write('{"architectures":["SCMP_ARCH_X86_64"]}\n')
sc_good_root = tempfile.mkdtemp(prefix="apex-scg-")
os.makedirs(os.path.join(sc_good_root, "etc", "systemd", "system"))
os.makedirs(os.path.join(sc_good_root, "etc", "seccomp"))
with open(os.path.join(sc_good_root, "etc", "systemd", "system",
"strict.service"), "w") as f:
f.write("[Service]\n")
f.write("ExecStart=/usr/local/bin/strict\n")
f.write("SystemCallFilter=@system-service\n")
f.write("NoNewPrivileges=yes\n")
f.write("User=strict\n")
with open(os.path.join(sc_good_root, "etc", "seccomp", "strict.json"),
"w") as f:
f.write('{"defaultAction":"SCMP_ACT_ERRNO","syscalls":'
'[{"names":["read"],"action":"SCMP_ACT_ALLOW"}]}\n')
ss_root = tempfile.mkdtemp(prefix="apex-ss-")
os.makedirs(os.path.join(ss_root, "etc", "systemd", "system"))
with open(os.path.join(ss_root, "etc", "systemd", "system", "wide.socket"),
"w") as f:
f.write("[Socket]\n")
f.write("ListenStream=0.0.0.0:8080\n")
f.write("SocketMode=0666\n")
f.write("Accept=yes\n")
with open(os.path.join(ss_root, "etc", "systemd", "system", "v6.socket"),
"w") as f:
f.write("[Socket]\n")
f.write("ListenStream=[::]:9090\n")
f.write("Accept=no\n")
ss_good_root = tempfile.mkdtemp(prefix="apex-ssg-")
os.makedirs(os.path.join(ss_good_root, "etc", "systemd", "system"))
with open(os.path.join(ss_good_root, "etc", "systemd", "system",
"local.socket"), "w") as f:
f.write("[Socket]\n")
f.write("ListenStream=127.0.0.1:7000\n")
f.write("SocketMode=0600\n")
f.write("Accept=yes\n")
f.write("MaxConnections=16\n")
class _SolrHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/solr/":
body = b"<html><title>Solr Admin</title></html>"
self.send_response(200)
elif path == "/solr/admin/cores":
body = (b'{"responseHeader":{"status":0},'
b'"status":{"books":{"name":"books","numDocs":42},'
b'"logs":{"name":"logs","numDocs":7}}}')
self.send_response(200)
elif path == "/solr/admin/info/system":
body = b'{"responseHeader":{"status":0},"mode":"std"}'
self.send_response(200)
else:
body = b'{"error":"not found"}'
self.send_response(404)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
class _SolrAuthHandler(_SolrHandler):
def do_GET(self):
body = b'{"error":"unauthorized"}'
self.send_response(401)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
solr_srv = http.server.HTTPServer(("127.0.0.1", 0), _SolrHandler)
solr_port = solr_srv.server_address[1]
solr_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _SolrAuthHandler)
solr_auth_port = solr_auth_srv.server_address[1]
for _s in (solr_srv, solr_auth_srv):
threading.Thread(target=_s.serve_forever, daemon=True).start()
cfg64_home = tempfile.mkdtemp(prefix="apex-cfg64-home-")
write_scope(cfg64_home,
{"label": "cfg64", "expires": "2099-01-01T00:00:00Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_domain": ["example.test"],
"allow_port": [str(solr_port), str(solr_auth_port)]})
sc_empty_root = tempfile.mkdtemp(prefix="apex-sce-")
ss_empty_root = tempfile.mkdtemp(prefix="apex-sse-")
res, _ = run([
call(1, "seccomp_audit", root=sc_root),
call(2, "seccomp_audit", root=sc_good_root),
call(3, "seccomp_audit", root=sc_empty_root),
call(4, "systemd_socket_audit", root=ss_root),
call(5, "systemd_socket_audit", root=ss_good_root),
call(6, "systemd_socket_audit", root=ss_empty_root),
call(7, "solr_probe", target="127.0.0.1", port=solr_port, tls=False),
call(8, "solr_probe", target="127.0.0.1", port=solr_auth_port, tls=False),
], home=cfg64_home)
by_id = {r["id"]: r for r in res if "id" in r}
sec = json.loads(text(by_id[1]))
sec_kinds = {f["kind"] for f in sec["findings"]}
check("seccomp_audit flags a negating filter, an empty filter, a root service "
"without NoNewPrivileges, a world-writable unit and loose profiles",
{"negative-only-filter", "empty-syscall-filter",
"no-new-privileges-off", "no-new-privileges-missing",
"world-writable-unit", "default-allow", "no-default-action"}
<= sec_kinds and sec["units"] == 2 and sec["profiles"] == 2, sc)
sec_good = json.loads(text(by_id[2]))
check("seccomp_audit accepts a positive filter, NoNewPrivileges and an "
"errno-default profile",
{f["kind"] for f in sec_good["findings"]} == {"no-findings"} and
sec_good["filtered_units"] == 1 and sec_good["profiles"] == 1,
sec_good)
sec_empty = json.loads(text(by_id[3]))
check("seccomp_audit reports an empty tree as no-config",
sec_empty["findings_count"] == 1 and
sec_empty["findings"][0]["kind"] == "no-config", sec_empty)
sso = json.loads(text(by_id[4]))
sso_kinds = {f["kind"] for f in sso["findings"]}
check("systemd_socket_audit flags wide listeners, a world socket mode and "
"Accept without a limit",
{"listen-all-interfaces", "socket-mode-world", "accept-no-max"}
<= sso_kinds and sso["sockets"] == 2 and sso["wide"] == 2, ss)
sso_good = json.loads(text(by_id[5]))
check("systemd_socket_audit accepts a loopback socket with a limit",
{f["kind"] for f in sso_good["findings"]} == {"no-findings"} and
sso_good["wide"] == 0 and sso_good["sockets"] == 1, sso_good)
sso_empty = json.loads(text(by_id[6]))
check("systemd_socket_audit reports an empty tree as no-config",
sso_empty["findings_count"] == 1 and
sso_empty["findings"][0]["kind"] == "no-config", sso_empty)
solr = json.loads(text(by_id[7]))
check("solr_probe finds an open core API and saves evidence",
solr["cores_open"] is True and solr["open_count"] == 3 and
solr["core_count"] == 2 and solr["evidence"] is not None and
os.path.isfile(solr["evidence"]), solr)
solr_auth = json.loads(text(by_id[8]))
check("solr_probe reports a closed core API as not open",
solr_auth["cores_open"] is False and solr_auth["evidence"] is None and
all(e["status"] == 401 for e in solr_auth["endpoints"]), solr_auth)
for _s in (solr_srv, solr_auth_srv):
_s.shutdown()
for d in (sc_root, sc_good_root, sc_empty_root, ss_root, ss_good_root,
ss_empty_root, cfg64_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.84.0: gated wrappers for external scanners (mock binaries) ---
print("\n== external scanner wrappers ==\n")