apex-twin 1.38.0: Consul, Vault and ZooKeeper audits, mTLS probe

Blue:
- consul_config_audit: consul.hcl and consul.d/*.hcl (root prefix): ACL
  default policy allow, bind_addr on every interface, incoming/outgoing
  verification off, missing gossip encryption, enabled UI and world-writable
  files.
- vault_config_audit: vault.hcl: tls_disable 1/true, UI enabled, disable_mlock
  and a Shamir seal without auto-unseal.
- zookeeper_audit: zoo.cfg: an open 4lw whitelist (stat/mntr/envi),
  clientPortAddress on every interface and a missing authProvider.

Red:
- tls_client_auth_probe: one openssl s_client -msg handshake; a
  CertificateRequest means the server requires a client certificate. Reports
  protocol and cipher and presents no certificate.

Tests with vulnerable and hardened Consul/Vault/ZooKeeper trees plus a
client-cert-required TLS server and a plain one. 905 checks, ASan suite green,
analyze clean, release-check green including distcheck 1.38.0.

Note: two unrelated nmap timeout checks failed once under system load and
passed on the immediate rerun (905/905), so they are recorded as environmental.
This commit is contained in:
lotherk committed 2026-11-22 07:18:12 +00:00
1 parent ba1796a7ee
commit ebb046c7b1
9 files changed
+687 -15

No files matched your search

+18 -1
View File
@@ -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.37.0 — 2026-11-21 — this change
## 1.38.0 — 2026-11-21 — this change
- **Consul** (`consul_config_audit`): consul.hcl and consul.d/*.hcl: ACL
default policy allow, bind_addr on every interface, incoming/outgoing
verification off, missing gossip encryption, enabled UI and world-writable
files.
- **Vault** (`vault_config_audit`): vault.hcl: tls_disable 1/true, UI enabled,
disable_mlock and a Shamir seal without auto-unseal.
- **ZooKeeper** (`zookeeper_audit`): zoo.cfg: an open 4lw whitelist
(stat/mntr/envi), clientPortAddress on every interface and a missing
authProvider.
- **mTLS** (`tls_client_auth_probe`): one `s_client -msg` handshake; a
CertificateRequest means the server requires a client certificate. Reports
protocol and cipher, presents no certificate.
- Tests with vulnerable and hardened Consul/Vault/ZooKeeper trees plus a
client-cert-required TLS server and a plain one. 905 checks. Coverage 82.1%.
## 1.37.0 — 2026-11-21 — ba1796a
- **kubelet** (`kubelet_config_audit`): /var/lib/kubelet/config.yaml (root
prefix): anonymous authentication enabled, authorization mode AlwaysAllow,
+12 -6
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.
**187 tools · 893 end-to-end checks · 340 fuzz cases · 81.9% line coverage · ~730 KiB**
**191 tools · 905 end-to-end checks · 340 fuzz cases · 82.1% line coverage · ~738 KiB**
```
$ ./apex-twin --check
{"version":"1.37.0","tools":187,...,"scope":{"loaded":true,...}}
{"version":"1.38.0","tools":191,...,"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 (187)
## Tools (191)
### Scope and bookkeeping
@@ -301,6 +301,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `dns_wildcard_check` | Random label under a domain; an answer means wildcard DNS |
| `dns_caa_check` | CAA records: flags, issue/issuewild/iodef tags and values |
| `sni_vhost_check` | Per-name `s_client -servername`: distinct certificate subjects/fingerprints |
| `tls_client_auth_probe` | `s_client -msg`: CertificateRequest means mutual TLS required |
| `imap_probe` | Banner, CAPABILITY list, STARTTLS and LOGINDISABLED; no LOGIN |
| `pop3_probe` | Banner, CAPA list, STLS flag; no USER/PASS |
| `sip_probe` | One UDP OPTIONS: status line, Server header, Allow methods |
@@ -384,6 +385,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `kubelet_config_audit` | kubelet config.yaml: anonymous auth, AlwaysAllow, readOnlyPort |
| `etcd_config_audit` | etcd config: 0.0.0.0/http URLs, client/peer cert auth off, auto-tls |
| `rabbitmq_audit` | rabbitmq.conf: loopback removed, guest/guest, management without TLS |
| `consul_config_audit` | consul.hcl: ACL allow, bind 0.0.0.0, verify flags off, no gossip encryption |
| `vault_config_audit` | vault.hcl: tls_disable, UI on, mlock off, Shamir without auto-unseal |
| `zookeeper_audit` | zoo.cfg: open 4lw whitelist, clientPortAddress all, missing authProvider |
### ESP32
@@ -644,6 +648,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| CAA | one gated dig query |
| kubelet/etcd/rabbitmq | config reads only; optional root prefix |
| SNI | one TLS handshake per name, no data |
| consul/vault/zookeeper | config reads only; optional root prefix |
| mTLS | one handshake, no client certificate presented |
| USB audit | 200 devices, sysfs reads only |
---
@@ -655,7 +661,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 893 end-to-end checks
make test # version check + gate audit + 905 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
@@ -773,7 +779,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
kerberos_discovery, winrm_probe, dnssec_check,
smtp_starttls_probe, tls_ocsp_probe, alpn_probe,
webdav_probe, dns_wildcard_check, dns_caa_check,
sni_vhost_check
sni_vhost_check, tls_client_auth_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,
@@ -816,7 +822,7 @@ examples/ scope.json
## Status
1.37.0. Built and run: 187 tools, 893 checks, 340 fuzz cases and 81.9% line
1.38.0. Built and run: 191 tools, 905 checks, 340 fuzz cases and 82.1% 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
+4 -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.37.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.38.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,9 @@ 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.
- **mTLS detection is one handshake.** `tls_client_auth_probe` reads the
CertificateRequest from `s_client -msg` and presents no certificate. Consul,
Vault and ZooKeeper audits read configuration files.
- **SNI checks are TLS handshakes only.** `sni_vhost_check` connects once per
in-scope name and reads the certificate; Kubernetes, etcd and RabbitMQ
audits read configuration files.
+4 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.37.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.38.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -43,7 +43,7 @@ memcached_probe, param_fuzz, open_redirect, host_header_injection, ssti_probe,
xxe_probe, ldap_probe, rdp_probe, smb_probe, vnc_probe, mqtt_probe,
graphql_probe, docker_api_probe, elasticsearch_probe, imap_probe, pop3_probe,
sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check),
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),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -59,7 +59,8 @@ exim_audit, elasticsearch_config_audit, squid_audit, unbound_audit,
cups_audit, rsync_audit, dhcpd_audit, krb5_conf_audit,
mongodb_config_audit, memcached_config_audit, ntpd_config_audit,
bind9_config_audit, tomcat_audit, proftpd_audit, kubelet_config_audit,
etcd_config_audit, rabbitmq_audit) and ESP32 board tools (esp_info, esp_monitor,
etcd_config_audit, rabbitmq_audit, consul_config_audit, vault_config_audit,
zookeeper_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).
.SH MODES
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.37.0"
#define APEX_VERSION "1.38.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+386
View File
@@ -10405,6 +10405,371 @@ static void t_rabbitmq_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- consul_audit */
static void consul_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files, int *acl_allow,
int *bind_all, int *verify_in, int *verify_out,
int *encrypt, int *ui_on, char *acl_value,
size_t acl_n, char *bind_value, size_t bind_n)
{
static char text[65536];
char value[256];
struct stat st;
if (read_text(path, text, sizeof(text)) < 0)
return;
(*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, "acl_default_policy", value, sizeof(value))) {
snprintf(acl_value, acl_n, "%.48s", value);
if (strcasecmp(value, "allow") == 0)
*acl_allow = 1;
}
if (conf_value(text, "bind_addr", value, sizeof(value))) {
snprintf(bind_value, bind_n, "%.100s", value);
if (conf_has_word(value, "0.0.0.0") ||
conf_has_word(value, "::"))
*bind_all = 1;
}
if (conf_value(text, "verify_incoming", value, sizeof(value)) &&
strcasecmp(value, "false") == 0)
*verify_in = 1;
if (conf_value(text, "verify_outgoing", value, sizeof(value)) &&
strcasecmp(value, "false") == 0)
*verify_out = 1;
if (conf_value(text, "encrypt", value, sizeof(value)) &&
value[0] != '\0')
*encrypt = 1;
if (conf_value(text, "ui", value, sizeof(value)) &&
strcasecmp(value, "true") == 0)
*ui_on = 1;
}
static void t_consul_config_audit(mcp_conn *c, const mcp_json *args,
void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
char acl_value[64];
char bind_value[128];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int acl_allow = 0;
int bind_all = 0;
int verify_in = 0;
int verify_out = 0;
int encrypt = 0;
int ui_on = 0;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
acl_value[0] = bind_value[0] = '\0';
mcp_buf_init(&findings);
snprintf(path, sizeof(path), "%s/etc/consul.hcl", root);
consul_scan_file(&findings, &first, &count, path, &files, &acl_allow,
&bind_all, &verify_in, &verify_out, &encrypt, &ui_on,
acl_value, sizeof(acl_value), bind_value,
sizeof(bind_value));
snprintf(path, sizeof(path), "%s/etc/consul.d", root);
{
DIR *d = opendir(path);
struct dirent *ent;
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char full[1024];
struct stat st;
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (nl < 5 ||
strcmp(ent->d_name + nl - 4, ".hcl") != 0)
continue;
snprintf(full, sizeof(full), "%.800s/%.160s",
path, ent->d_name);
if (stat(full, &st) != 0 ||
!S_ISREG(st.st_mode))
continue;
consul_scan_file(&findings, &first, &count,
full, &files, &acl_allow,
&bind_all, &verify_in,
&verify_out, &encrypt, &ui_on,
acl_value, sizeof(acl_value),
bind_value, sizeof(bind_value));
}
closedir(d);
}
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Consul configuration");
return;
}
if (acl_allow) {
add_finding(&findings, &first, "acl-allow", "high",
"the ACL default policy is allow");
count++;
}
if (bind_all) {
add_finding(&findings, &first, "bind-all", "high",
"Consul binds to every interface");
count++;
}
if (verify_in) {
add_finding(&findings, &first, "verify-incoming-off", "medium",
"incoming TLS verification is disabled");
count++;
}
if (verify_out) {
add_finding(&findings, &first, "verify-outgoing-off", "medium",
"outgoing TLS verification is disabled");
count++;
}
if (!encrypt) {
add_finding(&findings, &first, "no-encryption", "medium",
"gossip encryption is not configured");
count++;
}
if (ui_on) {
add_finding(&findings, &first, "ui-enabled", "low",
"the Consul UI is enabled");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"acl_default_policy\":", files);
apex_json_str(&b, acl_value);
mcp_buf_puts(&b, ",\"bind_addr\":");
apex_json_str(&b, bind_value);
mcp_buf_printf(&b, ",\"encryption\":%s,\"findings_count\":%d,"
"\"findings\":[",
encrypt ? "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);
}
/* ---------------------------------------------------------------- vault_audit */
static void t_vault_config_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/vault.d/vault.hcl",
"/etc/vault/vault.hcl", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
char tls_disable[32];
char ui[32];
char mlock[32];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int tls_off = 0;
int ui_on = 0;
int mlock_off = 0;
int shamir = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
tls_disable[0] = ui[0] = mlock[0] = '\0';
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
static char text[65536];
struct stat st;
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, "tls_disable", tls_disable,
sizeof(tls_disable));
conf_value(text, "ui", ui, sizeof(ui));
conf_value(text, "disable_mlock", mlock, sizeof(mlock));
if (strstr(text, "seal \"shamir\"") != NULL ||
(strstr(text, "seal \"") == NULL &&
strstr(text, "auto_unseal") == NULL))
shamir = 1;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Vault configuration");
return;
}
if (strcmp(tls_disable, "1") == 0 ||
strcasecmp(tls_disable, "true") == 0) {
tls_off = 1;
add_finding(&findings, &first, "tls-disabled", "high",
"the Vault listener disables TLS");
count++;
}
if (strcasecmp(ui, "true") == 0) {
ui_on = 1;
add_finding(&findings, &first, "ui-enabled", "low",
"the Vault web UI is enabled");
count++;
}
if (strcasecmp(mlock, "true") == 0) {
mlock_off = 1;
add_finding(&findings, &first, "mlock-disabled", "medium",
"memory locking is disabled");
count++;
}
if (shamir) {
add_finding(&findings, &first, "shamir-seal", "low",
"Shamir seal without auto-unseal");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"tls_disable\":%s,"
"\"ui\":%s,\"mlock_disabled\":%s,\"findings_count\":%d,"
"\"findings\":[",
files_read, tls_off ? "true" : "false",
ui_on ? "true" : "false",
mlock_off ? "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);
}
/* ------------------------------------------------------------- zookeeper_audit */
static void t_zookeeper_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/zookeeper/conf/zoo.cfg",
"/etc/zookeeper/zoo.cfg",
"/opt/zookeeper/conf/zoo.cfg", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
char whitelist[256];
char client_addr[128];
char auth_provider[256];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int open_4lw = 0;
int client_all = 0;
int have_auth = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
whitelist[0] = client_addr[0] = auth_provider[0] = '\0';
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
static char text[65536];
char value[256];
struct stat st;
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++;
}
if (conf_value(text, "4lw.commands.whitelist", value,
sizeof(value))) {
snprintf(whitelist, sizeof(whitelist), "%.200s", value);
if (conf_has_word(value, "*") ||
conf_has_word(value, "stat") ||
conf_has_word(value, "mntr") ||
conf_has_word(value, "dump") ||
conf_has_word(value, "envi"))
open_4lw = 1;
}
if (conf_value(text, "clientPortAddress", value, sizeof(value))) {
snprintf(client_addr, sizeof(client_addr), "%.100s", value);
if (conf_has_word(value, "0.0.0.0") ||
conf_has_word(value, "::"))
client_all = 1;
}
if (conf_value(text, "authProvider.1", value, sizeof(value)) ||
conf_value(text, "authProvider", value, sizeof(value))) {
if (value[0] != '\0')
have_auth = 1;
}
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a ZooKeeper configuration");
return;
}
if (open_4lw) {
add_finding(&findings, &first, "4lw-open", "medium",
"the four-letter commands expose stat/mntr/envi");
count++;
}
if (client_all) {
add_finding(&findings, &first, "client-all", "high",
"the client port listens on every interface");
count++;
}
if (!have_auth) {
add_finding(&findings, &first, "no-auth", "medium",
"no authProvider is configured");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"whitelist\":", files_read);
apex_json_str(&b, whitelist);
mcp_buf_puts(&b, ",\"client_port_address\":");
apex_json_str(&b, client_addr);
mcp_buf_printf(&b, ",\"auth\":%s,\"findings_count\":%d,\"findings\":[",
have_auth ? "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);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -10972,6 +11337,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_rabbitmq_audit },
{ "consul_config_audit",
"Parse consul.hcl and consul.d/*.hcl (root prefix): ACL default policy "
"allow, bind_addr on every interface, incoming/outgoing verification off, "
"missing gossip encryption, enabled UI and world-writable files. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_consul_config_audit },
{ "vault_config_audit",
"Parse vault.hcl (root prefix): tls_disable 1/true, ui enabled, "
"disable_mlock and a Shamir seal without auto-unseal. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_vault_config_audit },
{ "zookeeper_audit",
"Parse zoo.cfg (root prefix): an open 4lw whitelist (stat/mntr/envi), "
"clientPortAddress on every interface and a missing authProvider. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_zookeeper_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+82
View File
@@ -5618,6 +5618,79 @@ static void t_sni_vhost_check(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* --------------------------------------------------------- tls_client_auth_probe */
static void t_tls_client_auth_probe(mcp_conn *c, const mcp_json *args,
void *user)
{
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 443);
char conn[320];
char protocol[64];
char cipher[128];
int client_auth = 0;
mcp_buf b;
(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 (!apex_have("openssl")) {
mcp_reply_error(c, "openssl is not installed on this host");
return;
}
if (!gated(c, "tls_client_auth_probe", target, port))
return;
tls_conn_string(target, port, conn, sizeof(conn));
protocol[0] = cipher[0] = '\0';
{
char *argv[12];
int k = 0;
apex_proc p;
argv[k++] = "openssl";
argv[k++] = "s_client";
argv[k++] = "-connect";
argv[k++] = conn;
argv[k++] = "-servername";
argv[k++] = (char *)target;
argv[k++] = "-msg";
argv[k] = NULL;
if (apex_run(argv, 20000, g_cfg.max_output, &p) != 0) {
mcp_reply_error(c, "cannot run openssl s_client");
return;
}
if (p.out != NULL) {
tls_summary(p.out, protocol, sizeof(protocol), cipher,
sizeof(cipher));
if (strstr(p.out, "CertificateRequest") != NULL ||
strstr(p.out, "Client Certificate Types:") != NULL)
client_auth = 1;
}
apex_proc_free(&p);
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":true,\"protocol\":", port);
apex_json_str(&b, protocol);
mcp_buf_puts(&b, ",\"cipher\":");
apex_json_str(&b, cipher);
mcp_buf_printf(&b, ",\"client_certificate_requested\":%s,"
"\"mutual_tls\":%s}", client_auth ? "true" : "false",
client_auth ? "true" : "false");
apex_audit("tls_client_auth_probe", target, port, !client_auth,
client_auth ? "the server requests a client certificate"
: "no client certificate requested", protocol);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_PROTO[] = {
{ "ftp_probe",
"One-connection FTP check: read the 220 banner, ask FEAT, then try the "
@@ -5966,6 +6039,15 @@ const mcp_tool TOOLS_PROTO[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"}},"
"\"required\":[\"target\",\"names\"]}",
t_sni_vhost_check },
{ "tls_client_auth_probe",
"Open one TLS connection with openssl s_client -msg and report whether "
"the server sends a CertificateRequest (mutual TLS), plus the negotiated "
"protocol and cipher. No certificate is presented. Gate: target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"}},"
"\"required\":[\"target\"]}",
t_tls_client_auth_probe },
};
const size_t TOOLS_PROTO_N = sizeof(TOOLS_PROTO) / sizeof(TOOLS_PROTO[0]);
+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 = 187
EXPECTED_TOOLS = 191
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.
+179 -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("187 tools registered", len(tools) == 187, len(tools))
check("191 tools registered", len(tools) == 191, 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"]) == 187)
check("http tools/list", len(listing["result"]["tools"]) == 191)
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
@@ -8452,6 +8452,183 @@ shutil.rmtree(rb_good_root, ignore_errors=True)
shutil.rmtree(sni_dir, ignore_errors=True)
shutil.rmtree(cfg9_home, ignore_errors=True)
print("\n== Consul, Vault, ZooKeeper and mTLS ==\n")
co_root = tempfile.mkdtemp(prefix="apex-co-")
os.makedirs(os.path.join(co_root, "etc", "consul.d"))
co_bad = os.path.join(co_root, "etc", "consul.d", "consul.hcl")
with open(co_bad, "w") as f:
f.write('acl_default_policy = "allow"\n')
f.write('bind_addr = "0.0.0.0"\n')
f.write("verify_incoming = false\n")
f.write("verify_outgoing = false\n")
f.write("ui = true\n")
os.chmod(co_bad, 0o666)
co_good_root = tempfile.mkdtemp(prefix="apex-cog-")
os.makedirs(os.path.join(co_good_root, "etc", "consul.d"))
with open(os.path.join(co_good_root, "etc", "consul.d", "consul.hcl"),
"w") as f:
f.write('acl_default_policy = "deny"\n')
f.write('bind_addr = "127.0.0.1"\n')
f.write("verify_incoming = true\n")
f.write("verify_outgoing = true\n")
f.write('encrypt = "shared-secret"\n')
f.write("ui = false\n")
va_root = tempfile.mkdtemp(prefix="apex-va-")
os.makedirs(os.path.join(va_root, "etc", "vault.d"))
va_bad = os.path.join(va_root, "etc", "vault.d", "vault.hcl")
with open(va_bad, "w") as f:
f.write("ui = true\n")
f.write("disable_mlock = true\n")
f.write('listener "tcp" {\n address = "0.0.0.0:8200"\n')
f.write(" tls_disable = 1\n}\n")
f.write('seal "shamir" {}\n')
os.chmod(va_bad, 0o666)
va_good_root = tempfile.mkdtemp(prefix="apex-vag-")
os.makedirs(os.path.join(va_good_root, "etc", "vault.d"))
with open(os.path.join(va_good_root, "etc", "vault.d", "vault.hcl"),
"w") as f:
f.write("ui = false\n")
f.write("disable_mlock = false\n")
f.write('listener "tcp" {\n address = "127.0.0.1:8200"\n')
f.write(" tls_disable = 0\n}\n")
f.write('seal "awskms" {\n region = "eu-west-1"\n}\n')
zk_root = tempfile.mkdtemp(prefix="apex-zk-")
os.makedirs(os.path.join(zk_root, "etc", "zookeeper", "conf"))
zk_bad = os.path.join(zk_root, "etc", "zookeeper", "conf", "zoo.cfg")
with open(zk_bad, "w") as f:
f.write("4lw.commands.whitelist=*\n")
f.write("clientPortAddress=0.0.0.0\n")
os.chmod(zk_bad, 0o666)
zk_good_root = tempfile.mkdtemp(prefix="apex-zkg-")
os.makedirs(os.path.join(zk_good_root, "etc", "zookeeper", "conf"))
with open(os.path.join(zk_good_root, "etc", "zookeeper", "conf",
"zoo.cfg"), "w") as f:
f.write("4lw.commands.whitelist=srvr\n")
f.write("clientPortAddress=127.0.0.1\n")
f.write("authProvider.1=org.apache.zookeeper.server.auth."
"SASLAuthenticationProvider\n")
mtls_dir = tempfile.mkdtemp(prefix="apex-mtls2-")
mtls_cert = os.path.join(mtls_dir, "cert.pem")
mtls_key = os.path.join(mtls_dir, "key.pem")
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
"-keyout", mtls_key, "-out", mtls_cert, "-days", "2",
"-subj", "/CN=localhost"],
check=True, capture_output=True)
def mtls_server(cert, key):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain(cert, key)
ctx.verify_mode = ssl.CERT_REQUIRED
ctx.load_verify_locations(cert)
srv = socket.socket()
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("127.0.0.1", 0))
srv.listen(8)
port = srv.getsockname()[1]
def loop():
while True:
try:
conn, _ = srv.accept()
except OSError:
return
try:
tls = ctx.wrap_socket(conn, server_side=True)
try:
tls.recv(1)
except OSError:
pass
tls.close()
except (ssl.SSLError, OSError):
conn.close()
threading.Thread(target=loop, daemon=True).start()
return srv, port
mtls_srv, mtls_port = mtls_server(mtls_cert, mtls_key)
plain_srv2, plain_port2 = tls_server(mtls_cert, mtls_key)
cfg10_home = tempfile.mkdtemp(prefix="apex-cfg10-home-")
write_scope(cfg10_home, {"label": "cfg10", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(mtls_port), str(plain_port2)]})
res, _ = run([
call(1, "consul_config_audit", root=co_root),
call(2, "consul_config_audit", root=co_good_root),
call(3, "vault_config_audit", root=va_root),
call(4, "vault_config_audit", root=va_good_root),
call(5, "zookeeper_audit", root=zk_root),
call(6, "zookeeper_audit", root=zk_good_root),
call(7, "tls_client_auth_probe", target="127.0.0.1", port=mtls_port),
call(8, "tls_client_auth_probe", target="127.0.0.1", port=plain_port2),
call(9, "consul_config_audit", root="/nonexistent-co"),
call(10, "vault_config_audit", root="/nonexistent-va"),
call(11, "zookeeper_audit", root="/nonexistent-zk"),
call(12, "tls_client_auth_probe", target="198.51.100.9", port=443),
], home=cfg10_home)
by_id = {r.get("id"): r for r in res}
co = json.loads(text(by_id[1]))
co_kinds = {f["id"] for f in co["findings"]}
check("consul_config_audit flags ACL, bind, TLS and encryption",
{"world-writable", "acl-allow", "bind-all", "verify-incoming-off",
"verify-outgoing-off", "no-encryption", "ui-enabled"} <= co_kinds,
co)
co_good = json.loads(text(by_id[2]))
check("consul_config_audit accepts a hardened config",
co_good["findings_count"] == 0 and
co_good["acl_default_policy"] == "deny" and
co_good["encryption"] is True, co_good)
va = json.loads(text(by_id[3]))
va_kinds = {f["id"] for f in va["findings"]}
check("vault_config_audit flags TLS, UI, mlock and Shamir",
{"world-writable", "tls-disabled", "ui-enabled", "mlock-disabled",
"shamir-seal"} <= va_kinds, va)
va_good = json.loads(text(by_id[4]))
check("vault_config_audit accepts a hardened config",
va_good["findings_count"] == 0 and
va_good["tls_disable"] is False, va_good)
zk = json.loads(text(by_id[5]))
zk_kinds = {f["id"] for f in zk["findings"]}
check("zookeeper_audit flags 4lw, client bind and auth",
{"world-writable", "4lw-open", "client-all", "no-auth"} <= zk_kinds,
zk)
zk_good = json.loads(text(by_id[6]))
check("zookeeper_audit accepts a hardened config",
zk_good["findings_count"] == 0 and zk_good["auth"] is True, zk_good)
mtls = json.loads(text(by_id[7]))
check("tls_client_auth_probe detects mutual TLS",
mtls["client_certificate_requested"] is True and
mtls["mutual_tls"] is True and
mtls["protocol"].startswith("TLSv1."), mtls)
plain_mtls = json.loads(text(by_id[8]))
check("tls_client_auth_probe stays quiet without a request",
plain_mtls["client_certificate_requested"] is False and
plain_mtls["mutual_tls"] is False, plain_mtls)
check("consul_config_audit reports a missing config", err(by_id[9]),
text(by_id[9]))
check("vault_config_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("zookeeper_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("tls_client_auth_probe refuses an out-of-scope target", err(by_id[12]),
text(by_id[12]))
mtls_srv.close()
plain_srv2.close()
shutil.rmtree(co_root, ignore_errors=True)
shutil.rmtree(co_good_root, ignore_errors=True)
shutil.rmtree(va_root, ignore_errors=True)
shutil.rmtree(va_good_root, ignore_errors=True)
shutil.rmtree(zk_root, ignore_errors=True)
shutil.rmtree(zk_good_root, ignore_errors=True)
shutil.rmtree(mtls_dir, ignore_errors=True)
shutil.rmtree(cfg10_home, ignore_errors=True)
print("\n== esp32 tools ==")
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"})