apex-twin 1.33.0: Squid, Unbound and CUPS audits, ALPN matrix
Blue: - squid_audit: squid.conf (root prefix): http_access allow all, an http_port on every interface, a cache_dir in /tmp or /dev/shm and a world-writable config. - unbound_audit: unbound.conf and unbound.conf.d: interface on every address, access-control 0.0.0.0/0 or ::/0 allow, a missing DNSSEC trust anchor and world-writable files. - cups_audit: cupsd.conf: Listen on every interface, Browsing On, a Location block with Allow All and a world-writable config. Red: - alpn_probe: one openssl s_client -alpn handshake per protocol (h2, http/1.1, spdy/3.1 by default) and which one the server selects. Tests with vulnerable and hardened Squid/Unbound/CUPS trees and an ALPN server offering h2 and http/1.1. 842 checks, ASan suite green, analyze clean, release-check green including distcheck 1.33.0.
This commit is contained in:
1 parent
1a5a7bcc3d
commit
cb8b4ac498
9 files changed
+685
-15
No files matched your search
+16
-1
@@ -8,7 +8,22 @@ 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.32.0 — 2026-11-21 — this change
|
||||
## 1.33.0 — 2026-11-21 — this change
|
||||
|
||||
- **Squid** (`squid_audit`): squid.conf (root prefix): http_access allow all,
|
||||
an http_port on every interface, a cache_dir in /tmp or /dev/shm and a
|
||||
world-writable config.
|
||||
- **Unbound** (`unbound_audit`): unbound.conf and unbound.conf.d: interface on
|
||||
every address, access-control 0.0.0.0/0 or ::/0 allow, a missing DNSSEC
|
||||
trust anchor and world-writable files.
|
||||
- **CUPS** (`cups_audit`): cupsd.conf: Listen on every interface, Browsing On,
|
||||
a Location block with Allow All and a world-writable config.
|
||||
- **ALPN** (`alpn_probe`): one openssl s_client -alpn handshake per protocol
|
||||
(h2, http/1.1, spdy/3.1 by default) and which one the server selects.
|
||||
- Tests with vulnerable and hardened Squid/Unbound/CUPS trees and an ALPN
|
||||
server offering h2 and http/1.1. 842 checks. Coverage 81.4%.
|
||||
|
||||
## 1.32.0 — 2026-11-21 — 1a5a7bc
|
||||
|
||||
- **PostgreSQL** (`postgresql_config_audit`): scans /etc/postgresql/<ver>/
|
||||
<cluster> (root prefix) for postgresql.conf and pg_hba.conf: listen_addresses
|
||||
|
||||
@@ -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.
|
||||
|
||||
**167 tools · 830 end-to-end checks · 340 fuzz cases · 81.2% line coverage · ~672 KiB**
|
||||
**171 tools · 842 end-to-end checks · 340 fuzz cases · 81.4% line coverage · ~680 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.32.0","tools":167,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.33.0","tools":171,...,"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 (167)
|
||||
## Tools (171)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -296,6 +296,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `dnssec_check` | DNSKEY/DS with +dnssec: signed, algorithm, key bits; flags unsigned/RSASHA1/short keys |
|
||||
| `smtp_starttls_probe` | EHLO/STARTTLS and a real TLS upgrade via openssl s_client -starttls smtp |
|
||||
| `tls_ocsp_probe` | `s_client -status`: stapled or not, OCSP response and certificate status |
|
||||
| `alpn_probe` | Per-protocol `s_client -alpn`: which of h2/http1.1/spdy3.1 the server selects |
|
||||
| `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 |
|
||||
@@ -364,6 +365,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `postgresql_config_audit` | postgresql.conf/pg_hba.conf: listen-all, ssl off, trust, md5/password |
|
||||
| `exim_audit` | exim.conf: relay_from_hosts all, accept-any, no TLS advertisement, writable config |
|
||||
| `elasticsearch_config_audit` | elasticsearch.yml: network.host all, security disabled, single-node |
|
||||
| `squid_audit` | squid.conf: http_access allow all, open http_port, cache in /tmp, writable config |
|
||||
| `unbound_audit` | unbound.conf: interface all, access-control allow all, missing DNSSEC anchor |
|
||||
| `cups_audit` | cupsd.conf: Listen all, Browsing On, Location Allow All, writable config |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -614,6 +618,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| SMTP STARTTLS | one handshake, no auth, no mail |
|
||||
| postgres/exim/elasticsearch | config reads only; optional root prefix |
|
||||
| OCSP | one TLS handshake, no responder call |
|
||||
| squid/unbound/cups | config reads only; optional root prefix |
|
||||
| ALPN | one handshake per protocol, no data |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -625,7 +631,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 830 end-to-end checks
|
||||
make test # version check + gate audit + 842 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
|
||||
@@ -741,7 +747,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
crlf_probe, dns_version_bind, oidc_discovery,
|
||||
security_txt, http2_probe, ssh_hostkey_fingerprint,
|
||||
kerberos_discovery, winrm_probe, dnssec_check,
|
||||
smtp_starttls_probe, tls_ocsp_probe
|
||||
smtp_starttls_probe, tls_ocsp_probe, alpn_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,
|
||||
@@ -784,7 +790,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.32.0. Built and run: 167 tools, 830 checks, 340 fuzz cases and 81.2% line
|
||||
1.33.0. Built and run: 171 tools, 842 checks, 340 fuzz cases and 81.4% 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.32.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.33.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.
|
||||
- **ALPN is one handshake per protocol.** `alpn_probe` never sends
|
||||
application data; squid/unbound/CUPS audits read configuration files.
|
||||
- **OCSP is read from one handshake.** `tls_ocsp_probe` opens one TLS
|
||||
connection with `openssl s_client -status` and reads the stapled response;
|
||||
it does not contact the OCSP responder itself.
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.32.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.33.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),
|
||||
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -55,7 +55,8 @@ samba_audit, snmpd_audit, rsyslog_audit, apparmor_audit, selinux_audit,
|
||||
usb_audit, docker_audit, www_audit, audit_rules, postfix_audit, nginx_audit,
|
||||
mysql_config_audit, apache_audit, haproxy_audit, redis_config_audit,
|
||||
php_config_audit, dovecot_audit, openvpn_audit, postgresql_config_audit,
|
||||
exim_audit, elasticsearch_config_audit) and ESP32 board tools (esp_info, esp_monitor,
|
||||
exim_audit, elasticsearch_config_audit, squid_audit, unbound_audit,
|
||||
cups_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
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.32.0"
|
||||
#define APEX_VERSION "1.33.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -8552,6 +8552,367 @@ static void t_elasticsearch_config_audit(mcp_conn *c, const mcp_json *args,
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- squid_audit */
|
||||
|
||||
static void t_squid_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
static char text[65536];
|
||||
char path[1024];
|
||||
char http_port[128];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int allow_all = 0;
|
||||
int open_port = 0;
|
||||
int temp_cache = 0;
|
||||
struct stat st;
|
||||
|
||||
(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/squid/squid.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read squid.conf");
|
||||
return;
|
||||
}
|
||||
http_port[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"squid.conf is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
{
|
||||
char *copy = strdup(text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *t = line;
|
||||
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
if (*t != '#' && *t != '\0') {
|
||||
if (strncmp(t, "http_access", 11) == 0 &&
|
||||
strstr(t, "allow all") != NULL)
|
||||
allow_all = 1;
|
||||
if (strncmp(t, "http_port", 9) == 0) {
|
||||
snprintf(http_port,
|
||||
sizeof(http_port),
|
||||
"%.100s", t + 9);
|
||||
if (strstr(t, "0.0.0.0") != NULL ||
|
||||
strstr(t, "[::]") != NULL ||
|
||||
strstr(t, " ::") != NULL)
|
||||
open_port = 1;
|
||||
}
|
||||
if (strncmp(t, "cache_dir", 9) == 0 &&
|
||||
(strstr(t, "/tmp") != NULL ||
|
||||
strstr(t, "/dev/shm") != NULL))
|
||||
temp_cache = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
if (allow_all) {
|
||||
add_finding(&findings, &first, "allow-all", "high",
|
||||
"http_access allows every request");
|
||||
count++;
|
||||
}
|
||||
if (open_port) {
|
||||
add_finding(&findings, &first, "open-port", "medium",
|
||||
"http_port listens on every interface");
|
||||
count++;
|
||||
}
|
||||
if (temp_cache) {
|
||||
add_finding(&findings, &first, "temp-cache", "low",
|
||||
"the cache lives in a temporary directory");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"http_port\":");
|
||||
apex_json_str(&b, http_port);
|
||||
mcp_buf_printf(&b, ",\"allow_all\":%s,\"findings_count\":%d,"
|
||||
"\"findings\":[",
|
||||
allow_all ? "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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- unbound_audit */
|
||||
|
||||
static void unbound_scan_file(mcp_buf *findings, int *first, int *count,
|
||||
const char *path, int *files, int *iface_all,
|
||||
int *open_resolver, int *dnssec,
|
||||
char *iface_value, size_t iface_n)
|
||||
{
|
||||
static char text[65536];
|
||||
char value[256];
|
||||
struct stat st;
|
||||
char *copy;
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
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 (yaml_value(text, "interface", value, sizeof(value))) {
|
||||
snprintf(iface_value, iface_n, "%.100s", value);
|
||||
if (conf_has_word(value, "0.0.0.0") ||
|
||||
conf_has_word(value, "::"))
|
||||
*iface_all = 1;
|
||||
}
|
||||
copy = strdup(text);
|
||||
if (copy == NULL)
|
||||
return;
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *t = line;
|
||||
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
if (*t != '#' && *t != '\0') {
|
||||
if (strncmp(t, "access-control:", 15) == 0 &&
|
||||
(strstr(t, "0.0.0.0/0 allow") != NULL ||
|
||||
strstr(t, "::/0 allow") != NULL))
|
||||
*open_resolver = 1;
|
||||
if (strncmp(t, "auto-trust-anchor-file:", 23) == 0 ||
|
||||
strncmp(t, "trust-anchor-file:", 18) == 0 ||
|
||||
strncmp(t, "trust-anchor:", 13) == 0)
|
||||
*dnssec = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static void t_unbound_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char path[1024];
|
||||
char iface_value[128];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files = 0;
|
||||
int iface_all = 0;
|
||||
int open_resolver = 0;
|
||||
int dnssec = 0;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
iface_value[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
snprintf(path, sizeof(path), "%s/etc/unbound/unbound.conf", root);
|
||||
unbound_scan_file(&findings, &first, &count, path, &files, &iface_all,
|
||||
&open_resolver, &dnssec, iface_value,
|
||||
sizeof(iface_value));
|
||||
snprintf(path, sizeof(path), "%s/etc/unbound/unbound.conf.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 < 6 ||
|
||||
strcmp(ent->d_name + nl - 5, ".conf") != 0)
|
||||
continue;
|
||||
snprintf(full, sizeof(full), "%.800s/%.160s",
|
||||
path, ent->d_name);
|
||||
if (stat(full, &st) != 0 ||
|
||||
!S_ISREG(st.st_mode))
|
||||
continue;
|
||||
unbound_scan_file(&findings, &first, &count,
|
||||
full, &files, &iface_all,
|
||||
&open_resolver, &dnssec,
|
||||
iface_value,
|
||||
sizeof(iface_value));
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
if (files == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read an Unbound configuration");
|
||||
return;
|
||||
}
|
||||
if (iface_all) {
|
||||
add_finding(&findings, &first, "interface-all", "high",
|
||||
"Unbound listens on every interface");
|
||||
count++;
|
||||
}
|
||||
if (open_resolver) {
|
||||
add_finding(&findings, &first, "open-resolver", "high",
|
||||
"access-control allows recursion for every client");
|
||||
count++;
|
||||
}
|
||||
if (!dnssec) {
|
||||
add_finding(&findings, &first, "no-dnssec", "medium",
|
||||
"no DNSSEC trust anchor is configured");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"interface\":", files);
|
||||
apex_json_str(&b, iface_value);
|
||||
mcp_buf_printf(&b, ",\"dnssec\":%s,\"findings_count\":%d,"
|
||||
"\"findings\":[", dnssec ? "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);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- cups_audit */
|
||||
|
||||
static void t_cups_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
static char text[65536];
|
||||
char path[1024];
|
||||
char listen_value[128];
|
||||
char browsing[32];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int listen_all = 0;
|
||||
int browsing_on = 0;
|
||||
int allow_all = 0;
|
||||
struct stat st;
|
||||
|
||||
(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/cups/cupsd.conf", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read cupsd.conf");
|
||||
return;
|
||||
}
|
||||
listen_value[0] = browsing[0] = '\0';
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"cupsd.conf is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
{
|
||||
char *copy = strdup(text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
int in_location = 0;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *t = line;
|
||||
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
if (*t != '#' && *t != '\0') {
|
||||
if (strncmp(t, "Listen", 6) == 0) {
|
||||
snprintf(listen_value,
|
||||
sizeof(listen_value),
|
||||
"%.100s", t + 6);
|
||||
if (strstr(t, "0.0.0.0") != NULL ||
|
||||
strstr(t, "[::]") != NULL ||
|
||||
strstr(t, " ::") != NULL)
|
||||
listen_all = 1;
|
||||
}
|
||||
if (strncmp(t, "Browsing", 8) == 0) {
|
||||
char *v = t + 8;
|
||||
|
||||
while (*v == ' ' || *v == '\t')
|
||||
v++;
|
||||
snprintf(browsing,
|
||||
sizeof(browsing),
|
||||
"%.24s", v);
|
||||
if (strncasecmp(v, "On", 2) == 0)
|
||||
browsing_on = 1;
|
||||
}
|
||||
if (strncmp(t, "<Location", 9) == 0)
|
||||
in_location = 1;
|
||||
else if (strncmp(t, "</Location>", 11) == 0)
|
||||
in_location = 0;
|
||||
else if (in_location &&
|
||||
strstr(t, "Allow All") != NULL)
|
||||
allow_all = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
}
|
||||
if (listen_all) {
|
||||
add_finding(&findings, &first, "listen-all", "high",
|
||||
"CUPS listens on every interface");
|
||||
count++;
|
||||
}
|
||||
if (browsing_on) {
|
||||
add_finding(&findings, &first, "browsing", "low",
|
||||
"printer browsing broadcasts on the network");
|
||||
count++;
|
||||
}
|
||||
if (allow_all) {
|
||||
add_finding(&findings, &first, "allow-all", "high",
|
||||
"a Location block allows every client");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_puts(&b, ",\"listen\":");
|
||||
apex_json_str(&b, listen_value);
|
||||
mcp_buf_puts(&b, ",\"browsing\":");
|
||||
apex_json_str(&b, browsing);
|
||||
mcp_buf_printf(&b, ",\"findings_count\":%d,\"findings\":[", count);
|
||||
if (findings.p != NULL)
|
||||
mcp_buf_add(&b, findings.p, findings.len);
|
||||
mcp_buf_puts(&b, "]}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_BLUE[] = {
|
||||
{ "hardening_audit",
|
||||
"Read-only posture audit of the local host: sshd_config (root login, "
|
||||
@@ -9015,6 +9376,26 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_elasticsearch_config_audit },
|
||||
{ "squid_audit",
|
||||
"Parse squid.conf (root prefix): http_access allow all, an http_port "
|
||||
"listening on every interface, a cache_dir in /tmp or /dev/shm and a "
|
||||
"world-writable config. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_squid_audit },
|
||||
{ "unbound_audit",
|
||||
"Parse unbound.conf and unbound.conf.d (root prefix): interface on every "
|
||||
"address, access-control 0.0.0.0/0 or ::/0 allow, a missing DNSSEC trust "
|
||||
"anchor and world-writable files. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_unbound_audit },
|
||||
{ "cups_audit",
|
||||
"Parse cupsd.conf (root prefix): Listen on every interface, Browsing On, "
|
||||
"a Location block with Allow All and a world-writable config. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_cups_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
@@ -5322,6 +5322,132 @@ static void t_tls_ocsp_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- alpn_probe */
|
||||
|
||||
static void alpn_after(const char *text, char *out, size_t n)
|
||||
{
|
||||
static const char key[] = "ALPN protocol: ";
|
||||
const char *p = strstr(text, key);
|
||||
size_t w = 0;
|
||||
|
||||
out[0] = '\0';
|
||||
if (p == NULL)
|
||||
return;
|
||||
p += sizeof(key) - 1;
|
||||
while (*p != '\0' && *p != '\r' && *p != '\n' && w + 1 < n)
|
||||
out[w++] = *p++;
|
||||
out[w] = '\0';
|
||||
}
|
||||
|
||||
static void t_alpn_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *defaults[] = { "h2", "http/1.1", "spdy/3.1", NULL };
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
const char *list_arg = mcp_arg_string(args, "protocols");
|
||||
int port = mcp_arg_int(args, "port", 443);
|
||||
char conn[320];
|
||||
char names[8][64];
|
||||
int nnames = 0;
|
||||
mcp_buf b;
|
||||
int first = 1;
|
||||
int accepted = 0;
|
||||
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 (list_arg != NULL && *list_arg != '\0') {
|
||||
char *copy = strdup(list_arg);
|
||||
char *save = NULL;
|
||||
char *tok;
|
||||
|
||||
if (copy == NULL) {
|
||||
mcp_reply_error(c, "out of memory");
|
||||
return;
|
||||
}
|
||||
tok = strtok_r(copy, ",", &save);
|
||||
while (tok != NULL && nnames < 8) {
|
||||
while (*tok == ' ' || *tok == '\t')
|
||||
tok++;
|
||||
if (*tok != '\0') {
|
||||
snprintf(names[nnames], sizeof(names[0]),
|
||||
"%.48s", tok);
|
||||
nnames++;
|
||||
}
|
||||
tok = strtok_r(NULL, ",", &save);
|
||||
}
|
||||
free(copy);
|
||||
} else {
|
||||
for (i = 0; defaults[i] != NULL && nnames < 8; i++)
|
||||
snprintf(names[nnames++], sizeof(names[0]), "%s",
|
||||
defaults[i]);
|
||||
}
|
||||
if (nnames == 0) {
|
||||
mcp_reply_error(c, "no protocols given");
|
||||
return;
|
||||
}
|
||||
if (!apex_have("openssl")) {
|
||||
mcp_reply_error(c, "openssl is not installed on this host");
|
||||
return;
|
||||
}
|
||||
if (!gated(c, "alpn_probe", target, port))
|
||||
return;
|
||||
tls_conn_string(target, port, conn, sizeof(conn));
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"target\":");
|
||||
apex_json_str(&b, target);
|
||||
mcp_buf_printf(&b, ",\"port\":%d,\"tested\":[", port);
|
||||
for (i = 0; i < nnames; i++) {
|
||||
char *argv[12];
|
||||
int k = 0;
|
||||
apex_proc p;
|
||||
char negotiated[64];
|
||||
int ok = 0;
|
||||
|
||||
argv[k++] = "openssl";
|
||||
argv[k++] = "s_client";
|
||||
argv[k++] = "-connect";
|
||||
argv[k++] = conn;
|
||||
argv[k++] = "-servername";
|
||||
argv[k++] = (char *)target;
|
||||
argv[k++] = "-alpn";
|
||||
argv[k++] = names[i];
|
||||
argv[k] = NULL;
|
||||
negotiated[0] = '\0';
|
||||
if (apex_run(argv, 15000, g_cfg.max_output, &p) == 0) {
|
||||
if (p.out != NULL) {
|
||||
alpn_after(p.out, negotiated,
|
||||
sizeof(negotiated));
|
||||
ok = strcmp(negotiated, names[i]) == 0;
|
||||
}
|
||||
apex_proc_free(&p);
|
||||
}
|
||||
if (ok)
|
||||
accepted++;
|
||||
if (!first)
|
||||
mcp_buf_puts(&b, ",");
|
||||
first = 0;
|
||||
mcp_buf_puts(&b, "{\"protocol\":");
|
||||
apex_json_str(&b, names[i]);
|
||||
mcp_buf_printf(&b, ",\"accepted\":%s,\"negotiated\":",
|
||||
ok ? "true" : "false");
|
||||
apex_json_str(&b, negotiated);
|
||||
mcp_buf_puts(&b, "}");
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"accepted_count\":%d}", accepted);
|
||||
apex_audit("alpn_probe", target, port, accepted == 0,
|
||||
accepted == 0 ? "no ALPN protocol accepted"
|
||||
: "ALPN protocols accepted", "s_client -alpn");
|
||||
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 "
|
||||
@@ -5649,6 +5775,16 @@ const mcp_tool TOOLS_PROTO[] = {
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_tls_ocsp_probe },
|
||||
{ "alpn_probe",
|
||||
"Offer each ALPN protocol in turn (h2, http/1.1, spdy/3.1 by default) with "
|
||||
"openssl s_client -alpn and report which ones the server selects. One "
|
||||
"handshake per protocol, gated once. Gate: the target must be in scope.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"},"
|
||||
"\"protocols\":{\"type\":\"string\",\"description\":\"comma list, max 8\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_alpn_probe },
|
||||
};
|
||||
|
||||
const size_t TOOLS_PROTO_N = sizeof(TOOLS_PROTO) / sizeof(TOOLS_PROTO[0]);
|
||||
+1
-1
@@ -21,7 +21,7 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 167
|
||||
EXPECTED_TOOLS = 171
|
||||
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.
|
||||
|
||||
+131
-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("167 tools registered", len(tools) == 167, len(tools))
|
||||
check("171 tools registered", len(tools) == 171, 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"]) == 167)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 171)
|
||||
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
|
||||
@@ -7595,6 +7595,135 @@ shutil.rmtree(es_good_root, ignore_errors=True)
|
||||
shutil.rmtree(ocsp_dir, ignore_errors=True)
|
||||
shutil.rmtree(cfg4_home, ignore_errors=True)
|
||||
|
||||
print("\n== Squid, Unbound, CUPS and ALPN ==\n")
|
||||
|
||||
sq_root = tempfile.mkdtemp(prefix="apex-sq-")
|
||||
os.makedirs(os.path.join(sq_root, "etc", "squid"))
|
||||
sq_bad = os.path.join(sq_root, "etc", "squid", "squid.conf")
|
||||
with open(sq_bad, "w") as f:
|
||||
f.write("http_port 0.0.0.0:3128\n")
|
||||
f.write("http_access allow all\n")
|
||||
f.write("cache_dir ufs /tmp/squid 100 16 256\n")
|
||||
os.chmod(sq_bad, 0o666)
|
||||
sq_good_root = tempfile.mkdtemp(prefix="apex-sqg-")
|
||||
os.makedirs(os.path.join(sq_good_root, "etc", "squid"))
|
||||
with open(os.path.join(sq_good_root, "etc", "squid", "squid.conf"),
|
||||
"w") as f:
|
||||
f.write("http_port 3128\n")
|
||||
f.write("http_access allow localnet\n")
|
||||
f.write("http_access deny all\n")
|
||||
f.write("cache_dir ufs /var/spool/squid 100 16 256\n")
|
||||
|
||||
ub_root = tempfile.mkdtemp(prefix="apex-ub-")
|
||||
os.makedirs(os.path.join(ub_root, "etc", "unbound", "unbound.conf.d"))
|
||||
ub_bad = os.path.join(ub_root, "etc", "unbound", "unbound.conf")
|
||||
with open(ub_bad, "w") as f:
|
||||
f.write("server:\n")
|
||||
f.write(" interface: 0.0.0.0\n")
|
||||
f.write(" access-control: 0.0.0.0/0 allow\n")
|
||||
os.chmod(ub_bad, 0o666)
|
||||
ub_good_root = tempfile.mkdtemp(prefix="apex-ubg-")
|
||||
os.makedirs(os.path.join(ub_good_root, "etc", "unbound"))
|
||||
with open(os.path.join(ub_good_root, "etc", "unbound", "unbound.conf"),
|
||||
"w") as f:
|
||||
f.write("server:\n")
|
||||
f.write(" interface: 127.0.0.1\n")
|
||||
f.write(" access-control: 127.0.0.0/8 allow\n")
|
||||
f.write(' auto-trust-anchor-file: "/var/lib/unbound/root.key"\n')
|
||||
|
||||
cu_root = tempfile.mkdtemp(prefix="apex-cu-")
|
||||
os.makedirs(os.path.join(cu_root, "etc", "cups"))
|
||||
cu_bad = os.path.join(cu_root, "etc", "cups", "cupsd.conf")
|
||||
with open(cu_bad, "w") as f:
|
||||
f.write("Listen 0.0.0.0:631\n")
|
||||
f.write("Browsing On\n")
|
||||
f.write("<Location />\n Allow All\n</Location>\n")
|
||||
os.chmod(cu_bad, 0o666)
|
||||
cu_good_root = tempfile.mkdtemp(prefix="apex-cug-")
|
||||
os.makedirs(os.path.join(cu_good_root, "etc", "cups"))
|
||||
with open(os.path.join(cu_good_root, "etc", "cups", "cupsd.conf"),
|
||||
"w") as f:
|
||||
f.write("Listen localhost:631\n")
|
||||
f.write("Browsing Off\n")
|
||||
f.write("<Location />\n Allow localhost\n</Location>\n")
|
||||
|
||||
alpn_dir = tempfile.mkdtemp(prefix="apex-alpn2-")
|
||||
alpn_cert = os.path.join(alpn_dir, "cert.pem")
|
||||
alpn_key = os.path.join(alpn_dir, "key.pem")
|
||||
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
|
||||
"-keyout", alpn_key, "-out", alpn_cert, "-days", "2",
|
||||
"-subj", "/CN=localhost"],
|
||||
check=True, capture_output=True)
|
||||
alpn_srv2, alpn_port2 = alpn_server(alpn_cert, alpn_key)
|
||||
|
||||
cfg5_home = tempfile.mkdtemp(prefix="apex-cfg5-home-")
|
||||
write_scope(cfg5_home, {"label": "cfg5", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": [str(alpn_port2)]})
|
||||
res, _ = run([
|
||||
call(1, "squid_audit", root=sq_root),
|
||||
call(2, "squid_audit", root=sq_good_root),
|
||||
call(3, "unbound_audit", root=ub_root),
|
||||
call(4, "unbound_audit", root=ub_good_root),
|
||||
call(5, "cups_audit", root=cu_root),
|
||||
call(6, "cups_audit", root=cu_good_root),
|
||||
call(7, "alpn_probe", target="127.0.0.1", port=alpn_port2),
|
||||
call(8, "squid_audit", root="/nonexistent-sq"),
|
||||
call(9, "unbound_audit", root="/nonexistent-ub"),
|
||||
call(10, "cups_audit", root="/nonexistent-cu"),
|
||||
call(11, "alpn_probe", target="198.51.100.9", port=443),
|
||||
], home=cfg5_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
sq = json.loads(text(by_id[1]))
|
||||
sq_kinds = {f["id"] for f in sq["findings"]}
|
||||
check("squid_audit flags allow-all, open port and temp cache",
|
||||
{"allow-all", "open-port", "temp-cache", "world-writable"} <= sq_kinds,
|
||||
sq)
|
||||
sq_good = json.loads(text(by_id[2]))
|
||||
check("squid_audit accepts a hardened config",
|
||||
sq_good["findings_count"] == 0 and sq_good["allow_all"] is False,
|
||||
sq_good)
|
||||
ub = json.loads(text(by_id[3]))
|
||||
ub_kinds = {f["id"] for f in ub["findings"]}
|
||||
check("unbound_audit flags interface-all, open resolver and no DNSSEC",
|
||||
{"interface-all", "open-resolver", "no-dnssec", "world-writable"} <=
|
||||
ub_kinds, ub)
|
||||
ub_good = json.loads(text(by_id[4]))
|
||||
check("unbound_audit accepts a hardened config",
|
||||
ub_good["findings_count"] == 0 and ub_good["dnssec"] is True and
|
||||
ub_good["interface"] == "127.0.0.1", ub_good)
|
||||
cu = json.loads(text(by_id[5]))
|
||||
cu_kinds = {f["id"] for f in cu["findings"]}
|
||||
check("cups_audit flags listen-all, browsing and Allow All",
|
||||
{"listen-all", "browsing", "allow-all", "world-writable"} <= cu_kinds,
|
||||
cu)
|
||||
cu_good = json.loads(text(by_id[6]))
|
||||
check("cups_audit accepts a hardened config",
|
||||
cu_good["findings_count"] == 0 and cu_good["browsing"] == "Off",
|
||||
cu_good)
|
||||
alpn = json.loads(text(by_id[7]))
|
||||
by_proto = {e["protocol"]: e for e in alpn["tested"]}
|
||||
check("alpn_probe finds h2 and http/1.1", alpn["accepted_count"] == 2 and
|
||||
by_proto["h2"]["accepted"] is True and
|
||||
by_proto["http/1.1"]["accepted"] is True, alpn)
|
||||
check("alpn_probe reports spdy/3.1 as refused",
|
||||
by_proto["spdy/3.1"]["accepted"] is False, by_proto["spdy/3.1"])
|
||||
check("squid_audit reports a missing config", err(by_id[8]), text(by_id[8]))
|
||||
check("unbound_audit reports a missing config", err(by_id[9]),
|
||||
text(by_id[9]))
|
||||
check("cups_audit reports a missing config", err(by_id[10]), text(by_id[10]))
|
||||
check("alpn_probe refuses an out-of-scope target", err(by_id[11]),
|
||||
text(by_id[11]))
|
||||
alpn_srv2.close()
|
||||
shutil.rmtree(sq_root, ignore_errors=True)
|
||||
shutil.rmtree(sq_good_root, ignore_errors=True)
|
||||
shutil.rmtree(ub_root, ignore_errors=True)
|
||||
shutil.rmtree(ub_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cu_root, ignore_errors=True)
|
||||
shutil.rmtree(cu_good_root, ignore_errors=True)
|
||||
shutil.rmtree(alpn_dir, ignore_errors=True)
|
||||
shutil.rmtree(cfg5_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"})
|
||||
|
||||
Reference in new issue
Block a user