apex-twin 1.58.0: Logstash, Filebeat and Fluentd audits, InfluxDB probe

Blue:
- logstash_audit: logstash.yml: api.http.host 0.0.0.0, xpack monitoring
  disabled, missing path.data and a world-writable file.
- filebeat_audit: filebeat.yml: an HTTP Elasticsearch output,
  ssl.verification_mode none (both key forms), credentials in the file, no
  output and a world-writable file.
- fluentd_audit: fluent.conf/td-agent.conf: a forward source without
  shared_key, an HTTP output without TLS and a world-writable file.

Red:
- influxdb_probe: /ping and /query?q=SHOW+DATABASES without credentials; a 2xx
  query is an open database API and is saved as evidence.

Tests with Logstash/Filebeat/Fluentd trees and two InfluxDB fixtures (open and
401 with a public ping). 1156 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.58.0.
This commit is contained in:
lotherk committed 2026-11-22 14:25:37 +00:00
1 parent ea69d8d92f
commit 827ff97441
9 files changed
+598 -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.57.0 — 2026-11-23 — this change
## 1.58.0 — 2026-11-23 — this change
- **Logstash** (`logstash_audit`): `logstash.yml`: `api.http.host: 0.0.0.0`,
monitoring disabled, a missing `path.data` and a world-writable file.
- **Filebeat** (`filebeat_audit`): `filebeat.yml`: an HTTP Elasticsearch
output, `ssl.verification_mode: none`, credentials in the file, no output
and a world-writable file.
- **Fluentd** (`fluentd_audit`): `fluent.conf`/`td-agent.conf`: a forward
source without `shared_key`, an HTTP output without TLS and a
world-writable file.
- **InfluxDB** (`influxdb_probe`): `/ping` and
`/query?q=SHOW+DATABASES` without credentials; a 2xx query is an open
database API and is saved as evidence.
- Tests with Logstash/Filebeat/Fluentd trees and two InfluxDB fixtures (open
and 401 with a public ping). 1156 checks. Coverage 84.0%.
## 1.57.0 — 2026-11-23 — ea69d8d
- **Kibana** (`kibana_audit`): `kibana.yml`: `server.host: 0.0.0.0`,
`xpack.security.enabled: false`, Elasticsearch credentials in the file,
+13 -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.
**266 tools · 1144 end-to-end checks · 340 fuzz cases · 83.9% line coverage · ~929 KiB**
**270 tools · 1156 end-to-end checks · 340 fuzz cases · 84.0% line coverage · ~946 KiB**
```
$ ./apex-twin --check
{"version":"1.57.0","tools":266,...,"scope":{"loaded":true,...}}
{"version":"1.58.0","tools":270,...,"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 (266)
## Tools (270)
### Scope and bookkeeping
@@ -216,6 +216,7 @@ uploads and secret-file reads. It does not execute anything.
| `grafana_api_probe` | `/api/datasources` and `/api/admin/users` without auth; datasources as evidence |
| `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 |
| `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 |
@@ -463,6 +464,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `kibana_audit` | kibana.yml: 0.0.0.0, xpack off, credentials in file |
| `nagios_audit` | nagios.cfg/cgi.cfg: external commands, no SSL, CGI wildcard |
| `synapse_audit` | homeserver.yaml: open registration, no TLS |
| `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 |
### ESP32
@@ -765,6 +769,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| MinIO admin API | two unauthenticated GETs, admin answer as evidence |
| kibana/nagios/synapse | config reads only; optional root prefix |
| 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 |
| USB audit | 200 devices, sysfs reads only |
---
@@ -776,7 +782,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1144 end-to-end checks
make test # version check + gate audit + 1156 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
@@ -904,7 +910,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
docker_registry_probe, consul_api_probe,
couchdb_probe, prometheus_api_probe,
rabbitmq_management_probe, grafana_api_probe,
minio_admin_probe, nats_monitoring_probe
minio_admin_probe, nats_monitoring_probe,
influxdb_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,
@@ -947,7 +954,7 @@ examples/ scope.json
## Status
1.57.0. Built and run: 266 tools, 1144 checks, 340 fuzz cases and 83.9% line
1.58.0. Built and run: 270 tools, 1156 checks, 340 fuzz cases and 84.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
+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.57.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.58.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.
- **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
monitoring probe sends two unauthenticated GETs and saves the varz answer.
- **Webmin, Cockpit and phpMyAdmin audits read local files.** The MinIO
+4 -3
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.57.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.58.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),
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),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -74,7 +74,8 @@ varnish_audit, freeradius_audit, containerd_audit, nats_audit, caddy_audit, trae
autofs_audit, gitea_audit, minio_audit, nextcloud_audit, zabbix_audit, nrpe_audit,
unattended_upgrades_audit, gitlab_audit, vaultwarden_audit,
keepalived_audit, webmin_audit, cockpit_audit, phpmyadmin_audit, kibana_audit,
nagios_audit, synapse_audit)
nagios_audit, synapse_audit, logstash_audit, filebeat_audit,
fluentd_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.57.0"
#define APEX_VERSION "1.58.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+276
View File
@@ -17330,6 +17330,261 @@ static void t_synapse_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* ------------------------------------------------------------- logstash_audit */
static void t_logstash_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 host[256];
char value[64];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int api_all = 0;
int monitoring_off = 0;
int no_path_data = 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/logstash/logstash.yml", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read logstash.yml");
return;
}
host[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"logstash.yml is writable by anyone");
count++;
}
yaml_value(text, "api.http.host", host, sizeof(host));
if (strcmp(host, "0.0.0.0") == 0 || strcmp(host, "::") == 0)
api_all = 1;
if (yaml_value(text, "xpack.monitoring.enabled", value,
sizeof(value)) &&
strcasecmp(value, "false") == 0)
monitoring_off = 1;
if (!yaml_value(text, "path.data", value, sizeof(value)) ||
value[0] == '\0')
no_path_data = 1;
if (api_all) {
add_finding(&findings, &first, "api-all", "high",
"the Logstash API listens on every interface");
count++;
}
if (monitoring_off) {
add_finding(&findings, &first, "monitoring-off", "low",
"xpack monitoring is disabled");
count++;
}
if (no_path_data) {
add_finding(&findings, &first, "no-path-data", "low",
"path.data is not set explicitly");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"api_host\":");
apex_json_str(&b, host);
mcp_buf_printf(&b, ",\"api_all\":%s,\"monitoring\":%s,"
"\"path_data\":%s,\"findings_count\":%d,\"findings\":[",
api_all ? "true" : "false",
monitoring_off ? "false" : "true",
no_path_data ? "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);
}
/* -------------------------------------------------------------- filebeat_audit */
static void t_filebeat_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 hosts[512];
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;
int no_output = 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/filebeat/filebeat.yml", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read filebeat.yml");
return;
}
hosts[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"filebeat.yml is writable by anyone");
count++;
}
yaml_value(text, "hosts", hosts, sizeof(hosts));
if (strstr(hosts, "http://") != NULL)
plain_http = 1;
{
int have_mode = yaml_value(text, "ssl.verification_mode", value,
sizeof(value));
if (!have_mode)
have_mode = yaml_value(text, "verification_mode", value,
sizeof(value));
if (have_mode && strcasecmp(value, "none") == 0)
no_verify = 1;
}
if ((yaml_value(text, "username", value, sizeof(value)) &&
value[0] != '\0') ||
(yaml_value(text, "password", value, sizeof(value)) &&
value[0] != '\0'))
credentials = 1;
if (strstr(text, "output.") == NULL)
no_output = 1;
if (plain_http) {
add_finding(&findings, &first, "plain-http", "medium",
"the Elasticsearch output 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",
"Elasticsearch credentials are stored in filebeat.yml");
count++;
}
if (no_output) {
add_finding(&findings, &first, "no-output", "low",
"no output is configured");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"hosts\":");
apex_json_str(&b, hosts);
mcp_buf_printf(&b, ",\"plain_http\":%s,\"verify_tls\":%s,"
"\"credentials_in_file\":%s,\"output\":%s,"
"\"findings_count\":%d,\"findings\":[",
plain_http ? "true" : "false",
no_verify ? "false" : "true",
credentials ? "true" : "false",
no_output ? "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);
}
/* --------------------------------------------------------------- fluentd_audit */
static void t_fluentd_audit(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *files[] = { "/etc/fluent/fluent.conf",
"/etc/td-agent/td-agent.conf", NULL };
const char *root = mcp_arg_string(args, "root");
char path[1024];
static char text[131072];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files_read = 0;
int forward_no_key = 0;
int http_no_tls = 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 (strstr(text, "@type forward") != NULL &&
strstr(text, "shared_key") == NULL)
forward_no_key = 1;
if (strstr(text, "@type http") != NULL &&
strstr(text, "tls") == NULL &&
strstr(text, "https://") == NULL)
http_no_tls = 1;
break;
}
if (files_read == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read a Fluentd configuration");
return;
}
if (forward_no_key) {
add_finding(&findings, &first, "forward-no-key", "high",
"the forward source accepts input without a shared key");
count++;
}
if (http_no_tls) {
add_finding(&findings, &first, "http-no-tls", "medium",
"an HTTP output ships logs without TLS");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"forward_shared_key\":%s,\"http_tls\":%s,"
"\"findings_count\":%d,\"findings\":[",
forward_no_key ? "false" : "true",
http_no_tls ? "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);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -18300,6 +18555,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_synapse_audit },
{ "logstash_audit",
"Parse logstash.yml (root prefix): api.http.host on every interface, "
"xpack monitoring disabled, a missing path.data and a world-writable "
"file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_logstash_audit },
{ "filebeat_audit",
"Parse filebeat.yml (root prefix): an HTTP Elasticsearch output, "
"verification_mode none, credentials in the file, no output and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_filebeat_audit },
{ "fluentd_audit",
"Parse fluent.conf/td-agent.conf (root prefix): a forward source "
"without shared_key, an HTTP output without TLS and a world-writable "
"file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_fluentd_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+97
View File
@@ -7287,6 +7287,93 @@ static void t_nats_monitoring_probe(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* ------------------------------------------------------------- influxdb_probe */
static void t_influxdb_probe(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/ping", "/query?q=SHOW+DATABASES", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 8086);
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, "influxdb_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 = strncmp(paths[i], "/query", 6) == 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 && !query)
ping_open = 1;
if (open && query) {
query_open = 1;
if (evidence == NULL)
evidence = apex_evidence_save("influxdb-databases",
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("influxdb_probe", target, port, !query_open,
query_open
? "the InfluxDB query API answers without authentication"
: "the InfluxDB 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: "
@@ -7900,6 +7987,16 @@ const mcp_tool TOOLS_RED[] = {
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_nats_monitoring_probe },
{ "influxdb_probe",
"Query InfluxDB without credentials: /ping and "
"/query?q=SHOW+DATABASES. A 2xx on the query is an open database API; "
"the answer is saved as evidence. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 8086\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_influxdb_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 = 266
EXPECTED_TOOLS = 270
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.
+186 -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("266 tools registered", len(tools) == 266, len(tools))
check("270 tools registered", len(tools) == 270, 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"]) == 266)
check("http tools/list", len(listing["result"]["tools"]) == 270)
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
@@ -12199,6 +12199,189 @@ shutil.rmtree(sy_root, ignore_errors=True)
shutil.rmtree(sy_good_root, ignore_errors=True)
shutil.rmtree(cfg29_home, ignore_errors=True)
print("\n== Logstash, Filebeat, Fluentd and InfluxDB ==\n")
ls_root = tempfile.mkdtemp(prefix="apex-ls-")
os.makedirs(os.path.join(ls_root, "etc", "logstash"))
ls_bad = os.path.join(ls_root, "etc", "logstash", "logstash.yml")
with open(ls_bad, "w") as f:
f.write('api.http.host: "0.0.0.0"\n')
f.write("xpack.monitoring.enabled: false\n")
os.chmod(ls_bad, 0o666)
ls_good_root = tempfile.mkdtemp(prefix="apex-lsg-")
os.makedirs(os.path.join(ls_good_root, "etc", "logstash"))
with open(os.path.join(ls_good_root, "etc", "logstash", "logstash.yml"),
"w") as f:
f.write('api.http.host: "127.0.0.1"\n')
f.write("xpack.monitoring.enabled: true\n")
f.write("path.data: /var/lib/logstash\n")
fb_root = tempfile.mkdtemp(prefix="apex-fb-")
os.makedirs(os.path.join(fb_root, "etc", "filebeat"))
fb_bad = os.path.join(fb_root, "etc", "filebeat", "filebeat.yml")
with open(fb_bad, "w") as f:
f.write("output.elasticsearch:\n")
f.write(' hosts: ["http://es.example.test:9200"]\n')
f.write(' username: "beats"\n')
f.write(' password: "secret"\n')
f.write(" ssl.verification_mode: none\n")
os.chmod(fb_bad, 0o666)
fb_good_root = tempfile.mkdtemp(prefix="apex-fbg-")
os.makedirs(os.path.join(fb_good_root, "etc", "filebeat"))
with open(os.path.join(fb_good_root, "etc", "filebeat", "filebeat.yml"),
"w") as f:
f.write("output.elasticsearch:\n")
f.write(' hosts: ["https://es.example.test:9200"]\n')
f.write(" ssl.verification_mode: full\n")
fd_root = tempfile.mkdtemp(prefix="apex-fd-")
os.makedirs(os.path.join(fd_root, "etc", "fluent"))
fd_bad = os.path.join(fd_root, "etc", "fluent", "fluent.conf")
with open(fd_bad, "w") as f:
f.write("<source>\n @type forward\n port 24224\n</source>\n")
f.write("<match **>\n @type http\n")
f.write(" endpoint http://logs.example.test\n</match>\n")
os.chmod(fd_bad, 0o666)
fd_good_root = tempfile.mkdtemp(prefix="apex-fdg-")
os.makedirs(os.path.join(fd_good_root, "etc", "fluent"))
with open(os.path.join(fd_good_root, "etc", "fluent", "fluent.conf"),
"w") as f:
f.write("<source>\n @type forward\n shared_key s3cret-key\n")
f.write(" self_hostname node1\n</source>\n")
f.write("<match **>\n @type http\n tls true\n")
f.write(" endpoint https://logs.example.test\n</match>\n")
class _InfluxHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/ping":
self.send_response(204)
self.send_header("Content-Length", "0")
self.end_headers()
return
if path == "/query":
body = (b'{"results":[{"statement_id":0,"series":'
b'[{"name":"databases","columns":["name"],'
b'"values":[["app"]]}]}]}')
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 _InfluxAuthHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/ping":
self.send_response(204)
self.send_header("Content-Length", "0")
self.end_headers()
return
body = b'{"error":"authorization failed"}'
self.send_response(401)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
inf_srv = http.server.HTTPServer(("127.0.0.1", 0), _InfluxHandler)
inf_port = inf_srv.server_address[1]
threading.Thread(target=inf_srv.serve_forever, daemon=True).start()
inf_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
_InfluxAuthHandler)
inf_auth_port = inf_auth_srv.server_address[1]
threading.Thread(target=inf_auth_srv.serve_forever, daemon=True).start()
cfg30_home = tempfile.mkdtemp(prefix="apex-cfg30-home-")
write_scope(cfg30_home, {"label": "cfg30", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(inf_port), str(inf_auth_port)]})
res, _ = run([
call(1, "logstash_audit", root=ls_root),
call(2, "logstash_audit", root=ls_good_root),
call(3, "filebeat_audit", root=fb_root),
call(4, "filebeat_audit", root=fb_good_root),
call(5, "fluentd_audit", root=fd_root),
call(6, "fluentd_audit", root=fd_good_root),
call(7, "influxdb_probe", target="127.0.0.1", port=inf_port,
tls=False),
call(8, "influxdb_probe", target="127.0.0.1", port=inf_auth_port,
tls=False),
call(9, "influxdb_probe", target="198.51.100.9", port=8086),
call(10, "logstash_audit", root="/nonexistent-ls"),
call(11, "filebeat_audit", root="/nonexistent-fb"),
call(12, "fluentd_audit", root="/nonexistent-fd"),
], home=cfg30_home)
by_id = {r.get("id"): r for r in res}
ls = json.loads(text(by_id[1]))
ls_kinds = {f["id"] for f in ls["findings"]}
check("logstash_audit flags the exposed API and disabled monitoring",
{"world-writable", "api-all", "monitoring-off", "no-path-data"} <=
ls_kinds and ls["api_all"] is True and ls["monitoring"] is False, ls)
ls_good = json.loads(text(by_id[2]))
check("logstash_audit accepts loopback with monitoring and path.data",
ls_good["findings_count"] == 0 and ls_good["api_all"] is False and
ls_good["path_data"] is True, ls_good)
fb = json.loads(text(by_id[3]))
fb_kinds = {f["id"] for f in fb["findings"]}
check("filebeat_audit flags HTTP, no verification and credentials",
{"world-writable", "plain-http", "no-verify",
"plaintext-credentials"} <= fb_kinds and fb["plain_http"] is True and
fb["verify_tls"] is False, fb)
fb_good = json.loads(text(by_id[4]))
check("filebeat_audit accepts HTTPS with full verification",
fb_good["findings_count"] == 0 and fb_good["plain_http"] is False and
fb_good["verify_tls"] is True, fb_good)
fd = json.loads(text(by_id[5]))
fd_kinds = {f["id"] for f in fd["findings"]}
check("fluentd_audit flags a keyless forward and an HTTP output",
{"world-writable", "forward-no-key", "http-no-tls"} <= fd_kinds and
fd["forward_shared_key"] is False and fd["http_tls"] is False, fd)
fd_good = json.loads(text(by_id[6]))
check("fluentd_audit accepts a shared key and HTTPS",
fd_good["findings_count"] == 0 and
fd_good["forward_shared_key"] is True and fd_good["http_tls"] is True,
fd_good)
inf = json.loads(text(by_id[7]))
check("influxdb_probe finds the open query API",
inf["query_open"] is True and inf["ping_open"] is True and
inf["evidence"] and os.path.isfile(inf["evidence"]), inf)
inf_auth = json.loads(text(by_id[8]))
check("influxdb_probe reports a protected query API",
inf_auth["query_open"] is False and inf_auth["ping_open"] is True and
all(e["status"] == 401 for e in inf_auth["endpoints"]
if e["path"].startswith("/query")), inf_auth)
check("influxdb_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("logstash_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("filebeat_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("fluentd_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
inf_srv.shutdown()
inf_srv.server_close()
inf_auth_srv.shutdown()
inf_auth_srv.server_close()
shutil.rmtree(ls_root, ignore_errors=True)
shutil.rmtree(ls_good_root, ignore_errors=True)
shutil.rmtree(fb_root, ignore_errors=True)
shutil.rmtree(fb_good_root, ignore_errors=True)
shutil.rmtree(fd_root, ignore_errors=True)
shutil.rmtree(fd_good_root, ignore_errors=True)
shutil.rmtree(cfg30_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -12218,6 +12401,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()