apex-twin 1.63.0: OpenSSL, curl and wget config audits, TLS chain probe

Blue:
- openssl_cnf_audit: openssl.cnf: MinProtocol TLSv1/TLSv1.1, a CipherString
  with SECLEVEL=0/1, a missing system_default_sect and a world-writable file.
- curlrc_audit: /etc/curlrc: insecure, a plain-HTTP proxy, world-writable.
- wgetrc_audit: /etc/wgetrc: check_certificate=off, a plain-HTTP proxy,
  world-writable.

Red:
- tls_chain_probe: one -showcerts handshake; a one-certificate chain whose
  subject differs from its issuer means a missing intermediate. Self-signed
  certificates are accepted.

Tests with OpenSSL/curlrc/wgetrc trees and three TLS servers (leaf only,
leaf+CA, self-signed). 1218 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.63.0.
This commit is contained in:
lotherk committed 2026-11-22 16:23:43 +00:00
1 parent 7a3fc47b8f
commit ea281386ba
9 files changed
+645 -15

No files matched your search

+16 -1
View File
@@ -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.62.0 — 2026-11-23 — this change
## 1.63.0 — 2026-11-23 — this change
- **OpenSSL config** (`openssl_cnf_audit`): `openssl.cnf`: `MinProtocol`
TLSv1/TLSv1.1, a `CipherString` with `SECLEVEL=0/1`, a missing
`system_default_sect` and a world-writable file.
- **curlrc** (`curlrc_audit`): `/etc/curlrc`: `insecure`, a plain-HTTP proxy
and a world-writable file.
- **wgetrc** (`wgetrc_audit`): `/etc/wgetrc`: `check_certificate=off`, a
plain-HTTP proxy and a world-writable file.
- **TLS chain** (`tls_chain_probe`): one `-showcerts` handshake; a
one-certificate chain whose subject differs from its issuer means a missing
intermediate. Self-signed certificates are accepted.
- Tests with OpenSSL/curlrc/wgetrc trees and three TLS servers (leaf only,
leaf+CA, self-signed). 1218 checks. Coverage 84.2%.
## 1.62.0 — 2026-11-23 — 7a3fc47
- **Compose** (`compose_audit`): a compose file: `privileged`, host
network/PID, a mounted Docker socket, plaintext passwords/tokens and a
+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.
**286 tools · 1205 end-to-end checks · 340 fuzz cases · 84.2% line coverage · ~983 KiB**
**290 tools · 1218 end-to-end checks · 340 fuzz cases · 84.2% line coverage · ~996 KiB**
```
$ ./apex-twin --check
{"version":"1.62.0","tools":286,...,"scope":{"loaded":true,...}}
{"version":"1.63.0","tools":290,...,"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 (286)
## Tools (290)
### Scope and bookkeeping
@@ -221,6 +221,7 @@ uploads and secret-file reads. It does not execute anything.
| `kibana_api_probe` | `/api/saved_objects/_find` without auth; answer as evidence |
| `logstash_api_probe` | `/_node/info` and `/_node/stats` without auth; stats as evidence |
| `amqp_probe` | AMQP 0-9-1 Connection.Start: product, version, mechanisms, no login |
| `tls_chain_probe` | Counts presented certs; a lone non-self-signed leaf means a missing intermediate |
| `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 |
@@ -483,6 +484,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `compose_audit` | compose: privileged, host namespaces, docker socket, secrets |
| `k8s_manifest_audit` | manifest: privileged, host namespaces, root, hostPath / |
| `dockerfile_audit` | Dockerfile: root USER, :latest base, remote ADD, curl pipe |
| `openssl_cnf_audit` | openssl.cnf: MinProtocol TLSv1, SECLEVEL 0/1 |
| `curlrc_audit` | /etc/curlrc: `insecure`, plain-HTTP proxy |
| `wgetrc_audit` | /etc/wgetrc: `check_certificate=off`, plain proxy |
### ESP32
@@ -795,6 +799,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| Logstash API | two unauthenticated GETs, stats as evidence |
| compose/k8s/dockerfile | one local file each; no execution |
| AMQP | protocol header + Connection.Start, no login |
| openssl/curl/wget cnf | config reads only; optional root prefix |
| TLS chain | one handshake, no data |
| USB audit | 200 devices, sysfs reads only |
---
@@ -806,7 +812,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1205 end-to-end checks
make test # version check + gate audit + 1218 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
@@ -936,7 +942,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
rabbitmq_management_probe, grafana_api_probe,
minio_admin_probe, nats_monitoring_probe,
influxdb_probe, clickhouse_probe, kibana_api_probe,
logstash_api_probe, amqp_probe
logstash_api_probe, amqp_probe, tls_chain_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,
@@ -979,7 +985,7 @@ examples/ scope.json
## Status
1.62.0. Built and run: 286 tools, 1205 checks, 340 fuzz cases and 84.2% line
1.63.0. Built and run: 290 tools, 1218 checks, 340 fuzz cases and 84.2% 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.62.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.63.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.
- **OpenSSL/curl/wget configuration audits read local files.** The TLS
chain probe performs one handshake and reads the presented certificates.
- **Compose, manifest and Dockerfile audits read one local file each.** The
AMQP probe reads Connection.Start and never sends credentials.
- **atd, securetty and tmpfiles audits read local files.** The Logstash node
+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.62.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.63.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -46,7 +46,7 @@ sip_probe, telnet_probe, http_methods, websocket_probe, ike_probe, snmp_walk,
ldap_search, openapi_discovery, csrf_audit, rpc_probe, ntp_probe, dnssec_check, smtp_starttls_probe, tls_ocsp_probe, alpn_probe, webdav_probe, dns_wildcard_check, dns_caa_check, sni_vhost_check, tls_client_auth_probe, kubernetes_api_probe,
dns_ns_consistency, dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_check, http_redirect_audit,
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe),
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe, zookeeper_4lw_probe, etcd_api_probe, docker_registry_probe, consul_api_probe, couchdb_probe, prometheus_api_probe, rabbitmq_management_probe, grafana_api_probe, minio_admin_probe, nats_monitoring_probe, influxdb_probe, clickhouse_probe, kibana_api_probe, logstash_api_probe, amqp_probe, tls_chain_probe),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -77,7 +77,8 @@ keepalived_audit, webmin_audit, cockpit_audit, phpmyadmin_audit, kibana_audit,
nagios_audit, synapse_audit, logstash_audit, filebeat_audit,
fluentd_audit, telegraf_audit, graylog_audit, netdata_audit, sshd_config_audit,
hosts_access_audit, profile_audit, atd_audit, securetty_audit,
tmpfiles_audit, compose_audit, k8s_manifest_audit, dockerfile_audit)
tmpfiles_audit, compose_audit, k8s_manifest_audit, dockerfile_audit,
openssl_cnf_audit, curlrc_audit, wgetrc_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.62.0"
#define APEX_VERSION "1.63.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+265
View File
@@ -18940,6 +18940,252 @@ static void t_dockerfile_audit(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&findings);
}
/* ---------------------------------------------------------- openssl_cnf_audit */
static void t_openssl_cnf_audit(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *files[] = { "/etc/ssl/openssl.cnf",
"/usr/lib/ssl/openssl.cnf", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
char value[256];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int weak_min = 0;
int weak_seclevel = 0;
int no_system_defaults = 0;
int i;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
if (read_text(path, text, sizeof(text)) <= 0)
continue;
files_read++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"%s is writable by anyone", path);
count++;
}
if (ini_value(text, "system_default_sect", "MinProtocol", value,
sizeof(value)) &&
(strcasecmp(value, "TLSv1") == 0 ||
strcasecmp(value, "TLSv1.1") == 0 ||
strcasecmp(value, "SSLv3") == 0))
weak_min = 1;
if (ini_value(text, "system_default_sect", "CipherString", value,
sizeof(value)) &&
(strstr(value, "SECLEVEL=0") != NULL ||
strstr(value, "SECLEVEL=1") != NULL))
weak_seclevel = 1;
if (strstr(text, "[system_default_sect]") == NULL)
no_system_defaults = 1;
break;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read an OpenSSL configuration");
return;
}
if (weak_min) {
add_finding(&findings, &first, "weak-min-protocol", "high",
"MinProtocol still allows TLS 1.0 or 1.1");
count++;
}
if (weak_seclevel) {
add_finding(&findings, &first, "weak-security-level", "high",
"CipherString lowers the OpenSSL security level");
count++;
}
if (no_system_defaults) {
add_finding(&findings, &first, "no-system-defaults", "low",
"no system_default_sect is configured");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"weak_min_protocol\":%s,"
"\"weak_security_level\":%s,\"system_defaults\":%s,"
"\"findings_count\":%d,\"findings\":[",
files_read, weak_min ? "true" : "false",
weak_seclevel ? "true" : "false",
no_system_defaults ? "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);
}
/* --------------------------------------------------------------- curlrc_audit */
static void t_curlrc_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 proxy[512];
struct stat st;
char *copy;
char *save = NULL;
char *line;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int insecure = 0;
int plain_proxy = 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/curlrc", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read /etc/curlrc");
return;
}
proxy[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"/etc/curlrc is writable by anyone");
count++;
}
copy = strdup(text);
if (copy == NULL) {
mcp_buf_free(&findings);
mcp_reply_error(c, "out of memory");
return;
}
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s != '#' && *s != '\0') {
if (strcmp(s, "insecure") == 0 ||
strcmp(s, "--insecure") == 0 ||
strcmp(s, "insecure = true") == 0)
insecure = 1;
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
conf_value(text, "proxy", proxy, sizeof(proxy));
if (strncmp(proxy, "http://", 7) == 0)
plain_proxy = 1;
if (insecure) {
add_finding(&findings, &first, "insecure", "high",
"curl disables certificate verification by default");
count++;
}
if (plain_proxy) {
add_finding(&findings, &first, "plain-proxy", "medium",
"curl uses a plain-HTTP proxy");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"proxy\":");
apex_json_str(&b, proxy);
mcp_buf_printf(&b, ",\"insecure\":%s,\"plain_proxy\":%s,"
"\"findings_count\":%d,\"findings\":[",
insecure ? "true" : "false",
plain_proxy ? "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);
}
/* --------------------------------------------------------------- wgetrc_audit */
static void t_wgetrc_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[65536];
char value[512];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int no_cert = 0;
int plain_proxy = 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/wgetrc", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read /etc/wgetrc");
return;
}
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"/etc/wgetrc is writable by anyone");
count++;
}
if (conf_value(text, "check_certificate", value, sizeof(value)) &&
strcasecmp(value, "off") == 0)
no_cert = 1;
if (conf_value(text, "http_proxy", value, sizeof(value)) &&
strncmp(value, "http://", 7) == 0)
plain_proxy = 1;
if (no_cert) {
add_finding(&findings, &first, "no-cert-check", "high",
"wget skips certificate verification");
count++;
}
if (plain_proxy) {
add_finding(&findings, &first, "plain-proxy", "medium",
"wget uses a plain-HTTP proxy");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"check_certificate\":%s,\"plain_proxy\":%s,"
"\"findings_count\":%d,\"findings\":[",
no_cert ? "false" : "true",
plain_proxy ? "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, "
@@ -20017,6 +20263,25 @@ const mcp_tool TOOLS_BLUE[] = {
"\"path\":{\"type\":\"string\"}},"
"\"required\":[\"path\"]}",
t_dockerfile_audit },
{ "openssl_cnf_audit",
"Parse openssl.cnf (root prefix, two usual paths): MinProtocol TLSv1 "
"or TLSv1.1, a lowered CipherString security level, a missing "
"system_default_sect and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_openssl_cnf_audit },
{ "curlrc_audit",
"Parse /etc/curlrc (root prefix): insecure by default, a plain-HTTP "
"proxy and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_curlrc_audit },
{ "wgetrc_audit",
"Parse /etc/wgetrc (root prefix): check_certificate=off, a plain-HTTP "
"proxy and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_wgetrc_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+180
View File
@@ -6110,6 +6110,175 @@ static void t_zookeeper_4lw_probe(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* ------------------------------------------------------------ tls_chain_probe */
static int extract_last_pem(const char *out, mcp_buf *pem)
{
const char *begin = NULL;
const char *p = out;
const char *end;
while ((p = strstr(p, "-----BEGIN CERTIFICATE-----")) != NULL) {
begin = p;
p += strlen("-----BEGIN CERTIFICATE-----");
}
if (begin == NULL)
return -1;
end = strstr(begin, "-----END CERTIFICATE-----");
if (end == NULL)
return -1;
end += strlen("-----END CERTIFICATE-----");
mcp_buf_add(pem, begin, (size_t)(end - begin));
mcp_buf_puts(pem, "\n");
return 0;
}
static void t_tls_chain_probe(mcp_conn *c, const mcp_json *args, void *user)
{
const char *target = mcp_arg_string(args, "target");
const char *name = mcp_arg_string(args, "name");
int port = mcp_arg_int(args, "port", 443);
char conn[320];
char reason[512];
char subject[512];
char issuer[512];
unsigned char raw[16];
int is_ip;
int chain_length = 0;
int incomplete = 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 (name != NULL && *name != '\0' &&
!apex_scope_check(name, port, reason, sizeof(reason))) {
mcp_buf_init(&b);
mcp_buf_printf(&b, "name %s is outside the scope: %s", name,
reason);
mcp_reply_error(c, b.p);
mcp_buf_free(&b);
return;
}
if (!gated(c, "tls_chain_probe", target, port))
return;
tls_conn_string(target, port, conn, sizeof(conn));
is_ip = inet_pton(AF_INET, target, raw) == 1 ||
inet_pton(AF_INET6, target, raw) == 1;
subject[0] = issuer[0] = '\0';
{
char *argv[14];
int k = 0;
apex_proc p;
argv[k++] = "openssl";
argv[k++] = "s_client";
argv[k++] = "-connect";
argv[k++] = conn;
if (!is_ip && name != NULL && *name != '\0') {
argv[k++] = "-servername";
argv[k++] = (char *)name;
} else if (!is_ip) {
argv[k++] = "-servername";
argv[k++] = (char *)target;
}
argv[k++] = "-showcerts";
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) {
const char *scan = p.out;
while ((scan = strstr(scan,
"-----BEGIN CERTIFICATE-----")) != NULL) {
chain_length++;
scan += strlen("-----BEGIN CERTIFICATE-----");
}
if (chain_length > 0) {
mcp_buf pem;
char pem_path[APEX_PATH_FULL];
mcp_buf_init(&pem);
if (extract_last_pem(p.out, &pem) == 0) {
snprintf(pem_path, sizeof(pem_path),
"%s/chain-%ld.pem",
g_cfg.evidence_dir,
(long)getpid());
if (apex_write_file(pem_path, pem.p,
pem.len, 0600) == 0) {
char *xargv[10];
int x = 0;
apex_proc xp;
xargv[x++] = "openssl";
xargv[x++] = "x509";
xargv[x++] = "-in";
xargv[x++] = pem_path;
xargv[x++] = "-noout";
xargv[x++] = "-subject";
xargv[x++] = "-issuer";
xargv[x] = NULL;
if (apex_run(xargv, 10000, 65536,
&xp) == 0) {
if (xp.out != NULL) {
header_value(xp.out,
"subject=",
subject,
sizeof(subject));
header_value(xp.out,
"issuer=",
issuer,
sizeof(issuer));
}
apex_proc_free(&xp);
}
unlink(pem_path);
}
}
mcp_buf_free(&pem);
}
}
apex_proc_free(&p);
}
if (chain_length == 0) {
mcp_reply_error(c, "no certificate presented");
return;
}
if (chain_length == 1 && subject[0] != '\0' && issuer[0] != '\0' &&
strcmp(subject, issuer) != 0)
incomplete = 1;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"chain_length\":%d,"
"\"incomplete_chain\":%s,\"last_subject\":",
port, chain_length, incomplete ? "true" : "false");
apex_json_str(&b, subject);
mcp_buf_puts(&b, ",\"last_issuer\":");
apex_json_str(&b, issuer);
mcp_buf_puts(&b, "}");
apex_audit("tls_chain_probe", target, port, !incomplete,
incomplete
? "the server sends one non-self-signed certificate; an "
"intermediate is missing"
: "the chain is complete or self-signed", name != NULL
? name : target);
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 "
@@ -6496,6 +6665,17 @@ const mcp_tool TOOLS_PROTO[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"}},"
"\"required\":[\"target\"]}",
t_tls_hostname_check },
{ "tls_chain_probe",
"Open one TLS connection with -showcerts, count the certificates and "
"compare the last subject and issuer. A one-certificate chain from a "
"non-self-signed leaf means a missing intermediate. Gate: the target "
"(and name).",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"name\":{\"type\":\"string\",\"description\":\"SNI name, optional\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"}},"
"\"required\":[\"target\"]}",
t_tls_chain_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 = 286
EXPECTED_TOOLS = 290
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.
+163 -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("286 tools registered", len(tools) == 286, len(tools))
check("290 tools registered", len(tools) == 290, 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"]) == 286)
check("http tools/list", len(listing["result"]["tools"]) == 290)
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
@@ -13060,6 +13060,166 @@ shutil.rmtree(k8_dir, ignore_errors=True)
shutil.rmtree(df_dir, ignore_errors=True)
shutil.rmtree(cfg34_home, ignore_errors=True)
print("\n== OpenSSL cnf, curlrc, wgetrc and TLS chains ==\n")
os_root = tempfile.mkdtemp(prefix="apex-os-")
os.makedirs(os.path.join(os_root, "etc", "ssl"))
os_bad = os.path.join(os_root, "etc", "ssl", "openssl.cnf")
with open(os_bad, "w") as f:
f.write("[system_default_sect]\n")
f.write("MinProtocol = TLSv1\n")
f.write("CipherString = DEFAULT@SECLEVEL=0\n")
os.chmod(os_bad, 0o666)
os_good_root = tempfile.mkdtemp(prefix="apex-osg-")
os.makedirs(os.path.join(os_good_root, "etc", "ssl"))
with open(os.path.join(os_good_root, "etc", "ssl", "openssl.cnf"),
"w") as f:
f.write("[system_default_sect]\n")
f.write("MinProtocol = TLSv1.2\n")
f.write("CipherString = DEFAULT@SECLEVEL=2\n")
cr_root = tempfile.mkdtemp(prefix="apex-cr-")
os.makedirs(os.path.join(cr_root, "etc"))
cr_bad = os.path.join(cr_root, "etc", "curlrc")
with open(cr_bad, "w") as f:
f.write("insecure\n")
f.write("proxy = http://proxy.example.test:3128\n")
os.chmod(cr_bad, 0o666)
cr_good_root = tempfile.mkdtemp(prefix="apex-crg-")
os.makedirs(os.path.join(cr_good_root, "etc"))
with open(os.path.join(cr_good_root, "etc", "curlrc"), "w") as f:
f.write("proxy = https://proxy.example.test:3128\n")
wr_root = tempfile.mkdtemp(prefix="apex-wr-")
os.makedirs(os.path.join(wr_root, "etc"))
wr_bad = os.path.join(wr_root, "etc", "wgetrc")
with open(wr_bad, "w") as f:
f.write("check_certificate = off\n")
f.write("use_proxy = on\n")
f.write("http_proxy = http://proxy.example.test:3128\n")
os.chmod(wr_bad, 0o666)
wr_good_root = tempfile.mkdtemp(prefix="apex-wrg-")
os.makedirs(os.path.join(wr_good_root, "etc"))
with open(os.path.join(wr_good_root, "etc", "wgetrc"), "w") as f:
f.write("check_certificate = on\n")
f.write("https_proxy = https://proxy.example.test:3128\n")
chain_dir = tempfile.mkdtemp(prefix="apex-chain-")
ca_key = os.path.join(chain_dir, "ca.key")
ca_pem = os.path.join(chain_dir, "ca.pem")
leaf_key = os.path.join(chain_dir, "leaf.key")
leaf_csr = os.path.join(chain_dir, "leaf.csr")
leaf_pem = os.path.join(chain_dir, "leaf.pem")
full_pem = os.path.join(chain_dir, "full.pem")
self_key = os.path.join(chain_dir, "self.key")
self_pem = os.path.join(chain_dir, "self.pem")
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
"-keyout", ca_key, "-out", ca_pem, "-days", "2",
"-subj", "/CN=Test CA"], check=True, capture_output=True)
subprocess.run(["openssl", "req", "-new", "-newkey", "rsa:2048", "-nodes",
"-keyout", leaf_key, "-out", leaf_csr,
"-subj", "/CN=localhost"], check=True,
capture_output=True)
subprocess.run(["openssl", "x509", "-req", "-in", leaf_csr, "-CA", ca_pem,
"-CAkey", ca_key, "-CAcreateserial", "-days", "2",
"-out", leaf_pem], check=True, capture_output=True)
with open(full_pem, "wb") as out:
for part in (leaf_pem, ca_pem):
with open(part, "rb") as f:
out.write(f.read())
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
"-keyout", self_key, "-out", self_pem, "-days", "2",
"-subj", "/CN=self.test"], check=True, capture_output=True)
leaf_srv, leaf_port = tls_server(leaf_pem, leaf_key)
full_srv, full_port = tls_server(full_pem, leaf_key)
self_srv, self_port = tls_server(self_pem, self_key)
cfg35_home = tempfile.mkdtemp(prefix="apex-cfg35-home-")
write_scope(cfg35_home, {"label": "cfg35", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(leaf_port), str(full_port),
str(self_port)]})
res, _ = run([
call(1, "openssl_cnf_audit", root=os_root),
call(2, "openssl_cnf_audit", root=os_good_root),
call(3, "curlrc_audit", root=cr_root),
call(4, "curlrc_audit", root=cr_good_root),
call(5, "wgetrc_audit", root=wr_root),
call(6, "wgetrc_audit", root=wr_good_root),
call(7, "tls_chain_probe", target="127.0.0.1", port=leaf_port),
call(8, "tls_chain_probe", target="127.0.0.1", port=full_port),
call(9, "tls_chain_probe", target="127.0.0.1", port=self_port),
call(10, "tls_chain_probe", target="198.51.100.9", port=443),
call(11, "openssl_cnf_audit", root="/nonexistent-os"),
call(12, "curlrc_audit", root="/nonexistent-cr"),
call(13, "wgetrc_audit", root="/nonexistent-wr"),
], home=cfg35_home)
by_id = {r.get("id"): r for r in res}
os_cnf = json.loads(text(by_id[1]))
os_kinds = {f["id"] for f in os_cnf["findings"]}
check("openssl_cnf_audit flags TLS 1.0 and SECLEVEL 0",
{"world-writable", "weak-min-protocol", "weak-security-level"} <=
os_kinds and os_cnf["weak_min_protocol"] is True and
os_cnf["weak_security_level"] is True, os_cnf)
os_good = json.loads(text(by_id[2]))
check("openssl_cnf_audit accepts TLS 1.2 and SECLEVEL 2",
os_good["findings_count"] == 0 and
os_good["weak_min_protocol"] is False and
os_good["weak_security_level"] is False, os_good)
cr = json.loads(text(by_id[3]))
cr_kinds = {f["id"] for f in cr["findings"]}
check("curlrc_audit flags insecure and a plain proxy",
{"world-writable", "insecure", "plain-proxy"} <= cr_kinds and
cr["insecure"] is True and cr["plain_proxy"] is True, cr)
cr_good = json.loads(text(by_id[4]))
check("curlrc_audit accepts an HTTPS proxy",
cr_good["findings_count"] == 0 and cr_good["insecure"] is False and
cr_good["plain_proxy"] is False, cr_good)
wr = json.loads(text(by_id[5]))
wr_kinds = {f["id"] for f in wr["findings"]}
check("wgetrc_audit flags no certificate check and a plain proxy",
{"world-writable", "no-cert-check", "plain-proxy"} <= wr_kinds and
wr["check_certificate"] is False and wr["plain_proxy"] is True, wr)
wr_good = json.loads(text(by_id[6]))
check("wgetrc_audit accepts certificate checks",
wr_good["findings_count"] == 0 and
wr_good["check_certificate"] is True and
wr_good["plain_proxy"] is False, wr_good)
chain_leaf = json.loads(text(by_id[7]))
check("tls_chain_probe flags a missing intermediate",
chain_leaf["chain_length"] == 1 and
chain_leaf["incomplete_chain"] is True and
chain_leaf["last_subject"] == "CN=localhost" and
chain_leaf["last_issuer"] == "CN=Test CA", chain_leaf)
chain_full = json.loads(text(by_id[8]))
check("tls_chain_probe accepts a full chain",
chain_full["chain_length"] == 2 and
chain_full["incomplete_chain"] is False, chain_full)
chain_self = json.loads(text(by_id[9]))
check("tls_chain_probe accepts a self-signed certificate",
chain_self["chain_length"] == 1 and
chain_self["incomplete_chain"] is False, chain_self)
check("tls_chain_probe refuses an out-of-scope target", err(by_id[10]),
text(by_id[10]))
check("openssl_cnf_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("curlrc_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
check("wgetrc_audit reports a missing config", err(by_id[13]),
text(by_id[13]))
leaf_srv.close()
full_srv.close()
self_srv.close()
shutil.rmtree(os_root, ignore_errors=True)
shutil.rmtree(os_good_root, ignore_errors=True)
shutil.rmtree(cr_root, ignore_errors=True)
shutil.rmtree(cr_good_root, ignore_errors=True)
shutil.rmtree(wr_root, ignore_errors=True)
shutil.rmtree(wr_good_root, ignore_errors=True)
shutil.rmtree(chain_dir, ignore_errors=True)
shutil.rmtree(cfg35_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -13082,6 +13242,7 @@ print("\n== esp32 tools ==")
esp_home = tempfile.mkdtemp(prefix="apex-esp-")