apex-twin 1.87.0: smartd, tlog and abrt audits, Nomad probe

Three blue config audits: smartd_audit (device without -m, untyped
DEVICESCAN, writable -M exec hook, world-writable smartd.conf),
tlog_audit (scope without session, notice without wall, no log target,
writable config) and abrt_audit (AutoreportingEnabled=yes, non-local
report URL, upload without SSLVerify, writable abrt.conf). One red probe:
nomad_probe reads /v1/agent/self, /v1/jobs and /v1/nodes on 4646 without
a token and saves the job list as evidence.

382 tools, 1445 end-to-end checks. Verified: make test 1445/1445,
test-asan 1445/1445, analyze 0 warnings, 240 fuzz cases green,
release-check exit 0 including distcheck from the tarball, coverage 85.0%.
Reverse test: forcing the writable-exec check off turns the smartd check
red (1444/1445), restored afterwards.
This commit is contained in:
lotherk committed 2026-11-23 13:41:11 +00:00
1 parent b56687ef7f
commit 53d5084a77
9 files changed
+796 -12

No files matched your search

+16
View File
@@ -1,5 +1,21 @@
# Changelog
## 1.87.0 - 2026-11-24 - this change
- **smartd** (`smartd_audit`): a monitored device without a `-m` address (a
failing disk reports to nobody), a `DEVICESCAN` without `-d`/`-H` so smartd
guesses the device type, an `-M exec` hook that is writable by any local
user, and a world-writable `smartd.conf`.
- **tlog** (`tlog_audit`): a `scope` that does not contain `session`
(interactive input and output are not captured), a `notice` without `wall`,
no `log` target at all, and a writable `tlog-rec-session.conf` or drop-in.
- **abrt** (`abrt_audit`): `AutoreportingEnabled=yes`, a `URL` that points at
anything but a local collector (crash dumps, with process memory, leave the
host), an upload without `SSLVerify`, and a writable `abrt.conf`.
- **Nomad** (`nomad_probe`): `/v1/jobs` and `/v1/nodes` on 4646 without a
token. A 2xx lists every deployed job and node; the body is saved as
evidence and the ACL flag from `/v1/agent/self` is reported.
## 1.86.0 - 2026-11-24 - this change
- **dhclient** (`dhclient_audit`): `dhclient.conf` that takes
+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.
**378 tools · 1437 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
**382 tools · 1445 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.86.0","tools":378,...,"scope":{"loaded":true,...}}
{"version":"1.87.0","tools":382,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -236,6 +236,7 @@ uploads and secret-file reads. It does not execute anything.
| `zabbix_probe` | `user.login` with the default Admin/zabbix pair; response as evidence |
| `datasette_probe` | `/-/databases.json` without a token; database list as evidence |
| `vault_probe` | `/v1/sys/mounts` on 8200 without a token; mount list as evidence |
| `nomad_probe` | `/v1/jobs` on 4646 without a token; job inventory 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 |
@@ -575,6 +576,9 @@ does.
| `dhclient_audit` | dhclient.conf + hooks: DHCP resolver, supersede override, writable hook |
| `journal_upload_audit` | journal-upload.conf: plain http URL, missing client key |
| `fwupd_audit` | fwupd daemon.conf: OnlyTrusted off, empty DisabledPlugins |
| `smartd_audit` | smartd.conf: device without `-m`, writable `-M exec` hook, untyped DEVICESCAN |
| `tlog_audit` | tlog: scope without `session`, notice without `wall`, missing log target |
| `abrt_audit` | abrt.conf: autoreporting, public collector URL, no TLS verify |
| `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 |
| `ssh_client_audit` | ssh_config: StrictHostKeyChecking no, known_hosts /dev/null, ssh-rsa |
@@ -1059,7 +1063,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
gitlab_probe, jupyter_probe, jira_probe,
ollama_probe, cadvisor_probe, teamcity_probe,
superset_probe, argocd_probe, kafka_connect_probe,
zabbix_probe, datasette_probe, vault_probe
zabbix_probe, datasette_probe, vault_probe,
nomad_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,
@@ -1082,7 +1087,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
apt_auth_audit, aliases_audit, netgroup_audit,
php_fpm_audit, uwsgi_audit, lighttpd_audit,
jetty_audit, dhclient_audit,
journal_upload_audit, fwupd_audit)
journal_upload_audit, fwupd_audit,
smartd_audit, tlog_audit, abrt_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
@@ -1121,7 +1127,7 @@ examples/ scope.json
## Status
1.86.0. Built and run: 378 tools, 1437 checks, 240 fuzz cases and 85.0% line
1.87.0. Built and run: 382 tools, 1445 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.86.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.87.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.86.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.87.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,
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,
nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
@@ -95,6 +95,7 @@ modules_load_audit, depmod_audit, adduser_conf_audit,
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,
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.86.0"
#define APEX_VERSION "1.87.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+473
View File
@@ -28316,6 +28316,452 @@ static void t_fwupd_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- smartd_audit */
/* smartd.conf is one directive per line: "DEVICESCAN" or a device path,
* followed by options. -m needs an address, -M exec needs a script that is not
* writable by every local user, and a DEVICESCAN without -d or -H picks the
* device type by guesswork. Lines starting with # are comments. */
struct smartd_state {
int files;
int devices;
int no_mail;
int scan_no_type;
int exec_scripts;
int writable_exec;
int world_writable;
};
static void smartd_check_exec(struct smartd_state *st, const char *script,
mcp_buf *findings, int *first, int *count);
static void smartd_scan_file(struct smartd_state *st, const char *path,
mcp_buf *findings, int *first, int *count)
{
static char text[65536];
struct stat sb;
const char *p;
int have_mail = 0;
if (read_text(path, text, sizeof(text)) <= 0)
return;
st->files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st->world_writable++;
add_finding(findings, first, "world-writable", "high",
"%s is writable by any local user; it decides which "
"disk failures are reported and to whom", path);
(*count)++;
}
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];
char *save = NULL;
char *word;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
p = eol != NULL ? eol + 1 : NULL;
if (len > 0 && line[len - 1] == '\r')
line[(len--) - 1] = '\0';
while (len > 0 && (line[len - 1] == ' ' || line[len - 1] == '\t'))
line[--len] = '\0';
word = strtok_r(line, " \t", &save);
if (word == NULL || word[0] == '#')
continue;
st->devices++;
have_mail = 0;
if (strcmp(word, "DEVICESCAN") == 0) {
int scan_type = 0;
char *opt;
while ((opt = strtok_r(NULL, " \t", &save)) != NULL) {
if (strcmp(opt, "-d") == 0 || strcmp(opt, "-H") == 0)
scan_type = 1;
else if (strcmp(opt, "-m") == 0) {
have_mail = 1;
(void)strtok_r(NULL, " \t", &save);
} else if (strcmp(opt, "-M") == 0) {
char *how = strtok_r(NULL, " \t", &save);
char *arg = strtok_r(NULL, " \t", &save);
if (how != NULL && strcmp(how, "exec") == 0 &&
arg != NULL) {
st->exec_scripts++;
smartd_check_exec(st, arg, findings,
first, count);
}
}
}
if (!scan_type) {
st->scan_no_type++;
add_finding(findings, first, "devicescan-untyped",
"medium",
"%s: DEVICESCAN without -d or -H lets smartd "
"guess the device type; failures on the wrong "
"protocol go unreported", path);
(*count)++;
}
} else {
char *opt;
while ((opt = strtok_r(NULL, " \t", &save)) != NULL) {
if (strcmp(opt, "-m") == 0) {
have_mail = 1;
(void)strtok_r(NULL, " \t", &save);
} else if (strcmp(opt, "-M") == 0) {
char *how = strtok_r(NULL, " \t", &save);
char *arg = strtok_r(NULL, " \t", &save);
if (how != NULL && strcmp(how, "exec") == 0 &&
arg != NULL) {
st->exec_scripts++;
smartd_check_exec(st, arg, findings,
first, count);
}
}
}
}
if (!have_mail) {
st->no_mail++;
add_finding(findings, first, "no-mail", "medium",
"%s: a monitored device has no -m address, so a "
"failing disk reports to nobody", path);
(*count)++;
}
}
}
static void smartd_check_exec(struct smartd_state *st, const char *script,
mcp_buf *findings, int *first, int *count)
{
struct stat sb;
if (stat(script, &sb) != 0 || !S_ISREG(sb.st_mode))
return;
if ((sb.st_mode & 0002) != 0) {
st->writable_exec++;
add_finding(findings, first, "writable-exec", "high",
"%s runs as root when smartd reports a problem and is "
"writable by any local user", script);
(*count)++;
}
}
static void t_smartd_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
struct smartd_state st;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/smartd.conf",
"/etc/smartmontools/smartd.conf", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
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), "%.400s%s", root, files[i]);
smartd_scan_file(&st, path, &findings, &first, &count);
}
if (st.files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a smartd configuration");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"every monitored device has a mail address and a device "
"type, no exec hook is writable and the file is read-only");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"devices\":%d,\"no_mail\":%d,"
"\"devicescan_untyped\":%d,\"exec_scripts\":%d,"
"\"writable_exec\":%d,\"world_writable\":%d,"
"\"findings_count\":%d,\"findings\":[",
st.files, st.devices, st.no_mail, st.scan_no_type,
st.exec_scripts, st.writable_exec, st.world_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);
}
/* ---------------------------------------------------------------- tlog_audit */
/* tlog records terminal sessions through sssd. tlog-rec-session.conf (and the
* conf.d drop-ins) is JSON: a "scope" without "session", "notice" without
* "wall", and "log" settings that write to a world-writable path all mean the
* audit trail misses what it was installed for. */
struct tlog_state {
int files;
int scope_no_session;
int notice_no_wall;
int no_log;
int world_writable;
};
static void tlog_scan_file(struct tlog_state *st, const char *path,
mcp_buf *findings, int *first, int *count)
{
static char text[65536];
struct stat sb;
const char *scope;
const char *notice;
const char *logp;
if (read_text(path, text, sizeof(text)) <= 0)
return;
st->files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st->world_writable++;
add_finding(findings, first, "world-writable", "high",
"%s is writable by any local user; it decides what tlog "
"records and where the recording goes", path);
(*count)++;
}
scope = strstr(text, "\"scope\"");
if (scope != NULL && strstr(scope, "session") == NULL) {
st->scope_no_session++;
add_finding(findings, first, "scope-no-session", "high",
"%s records a scope without \"session\"; interactive "
"shell input and output are not captured", path);
(*count)++;
}
notice = strstr(text, "\"notice\"");
if (notice != NULL && strstr(notice, "wall") == NULL) {
st->notice_no_wall++;
add_finding(findings, first, "notice-no-wall", "medium",
"%s does not set notice to wall, so the recorded user is "
"never told the session is logged", path);
(*count)++;
}
logp = strstr(text, "\"log\"");
if (logp == NULL) {
st->no_log++;
add_finding(findings, first, "no-log", "high",
"%s has no \"log\" target; tlog has nowhere to write the "
"recording", path);
(*count)++;
}
}
static void tlog_scan_dir(struct tlog_state *st, const char *dir,
mcp_buf *findings, int *first, int *count)
{
DIR *d = opendir(dir);
struct dirent *ent;
if (d == NULL)
return;
while ((ent = readdir(d)) != NULL) {
char full[1400];
if (ent->d_name[0] == '.')
continue;
snprintf(full, sizeof(full), "%.1024s/%.255s", dir, ent->d_name);
if (strstr(ent->d_name, "tlog") == NULL)
continue;
tlog_scan_file(st, full, findings, first, count);
}
closedir(d);
}
static void t_tlog_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
struct tlog_state st;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/tlog/tlog-rec-session.conf",
"/etc/tlog/tlog-rec.conf", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
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), "%.400s%s", root, files[i]);
tlog_scan_file(&st, path, &findings, &first, &count);
}
snprintf(path, sizeof(path), "%.400s/etc/sssd/conf.d", root);
tlog_scan_dir(&st, path, &findings, &first, &count);
if (st.files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a tlog configuration");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"tlog records the session scope, warns the user via wall "
"and has a log target");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"scope_no_session\":%d,"
"\"notice_no_wall\":%d,\"no_log\":%d,"
"\"world_writable\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.scope_no_session, st.notice_no_wall,
st.no_log, st.world_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);
}
/* ---------------------------------------------------------------- abrt_audit */
/* abrt reports crashes. A URL in AutoreportingEnabled=yes sends them off the
* host; an entries list pointing at a public central collector leaks process
* memory, and a world-writable abrt.conf decides what runs with root rights
* (the -M style hooks are configured there). */
struct abrt_state {
int files;
int autoreport;
int public_target;
int no_auth;
int world_writable;
};
static int abrt_public_target(const char *url)
{
/* localhost, 127.0.0.0/8, ::1 and .local names stay on the host. */
if (strstr(url, "localhost") != NULL || strstr(url, "127.0.0.1") != NULL)
return 0;
if (strstr(url, "[::1]") != NULL || strstr(url, ".local") != NULL)
return 0;
return 1;
}
static void abrt_scan_file(struct abrt_state *st, const char *path,
mcp_buf *findings, int *first, int *count)
{
static char text[65536];
struct stat sb;
char value[512];
if (read_text(path, text, sizeof(text)) <= 0)
return;
st->files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st->world_writable++;
add_finding(findings, first, "world-writable", "high",
"%s is writable by any local user; it decides where "
"crash dumps go and what abrt runs on them", path);
(*count)++;
}
if (ini_value(text, "Common", "AutoreportingEnabled", value,
sizeof(value)) == 1 && strcmp(value, "yes") == 0) {
st->autoreport++;
add_finding(findings, first, "autoreporting", "low",
"%s has AutoreportingEnabled=yes; every crash is sent "
"off the host without a human in between", path);
(*count)++;
}
if (ini_value(text, "Common", "URL", value, sizeof(value)) == 1) {
if (abrt_public_target(value)) {
st->public_target++;
add_finding(findings, first, "public-report-target", "high",
"%s sends crash dumps to %s, which is not a local "
"collector; process memory leaves the host", path,
value);
(*count)++;
}
}
if (ini_value(text, "Common", "AutoreportingEvent", value,
sizeof(value)) == 1 && strstr(value, "report") != NULL &&
strstr(text, "SSLVerify") == NULL) {
st->no_auth++;
add_finding(findings, first, "no-tls-verify", "medium",
"%s uploads crash reports but does not set SSLVerify; a "
"gateway can read the upload", path);
(*count)++;
}
}
static void t_abrt_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
struct abrt_state st;
int first = 1;
int count = 0;
int i;
static const char *files[] = {
"/etc/abrt/abrt.conf",
"/etc/abrt/abrt-action-save-package-data.conf", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
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), "%.400s%s", root, files[i]);
abrt_scan_file(&st, path, &findings, &first, &count);
}
if (st.files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read an abrt configuration");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"abrt does not auto-report, targets no public collector "
"and keeps a read-only configuration");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"autoreporting\":%d,"
"\"public_target\":%d,\"no_tls_verify\":%d,"
"\"world_writable\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.autoreport, st.public_target, st.no_auth,
st.world_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, "
@@ -29892,6 +30338,33 @@ const mcp_tool TOOLS_BLUE[] = {
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default "
"empty\"}}}",
t_fwupd_audit },
{ "smartd_audit",
"Parse smartd.conf (root prefix): DEVICESCAN without -d or -H (the "
"device type is guessed), a monitored device without -m, an -M exec "
"script that is writable by every local user, and a writable "
"configuration file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default "
"empty\"}}}",
t_smartd_audit },
{ "tlog_audit",
"Parse tlog configuration (root prefix): tlog-rec-session.conf, "
"tlog-rec.conf and the sssd conf.d tlog drop-ins. Flags a scope "
"without session, a notice without wall, a missing log target and a "
"writable configuration file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default "
"empty\"}}}",
t_tlog_audit },
{ "abrt_audit",
"Parse abrt configuration (root prefix): abrt.conf and "
"abrt-action-save-package-data.conf. Flags AutoreportingEnabled=yes, "
"a report URL that is not a local collector, a report upload without "
"SSLVerify and a writable configuration file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default "
"empty\"}}}",
t_abrt_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+103
View File
@@ -9025,6 +9025,98 @@ static void t_datasette_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ------------------------------------------------------------- nomad_probe */
/* Nomad's HTTP API is unauthenticated unless an ACL system is enabled. A 2xx
* on /v1/jobs without a token names every deployed job and its namespace, so
* the body is saved as evidence; /v1/agent/self only proves the endpoint is a
* Nomad agent. */
static void t_nomad_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/v1/agent/self", "/v1/jobs",
"/v1/nodes", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 4646);
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 jobs_open = 0;
int acl_enabled = 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, "nomad_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 is_jobs = strcmp(paths[i], "/v1/jobs") == 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 && strstr(paths[i], "agent/self") != NULL &&
resp != NULL &&
strstr(resp, "\"ACLEnabled\":true") != NULL)
acl_enabled = 1;
if (open && is_jobs) {
jobs_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("nomad-jobs", 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,"
"\"jobs_open\":%s,\"acl_enabled\":%s,\"evidence\":",
tested, open_count, jobs_open ? "true" : "false",
acl_enabled ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("nomad_probe", target, port, !jobs_open,
jobs_open
? "the Nomad job list answers without a token"
: "the Nomad job list requires a token", "list");
mcp_reply_json(c, b.p);
free(evidence);
mcp_buf_free(&b);
}
/* ---------------------------------------------------------------- vault_probe */
/* HashiCorp Vault on 8200. /v1/sys/seal-status answers without a token on
@@ -10579,6 +10671,17 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_vault_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 "
"and without ACLs; the body is saved as evidence. The ACL flag is "
"reported from the agent info.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 4646\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_nomad_probe },
{ "airflow_probe",
"Query Airflow on 8080 without credentials: /api/v1/version and "
"/api/v1/dags. A 2xx on the DAG list means the whole DAG inventory is "
+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 = 378
EXPECTED_TOOLS = 382
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
+187 -2
View File
@@ -134,7 +134,7 @@ res, _ = run([
], home=empty)
check("tools/list answers", any(r.get("id") == 1 for r in res))
tools = [r for r in res if r.get("id") == 1][0]["result"]["tools"]
check("378 tools registered", len(tools) == 378, len(tools))
check("382 tools registered", len(tools) == 382, 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"]) == 378)
check("http tools/list", len(listing["result"]["tools"]) == 382)
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
@@ -17015,6 +17015,191 @@ for d in (dh_root, dh_good_root, ju_root, ju_good_root, fw_root,
shutil.rmtree(d, ignore_errors=True)
# --- 1.87.0: smartd, tlog and abrt audits plus the Nomad probe ---
print("\n== smartd, tlog, abrt and Nomad ==")
sm_root = tempfile.mkdtemp(prefix="apex-sm-")
os.makedirs(os.path.join(sm_root, "etc"))
sm_script = os.path.join(sm_root, "smarthook.sh")
with open(sm_script, "w") as f:
f.write("#!/bin/sh\necho failing disk\n")
os.chmod(sm_script, 0o666)
sm_conf = os.path.join(sm_root, "etc", "smartd.conf")
with open(sm_conf, "w") as f:
f.write("DEVICESCAN -d sat\n")
f.write("/dev/sdb -m root@example.test -M exec %s\n" % sm_script)
f.write("/dev/sdc -a\n")
os.chmod(sm_conf, 0o666)
sm_good_root = tempfile.mkdtemp(prefix="apex-smg-")
os.makedirs(os.path.join(sm_good_root, "etc"))
smg_conf = os.path.join(sm_good_root, "etc", "smartd.conf")
with open(smg_conf, "w") as f:
f.write("DEVICESCAN -d sat -m root@example.test\n")
f.write("/dev/sdb -m admin@example.test -M exec /usr/local/bin/notify\n")
os.chmod(smg_conf, 0o644)
tl_root = tempfile.mkdtemp(prefix="apex-tl-")
os.makedirs(os.path.join(tl_root, "etc", "tlog"))
tl_conf = os.path.join(tl_root, "etc", "tlog", "tlog-rec-session.conf")
with open(tl_conf, "w") as f:
f.write('{\n "schema": "file",\n')
f.write(' "scope": "io",\n')
f.write(' "notice": "log",\n')
f.write(' "log": {"file": "/var/log/tlog"}\n}\n')
os.chmod(tl_conf, 0o666)
tl_good_root = tempfile.mkdtemp(prefix="apex-tlg-")
os.makedirs(os.path.join(tl_good_root, "etc", "tlog",
"conf.d", "sssd"))
tlg_conf = os.path.join(tl_good_root, "etc", "tlog",
"tlog-rec-session.conf")
with open(tlg_conf, "w") as f:
f.write('{\n "scope": "session",\n')
f.write(' "notice": "wall",\n')
f.write(' "log": {"file": "/var/log/tlog/session.log"}\n}\n')
os.chmod(tlg_conf, 0o644)
ab_root = tempfile.mkdtemp(prefix="apex-ab-")
os.makedirs(os.path.join(ab_root, "etc", "abrt"))
ab_conf = os.path.join(ab_root, "etc", "abrt", "abrt.conf")
with open(ab_conf, "w") as f:
f.write("[Common]\n")
f.write("AutoreportingEnabled=yes\n")
f.write("URL=https://crash.example.test/submit\n")
f.write("AutoreportingEvent=report_uReport\n")
os.chmod(ab_conf, 0o666)
ab_good_root = tempfile.mkdtemp(prefix="apex-abg-")
os.makedirs(os.path.join(ab_good_root, "etc", "abrt"))
abg_conf = os.path.join(ab_good_root, "etc", "abrt", "abrt.conf")
with open(abg_conf, "w") as f:
f.write("[Common]\n")
f.write("AutoreportingEnabled=no\n")
f.write("URL=http://127.0.0.1:8080/submit\n")
f.write("SSLVerify=yes\n")
os.chmod(abg_conf, 0o644)
class _NomadHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/v1/agent/self":
body = (b'{"member":{"Name":"nomad-1"},'
b'"config":{"ACL":{"Enabled":false}}}')
self.send_response(200)
elif path == "/v1/jobs":
body = (b'[{"ID":"web","Name":"web","Namespace":"default",'
b'"Status":"running"}]')
self.send_response(200)
elif path == "/v1/nodes":
body = b'[{"ID":"11111111-2222","Name":"nomad-1"}]'
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 _NomadACLHandler(_NomadHandler):
def do_GET(self):
body = b'{"errors":["ACL token required"]}'
self.send_response(403)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
nm_srv = http.server.HTTPServer(("127.0.0.1", 0), _NomadHandler)
nm_port = nm_srv.server_address[1]
nm_acl_srv = http.server.HTTPServer(("127.0.0.1", 0), _NomadACLHandler)
nm_acl_port = nm_acl_srv.server_address[1]
for _s in (nm_srv, nm_acl_srv):
threading.Thread(target=_s.serve_forever, daemon=True).start()
cfg58_home = tempfile.mkdtemp(prefix="apex-cfg58-home-")
write_scope(cfg58_home,
{"label": "cfg58", "expires": "2099-01-01T00:00:00Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": ["1-65535"]})
res, _ = run([
call(1, "smartd_audit", root=sm_root),
call(2, "smartd_audit", root=sm_good_root),
call(3, "tlog_audit", root=tl_root),
call(4, "tlog_audit", root=tl_good_root),
call(5, "abrt_audit", root=ab_root),
call(6, "abrt_audit", root=ab_good_root),
call(7, "nomad_probe", target="127.0.0.1", port=nm_port, tls=False),
call(8, "nomad_probe", target="127.0.0.1", port=nm_acl_port, tls=False),
], home=cfg58_home)
by_id = {r["id"]: r for r in res if "id" in r}
sm = json.loads(text(by_id[1]))
sm_kinds = {f["id"] for f in sm["findings"]}
check("smartd_audit flags a device without mail, a writable exec hook and a "
"writable config",
{"no-mail", "writable-exec", "world-writable"} <= sm_kinds and
sm["devices"] == 3 and sm["exec_scripts"] == 1 and
sm["writable_exec"] == 1, sm)
sm_good = json.loads(text(by_id[2]))
check("smartd_audit accepts a typed scan with mail addresses",
sm_good["findings_count"] == 0 and
sm_good["findings"][0]["id"] == "no-findings" and
sm_good["devicescan_untyped"] == 0 and sm_good["no_mail"] == 0,
sm_good)
tl = json.loads(text(by_id[3]))
tl_kinds = {f["id"] for f in tl["findings"]}
check("tlog_audit flags a scope without session, a notice without wall and a "
"writable file",
{"scope-no-session", "notice-no-wall", "world-writable"} <= tl_kinds and
tl["scope_no_session"] == 1 and tl["no_log"] == 0, tl)
tl_good = json.loads(text(by_id[4]))
check("tlog_audit accepts the session scope with wall and a log target",
tl_good["findings_count"] == 0 and
tl_good["findings"][0]["id"] == "no-findings" and
tl_good["scope_no_session"] == 0 and tl_good["notice_no_wall"] == 0,
tl_good)
ab = json.loads(text(by_id[5]))
ab_kinds = {f["id"] for f in ab["findings"]}
check("abrt_audit flags autoreporting to a public collector and a writable "
"config",
{"autoreporting", "public-report-target", "no-tls-verify",
"world-writable"} <= ab_kinds and
ab["autoreporting"] == 1 and ab["public_target"] == 1, ab)
ab_good = json.loads(text(by_id[6]))
check("abrt_audit accepts manual reporting to a local collector",
ab_good["findings_count"] == 0 and
ab_good["findings"][0]["id"] == "no-findings" and
ab_good["autoreporting"] == 0 and ab_good["public_target"] == 0,
ab_good)
nm = json.loads(text(by_id[7]))
check("nomad_probe finds an open job list and saves evidence",
nm["jobs_open"] is True and nm["open_count"] == 3 and
nm["acl_enabled"] is False and os.path.isfile(nm["evidence"]) and
"web" in open(nm["evidence"]).read(), nm)
nm_acl = json.loads(text(by_id[8]))
check("nomad_probe reports an ACL-protected job list as not open",
nm_acl["jobs_open"] is False and nm_acl["evidence"] is None and
all(e["open"] is False for e in nm_acl["endpoints"]), nm_acl)
nm_srv.shutdown()
nm_acl_srv.shutdown()
for d in (sm_root, sm_good_root, tl_root, tl_good_root, ab_root,
ab_good_root, cfg58_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.84.0: gated wrappers for external scanners (mock binaries) ---
print("\n== external scanner wrappers ==\n")