apex-twin 1.59.0: Telegraf, Graylog and Netdata audits, ClickHouse probe

Blue:
- telegraf_audit: telegraf.conf: an HTTP output URL, insecure_skip_verify,
  credentials in the file and a world-writable file.
- graylog_audit: server.conf: the REST API on 0.0.0.0, plain HTTP, a
  password_secret shorter than 64, an empty root_password_sha2 and a
  world-writable file.
- netdata_audit: netdata.conf: bind to IP 0.0.0.0, an allow list of *, a
  missing allow list and a world-writable file.

Red:
- clickhouse_probe: /ping and /?query=SELECT version() without credentials; a
  2xx with a version is an open HTTP API and is saved as evidence.

Tests with Telegraf/Graylog/Netdata trees and two ClickHouse fixtures (open
and 403 with a public ping). 1168 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.59.0.
This commit is contained in:
lotherk committed 2026-11-22 14:46:55 +00:00
1 parent 827ff97441
commit f1fbf9d8fe
9 files changed
+593 -15

No files matched your search

+17 -1
View File
@@ -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.58.0 — 2026-11-23 — this change
## 1.59.0 — 2026-11-23 — this change
- **Telegraf** (`telegraf_audit`): `telegraf.conf`: an HTTP output URL,
`insecure_skip_verify = true`, credentials in the file and a
world-writable file.
- **Graylog** (`graylog_audit`): `server.conf`: the REST API on `0.0.0.0`,
plain HTTP, a `password_secret` shorter than 64 characters, an empty
`root_password_sha2` and a world-writable file.
- **Netdata** (`netdata_audit`): `netdata.conf`: `bind to IP = 0.0.0.0`, an
allow list of `*`, a missing allow list and a world-writable file.
- **ClickHouse** (`clickhouse_probe`): `/ping` and
`/?query=SELECT version()` without credentials; a 2xx with a version is an
open HTTP API, saved as evidence.
- Tests with Telegraf/Graylog/Netdata trees and two ClickHouse fixtures (open
and 403 with a public ping). 1168 checks. Coverage 84.1%.
## 1.58.0 — 2026-11-23 — 827ff97
- **Logstash** (`logstash_audit`): `logstash.yml`: `api.http.host: 0.0.0.0`,
monitoring disabled, a missing `path.data` and a world-writable file.
+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.
**270 tools · 1156 end-to-end checks · 340 fuzz cases · 84.0% line coverage · ~946 KiB**
**274 tools · 1168 end-to-end checks · 340 fuzz cases · 84.1% line coverage · ~954 KiB**
```
$ ./apex-twin --check
{"version":"1.58.0","tools":270,...,"scope":{"loaded":true,...}}
{"version":"1.59.0","tools":274,...,"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 (270)
## Tools (274)
### Scope and bookkeeping
@@ -217,6 +217,7 @@ uploads and secret-file reads. It does not execute anything.
| `minio_admin_probe` | `/minio/admin/v3/info` without a signature; admin answer as evidence |
| `nats_monitoring_probe` | `/varz` and `/connz` without auth; varz answer as evidence |
| `influxdb_probe` | `/ping` and `/query?q=SHOW DATABASES` without auth; answer as evidence |
| `clickhouse_probe` | `/ping` and `SELECT version()` without auth; version 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 |
@@ -467,6 +468,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `logstash_audit` | logstash.yml: API on 0.0.0.0, monitoring off, no path.data |
| `filebeat_audit` | filebeat.yml: HTTP output, verification none, credentials |
| `fluentd_audit` | forward without shared key, HTTP output without TLS |
| `telegraf_audit` | HTTP output, insecure_skip_verify, credentials in file |
| `graylog_audit` | REST on 0.0.0.0, short password_secret, empty root hash |
| `netdata_audit` | bind 0.0.0.0, allow list `*`, missing allow list |
### ESP32
@@ -771,6 +775,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| NATS monitoring | two unauthenticated GETs, varz answer as evidence |
| logstash/filebeat/fluentd | config reads only; optional root prefix |
| InfluxDB | two unauthenticated GETs, query answer as evidence |
| telegraf/graylog/netdata | config reads only; optional root prefix |
| ClickHouse | two unauthenticated GETs, version as evidence |
| USB audit | 200 devices, sysfs reads only |
---
@@ -782,7 +788,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1156 end-to-end checks
make test # version check + gate audit + 1168 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
@@ -911,7 +917,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
couchdb_probe, prometheus_api_probe,
rabbitmq_management_probe, grafana_api_probe,
minio_admin_probe, nats_monitoring_probe,
influxdb_probe
influxdb_probe, clickhouse_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,
@@ -954,7 +960,7 @@ examples/ scope.json
## Status
1.58.0. Built and run: 270 tools, 1156 checks, 340 fuzz cases and 84.0% line
1.59.0. Built and run: 274 tools, 1168 checks, 340 fuzz cases and 84.1% 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.58.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.59.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.
- **Telegraf, Graylog and Netdata audits read local files.** The ClickHouse
probe sends two unauthenticated GETs and saves the query answer.
- **Logstash, Filebeat and Fluentd audits read local files.** The InfluxDB
probe sends two unauthenticated GETs and saves the query answer.
- **Kibana, Nagios and Synapse audits read local files.** The NATS
+3 -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.58.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.59.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),
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),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -75,7 +75,7 @@ autofs_audit, gitea_audit, minio_audit, nextcloud_audit, zabbix_audit, nrpe_audi
unattended_upgrades_audit, gitlab_audit, vaultwarden_audit,
keepalived_audit, webmin_audit, cockpit_audit, phpmyadmin_audit, kibana_audit,
nagios_audit, synapse_audit, logstash_audit, filebeat_audit,
fluentd_audit)
fluentd_audit, telegraf_audit, graylog_audit, netdata_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.58.0"
#define APEX_VERSION "1.59.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+275
View File
@@ -17585,6 +17585,260 @@ static void t_fluentd_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* -------------------------------------------------------------- telegraf_audit */
static void t_telegraf_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
char urls[1024];
char value[256];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int plain_http = 0;
int no_verify = 0;
int credentials = 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/telegraf/telegraf.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read telegraf.conf");
return;
}
urls[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"telegraf.conf is writable by anyone");
count++;
}
line_value(text, "urls", urls, sizeof(urls));
if (strstr(text, "http://") != NULL)
plain_http = 1;
if (line_value(text, "insecure_skip_verify", value, sizeof(value)) &&
strcasecmp(value, "true") == 0)
no_verify = 1;
if ((line_value(text, "username", value, sizeof(value)) &&
value[0] != '\0') ||
(line_value(text, "password", value, sizeof(value)) &&
value[0] != '\0'))
credentials = 1;
if (plain_http) {
add_finding(&findings, &first, "plain-http", "medium",
"an output URL uses plain HTTP");
count++;
}
if (no_verify) {
add_finding(&findings, &first, "no-verify", "high",
"TLS certificate verification is disabled");
count++;
}
if (credentials) {
add_finding(&findings, &first, "plaintext-credentials",
"medium",
"credentials are stored in telegraf.conf");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"urls\":");
apex_json_str(&b, urls);
mcp_buf_printf(&b, ",\"plain_http\":%s,\"verify_tls\":%s,"
"\"credentials_in_file\":%s,\"findings_count\":%d,"
"\"findings\":[",
plain_http ? "true" : "false",
no_verify ? "false" : "true",
credentials ? "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);
}
/* --------------------------------------------------------------- graylog_audit */
static void t_graylog_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
char rest[512];
char secret[512];
char rootpw[256];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int rest_all = 0;
int plain_http = 0;
int weak_secret = 0;
int no_rootpw = 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/graylog/server/server.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read the Graylog server.conf");
return;
}
rest[0] = secret[0] = rootpw[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"server.conf is writable by anyone");
count++;
}
conf_value(text, "rest_listen_uri", rest, sizeof(rest));
conf_value(text, "password_secret", secret, sizeof(secret));
conf_value(text, "root_password_sha2", rootpw, sizeof(rootpw));
if (strstr(rest, "0.0.0.0") != NULL)
rest_all = 1;
if (strstr(rest, "http://") != NULL)
plain_http = 1;
if (strlen(secret) < 64)
weak_secret = 1;
if (rootpw[0] == '\0')
no_rootpw = 1;
if (rest_all) {
add_finding(&findings, &first, "rest-all", "high",
"the REST API listens on every interface");
count++;
}
if (plain_http) {
add_finding(&findings, &first, "plain-http", "medium",
"the REST API uses plain HTTP");
count++;
}
if (weak_secret) {
add_finding(&findings, &first, "weak-password-secret", "high",
"password_secret is empty or shorter than 64");
count++;
}
if (no_rootpw) {
add_finding(&findings, &first, "no-root-password", "high",
"root_password_sha2 is empty");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"rest_listen_uri\":");
apex_json_str(&b, rest);
mcp_buf_printf(&b, ",\"rest_all\":%s,\"https\":%s,"
"\"password_secret\":%s,\"root_password\":%s,"
"\"findings_count\":%d,\"findings\":[",
rest_all ? "true" : "false",
plain_http ? "false" : "true",
weak_secret ? "false" : "true",
no_rootpw ? "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);
}
/* --------------------------------------------------------------- netdata_audit */
static void t_netdata_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
char bind[256];
char allow[512];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int bind_all = 0;
int allow_all = 0;
int no_access_list = 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/netdata/netdata.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read netdata.conf");
return;
}
bind[0] = allow[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"netdata.conf is writable by anyone");
count++;
}
ini_value(text, "web", "bind to IP", bind, sizeof(bind));
if (strcmp(bind, "0.0.0.0") == 0 || strcmp(bind, "*") == 0 ||
strcmp(bind, "::") == 0)
bind_all = 1;
if (!ini_value(text, "web", "allow connections from", allow,
sizeof(allow))) {
no_access_list = 1;
} else if (strcmp(allow, "*") == 0 || strstr(allow, "0.0.0.0/0") != NULL) {
allow_all = 1;
}
if (bind_all) {
add_finding(&findings, &first, "bind-all", "high",
"the dashboard binds to every interface");
count++;
}
if (allow_all) {
add_finding(&findings, &first, "allow-all", "high",
"any address may read the dashboard");
count++;
}
if (no_access_list) {
add_finding(&findings, &first, "no-access-list", "medium",
"no allow connections from list is configured");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"bind_to_ip\":");
apex_json_str(&b, bind);
mcp_buf_puts(&b, ",\"allow_connections_from\":");
apex_json_str(&b, allow);
mcp_buf_printf(&b, ",\"bind_all\":%s,\"allow_all\":%s,"
"\"findings_count\":%d,\"findings\":[",
bind_all ? "true" : "false",
allow_all ? "true" : "false", count);
if (findings.p != NULL)
mcp_buf_add(&b, findings.p, findings.len);
mcp_buf_puts(&b, "]}");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
mcp_buf_free(&findings);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -18576,6 +18830,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_fluentd_audit },
{ "telegraf_audit",
"Parse telegraf.conf (root prefix): an HTTP output URL, "
"insecure_skip_verify, credentials in the file and a world-writable "
"file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_telegraf_audit },
{ "graylog_audit",
"Parse the Graylog server.conf (root prefix): the REST API on every "
"interface, plain HTTP, a short password_secret, an empty "
"root_password_sha2 and a world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_graylog_audit },
{ "netdata_audit",
"Parse netdata.conf (root prefix): the dashboard bound to 0.0.0.0, an "
"allow list of *, a missing allow list and a world-writable file. "
"Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_netdata_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+100
View File
@@ -7374,6 +7374,96 @@ static void t_influxdb_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ---------------------------------------------------------- clickhouse_probe */
static void t_clickhouse_probe(mcp_conn *c, const mcp_json *args,
void *user)
{
static const char *paths[] = { "/ping", "/?query=SELECT%20version()",
NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 8123);
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 ping_open = 0;
int query_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, "clickhouse_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 query = strstr(paths[i], "query=") != 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 && !query)
ping_open = 1;
if (open && query) {
query_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("clickhouse-version",
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,"
"\"ping_open\":%s,\"query_open\":%s,\"evidence\":",
tested, open_count, ping_open ? "true" : "false",
query_open ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("clickhouse_probe", target, port, !query_open,
query_open
? "the ClickHouse HTTP query API answers without authentication"
: "the ClickHouse HTTP query 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: "
@@ -7997,6 +8087,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_influxdb_probe },
{ "clickhouse_probe",
"Query ClickHouse without credentials: /ping and "
"/?query=SELECT%20version(). A 2xx with a version is an open HTTP API; "
"the answer is saved as evidence. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 8123\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_clickhouse_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
View File
@@ -21,7 +21,7 @@ import re
import sys
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXPECTED_TOOLS = 270
EXPECTED_TOOLS = 274
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.
+181 -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("270 tools registered", len(tools) == 270, len(tools))
check("274 tools registered", len(tools) == 274, 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"]) == 270)
check("http tools/list", len(listing["result"]["tools"]) == 274)
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
@@ -12382,6 +12382,184 @@ shutil.rmtree(fd_root, ignore_errors=True)
shutil.rmtree(fd_good_root, ignore_errors=True)
shutil.rmtree(cfg30_home, ignore_errors=True)
print("\n== Telegraf, Graylog, Netdata and ClickHouse ==\n")
tg_root = tempfile.mkdtemp(prefix="apex-tg-")
os.makedirs(os.path.join(tg_root, "etc", "telegraf"))
tg_bad = os.path.join(tg_root, "etc", "telegraf", "telegraf.conf")
with open(tg_bad, "w") as f:
f.write("[[outputs.influxdb]]\n")
f.write(' urls = ["http://influx.example.test:8086"]\n')
f.write(" insecure_skip_verify = true\n")
f.write(' username = "telegraf"\n')
f.write(' password = "secret"\n')
os.chmod(tg_bad, 0o666)
tg_good_root = tempfile.mkdtemp(prefix="apex-tgg-")
os.makedirs(os.path.join(tg_good_root, "etc", "telegraf"))
with open(os.path.join(tg_good_root, "etc", "telegraf", "telegraf.conf"),
"w") as f:
f.write("[[outputs.influxdb]]\n")
f.write(' urls = ["https://influx.example.test:8086"]\n')
f.write(" insecure_skip_verify = false\n")
gl_root = tempfile.mkdtemp(prefix="apex-gl2-")
os.makedirs(os.path.join(gl_root, "etc", "graylog", "server"))
gl_bad = os.path.join(gl_root, "etc", "graylog", "server", "server.conf")
with open(gl_bad, "w") as f:
f.write("rest_listen_uri = http://0.0.0.0:9000/api/\n")
f.write("password_secret = short\n")
f.write("root_password_sha2 =\n")
os.chmod(gl_bad, 0o666)
gl_good_root = tempfile.mkdtemp(prefix="apex-gl2g-")
os.makedirs(os.path.join(gl_good_root, "etc", "graylog", "server"))
with open(os.path.join(gl_good_root, "etc", "graylog", "server",
"server.conf"), "w") as f:
f.write("rest_listen_uri = https://127.0.0.1:9000/api/\n")
f.write("password_secret = " + "a" * 96 + "\n")
f.write("root_password_sha2 = " + "b" * 64 + "\n")
nd_root = tempfile.mkdtemp(prefix="apex-nd-")
os.makedirs(os.path.join(nd_root, "etc", "netdata"))
nd_bad = os.path.join(nd_root, "etc", "netdata", "netdata.conf")
with open(nd_bad, "w") as f:
f.write("[web]\n")
f.write(" bind to IP = 0.0.0.0\n")
f.write(" allow connections from = *\n")
os.chmod(nd_bad, 0o666)
nd_good_root = tempfile.mkdtemp(prefix="apex-ndg-")
os.makedirs(os.path.join(nd_good_root, "etc", "netdata"))
with open(os.path.join(nd_good_root, "etc", "netdata", "netdata.conf"),
"w") as f:
f.write("[web]\n")
f.write(" bind to IP = 127.0.0.1\n")
f.write(" allow connections from = localhost 10.0.0.0/8\n")
class _ClickHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/ping":
body = b"Ok.\n"
self.send_response(200)
elif path == "/":
body = b"23.8.1.1\n"
self.send_response(200)
else:
body = b"not found"
self.send_response(404)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
class _ClickAuthHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/ping":
body = b"Ok.\n"
self.send_response(200)
else:
body = b"Authentication failed"
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
ch_srv = http.server.HTTPServer(("127.0.0.1", 0), _ClickHandler)
ch_port = ch_srv.server_address[1]
threading.Thread(target=ch_srv.serve_forever, daemon=True).start()
ch_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
_ClickAuthHandler)
ch_auth_port = ch_auth_srv.server_address[1]
threading.Thread(target=ch_auth_srv.serve_forever, daemon=True).start()
cfg31_home = tempfile.mkdtemp(prefix="apex-cfg31-home-")
write_scope(cfg31_home, {"label": "cfg31", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(ch_port), str(ch_auth_port)]})
res, _ = run([
call(1, "telegraf_audit", root=tg_root),
call(2, "telegraf_audit", root=tg_good_root),
call(3, "graylog_audit", root=gl_root),
call(4, "graylog_audit", root=gl_good_root),
call(5, "netdata_audit", root=nd_root),
call(6, "netdata_audit", root=nd_good_root),
call(7, "clickhouse_probe", target="127.0.0.1", port=ch_port,
tls=False),
call(8, "clickhouse_probe", target="127.0.0.1", port=ch_auth_port,
tls=False),
call(9, "clickhouse_probe", target="198.51.100.9", port=8123),
call(10, "telegraf_audit", root="/nonexistent-tg"),
call(11, "graylog_audit", root="/nonexistent-gl"),
call(12, "netdata_audit", root="/nonexistent-nd"),
], home=cfg31_home)
by_id = {r.get("id"): r for r in res}
tg = json.loads(text(by_id[1]))
tg_kinds = {f["id"] for f in tg["findings"]}
check("telegraf_audit flags HTTP, no verify and credentials",
{"world-writable", "plain-http", "no-verify",
"plaintext-credentials"} <= tg_kinds and tg["plain_http"] is True and
tg["verify_tls"] is False, tg)
tg_good = json.loads(text(by_id[2]))
check("telegraf_audit accepts HTTPS with verification",
tg_good["findings_count"] == 0 and tg_good["plain_http"] is False and
tg_good["verify_tls"] is True, tg_good)
gl = json.loads(text(by_id[3]))
gl_kinds = {f["id"] for f in gl["findings"]}
check("graylog_audit flags the open REST API and empty secrets",
{"world-writable", "rest-all", "plain-http", "weak-password-secret",
"no-root-password"} <= gl_kinds and gl["rest_all"] is True and
gl["root_password"] is False, gl)
gl_good = json.loads(text(by_id[4]))
check("graylog_audit accepts HTTPS with strong secrets",
gl_good["findings_count"] == 0 and gl_good["rest_all"] is False and
gl_good["root_password"] is True, gl_good)
nd = json.loads(text(by_id[5]))
nd_kinds = {f["id"] for f in nd["findings"]}
check("netdata_audit flags a world-open dashboard",
{"world-writable", "bind-all", "allow-all"} <= nd_kinds and
nd["bind_all"] is True and nd["allow_all"] is True, nd)
nd_good = json.loads(text(by_id[6]))
check("netdata_audit accepts loopback with a scoped allow list",
nd_good["findings_count"] == 0 and nd_good["bind_all"] is False and
nd_good["allow_all"] is False, nd_good)
ch = json.loads(text(by_id[7]))
check("clickhouse_probe finds the open query API",
ch["query_open"] is True and ch["ping_open"] is True and
ch["evidence"] and os.path.isfile(ch["evidence"]), ch)
ch_auth = json.loads(text(by_id[8]))
check("clickhouse_probe reports a protected query API",
ch_auth["query_open"] is False and ch_auth["ping_open"] is True and
all(e["status"] == 403 for e in ch_auth["endpoints"]
if "query=" in e["path"]), ch_auth)
check("clickhouse_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("telegraf_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("graylog_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("netdata_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
ch_srv.shutdown()
ch_srv.server_close()
ch_auth_srv.shutdown()
ch_auth_srv.server_close()
shutil.rmtree(tg_root, ignore_errors=True)
shutil.rmtree(tg_good_root, ignore_errors=True)
shutil.rmtree(gl_root, ignore_errors=True)
shutil.rmtree(gl_good_root, ignore_errors=True)
shutil.rmtree(nd_root, ignore_errors=True)
shutil.rmtree(nd_good_root, ignore_errors=True)
shutil.rmtree(cfg31_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -12402,6 +12580,7 @@ print("\n== esp32 tools ==")
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"})
esp_m, esp_s = pty.openpty()