apex-twin 1.47.0: pgbouncer, xinetd and SSSD audits, FTP TLS probe

Blue:
- pgbouncer_audit: pgbouncer.ini: auth_type trust/plain, listen_addr on
  every interface (token-wise, so ::1 is not a wildcard), an auth_file
  readable beyond its owner and a world-writable config.
- xinetd_audit: xinetd.conf and xinetd.d files: enabled legacy services,
  a service without only_from, a service running as root and world-writable
  files. Missing 'disable' means enabled in xinetd.
- sssd_audit: sssd.conf: enumerate, cache_credentials,
  ldap_id_use_start_tls=false, ldap_tls_reqcert never/allow and a
  world-writable file.

Red:
- ftp_tls_probe: read the banner and send AUTH TLS; 234 means explicit
  FTPS, 500/502/530 means credentials would cross in clear text.

Tests with pgbouncer/xinetd/sssd trees and two FTP servers (AUTH TLS
accepted and refused). 1023 checks, ASan suite green, analyze clean,
release-check green including distcheck 1.47.0.
This commit is contained in:
lotherk committed 2026-11-22 10:29:30 +00:00
1 parent b4996fd55d
commit 5c028a60c9
9 files changed
+769 -15

No files matched your search

+18 -1
View File
@@ -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.46.0 — 2026-11-23 — this change
## 1.47.0 — 2026-11-23 — this change
- **pgbouncer** (`pgbouncer_audit`): `pgbouncer.ini`: `auth_type` trust or
plain, `listen_addr` on every interface, an `auth_file` readable beyond its
owner and a world-writable config.
- **xinetd** (`xinetd_audit`): `xinetd.conf` and `xinetd.d/*`: enabled
legacy services (telnet, ftp, rsh, rlogin, rexec, tftp, talk, echo,
discard, chargen), a service without `only_from`, a service running as root
and world-writable files.
- **SSSD** (`sssd_audit`): `sssd.conf`: `enumerate`, `cache_credentials`,
`ldap_id_use_start_tls = false`, `ldap_tls_reqcert = never/allow` and a
world-writable file.
- **FTP TLS** (`ftp_tls_probe`): read the banner and send `AUTH TLS`; 234
means explicit FTPS, 500/502/530 means credentials would cross in clear.
- Tests with pgbouncer/xinetd/sssd trees and two FTP servers (AUTH TLS
accepted and refused). 1023 checks. Coverage 83.0%.
## 1.46.0 — 2026-11-23 — b4996fd
- **dnsmasq** (`dnsmasq_audit`): `dnsmasq.conf` and `dnsmasq.d/*.conf`: a
wildcard or missing interface restriction, no `bind-interfaces`, missing
+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.
**222 tools · 1011 end-to-end checks · 340 fuzz cases · 82.9% line coverage · ~826 KiB**
**226 tools · 1023 end-to-end checks · 340 fuzz cases · 83.0% line coverage · ~838 KiB**
```
$ ./apex-twin --check
{"version":"1.46.0","tools":222,...,"scope":{"loaded":true,...}}
{"version":"1.47.0","tools":226,...,"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 (222)
## Tools (226)
### Scope and bookkeeping
@@ -205,6 +205,7 @@ uploads and secret-file reads. It does not execute anything.
| `http_redirect_audit` | Follows redirects per hop inside the scope; flags HTTPS-to-HTTP downgrades |
| `hsts_audit` | HSTS max-age, includeSubDomains and preload, or a missing header |
| `tls_hostname_check` | SAN/CN wildcard match for the requested SNI name |
| `ftp_tls_probe` | `AUTH TLS` -> 234 means explicit FTPS; otherwise cleartext |
| `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 |
@@ -419,6 +420,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `dnsmasq_audit` | dnsmasq.conf: wildcard listener, missing bogus-priv/domain-needed |
| `nsswitch_audit` | nsswitch.conf: NIS compat, direct LDAP, hosts without files |
| `jenkins_audit` | config.xml: security off, AnyoneCanDoAnything, no CSRF, fixed agent port |
| `pgbouncer_audit` | pgbouncer.ini: trust auth, wildcard listen, readable auth file |
| `xinetd_audit` | xinetd: telnet/ftp/rsh enabled, no only_from, service as root |
| `sssd_audit` | sssd.conf: enumerate, cache_credentials, StartTLS off, reqcert never |
### ESP32
@@ -699,6 +703,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| HSTS | one TLS GET |
| dnsmasq/nsswitch/jenkins | config reads only; optional root prefix |
| TLS hostname | one handshake with the name as SNI |
| pgbouncer/xinetd/sssd | config reads only; optional root prefix |
| FTP TLS | banner plus one AUTH TLS command, no login |
| USB audit | 200 devices, sysfs reads only |
---
@@ -710,7 +716,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 1011 end-to-end checks
make test # version check + gate audit + 1023 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
@@ -833,7 +839,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
dns_dangling_cname, http_redirect_audit,
websocket_origin_check, dns_fcrdns_check,
dns_soa_mname_check, hsts_audit,
tls_hostname_check
tls_hostname_check, ftp_tls_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,
@@ -876,7 +882,7 @@ examples/ scope.json
## Status
1.46.0. Built and run: 222 tools, 1011 checks, 340 fuzz cases and 82.9% line
1.47.0. Built and run: 226 tools, 1023 checks, 340 fuzz cases and 83.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.46.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.47.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.
- **pgbouncer, xinetd and SSSD audits read local files.** The FTP TLS probe
reads the banner and sends AUTH TLS without logging in.
- **dnsmasq, nsswitch and Jenkins audits read local files.** The TLS
hostname check is one handshake with the name as SNI.
- **journald, coredump and nftables audits read local files.** The HSTS
+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.46.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.47.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),
websocket_origin_check, hsts_audit, tls_hostname_check, ftp_tls_probe),
defensive
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
@@ -68,7 +68,7 @@ ipsec_config_audit, openldap_config_audit, cron_audit, fail2ban_audit, chrony_co
apt_config_audit, login_defs_audit, pg_hba_audit, polkit_audit,
ldap_client_audit, ssl_cert_audit, timesyncd_audit, resolv_conf_audit, journald_audit,
coredump_audit, nftables_audit, dnsmasq_audit, nsswitch_audit,
jenkins_audit)
jenkins_audit, pgbouncer_audit, xinetd_audit, sssd_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.46.0"
#define APEX_VERSION "1.47.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+489
View File
@@ -13589,6 +13589,474 @@ static void t_jenkins_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* -------------------------------------------------------------- pgbouncer_audit */
static int pgb_listen_all(const char *value)
{
char copy[512];
char *save = NULL;
char *tok;
snprintf(copy, sizeof(copy), "%.500s", value);
tok = strtok_r(copy, ",", &save);
while (tok != NULL) {
char *t = tok;
while (*t == ' ' || *t == '\t')
t++;
{
size_t tl = strlen(t);
while (tl > 0 && (t[tl - 1] == ' ' || t[tl - 1] == '\t'))
t[--tl] = '\0';
}
if (strcmp(t, "0.0.0.0") == 0 || strcmp(t, "::") == 0 ||
strcmp(t, "*") == 0)
return 1;
tok = strtok_r(NULL, ",", &save);
}
return 0;
}
static void t_pgbouncer_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
char auth_file_path[1200];
static char text[65536];
char auth_type[64];
char listen_addr[256];
char auth_file[512];
struct stat st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int trust = 0;
int listen_every = 0;
int readable_auth_file = 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/pgbouncer/pgbouncer.ini", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read pgbouncer.ini");
return;
}
auth_type[0] = listen_addr[0] = auth_file[0] = '\0';
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"pgbouncer.ini is writable by anyone");
count++;
}
ini_value(text, "pgbouncer", "auth_type", auth_type,
sizeof(auth_type));
ini_value(text, "pgbouncer", "listen_addr", listen_addr,
sizeof(listen_addr));
ini_value(text, "pgbouncer", "auth_file", auth_file, sizeof(auth_file));
if (strcasecmp(auth_type, "trust") == 0 ||
strcasecmp(auth_type, "plain") == 0) {
trust = 1;
add_finding(&findings, &first, "trust-auth", "high",
"clients are trusted without a password check");
count++;
}
if (listen_addr[0] == '\0' || pgb_listen_all(listen_addr)) {
listen_every = 1;
add_finding(&findings, &first, "listen-all", "high",
"pgbouncer listens on every interface");
count++;
}
if (auth_file[0] == '/') {
snprintf(auth_file_path, sizeof(auth_file_path), "%.400s%s",
root, auth_file);
if (stat(auth_file_path, &st) == 0 &&
(st.st_mode & 0044) != 0) {
readable_auth_file = 1;
add_finding(&findings, &first, "readable-auth-file",
"high",
"the password file is readable beyond its "
"owner");
count++;
}
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_puts(&b, ",\"auth_type\":");
apex_json_str(&b, auth_type);
mcp_buf_puts(&b, ",\"listen_addr\":");
apex_json_str(&b, listen_addr);
mcp_buf_printf(&b, ",\"trust_auth\":%s,\"listen_all\":%s,"
"\"readable_auth_file\":%s,\"findings_count\":%d,"
"\"findings\":[",
trust ? "true" : "false",
listen_every ? "true" : "false",
readable_auth_file ? "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);
}
/* ---------------------------------------------------------------- xinetd_audit */
typedef struct {
char name[64];
int disable_yes;
int only_from;
int user_root;
int active;
} xinetd_service;
static int xinetd_insecure(const char *name)
{
static const char *bad[] = { "telnet", "ftp", "rsh", "rlogin", "rexec",
"tftp", "talk", "daytime", "echo",
"discard", "chargen", NULL };
int i;
for (i = 0; bad[i] != NULL; i++)
if (strcasecmp(name, bad[i]) == 0)
return 1;
return 0;
}
static void xinetd_eval(mcp_buf *findings, int *first, int *count,
const char *path, xinetd_service *sv)
{
if (!sv->active)
return;
sv->active = 0;
if (sv->name[0] == '\0' || strcasecmp(sv->name, "defaults") == 0)
return;
if (sv->disable_yes)
return;
if (xinetd_insecure(sv->name)) {
add_finding(findings, first, "insecure-service", "high",
"%s enables the %s service", path, sv->name);
(*count)++;
}
if (!sv->only_from) {
add_finding(findings, first, "no-only-from", "medium",
"%s allows %s from any host", path, sv->name);
(*count)++;
}
if (sv->user_root) {
add_finding(findings, first, "root-service", "high",
"%s runs %s as root", path, sv->name);
(*count)++;
}
}
static void xinetd_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files)
{
static char text[65536];
struct stat st;
char *copy;
char *save = NULL;
char *line;
xinetd_service sv;
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)++;
}
memset(&sv, 0, sizeof(sv));
sv.disable_yes = 1;
copy = strdup(text);
if (copy == NULL)
return;
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s == '#' || *s == '\0') {
line = strtok_r(NULL, "\n", &save);
continue;
}
if (strncasecmp(s, "service", 7) == 0 &&
(s[7] == ' ' || s[7] == '\t')) {
char *name = s + 7;
while (*name == ' ' || *name == '\t')
name++;
memset(&sv, 0, sizeof(sv));
sv.disable_yes = 0;
sv.active = 1;
snprintf(sv.name, sizeof(sv.name), "%.60s", name);
{
char *sp = strpbrk(sv.name, " \t{");
if (sp != NULL)
*sp = '\0';
}
} else if (*s == '}') {
xinetd_eval(findings, first, count, path, &sv);
} else if (sv.active) {
char *eq = strchr(s, '=');
char key[64];
if (eq == NULL) {
line = strtok_r(NULL, "\n", &save);
continue;
}
*eq = '\0';
snprintf(key, sizeof(key), "%.60s", s);
{
char *k = key;
size_t kl;
while (*k == ' ' || *k == '\t')
memmove(k, k + 1, strlen(k));
kl = strlen(k);
while (kl > 0 && (k[kl - 1] == ' ' ||
k[kl - 1] == '\t'))
k[--kl] = '\0';
}
{
char *v = eq + 1;
while (*v == ' ' || *v == '\t')
v++;
if (strcasecmp(key, "disable") == 0 &&
strcasecmp(v, "no") == 0)
sv.disable_yes = 0;
else if (strcasecmp(key, "disable") == 0 &&
strcasecmp(v, "yes") == 0)
sv.disable_yes = 1;
else if (strcasecmp(key, "only_from") == 0)
sv.only_from = 1;
else if (strcasecmp(key, "user") == 0 &&
strcasecmp(v, "root") == 0)
sv.user_root = 1;
}
}
line = strtok_r(NULL, "\n", &save);
}
xinetd_eval(findings, first, count, path, &sv);
free(copy);
}
static void t_xinetd_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;
DIR *d;
(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/xinetd.conf", root);
xinetd_scan_file(&findings, &first, &count, path, &files);
snprintf(path, sizeof(path), "%s/etc/xinetd.d", root);
d = opendir(path);
if (d != NULL) {
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
char full[1200];
struct stat st;
if (ent->d_name[0] == '.')
continue;
snprintf(full, sizeof(full), "%.900s/%.200s", path,
ent->d_name);
if (stat(full, &st) != 0 || !S_ISREG(st.st_mode))
continue;
xinetd_scan_file(&findings, &first, &count, full,
&files);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read an xinetd configuration");
return;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"findings_count\":%d,"
"\"findings\":[", files, 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);
}
/* ----------------------------------------------------------------- sssd_audit */
static void t_sssd_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;
char *copy;
char *save = NULL;
char *line;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int enumerate = 0;
int cache_credentials = 0;
int starttls_off = 0;
int reqcert_weak = 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/sssd/sssd.conf", root);
if (read_text(path, text, sizeof(text)) <= 0) {
mcp_reply_error(c, "cannot read sssd.conf");
return;
}
mcp_buf_init(&findings);
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0) {
add_finding(&findings, &first, "world-writable", "high",
"sssd.conf is writable by anyone");
count++;
}
copy = strdup(text);
if (copy != NULL) {
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
char *s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s != '#' && *s != ';' && *s != '[' &&
*s != '\0') {
char *eq = strchr(s, '=');
char key[64];
char *v;
if (eq != NULL) {
*eq = '\0';
snprintf(key, sizeof(key), "%.60s", s);
{
char *k = key;
size_t kl;
while (*k == ' ' || *k == '\t')
memmove(k, k + 1,
strlen(k));
kl = strlen(k);
while (kl > 0 &&
(k[kl - 1] == ' ' ||
k[kl - 1] == '\t'))
k[--kl] = '\0';
}
v = eq + 1;
while (*v == ' ' || *v == '\t')
v++;
{
size_t vl = strlen(v);
while (vl > 0 &&
(v[vl - 1] == ' ' ||
v[vl - 1] == '\t' ||
v[vl - 1] == '\r'))
v[--vl] = '\0';
}
if (strcasecmp(key, "enumerate") == 0 &&
strcasecmp(v, "true") == 0)
enumerate = 1;
else if (strcasecmp(key,
"cache_credentials")
== 0 &&
strcasecmp(v, "true") == 0)
cache_credentials = 1;
else if (strcasecmp(
key,
"ldap_id_use_start_tls")
== 0 &&
strcasecmp(v, "false") == 0)
starttls_off = 1;
else if (strcasecmp(
key,
"ldap_tls_reqcert")
== 0 &&
(strcasecmp(v, "never") == 0 ||
strcasecmp(v, "allow") == 0))
reqcert_weak = 1;
}
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
if (enumerate) {
add_finding(&findings, &first, "enumerate", "medium",
"SSSD enumerates every user and group");
count++;
}
if (cache_credentials) {
add_finding(&findings, &first, "cache-credentials", "medium",
"credentials are cached on disk");
count++;
}
if (starttls_off) {
add_finding(&findings, &first, "starttls-off", "high",
"LDAP runs without StartTLS");
count++;
}
if (reqcert_weak) {
add_finding(&findings, &first, "reqcert-weak", "high",
"the LDAP server certificate is not verified");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"enumerate\":%s,\"cache_credentials\":%s,"
"\"starttls\":%s,\"reqcert\":%s,\"findings_count\":%d,"
"\"findings\":[",
enumerate ? "true" : "false",
cache_credentials ? "true" : "false",
starttls_off ? "false" : "true",
reqcert_weak ? "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, "
@@ -14333,6 +14801,27 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_jenkins_audit },
{ "pgbouncer_audit",
"Parse pgbouncer.ini (root prefix): auth_type trust or plain, a "
"listen_addr on every interface, an auth_file readable beyond its owner "
"and a world-writable config. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_pgbouncer_audit },
{ "xinetd_audit",
"Parse xinetd.conf and xinetd.d files (root prefix): enabled legacy "
"services, a service without only_from, a service running as root and "
"world-writable files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_xinetd_audit },
{ "sssd_audit",
"Parse sssd.conf (root prefix): enumerate, cache_credentials, "
"ldap_id_use_start_tls=false, ldap_tls_reqcert never/allow and a "
"world-writable file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_sssd_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+71
View File
@@ -5942,6 +5942,68 @@ static void t_tls_hostname_check(mcp_conn *c, const mcp_json *args,
mcp_buf_free(&b);
}
/* ------------------------------------------------------------- ftp_tls_probe */
static void t_ftp_tls_probe(mcp_conn *c, const mcp_json *args, void *user)
{
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 21);
char banner[512];
char reply[4096];
int code;
int auth_code = 0;
int fd;
int supported;
mcp_buf b;
(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, "ftp_tls_probe", target, port))
return;
fd = tcp_connect_host(target, port, 8000);
if (fd < 0) {
mcp_reply_error(c, "cannot connect to the FTP service");
return;
}
banner[0] = '\0';
code = read_line(fd, banner, sizeof(banner)) >= 0
? reply_code(banner) : 0;
if (code != 220) {
mcp_buf_init(&b);
mcp_buf_printf(&b, "no FTP banner (code %d)", code);
mcp_reply_error(c, b.p);
mcp_buf_free(&b);
close(fd);
return;
}
if (write_all(fd, "AUTH TLS\r\n") == 0) {
if (read_reply(fd, reply, sizeof(reply)) > 0)
auth_code = reply_code(reply);
}
close(fd);
supported = auth_code == 234;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"banner\":", port);
apex_json_str(&b, banner);
mcp_buf_printf(&b, ",\"auth_tls_code\":%d,\"explicit_ftps\":%s}",
auth_code, supported ? "true" : "false");
apex_audit("ftp_tls_probe", target, port, !supported,
supported
? "the server offers AUTH TLS (explicit FTPS)"
: "AUTH TLS is not offered", "FTP AUTH TLS");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_PROTO[] = {
{ "ftp_probe",
"One-connection FTP check: read the 220 banner, ask FEAT, then try the "
@@ -5954,6 +6016,15 @@ const mcp_tool TOOLS_PROTO[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 21\"}},"
"\"required\":[\"target\"]}",
t_ftp_probe },
{ "ftp_tls_probe",
"Read the FTP banner and send AUTH TLS. A 234 answer means explicit "
"FTPS is available; 500/502/530 means credentials would cross the wire "
"in clear text. Gate: the target.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 21\"}},"
"\"required\":[\"target\"]}",
t_ftp_tls_probe },
{ "smtp_probe",
"One-connection SMTP check: read the 220 banner, send EHLO and list the "
"advertised extensions (STARTTLS, AUTH, SIZE, ...), then VRFY a small "
+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 = 222
EXPECTED_TOOLS = 226
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.
+171 -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("222 tools registered", len(tools) == 222, len(tools))
check("226 tools registered", len(tools) == 226, 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"]) == 222)
check("http tools/list", len(listing["result"]["tools"]) == 226)
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
@@ -10235,6 +10235,174 @@ shutil.rmtree(jk_good_root, ignore_errors=True)
shutil.rmtree(hn_dir, ignore_errors=True)
shutil.rmtree(cfg18_home, ignore_errors=True)
print("\n== pgbouncer, xinetd, SSSD and FTP TLS ==\n")
pgb_root = tempfile.mkdtemp(prefix="apex-pgb-")
os.makedirs(os.path.join(pgb_root, "etc", "pgbouncer"))
pgb_bad = os.path.join(pgb_root, "etc", "pgbouncer", "pgbouncer.ini")
with open(pgb_bad, "w") as f:
f.write("[databases]\n")
f.write("* = host=127.0.0.1\n\n")
f.write("[pgbouncer]\n")
f.write("auth_type = trust\n")
f.write("listen_addr = 0.0.0.0\n")
f.write("auth_file = /etc/pgbouncer/userlist.txt\n")
os.chmod(pgb_bad, 0o666)
pgb_auth = os.path.join(pgb_root, "etc", "pgbouncer", "userlist.txt")
with open(pgb_auth, "w") as f:
f.write('"app" "secret"\n')
os.chmod(pgb_auth, 0o666)
pgb_good_root = tempfile.mkdtemp(prefix="apex-pgbg-")
os.makedirs(os.path.join(pgb_good_root, "etc", "pgbouncer"))
with open(os.path.join(pgb_good_root, "etc", "pgbouncer",
"pgbouncer.ini"), "w") as f:
f.write("[pgbouncer]\n")
f.write("auth_type = scram-sha-256\n")
f.write("listen_addr = 127.0.0.1\n")
f.write("auth_file = /etc/pgbouncer/userlist.txt\n")
pgb_good_auth = os.path.join(pgb_good_root, "etc", "pgbouncer",
"userlist.txt")
with open(pgb_good_auth, "w") as f:
f.write('"app" "secret"\n')
os.chmod(pgb_good_auth, 0o600)
xi_root = tempfile.mkdtemp(prefix="apex-xi-")
os.makedirs(os.path.join(xi_root, "etc", "xinetd.d"))
xi_bad = os.path.join(xi_root, "etc", "xinetd.d", "telnet")
with open(xi_bad, "w") as f:
f.write("service telnet\n{\n")
f.write(" disable = no\n")
f.write(" socket_type = stream\n")
f.write(" user = root\n")
f.write(" server = /usr/sbin/in.telnetd\n")
f.write("}\n")
os.chmod(xi_bad, 0o666)
xi_good_root = tempfile.mkdtemp(prefix="apex-xig-")
os.makedirs(os.path.join(xi_good_root, "etc", "xinetd.d"))
with open(os.path.join(xi_good_root, "etc", "xinetd.d", "rsync"), "w") as f:
f.write("service rsync\n{\n")
f.write(" disable = no\n")
f.write(" user = nobody\n")
f.write(" only_from = 10.0.0.0/8\n")
f.write("}\n")
sssd_root = tempfile.mkdtemp(prefix="apex-sssd-")
os.makedirs(os.path.join(sssd_root, "etc", "sssd"))
sssd_bad = os.path.join(sssd_root, "etc", "sssd", "sssd.conf")
with open(sssd_bad, "w") as f:
f.write("[domain/example]\n")
f.write("enumerate = true\n")
f.write("cache_credentials = true\n")
f.write("ldap_id_use_start_tls = false\n")
f.write("ldap_tls_reqcert = never\n")
os.chmod(sssd_bad, 0o666)
sssd_good_root = tempfile.mkdtemp(prefix="apex-sssdg-")
os.makedirs(os.path.join(sssd_good_root, "etc", "sssd"))
with open(os.path.join(sssd_good_root, "etc", "sssd", "sssd.conf"),
"w") as f:
f.write("[domain/example]\n")
f.write("enumerate = false\n")
f.write("cache_credentials = false\n")
f.write("ldap_id_use_start_tls = true\n")
f.write("ldap_tls_reqcert = demand\n")
def ftp_tls_handler(support_tls):
def handle(conn):
f = conn.makefile("rb")
conn.sendall(b"220 test FTP ready\r\n")
while True:
line = f.readline()
if not line:
return
cmd = line.strip().split(b" ")[0].upper()
if cmd == b"AUTH":
conn.sendall(b"234 AUTH TLS ok\r\n" if support_tls
else b"502 AUTH not supported\r\n")
else:
conn.sendall(b"500 unknown\r\n")
return handle
ftp_tls_srv, ftp_tls_port = start_line_server(ftp_tls_handler(True))
ftp_plain_srv, ftp_plain_port = start_line_server(ftp_tls_handler(False))
cfg19_home = tempfile.mkdtemp(prefix="apex-cfg19-home-")
write_scope(cfg19_home, {"label": "cfg19", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(ftp_tls_port),
str(ftp_plain_port)]})
res, _ = run([
call(1, "pgbouncer_audit", root=pgb_root),
call(2, "pgbouncer_audit", root=pgb_good_root),
call(3, "xinetd_audit", root=xi_root),
call(4, "xinetd_audit", root=xi_good_root),
call(5, "sssd_audit", root=sssd_root),
call(6, "sssd_audit", root=sssd_good_root),
call(7, "ftp_tls_probe", target="127.0.0.1", port=ftp_tls_port),
call(8, "ftp_tls_probe", target="127.0.0.1", port=ftp_plain_port),
call(9, "ftp_tls_probe", target="198.51.100.9", port=21),
call(10, "pgbouncer_audit", root="/nonexistent-pgb"),
call(11, "xinetd_audit", root="/nonexistent-xi"),
call(12, "sssd_audit", root="/nonexistent-sssd"),
], home=cfg19_home)
by_id = {r.get("id"): r for r in res}
pgb = json.loads(text(by_id[1]))
pgb_kinds = {f["id"] for f in pgb["findings"]}
check("pgbouncer_audit flags trust, wildcard listen and auth file",
{"world-writable", "trust-auth", "listen-all",
"readable-auth-file"} <= pgb_kinds and
pgb["trust_auth"] is True and pgb["listen_all"] is True, pgb)
pgb_good = json.loads(text(by_id[2]))
check("pgbouncer_audit accepts scram on loopback",
pgb_good["findings_count"] == 0 and
pgb_good["trust_auth"] is False and
pgb_good["readable_auth_file"] is False, pgb_good)
xi = json.loads(text(by_id[3]))
xi_kinds = {f["id"] for f in xi["findings"]}
check("xinetd_audit flags telnet, any host and root",
{"world-writable", "insecure-service", "no-only-from",
"root-service"} <= xi_kinds, xi)
xi_good = json.loads(text(by_id[4]))
check("xinetd_audit accepts a scoped rsync service",
xi_good["findings_count"] == 0, xi_good)
sssd = json.loads(text(by_id[5]))
sssd_kinds = {f["id"] for f in sssd["findings"]}
check("sssd_audit flags enumeration, cache and weak TLS",
{"world-writable", "enumerate", "cache-credentials", "starttls-off",
"reqcert-weak"} <= sssd_kinds and sssd["enumerate"] is True and
sssd["starttls"] is False, sssd)
sssd_good = json.loads(text(by_id[6]))
check("sssd_audit accepts a hardened domain",
sssd_good["findings_count"] == 0 and
sssd_good["enumerate"] is False and sssd_good["starttls"] is True,
sssd_good)
ftp_tls = json.loads(text(by_id[7]))
check("ftp_tls_probe detects explicit FTPS",
ftp_tls["explicit_ftps"] is True and
ftp_tls["auth_tls_code"] == 234, ftp_tls)
ftp_plain = json.loads(text(by_id[8]))
check("ftp_tls_probe reports a plain FTP server",
ftp_plain["explicit_ftps"] is False and
ftp_plain["auth_tls_code"] == 502, ftp_plain)
check("ftp_tls_probe refuses an out-of-scope target", err(by_id[9]),
text(by_id[9]))
check("pgbouncer_audit reports a missing config", err(by_id[10]),
text(by_id[10]))
check("xinetd_audit reports a missing config", err(by_id[11]),
text(by_id[11]))
check("sssd_audit reports a missing config", err(by_id[12]),
text(by_id[12]))
ftp_tls_srv.close()
ftp_plain_srv.close()
shutil.rmtree(pgb_root, ignore_errors=True)
shutil.rmtree(pgb_good_root, ignore_errors=True)
shutil.rmtree(xi_root, ignore_errors=True)
shutil.rmtree(xi_good_root, ignore_errors=True)
shutil.rmtree(sssd_root, ignore_errors=True)
shutil.rmtree(sssd_good_root, ignore_errors=True)
shutil.rmtree(cfg19_home, ignore_errors=True)
print("\n== esp32 tools ==")
@@ -10243,6 +10411,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()