apex-twin 1.77.0: networkd, pam_namespace and SSH client audits

Three blue config audits, no new red tool (memcached_probe already existed
in tools_db.c and a duplicate registration was caught and removed):

- networkd_audit: /etc/systemd/network/*.network, *.netdev, *.link - a
  [Match] without Name=/MACAddress=/Type=/Path=/Driver= applies to every
  interface; DHCP=yes with IPv6AcceptRA=yes and no UseDNS=no lets DHCP and
  RA pick the resolver; DNS= with a public resolver; world-writable unit.
- namespace_audit: /etc/security/namespace.conf - no /tmp, /var/tmp or
  /dev/shm entry (shared tmp), empty or unknown method field, user list
  starting with "~" (isolation only for the listed users), world-writable.
- ssh_client_audit: /etc/ssh/ssh_config plus ssh_config.d/*.conf -
  StrictHostKeyChecking no, UserKnownHostsFile /dev/null or none,
  GlobalKnownHostsFile none, ssh-rsa/ssh-dss in the algorithm lists.
  ssh_config_audit reads only the server side.

Test evidence: make test 1354/1354, test-asan 1354/1354, analyze 0 warnings,
fuzz 240 cases, coverage 85.0%, release-check exit 0 including distcheck of
apex-twin-1.77.0. Red proof: disabling the DHCP= branch in networkd_scan_file
turned the networkd check red, then rolled back.
This commit is contained in:
lotherk committed 2026-11-23 00:13:27 +00:00
1 parent ecfb18cf97
commit e1703cfa4d
8 files changed
+702 -11

No files matched your search

+19
View File
@@ -1,5 +1,24 @@
# Changelog
## 1.77.0 — 2026-11-23 — this change
- **systemd-networkd** (`networkd_audit`): a `[Match]` section without
`Name=`, `MACAddress=`, `Type=`, `Path=` or `Driver=` applies to every
interface; `DHCP=yes` together with `IPv6AcceptRA=yes` and no `UseDNS=no`
lets the DHCP server and the router choose the resolver; a `DNS=` with a
public resolver sends every query outside. A world-writable unit is high.
- **pam_namespace** (`namespace_audit`): no `/tmp`, `/var/tmp` or `/dev/shm`
entry means every session shares one temporary directory; a missing or
unknown method field makes the module fall back to its defaults; a user
list that starts with `~` isolates only the listed users. A world-writable
`namespace.conf` is high.
- **SSH client** (`ssh_client_audit`): `ssh_config` and `ssh_config.d` —
`StrictHostKeyChecking no`, `UserKnownHostsFile /dev/null` or
`GlobalKnownHostsFile none` remove the host key check, and `ssh-rsa` or
`ssh-dss` in the algorithm lists re-enable the weak signature schemes.
`ssh_config_audit` only reads the server side.
- 342 tools, 1354 checks.
## 1.76.0 - 2026-11-23 - this change
- **nscd** (`nscd_audit`): `persistent yes` keeps the credential cache on
+7 -3
View File
@@ -5,7 +5,7 @@ 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.
**339 tools · 1348 end-to-end checks · 240 fuzz cases · 84.9% line coverage · ~1041 KiB**
**342 tools · 1354 end-to-end checks · 240 fuzz cases · 85.0% line coverage · ~1041 KiB**
```
$ ./apex-twin --check
@@ -524,6 +524,9 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `inetd_audit` | inetd.conf: shell services, legacy cleartext daemons, writable file |
| `ld_so_conf_audit` | ld.so.conf: user-writable library path, world-writable dir |
| `rc_local_audit` | rc.local: remote pipe, /tmp reference, missing exit |
| `networkd_audit` | systemd-networkd: [Match] without Name/MAC/Type, DHCP DNS without UseDNS=no, public resolver |
| `namespace_audit` | namespace.conf: no /tmp entry, empty/unknown method, `~` user list |
| `ssh_client_audit` | ssh_config: StrictHostKeyChecking no, known_hosts /dev/null, ssh-rsa |
| `podman_audit` | registries.conf: insecure or http registry, unsigned policy |
| `buildkitd_audit` | buildkitd.toml: insecure registry, tcp without CA, no rootless |
| `supervisor_audit` | supervisord.conf: exposed web UI, no username, root programs |
@@ -1017,7 +1020,8 @@ src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
anacrontab_audit, motd_audit,
syslog_ng_audit, ntpd_audit, inetd_audit,
ld_so_conf_audit, rc_local_audit, nscd_audit,
faillock_audit)
faillock_audit, networkd_audit, namespace_audit,
ssh_client_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
@@ -1054,7 +1058,7 @@ examples/ scope.json
## Status
1.76.0. Built and run: 339 tools, 1348 checks, 240 fuzz cases and 84.9% line
1.77.0. Built and run: 342 tools, 1354 checks, 240 fuzz cases and 85.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
+1 -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.76.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.77.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 -2
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-23" "apex-twin 1.76.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-23" "apex-twin 1.77.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
@@ -88,7 +88,8 @@ 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, nscd_audit, faillock_audit)
ld_so_conf_audit, rc_local_audit, nscd_audit, faillock_audit,
networkd_audit, namespace_audit, ssh_client_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.76.0"
#define APEX_VERSION "1.77.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+555
View File
@@ -23781,6 +23781,534 @@ static void faillock_scan_text(const char *text, struct faillock_state *st)
}
}
/* ------------------------------------------------------------- networkd_audit */
/* systemd-networkd reads one file per link. Three things matter here: a
* [Match] with no Name=, MACAddress= or Type= matches every interface at once,
* a wildcard and DHCP=yes puts every card on the network unattended, a DNS
* server taken from DHCP runs whatever the DHCP server says, and a public
* resolver in [Network] moves every query to a third party. */
struct networkd_state {
int files;
int wildcard_match;
int dhcp_no_usedns;
int public_dns;
};
static int nd_public_dns(const char *v)
{
static const char *known[] = { "8.8.8.8", "8.8.4.4", "1.1.1.1",
"1.0.0.1", "9.9.9.9", "149.112.112.112",
"208.67.222.222", "208.67.220.220",
"64.6.64.6", "77.88.8.8", NULL };
int i;
for (i = 0; known[i] != NULL; i++)
if (strcmp(v, known[i]) == 0)
return 1;
return 0;
}
static void networkd_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, struct networkd_state *st)
{
static char text[65536];
char current[64];
char dns[512];
int has_match = 0;
int match_specific = 0;
int dhcp = 0;
int usedns_off = 0;
int ra = 0;
const char *p = text;
if (read_text(path, text, sizeof(text)) <= 0)
return;
st->files++;
{
struct stat fs;
if (stat(path, &fs) == 0 && (fs.st_mode & 0002) != 0) {
add_finding(findings, first, "world-writable", "high",
"%s is writable by anyone", path);
(*count)++;
}
}
current[0] = '\0';
dns[0] = '\0';
while (p != NULL && *p != '\0') {
const char *eol = strchr(p, '\n');
size_t len = eol != NULL ? (size_t)(eol - p) : strlen(p);
char line[1024];
char *s;
if (len >= sizeof(line))
len = sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
s = line;
while (*s == ' ' || *s == '\t')
s++;
if (*s == '[') {
char *close = strchr(s, ']');
current[0] = '\0';
if (close != NULL) {
size_t cl = (size_t)(close - s - 1);
if (cl >= sizeof(current))
cl = sizeof(current) - 1;
memcpy(current, s + 1, cl);
current[cl] = '\0';
}
if (strcmp(current, "Match") == 0)
has_match = 1;
} else if (*s != '#' && *s != ';' && *s != '\0') {
char *eq = strchr(s, '=');
if (eq != NULL) {
char *k = s;
char *v;
size_t ke;
*eq = '\0';
ke = strlen(k);
while (ke > 0 && (k[ke - 1] == ' ' ||
k[ke - 1] == '\t'))
k[--ke] = '\0';
v = eq + 1;
while (*v == ' ' || *v == '\t')
v++;
trim_eol(v);
if (strcmp(current, "Match") == 0 &&
(strcmp(k, "Name") == 0 ||
strcmp(k, "MACAddress") == 0 ||
strcmp(k, "Type") == 0 ||
strcmp(k, "Path") == 0 ||
strcmp(k, "Driver") == 0))
match_specific = 1;
if (strcmp(current, "Network") == 0 &&
strcmp(k, "DHCP") == 0 &&
strcasecmp(v, "no") != 0 &&
strcasecmp(v, "false") != 0 &&
strcasecmp(v, "off") != 0)
dhcp = 1;
if (strcmp(current, "Network") == 0 &&
strcmp(k, "IPv6AcceptRA") == 0 &&
strcasecmp(v, "yes") == 0)
ra = 1;
if (strcmp(current, "Network") == 0 &&
strcmp(k, "DNS") == 0)
snprintf(dns, sizeof(dns), "%s", v);
if ((strcmp(current, "DHCPv4") == 0 ||
strcmp(current, "DHCPv6") == 0 ||
strcmp(current, "IPv6AcceptRA") == 0) &&
strcmp(k, "UseDNS") == 0 &&
strcasecmp(v, "no") == 0)
usedns_off = 1;
}
}
p = eol != NULL ? eol + 1 : NULL;
}
if (has_match && !match_specific) {
add_finding(findings, first, "match-all", "medium",
"%s has a [Match] without Name=, MACAddress= or "
"Type=: it applies to every interface", path);
(*count)++;
st->wildcard_match++;
}
if (dhcp && !usedns_off && ra) {
add_finding(findings, first, "dhcp-dns", "low",
"%s takes DNS from DHCP and RA without UseDNS=no: "
"the DHCP server chooses the resolver", path);
(*count)++;
st->dhcp_no_usedns++;
}
if (dns[0] != '\0' && nd_public_dns(dns)) {
add_finding(findings, first, "public-dns", "low",
"%s sends every query to the public resolver %s",
path, dns);
(*count)++;
st->public_dns++;
}
}
static void t_networkd_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
DIR *d;
struct dirent *ent;
struct networkd_state st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int opened = 0;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
mcp_buf_init(&findings);
snprintf(path, sizeof(path), "%.400s/etc/systemd/network", root);
d = opendir(path);
if (d != NULL) {
opened = 1;
while ((ent = readdir(d)) != NULL) {
char file[1200];
const char *dot;
struct stat fs;
if (ent->d_name[0] == '.')
continue;
dot = strrchr(ent->d_name, '.');
if (dot == NULL ||
(strcmp(dot, ".network") != 0 &&
strcmp(dot, ".netdev") != 0 &&
strcmp(dot, ".link") != 0))
continue;
snprintf(file, sizeof(file), "%.800s/%.200s", path,
ent->d_name);
if (stat(file, &fs) != 0 || !S_ISREG(fs.st_mode))
continue;
networkd_scan_file(&findings, &first, &count, file,
&st);
}
closedir(d);
}
if (!opened) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read /etc/systemd/network");
return;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"match_all\":%d,"
"\"dhcp_dns\":%d,\"public_dns\":%d,"
"\"findings_count\":%d,\"findings\":[",
st.files, st.wildcard_match, st.dhcp_no_usedns,
st.public_dns, 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);
}
/* ------------------------------------------------------------ namespace_audit */
/* namespace.conf: "polydir instance_prefix method [uids]". pam_namespace
* bind-mounts an instance of polydir for each session; the method decides how
* the instance is named. Nothing polyinstantiated means every session shares
* one /tmp. A method field that is missing or unknown makes the module fall
* back to defaults, and a "~" list turns the feature around: only the listed
* users get isolation. */
struct ns_state {
int entries;
int tmp_covered;
int shared_tmp;
int empty_method;
int restricted_only;
int unknown_method;
};
static int ns_tmp_dir(const char *dir)
{
return strcmp(dir, "/tmp") == 0 || strcmp(dir, "/var/tmp") == 0 ||
strcmp(dir, "/dev/shm") == 0;
}
static int ns_known_method(const char *m)
{
return strcmp(m, "user") == 0 || strcmp(m, "level") == 0 ||
strcmp(m, "context") == 0 || strcmp(m, "tmpfs") == 0 ||
strcmp(m, "tmpdir") == 0;
}
static void namespace_scan_text(const char *text, struct ns_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[1024];
char *tok[8];
int nt = 0;
char *save = NULL;
char *word;
char *hash;
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';
for (word = strtok_r(line, " \t", &save); word != NULL;
word = strtok_r(NULL, " \t", &save)) {
if (nt < (int)(sizeof(tok) / sizeof(tok[0])))
tok[nt++] = word;
}
if (nt == 0)
continue;
st->entries++;
if (ns_tmp_dir(tok[0]))
st->tmp_covered = 1;
if (nt < 3 || tok[2][0] == '\0') {
st->empty_method++;
continue;
}
if (!ns_known_method(tok[2]))
st->unknown_method++;
if (nt >= 4 && tok[3][0] == '~')
st->restricted_only++;
}
}
static void t_namespace_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 ns_state st;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int read_ok;
(void)user;
if (root == NULL)
root = "";
if (strlen(root) > 400) {
mcp_reply_error(c, "root path too long");
return;
}
memset(&st, 0, sizeof(st));
snprintf(path, sizeof(path), "%.400s/etc/security/namespace.conf",
root);
read_ok = read_text(path, text, sizeof(text)) > 0;
if (read_ok)
namespace_scan_text(text, &st);
mcp_buf_init(&findings);
if (!read_ok) {
add_finding(&findings, &first, "no-config", "info",
"%s is not readable: pam_namespace does not isolate "
"any directory", 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);
count++;
}
if (!st.tmp_covered) {
add_finding(&findings, &first, "shared-tmp", "medium",
"no /tmp, /var/tmp or /dev/shm entry: every "
"session shares one temporary directory");
count++;
st.shared_tmp = 1;
}
if (st.empty_method > 0) {
add_finding(&findings, &first, "empty-method", "high",
"%d entry/entries have no method field, "
"pam_namespace falls back to its defaults",
st.empty_method);
count++;
}
if (st.unknown_method > 0) {
add_finding(&findings, &first, "unknown-method",
"medium",
"%d entry/entries use a method that is not "
"user, level, context, tmpfs or tmpdir",
st.unknown_method);
count++;
}
if (st.restricted_only > 0) {
add_finding(&findings, &first, "restricted-only",
"medium",
"%d entry/entries start the user list with "
"~: only the listed users are isolated",
st.restricted_only);
count++;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"%d entries isolate every session, all "
"methods are known", st.entries);
count++;
}
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"present\":%s,\"entries\":%d,"
"\"tmp_covered\":%s,\"shared_tmp\":%s,"
"\"empty_method\":%d,"
"\"restricted_only\":%d,\"findings_count\":%d,"
"\"findings\":[",
read_ok ? "true" : "false", st.entries,
st.tmp_covered ? "true" : "false",
st.shared_tmp ? "true" : "false", st.empty_method,
st.restricted_only, 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);
}
/* ---------------------------------------------------------- ssh_client_audit */
/* ssh_config is the client side: ssh_config_audit only reads sshd_config.
* StrictHostKeyChecking=no and a known_hosts of /dev/null remove the host key
* check entirely, so every later connection accepts whatever key answers.
* ssh-rsa and ssh-dss in the algorithm lists re-enable the weak signatures. */
static void sshc_scan_file(mcp_buf *findings, int *first, int *count,
const char *path, int *files, int *no_check,
int *no_known_hosts, int *weak_algo)
{
static char text[65536];
char value[512];
struct stat fs;
if (read_text(path, text, sizeof(text)) <= 0)
return;
(*files)++;
if (stat(path, &fs) == 0 && (fs.st_mode & 0002) != 0) {
add_finding(findings, first, "world-writable", "high",
"%s is writable by anyone", path);
(*count)++;
}
if (sshd_value(text, "StrictHostKeyChecking", value, sizeof(value)) &&
(strcasecmp(value, "no") == 0 ||
strcasecmp(value, "off") == 0 ||
strcasecmp(value, "false") == 0)) {
add_finding(findings, first, "no-host-key-check", "high",
"%s sets StrictHostKeyChecking %s: a changed host "
"key is accepted without a question", path, value);
(*count)++;
(*no_check)++;
}
if (sshd_value(text, "UserKnownHostsFile", value, sizeof(value))) {
if (strstr(value, "/dev/null") != NULL ||
strcasecmp(value, "none") == 0) {
add_finding(findings, first, "known-hosts-off",
"high",
"%s points UserKnownHostsFile at %s: nothing "
"is remembered", path, value);
(*count)++;
(*no_known_hosts)++;
}
}
if (sshd_value(text, "GlobalKnownHostsFile", value,
sizeof(value)) &&
strcasecmp(value, "none") == 0) {
add_finding(findings, first, "known-hosts-off", "high",
"%s sets GlobalKnownHostsFile none", path);
(*count)++;
(*no_known_hosts)++;
}
if ((sshd_value(text, "HostKeyAlgorithms", value, sizeof(value)) ||
sshd_value(text, "PubkeyAcceptedKeyTypes", value,
sizeof(value)) ||
sshd_value(text, "PubkeyAcceptedAlgorithms", value,
sizeof(value))) &&
(strstr(value, "ssh-rsa") != NULL ||
strstr(value, "ssh-dss") != NULL)) {
add_finding(findings, first, "weak-algorithm", "medium",
"%s still offers ssh-rsa/ssh-dss (%s)", path,
value);
(*count)++;
(*weak_algo)++;
}
}
static void t_ssh_client_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char path[1024];
char dir[1024];
DIR *d;
struct dirent *ent;
mcp_buf b;
mcp_buf findings;
int first = 1;
int count = 0;
int files = 0;
int no_check = 0;
int no_known_hosts = 0;
int weak_algo = 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), "%.400s/etc/ssh/ssh_config", root);
sshc_scan_file(&findings, &first, &count, path, &files, &no_check,
&no_known_hosts, &weak_algo);
snprintf(dir, sizeof(dir), "%.400s/etc/ssh/ssh_config.d", root);
d = opendir(dir);
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char file[1200];
struct stat fs;
if (ent->d_name[0] == '.')
continue;
if (strstr(ent->d_name, ".conf") == NULL)
continue;
snprintf(file, sizeof(file), "%.800s/%.200s", dir,
ent->d_name);
if (stat(file, &fs) != 0 || !S_ISREG(fs.st_mode))
continue;
sshc_scan_file(&findings, &first, &count, file,
&files, &no_check, &no_known_hosts,
&weak_algo);
}
closedir(d);
}
if (files == 0) {
mcp_buf_free(&findings);
mcp_reply_error(c, "cannot read ssh client configuration");
return;
}
if (count == 0) {
add_finding(&findings, &first, "no-findings", "info",
"host keys are checked and no weak algorithm is "
"enabled");
count++;
}
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, root);
mcp_buf_printf(&b, ",\"files\":%d,\"no_host_key_check\":%d,"
"\"known_hosts_off\":%d,\"weak_algorithm\":%d,"
"\"findings_count\":%d,\"findings\":[",
files, no_check, no_known_hosts, weak_algo, 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);
}
static void t_faillock_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
@@ -24628,6 +25156,33 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_faillock_audit },
{ "networkd_audit",
"Parse /etc/systemd/network/*.network, *.netdev and *.link (root "
"prefix): a [Match] without Name=, MACAddress= or Type= that applies "
"to every interface, DHCP with IPv6AcceptRA and no UseDNS=no, a "
"[Network] DNS= pointing at a public resolver, and world-writable "
"files. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_networkd_audit },
{ "namespace_audit",
"Parse /etc/security/namespace.conf (root prefix): no entry for /tmp, "
"/var/tmp or /dev/shm (every session shares one temporary directory), "
"an entry without a method field, an unknown method, a user list "
"starting with ~ (only those users are isolated) and a world-writable "
"file. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_namespace_audit },
{ "ssh_client_audit",
"Parse /etc/ssh/ssh_config and ssh_config.d/*.conf (root prefix): "
"StrictHostKeyChecking no, UserKnownHostsFile /dev/null or none, "
"GlobalKnownHostsFile none, ssh-rsa/ssh-dss in the host key or pubkey "
"algorithm lists and world-writable files. The client side of "
"ssh_config_audit. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_ssh_client_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 "
+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 = 339
EXPECTED_TOOLS = 342
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.
+115 -3
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("339 tools registered", len(tools) == 339, len(tools))
check("342 tools registered", len(tools) == 342, 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"]) == 339)
check("http tools/list", len(listing["result"]["tools"]) == 342)
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
@@ -15449,6 +15449,62 @@ class _GitLabClosedHandler(_GitLabHandler):
self.wfile.write(body)
nd_root = tempfile.mkdtemp(prefix="apex-nd-")
os.makedirs(os.path.join(nd_root, "etc", "systemd", "network"))
nd_bad = os.path.join(nd_root, "etc", "systemd", "network",
"20-wan.network")
with open(nd_bad, "w") as f:
f.write("[Match]\n")
f.write("[Network]\n")
f.write("DHCP=yes\n")
f.write("IPv6AcceptRA=yes\n")
f.write("DNS=8.8.8.8\n")
os.chmod(nd_bad, 0o666)
with open(os.path.join(nd_root, "etc", "systemd", "network",
"10-lo.netdev"), "w") as f:
f.write("[NetDev]\nName=dummy0\nKind=dummy\n")
nd_good_root = tempfile.mkdtemp(prefix="apex-ndg-")
os.makedirs(os.path.join(nd_good_root, "etc", "systemd", "network"))
with open(os.path.join(nd_good_root, "etc", "systemd", "network",
"20-wan.network"), "w") as f:
f.write("[Match]\nName=eth0\n")
f.write("[Network]\nDHCP=yes\nIPv6AcceptRA=yes\n")
f.write("DNS=127.0.0.1\n")
f.write("[DHCPv4]\nUseDNS=no\n")
ns_root = tempfile.mkdtemp(prefix="apex-ns-")
os.makedirs(os.path.join(ns_root, "etc", "security"))
ns_conf = os.path.join(ns_root, "etc", "security", "namespace.conf")
with open(ns_conf, "w") as f:
f.write("/tmp /tmp-inst user ~alice\n")
f.write("/var/tmp /var-tmp bogus\n")
f.write("/home /home-inst\n")
os.chmod(ns_conf, 0o666)
ns_good_root = tempfile.mkdtemp(prefix="apex-nsg-")
os.makedirs(os.path.join(ns_good_root, "etc", "security"))
with open(os.path.join(ns_good_root, "etc", "security",
"namespace.conf"), "w") as f:
f.write("/tmp /tmp-inst level\n")
f.write("/var/tmp /var-tmp user\n")
sc_root = tempfile.mkdtemp(prefix="apex-sc-")
os.makedirs(os.path.join(sc_root, "etc", "ssh", "ssh_config.d"))
sc_bad = os.path.join(sc_root, "etc", "ssh", "ssh_config")
with open(sc_bad, "w") as f:
f.write("Host *\n")
f.write(" StrictHostKeyChecking no\n")
f.write(" UserKnownHostsFile /dev/null\n")
f.write(" HostKeyAlgorithms +ssh-rsa\n")
os.chmod(sc_bad, 0o666)
with open(os.path.join(sc_root, "etc", "ssh", "ssh_config.d",
"10-lab.conf"), "w") as f:
f.write("Host lab\n GlobalKnownHostsFile none\n")
sc_good_root = tempfile.mkdtemp(prefix="apex-scg-")
os.makedirs(os.path.join(sc_good_root, "etc", "ssh"))
with open(os.path.join(sc_good_root, "etc", "ssh", "ssh_config"),
"w") as f:
f.write("Host *\n StrictHostKeyChecking ask\n")
f.write(" UserKnownHostsFile ~/.ssh/known_hosts\n")
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()
@@ -15456,6 +15512,22 @@ 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()
cfg49_home = tempfile.mkdtemp(prefix="apex-cfg49-home-")
write_scope(cfg49_home,
{"label": "cfg49", "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, "networkd_audit", root=nd_root),
call(2, "networkd_audit", root=nd_good_root),
call(3, "namespace_audit", root=ns_root),
call(4, "namespace_audit", root=ns_good_root),
call(5, "ssh_client_audit", root=sc_root),
call(6, "ssh_client_audit", root=sc_good_root),
], home=cfg49_home)
b49 = {r.get("id"): text(r) for r in res}
cfg48_home = tempfile.mkdtemp(prefix="apex-cfg48-home-")
write_scope(cfg48_home,
{"label": "cfg48", "expires": "2099-01-01T00:00:00Z",
@@ -15498,6 +15570,44 @@ check("faillock_audit accepts unlock_time=0 as strict",
fl_good["even_deny_root"] is True and
{f["id"] for f in fl_good["findings"]} == {"no-findings"}, fl_good)
nd = json.loads(b49[1])
nd_kinds = {f["id"] for f in nd["findings"]}
check("networkd_audit flags a match-all unit, DHCP DNS and a writable file",
{"match-all", "dhcp-dns", "public-dns", "world-writable"} <= nd_kinds
and nd["files"] == 2 and nd["match_all"] == 1 and
nd["dhcp_dns"] == 1 and nd["public_dns"] == 1, nd)
nd_good = json.loads(b49[2])
check("networkd_audit accepts a named interface with UseDNS=no",
nd_good["findings_count"] == 0 and nd_good["match_all"] == 0 and
nd_good["dhcp_dns"] == 0 and nd_good["public_dns"] == 0, nd_good)
ns = json.loads(b49[3])
ns_kinds = {f["id"] for f in ns["findings"]}
check("namespace_audit flags a writable file, an unknown method and a "
"restricted user list",
{"world-writable", "unknown-method", "restricted-only"} <= ns_kinds
and ns["present"] is True and ns["entries"] == 3 and
ns["tmp_covered"] is True and ns["restricted_only"] == 1, ns)
ns_good = json.loads(b49[4])
check("namespace_audit accepts level and user methods for both tmp dirs",
{f["id"] for f in ns_good["findings"]} == {"no-findings"} and
ns_good["entries"] == 2 and ns_good["shared_tmp"] is False and
ns_good["restricted_only"] == 0, ns_good)
sc = json.loads(b49[5])
sc_kinds = {f["id"] for f in sc["findings"]}
check("ssh_client_audit flags no host key check, a dead known_hosts and "
"ssh-rsa",
{"no-host-key-check", "known-hosts-off", "weak-algorithm",
"world-writable"} <= sc_kinds and sc["files"] == 2 and
sc["no_host_key_check"] == 1 and sc["known_hosts_off"] == 2 and
sc["weak_algorithm"] == 1, sc)
sc_good = json.loads(b49[6])
check("ssh_client_audit accepts ask plus a real known_hosts file",
{f["id"] for f in sc_good["findings"]} == {"no-findings"} and
sc_good["no_host_key_check"] == 0 and
sc_good["known_hosts_off"] == 0, sc_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
@@ -15510,7 +15620,9 @@ check("gitlab_probe reports a closed project API as not open",
gl_srv.shutdown()
gl_closed_srv.shutdown()
for d in (nscd_root, nscd_good_root, fl_root, fl_good_root, cfg48_home):
for d in (nscd_root, nscd_good_root, fl_root, fl_good_root, cfg48_home,
nd_root, nd_good_root, ns_root, ns_good_root, sc_root,
sc_good_root, cfg49_home):
shutil.rmtree(d, ignore_errors=True)
print("%d passed, %d failed" % (passes, len(fails)))