apex-twin 1.88.0: freshclam and tripwire audits, CoreDNS probe

Three new tools (385 total):
- freshclam_audit (blue): UpdateChecks no, DatabaseMirror over plain http,
  Checks below 2, world-writable freshclam.conf.
- tripwire_audit (blue): no SITEKEYFILE, site key readable beyond its owner,
  no MAILTO, world-writable twcfg.txt.
- coredns_probe (red): the caddy plugin API /config/ on 2019 without a token;
  a 2xx means the DNS server blocks can be rewritten at runtime, the answer
  goes to evidence.

Proof: make test 1451/1451, test-asan 1451/1451, analyze 0 warnings,
240 fuzz cases, release-check exit 0 in 356 s incl. distcheck, coverage 85.0%.
Red proof: breaking the UpdateChecks match in freshclam_scan_file turned the
new freshclam check red and nothing else.

Not fully covered: the second remote git.hiddenbox.org still answers HTTP 502,
so this commit is pushed to kropa only.
This commit is contained in:
lotherk committed 2026-11-23 14:03:56 +00:00
1 parent 53d5084a77
commit c5ba9d537b
9 files changed
+531 -13

No files matched your search

+15
View File
@@ -1,5 +1,20 @@
# Changelog
## 1.88.0 - 2026-11-24 - this change
- **freshclam** (`freshclam_audit`): `UpdateChecks no` (the signatures never
refresh), a `DatabaseMirror` over plain `http://` (anyone on the path can
swap the signature database), `Checks` of 0 or 1 (the download is not fully
verified), and a world-writable `freshclam.conf`.
- **tripwire** (`tripwire_audit`): a `twcfg.txt` with no `SITEKEYFILE`, a site
key readable beyond its owner (the private half of the policy signature),
no `MAILTO` (a violation lands in a log nobody reads), and a world-writable
config.
- **CoreDNS** (`coredns_probe`): gets `/health`, `/metrics` and the caddy
plugin API `/config/` on 2019 without a token. A 2xx on `/config/` means the
DNS server blocks can be rewritten at runtime; the answer is saved as
evidence.
## 1.87.0 - 2026-11-24 - this change
- **smartd** (`smartd_audit`): a monitored device without a `-m` address (a
+9 -5
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.
**382 tools · 1445 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
**385 tools · 1451 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
{"version":"1.87.0","tools":382,...,"scope":{"loaded":true,...}}
{"version":"1.88.0","tools":385,...,"scope":{"loaded":true,...}}
```
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
@@ -237,6 +237,7 @@ uploads and secret-file reads. It does not execute anything.
| `datasette_probe` | `/-/databases.json` without a token; database list as evidence |
| `vault_probe` | `/v1/sys/mounts` on 8200 without a token; mount list as evidence |
| `nomad_probe` | `/v1/jobs` on 4646 without a token; job inventory as evidence |
| `coredns_probe` | plugin API `/config/` on 2019 without a token; server blocks as evidence |
| `airflow_probe` | `/api/v1/dags` without auth; DAG inventory as evidence |
| `jupyter_probe` | `/api/kernels` on 8888 without a token; sessions as evidence |
| `jira_probe` | `/rest/api/2/project` on 8080 without auth; project list as evidence |
@@ -579,6 +580,8 @@ does.
| `smartd_audit` | smartd.conf: device without `-m`, writable `-M exec` hook, untyped DEVICESCAN |
| `tlog_audit` | tlog: scope without `session`, notice without `wall`, missing log target |
| `abrt_audit` | abrt.conf: autoreporting, public collector URL, no TLS verify |
| `freshclam_audit` | freshclam.conf: UpdateChecks off, http mirror, Checks below 2 |
| `tripwire_audit` | twcfg.txt: no site key, loose site key, no MAILTO |
| `networkd_audit` | systemd-networkd: [Match] without Name/MAC/Type, DHCP DNS without UseDNS=no, public resolver |
| `namespace_audit` | namespace.conf: no /tmp entry, empty/unknown method, `~` user list |
| `ssh_client_audit` | ssh_config: StrictHostKeyChecking no, known_hosts /dev/null, ssh-rsa |
@@ -1064,7 +1067,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
ollama_probe, cadvisor_probe, teamcity_probe,
superset_probe, argocd_probe, kafka_connect_probe,
zabbix_probe, datasette_probe, vault_probe,
nomad_probe
nomad_probe, coredns_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,
@@ -1088,7 +1091,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
php_fpm_audit, uwsgi_audit, lighttpd_audit,
jetty_audit, dhclient_audit,
journal_upload_audit, fwupd_audit,
smartd_audit, tlog_audit, abrt_audit)
smartd_audit, tlog_audit, abrt_audit,
freshclam_audit, tripwire_audit)
src/tools_esp.c esp_info, esp_monitor, esp_read_flash, esp_flash,
esp_partition_table, esp_nvs_parse, firmware_scan,
esp_app_info, esp_image_verify
@@ -1127,7 +1131,7 @@ examples/ scope.json
## Status
1.87.0. Built and run: 382 tools, 1445 checks, 240 fuzz cases and 85.0% line
1.88.0. Built and run: 385 tools, 1451 checks, 240 fuzz cases and 85.0% 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
+1 -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.87.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.88.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.
+3 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.87.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-24" "apex-twin 1.88.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -45,7 +45,7 @@ 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, 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, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nomad_probe,
websocket_origin_check, dns_fcrdns_check, dns_soa_mname_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, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, zabbix_probe, datasette_probe, airflow_probe, gitlab_probe, jupyter_probe, jira_probe, ollama_probe, cadvisor_probe, teamcity_probe, superset_probe, vault_probe, nomad_probe, coredns_probe,
nuclei_scan, nikto_scan, ffuf_scan, gobuster_scan, sqlmap_scan),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
@@ -95,7 +95,7 @@ modules_load_audit, depmod_audit, adduser_conf_audit,
nfs_conf_audit, idmapd_audit, netplan_audit,
apt_auth_audit, aliases_audit, netgroup_audit, jetty_audit,
dhclient_audit, journal_upload_audit, fwupd_audit,
smartd_audit, tlog_audit, abrt_audit,
smartd_audit, tlog_audit, abrt_audit, freshclam_audit, tripwire_audit,
php_fpm_audit, uwsgi_audit, lighttpd_audit)
and ESP32 board tools (esp_info, esp_monitor,
esp_read_flash, esp_flash, esp_partition_table, esp_nvs_parse, firmware_scan,
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.87.0"
#define APEX_VERSION "1.88.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+261
View File
@@ -28762,6 +28762,255 @@ static void t_abrt_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* ----------------------------------------------------------- wireguard_audit */
/* ----------------------------------------------------------- freshclam_audit */
/* freshclam.conf is "Key value" with # comments. Chef: UpdateChecks off means
* the signatures never refresh; a DatabaseMirror over plain http lets anyone
* on the path swap a signature database, and Checks with a value below 2
* skips the verification freshclam would otherwise do. */
struct fclam_state {
int files;
int no_checks;
int plain_http;
int weak_checks;
int world_writable;
};
static void fclam_scan_file(struct fclam_state *st, const char *path,
mcp_buf *findings, int *first, int *count)
{
static char text[65536];
struct stat sb;
const char *p;
if (read_text(path, text, sizeof(text)) <= 0)
return;
st->files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st->world_writable++;
add_finding(findings, first, "world-writable", "high",
"%s is writable by any local user; it decides which "
"signature mirror the scanner trusts", path);
(*count)++;
}
p = text;
while (p != NULL && *p != '\0') {
const char *eol = strchr(p, '\n');
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
char line[1024];
char *key;
char *val;
char *save = NULL;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
p = eol != NULL ? eol + 1 : NULL;
while (len > 0 && (line[len - 1] == ' ' || line[len - 1] == '\t' ||
line[len - 1] == '\r'))
line[--len] = '\0';
key = strtok_r(line, " \t", &save);
if (key == NULL || key[0] == '#')
continue;
val = strtok_r(NULL, " \t", &save);
if (val == NULL)
continue;
if (strcasecmp(key, "UpdateChecks") == 0 &&
strcasecmp(val, "no") == 0) {
st->no_checks++;
add_finding(findings, first, "update-checks-off", "medium",
"%s has UpdateChecks no; freshclam never asks "
"whether the signatures are current", path);
(*count)++;
} else if (strcasecmp(key, "DatabaseMirror") == 0 &&
strncasecmp(val, "http://", 7) == 0) {
st->plain_http++;
add_finding(findings, first, "plain-http-mirror", "high",
"%s fetches signatures from %s over plain http; "
"anyone on the path can hand over a database",
path, val);
(*count)++;
} else if (strcasecmp(key, "Checks") == 0) {
if (strcmp(val, "0") == 0 || strcmp(val, "1") == 0) {
st->weak_checks++;
add_finding(findings, first, "weak-checks", "high",
"%s sets Checks %s; the downloaded database "
"is not fully verified", path, val);
(*count)++;
}
}
}
}
static void t_freshclam_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;
struct fclam_state st;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/clamav/freshclam.conf",
"/etc/freshclam.conf", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
fclam_scan_file(&st, path, &findings, &first, &count);
}
if (st.files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a freshclam configuration");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"freshclam checks for updates, fetches over TLS and "
"verifies the database");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"update_checks_off\":%d,"
"\"plain_http\":%d,\"weak_checks\":%d,"
"\"world_writable\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.no_checks, st.plain_http, st.weak_checks,
st.world_writable, 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);
}
/* ------------------------------------------------------------ tripwire_audit */
/* Tripwire verifies file integrity with a signed policy and a site key. An
* unsigned twcfg.txt can be rewritten to point at a weaker policy, a site key
* readable beyond its owner is the private half of that signature, and an
* empty or missing MAILTO means a violation is written to a log nobody reads. */
struct tw_state {
int files;
int no_keyfile;
int loose_key;
int no_mail;
int world_writable;
};
static void tw_scan_file(struct tw_state *st, const char *path,
mcp_buf *findings, int *first, int *count)
{
static char text[65536];
struct stat sb;
char value[512];
char keypath[1024];
if (read_text(path, text, sizeof(text)) <= 0)
return;
st->files++;
if (stat(path, &sb) == 0 && (sb.st_mode & 0002) != 0) {
st->world_writable++;
add_finding(findings, first, "world-writable", "high",
"%s is writable by any local user; it decides which "
"policy tripwire enforces and where it reports", path);
(*count)++;
}
if (ini_value(text, "", "SITEKEYFILE", value, sizeof(value)) != 1) {
st->no_keyfile++;
add_finding(findings, first, "no-site-key", "high",
"%s names no SITEKEYFILE; the policy signature cannot be "
"verified against a key", path);
(*count)++;
} else if (*value != '\0') {
struct stat kb;
snprintf(keypath, sizeof(keypath), "%s", value);
if (stat(keypath, &kb) == 0 && (kb.st_mode & 0077) != 0) {
st->loose_key++;
add_finding(findings, first, "loose-key-permissions",
"high",
"%s is readable beyond its owner (%03o); the "
"private half of the policy signature is exposed",
keypath, (unsigned)(kb.st_mode & 0777));
(*count)++;
}
}
if (ini_value(text, "", "MAILTO", value, sizeof(value)) != 1 ||
*value == '\0') {
st->no_mail++;
add_finding(findings, first, "no-mail", "medium",
"%s sets no MAILTO; an integrity violation only lands "
"in a log file", path);
(*count)++;
}
}
static void t_tripwire_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;
struct tw_state st;
int first = 1;
int count = 0;
int i;
static const char *files[] = { "/etc/tripwire/twcfg.txt",
"/etc/tripwire/twcfg", NULL };
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
for (i = 0; files[i] != NULL; i++) {
snprintf(path, sizeof(path), "%.400s%s", root, files[i]);
tw_scan_file(&st, path, &findings, &first, &count);
}
if (st.files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a tripwire configuration");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"tripwire names a site key that is private to its owner "
"and reports to a mail address");
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"no_site_key\":%d,"
"\"loose_key_permissions\":%d,\"no_mail\":%d,"
"\"world_writable\":%d,\"findings_count\":%d,\"findings\":[",
st.files, st.no_keyfile, st.loose_key, st.no_mail,
st.world_writable, 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, "
@@ -30365,6 +30614,18 @@ const mcp_tool TOOLS_BLUE[] = {
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default "
"empty\"}}}",
t_abrt_audit },
{ "freshclam_audit",
"Read freshclam.conf (root prefix): UpdateChecks no, a DatabaseMirror "
"over plain http, Checks below 2 and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_freshclam_audit },
{ "tripwire_audit",
"Read twcfg.txt (root prefix): no SITEKEYFILE, a site key readable "
"beyond its owner, no MAILTO and a world-writable config. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_tripwire_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+95
View File
@@ -9212,6 +9212,91 @@ static void t_vault_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ------------------------------------------------------------- coredns_probe */
/* CoreDNS serves its health and metrics on plain HTTP (:8080 health, :9153
* metrics) and its plugin API on :2019 behind caddy. The probe asks all three
* and treats a 2xx on /config/ as exposure: that API rewrites the server
* blocks at runtime, so an open one is remote DNS control. */
static void t_coredns_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/health", "/metrics", "/config/", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 2019);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port));
mcp_buf b;
int first = 1;
int tested = 0;
int open_count = 0;
int config_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, "coredns_probe", target, port))
return;
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 is_config = strstr(paths[i], "/config") != NULL;
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 && is_config) {
config_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("coredns-config", resp, len);
}
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,"
"\"config_open\":%s,\"evidence\":",
tested, open_count, config_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("coredns_probe", target, port, !config_open,
config_open
? "the CoreDNS plugin API answers without a token"
: "the CoreDNS plugin API requires a token", "list");
mcp_reply_json(c, b.p);
free(evidence);
mcp_buf_free(&b);
}
/* -------------------------------------------------------------- rundeck_probe */
/* Rundeck on 4440. /api/1/system/info answers on many installs and is not
@@ -10671,6 +10756,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_vault_probe },
{ "coredns_probe",
"Get /health, /metrics and the caddy plugin API /config/ on 2019 "
"without a token. A 2xx on /config/ means the DNS server blocks can be "
"rewritten at runtime; the answer is saved as evidence.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 2019\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_coredns_probe },
{ "nomad_probe",
"Get /v1/agent/self, /v1/jobs and /v1/nodes without a token on 4646. "
"A 2xx on the job list means the whole Nomad job inventory is public "
+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 = 382
EXPECTED_TOOLS = 385
GATE = ("gated(", "gated_cmd(", "gated_run(", "apex_scope_check(")
# Handlers may hand argv to a shared runner instead of calling the gate
# themselves. That runner has to call the gate; both halves are checked
+145 -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("382 tools registered", len(tools) == 382, len(tools))
check("385 tools registered", len(tools) == 385, 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"]) == 382)
check("http tools/list", len(listing["result"]["tools"]) == 385)
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
@@ -17198,7 +17198,150 @@ for d in (sm_root, sm_good_root, tl_root, tl_good_root, ab_root,
ab_good_root, cfg58_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.88.0: freshclam and tripwire audits plus the CoreDNS probe ---
print("\n== freshclam, tripwire and CoreDNS ==")
fc_root = tempfile.mkdtemp(prefix="apex-fc-")
os.makedirs(os.path.join(fc_root, "etc", "clamav"))
fc_bad = os.path.join(fc_root, "etc", "clamav", "freshclam.conf")
with open(fc_bad, "w") as f:
f.write("DatabaseOwner clamav\n")
f.write("UpdateChecks no\n")
f.write("DatabaseMirror http://mirror.example.test/clamav\n")
f.write("Checks 1\n")
os.chmod(fc_bad, 0o666)
fc_good_root = tempfile.mkdtemp(prefix="apex-fcg-")
os.makedirs(os.path.join(fc_good_root, "etc", "clamav"))
fc_good = os.path.join(fc_good_root, "etc", "clamav", "freshclam.conf")
with open(fc_good, "w") as f:
f.write("DatabaseOwner clamav\n")
f.write("UpdateChecks yes\n")
f.write("DatabaseMirror https://database.clamav.net\n")
f.write("Checks 4\n")
os.chmod(fc_good, 0o644)
tw_root = tempfile.mkdtemp(prefix="apex-tw-")
os.makedirs(os.path.join(tw_root, "etc", "tripwire"))
tw_cfg = os.path.join(tw_root, "etc", "tripwire", "twcfg.txt")
tw_key = os.path.join(tw_root, "etc", "tripwire", "site.key")
with open(tw_cfg, "w") as f:
f.write("POLFILE = /etc/tripwire/tw.pol\n")
f.write("SITEKEYFILE = %s\n" % tw_key)
os.chmod(tw_cfg, 0o666)
with open(tw_key, "w") as f:
f.write("dummy-site-key\n")
os.chmod(tw_key, 0o644)
tw_good_root = tempfile.mkdtemp(prefix="apex-twg-")
os.makedirs(os.path.join(tw_good_root, "etc", "tripwire"))
tw_good_cfg = os.path.join(tw_good_root, "etc", "tripwire", "twcfg.txt")
tw_good_key = os.path.join(tw_good_root, "etc", "tripwire", "site.key")
with open(tw_good_cfg, "w") as f:
f.write("POLFILE = /etc/tripwire/tw.pol\n")
f.write("SITEKEYFILE = %s\n" % tw_good_key)
f.write("MAILTO = root@example.test\n")
os.chmod(tw_good_cfg, 0o600)
with open(tw_good_key, "w") as f:
f.write("dummy-site-key\n")
os.chmod(tw_good_key, 0o600)
class _CoreDNSHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/health":
body = b'{"healthy":true}'
self.send_response(200)
elif path == "/metrics":
body = b"# HELP coredns_dns_requests_total counter\n"
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 _CoreDNSOpenHandler(_CoreDNSHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/config/":
body = b'{"apps":{"dns":{"servers":{}}}}'
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
return
_CoreDNSHandler.do_GET(self)
cd_srv = http.server.HTTPServer(("127.0.0.1", 0), _CoreDNSHandler)
cd_port = cd_srv.server_address[1]
cd_open_srv = http.server.HTTPServer(("127.0.0.1", 0), _CoreDNSOpenHandler)
cd_open_port = cd_open_srv.server_address[1]
for _s in (cd_srv, cd_open_srv):
threading.Thread(target=_s.serve_forever, daemon=True).start()
cfg59_home = tempfile.mkdtemp(prefix="apex-cfg59-home-")
write_scope(cfg59_home,
{"label": "cfg59", "expires": "2099-01-01T00:00:00Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": ["1-65535"]})
res, _ = run([
call(1, "freshclam_audit", root=fc_root),
call(2, "freshclam_audit", root=fc_good_root),
call(3, "tripwire_audit", root=tw_root),
call(4, "tripwire_audit", root=tw_good_root),
call(5, "coredns_probe", target="127.0.0.1", port=cd_port, tls=False),
call(6, "coredns_probe", target="127.0.0.1", port=cd_open_port, tls=False),
], home=cfg59_home)
by_id = {r["id"]: r for r in res if "id" in r}
fca = json.loads(text(by_id[1]))
fca_kinds = {f["id"] for f in fca["findings"]}
check("freshclam_audit flags UpdateChecks off, a plain http mirror, weak "
"checks and a writable file",
{"update-checks-off", "plain-http-mirror", "weak-checks",
"world-writable"} <= fca_kinds and fca["update_checks_off"] == 1 and
fca["plain_http"] == 1 and fca["weak_checks"] == 1, fca)
fca_good = json.loads(text(by_id[2]))
check("freshclam_audit accepts TLS, update checks and full verification",
fca_good["findings_count"] == 0 and
fca_good["findings"][0]["id"] == "no-findings" and
fca_good["plain_http"] == 0 and fca_good["weak_checks"] == 0, fca_good)
twa = json.loads(text(by_id[3]))
twa_kinds = {f["id"] for f in twa["findings"]}
check("tripwire_audit flags a loose site key, no mail and a writable config",
{"loose-key-permissions", "no-mail", "world-writable"} <= twa_kinds and
twa["loose_key_permissions"] == 1 and twa["no_mail"] == 1, twa)
twa_good = json.loads(text(by_id[4]))
check("tripwire_audit accepts a private site key with mail and no key gap",
twa_good["findings_count"] == 0 and
twa_good["findings"][0]["id"] == "no-findings" and
twa_good["loose_key_permissions"] == 0 and twa_good["no_mail"] == 0,
twa_good)
cd = json.loads(text(by_id[5]))
check("coredns_probe reports a closed plugin API as not open",
cd["config_open"] is False and cd["evidence"] is None and
cd["open_count"] == 2, cd)
cd_open = json.loads(text(by_id[6]))
check("coredns_probe finds the open plugin API and saves evidence",
cd_open["config_open"] is True and cd_open["open_count"] == 3 and
os.path.isfile(cd_open["evidence"]) and
"servers" in open(cd_open["evidence"]).read(), cd_open)
cd_srv.shutdown()
cd_open_srv.shutdown()
for d in (fc_root, fc_good_root, tw_root, tw_good_root, cfg59_home):
shutil.rmtree(d, ignore_errors=True)
# --- 1.84.0: gated wrappers for external scanners (mock binaries) ---
print("\n== external scanner wrappers ==\n")