apex-twin 1.61.0: atd, securetty and tmpfiles audits, Logstash API probe
Blue: - atd_audit: at.allow/at.deny: world-writable lists and an empty at.deny that opens scheduling to every user. Both files missing is the safe case (root only) and is not flagged. - securetty_audit: serial or virtual console entries (ttyS0, ttyS1, console, hvc0, ttyAMA0) that allow root login, and a world-writable file. - tmpfiles_audit: tmpfiles.d/*.conf from /etc and /usr/lib: 0777/0666 modes, z/Z rules on /tmp or /var/tmp, world-writable files. Red: - logstash_api_probe: /_node/info and /_node/stats without credentials; a 2xx is an open monitoring API with the stats answer saved as evidence. Tests with atd/securetty/tmpfiles trees and two Logstash fixtures (open and 401). 1193 checks, ASan suite green, analyze clean, release-check green including distcheck 1.61.0.
This commit is contained in:
1 parent
ddb99c0609
commit
a118a8d226
9 files changed
+630
-15
No files matched your search
+18
-1
@@ -8,7 +8,24 @@ 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.60.0 — 2026-11-23 — this change
|
||||
## 1.61.0 — 2026-11-23 — this change
|
||||
|
||||
- **atd** (`atd_audit`): `at.allow` and `at.deny`: world-writable lists and
|
||||
an empty `at.deny` that opens scheduling to every user. Both files missing
|
||||
is the safe case (root only) and is *not* a finding.
|
||||
- **securetty** (`securetty_audit`): `/etc/securetty`: serial or virtual
|
||||
console entries (`ttyS0`, `ttyS1`, `console`, `hvc0`, `ttyAMA0`) that allow
|
||||
root login and a world-writable file.
|
||||
- **tmpfiles** (`tmpfiles_audit`): `tmpfiles.d/*.conf` from `/etc` and
|
||||
`/usr/lib`: world-writable modes, `z`/`Z` rules on `/tmp` or `/var/tmp` and
|
||||
world-writable files.
|
||||
- **Logstash node** (`logstash_api_probe`): `/_node/info` and `/_node/stats`
|
||||
without credentials; a 2xx is an open monitoring API with the stats answer
|
||||
saved as evidence.
|
||||
- Tests with atd/securetty/tmpfiles trees and two Logstash fixtures (open and
|
||||
401). 1193 checks. Coverage 84.2%.
|
||||
|
||||
## 1.60.0 — 2026-11-23 — ddb99c0
|
||||
|
||||
- **sshd_config** (`sshd_config_audit`): `sshd_config` and
|
||||
`sshd_config.d/*.conf` with OpenSSH's first-value-wins order (drop-ins
|
||||
|
||||
@@ -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.
|
||||
|
||||
**278 tools · 1181 end-to-end checks · 340 fuzz cases · 84.1% line coverage · ~966 KiB**
|
||||
**282 tools · 1193 end-to-end checks · 340 fuzz cases · 84.2% line coverage · ~971 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.60.0","tools":278,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.61.0","tools":282,...,"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 (278)
|
||||
## Tools (282)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -219,6 +219,7 @@ uploads and secret-file reads. It does not execute anything.
|
||||
| `influxdb_probe` | `/ping` and `/query?q=SHOW DATABASES` without auth; answer as evidence |
|
||||
| `clickhouse_probe` | `/ping` and `SELECT version()` without auth; version as evidence |
|
||||
| `kibana_api_probe` | `/api/saved_objects/_find` without auth; answer as evidence |
|
||||
| `logstash_api_probe` | `/_node/info` and `/_node/stats` without auth; stats as evidence |
|
||||
| `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 |
|
||||
@@ -475,6 +476,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `sshd_config_audit` | sshd_config(.d): root login, password auth, empty passwords |
|
||||
| `hosts_access_audit` | hosts.allow/deny: `ALL: ALL`, missing deny rules |
|
||||
| `profile_audit` | profile scripts: world-writable, loose umask, `.` in PATH |
|
||||
| `atd_audit` | at.allow/deny: empty deny list, world-writable lists |
|
||||
| `securetty_audit` | securetty: serial/console entries allow root login |
|
||||
| `tmpfiles_audit` | tmpfiles.d: 0777/0666 modes, z/Z rules on /tmp |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -783,6 +787,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| ClickHouse | two unauthenticated GETs, version as evidence |
|
||||
| sshd_config/hosts_access/profile | config reads only; optional root prefix |
|
||||
| Kibana API | two unauthenticated GETs, saved objects as evidence |
|
||||
| atd/securetty/tmpfiles | config reads only; optional root prefix |
|
||||
| Logstash API | two unauthenticated GETs, stats as evidence |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -794,7 +800,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 1181 end-to-end checks
|
||||
make test # version check + gate audit + 1193 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
|
||||
@@ -923,7 +929,8 @@ 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, clickhouse_probe, kibana_api_probe
|
||||
influxdb_probe, clickhouse_probe, kibana_api_probe,
|
||||
logstash_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,
|
||||
@@ -966,7 +973,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.60.0. Built and run: 278 tools, 1181 checks, 340 fuzz cases and 84.1% line
|
||||
1.61.0. Built and run: 282 tools, 1193 checks, 340 fuzz cases and 84.2% line
|
||||
coverage. The loop closes: a probe captures the exchange as a pair, a finding
|
||||
points at it, `finding_update` gives it a state, an asset records the host it
|
||||
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
|
||||
|
||||
+3
-1
@@ -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.60.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.61.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.
|
||||
- **atd, securetty and tmpfiles audits read local files.** The Logstash node
|
||||
probe sends two unauthenticated GETs and saves the stats answer.
|
||||
- **sshd_config, hosts_access and profile audits read local files.** The
|
||||
Kibana probe sends two unauthenticated GETs and saves the saved-objects
|
||||
answer.
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.60.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.61.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),
|
||||
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),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -76,7 +76,8 @@ 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, telegraf_audit, graylog_audit, netdata_audit, sshd_config_audit,
|
||||
hosts_access_audit, profile_audit)
|
||||
hosts_access_audit, profile_audit, atd_audit, securetty_audit,
|
||||
tmpfiles_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.60.0"
|
||||
#define APEX_VERSION "1.61.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -18260,6 +18260,313 @@ static void t_profile_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- atd_audit */
|
||||
|
||||
static void t_atd_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char allow_path[1024];
|
||||
char deny_path[1024];
|
||||
static char allow_text[65536];
|
||||
static char deny_text[65536];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int allow_exists;
|
||||
int deny_exists;
|
||||
int open_to_all = 0;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(allow_path, sizeof(allow_path), "%s/etc/at.allow", root);
|
||||
snprintf(deny_path, sizeof(deny_path), "%s/etc/at.deny", root);
|
||||
allow_exists = read_text(allow_path, allow_text, sizeof(allow_text)) >= 0;
|
||||
deny_exists = read_text(deny_path, deny_text, sizeof(deny_text)) >= 0;
|
||||
mcp_buf_init(&findings);
|
||||
if (allow_exists) {
|
||||
if (stat(allow_path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"at.allow is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (deny_exists) {
|
||||
if (stat(deny_path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"at.deny is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
if (!allow_exists) {
|
||||
char *copy = strdup(deny_text);
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
int entries = 0;
|
||||
|
||||
if (copy != NULL) {
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *s = line;
|
||||
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s != '#' && *s != '\0')
|
||||
entries++;
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
if (entries == 0)
|
||||
open_to_all = 1;
|
||||
}
|
||||
}
|
||||
if (open_to_all) {
|
||||
add_finding(&findings, &first, "open-to-all", "medium",
|
||||
"at.deny exists but is empty, so every user may "
|
||||
"schedule jobs");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"allow_file\":%s,\"deny_file\":%s,"
|
||||
"\"open_to_all\":%s,\"findings_count\":%d,\"findings\":[",
|
||||
allow_exists ? "true" : "false",
|
||||
deny_exists ? "true" : "false",
|
||||
open_to_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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- securetty_audit */
|
||||
|
||||
static void t_securetty_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];
|
||||
struct stat st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int serial = 0;
|
||||
int entries = 0;
|
||||
char *copy;
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
(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/securetty", root);
|
||||
if (read_text(path, text, sizeof(text)) <= 0) {
|
||||
mcp_reply_error(c, "cannot read /etc/securetty");
|
||||
return;
|
||||
}
|
||||
mcp_buf_init(&findings);
|
||||
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"securetty is writable by anyone");
|
||||
count++;
|
||||
}
|
||||
copy = strdup(text);
|
||||
if (copy == NULL) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "out of memory");
|
||||
return;
|
||||
}
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
char *s = line;
|
||||
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s != '#' && *s != '\0') {
|
||||
entries++;
|
||||
if (strcmp(s, "ttyS0") == 0 || strcmp(s, "ttyS1") == 0 ||
|
||||
strcmp(s, "console") == 0 || strcmp(s, "hvc0") == 0 ||
|
||||
strcmp(s, "ttyAMA0") == 0)
|
||||
serial = 1;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
if (serial) {
|
||||
add_finding(&findings, &first, "serial-console", "medium",
|
||||
"root may log in on a serial or virtual console");
|
||||
count++;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"entries\":%d,\"serial_console\":%s,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
entries, serial ? "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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- tmpfiles_audit */
|
||||
|
||||
static int tmpfiles_mode_open(const char *mode)
|
||||
{
|
||||
return strcmp(mode, "0777") == 0 || strcmp(mode, "777") == 0 ||
|
||||
strcmp(mode, "0666") == 0 || strcmp(mode, "666") == 0;
|
||||
}
|
||||
|
||||
static void tmpfiles_scan_file(mcp_buf *findings, int *first, int *count,
|
||||
const char *path, int *files,
|
||||
int *open_modes, int *recursive_tmp)
|
||||
{
|
||||
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;
|
||||
char type;
|
||||
char *fields[4];
|
||||
int nf = 0;
|
||||
char *tok;
|
||||
char *rest;
|
||||
|
||||
while (*s == ' ' || *s == '\t')
|
||||
s++;
|
||||
if (*s == '#' || *s == '\0') {
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
continue;
|
||||
}
|
||||
type = *s;
|
||||
tok = strtok_r(s + 1, " \t", &rest);
|
||||
while (tok != NULL && nf < 4) {
|
||||
fields[nf++] = tok;
|
||||
tok = strtok_r(NULL, " \t", &rest);
|
||||
}
|
||||
if (nf >= 2 && tmpfiles_mode_open(fields[1])) {
|
||||
add_finding(findings, first, "world-writable-mode", "high",
|
||||
"%s creates %s with mode %s", path, fields[0],
|
||||
fields[1]);
|
||||
(*count)++;
|
||||
(*open_modes)++;
|
||||
}
|
||||
if (nf >= 1 && (type == 'z' || type == 'Z') &&
|
||||
(strcmp(fields[0], "/tmp") == 0 ||
|
||||
strcmp(fields[0], "/var/tmp") == 0)) {
|
||||
add_finding(findings, first, "recursive-tmp", "high",
|
||||
"%s applies %c rules to %s", path, type,
|
||||
fields[0]);
|
||||
(*count)++;
|
||||
(*recursive_tmp)++;
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static void tmpfiles_scan_dir(mcp_buf *findings, int *first, int *count,
|
||||
const char *dirpath, int *files,
|
||||
int *open_modes, int *recursive_tmp)
|
||||
{
|
||||
DIR *d = opendir(dirpath);
|
||||
struct dirent *ent;
|
||||
|
||||
if (d == NULL)
|
||||
return;
|
||||
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);
|
||||
tmpfiles_scan_file(findings, first, count, full, files,
|
||||
open_modes, recursive_tmp);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
static void t_tmpfiles_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;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int files = 0;
|
||||
int open_modes = 0;
|
||||
int recursive_tmp = 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/tmpfiles.d", root);
|
||||
tmpfiles_scan_dir(&findings, &first, &count, path, &files,
|
||||
&open_modes, &recursive_tmp);
|
||||
snprintf(path, sizeof(path), "%s/usr/lib/tmpfiles.d", root);
|
||||
tmpfiles_scan_dir(&findings, &first, &count, path, &files,
|
||||
&open_modes, &recursive_tmp);
|
||||
if (files == 0) {
|
||||
mcp_buf_free(&findings);
|
||||
mcp_reply_error(c, "cannot read a tmpfiles.d configuration");
|
||||
return;
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"open_modes\":%d,"
|
||||
"\"recursive_tmp\":%d,\"findings_count\":%d,"
|
||||
"\"findings\":[",
|
||||
files, open_modes, recursive_tmp, 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, "
|
||||
@@ -19293,6 +19600,26 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_profile_audit },
|
||||
{ "atd_audit",
|
||||
"Parse at.allow and at.deny (root prefix): world-writable lists and an "
|
||||
"empty at.deny that lets every user schedule jobs. Both files missing "
|
||||
"is safe (root only). Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_atd_audit },
|
||||
{ "securetty_audit",
|
||||
"Parse /etc/securetty (root prefix): serial or virtual console entries "
|
||||
"that allow root login and a world-writable file. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_securetty_audit },
|
||||
{ "tmpfiles_audit",
|
||||
"Parse tmpfiles.d/*.conf (root prefix, /etc and /usr/lib): world-writable "
|
||||
"modes, z/Z rules on /tmp or /var/tmp and world-writable files. "
|
||||
"Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_tmpfiles_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
@@ -7551,6 +7551,95 @@ static void t_kibana_api_probe(mcp_conn *c, const mcp_json *args,
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------- logstash_api_probe */
|
||||
|
||||
static void t_logstash_api_probe(mcp_conn *c, const mcp_json *args,
|
||||
void *user)
|
||||
{
|
||||
static const char *paths[] = { "/_node/info", "/_node/stats", NULL };
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 9600);
|
||||
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 info_open = 0;
|
||||
int stats_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, "logstash_api_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 stats = strcmp(paths[i], "/_node/stats") == 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 && !stats)
|
||||
info_open = 1;
|
||||
if (open && stats) {
|
||||
stats_open = 1;
|
||||
if (evidence == NULL)
|
||||
evidence = apex_evidence_save("logstash-stats", 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,"
|
||||
"\"info_open\":%s,\"stats_open\":%s,\"evidence\":",
|
||||
tested, open_count, info_open ? "true" : "false",
|
||||
stats_open ? "true" : "false");
|
||||
if (evidence != NULL)
|
||||
apex_json_str(&b, evidence);
|
||||
else
|
||||
mcp_buf_puts(&b, "null");
|
||||
mcp_buf_puts(&b, "}");
|
||||
apex_audit("logstash_api_probe", target, port,
|
||||
!(info_open || stats_open),
|
||||
info_open || stats_open
|
||||
? "the Logstash node API answers without authentication"
|
||||
: "the Logstash node 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: "
|
||||
@@ -8194,6 +8283,16 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_kibana_api_probe },
|
||||
{ "logstash_api_probe",
|
||||
"Query the Logstash node API without credentials: /_node/info and "
|
||||
"/_node/stats. A 2xx is an open monitoring API; the stats answer is "
|
||||
"saved as evidence. Gate: the target.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 9600\"},"
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_logstash_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 = 278
|
||||
EXPECTED_TOOLS = 282
|
||||
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.
|
||||
|
||||
+164
-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("278 tools registered", len(tools) == 278, len(tools))
|
||||
check("282 tools registered", len(tools) == 282, 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"]) == 278)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 282)
|
||||
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
|
||||
@@ -12749,6 +12749,167 @@ shutil.rmtree(pr_root, ignore_errors=True)
|
||||
shutil.rmtree(pr_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg32_home, ignore_errors=True)
|
||||
|
||||
print("\n== atd, securetty, tmpfiles and the Logstash API ==\n")
|
||||
|
||||
at_root = tempfile.mkdtemp(prefix="apex-at-")
|
||||
os.makedirs(os.path.join(at_root, "etc"))
|
||||
at_deny = os.path.join(at_root, "etc", "at.deny")
|
||||
with open(at_deny, "w") as f:
|
||||
pass
|
||||
os.chmod(at_deny, 0o666)
|
||||
at_good_root = tempfile.mkdtemp(prefix="apex-atg-")
|
||||
os.makedirs(os.path.join(at_good_root, "etc"))
|
||||
with open(os.path.join(at_good_root, "etc", "at.allow"), "w") as f:
|
||||
f.write("deploy\n")
|
||||
at_none_root = tempfile.mkdtemp(prefix="apex-atn-")
|
||||
os.makedirs(os.path.join(at_none_root, "etc"))
|
||||
|
||||
st_root = tempfile.mkdtemp(prefix="apex-st-")
|
||||
os.makedirs(os.path.join(st_root, "etc"))
|
||||
st_bad = os.path.join(st_root, "etc", "securetty")
|
||||
with open(st_bad, "w") as f:
|
||||
f.write("tty1\nttyS0\nconsole\n")
|
||||
os.chmod(st_bad, 0o666)
|
||||
st_good_root = tempfile.mkdtemp(prefix="apex-stg-")
|
||||
os.makedirs(os.path.join(st_good_root, "etc"))
|
||||
with open(os.path.join(st_good_root, "etc", "securetty"), "w") as f:
|
||||
f.write("tty1\ntty2\n")
|
||||
|
||||
tf_root = tempfile.mkdtemp(prefix="apex-tf2-")
|
||||
os.makedirs(os.path.join(tf_root, "etc", "tmpfiles.d"))
|
||||
tf_bad = os.path.join(tf_root, "etc", "tmpfiles.d", "evil.conf")
|
||||
with open(tf_bad, "w") as f:
|
||||
f.write("f /tmp/evil 0777 - - -\n")
|
||||
f.write("z /var/tmp - - - -\n")
|
||||
os.chmod(tf_bad, 0o666)
|
||||
tf_good_root = tempfile.mkdtemp(prefix="apex-tf2g-")
|
||||
os.makedirs(os.path.join(tf_good_root, "etc", "tmpfiles.d"))
|
||||
with open(os.path.join(tf_good_root, "etc", "tmpfiles.d", "app.conf"),
|
||||
"w") as f:
|
||||
f.write("d /run/app 0755 app app -\n")
|
||||
f.write("f /run/app/lock 0644 app app -\n")
|
||||
|
||||
|
||||
class _LsApiHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/_node/info":
|
||||
body = b'{"version":"8.13.0","pipeline":{"workers":2}}'
|
||||
self.send_response(200)
|
||||
elif path == "/_node/stats":
|
||||
body = b'{"jvm":{"uptime_in_millis":1000},"events":{}}'
|
||||
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 _LsApiAuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
body = b"Unauthorized"
|
||||
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
|
||||
|
||||
|
||||
ls_srv = http.server.HTTPServer(("127.0.0.1", 0), _LsApiHandler)
|
||||
ls_port = ls_srv.server_address[1]
|
||||
threading.Thread(target=ls_srv.serve_forever, daemon=True).start()
|
||||
ls_auth_srv = http.server.HTTPServer(("127.0.0.1", 0),
|
||||
_LsApiAuthHandler)
|
||||
ls_auth_port = ls_auth_srv.server_address[1]
|
||||
threading.Thread(target=ls_auth_srv.serve_forever, daemon=True).start()
|
||||
|
||||
cfg33_home = tempfile.mkdtemp(prefix="apex-cfg33-home-")
|
||||
write_scope(cfg33_home, {"label": "cfg33", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_port": [str(ls_port), str(ls_auth_port)]})
|
||||
res, _ = run([
|
||||
call(1, "atd_audit", root=at_root),
|
||||
call(2, "atd_audit", root=at_good_root),
|
||||
call(3, "atd_audit", root=at_none_root),
|
||||
call(4, "securetty_audit", root=st_root),
|
||||
call(5, "securetty_audit", root=st_good_root),
|
||||
call(6, "tmpfiles_audit", root=tf_root),
|
||||
call(7, "tmpfiles_audit", root=tf_good_root),
|
||||
call(8, "logstash_api_probe", target="127.0.0.1", port=ls_port,
|
||||
tls=False),
|
||||
call(9, "logstash_api_probe", target="127.0.0.1", port=ls_auth_port,
|
||||
tls=False),
|
||||
call(10, "logstash_api_probe", target="198.51.100.9", port=9600),
|
||||
call(11, "securetty_audit", root="/nonexistent-st"),
|
||||
call(12, "tmpfiles_audit", root="/nonexistent-tf"),
|
||||
], home=cfg33_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
at = json.loads(text(by_id[1]))
|
||||
at_kinds = {f["id"] for f in at["findings"]}
|
||||
check("atd_audit flags an empty deny list and a writable file",
|
||||
{"world-writable", "open-to-all"} <= at_kinds and
|
||||
at["open_to_all"] is True, at)
|
||||
at_good = json.loads(text(by_id[2]))
|
||||
check("atd_audit accepts an allow list",
|
||||
at_good["findings_count"] == 0 and at_good["allow_file"] is True and
|
||||
at_good["open_to_all"] is False, at_good)
|
||||
at_none = json.loads(text(by_id[3]))
|
||||
check("atd_audit treats missing lists as root-only",
|
||||
at_none["findings_count"] == 0 and at_none["allow_file"] is False and
|
||||
at_none["deny_file"] is False, at_none)
|
||||
st = json.loads(text(by_id[4]))
|
||||
st_kinds = {f["id"] for f in st["findings"]}
|
||||
check("securetty_audit flags serial consoles and a writable file",
|
||||
{"world-writable", "serial-console"} <= st_kinds and
|
||||
st["serial_console"] is True and st["entries"] == 3, st)
|
||||
st_good = json.loads(text(by_id[5]))
|
||||
check("securetty_audit accepts local TTYs only",
|
||||
st_good["findings_count"] == 0 and
|
||||
st_good["serial_console"] is False, st_good)
|
||||
tf = json.loads(text(by_id[6]))
|
||||
tf_kinds = {f["id"] for f in tf["findings"]}
|
||||
check("tmpfiles_audit flags open modes and recursive /tmp rules",
|
||||
{"world-writable", "world-writable-mode", "recursive-tmp"} <=
|
||||
tf_kinds and tf["open_modes"] == 1 and tf["recursive_tmp"] == 1, tf)
|
||||
tf_good = json.loads(text(by_id[7]))
|
||||
check("tmpfiles_audit accepts private runtime files",
|
||||
tf_good["findings_count"] == 0 and tf_good["open_modes"] == 0 and
|
||||
tf_good["recursive_tmp"] == 0, tf_good)
|
||||
ls = json.loads(text(by_id[8]))
|
||||
check("logstash_api_probe finds the open node API",
|
||||
ls["info_open"] is True and ls["stats_open"] is True and
|
||||
ls["evidence"] and os.path.isfile(ls["evidence"]), ls)
|
||||
ls_auth = json.loads(text(by_id[9]))
|
||||
check("logstash_api_probe reports a protected API",
|
||||
ls_auth["info_open"] is False and ls_auth["stats_open"] is False and
|
||||
all(e["status"] == 401 for e in ls_auth["endpoints"]), ls_auth)
|
||||
check("logstash_api_probe refuses an out-of-scope target", err(by_id[10]),
|
||||
text(by_id[10]))
|
||||
check("securetty_audit reports a missing file", err(by_id[11]),
|
||||
text(by_id[11]))
|
||||
check("tmpfiles_audit reports missing rules", err(by_id[12]),
|
||||
text(by_id[12]))
|
||||
ls_srv.shutdown()
|
||||
ls_srv.server_close()
|
||||
ls_auth_srv.shutdown()
|
||||
ls_auth_srv.server_close()
|
||||
shutil.rmtree(at_root, ignore_errors=True)
|
||||
shutil.rmtree(at_good_root, ignore_errors=True)
|
||||
shutil.rmtree(at_none_root, ignore_errors=True)
|
||||
shutil.rmtree(st_root, ignore_errors=True)
|
||||
shutil.rmtree(st_good_root, ignore_errors=True)
|
||||
shutil.rmtree(tf_root, ignore_errors=True)
|
||||
shutil.rmtree(tf_good_root, ignore_errors=True)
|
||||
shutil.rmtree(cfg33_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
@@ -12769,6 +12930,7 @@ print("\n== esp32 tools ==")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
|
||||
|
||||
Reference in new issue
Block a user