apex-twin 1.54.0: Zabbix, NRPE and unattended-upgrades audits, RabbitMQ probe
Blue: - zabbix_audit: zabbix_agentd.conf: Server=0.0.0.0/0, remote commands and their logging, TLSConnect unencrypted, shell metacharacters in a UserParameter. - nrpe_audit: nrpe.cfg: allowed_hosts covering every address, dont_blame_nrpe=1 and check commands with shell metacharacters. - unattended_upgrades_audit: 50unattended-upgrades: security-only origins, automatic reboot disabled or unset, no mail recipient. Red: - rabbitmq_management_probe: /api/overview and /api/queues without credentials; a 2xx overview with rabbitmq_version is an open management API and is saved as evidence. Tests with Zabbix/NRPE/unattended-upgrades trees and two RabbitMQ fixtures (open and 401). 1108 checks, ASan suite green, analyze clean, release-check green including distcheck 1.54.0.
This commit is contained in:
1 parent
34ac87b20f
commit
a388415735
9 files changed
+668
-15
No files matched your search
+17
-1
@@ -8,7 +8,23 @@ 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.53.0 — 2026-11-23 — this change
|
||||
## 1.54.0 — 2026-11-23 — this change
|
||||
|
||||
- **Zabbix** (`zabbix_audit`): `zabbix_agentd.conf`: `Server=0.0.0.0/0`,
|
||||
`EnableRemoteCommands=1`, `LogRemoteCommands=1`, `TLSConnect=unencrypted`
|
||||
and a `UserParameter` with shell metacharacters.
|
||||
- **NRPE** (`nrpe_audit`): `nrpe.cfg`: an `allowed_hosts` covering every
|
||||
address, `dont_blame_nrpe=1` and check commands with shell metacharacters.
|
||||
- **unattended-upgrades** (`unattended_upgrades_audit`):
|
||||
`50unattended-upgrades`: security-only origins, automatic reboot disabled
|
||||
or unset, and no mail recipient.
|
||||
- **RabbitMQ** (`rabbitmq_management_probe`): `/api/overview` and
|
||||
`/api/queues` without credentials; a 2xx overview with `rabbitmq_version`
|
||||
is an open management API, saved as evidence.
|
||||
- Tests with Zabbix/NRPE/unattended-upgrades trees and two RabbitMQ HTTP
|
||||
fixtures (open and 401). 1108 checks. Coverage 83.6%.
|
||||
|
||||
## 1.53.0 — 2026-11-23 — 34ac87b
|
||||
|
||||
- **Gitea** (`gitea_audit`): `app.ini` from three homes: `PROTOCOL = http`,
|
||||
`INSTALL_LOCK = false`, an empty or default `SECRET_KEY`,
|
||||
|
||||
@@ -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.
|
||||
|
||||
**250 tools · 1096 end-to-end checks · 340 fuzz cases · 83.5% line coverage · ~896 KiB**
|
||||
**254 tools · 1108 end-to-end checks · 340 fuzz cases · 83.6% line coverage · ~904 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.53.0","tools":250,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.54.0","tools":254,...,"scope":{"loaded":true,...}}
|
||||
```
|
||||
|
||||
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
|
||||
@@ -149,7 +149,7 @@ closes a request whose head or body does not arrive within
|
||||
|
||||
---
|
||||
|
||||
## Tools (250)
|
||||
## Tools (254)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -212,6 +212,7 @@ uploads and secret-file reads. It does not execute anything.
|
||||
| `consul_api_probe` | `/v1/agent/self` and `/v1/catalog/services` without a token |
|
||||
| `couchdb_probe` | `/` welcome and `/_all_dbs` without auth; database list as evidence |
|
||||
| `prometheus_api_probe` | `/-/ready` and `/api/v1/query` without auth; query answer as evidence |
|
||||
| `rabbitmq_management_probe` | `/api/overview` and `/api/queues` without auth; overview 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 |
|
||||
@@ -447,6 +448,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `gitea_audit` | app.ini: HTTP, open installer, empty SECRET_KEY |
|
||||
| `minio_audit` | minio defaults: default root credentials, browser, HTTP |
|
||||
| `nextcloud_audit` | config.php: debug, wildcard domain, HTTP, writable data |
|
||||
| `zabbix_audit` | agent: any Server, remote commands, no TLS, unsafe UserParameter |
|
||||
| `nrpe_audit` | nrpe.cfg: any allowed host, dont_blame_nrpe, shell commands |
|
||||
| `unattended_upgrades_audit` | security-only origins, no auto reboot, no mail |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -741,6 +745,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| CouchDB | two unauthenticated GETs, database list as evidence |
|
||||
| gitea/minio/nextcloud | config reads only; optional root prefix |
|
||||
| Prometheus API | two unauthenticated GETs, query answer as evidence |
|
||||
| zabbix/nrpe/unattended-upgrades | config reads only; optional root prefix |
|
||||
| RabbitMQ API | two unauthenticated GETs, overview as evidence |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -752,7 +758,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 1096 end-to-end checks
|
||||
make test # version check + gate audit + 1108 end-to-end checks
|
||||
make version-check # the five places that carry a version must agree
|
||||
make gate-audit # static: every target-taking tool calls the gate
|
||||
make asan # apex-twin-asan with ASan + UBSan
|
||||
@@ -878,7 +884,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
tls_hostname_check, ftp_tls_probe,
|
||||
zookeeper_4lw_probe, etcd_api_probe,
|
||||
docker_registry_probe, consul_api_probe,
|
||||
couchdb_probe, prometheus_api_probe
|
||||
couchdb_probe, prometheus_api_probe,
|
||||
rabbitmq_management_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,
|
||||
@@ -921,7 +928,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.53.0. Built and run: 250 tools, 1096 checks, 340 fuzz cases and 83.5% line
|
||||
1.54.0. Built and run: 254 tools, 1108 checks, 340 fuzz cases and 83.6% 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
|
||||
|
||||
+3
-1
@@ -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.53.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.54.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.
|
||||
@@ -66,6 +66,8 @@ only narrow what the proxy does (the scope gate still runs first).
|
||||
- **Firmware writing needs an explicit confirmation.** `esp_flash` refuses
|
||||
without `confirm=true`, validates an absolute image path and audits the
|
||||
attempt; it exists to provision the operator's own board.
|
||||
- **Zabbix, NRPE and unattended-upgrades audits read local files.** The
|
||||
RabbitMQ probe sends two unauthenticated GETs and saves the overview.
|
||||
- **Gitea, MinIO and Nextcloud audits read local files.** The Prometheus
|
||||
probe sends two unauthenticated GETs and saves the query answer as evidence.
|
||||
- **Caddy, Traefik and autofs audits read local files.** The CouchDB probe
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.53.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.54.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),
|
||||
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),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -71,7 +71,8 @@ coredump_audit, nftables_audit, dnsmasq_audit, nsswitch_audit,
|
||||
jenkins_audit, pgbouncer_audit, xinetd_audit, sssd_audit, avahi_audit, logind_audit,
|
||||
tftpd_hpa_audit, iscsi_audit, rpcbind_audit, kdump_audit, kafka_audit, powerdns_audit,
|
||||
varnish_audit, freeradius_audit, containerd_audit, nats_audit, caddy_audit, traefik_audit,
|
||||
autofs_audit, gitea_audit, minio_audit, nextcloud_audit)
|
||||
autofs_audit, gitea_audit, minio_audit, nextcloud_audit, zabbix_audit, nrpe_audit,
|
||||
unattended_upgrades_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
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.53.0"
|
||||
#define APEX_VERSION "1.54.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -16086,6 +16086,303 @@ static void t_nextcloud_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- zabbix_audit */
|
||||
|
||||
static void t_zabbix_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];
|
||||
char server[256];
|
||||
char value[64];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int server_any = 0;
|
||||
int remote_commands = 0;
|
||||
int log_remote = 0;
|
||||
int no_tls = 0;
|
||||
int unsafe_param = 0;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(path, sizeof(path), "%s/etc/zabbix/zabbix_agentd.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read zabbix_agentd.conf");
|
||||
return;
|
||||
}
|
||||
server[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"zabbix_agentd.conf is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
conf_value(text, "Server", server, sizeof(server));
|
||||
if (strstr(server, "0.0.0.0/0") != NULL ||
|
||||
strstr(server, "::/0") != NULL ||
|
||||
strcmp(server, "0.0.0.0") == 0) {
|
||||
server_any = 1;
|
||||
add_finding(&findings, &first, "server-any", "high",
|
||||
"any host may poll the agent");
|
||||
count++;
|
||||
}
|
||||
if (conf_value(text, "EnableRemoteCommands", value, sizeof(value)) &&
|
||||
strcmp(value, "1") == 0) {
|
||||
remote_commands = 1;
|
||||
add_finding(&findings, &first, "remote-commands", "high",
|
||||
"remote commands are enabled");
|
||||
count++;
|
||||
}
|
||||
if (conf_value(text, "LogRemoteCommands", value, sizeof(value)) &&
|
||||
strcmp(value, "1") == 0) {
|
||||
log_remote = 1;
|
||||
add_finding(&findings, &first, "log-remote-commands", "low",
|
||||
"remote commands are logged to the agent log");
|
||||
count++;
|
||||
}
|
||||
if (!conf_value(text, "TLSConnect", value, sizeof(value)) ||
|
||||
strcasecmp(value, "unencrypted") == 0) {
|
||||
no_tls = 1;
|
||||
add_finding(&findings, &first, "no-tls", "medium",
|
||||
"the agent accepts unencrypted connections");
|
||||
count++;
|
||||
}
|
||||
if (text_has_line(text, "UserParameter", "|") ||
|
||||
text_has_line(text, "UserParameter", ";") ||
|
||||
text_has_line(text, "UserParameter", "$(") ||
|
||||
text_has_line(text, "UserParameter", "`")) {
|
||||
unsafe_param = 1;
|
||||
add_finding(&findings, &first, "unsafe-userparameter",
|
||||
"medium",
|
||||
"a UserParameter runs shell metacharacters");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"server\":");
|
||||
apex_json_str(&b, server);
|
||||
mcp_buf_printf(&b, ",\"server_any\":%s,\"remote_commands\":%s,"
|
||||
"\"log_remote_commands\":%s,\"tls\":%s,"
|
||||
"\"unsafe_userparameter\":%s,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
server_any ? "true" : "false",
|
||||
remote_commands ? "true" : "false",
|
||||
log_remote ? "true" : "false",
|
||||
no_tls ? "false" : "true",
|
||||
unsafe_param ? "true" : "false", 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);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- nrpe_audit */
|
||||
|
||||
static int nrpe_shell_meta(const char *text)
|
||||
{
|
||||
char *copy = strdup(text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
int found = 0;
|
||||
|
||||
if (copy == NULL)
|
||||
return 0;
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *s = line;
|
||||
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s != '#' && strncmp(s, "command[", 8) == 0 &&
|
||||
(strstr(s, ";") != NULL || strstr(s, "|") != NULL ||
|
||||
strstr(s, "$(") != NULL || strstr(s, "`") != NULL ||
|
||||
strstr(s, "&&") != NULL)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
return found;
|
||||
}
|
||||
|
||||
static void t_nrpe_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *files[] = { "/etc/nagios/nrpe.cfg",
|
||||
"/etc/nrpe.cfg", NULL };
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char path[1024];
|
||||
static char text[65536];
|
||||
char allowed[256];
|
||||
char value[64];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files_read = 0;
|
||||
int allowed_any = 0;
|
||||
int dont_blame = 0;
|
||||
int shell = 0;
|
||||
int i;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
allowed[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
for (i = 0; files[i] != NULL; i++) {
|
||||
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
|
||||
if (read_text(path, text, sizeof(text)) <= 0)
|
||||
continue;
|
||||
files_read++;
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"%s is writable by anyone", path);
|
||||
count++;
|
||||
}
|
||||
conf_value(text, "allowed_hosts", allowed, sizeof(allowed));
|
||||
if (strstr(allowed, "0.0.0.0/0") != NULL ||
|
||||
strstr(allowed, "::/0") != NULL ||
|
||||
strcmp(allowed, "*") == 0)
|
||||
allowed_any = 1;
|
||||
if (conf_value(text, "dont_blame_nrpe", value, sizeof(value)) &&
|
||||
strcmp(value, "1") == 0)
|
||||
dont_blame = 1;
|
||||
if (nrpe_shell_meta(text))
|
||||
shell = 1;
|
||||
break;
|
||||
}
|
||||
if (files_read == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read an NRPE configuration");
|
||||
return;
|
||||
}
|
||||
if (allowed_any) {
|
||||
add_finding(&findings, &first, "allowed-any", "high",
|
||||
"any host may query NRPE");
|
||||
count++;
|
||||
}
|
||||
if (dont_blame) {
|
||||
add_finding(&findings, &first, "dont-blame", "high",
|
||||
"client-supplied command arguments are allowed");
|
||||
count++;
|
||||
}
|
||||
if (shell) {
|
||||
add_finding(&findings, &first, "shell-command", "medium",
|
||||
"a check command relies on shell metacharacters");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"allowed_hosts\":");
|
||||
apex_json_str(&b, allowed);
|
||||
mcp_buf_printf(&b, ",\"allowed_any\":%s,\"dont_blame_nrpe\":%s,"
|
||||
"\"shell_command\":%s,\"findings_count\":%d,"
|
||||
"\"findings\":[",
|
||||
allowed_any ? "true" : "false",
|
||||
dont_blame ? "true" : "false",
|
||||
shell ? "true" : "false", 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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------- unattended_upgrades_audit */
|
||||
|
||||
static void t_unattended_upgrades_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];
|
||||
char value[128];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int security_only = 0;
|
||||
int no_reboot = 0;
|
||||
int no_mail = 0;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(path, sizeof(path),
|
||||
"%s/etc/apt/apt.conf.d/50unattended-upgrades", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read 50unattended-upgrades");
|
||||
return;
|
||||
}
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"50unattended-upgrades is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
if (strstr(text, "-security") != NULL &&
|
||||
strstr(text, "-updates") == NULL) {
|
||||
security_only = 1;
|
||||
add_finding(&findings, &first, "security-only", "low",
|
||||
"only security updates are installed automatically");
|
||||
count++;
|
||||
}
|
||||
if (!conf_value(text, "Unattended-Upgrade::Automatic-Reboot", value,
|
||||
sizeof(value)) ||
|
||||
strcasecmp(value, "false") == 0) {
|
||||
no_reboot = 1;
|
||||
add_finding(&findings, &first, "no-auto-reboot", "low",
|
||||
"automatic reboots are disabled or unset");
|
||||
count++;
|
||||
}
|
||||
if (!conf_value(text, "Unattended-Upgrade::Mail", value,
|
||||
sizeof(value)) ||
|
||||
value[0] == '\0') {
|
||||
no_mail = 1;
|
||||
add_finding(&findings, &first, "no-mail", "low",
|
||||
"no mail recipient is configured");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"security_only\":%s,\"auto_reboot\":%s,"
|
||||
"\"mail\":%s,\"findings_count\":%d,\"findings\":[",
|
||||
security_only ? "true" : "false",
|
||||
no_reboot ? "false" : "true",
|
||||
no_mail ? "false" : "true", 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, "
|
||||
@@ -16974,6 +17271,26 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_nextcloud_audit },
|
||||
{ "zabbix_audit",
|
||||
"Parse zabbix_agentd.conf (root prefix): Server=0.0.0.0/0, remote "
|
||||
"commands (and their logging), TLSConnect unencrypted and shell "
|
||||
"metacharacters in a UserParameter. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_zabbix_audit },
|
||||
{ "nrpe_audit",
|
||||
"Parse nrpe.cfg (root prefix, two usual paths): allowed_hosts covering "
|
||||
"every address, dont_blame_nrpe=1 and command definitions with shell "
|
||||
"metacharacters. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_nrpe_audit },
|
||||
{ "unattended_upgrades_audit",
|
||||
"Parse 50unattended-upgrades (root prefix): security-only origins, no "
|
||||
"automatic reboot and no mail recipient. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_unattended_upgrades_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
+123
@@ -6884,6 +6884,119 @@ static void t_prometheus_api_probe(mcp_conn *c, const mcp_json *args,
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------- rabbitmq_management_probe */
|
||||
|
||||
static void t_rabbitmq_management_probe(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
static const char *paths[] = { "/api/overview", "/api/queues", NULL };
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 15672);
|
||||
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port));
|
||||
char version[64];
|
||||
mcp_buf b;
|
||||
int first = 1;
|
||||
int tested = 0;
|
||||
int open_count = 0;
|
||||
int overview_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, "rabbitmq_management_probe", target, port))
|
||||
return;
|
||||
version[0] = '\0';
|
||||
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 has_version = 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 && resp != NULL &&
|
||||
find_bytes(resp, len, "rabbitmq_version"))
|
||||
has_version = 1;
|
||||
if (open)
|
||||
open_count++;
|
||||
if (open && strcmp(paths[i], "/api/overview") == 0 &&
|
||||
has_version) {
|
||||
overview_open = 1;
|
||||
if (evidence == NULL) {
|
||||
const char *p = NULL;
|
||||
|
||||
evidence = apex_evidence_save("rabbitmq-overview",
|
||||
resp, len);
|
||||
if (resp != NULL &&
|
||||
(p = strstr(resp,
|
||||
"\"rabbitmq_version\"")) != NULL) {
|
||||
p = strchr(p + 18, '"');
|
||||
if (p != NULL) {
|
||||
size_t k = 0;
|
||||
|
||||
p++;
|
||||
while (p[k] != '\0' && p[k] != '"' &&
|
||||
k + 1 < sizeof(version)) {
|
||||
version[k] = p[k];
|
||||
k++;
|
||||
}
|
||||
version[k] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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,"
|
||||
"\"version\":%s}",
|
||||
code, (unsigned long)len,
|
||||
open ? "true" : "false",
|
||||
has_version ? "true" : "false");
|
||||
free(resp);
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d,"
|
||||
"\"overview_open\":%s,\"version\":", tested, open_count,
|
||||
overview_open ? "true" : "false");
|
||||
apex_json_str(&b, version);
|
||||
mcp_buf_puts(&b, ",\"evidence\":");
|
||||
if (evidence != NULL)
|
||||
apex_json_str(&b, evidence);
|
||||
else
|
||||
mcp_buf_puts(&b, "null");
|
||||
mcp_buf_puts(&b, "}");
|
||||
apex_audit("rabbitmq_management_probe", target, port, !overview_open,
|
||||
overview_open
|
||||
? "the management API answers without authentication"
|
||||
: "the management 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: "
|
||||
@@ -7457,6 +7570,16 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_prometheus_api_probe },
|
||||
{ "rabbitmq_management_probe",
|
||||
"Query the RabbitMQ management API without credentials: /api/overview "
|
||||
"and /api/queues. A 2xx overview with rabbitmq_version is an open "
|
||||
"management API; the answer is saved as evidence. Gate: the target.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 15672\"},"
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_rabbitmq_management_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
@@ -21,7 +21,7 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 250
|
||||
EXPECTED_TOOLS = 254
|
||||
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.
|
||||
|
||||
+189
-2
@@ -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("250 tools registered", len(tools) == 250, len(tools))
|
||||
check("254 tools registered", len(tools) == 254, 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"]) == 250)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 254)
|
||||
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
|
||||
@@ -11463,6 +11463,192 @@ shutil.rmtree(nc_root, ignore_errors=True)
|
||||
shutil.rmtree(nc_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg25_home, ignore_errors=True)
|
||||
|
||||
print("\n== Zabbix, NRPE, unattended-upgrades and RabbitMQ ==\n")
|
||||
|
||||
zb_root = tempfile.mkdtemp(prefix="apex-zb-")
|
||||
os.makedirs(os.path.join(zb_root, "etc", "zabbix"))
|
||||
zb_bad = os.path.join(zb_root, "etc", "zabbix", "zabbix_agentd.conf")
|
||||
with open(zb_bad, "w") as f:
|
||||
f.write("Server=0.0.0.0/0\n")
|
||||
f.write("EnableRemoteCommands=1\n")
|
||||
f.write("LogRemoteCommands=1\n")
|
||||
f.write("TLSConnect=unencrypted\n")
|
||||
f.write("UserParameter=foo,cat /etc/passwd | head\n")
|
||||
os.chmod(zb_bad, 0o666)
|
||||
zb_good_root = tempfile.mkdtemp(prefix="apex-zbg-")
|
||||
os.makedirs(os.path.join(zb_good_root, "etc", "zabbix"))
|
||||
with open(os.path.join(zb_good_root, "etc", "zabbix",
|
||||
"zabbix_agentd.conf"), "w") as f:
|
||||
f.write("Server=10.0.0.5\n")
|
||||
f.write("EnableRemoteCommands=0\n")
|
||||
f.write("TLSConnect=psk\n")
|
||||
f.write("TLSAccept=psk\n")
|
||||
f.write("UserParameter=load,uptime\n")
|
||||
|
||||
nr_root = tempfile.mkdtemp(prefix="apex-nr-")
|
||||
os.makedirs(os.path.join(nr_root, "etc", "nagios"))
|
||||
nr_bad = os.path.join(nr_root, "etc", "nagios", "nrpe.cfg")
|
||||
with open(nr_bad, "w") as f:
|
||||
f.write("allowed_hosts=0.0.0.0/0\n")
|
||||
f.write("dont_blame_nrpe=1\n")
|
||||
f.write("command[check_disk]=/usr/lib/nagios/plugins/check_disk "
|
||||
"-w 10% ; rm -rf /tmp/x\n")
|
||||
os.chmod(nr_bad, 0o666)
|
||||
nr_good_root = tempfile.mkdtemp(prefix="apex-nrg-")
|
||||
os.makedirs(os.path.join(nr_good_root, "etc", "nagios"))
|
||||
with open(os.path.join(nr_good_root, "etc", "nagios", "nrpe.cfg"),
|
||||
"w") as f:
|
||||
f.write("allowed_hosts=127.0.0.1,10.0.0.5\n")
|
||||
f.write("dont_blame_nrpe=0\n")
|
||||
f.write("command[check_disk]=/usr/lib/nagios/plugins/check_disk "
|
||||
"-w 10% -c 5%\n")
|
||||
|
||||
uu_root = tempfile.mkdtemp(prefix="apex-uu-")
|
||||
os.makedirs(os.path.join(uu_root, "etc", "apt", "apt.conf.d"))
|
||||
uu_bad = os.path.join(uu_root, "etc", "apt", "apt.conf.d",
|
||||
"50unattended-upgrades")
|
||||
with open(uu_bad, "w") as f:
|
||||
f.write("Unattended-Upgrade::Allowed-Origins {\n")
|
||||
f.write(' "${distro_id}:${distro_codename}-security";\n')
|
||||
f.write("};\n")
|
||||
f.write('Unattended-Upgrade::Automatic-Reboot "false";\n')
|
||||
os.chmod(uu_bad, 0o666)
|
||||
uu_good_root = tempfile.mkdtemp(prefix="apex-uug-")
|
||||
os.makedirs(os.path.join(uu_good_root, "etc", "apt", "apt.conf.d"))
|
||||
with open(os.path.join(uu_good_root, "etc", "apt", "apt.conf.d",
|
||||
"50unattended-upgrades"), "w") as f:
|
||||
f.write("Unattended-Upgrade::Allowed-Origins {\n")
|
||||
f.write(' "${distro_id}:${distro_codename}-security";\n')
|
||||
f.write(' "${distro_id}:${distro_codename}-updates";\n')
|
||||
f.write("};\n")
|
||||
f.write('Unattended-Upgrade::Automatic-Reboot "true";\n')
|
||||
f.write('Unattended-Upgrade::Mail "root";\n')
|
||||
|
||||
|
||||
class _RabbitHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
docs = {
|
||||
"/api/overview": b'{"rabbitmq_version":"3.12.0",'
|
||||
b'"cluster_name":"rabbit@test"}',
|
||||
"/api/queues": b"[]",
|
||||
}
|
||||
body = docs.get(path, b'{"error":"not_found"}')
|
||||
code = 200 if path in docs else 404
|
||||
self.send_response(code)
|
||||
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 _RabbitAuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
body = b'{"error":"not_authorised"}'
|
||||
self.send_response(401)
|
||||
self.send_header("WWW-Authenticate", 'Basic realm="RabbitMQ Management"')
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
rab_srv = http.server.HTTPServer(("127.0.0.1", 0), _RabbitHandler)
|
||||
rab_port = rab_srv.server_address[1]
|
||||
threading.Thread(target=rab_srv.serve_forever, daemon=True).start()
|
||||
rab_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
|
||||
_RabbitAuthHandler)
|
||||
rab_auth_port = rab_auth_srv.server_address[1]
|
||||
threading.Thread(target=rab_auth_srv.serve_forever, daemon=True).start()
|
||||
|
||||
cfg26_home = tempfile.mkdtemp(prefix="apex-cfg26-home-")
|
||||
write_scope(cfg26_home, {"label": "cfg26", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": [str(rab_port), str(rab_auth_port)]})
|
||||
res, _ = run([
|
||||
call(1, "zabbix_audit", root=zb_root),
|
||||
call(2, "zabbix_audit", root=zb_good_root),
|
||||
call(3, "nrpe_audit", root=nr_root),
|
||||
call(4, "nrpe_audit", root=nr_good_root),
|
||||
call(5, "unattended_upgrades_audit", root=uu_root),
|
||||
call(6, "unattended_upgrades_audit", root=uu_good_root),
|
||||
call(7, "rabbitmq_management_probe", target="127.0.0.1", port=rab_port,
|
||||
tls=False),
|
||||
call(8, "rabbitmq_management_probe", target="127.0.0.1",
|
||||
port=rab_auth_port, tls=False),
|
||||
call(9, "rabbitmq_management_probe", target="198.51.100.9", port=15672),
|
||||
call(10, "zabbix_audit", root="/nonexistent-zb"),
|
||||
call(11, "nrpe_audit", root="/nonexistent-nr"),
|
||||
call(12, "unattended_upgrades_audit", root="/nonexistent-uu"),
|
||||
], home=cfg26_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
zb = json.loads(text(by_id[1]))
|
||||
zb_kinds = {f["id"] for f in zb["findings"]}
|
||||
check("zabbix_audit flags any server, remote commands and no TLS",
|
||||
{"world-writable", "server-any", "remote-commands",
|
||||
"log-remote-commands", "no-tls", "unsafe-userparameter"} <=
|
||||
zb_kinds and zb["server_any"] is True and
|
||||
zb["remote_commands"] is True and zb["tls"] is False, zb)
|
||||
zb_good = json.loads(text(by_id[2]))
|
||||
check("zabbix_audit accepts a scoped PSK agent",
|
||||
zb_good["findings_count"] == 0 and zb_good["server_any"] is False and
|
||||
zb_good["remote_commands"] is False and zb_good["tls"] is True,
|
||||
zb_good)
|
||||
nr = json.loads(text(by_id[3]))
|
||||
nr_kinds = {f["id"] for f in nr["findings"]}
|
||||
check("nrpe_audit flags any host, dont_blame_nrpe and shell commands",
|
||||
{"world-writable", "allowed-any", "dont-blame", "shell-command"} <=
|
||||
nr_kinds and nr["allowed_any"] is True and
|
||||
nr["dont_blame_nrpe"] is True, nr)
|
||||
nr_good = json.loads(text(by_id[4]))
|
||||
check("nrpe_audit accepts a scoped configuration",
|
||||
nr_good["findings_count"] == 0 and nr_good["allowed_any"] is False and
|
||||
nr_good["dont_blame_nrpe"] is False, nr_good)
|
||||
uu = json.loads(text(by_id[5]))
|
||||
uu_kinds = {f["id"] for f in uu["findings"]}
|
||||
check("unattended_upgrades_audit flags security-only and no reboot/mail",
|
||||
{"world-writable", "security-only", "no-auto-reboot", "no-mail"} <=
|
||||
uu_kinds and uu["security_only"] is True and
|
||||
uu["auto_reboot"] is False, uu)
|
||||
uu_good = json.loads(text(by_id[6]))
|
||||
check("unattended_upgrades_audit accepts updates with reboot and mail",
|
||||
uu_good["findings_count"] == 0 and
|
||||
uu_good["security_only"] is False and uu_good["auto_reboot"] is True
|
||||
and uu_good["mail"] is True, uu_good)
|
||||
rab = json.loads(text(by_id[7]))
|
||||
check("rabbitmq_management_probe finds the open overview",
|
||||
rab["overview_open"] is True and rab["open_count"] == 2 and
|
||||
rab["version"] == "3.12.0" and rab["evidence"] and
|
||||
os.path.isfile(rab["evidence"]), rab)
|
||||
rab_auth = json.loads(text(by_id[8]))
|
||||
check("rabbitmq_management_probe reports a protected API",
|
||||
rab_auth["overview_open"] is False and
|
||||
all(e["status"] == 401 for e in rab_auth["endpoints"]), rab_auth)
|
||||
check("rabbitmq_management_probe refuses an out-of-scope target",
|
||||
err(by_id[9]), text(by_id[9]))
|
||||
check("zabbix_audit reports a missing config", err(by_id[10]),
|
||||
text(by_id[10]))
|
||||
check("nrpe_audit reports a missing config", err(by_id[11]),
|
||||
text(by_id[11]))
|
||||
check("unattended_upgrades_audit reports a missing config", err(by_id[12]),
|
||||
text(by_id[12]))
|
||||
rab_srv.shutdown()
|
||||
rab_srv.server_close()
|
||||
rab_auth_srv.shutdown()
|
||||
rab_auth_srv.server_close()
|
||||
shutil.rmtree(zb_root, ignore_errors=True)
|
||||
shutil.rmtree(zb_good_root, ignore_errors=True)
|
||||
shutil.rmtree(nr_root, ignore_errors=True)
|
||||
shutil.rmtree(nr_good_root, ignore_errors=True)
|
||||
shutil.rmtree(uu_root, ignore_errors=True)
|
||||
shutil.rmtree(uu_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg26_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
@@ -11478,6 +11664,7 @@ print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
|
||||
|
||||
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
|
||||
write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"})
|
||||
esp_m, esp_s = pty.openpty()
|
||||
|
||||
Reference in new issue
Block a user