apex-twin 1.57.0: Kibana, Nagios and Synapse audits, NATS monitoring probe
Blue: - kibana_audit: kibana.yml: server.host 0.0.0.0, xpack.security disabled, Elasticsearch credentials in the file, no TLS, world-writable. - nagios_audit: nagios.cfg and the cgi.cfg beside it: external commands, use_ssl_authentication=0, wildcard CGI authorization, a default user. - synapse_audit: homeserver.yaml: open registration without a token, no TLS listener, no trusted key servers. Red: - nats_monitoring_probe: /varz and /connz without credentials; a 2xx with a version is an open monitoring endpoint with evidence saved. Tests with Kibana/Nagios/Synapse trees and two NATS monitoring fixtures (open and 401). 1144 checks, ASan suite green, analyze clean, release-check green including distcheck 1.57.0.
This commit is contained in:
1 parent
2bbe0c206e
commit
ea69d8d92f
9 files changed
+682
-15
No files matched your search
+18
-1
@@ -8,7 +8,24 @@ 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.56.0 — 2026-11-23 — this change
|
||||
## 1.57.0 — 2026-11-23 — this change
|
||||
|
||||
- **Kibana** (`kibana_audit`): `kibana.yml`: `server.host: 0.0.0.0`,
|
||||
`xpack.security.enabled: false`, Elasticsearch credentials in the file,
|
||||
no TLS and a world-writable file.
|
||||
- **Nagios** (`nagios_audit`): `nagios.cfg` and `cgi.cfg`:
|
||||
`check_external_commands=1`, `use_ssl_authentication=0`, wildcard CGI
|
||||
authorization, a default user and world-writable files.
|
||||
- **Synapse** (`synapse_audit`): `homeserver.yaml`: open registration
|
||||
without a token, no TLS listener, no trusted key servers and a
|
||||
world-writable file.
|
||||
- **NATS monitoring** (`nats_monitoring_probe`): `/varz` and `/connz` without
|
||||
credentials; a 2xx with a version is an open monitoring endpoint, saved as
|
||||
evidence.
|
||||
- Tests with Kibana/Nagios/Synapse trees and two NATS monitoring fixtures
|
||||
(open and 401). 1144 checks. Coverage 83.9%.
|
||||
|
||||
## 1.56.0 — 2026-11-23 — 2bbe0c2
|
||||
|
||||
- **Webmin** (`webmin_audit`): `miniserv.conf`: `ssl=0`, an allow list
|
||||
covering every address, an empty or default password and a world-writable
|
||||
|
||||
@@ -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.
|
||||
|
||||
**262 tools · 1132 end-to-end checks · 340 fuzz cases · 83.8% line coverage · ~925 KiB**
|
||||
**266 tools · 1144 end-to-end checks · 340 fuzz cases · 83.9% line coverage · ~929 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.56.0","tools":262,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.57.0","tools":266,...,"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 (262)
|
||||
## Tools (266)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -215,6 +215,7 @@ uploads and secret-file reads. It does not execute anything.
|
||||
| `rabbitmq_management_probe` | `/api/overview` and `/api/queues` without auth; overview as evidence |
|
||||
| `grafana_api_probe` | `/api/datasources` and `/api/admin/users` without auth; datasources as evidence |
|
||||
| `minio_admin_probe` | `/minio/admin/v3/info` without a signature; admin answer as evidence |
|
||||
| `nats_monitoring_probe` | `/varz` and `/connz` without auth; varz answer 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 |
|
||||
@@ -459,6 +460,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `webmin_audit` | miniserv.conf: ssl=0, wildcard allow, weak password |
|
||||
| `cockpit_audit` | cockpit.conf: AllowUnencrypted, missing Origins |
|
||||
| `phpmyadmin_audit` | config.inc.php: empty blowfish secret, config auth |
|
||||
| `kibana_audit` | kibana.yml: 0.0.0.0, xpack off, credentials in file |
|
||||
| `nagios_audit` | nagios.cfg/cgi.cfg: external commands, no SSL, CGI wildcard |
|
||||
| `synapse_audit` | homeserver.yaml: open registration, no TLS |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -759,6 +763,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| Grafana API | three unauthenticated GETs, datasources as evidence |
|
||||
| webmin/cockpit/phpmyadmin | config reads only; optional root prefix |
|
||||
| MinIO admin API | two unauthenticated GETs, admin answer as evidence |
|
||||
| kibana/nagios/synapse | config reads only; optional root prefix |
|
||||
| NATS monitoring | two unauthenticated GETs, varz answer as evidence |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -770,7 +776,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 1132 end-to-end checks
|
||||
make test # version check + gate audit + 1144 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
|
||||
@@ -898,7 +904,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
docker_registry_probe, consul_api_probe,
|
||||
couchdb_probe, prometheus_api_probe,
|
||||
rabbitmq_management_probe, grafana_api_probe,
|
||||
minio_admin_probe
|
||||
minio_admin_probe, nats_monitoring_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,
|
||||
@@ -941,7 +947,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.56.0. Built and run: 262 tools, 1132 checks, 340 fuzz cases and 83.8% line
|
||||
1.57.0. Built and run: 266 tools, 1144 checks, 340 fuzz cases and 83.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
|
||||
|
||||
+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.56.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.57.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.
|
||||
- **Kibana, Nagios and Synapse audits read local files.** The NATS
|
||||
monitoring probe sends two unauthenticated GETs and saves the varz answer.
|
||||
- **Webmin, Cockpit and phpMyAdmin audits read local files.** The MinIO
|
||||
probe sends two unauthenticated GETs and saves the admin answer.
|
||||
- **GitLab, Vaultwarden and keepalived audits read local files.** The Grafana
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.56.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.57.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),
|
||||
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),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -73,7 +73,8 @@ tftpd_hpa_audit, iscsi_audit, rpcbind_audit, kdump_audit, kafka_audit, powerdns_
|
||||
varnish_audit, freeradius_audit, containerd_audit, nats_audit, caddy_audit, traefik_audit,
|
||||
autofs_audit, gitea_audit, minio_audit, nextcloud_audit, zabbix_audit, nrpe_audit,
|
||||
unattended_upgrades_audit, gitlab_audit, vaultwarden_audit,
|
||||
keepalived_audit, webmin_audit, cockpit_audit, phpmyadmin_audit)
|
||||
keepalived_audit, webmin_audit, cockpit_audit, phpmyadmin_audit, kibana_audit,
|
||||
nagios_audit, synapse_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.56.0"
|
||||
#define APEX_VERSION "1.57.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -17014,6 +17014,322 @@ static void t_phpmyadmin_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- kibana_audit */
|
||||
|
||||
static void t_kibana_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 host[256];
|
||||
char value[256];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int listen_all = 0;
|
||||
int security_off = 0;
|
||||
int credentials = 0;
|
||||
int no_tls = 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/kibana/kibana.yml", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read kibana.yml");
|
||||
return;
|
||||
}
|
||||
host[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"kibana.yml is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
yaml_value(text, "server.host", host, sizeof(host));
|
||||
if (strcmp(host, "0.0.0.0") == 0 || strcmp(host, "::") == 0 ||
|
||||
strcmp(host, "\"0.0.0.0\"") == 0)
|
||||
listen_all = 1;
|
||||
if (yaml_value(text, "server.ssl.enabled", value, sizeof(value))) {
|
||||
if (strcasecmp(value, "false") == 0)
|
||||
no_tls = 1;
|
||||
} else {
|
||||
no_tls = 1;
|
||||
}
|
||||
if (yaml_value(text, "xpack.security.enabled", value, sizeof(value)) &&
|
||||
strcasecmp(value, "false") == 0)
|
||||
security_off = 1;
|
||||
if ((yaml_value(text, "elasticsearch.username", value,
|
||||
sizeof(value)) && value[0] != '\0') ||
|
||||
(yaml_value(text, "elasticsearch.password", value,
|
||||
sizeof(value)) && value[0] != '\0'))
|
||||
credentials = 1;
|
||||
if (listen_all) {
|
||||
add_finding(&findings, &first, "listen-all", "high",
|
||||
"Kibana listens on every interface");
|
||||
count++;
|
||||
}
|
||||
if (security_off) {
|
||||
add_finding(&findings, &first, "security-off", "high",
|
||||
"xpack security is disabled");
|
||||
count++;
|
||||
}
|
||||
if (credentials) {
|
||||
add_finding(&findings, &first, "plaintext-credentials",
|
||||
"medium",
|
||||
"Elasticsearch credentials are stored in kibana.yml");
|
||||
count++;
|
||||
}
|
||||
if (no_tls) {
|
||||
add_finding(&findings, &first, "no-tls", "high",
|
||||
"Kibana serves without TLS");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"server_host\":");
|
||||
apex_json_str(&b, host);
|
||||
mcp_buf_printf(&b, ",\"listen_all\":%s,\"security\":%s,"
|
||||
"\"credentials_in_file\":%s,\"tls\":%s,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
listen_all ? "true" : "false",
|
||||
security_off ? "false" : "true",
|
||||
credentials ? "true" : "false",
|
||||
no_tls ? "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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- nagios_audit */
|
||||
|
||||
static int nagios_scan_cfg(mcp_buf *findings, int *first, int *count,
|
||||
const char *path, int *files, int *external_cmds,
|
||||
int *no_ssl, char *cgi_path, size_t cgi_n)
|
||||
{
|
||||
static char text[65536];
|
||||
struct stat st;
|
||||
char value[64];
|
||||
char dir[1024];
|
||||
char *slash;
|
||||
|
||||
if (read_text(path, text, sizeof(text)) <= 0)
|
||||
return 0;
|
||||
(*files)++;
|
||||
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 (conf_value(text, "check_external_commands", value, sizeof(value)) &&
|
||||
strcmp(value, "1") == 0)
|
||||
*external_cmds = 1;
|
||||
if (conf_value(text, "use_ssl_authentication", value, sizeof(value)) &&
|
||||
strcmp(value, "0") == 0)
|
||||
*no_ssl = 1;
|
||||
snprintf(dir, sizeof(dir), "%.900s", path);
|
||||
slash = strrchr(dir, '/');
|
||||
if (slash == NULL)
|
||||
return 1;
|
||||
*slash = '\0';
|
||||
snprintf(cgi_path, cgi_n, "%.700s/cgi.cfg", dir);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void t_nagios_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *files[] = { "/usr/local/nagios/etc/nagios.cfg",
|
||||
"/etc/nagios4/nagios.cfg",
|
||||
"/etc/nagios/nagios.cfg", NULL };
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char cgi_path[1024];
|
||||
static char text[65536];
|
||||
char value[256];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files_read = 0;
|
||||
int external_cmds = 0;
|
||||
int no_ssl = 0;
|
||||
int cgi_wildcard = 0;
|
||||
int default_user = 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);
|
||||
cgi_path[0] = '\0';
|
||||
for (i = 0; files[i] != NULL; i++) {
|
||||
char full[1200];
|
||||
|
||||
snprintf(full, sizeof(full), "%.400s%s", root, files[i]);
|
||||
if (nagios_scan_cfg(&findings, &first, &count, full, &files_read,
|
||||
&external_cmds, &no_ssl, cgi_path,
|
||||
sizeof(cgi_path)))
|
||||
break;
|
||||
}
|
||||
if (files_read == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read a Nagios configuration");
|
||||
return;
|
||||
}
|
||||
if (read_text(cgi_path, text, sizeof(text)) > 0) {
|
||||
if (stat(cgi_path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"cgi.cfg is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
if (conf_value(text, "authorized_for_all_services", value,
|
||||
sizeof(value)) &&
|
||||
(strcmp(value, "*") == 0 || strstr(value, "*") != NULL))
|
||||
cgi_wildcard = 1;
|
||||
if (conf_value(text, "authorized_for_all_hosts", value,
|
||||
sizeof(value)) &&
|
||||
(strcmp(value, "*") == 0 || strstr(value, "*") != NULL))
|
||||
cgi_wildcard = 1;
|
||||
if (conf_value(text, "default_user_name", value,
|
||||
sizeof(value)) &&
|
||||
value[0] != '\0')
|
||||
default_user = 1;
|
||||
}
|
||||
if (external_cmds) {
|
||||
add_finding(&findings, &first, "external-commands", "high",
|
||||
"external command checks are enabled");
|
||||
count++;
|
||||
}
|
||||
if (no_ssl) {
|
||||
add_finding(&findings, &first, "no-ssl-auth", "medium",
|
||||
"the CGIs do not require SSL");
|
||||
count++;
|
||||
}
|
||||
if (cgi_wildcard) {
|
||||
add_finding(&findings, &first, "cgi-wildcard", "high",
|
||||
"every CGI user may control all hosts and services");
|
||||
count++;
|
||||
}
|
||||
if (default_user) {
|
||||
add_finding(&findings, &first, "default-user", "medium",
|
||||
"the CGI logs in a default user automatically");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"external_commands\":%s,"
|
||||
"\"ssl_auth\":%s,\"cgi_wildcard\":%s,"
|
||||
"\"default_user\":%s,\"findings_count\":%d,"
|
||||
"\"findings\":[",
|
||||
files_read, external_cmds ? "true" : "false",
|
||||
no_ssl ? "false" : "true",
|
||||
cgi_wildcard ? "true" : "false",
|
||||
default_user ? "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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- synapse_audit */
|
||||
|
||||
static void t_synapse_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[64];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int open_registration = 0;
|
||||
int token_required = 0;
|
||||
int no_tls = 0;
|
||||
int no_key_servers = 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/matrix-synapse/homeserver.yaml",
|
||||
root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read homeserver.yaml");
|
||||
return;
|
||||
}
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"homeserver.yaml is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
if (yaml_value(text, "registration_requires_token", value,
|
||||
sizeof(value)) &&
|
||||
strcasecmp(value, "true") == 0)
|
||||
token_required = 1;
|
||||
if (yaml_value(text, "enable_registration", value, sizeof(value)) &&
|
||||
strcasecmp(value, "true") == 0 && !token_required)
|
||||
open_registration = 1;
|
||||
if (strstr(text, "tls:") == NULL)
|
||||
no_tls = 1;
|
||||
if (strstr(text, "trusted_key_servers") == NULL)
|
||||
no_key_servers = 1;
|
||||
if (open_registration) {
|
||||
add_finding(&findings, &first, "open-registration", "high",
|
||||
"anyone may register an account");
|
||||
count++;
|
||||
}
|
||||
if (no_tls) {
|
||||
add_finding(&findings, &first, "no-tls", "low",
|
||||
"no TLS listener is configured");
|
||||
count++;
|
||||
}
|
||||
if (no_key_servers) {
|
||||
add_finding(&findings, &first, "no-trusted-key-servers", "low",
|
||||
"no trusted key servers are configured");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"open_registration\":%s,"
|
||||
"\"token_required\":%s,\"tls\":%s,"
|
||||
"\"trusted_key_servers\":%s,\"findings_count\":%d,"
|
||||
"\"findings\":[",
|
||||
open_registration ? "true" : "false",
|
||||
token_required ? "true" : "false",
|
||||
no_tls ? "false" : "true",
|
||||
no_key_servers ? "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, "
|
||||
@@ -17963,6 +18279,27 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_phpmyadmin_audit },
|
||||
{ "kibana_audit",
|
||||
"Parse kibana.yml (root prefix): server.host on every interface, "
|
||||
"xpack.security disabled, Elasticsearch credentials in the file, no TLS "
|
||||
"and a world-writable file. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_kibana_audit },
|
||||
{ "nagios_audit",
|
||||
"Parse nagios.cfg and cgi.cfg (root prefix, three usual paths): external "
|
||||
"commands enabled, no SSL auth, CGI wildcards, a default user and "
|
||||
"world-writable files. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_nagios_audit },
|
||||
{ "synapse_audit",
|
||||
"Parse homeserver.yaml (root prefix): open registration without a "
|
||||
"token, no TLS listener, no trusted key servers and a world-writable "
|
||||
"file. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_synapse_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
+120
@@ -7177,6 +7177,116 @@ static void t_minio_admin_probe(mcp_conn *c, const mcp_json *args,
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------- nats_monitoring_probe */
|
||||
|
||||
static void t_nats_monitoring_probe(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
static const char *paths[] = { "/varz", "/connz", NULL };
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 8222);
|
||||
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 varz_open = 0;
|
||||
int connz_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, "nats_monitoring_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;
|
||||
|
||||
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 && strcmp(paths[i], "/varz") == 0) {
|
||||
const char *p = NULL;
|
||||
|
||||
varz_open = 1;
|
||||
if (evidence == NULL)
|
||||
evidence = apex_evidence_save("nats-varz", resp,
|
||||
len);
|
||||
if (resp != NULL &&
|
||||
(p = strstr(resp, "\"version\"")) != NULL) {
|
||||
p = strchr(p + 9, '"');
|
||||
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 (open && strcmp(paths[i], "/connz") == 0)
|
||||
connz_open = 1;
|
||||
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,"
|
||||
"\"varz_open\":%s,\"connz_open\":%s,\"version\":",
|
||||
tested, open_count, varz_open ? "true" : "false",
|
||||
connz_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("nats_monitoring_probe", target, port,
|
||||
!(varz_open || connz_open),
|
||||
varz_open || connz_open
|
||||
? "the NATS monitoring endpoints answer without auth"
|
||||
: "the NATS monitoring endpoints require 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: "
|
||||
@@ -7780,6 +7890,16 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_minio_admin_probe },
|
||||
{ "nats_monitoring_probe",
|
||||
"Query the NATS monitoring port without credentials: /varz and /connz. "
|
||||
"A 2xx with a version is an open monitoring endpoint; the varz answer "
|
||||
"is saved as evidence. Gate: the target.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 8222\"},"
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_nats_monitoring_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 = 262
|
||||
EXPECTED_TOOLS = 266
|
||||
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.
|
||||
|
||||
+186
-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("262 tools registered", len(tools) == 262, len(tools))
|
||||
check("266 tools registered", len(tools) == 266, 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"]) == 262)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 266)
|
||||
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
|
||||
@@ -12016,6 +12016,189 @@ shutil.rmtree(pa_root, ignore_errors=True)
|
||||
shutil.rmtree(pa_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg28_home, ignore_errors=True)
|
||||
|
||||
print("\n== Kibana, Nagios, Synapse and NATS monitoring ==\n")
|
||||
|
||||
kb_root = tempfile.mkdtemp(prefix="apex-kb-")
|
||||
os.makedirs(os.path.join(kb_root, "etc", "kibana"))
|
||||
kb_bad = os.path.join(kb_root, "etc", "kibana", "kibana.yml")
|
||||
with open(kb_bad, "w") as f:
|
||||
f.write('server.host: "0.0.0.0"\n')
|
||||
f.write("server.ssl.enabled: false\n")
|
||||
f.write("xpack.security.enabled: false\n")
|
||||
f.write('elasticsearch.username: "kibana"\n')
|
||||
f.write('elasticsearch.password: "secret"\n')
|
||||
os.chmod(kb_bad, 0o666)
|
||||
kb_good_root = tempfile.mkdtemp(prefix="apex-kbg-")
|
||||
os.makedirs(os.path.join(kb_good_root, "etc", "kibana"))
|
||||
with open(os.path.join(kb_good_root, "etc", "kibana", "kibana.yml"),
|
||||
"w") as f:
|
||||
f.write('server.host: "127.0.0.1"\n')
|
||||
f.write("server.ssl.enabled: true\n")
|
||||
f.write("xpack.security.enabled: true\n")
|
||||
|
||||
ng_root = tempfile.mkdtemp(prefix="apex-ng-")
|
||||
os.makedirs(os.path.join(ng_root, "usr", "local", "nagios", "etc"))
|
||||
ng_cfg = os.path.join(ng_root, "usr", "local", "nagios", "etc",
|
||||
"nagios.cfg")
|
||||
with open(ng_cfg, "w") as f:
|
||||
f.write("check_external_commands=1\n")
|
||||
f.write("use_ssl_authentication=0\n")
|
||||
os.chmod(ng_cfg, 0o666)
|
||||
with open(os.path.join(ng_root, "usr", "local", "nagios", "etc",
|
||||
"cgi.cfg"), "w") as f:
|
||||
f.write("authorized_for_all_services=*\n")
|
||||
f.write("default_user_name=nagiosadmin\n")
|
||||
ng_good_root = tempfile.mkdtemp(prefix="apex-ngg-")
|
||||
os.makedirs(os.path.join(ng_good_root, "usr", "local", "nagios", "etc"))
|
||||
with open(os.path.join(ng_good_root, "usr", "local", "nagios", "etc",
|
||||
"nagios.cfg"), "w") as f:
|
||||
f.write("check_external_commands=0\n")
|
||||
f.write("use_ssl_authentication=1\n")
|
||||
with open(os.path.join(ng_good_root, "usr", "local", "nagios", "etc",
|
||||
"cgi.cfg"), "w") as f:
|
||||
f.write("authorized_for_all_services=nagiosadmin\n")
|
||||
|
||||
sy_root = tempfile.mkdtemp(prefix="apex-sy-")
|
||||
os.makedirs(os.path.join(sy_root, "etc", "matrix-synapse"))
|
||||
sy_bad = os.path.join(sy_root, "etc", "matrix-synapse", "homeserver.yaml")
|
||||
with open(sy_bad, "w") as f:
|
||||
f.write("server_name: example.test\n")
|
||||
f.write("enable_registration: true\n")
|
||||
f.write("registration_requires_token: false\n")
|
||||
os.chmod(sy_bad, 0o666)
|
||||
sy_good_root = tempfile.mkdtemp(prefix="apex-syg-")
|
||||
os.makedirs(os.path.join(sy_good_root, "etc", "matrix-synapse"))
|
||||
with open(os.path.join(sy_good_root, "etc", "matrix-synapse",
|
||||
"homeserver.yaml"), "w") as f:
|
||||
f.write("server_name: example.test\n")
|
||||
f.write("enable_registration: false\n")
|
||||
f.write("registration_requires_token: true\n")
|
||||
f.write("tls:\n certificate: /etc/matrix-synapse/tls/cert.pem\n")
|
||||
f.write("trusted_key_servers:\n - matrix.org\n")
|
||||
|
||||
|
||||
class _NatsMonHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
docs = {
|
||||
"/varz": b'{"server_id":"abc","version":"2.10.0",'
|
||||
b'"connections":1}',
|
||||
"/connz": b'{"num_connections":1,"connections":[]}',
|
||||
}
|
||||
body = docs.get(path, b"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 _NatsMonAuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
body = b"Unauthorized"
|
||||
self.send_response(401)
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
nm_srv = http.server.HTTPServer(("127.0.0.1", 0), _NatsMonHandler)
|
||||
nm_port = nm_srv.server_address[1]
|
||||
threading.Thread(target=nm_srv.serve_forever, daemon=True).start()
|
||||
nm_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
|
||||
_NatsMonAuthHandler)
|
||||
nm_auth_port = nm_auth_srv.server_address[1]
|
||||
threading.Thread(target=nm_auth_srv.serve_forever, daemon=True).start()
|
||||
|
||||
cfg29_home = tempfile.mkdtemp(prefix="apex-cfg29-home-")
|
||||
write_scope(cfg29_home, {"label": "cfg29", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": [str(nm_port), str(nm_auth_port)]})
|
||||
res, _ = run([
|
||||
call(1, "kibana_audit", root=kb_root),
|
||||
call(2, "kibana_audit", root=kb_good_root),
|
||||
call(3, "nagios_audit", root=ng_root),
|
||||
call(4, "nagios_audit", root=ng_good_root),
|
||||
call(5, "synapse_audit", root=sy_root),
|
||||
call(6, "synapse_audit", root=sy_good_root),
|
||||
call(7, "nats_monitoring_probe", target="127.0.0.1", port=nm_port,
|
||||
tls=False),
|
||||
call(8, "nats_monitoring_probe", target="127.0.0.1", port=nm_auth_port,
|
||||
tls=False),
|
||||
call(9, "nats_monitoring_probe", target="198.51.100.9", port=8222),
|
||||
call(10, "kibana_audit", root="/nonexistent-kb"),
|
||||
call(11, "nagios_audit", root="/nonexistent-ng"),
|
||||
call(12, "synapse_audit", root="/nonexistent-sy"),
|
||||
], home=cfg29_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
kb = json.loads(text(by_id[1]))
|
||||
kb_kinds = {f["id"] for f in kb["findings"]}
|
||||
check("kibana_audit flags listen-all, security off and credentials",
|
||||
{"world-writable", "listen-all", "security-off",
|
||||
"plaintext-credentials", "no-tls"} <= kb_kinds and
|
||||
kb["listen_all"] is True and kb["security"] is False, kb)
|
||||
kb_good = json.loads(text(by_id[2]))
|
||||
check("kibana_audit accepts loopback with TLS and security",
|
||||
kb_good["findings_count"] == 0 and kb_good["listen_all"] is False and
|
||||
kb_good["tls"] is True, kb_good)
|
||||
ng = json.loads(text(by_id[3]))
|
||||
ng_kinds = {f["id"] for f in ng["findings"]}
|
||||
check("nagios_audit flags external commands, SSL and CGI wildcards",
|
||||
{"world-writable", "external-commands", "no-ssl-auth",
|
||||
"cgi-wildcard", "default-user"} <= ng_kinds and
|
||||
ng["external_commands"] is True and ng["ssl_auth"] is False, ng)
|
||||
ng_good = json.loads(text(by_id[4]))
|
||||
check("nagios_audit accepts external commands off and SSL auth",
|
||||
ng_good["findings_count"] == 0 and
|
||||
ng_good["external_commands"] is False and
|
||||
ng_good["ssl_auth"] is True, ng_good)
|
||||
sy = json.loads(text(by_id[5]))
|
||||
sy_kinds = {f["id"] for f in sy["findings"]}
|
||||
check("synapse_audit flags open registration and missing TLS",
|
||||
{"world-writable", "open-registration", "no-tls",
|
||||
"no-trusted-key-servers"} <= sy_kinds and
|
||||
sy["open_registration"] is True and sy["tls"] is False, sy)
|
||||
sy_good = json.loads(text(by_id[6]))
|
||||
check("synapse_audit accepts closed registration with TLS",
|
||||
sy_good["findings_count"] == 0 and
|
||||
sy_good["open_registration"] is False and
|
||||
sy_good["tls"] is True, sy_good)
|
||||
nm = json.loads(text(by_id[7]))
|
||||
check("nats_monitoring_probe finds open varz and connz",
|
||||
nm["varz_open"] is True and nm["connz_open"] is True and
|
||||
nm["version"] == "2.10.0" and nm["evidence"] and
|
||||
os.path.isfile(nm["evidence"]), nm)
|
||||
nm_auth = json.loads(text(by_id[8]))
|
||||
check("nats_monitoring_probe reports a protected endpoint",
|
||||
nm_auth["varz_open"] is False and nm_auth["connz_open"] is False and
|
||||
all(e["status"] == 401 for e in nm_auth["endpoints"]), nm_auth)
|
||||
check("nats_monitoring_probe refuses an out-of-scope target",
|
||||
err(by_id[9]), text(by_id[9]))
|
||||
check("kibana_audit reports a missing config", err(by_id[10]),
|
||||
text(by_id[10]))
|
||||
check("nagios_audit reports a missing config", err(by_id[11]),
|
||||
text(by_id[11]))
|
||||
check("synapse_audit reports a missing config", err(by_id[12]),
|
||||
text(by_id[12]))
|
||||
nm_srv.shutdown()
|
||||
nm_srv.server_close()
|
||||
nm_auth_srv.shutdown()
|
||||
nm_auth_srv.server_close()
|
||||
shutil.rmtree(kb_root, ignore_errors=True)
|
||||
shutil.rmtree(kb_good_root, ignore_errors=True)
|
||||
shutil.rmtree(ng_root, ignore_errors=True)
|
||||
shutil.rmtree(ng_good_root, ignore_errors=True)
|
||||
shutil.rmtree(sy_root, ignore_errors=True)
|
||||
shutil.rmtree(sy_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg29_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
@@ -12034,6 +12217,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