apex-twin 1.90.0: suricata, icinga2 and falco audits, Schema Registry probe

Three blue config audits and one red probe:
- suricata_audit: rule-files left empty (sensor inspects nothing), enabled: no,
  a default-rule-path that does not exist, world-writable .rules files.
- icinga2_audit: accept_config/accept_commands, ApiListener bound beyond
  localhost, run_as_root check commands, world-writable .conf.
- falco_audit: no rules_file, minimum_priority debug/info, http webhook,
  writable rules in rules.d.
- schema_registry_probe: /subjects on 8081 without credentials, subject list
  saved as evidence.

Four parser bugs found and fixed while writing the fixtures: strcmp suffix
check used n-4 instead of n-5 for ".conf", yaml_value() cannot tell an empty
key from a list (new yaml_has_inline_value), suricata never counted the config
file it read, and schema_registry_probe emitted an unterminated endpoints
array. Dead icinga_state.no_tls field removed instead of faking a value.

Verified: make test 1467/1467, make test-asan 1467/1467, analyze 0 warnings,
240 fuzz cases, coverage 85.0%, release-check incl. distcheck exit 0.
Red proof: disabling the rule-files check turns the new suricata check red.

393 tools, 1467 checks.
This commit is contained in:
lotherk committed 2026-11-23 15:12:30 +00:00
1 parent ea40473dc3
commit 2a0d5e5833
9 files changed
+884 -13

No files matched your search

