apex-twin 1.45.0: journald, coredump and nftables audits, HSTS check

Blue:
- journald_audit: journald.conf: Storage=volatile/none, ForwardToSyslog=no,
  SystemMaxUse above 1G, Seal=no and a world-writable file.
- coredump_audit: coredump.conf: explicit or default Storage=external (cores
  persist on disk), Compress=no and a world-writable file. ProcessSizeMax=0
  is not flagged: it means unlimited processing, not disabled storage.
- nftables_audit: nftables.conf and nftables.d/*.nft: policy accept, no
  established/related rule, admin ports (22/3306/5432/6379/27017/9200) opened
  without a saddr check and world-writable files.

Red:
- hsts_audit: one TLS GET: missing Strict-Transport-Security, max-age zero or
  below six months, missing includeSubDomains and preload.

Tests with journald/coredump/nftables trees and a TLS server serving weak,
strong and absent HSTS headers. 996 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.45.0.
This commit is contained in:
lotherk committed 2026-11-22 09:46:12 +00:00
1 parent 3a6e1e4a83
commit 38ce77698d
9 files changed
+703 -15

No files matched your search

+19 -1
View File
@@ -8,7 +8,25 @@ 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.44.0 — 2026-11-23 — this change
## 1.45.0 — 2026-11-23 — this change
- **journald** (`journald_audit`): `journald.conf`: `Storage=volatile` or
`none`, `ForwardToSyslog=no`, `SystemMaxUse` above one gigabyte, `Seal=no`
and a world-writable file.
- **coredump** (`coredump_audit`): `coredump.conf`: explicit or default
`Storage=external` (cores persist on disk and may hold secrets),
`Compress=no` and a world-writable file. `ProcessSizeMax=0` is *not* a
finding: it means an unlimited size, not disabled storage.
- **nftables** (`nftables_audit`): `nftables.conf` and `nftables.d/*.nft`:
`policy accept`, no established/related rule, ports 22/3306/5432/6379/27017/9200
opened without a `saddr` check and world-writable files.
- **HSTS** (`hsts_audit`): one TLS GET: missing
`Strict-Transport-Security`, `max-age` of zero or below six months, missing
`includeSubDomains` and `preload`.
- Tests with journald/coredump/nftables trees and a TLS server serving weak,
strong and absent HSTS headers. 996 checks. Coverage 82.8%.
## 1.44.0 — 2026-11-23 — 3a6e1e4
- **Certificates** (`ssl_cert_audit`): every certificate under
`/etc/ssl/certs` (root prefix) through `openssl x509`: expired or not yet
+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.
**214 tools · 983 end-to-end checks · 340 fuzz cases · 82.8% line coverage · ~805 KiB**
**218 tools · 996 end-to-end checks · 340 fuzz cases · 82.8% line coverage · ~813 KiB**
```
$ ./apex-twin --check
{"version":"1.44.0","tools":214,...,"scope":{"loaded":true,...}}
{"version":"1.45.0","tools":218,...,"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 (214)
## Tools (218)
### Scope and bookkeeping
@@ -203,6 +203,7 @@ uploads and secret-file reads. It does not execute anything.
| `http_paths` | Built-in wordlist: `.git`, `.env`, admin, actuator, swagger, backups |
| `cors_check` | Marker `Origin`; grades reflection with credentials as high risk |
| `http_redirect_audit` | Follows redirects per hop inside the scope; flags HTTPS-to-HTTP downgrades |
| `hsts_audit` | HSTS max-age, includeSubDomains and preload, or a missing header |
| `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 |
@@ -411,6 +412,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `ssl_cert_audit` | /etc/ssl/certs: expired, SHA-1, weak key, non-critical CA |
| `timesyncd_audit` | timesyncd.conf: no servers, public fallback, lax polling |
| `resolv_conf_audit` | resolv.conf: no/single/public nameserver, no search domain |
| `journald_audit` | journald.conf: volatile storage, forwarding, size, sealing |
| `coredump_audit` | coredump.conf: disk storage keeps cores, no compression |
| `nftables_audit` | nftables: accept policy, no conntrack, exposed admin ports |
### ESP32
@@ -687,6 +691,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| certificate store | local openssl parse only |
| timesyncd/resolv.conf | config reads only; optional root prefix |
| SOA MNAME | two dig queries |
| journald/coredump/nftables | config reads only; optional root prefix |
| HSTS | one TLS GET |
| USB audit | 200 devices, sysfs reads only |
---
@@ -698,7 +704,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 983 end-to-end checks
make test # version check + gate audit + 996 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
@@ -820,7 +826,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
kubernetes_api_probe, dns_ns_consistency,
dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check,
dns_soa_mname_check
dns_soa_mname_check, hsts_audit
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,
@@ -863,7 +869,7 @@ examples/ scope.json
## Status
1.44.0. Built and run: 214 tools, 983 checks, 340 fuzz cases and 82.8% line
1.45.0. Built and run: 218 tools, 996 checks, 340 fuzz cases and 82.8% 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
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.44.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.45.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.
- **journald, coredump and nftables audits read local files.** The HSTS
check makes one TLS GET.
- **Certificate, timesyncd and resolv.conf audits read local files.** The
certificate audit parses each file with `openssl x509`; no network is used.
- **pg_hba, polkit and LDAP client audits read local configuration.** The
+5 -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.44.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.45.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -45,7 +45,8 @@ 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, 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),
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit,
websocket_origin_check, hsts_audit),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -65,7 +66,8 @@ etcd_config_audit, rabbitmq_audit, consul_config_audit, vault_config_audit,
zookeeper_audit, grafana_audit, prometheus_audit, wireguard_config_audit,
ipsec_config_audit, openldap_config_audit, cron_audit, fail2ban_audit, chrony_config_audit,
apt_config_audit, login_defs_audit, pg_hba_audit, polkit_audit,
ldap_client_audit, ssl_cert_audit, timesyncd_audit, resolv_conf_audit)
ldap_client_audit, ssl_cert_audit, timesyncd_audit, resolv_conf_audit, journald_audit,
coredump_audit, nftables_audit)
and ESP32 board tools (esp_info, esp_monitor,
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
esp_app_info, esp_image_verify).
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.44.0"
#define APEX_VERSION "1.45.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+359
View File
@@ -12859,6 +12859,344 @@ static void t_resolv_conf_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* -------------------------------------------------------------- journald_audit */
static long long parse_size_bytes(const char *value)
{
char *end = NULL;
long long n = strtoll(value, &end, 10);
if (end == value || n < 0)
return -1;
while (*end == ' ')
end++;
switch (*end) {
case 'K':
case 'k':
n *= 1024LL;
break;
case 'M':
case 'm':
n *= 1024LL * 1024LL;
break;
case 'G':
case 'g':
n *= 1024LL * 1024LL * 1024LL;
break;
case 'T':
case 't':
n *= 1024LL * 1024LL * 1024LL * 1024LL;
break;
default:
break;
}
return n;
}
static void t_journald_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 storage[64];
char value[128];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int volatile_store = 0;
int no_store = 0;
int no_forward = 0;
int large_store = 0;
int no_sealing = 0;
long long bytes;
(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/systemd/journald.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read journald.conf");
return;
}
storage[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"journald.conf is writable by anyone");
count++;
}
ini_value(text, "Journal", "Storage", storage, sizeof(storage));
if (strcasecmp(storage, "volatile") == 0) {
volatile_store = 1;
add_finding(&findings, &first, "volatile-storage", "medium",
"the journal is kept in memory only");
count++;
} else if (strcasecmp(storage, "none") == 0) {
no_store = 1;
add_finding(&findings, &first, "no-storage", "high",
"the journal keeps no records");
count++;
}
if (ini_value(text, "Journal", "ForwardToSyslog", value,
sizeof(value)) &&
strcasecmp(value, "no") == 0) {
no_forward = 1;
add_finding(&findings, &first, "no-forward", "low",
"records are not forwarded to syslog");
count++;
}
if (ini_value(text, "Journal", "SystemMaxUse", value, sizeof(value))) {
bytes = parse_size_bytes(value);
if (bytes > 1024LL * 1024LL * 1024LL) {
large_store = 1;
add_finding(&findings, &first, "large-store", "low",
"SystemMaxUse is above one gigabyte");
count++;
}
}
if (ini_value(text, "Journal", "Seal", value, sizeof(value)) &&
strcasecmp(value, "no") == 0) {
no_sealing = 1;
add_finding(&findings, &first, "no-sealing", "low",
"forward-secure sealing is disabled");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"storage\":");
apex_json_str(&b, storage[0] != '\0' ? storage : "auto");
mcp_buf_printf(&b, ",\"volatile\":%s,\"no_storage\":%s,"
"\"forward_to_syslog\":%s,\"large_store\":%s,"
"\"sealed\":%s,\"findings_count\":%d,\"findings\":[",
volatile_store ? "true" : "false",
no_store ? "true" : "false",
no_forward ? "false" : "true",
large_store ? "true" : "false",
no_sealing ? "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);
}
/* -------------------------------------------------------------- coredump_audit */
static void t_coredump_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 storage[64];
char value[64];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int external = 0;
int no_compression = 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/systemd/coredump.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read coredump.conf");
return;
}
storage[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"coredump.conf is writable by anyone");
count++;
}
ini_value(text, "Coredump", "Storage", storage, sizeof(storage));
if (storage[0] == '\0' || strcasecmp(storage, "external") == 0) {
external = 1;
add_finding(&findings, &first, "external-storage", "medium",
"cores are written to disk and may hold secrets");
count++;
}
if (ini_value(text, "Coredump", "Compress", value, sizeof(value)) &&
strcasecmp(value, "no") == 0) {
no_compression = 1;
add_finding(&findings, &first, "no-compression", "low",
"cores are stored uncompressed");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"storage\":");
apex_json_str(&b, storage[0] != '\0' ? storage : "external");
mcp_buf_printf(&b, ",\"external\":%s,\"compressed\":%s,"
"\"findings_count\":%d,\"findings\":[",
external ? "true" : "false",
no_compression ? "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);
}
/* -------------------------------------------------------------- nftables_audit */
static int nft_open_port(const char *text, const char *port)
{
char needle[32];
char *copy;
char *save = NULL;
char *line;
int found = 0;
snprintf(needle, sizeof(needle), "dport %s", port);
copy = strdup(text);
if (copy == NULL)
return 0;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s != '#' && strstr(s, needle) != NULL &&
strstr(s, "saddr") == NULL) {
found = 1;
break;
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
return found;
}
static void nft_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files, int *policy_accept,
int *conntrack, int *open_ports)
{
static char text[65536];
struct stat st;
static const char *ports[] = { "22", "3306", "5432", "6379", "27017",
"9200", NULL };
int i;
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 (strstr(text, "policy accept") != NULL) {
*policy_accept = 1;
add_finding(findings, first, "policy-accept", "high",
"%s accepts traffic by default", path);
(*count)++;
}
if (strstr(text, "ct state established") != NULL ||
strstr(text, "ct state related") != NULL)
*conntrack = 1;
for (i = 0; ports[i] != NULL; i++) {
if (nft_open_port(text, ports[i])) {
add_finding(findings, first, "open-port", "medium",
"%s opens port %s without a source check",
path, ports[i]);
(*count)++;
(*open_ports)++;
}
}
}
static void t_nftables_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int policy_accept = 0;
int conntrack = 0;
int open_ports = 0;
DIR *d;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
snprintf(path, sizeof(path), "%s/etc/nftables.conf", root);
nft_scan_file(&findings, &first, &count, path, &files, &policy_accept,
&conntrack, &open_ports);
snprintf(path, sizeof(path), "%s/etc/nftables.d", root);
d = opendir(path);
if (d != NULL) {
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
char full[1200];
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (nl < 4 || strcmp(ent->d_name + nl - 4, ".nft") != 0)
continue;
snprintf(full, sizeof(full), "%.900s/%.200s", path,
ent->d_name);
nft_scan_file(&findings, &first, &count, full, &files,
&policy_accept, &conntrack,
&open_ports);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read an nftables ruleset");
return;
}
if (!conntrack) {
add_finding(&findings, &first, "no-conntrack", "low",
"no established/related rule keeps stateful replies "
"open");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"policy_accept\":%s,"
"\"conntrack\":%s,\"open_ports\":%d,"
"\"findings_count\":%d,\"findings\":[",
files, policy_accept ? "true" : "false",
conntrack ? "true" : "false", open_ports, 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, "
@@ -13561,6 +13899,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_resolv_conf_audit },
{ "journald_audit",
"Parse journald.conf (root prefix): Storage volatile or none, "
"ForwardToSyslog off, SystemMaxUse above one gigabyte, Seal=no and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_journald_audit },
{ "coredump_audit",
"Parse coredump.conf (root prefix): the default or explicit external "
"storage that persists cores, Compress=no and a world-writable file. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_coredump_audit },
{ "nftables_audit",
"Parse nftables.conf and nftables.d/*.nft (root prefix): a policy of "
"accept, no established/related rule, sensitive ports opened without a "
"saddr check and world-writable files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_nftables_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+118
View File
@@ -1529,6 +1529,113 @@ static void t_http_redirect_audit(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* ------------------------------------------------------------------- hsts_audit */
static void t_hsts_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *target = mcp_arg_string(args, "target");
const char *path = mcp_arg_string(args, "path");
int port = mcp_arg_int(args, "port", 443);
int tls = mcp_arg_bool(args, "tls", port == 443 || looks_tls(port));
char hsts[600];
char status[256];
char *resp = NULL;
size_t len = 0;
const char *p;
int max_age = -1;
int include;
int preload;
int missing;
int short_age;
int zero_age;
int first = 1;
mcp_buf b;
(void)user;
if (target == NULL || *target == '\0') {
mcp_reply_error(c, "target is required");
return;
}
if (path == NULL || *path == '\0')
path = "/";
if (!safe_token(path, 512) || path[0] != '/') {
mcp_reply_error(c, "path must start with / and contain no control "
"characters");
return;
}
if (port <= 0 || port > 65535) {
mcp_reply_error(c, "port out of range");
return;
}
if (!gated(c, "hsts_audit", target, port))
return;
status[0] = '\0';
if (http_once(target, port, tls, "GET", path, NULL, NULL, 15000, &resp,
&len, status, sizeof(status), NULL, NULL) != 0) {
mcp_reply_error(c, "no response");
return;
}
hsts[0] = '\0';
resp_header(resp, "strict-transport-security", hsts, sizeof(hsts));
free(resp);
missing = hsts[0] == '\0';
if (!missing) {
p = strcasestr(hsts, "max-age=");
if (p != NULL)
max_age = atoi(p + 8);
}
include = strcasestr(hsts, "includesubdomains") != NULL;
preload = strcasestr(hsts, "preload") != NULL;
zero_age = max_age == 0;
short_age = max_age > 0 && max_age < 15552000;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"header\":", port,
tls ? "true" : "false");
apex_json_str(&b, hsts);
mcp_buf_printf(&b, ",\"max_age\":%d,\"include_subdomains\":%s,"
"\"preload\":%s,\"issues\":[",
max_age, include ? "true" : "false",
preload ? "true" : "false");
if (missing) {
mcp_buf_puts(&b, "{\"id\":\"missing-hsts\",\"severity\":\"high\"}");
first = 0;
}
if (zero_age) {
if (!first)
mcp_buf_puts(&b, ",");
mcp_buf_puts(&b, "{\"id\":\"max-age-zero\",\"severity\":\"high\"}");
first = 0;
} else if (short_age) {
if (!first)
mcp_buf_puts(&b, ",");
mcp_buf_puts(&b, "{\"id\":\"short-max-age\",\"severity\":\"medium\"}");
first = 0;
}
if (!missing && !include) {
if (!first)
mcp_buf_puts(&b, ",");
mcp_buf_puts(&b, "{\"id\":\"no-subdomains\",\"severity\":\"low\"}");
first = 0;
}
if (!missing && !preload) {
if (!first)
mcp_buf_puts(&b, ",");
mcp_buf_puts(&b, "{\"id\":\"no-preload\",\"severity\":\"info\"}");
first = 0;
}
mcp_buf_puts(&b, "]}");
apex_audit("hsts_audit", target, port,
!(missing || zero_age || short_age),
missing ? "no Strict-Transport-Security header"
: zero_age ? "HSTS max-age is zero"
: short_age ? "HSTS max-age is below six months"
: "HSTS is present and long-lived", hsts);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_WEB[] = {
{ "http_request",
"Send one HTTP request and return status line plus the whole response. Use "
@@ -1600,6 +1707,17 @@ const mcp_tool TOOLS_WEB[] = {
"\"max_hops\":{\"type\":\"integer\",\"description\":\"default 5\"}},"
"\"required\":[\"target\"]}",
t_http_redirect_audit },
{ "hsts_audit",
"Fetch one page over TLS and grade Strict-Transport-Security: missing "
"header, max-age of zero or below six months, missing includeSubDomains "
"and missing preload. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"},"
"\"tls\":{\"type\":\"boolean\"},"
"\"path\":{\"type\":\"string\",\"description\":\"default /\"}},"
"\"required\":[\"target\"]}",
t_hsts_audit },
{ "cookie_audit",
"Collect the Set-Cookie headers and audit each cookie: Secure, HttpOnly, "
"SameSite, and the SameSite=None-without-Secure combination browsers "
+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 = 214
EXPECTED_TOOLS = 218
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.
+185 -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("214 tools registered", len(tools) == 214, len(tools))
check("218 tools registered", len(tools) == 218, 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"]) == 214)
check("http tools/list", len(listing["result"]["tools"]) == 218)
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
@@ -9888,12 +9888,195 @@ shutil.rmtree(rc_root, ignore_errors=True)
shutil.rmtree(rc_good_root, ignore_errors=True)
shutil.rmtree(cfg16_home, ignore_errors=True)
print("\n== journald, coredump, nftables and HSTS ==\n")
jr_root = tempfile.mkdtemp(prefix="apex-jr-")
os.makedirs(os.path.join(jr_root, "etc", "systemd"))
jr_bad = os.path.join(jr_root, "etc", "systemd", "journald.conf")
with open(jr_bad, "w") as f:
f.write("[Journal]\n")
f.write("Storage=volatile\n")
f.write("ForwardToSyslog=no\n")
f.write("SystemMaxUse=4G\n")
f.write("Seal=no\n")
os.chmod(jr_bad, 0o666)
jr_good_root = tempfile.mkdtemp(prefix="apex-jrg-")
os.makedirs(os.path.join(jr_good_root, "etc", "systemd"))
with open(os.path.join(jr_good_root, "etc", "systemd", "journald.conf"),
"w") as f:
f.write("[Journal]\n")
f.write("Storage=persistent\n")
f.write("ForwardToSyslog=yes\n")
f.write("SystemMaxUse=500M\n")
f.write("Seal=yes\n")
cd_root = tempfile.mkdtemp(prefix="apex-cd-")
os.makedirs(os.path.join(cd_root, "etc", "systemd"))
cd_bad = os.path.join(cd_root, "etc", "systemd", "coredump.conf")
with open(cd_bad, "w") as f:
f.write("[Coredump]\n")
f.write("Storage=external\n")
f.write("Compress=no\n")
os.chmod(cd_bad, 0o666)
cd_good_root = tempfile.mkdtemp(prefix="apex-cdg-")
os.makedirs(os.path.join(cd_good_root, "etc", "systemd"))
with open(os.path.join(cd_good_root, "etc", "systemd", "coredump.conf"),
"w") as f:
f.write("[Coredump]\n")
f.write("Storage=none\n")
f.write("Compress=yes\n")
nft_root = tempfile.mkdtemp(prefix="apex-nft-")
os.makedirs(os.path.join(nft_root, "etc"))
nft_bad = os.path.join(nft_root, "etc", "nftables.conf")
with open(nft_bad, "w") as f:
f.write("table inet filter {\n")
f.write(" chain input {\n")
f.write(" type filter hook input priority 0; policy accept;\n")
f.write(" tcp dport 22 accept\n")
f.write(" }\n}\n")
os.chmod(nft_bad, 0o666)
nft_good_root = tempfile.mkdtemp(prefix="apex-nftg-")
os.makedirs(os.path.join(nft_good_root, "etc"))
with open(os.path.join(nft_good_root, "etc", "nftables.conf"), "w") as f:
f.write("table inet filter {\n")
f.write(" chain input {\n")
f.write(" type filter hook input priority 0; policy drop;\n")
f.write(" ct state established,related accept\n")
f.write(" tcp dport 22 ip saddr 10.0.0.0/8 accept\n")
f.write(" }\n}\n")
def hsts_server(cert, key):
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
values = {
"/weak": "max-age=300",
"/strong": "max-age=63072000; includeSubDomains; preload",
}
body = b"ok"
self.send_response(200)
if path in values:
self.send_header("Strict-Transport-Security", values[path])
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
srv = http.server.HTTPServer(("127.0.0.1", 0), Handler)
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain(cert, key)
srv.socket = ctx.wrap_socket(srv.socket, server_side=True)
threading.Thread(target=srv.serve_forever, daemon=True).start()
return srv, srv.server_address[1]
hsts_dir = tempfile.mkdtemp(prefix="apex-hsts-")
hsts_cert = os.path.join(hsts_dir, "cert.pem")
hsts_key = os.path.join(hsts_dir, "key.pem")
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
"-keyout", hsts_key, "-out", hsts_cert, "-days", "2",
"-subj", "/CN=localhost",
"-addext", "basicConstraints=critical,CA:TRUE",
"-addext", "subjectAltName=IP:127.0.0.1"],
check=True, capture_output=True)
hsts_srv, hsts_port = hsts_server(hsts_cert, hsts_key)
cfg17_home = tempfile.mkdtemp(prefix="apex-cfg17-home-")
write_scope(cfg17_home, {"label": "cfg17", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(hsts_port)]})
res, _ = run([
call(1, "journald_audit", root=jr_root),
call(2, "journald_audit", root=jr_good_root),
call(3, "coredump_audit", root=cd_root),
call(4, "coredump_audit", root=cd_good_root),
call(5, "nftables_audit", root=nft_root),
call(6, "nftables_audit", root=nft_good_root),
call(7, "hsts_audit", target="127.0.0.1", port=hsts_port,
path="/weak", tls=True),
call(8, "hsts_audit", target="127.0.0.1", port=hsts_port,
path="/strong", tls=True),
call(9, "hsts_audit", target="127.0.0.1", port=hsts_port,
path="/none", tls=True),
call(10, "hsts_audit", target="198.51.100.9", port=443),
call(11, "journald_audit", root="/nonexistent-jr"),
call(12, "coredump_audit", root="/nonexistent-cd"),
call(13, "nftables_audit", root="/nonexistent-nft"),
], home=cfg17_home, extra_env={"CURL_CA_BUNDLE": hsts_cert})
by_id = {r.get("id"): r for r in res}
jr = json.loads(text(by_id[1]))
jr_kinds = {f["id"] for f in jr["findings"]}
check("journald_audit flags volatile storage, size and sealing",
{"world-writable", "volatile-storage", "no-forward", "large-store",
"no-sealing"} <= jr_kinds and jr["storage"] == "volatile", jr)
jr_good = json.loads(text(by_id[2]))
check("journald_audit accepts a persistent sealed journal",
jr_good["findings_count"] == 0 and jr_good["volatile"] is False and
jr_good["sealed"] is True, jr_good)
cd = json.loads(text(by_id[3]))
cd_kinds = {f["id"] for f in cd["findings"]}
check("coredump_audit flags disk storage and no compression",
{"world-writable", "external-storage", "no-compression"} <= cd_kinds and
cd["external"] is True and cd["compressed"] is False, cd)
cd_good = json.loads(text(by_id[4]))
check("coredump_audit accepts Storage=none",
cd_good["findings_count"] == 0 and cd_good["external"] is False,
cd_good)
nft = json.loads(text(by_id[5]))
nft_kinds = {f["id"] for f in nft["findings"]}
check("nftables_audit flags accept policy and an open port",
{"world-writable", "policy-accept", "open-port", "no-conntrack"} <=
nft_kinds and nft["open_ports"] == 1 and
nft["conntrack"] is False, nft)
nft_good = json.loads(text(by_id[6]))
check("nftables_audit accepts a drop policy with conntrack",
nft_good["findings_count"] == 0 and
nft_good["policy_accept"] is False and nft_good["conntrack"] is True,
nft_good)
hsts_weak = json.loads(text(by_id[7]))
weak_ids = {i["id"] for i in hsts_weak["issues"]}
check("hsts_audit flags a short max-age",
{"short-max-age", "no-subdomains"} <= weak_ids and
hsts_weak["max_age"] == 300, hsts_weak)
hsts_strong = json.loads(text(by_id[8]))
check("hsts_audit accepts a long-lived policy",
hsts_strong["issues"] == [] and hsts_strong["max_age"] == 63072000 and
hsts_strong["include_subdomains"] is True and
hsts_strong["preload"] is True, hsts_strong)
hsts_none = json.loads(text(by_id[9]))
check("hsts_audit flags a missing header",
{i["id"] for i in hsts_none["issues"]} == {"missing-hsts"} and
hsts_none["header"] == "", hsts_none)
check("hsts_audit refuses an out-of-scope target", err(by_id[10]),
text(by_id[10]))
check("journald_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("coredump_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
check("nftables_audit reports a missing ruleset", err(by_id[13]),
text(by_id[13]))
hsts_srv.shutdown()
hsts_srv.server_close()
shutil.rmtree(jr_root, ignore_errors=True)
shutil.rmtree(jr_good_root, ignore_errors=True)
shutil.rmtree(cd_root, ignore_errors=True)
shutil.rmtree(cd_good_root, ignore_errors=True)
shutil.rmtree(nft_root, ignore_errors=True)
shutil.rmtree(nft_good_root, ignore_errors=True)
shutil.rmtree(hsts_dir, ignore_errors=True)
shutil.rmtree(cfg17_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"})
esp_m, esp_s = pty.openpty()