apex-twin 1.76.0: nscd and faillock audits, GitLab probe
Three new tools, 13 new checks: - nscd_audit (blue): persistent/shared cache, TTL above an hour, world-writable /etc/nscd.conf. - faillock_audit (blue): deny=0 turns the lockout off, a non-zero unlock_time under a minute, missing even_deny_root. unlock_time=0 is strict (counter never cleared) and is not flagged. - gitlab_probe (red): /api/v4/projects decides, /api/v4/version alone answers to anyone; a non-empty project array is the exposure and becomes the evidence. Verification: 339 tools / 1348 checks in make test and test-asan, gate-audit 339 tools, analyze 0 warnings, 240 fuzz cases, distcheck from the 1.76.0 tarball, coverage 84.9 %. Red proof: disabling the unlock_time check turned faillock_audit's check red.
This commit is contained in:
1 parent
022086f474
commit
ecfb18cf97
9 files changed
+572
-12
No files matched your search
@@ -1,5 +1,21 @@
|
||||
# Changelog
|
||||
|
||||
## 1.76.0 - 2026-11-23 - this change
|
||||
|
||||
- **nscd** (`nscd_audit`): `persistent yes` keeps the credential cache on
|
||||
disk across a reboot and `shared yes` exposes one cache to every process;
|
||||
a `positive-time-to-live` above an hour keeps a deleted account resolvable
|
||||
for that long. A world-writable `/etc/nscd.conf` is high.
|
||||
- **faillock** (`faillock_audit`): `deny = 0` switches the account lockout
|
||||
off, a non-zero `unlock_time` under a minute lets a brute force resume
|
||||
almost immediately and a missing `even_deny_root` leaves root exempt.
|
||||
`unlock_time = 0` means the counter is never cleared automatically and is
|
||||
reported as strict, not as weak.
|
||||
- **GitLab** (`gitlab_probe`, red): `/api/v4/version` answers to anyone, so
|
||||
`/api/v4/projects` decides: a 2xx with a non-empty array means public
|
||||
visibility is on and the project list is saved as evidence.
|
||||
- 339 tools, 1348 checks.
|
||||
|
||||
## 1.75.0 — 2026-11-23 — this change
|
||||
|
||||
- **inetd** (`inetd_audit`): an enabled `shell`, `login`, `exec` or `rsh`
|
||||
|
||||
@@ -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.
|
||||
|
||||
**336 tools · 1342 end-to-end checks · 240 fuzz cases · 84.9% line coverage · ~1041 KiB**
|
||||
**339 tools · 1348 end-to-end checks · 240 fuzz cases · 84.9% line coverage · ~1041 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.75.0","tools":336,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.76.0","tools":339,...,"scope":{"loaded":true,...}}
|
||||
```
|
||||
|
||||
APEX TWIN was inspired by [ARTEX](https://github.com/Autumn-27/artex) (scope
|
||||
@@ -1002,6 +1002,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
smtp_auth_probe, jenkins_api_probe, nexus_probe,
|
||||
gitea_api_probe, harbor_probe, portainer_probe, sonarqube_probe,
|
||||
keycloak_probe, rundeck_probe, airflow_probe,
|
||||
gitlab_probe,
|
||||
argocd_probe, kafka_connect_probe
|
||||
src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
|
||||
detect_rules, integrity_baseline, mitre_map,
|
||||
@@ -1015,7 +1016,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
|
||||
pam_env_audit, hosts_audit, dnf_repo_audit,
|
||||
anacrontab_audit, motd_audit,
|
||||
syslog_ng_audit, ntpd_audit, inetd_audit,
|
||||
ld_so_conf_audit, rc_local_audit)
|
||||
ld_so_conf_audit, rc_local_audit, nscd_audit,
|
||||
faillock_audit)
|
||||
src/tools_esp.c esp_info, esp_monitor, esp_read_flash, esp_flash,
|
||||
esp_partition_table, esp_nvs_parse, firmware_scan,
|
||||
esp_app_info, esp_image_verify
|
||||
@@ -1052,7 +1054,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.75.0. Built and run: 336 tools, 1342 checks, 240 fuzz cases and 84.9% line
|
||||
1.76.0. Built and run: 339 tools, 1348 checks, 240 fuzz cases and 84.9% line
|
||||
coverage. The loop closes: a probe captures the exchange as a pair, a finding
|
||||
points at it, `finding_update` gives it a state, an asset records the host it
|
||||
came from, `cors_check`/`cookie_audit`/`http_options` turn a web answer into a
|
||||
|
||||
+1
-1
@@ -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.75.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.76.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
line. The 1.0 line promises that the on-disk JSON formats for findings, assets
|
||||
and traffic only gain fields, so state stays readable; older builds are still
|
||||
rebuilt rather than patched in place.
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-23" "apex-twin 1.75.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-23" "apex-twin 1.76.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, logstash_api_probe, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, airflow_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, amqp_probe, tls_chain_probe, smtp_auth_probe, jenkins_api_probe, nexus_probe, gitea_api_probe, harbor_probe, portainer_probe, argocd_probe, kafka_connect_probe, sonarqube_probe, keycloak_probe, rundeck_probe, airflow_probe, gitlab_probe),
|
||||
defensive
|
||||
audits (hardening_audit, log_audit, ioc_scan, web_log_audit, detect_rules,
|
||||
integrity_baseline, mitre_map, process_snapshot, persistence_audit,
|
||||
@@ -88,7 +88,7 @@ fstab_audit, modprobe_audit, grub_audit,
|
||||
limits_audit, access_conf_audit, pwquality_audit,
|
||||
pam_env_audit, hosts_audit, dnf_repo_audit,
|
||||
anacrontab_audit, motd_audit, syslog_ng_audit, ntpd_audit, inetd_audit,
|
||||
ld_so_conf_audit, rc_local_audit)
|
||||
ld_so_conf_audit, rc_local_audit, nscd_audit, faillock_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.75.0"
|
||||
#define APEX_VERSION "1.76.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -23573,6 +23573,296 @@ static void t_ntpd_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- nscd_audit */
|
||||
|
||||
/* nscd.conf is "attribute database value", one pair per line, with the
|
||||
* attribute optionally tab-aligned. Two attributes apply to every database
|
||||
* and may also stand alone, so a line of three tokens is not guaranteed.
|
||||
* "persistent yes" writes the cache to disk and reads it back after a
|
||||
* restart; "shared yes" lets every process see one cache; a long
|
||||
* positive-time-to-live keeps a removed user resolvable for that long. */
|
||||
struct nscd_state {
|
||||
int persistent;
|
||||
int shared;
|
||||
long max_ttl;
|
||||
char max_ttl_db[32];
|
||||
};
|
||||
|
||||
static void nscd_scan_text(const char *text, struct nscd_state *st)
|
||||
{
|
||||
const char *p = text;
|
||||
|
||||
while (p != NULL && *p != '\0') {
|
||||
const char *eol = strchr(p, '\n');
|
||||
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
|
||||
char line[512];
|
||||
char *tok[16];
|
||||
char *save = NULL;
|
||||
char *word;
|
||||
char *hash;
|
||||
int n = 0;
|
||||
|
||||
if (len >= sizeof(line))
|
||||
len = sizeof(line) - 1;
|
||||
memcpy(line, p, len);
|
||||
line[len] = '\0';
|
||||
p = eol != NULL ? eol + 1 : NULL;
|
||||
hash = strchr(line, '#');
|
||||
if (hash != NULL)
|
||||
*hash = '\0';
|
||||
word = strtok_r(line, " \t", &save);
|
||||
while (word != NULL && n < 16) {
|
||||
tok[n++] = word;
|
||||
word = strtok_r(NULL, " \t", &save);
|
||||
}
|
||||
if (n < 2)
|
||||
continue;
|
||||
if (strcmp(tok[0], "persistent") == 0) {
|
||||
if (strcmp(tok[n - 1], "yes") == 0)
|
||||
st->persistent = 1;
|
||||
} else if (strcmp(tok[0], "shared") == 0) {
|
||||
if (strcmp(tok[n - 1], "yes") == 0)
|
||||
st->shared = 1;
|
||||
} else if (strcmp(tok[0], "positive-time-to-live") == 0 &&
|
||||
n >= 3) {
|
||||
long ttl = strtol(tok[n - 1], NULL, 10);
|
||||
|
||||
if (ttl > st->max_ttl) {
|
||||
st->max_ttl = ttl;
|
||||
snprintf(st->max_ttl_db, sizeof(st->max_ttl_db),
|
||||
"%s", tok[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void t_nscd_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 fs;
|
||||
struct nscd_state st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int read_ok;
|
||||
|
||||
(void)user;
|
||||
st.persistent = 0;
|
||||
st.shared = 0;
|
||||
st.max_ttl = 0;
|
||||
st.max_ttl_db[0] = '\0';
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(path, sizeof(path), "%.400s/etc/nscd.conf", root);
|
||||
read_ok = read_text(path, text, sizeof(text)) > 0;
|
||||
if (read_ok)
|
||||
nscd_scan_text(text, &st);
|
||||
mcp_buf_init(&findings);
|
||||
if (!read_ok) {
|
||||
add_finding(&findings, &first, "no-config", "info",
|
||||
"%s is not readable (nscd not in use)", path);
|
||||
} else {
|
||||
if (stat(path, &fs) == 0 && (fs.st_mode & 0002) != 0)
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"%s is writable by anyone", path);
|
||||
if (st.persistent) {
|
||||
add_finding(&findings, &first, "persistent-cache", "medium",
|
||||
"persistent yes: the cache survives a reboot, "
|
||||
"a removed account stays resolvable");
|
||||
count++;
|
||||
}
|
||||
if (st.shared) {
|
||||
add_finding(&findings, &first, "shared-cache", "low",
|
||||
"shared yes: one cache for every process");
|
||||
count++;
|
||||
}
|
||||
if (st.max_ttl > 3600) {
|
||||
add_finding(&findings, &first, "long-ttl", "medium",
|
||||
"%s keeps entries for %ld s",
|
||||
st.max_ttl_db, st.max_ttl);
|
||||
count++;
|
||||
}
|
||||
if (count == 0) {
|
||||
add_finding(&findings, &first, "no-findings", "info",
|
||||
"the cache is not persistent or shared and keeps "
|
||||
"entries for %ld s", st.max_ttl);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"present\":%s,\"persistent\":%s,\"shared\":%s,"
|
||||
"\"max_ttl\":%ld,\"findings_count\":%d,\"findings\":[",
|
||||
read_ok ? "true" : "false",
|
||||
st.persistent ? "true" : "false",
|
||||
st.shared ? "true" : "false", st.max_ttl, 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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ faillock_audit */
|
||||
|
||||
/* /etc/security/faillock.conf is KEY = VALUE with # comments. The module
|
||||
* defaults are deny=3 and unlock_time=600, so a missing deny is fine while
|
||||
* deny=0 turns the lockout off. unlock_time=0 is NOT weak: it means the
|
||||
* counter is never cleared automatically. Only a short non-zero window
|
||||
* (under a minute) lets a brute force continue almost unimpeded. */
|
||||
struct faillock_state {
|
||||
int deny_seen;
|
||||
long deny;
|
||||
int unlock_seen;
|
||||
long unlock;
|
||||
int even_deny_root;
|
||||
int root_unlock_seen;
|
||||
};
|
||||
|
||||
static void faillock_scan_text(const char *text, struct faillock_state *st)
|
||||
{
|
||||
const char *p = text;
|
||||
|
||||
while (p != NULL && *p != '\0') {
|
||||
const char *eol = strchr(p, '\n');
|
||||
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
|
||||
char line[512];
|
||||
char *eq;
|
||||
|
||||
if (len >= sizeof(line))
|
||||
len = sizeof(line) - 1;
|
||||
memcpy(line, p, len);
|
||||
line[len] = '\0';
|
||||
p = eol != NULL ? eol + 1 : NULL;
|
||||
trim_eol(line);
|
||||
eq = strchr(line, '=');
|
||||
if (eq != NULL) {
|
||||
char *k = line;
|
||||
char *v;
|
||||
char *hash;
|
||||
|
||||
*eq = '\0';
|
||||
v = eq + 1;
|
||||
hash = strchr(v, '#');
|
||||
if (hash != NULL)
|
||||
*hash = '\0';
|
||||
trim_eol(k);
|
||||
while (*v == ' ' || *v == '\t')
|
||||
v++;
|
||||
trim_eol(v);
|
||||
if (strcmp(k, "deny") == 0) {
|
||||
st->deny_seen = 1;
|
||||
st->deny = strtol(v, NULL, 10);
|
||||
} else if (strcmp(k, "unlock_time") == 0) {
|
||||
st->unlock_seen = 1;
|
||||
st->unlock = strtol(v, NULL, 10);
|
||||
} else if (strcmp(k, "root_unlock_time") == 0) {
|
||||
st->root_unlock_seen = 1;
|
||||
}
|
||||
} else {
|
||||
char *hash = strchr(line, '#');
|
||||
char *k = line;
|
||||
|
||||
if (hash != NULL)
|
||||
*hash = '\0';
|
||||
trim_eol(k);
|
||||
if (strcmp(k, "even_deny_root") == 0)
|
||||
st->even_deny_root = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void t_faillock_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 fs;
|
||||
struct faillock_state st;
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
int first = 1;
|
||||
int count = 0;
|
||||
int read_ok;
|
||||
|
||||
(void)user;
|
||||
st.deny_seen = 0;
|
||||
st.deny = 3;
|
||||
st.unlock_seen = 0;
|
||||
st.unlock = 600;
|
||||
st.even_deny_root = 0;
|
||||
st.root_unlock_seen = 0;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) > 400) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(path, sizeof(path), "%.400s/etc/security/faillock.conf", root);
|
||||
read_ok = read_text(path, text, sizeof(text)) > 0;
|
||||
if (read_ok)
|
||||
faillock_scan_text(text, &st);
|
||||
mcp_buf_init(&findings);
|
||||
if (!read_ok) {
|
||||
add_finding(&findings, &first, "no-config", "info",
|
||||
"%s is not readable, module defaults apply (deny=3, "
|
||||
"unlock_time=600)", path);
|
||||
} else {
|
||||
if (stat(path, &fs) == 0 && (fs.st_mode & 0002) != 0)
|
||||
add_finding(&findings, &first, "world-writable", "high",
|
||||
"%s is writable by anyone", path);
|
||||
if (st.deny_seen && st.deny <= 0) {
|
||||
add_finding(&findings, &first, "no-lockout", "high",
|
||||
"deny = %ld disables the account lockout",
|
||||
st.deny);
|
||||
count++;
|
||||
}
|
||||
if (st.unlock_seen && st.unlock > 0 && st.unlock < 60) {
|
||||
add_finding(&findings, &first, "short-unlock", "medium",
|
||||
"unlock_time = %ld s lets a brute force resume "
|
||||
"after a minute", st.unlock);
|
||||
count++;
|
||||
}
|
||||
if (!st.even_deny_root) {
|
||||
add_finding(&findings, &first, "root-exempt", "low",
|
||||
"even_deny_root is not set: root is never locked "
|
||||
"out");
|
||||
count++;
|
||||
}
|
||||
if (count == 0) {
|
||||
add_finding(&findings, &first, "no-findings", "info",
|
||||
"deny = %ld and unlock_time = %ld lock every "
|
||||
"account out, root included", st.deny,
|
||||
st.unlock);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, root);
|
||||
mcp_buf_printf(&b, ",\"present\":%s,\"deny\":%ld,\"unlock_time\":%ld,"
|
||||
"\"even_deny_root\":%s,\"root_unlock_time\":%s,"
|
||||
"\"findings_count\":%d,\"findings\":[",
|
||||
read_ok ? "true" : "false", st.deny, st.unlock,
|
||||
st.even_deny_root ? "true" : "false",
|
||||
st.root_unlock_seen ? "true" : "false", count);
|
||||
if (findings.p != NULL)
|
||||
mcp_buf_add(&b, findings.p, findings.len);
|
||||
mcp_buf_puts(&b, "]}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_BLUE[] = {
|
||||
{ "hardening_audit",
|
||||
"Read-only posture audit of the local host: sshd_config (root login, "
|
||||
@@ -24324,6 +24614,20 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_pgbouncer_audit },
|
||||
{ "nscd_audit",
|
||||
"Parse /etc/nscd.conf (root prefix): persistent or shared cache, a "
|
||||
"positive-time-to-live above an hour and a world-writable file. "
|
||||
"Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_nscd_audit },
|
||||
{ "faillock_audit",
|
||||
"Parse /etc/security/faillock.conf (root prefix): deny=0 (lockout off), "
|
||||
"a non-zero unlock_time under a minute, a missing even_deny_root and a "
|
||||
"world-writable file. unlock_time=0 counts as strict. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_faillock_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 "
|
||||
|
||||
+101
@@ -8375,6 +8375,96 @@ static void t_airflow_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- gitlab_probe */
|
||||
|
||||
/* GitLab answers /api/v4/version to anyone, so a 2xx there is only a hint.
|
||||
* /api/v4/projects is the real test: on a private instance it answers 401,
|
||||
* while an instance with public visibility returns the project list. The
|
||||
* list becomes the evidence. GitLab listens on 80/443, not on 8080. */
|
||||
static void t_gitlab_probe(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *paths[] = { "/api/v4/version", "/api/v4/projects", NULL };
|
||||
const char *target = mcp_arg_string(args, "target");
|
||||
int port = mcp_arg_int(args, "port", 443);
|
||||
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 projects_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, "gitlab_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 projects = strcmp(paths[i], "/api/v4/projects") == 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;
|
||||
/* An empty JSON array is a valid answer but no exposure. */
|
||||
if (open && projects && len >= 2 && resp[0] == '[' &&
|
||||
resp[1] == ']')
|
||||
open = 0;
|
||||
if (open)
|
||||
open_count++;
|
||||
if (open && projects) {
|
||||
projects_open = 1;
|
||||
if (evidence == NULL)
|
||||
evidence = apex_evidence_save("gitlab-projects", 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,"
|
||||
"\"projects_open\":%s,\"evidence\":",
|
||||
tested, open_count, projects_open ? "true" : "false");
|
||||
if (evidence != NULL)
|
||||
apex_json_str(&b, evidence);
|
||||
else
|
||||
mcp_buf_puts(&b, "null");
|
||||
mcp_buf_puts(&b, "}");
|
||||
apex_audit("gitlab_probe", target, port, !projects_open,
|
||||
projects_open
|
||||
? "the GitLab project API answers without authentication"
|
||||
: "the GitLab project API requires authentication", "list");
|
||||
mcp_reply_json(c, b.p);
|
||||
free(evidence);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ sonarqube_probe */
|
||||
|
||||
/* SonarQube answers /api/system/status even when anonymous access is off, so
|
||||
@@ -9598,6 +9688,17 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 8080\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_airflow_probe },
|
||||
{ "gitlab_probe",
|
||||
"Query the GitLab API (default 443) without a token: /api/v4/version "
|
||||
"and /api/v4/projects. A 2xx on the project list means public "
|
||||
"visibility is on and the list is saved as evidence. An empty array "
|
||||
"counts as not open.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"},"
|
||||
"\"tls\":{\"type\":\"boolean\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_gitlab_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 = 336
|
||||
EXPECTED_TOOLS = 339
|
||||
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.
|
||||
|
||||
+139
-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("336 tools registered", len(tools) == 336, len(tools))
|
||||
check("339 tools registered", len(tools) == 339, 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"]) == 336)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 339)
|
||||
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
|
||||
@@ -15376,6 +15376,143 @@ for d in (idt_root, idt_good_root, lds_root, lds_good_root, rcl_root,
|
||||
rcl_good_root, cfg47_home):
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
print("\n== nscd, faillock and GitLab ==")
|
||||
|
||||
nscd_root = tempfile.mkdtemp(prefix="apex-nscd-")
|
||||
os.makedirs(os.path.join(nscd_root, "etc"))
|
||||
nscd_conf = os.path.join(nscd_root, "etc", "nscd.conf")
|
||||
with open(nscd_conf, "w") as f:
|
||||
f.write("persistent\tyes\n")
|
||||
f.write("\tpositive-time-to-live\tpasswd\t7200\n")
|
||||
f.write("\tshared\tyes\n")
|
||||
os.chmod(nscd_conf, 0o666)
|
||||
nscd_good_root = tempfile.mkdtemp(prefix="apex-nscdg-")
|
||||
os.makedirs(os.path.join(nscd_good_root, "etc"))
|
||||
with open(os.path.join(nscd_good_root, "etc", "nscd.conf"), "w") as f:
|
||||
f.write("persistent\tno\n")
|
||||
f.write("\tpositive-time-to-live\tpasswd\t600\n")
|
||||
|
||||
fl_root = tempfile.mkdtemp(prefix="apex-fl-")
|
||||
os.makedirs(os.path.join(fl_root, "etc", "security"))
|
||||
fl_conf = os.path.join(fl_root, "etc", "security", "faillock.conf")
|
||||
with open(fl_conf, "w") as f:
|
||||
f.write("deny = 0\n")
|
||||
f.write("unlock_time = 30\n")
|
||||
f.write("# even_deny_root fehlt\n")
|
||||
os.chmod(fl_conf, 0o666)
|
||||
fl_good_root = tempfile.mkdtemp(prefix="apex-flg-")
|
||||
os.makedirs(os.path.join(fl_good_root, "etc", "security"))
|
||||
with open(os.path.join(fl_good_root, "etc", "security", "faillock.conf"),
|
||||
"w") as f:
|
||||
f.write("deny = 5\n")
|
||||
f.write("unlock_time = 0\n")
|
||||
f.write("even_deny_root\n")
|
||||
f.write("root_unlock_time = 1200\n")
|
||||
|
||||
class _GitLabHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/api/v4/version":
|
||||
body = b'{"version":"16.5.2","revision":"a1b2c3"}'
|
||||
self.send_response(200)
|
||||
elif path == "/api/v4/projects":
|
||||
body = b'[{"id":1,"path_with_namespace":"ops/deploy"},' \
|
||||
b'{"id":2,"path_with_namespace":"lab/secret"}]'
|
||||
self.send_response(200)
|
||||
else:
|
||||
body = b'{"message":"404 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 _GitLabClosedHandler(_GitLabHandler):
|
||||
def do_GET(self):
|
||||
path = urllib.parse.urlsplit(self.path).path
|
||||
if path == "/api/v4/version":
|
||||
body = b'{"version":"16.5.2"}'
|
||||
self.send_response(200)
|
||||
elif path == "/api/v4/projects":
|
||||
body = b'{"message":"401 Unauthorized"}'
|
||||
self.send_response(401)
|
||||
else:
|
||||
body = b'{"message":"404 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)
|
||||
|
||||
|
||||
gl_srv = http.server.HTTPServer(("127.0.0.1", 0), _GitLabHandler)
|
||||
gl_port = gl_srv.server_address[1]
|
||||
threading.Thread(target=gl_srv.serve_forever, daemon=True).start()
|
||||
gl_closed_srv = http.server.HTTPServer(("127.0.0.1", 0), _GitLabClosedHandler)
|
||||
gl_closed_port = gl_closed_srv.server_address[1]
|
||||
threading.Thread(target=gl_closed_srv.serve_forever, daemon=True).start()
|
||||
|
||||
cfg48_home = tempfile.mkdtemp(prefix="apex-cfg48-home-")
|
||||
write_scope(cfg48_home,
|
||||
{"label": "cfg48", "expires": "2099-01-01T00:00:00Z",
|
||||
"allow_private": True,
|
||||
"allow_ip": ["127.0.0.1/32"], "allow_port": ["1-65535"]})
|
||||
|
||||
res, proc = run([
|
||||
call(1, "nscd_audit", root=nscd_root),
|
||||
call(2, "nscd_audit", root=nscd_good_root),
|
||||
call(3, "faillock_audit", root=fl_root),
|
||||
call(4, "faillock_audit", root=fl_good_root),
|
||||
call(5, "gitlab_probe", target="127.0.0.1", port=gl_port, tls=False),
|
||||
call(6, "gitlab_probe", target="127.0.0.1", port=gl_closed_port, tls=False),
|
||||
], home=cfg48_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
|
||||
nscd = json.loads(text(by_id[1]))
|
||||
nscd_kinds = {f["id"] for f in nscd["findings"]}
|
||||
check("nscd_audit flags persistent cache, shared cache and a long TTL",
|
||||
{"persistent-cache", "shared-cache", "long-ttl",
|
||||
"world-writable"} <= nscd_kinds and
|
||||
nscd["persistent"] is True and nscd["shared"] is True and
|
||||
nscd["max_ttl"] == 7200, nscd)
|
||||
nscd_good = json.loads(text(by_id[2]))
|
||||
check("nscd_audit accepts a non-persistent cache with a short TTL",
|
||||
nscd_good["persistent"] is False and nscd_good["max_ttl"] == 600 and
|
||||
{f["id"] for f in nscd_good["findings"]} == {"no-findings"}, nscd_good)
|
||||
|
||||
fl = json.loads(text(by_id[3]))
|
||||
fl_kinds = {f["id"] for f in fl["findings"]}
|
||||
check("faillock_audit flags deny=0, a short unlock window and a missing "
|
||||
"even_deny_root",
|
||||
{"no-lockout", "short-unlock", "root-exempt",
|
||||
"world-writable"} <= fl_kinds and
|
||||
fl["deny"] == 0 and fl["unlock_time"] == 30 and
|
||||
fl["even_deny_root"] is False, fl)
|
||||
fl_good = json.loads(text(by_id[4]))
|
||||
check("faillock_audit accepts unlock_time=0 as strict",
|
||||
fl_good["deny"] == 5 and fl_good["unlock_time"] == 0 and
|
||||
fl_good["even_deny_root"] is True and
|
||||
{f["id"] for f in fl_good["findings"]} == {"no-findings"}, fl_good)
|
||||
|
||||
gl = json.loads(text(by_id[5]))
|
||||
check("gitlab_probe finds an open project API and saves the list",
|
||||
gl["projects_open"] is True and gl["open_count"] == 2 and
|
||||
os.path.isfile(gl["evidence"]), gl)
|
||||
gl_closed = json.loads(text(by_id[6]))
|
||||
check("gitlab_probe reports a closed project API as not open",
|
||||
gl_closed["projects_open"] is False and
|
||||
gl_closed["open_count"] == 1, gl_closed)
|
||||
|
||||
gl_srv.shutdown()
|
||||
gl_closed_srv.shutdown()
|
||||
|
||||
for d in (nscd_root, nscd_good_root, fl_root, fl_good_root, cfg48_home):
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
|
||||
print("%d passed, %d failed" % (passes, len(fails)))
|
||||
if fails:
|
||||
print("failed: " + ", ".join(fails))
|
||||
|
||||
Reference in new issue
Block a user