+16
View File
@@ -1,5 +1,21 @@
# Changelog
## 1.90.0 - 2026-11-24 - this change
- **Suricata** (`suricata_audit`): `rule-files:` left empty (the sensor runs
but inspects nothing), `enabled: no`, a `default-rule-path` that does not
exist, and a `.rules` file any local user can write.
- **Icinga 2** (`icinga2_audit`): `accept_config`/`accept_commands` (any
cluster endpoint can push checks), an `ApiListener` bound beyond localhost,
`run_as_root = true` check commands, and a world-writable `.conf`.
- **Falco** (`falco_audit`): no `rules_file` at all, `minimum_priority:
debug`/`info` (every event is kept), a `webhook_address` over plain http,
and a writable rule file in `rules.d`.
- **Schema Registry** (`schema_registry_probe`): `/subjects` on 8081 answering
without credentials; the subject list is saved as evidence.
393 tools, 1467 checks, 240 fuzz cases, 85.0% line coverage.
## 1.89.0 - 2026-11-24 - this change
- **fapolicyd** (`fapolicyd_audit`): `permissive = 1` (a denial is only
+11 -5
View File
@@ -5,11 +5,11 @@ no Python in the serving path. It gives an agent real reconnaissance and real we
testing behind a scope gate that refuses everything until a rules-of-engagement
file says otherwise.
**389 tools · 1459 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
**393 tools · 1467 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.89.0","tools":389,...,"scope":{"loaded":true,...}}
{"version":"1.90.0","tools":393,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -239,6 +239,7 @@ uploads and secret-file reads. It does not execute anything.
| `nomad_probe` | `/v1/jobs` on 4646 without a token; job inventory as evidence |
| `coredns_probe` | plugin API `/config/` on 2019 without a token; server blocks as evidence |
| `openbmc_probe` | xyz.openbmc_project control tree on 443 without a session; power policy as evidence |
| `schema_registry_probe` | `/subjects` on 8081 without auth; subject list as evidence |
| `airflow_probe` | `/api/v1/dags` without auth; DAG inventory as evidence |
| `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 |
@@ -585,6 +586,9 @@ does.
| `fapolicyd_audit` | fapolicyd: permissive = 1, integrity = none, allow-all before deny |
| `systemd_timer_audit` | timers: every-minute interval, Persistent, service without User= |
| `yara_audit` | YARA: scanning disabled, writable or empty rule file |
| `suricata_audit` | suricata.yaml: empty rule-files, disabled engine, world-writable rules |
| `icinga2_audit` | API bound beyond localhost, accept_config, run_as_root commands, writable config |
| `falco_audit` | no rules_file, debug threshold, http webhook, writable rules |
| `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 |
@@ -1071,7 +1075,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
ollama_probe, cadvisor_probe, teamcity_probe,
superset_probe, argocd_probe, kafka_connect_probe,
zabbix_probe, datasette_probe, vault_probe,
nomad_probe, coredns_probe, openbmc_probe
nomad_probe, coredns_probe, openbmc_probe,
schema_registry_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,
@@ -1097,7 +1102,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
journal_upload_audit, fwupd_audit,
smartd_audit, tlog_audit, abrt_audit,
freshclam_audit, tripwire_audit, fapolicyd_audit,
systemd_timer_audit, yara_audit)
systemd_timer_audit, yara_audit,
suricata_audit, icinga2_audit, falco_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
@@ -1136,7 +1142,7 @@ examples/ scope.json
## Status
1.89.0. Built and run: 389 tools, 1459 checks, 240 fuzz cases and 85.0% line
1.90.0. Built and run: 393 tools, 1467 checks, 240 fuzz cases and 85.0% line
coverage. The loop closes: a probe captures the exchange as a pair, a finding
points at it, `finding_update` gives it a state, an asset records the host it
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
+1 -1
View File
@@ -9,7 +9,7 @@ problem.
The supported line is the one printed by `apex-twin --version` for the tree you
built; this document ships with that same tree. At the time of writing the line
is **1.89.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.90.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.
+4 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.89.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.90.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,
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,
nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
@@ -96,7 +96,8 @@ nfs_conf_audit, idmapd_audit, netplan_audit,
apt_auth_audit, aliases_audit, netgroup_audit, jetty_audit,
dhclient_audit, journal_upload_audit, fwupd_audit,
smartd_audit, tlog_audit, abrt_audit, freshclam_audit, tripwire_audit,
fapolicyd_audit, systemd_timer_audit, yara_audit,
fapolicyd_audit, systemd_timer_audit, yara_audit, suricata_audit,
icinga2_audit, falco_audit,
php_fpm_audit, uwsgi_audit, lighttpd_audit)
and ESP32 board tools (esp_info, esp_monitor,
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.89.0"
#define APEX_VERSION "1.90.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+561
View File
@@ -29517,6 +29517,546 @@ static void t_yara_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- suricata_audit */
/* Count the "- item" entries that belong to a YAML key, stopping at the next
* line that is not more indented than the key and at the next key at the same
* level. Suricata writes rule-files as such a list. */
static int yaml_list_count(const char *text, const char *key)
{
const char *p = text;
size_t kl = strlen(key);
int count = 0;
int in_list = 0;
int key_indent = -1;
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];
size_t i = 0;
int indent = 0;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
while (line[i] == ' ' || line[i] == '\t') {
indent += (line[i] == '\t') ? 8 : 1;
i++;
}
if (in_list) {
if (line[i] == '\0' || line[i] == '#') {
p = eol != NULL ? eol + 1 : NULL;
continue;
}
if (indent > key_indent && line[i] == '-' &&
(line[i + 1] == ' ' || line[i + 1] == '\0')) {
count++;
p = eol != NULL ? eol + 1 : NULL;
continue;
}
if (indent <= key_indent)
in_list = 0;
}
if (!in_list && line[i] != '#' &&
strncasecmp(line + i, key, kl) == 0 &&
line[i + kl] == ':') {
const char *v = line + i + kl + 1;
while (*v == ' ' || *v == '\t')
v++;
if (*v != '\0' && *v != '#')
return 1; /* inline value, not a list */
in_list = 1;
key_indent = indent;
}
p = eol != NULL ? eol + 1 : NULL;
}
return count;
}
/* suricata.yaml is a flat "key: value" YAML with nested rule-file lists. An IDS
* that loads no rule category, suppresses alerts with a blanket threshold, or
* keeps its rule directory writable by any local user is decoration: the log is
* full, the alerts are stale. The audit also counts the rule files it finds. */
struct suricata_state {
int files;
int rule_files;
int writable_rules;
int no_rule_paths;
int homedir_missing;
int disabled;
};
/* yaml_value() also matches "key:" with nothing behind it and then returns an
* empty string, so it cannot tell an empty value from a list. This only says
* yes when the same line carries a real value. */
static int yaml_has_inline_value(const char *text, const char *key)
{
char value[512];
if (yaml_value(text, key, value, sizeof(value)) != 1)
return 0;
return value[0] != '\0';
}
static void suricata_scan_rules(struct suricata_state *st, const char *dir,
mcp_buf *findings, int *first, int *count,
int depth)
{
DIR *d;
struct dirent *ent;
if (depth > 3)
return;
d = opendir(dir);
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL) {
char path[1400];
struct stat sb;
size_t n;
if (ent->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%.1000s/%.200s", dir, ent->d_name);
if (stat(path, &sb) != 0)
continue;
if (S_ISDIR(sb.st_mode)) {
suricata_scan_rules(st, path, findings, first, count,
depth + 1);
continue;
}
n = strlen(ent->d_name);
if (!(n > 6 && strcmp(ent->d_name + n - 6, ".rules") == 0))
continue;
st->rule_files++;
if ((sb.st_mode & 0002) != 0) {
st->writable_rules++;
add_finding(findings, first, "writable-rules", "high",
"%s is writable by any local user; a rule that "
"disables detection can be dropped in", path);
(*count)++;
}
}
closedir(d);
}
static void t_suricata_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1200];
static char text[131072];
char value[512];
mcp_buf b;
mcp_buf findings;
struct suricata_state st;
struct stat sb;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/suricata/suricata.yaml",
"/etc/suricata/suricata.yml", NULL };
static const char *dirs[] = { "/etc/suricata/rules",
"/var/lib/suricata/rules",
"/usr/share/suricata/rules", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 300) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
st.files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by any local user", path);
count++;
}
if (yaml_list_count(text, "rule-files") == 0 &&
!yaml_has_inline_value(text, "rule-files")) {
st.no_rule_paths++;
add_finding(&findings, &first, "no-rule-files", "high",
"%s loads no rule file (rule-files empty); the "
"sensor sees everything and alerts on nothing",
path);
count++;
}
if (yaml_value(text, "default-rule-path", value, sizeof(value)) ==
1) {
char full[1200];
snprintf(full, sizeof(full), "%.300s%s", root, value);
if (stat(full, &sb) != 0) {
st.homedir_missing++;
add_finding(&findings, &first, "rule-path-missing",
"medium",
"default-rule-path %.200s does not exist "
"under %.300s", value, root);
count++;
}
}
if (yaml_value(text, "enabled", value, sizeof(value)) == 1 &&
(strcmp(value, "no") == 0 || strcmp(value, "false") == 0)) {
st.disabled++;
add_finding(&findings, &first, "engine-disabled", "high",
"%s disables the engine; nothing is inspected",
path);
count++;
}
}
for (i = 0; dirs[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, dirs[i]);
suricata_scan_rules(&st, path, &findings, &first, &count, 0);
}
if (count == 0 && st.files == 0)
add_finding(&findings, &first, "no-config", "info",
"no readable suricata.yaml under %.300s", root);
else if (count == 0)
add_finding(&findings, &first, "no-findings", "info",
"the sensor loads its rule set from a path only root "
"can write");
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"rule_files\":%d,"
"\"writable_rules\":%d,"
"\"no_rule_paths\":%d,\"rule_path_missing\":%d,"
"\"disabled\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.rule_files, st.writable_rules,
st.no_rule_paths, st.homedir_missing, st.disabled, 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);
}
/* --------------------------------------------------------------- icinga2_audit */
/* icinga2.conf includes a conf.d tree. A config that runs commands as the
* Icinga user with sudo, a zone without an endpoint, or an api listener bound
* beyond localhost without a certificate check gives either the monitoring
* user root or the API to anyone on the wire. The audit reads the main file and
* the conf.d drop-ins. */
struct icinga_state {
int files;
int api_open;
int sudo_commands;
int writable;
};
static void icinga_scan_dir(struct icinga_state *st, const char *dir,
mcp_buf *findings, int *first, int *count,
int depth)
{
DIR *d;
struct dirent *ent;
if (depth > 2)
return;
d = opendir(dir);
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL) {
char path[1400];
struct stat sb;
size_t n;
static char text[65536];
if (ent->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%.1000s/%.200s", dir, ent->d_name);
if (stat(path, &sb) != 0)
continue;
if (S_ISDIR(sb.st_mode)) {
icinga_scan_dir(st, path, findings, first, count,
depth + 1);
continue;
}
n = strlen(ent->d_name);
/* ".conf" is five characters, so the suffix starts at n - 5. */
if (!(n > 5 && strcmp(ent->d_name + n - 5, ".conf") == 0))
continue;
st->files++;
if ((sb.st_mode & 0002) != 0) {
st->writable++;
add_finding(findings, first, "writable-config", "high",
"%s is writable by any local user", path);
(*count)++;
}
if (read_text(path, text, sizeof(text)) <= 0)
continue;
if (strstr(text, "run_as_root = true") != NULL) {
st->sudo_commands++;
add_finding(findings, first, "run-as-root", "high",
"%s runs check commands as root; a check "
"argument becomes a root command", path);
(*count)++;
}
}
closedir(d);
}
static void t_icinga2_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1200];
static char text[131072];
char value[256];
mcp_buf b;
mcp_buf findings;
struct icinga_state st;
struct stat sb;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/icinga2/icinga2.conf",
"/etc/icinga2/features-enabled/api.conf",
NULL };
static const char *dirs[] = { "/etc/icinga2/conf.d",
"/etc/icinga2/zones.d", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 300) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
st.files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st.writable++;
add_finding(&findings, &first, "writable-config", "high",
"%s is writable by any local user", path);
count++;
}
if (strcasestr(text, "accept_config") != NULL ||
strcasestr(text, "accept_commands") != NULL) {
st.api_open++;
add_finding(&findings, &first, "api-accepts-all", "high",
"%s accepts config or commands from any "
"endpoint; a cluster node can push checks",
path);
count++;
}
if (yaml_value(text, "bind_host", value, sizeof(value)) == 1 ||
conf_value(text, "bind_host", value, sizeof(value)) == 1) {
if (strcmp(value, "127.0.0.1") != 0 &&
strcmp(value, "::1") != 0) {
st.api_open++;
add_finding(&findings, &first, "api-exposed",
"medium",
"%s binds the API to %.100s; anyone on "
"the network reaches it", path, value);
count++;
}
}
}
for (i = 0; dirs[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, dirs[i]);
icinga_scan_dir(&st, path, &findings, &first, &count, 0);
}
if (count == 0 && st.files == 0)
add_finding(&findings, &first, "no-config", "info",
"no readable icinga2.conf under %.300s", root);
else if (count == 0)
add_finding(&findings, &first, "no-findings", "info",
"no writable config, no root check commands and the "
"API stays on localhost");
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"api_open\":%d,"
"\"run_as_root\":%d,\"writable\":%d,"
"\"findings_count\":%d,\"findings\":[",
st.files, st.api_open, st.sudo_commands,
st.writable, count);
if (findings.p != NULL)
mcp_buf_add(&b, findings.p, findings.len);
mcp_buf_puts(&b, "]}");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
mcp_buf_free(&findings);
}
/* ----------------------------------------------------------------- falco_audit */
/* Falco watches syscalls through a driver. Its rules are only as good as the
* "enabled" and priority settings: a rule with priority "debug" or "info" never
* reaches a default threshold, an empty rules_file, and a webhook output that
* posts every alert to a plain http URL. */
struct falco_state {
int files;
int rules_missing;
int low_priority;
int plain_http;
int writable;
};
static void falco_scan_rules(struct falco_state *st, const char *dir,
mcp_buf *findings, int *first, int *count,
int depth)
{
DIR *d;
struct dirent *ent;
if (depth > 3)
return;
d = opendir(dir);
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL) {
char path[1400];
struct stat sb;
size_t n;
static char text[131072];
if (ent->d_name[0] == '.')
continue;
snprintf(path, sizeof(path), "%.1000s/%.200s", dir, ent->d_name);
if (stat(path, &sb) != 0)
continue;
if (S_ISDIR(sb.st_mode)) {
falco_scan_rules(st, path, findings, first, count,
depth + 1);
continue;
}
n = strlen(ent->d_name);
if (!(n > 5 && strcmp(ent->d_name + n - 5, ".yaml") == 0) &&
!(n > 4 && strcmp(ent->d_name + n - 4, ".yml") == 0))
continue;
if ((sb.st_mode & 0002) != 0) {
st->writable++;
add_finding(findings, first, "writable-rules", "high",
"%s is writable by any local user; a rule that "
"swallows every alert can be added", path);
(*count)++;
}
if (read_text(path, text, sizeof(text)) <= 0)
continue;
if (strstr(text, "priority: debug") != NULL ||
strstr(text, "priority: info") != NULL) {
st->low_priority++;
add_finding(findings, first, "low-priority", "medium",
"%s uses priority debug or info; with a default "
"minimum priority these rules never fire", path);
(*count)++;
}
}
closedir(d);
}
static void t_falco_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1200];
static char text[131072];
char value[512];
mcp_buf b;
mcp_buf findings;
struct falco_state st;
struct stat sb;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/falco/falco.yaml", NULL };
static const char *dirs[] = { "/etc/falco/rules.d",
"/etc/falco", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 300) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
st.files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st.writable++;
add_finding(&findings, &first, "writable-config", "high",
"%s is writable by any local user", path);
count++;
}
if (yaml_value(text, "rules_file", value, sizeof(value)) != 1 &&
yaml_list_count(text, "rules_file") == 0) {
st.rules_missing++;
add_finding(&findings, &first, "no-rules", "high",
"%s loads no rules_file; Falco starts and "
"reports nothing", path);
count++;
}
if (yaml_value(text, "minimum_priority", value, sizeof(value)) ==
1 && (strcasecmp(value, "debug") == 0 ||
strcasecmp(value, "info") == 0)) {
st.low_priority++;
add_finding(&findings, &first, "low-threshold", "medium",
"%s sets minimum_priority to %.60s; every "
"informational rule floods the output", path,
value);
count++;
}
if (yaml_value(text, "webhook_address", value, sizeof(value)) ==
1 && strncmp(value, "http://", 7) == 0) {
st.plain_http++;
add_finding(&findings, &first, "plain-http-webhook",
"medium",
"alerts are posted to %.200s in clear text; "
"anyone on the path reads the findings", value);
count++;
}
}
for (i = 0; dirs[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.300s%s", root, dirs[i]);
falco_scan_rules(&st, path, &findings, &first, &count, 0);
}
if (count == 0 && st.files == 0)
add_finding(&findings, &first, "no-config", "info",
"no readable falco.yaml under %.300s", root);
else if (count == 0)
add_finding(&findings, &first, "no-findings", "info",
"rules load, the threshold is above info and the "
"webhook uses https");
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"rules_missing\":%d,"
"\"low_priority\":%d,\"plain_http\":%d,"
"\"writable\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.rules_missing, st.low_priority,
st.plain_http, st.writable, count);
if (findings.p != NULL)
mcp_buf_add(&b, findings.p, findings.len);
mcp_buf_puts(&b, "]}");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
mcp_buf_free(&findings);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -31153,6 +31693,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_yara_audit },
{ "suricata_audit",
"Parse suricata.yaml (root prefix): rule-files empty, a missing "
"default-rule-path, the engine disabled and a writable config or rule "
"directory. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_suricata_audit },
{ "icinga2_audit",
"Read the icinga2 main config and conf.d/zones.d (root prefix): an API "
"binding beyond localhost, accept_config, run_as_root check commands "
"and writable config files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_icinga2_audit },
{ "falco_audit",
"Read falco.yaml and rules.d (root prefix): no rules_file, "
"minimum_priority debug/info, an http webhook and writable rule or "
"config files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_falco_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+98
View File
@@ -9212,6 +9212,93 @@ static void t_vault_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ------------------------------------------------------ schema_registry_probe */
/* The Confluent Schema Registry keeps every subject's schema behind
* /subjects; without auth enabled the list and each schema body are readable.
* /config answers with the compatibility level, /mode with the read-write mode.
* A 2xx on /subjects is the open instance; the subject list becomes evidence. */
static void t_schema_registry_probe(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *paths[] = { "/subjects", "/config", "/mode", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 8081);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(8081));
mcp_buf b;
int first = 1;
int tested = 0;
int open_count = 0;
int subjects_open = 0;
int subject_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, "schema_registry_probe", target, port))
return;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port,
tls ? "true" : "false");
for (i = 0; paths[i] != NULL; i++) {
char status[256];
char *resp = NULL;
size_t len = 0;
int code;
status[0] = '\0';
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
8000, &resp, &len, status,
sizeof(status)) != 0)
continue;
tested++;
code = apex_status_code(status);
if (code >= 200 && code < 300) {
open_count++;
if (strcmp(paths[i], "/subjects") == 0) {
subjects_open = 1;
subject_count = count_needle(resp, "\"");
if (evidence == NULL)
evidence = apex_evidence_save(
"open-schema-registry", 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,"
"\"subjects_open\":%s,\"subject_chars\":%d,\"evidence\":",
tested, open_count,
subjects_open ? "true" : "false", subject_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 (subjects_open)
apex_audit("schema_registry_probe", target, port, 1,
"open Schema Registry: subject list readable without "
"credentials", "HTTP GET /subjects");
free(evidence);
mcp_buf_free(&b);
}
/* ------------------------------------------------------------ openbmc_probe */
/* OpenBMC exposes Redfish and the legacy xyz.openbmc_project REST tree over
@@ -10855,6 +10942,17 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_vault_probe },
{ "schema_registry_probe",
"Query a Confluent Schema Registry on 8081 without credentials: "
"/subjects, /config and /mode. A 2xx on /subjects means every subject "
"name and schema body is readable; the list is saved as evidence. Gate: "
"the target and port must be in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 8081\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_schema_registry_probe },
{ "openbmc_probe",
"Get the Redfish root and the xyz.openbmc_project tree on 443 without a "
"session. A 2xx on the host control tree means power control and "
+1 -1
View File
@@ -21,7 +21,7 @@ import re
import sys
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXPECTED_TOOLS = 389
EXPECTED_TOOLS = 393
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
+191 -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("389 tools registered", len(tools) == 389, len(tools))
check("393 tools registered", len(tools) == 393, 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"]) == 389)
check("http tools/list", len(listing["result"]["tools"]) == 393)
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
@@ -17557,6 +17557,195 @@ for d in (fap_root, fap_good_root, tm_root, tm_good_root, yr_root,
yr_good_root, cfg60_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.90.0: suricata, icinga2 and falco audits plus the Schema Registry probe ---
print("\n== suricata, icinga2, falco and Schema Registry ==")
sr_root = tempfile.mkdtemp(prefix="apex-sr-")
os.makedirs(os.path.join(sr_root, "etc", "suricata", "rules"))
with open(os.path.join(sr_root, "etc", "suricata", "suricata.yaml"), "w") as f:
f.write("default-rule-path: /etc/suricata/rules\n")
f.write("rule-files:\n")
f.write("enabled: no\n")
with open(os.path.join(sr_root, "etc", "suricata", "rules", "local.rules"),
"w") as f:
f.write('alert http any any -> any any (msg:"x"; sid:1;)\n')
os.chmod(os.path.join(sr_root, "etc", "suricata", "rules", "local.rules"),
0o666)
sr_good_root = tempfile.mkdtemp(prefix="apex-srg-")
os.makedirs(os.path.join(sr_good_root, "etc", "suricata", "rules"))
with open(os.path.join(sr_good_root, "etc", "suricata", "suricata.yaml"),
"w") as f:
f.write("default-rule-path: /etc/suricata/rules\n")
f.write("rule-files:\n")
f.write(" - local.rules\n")
f.write(" - emerging-all.rules\n")
with open(os.path.join(sr_good_root, "etc", "suricata", "rules",
"local.rules"), "w") as f:
f.write('alert http any any -> any any (msg:"x"; sid:1;)\n')
ic_root = tempfile.mkdtemp(prefix="apex-ic2-")
os.makedirs(os.path.join(ic_root, "etc", "icinga2", "features-enabled"))
os.makedirs(os.path.join(ic_root, "etc", "icinga2", "conf.d"))
with open(os.path.join(ic_root, "etc", "icinga2", "icinga2.conf"), "w") as f:
f.write("include <itl>\n")
with open(os.path.join(ic_root, "etc", "icinga2", "features-enabled",
"api.conf"), "w") as f:
f.write("object ApiListener \"api\" {\n")
f.write(" bind_host = \"0.0.0.0\"\n")
f.write(" accept_config = true\n")
f.write("}\n")
with open(os.path.join(ic_root, "etc", "icinga2", "conf.d", "commands.conf"),
"w") as f:
f.write("object CheckCommand \"x\" {\n")
f.write(" run_as_root = true\n")
f.write("}\n")
ic_good_root = tempfile.mkdtemp(prefix="apex-icg-")
os.makedirs(os.path.join(ic_good_root, "etc", "icinga2", "features-enabled"))
with open(os.path.join(ic_good_root, "etc", "icinga2", "icinga2.conf"),
"w") as f:
f.write("include <itl>\n")
with open(os.path.join(ic_good_root, "etc", "icinga2", "features-enabled",
"api.conf"), "w") as f:
f.write("object ApiListener \"api\" {\n")
f.write(" bind_host = \"127.0.0.1\"\n")
f.write("}\n")
fc_root = tempfile.mkdtemp(prefix="apex-fco-")
os.makedirs(os.path.join(fc_root, "etc", "falco", "rules.d"))
with open(os.path.join(fc_root, "etc", "falco", "falco.yaml"), "w") as f:
f.write("minimum_priority: debug\n")
f.write("webhook_address: http://collector.example.test/alerts\n")
with open(os.path.join(fc_root, "etc", "falco", "rules.d", "local.yaml"),
"w") as f:
f.write("- rule: Terminal shell\n")
f.write(" priority: debug\n")
os.chmod(os.path.join(fc_root, "etc", "falco", "rules.d", "local.yaml"), 0o666)
fc_good_root = tempfile.mkdtemp(prefix="apex-fcg-")
os.makedirs(os.path.join(fc_good_root, "etc", "falco", "rules.d"))
with open(os.path.join(fc_good_root, "etc", "falco", "falco.yaml"), "w") as f:
f.write("rules_file:\n")
f.write(" - /etc/falco/falco_rules.yaml\n")
f.write("minimum_priority: notice\n")
f.write("webhook_address: https://collector.example.test/alerts\n")
with open(os.path.join(fc_good_root, "etc", "falco", "rules.d", "local.yaml"),
"w") as f:
f.write("- rule: Terminal shell\n")
f.write(" priority: warning\n")
class _SchemaRegistryHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/subjects":
body = b'["orders-value","users-value"]'
self.send_response(200)
elif path in ("/config", "/mode"):
body = b'{"compatibilityLevel":"BACKWARD"}'
self.send_response(200)
else:
body = b'{"error_code":404,"message":"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 _SchemaRegistryAuthHandler(_SchemaRegistryHandler):
def do_GET(self):
body = b'{"error_code":401,"message":"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)
srg_srv = http.server.HTTPServer(("127.0.0.1", 0), _SchemaRegistryHandler)
srg_port = srg_srv.server_address[1]
srg_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
_SchemaRegistryAuthHandler)
srg_auth_port = srg_auth_srv.server_address[1]
for _s in (srg_srv, srg_auth_srv):
threading.Thread(target=_s.serve_forever, daemon=True).start()
cfg61_home = tempfile.mkdtemp(prefix="apex-cfg61-home-")
write_scope(cfg61_home,
{"label": "cfg61", "expires": "2099-01-01T00:00:00Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": ["1-65535"]})
res, _ = run([
call(1, "suricata_audit", root=sr_root),
call(2, "suricata_audit", root=sr_good_root),
call(3, "icinga2_audit", root=ic_root),
call(4, "icinga2_audit", root=ic_good_root),
call(5, "falco_audit", root=fc_root),
call(6, "falco_audit", root=fc_good_root),
call(7, "schema_registry_probe", target="127.0.0.1", port=srg_port,
tls=False),
call(8, "schema_registry_probe", target="127.0.0.1", port=srg_auth_port,
tls=False),
], home=cfg61_home)
by_id = {r["id"]: r for r in res if "id" in r}
sra = json.loads(text(by_id[1]))
sra_kinds = {f["id"] for f in sra["findings"]}
check("suricata_audit flags an empty rule-files list, a disabled engine and "
"writable rules",
{"no-rule-files", "engine-disabled", "writable-rules"} <= sra_kinds and
sra["no_rule_paths"] == 1 and sra["disabled"] == 1 and
sra["writable_rules"] == 1, sra)
sra_good = json.loads(text(by_id[2]))
check("suricata_audit accepts a loaded rule list on a root-owned path",
sra_good["findings_count"] == 0 and
sra_good["findings"][0]["id"] == "no-findings" and
sra_good["no_rule_paths"] == 0 and sra_good["writable_rules"] == 0,
sra_good)
ica = json.loads(text(by_id[3]))
ica_kinds = {f["id"] for f in ica["findings"]}
check("icinga2_audit flags accept_config, a public API bind and run_as_root",
{"api-accepts-all", "api-exposed", "run-as-root"} <= ica_kinds and
ica["api_open"] >= 1 and ica["run_as_root"] == 1, ica)
ica_good = json.loads(text(by_id[4]))
check("icinga2_audit accepts an API bound to localhost",
ica_good["findings_count"] == 0 and
ica_good["findings"][0]["id"] == "no-findings" and
ica_good["run_as_root"] == 0, ica_good)
fca = json.loads(text(by_id[5]))
fca_kinds = {f["id"] for f in fca["findings"]}
check("falco_audit flags no rules_file, a debug threshold, an http webhook "
"and writable rules",
{"no-rules", "low-threshold", "plain-http-webhook",
"writable-rules"} <= fca_kinds and fca["rules_missing"] == 1 and
fca["plain_http"] == 1 and fca["writable"] >= 1, fca)
fca_good = json.loads(text(by_id[6]))
check("falco_audit accepts a rules list, notice threshold and an https webhook",
fca_good["findings_count"] == 0 and
fca_good["findings"][0]["id"] == "no-findings" and
fca_good["rules_missing"] == 0 and fca_good["plain_http"] == 0,
fca_good)
srg = json.loads(text(by_id[7]))
check("schema_registry_probe finds an open subject list and saves evidence",
srg["subjects_open"] is True and srg["open_count"] == 3 and
srg["evidence"] is not None and os.path.isfile(srg["evidence"]), srg)
srg_auth = json.loads(text(by_id[8]))
check("schema_registry_probe reports a closed registry as not open",
srg_auth["subjects_open"] is False and srg_auth["evidence"] is None and
all(e["status"] == 401 for e in srg_auth["endpoints"]), srg_auth)
srg_srv.shutdown()
srg_auth_srv.shutdown()
for d in (sr_root, sr_good_root, ic_root, ic_good_root, fc_root,
fc_good_root, cfg61_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.84.0: gated wrappers for external scanners (mock binaries) ---
print("\n== external scanner wrappers ==\n")