apex-twin 1.27.0: Kerberos discovery, NFS exports, Samba audit
Red: - kerberos_discovery: gated dig SRV queries for _kerberos._tcp, _kerberos._udp and _kpasswd._tcp; reports priority, weight, port and target for each KDC (trailing dot trimmed). Blue: - nfs_exports_audit: /etc/exports and /etc/exports.d (root prefix): export count, world exports (*), writable exports without ro and no_root_squash, with file and line. - samba_audit: smb.conf (root prefix): shares exposing /, guest access, writable shares and guest shares without valid users. Tests: DNS SRV agent, exports tree and smb.conf. 765 checks, ASan suite green, analyze clean, release-check green including distcheck 1.27.0.
This commit is contained in:
1 parent
19b3696238
commit
0bfd94519d
9 files changed
+667
-15
No files matched your search
+14
-1
@@ -8,7 +8,20 @@ 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.26.0 — 2026-11-21 — this change
|
||||
## 1.27.0 — 2026-11-21 — this change
|
||||
|
||||
- **Kerberos** (`kerberos_discovery`): gated dig SRV queries for
|
||||
_kerberos._tcp, _kerberos._udp and _kpasswd._tcp, reporting priority, weight,
|
||||
port and target for each KDC (trailing dot trimmed).
|
||||
- **NFS** (`nfs_exports_audit`): /etc/exports and /etc/exports.d (root prefix):
|
||||
count exports and flag world exports (*), writable exports (no ro) and
|
||||
no_root_squash, with file and line.
|
||||
- **Samba** (`samba_audit`): smb.conf (root prefix): shares exposing /, guest
|
||||
access, writable shares and guest shares without valid users.
|
||||
- Tests with a DNS SRV agent, an exports tree and an smb.conf. 765 checks.
|
||||
Coverage 81.0%.
|
||||
|
||||
## 1.26.0 — 2026-11-21 — 19b3696
|
||||
|
||||
- **HTTP/2** (`http2_probe`): over TLS, `openssl s_client -alpn h2` and the
|
||||
negotiated ALPN protocol; over cleartext, the HTTP/2 client preface plus a
|
||||
|
||||
@@ -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.
|
||||
|
||||
**146 tools · 756 end-to-end checks · 340 fuzz cases · 80.8% line coverage · ~609 KiB**
|
||||
**149 tools · 765 end-to-end checks · 340 fuzz cases · 81.0% line coverage · ~614 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.26.0","tools":146,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.27.0","tools":149,...,"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 (146)
|
||||
## Tools (149)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -291,6 +291,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `security_txt` | security.txt Contact/Expires/Policy; expired documents flagged |
|
||||
| `http2_probe` | ALPN h2 over TLS or h2c preface/SETTINGS; reports HTTP/2 support |
|
||||
| `ssh_hostkey_fingerprint` | ssh-keyscan or saved output: key type, bits, SHA-256 fingerprint |
|
||||
| `kerberos_discovery` | DNS SRV for _kerberos._tcp/_udp and _kpasswd._tcp: KDC priority/weight/port/target |
|
||||
| `imap_probe` | Banner, CAPABILITY list, STARTTLS and LOGINDISABLED; no LOGIN |
|
||||
| `pop3_probe` | Banner, CAPA list, STLS flag; no USER/PASS |
|
||||
| `sip_probe` | One UDP OPTIONS: status line, Server header, Allow methods |
|
||||
@@ -343,6 +344,8 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `usb_audit` | sysfs USB devices: IDs, strings, serial, mass-storage interface flagged |
|
||||
| `ssh_known_hosts_audit` | known_hosts: hashed vs plain, ssh-rsa/ssh-dss, duplicates |
|
||||
| `logrotate_audit` | logrotate configs: world-writable, low rotate, no compress, unsafe postrotate |
|
||||
| `nfs_exports_audit` | exports/`: *`, writable (no ro), no_root_squash |
|
||||
| `samba_audit` | smb.conf shares: root path, guest access, writable, no valid users |
|
||||
|
||||
### ESP32
|
||||
|
||||
@@ -582,6 +585,8 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| HTTP/2 | one handshake (ALPN) or one preface (h2c) |
|
||||
| SSH keys | ssh-keyscan 20 s, or a saved output |
|
||||
| Logrotate | 100 files, read-only |
|
||||
| Kerberos | three SRV queries |
|
||||
| NFS/Samba | config reads only; optional root prefix |
|
||||
| USB audit | 200 devices, sysfs reads only |
|
||||
|
||||
---
|
||||
@@ -593,7 +598,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 756 end-to-end checks
|
||||
make test # version check + gate audit + 765 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
|
||||
@@ -707,7 +712,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
|
||||
tls_cipher_matrix, smb_null_session, smb_shares,
|
||||
email_security_audit, smtp_open_relay, dns_open_resolver,
|
||||
crlf_probe, dns_version_bind, oidc_discovery,
|
||||
security_txt, http2_probe, ssh_hostkey_fingerprint
|
||||
security_txt, http2_probe, ssh_hostkey_fingerprint,
|
||||
kerberos_discovery
|
||||
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,
|
||||
@@ -750,7 +756,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.26.0. Built and run: 146 tools, 756 checks, 340 fuzz cases and 80.8% line
|
||||
1.27.0. Built and run: 149 tools, 765 checks, 340 fuzz cases and 81.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
|
||||
@@ -793,8 +799,9 @@ audit; 1.22 added SMTP relay and DNS resolver checks plus AppArmor/SELinux
|
||||
audits; 1.23 added ESP image verification, CRLF injection and audit-rule
|
||||
checks; 1.24 added NTP monlist and DNS version disclosure checks plus a USB
|
||||
audit; 1.25 added OIDC discovery, security.txt and known-hosts checks; 1.26 added
|
||||
HTTP/2 probing, SSH host-key fingerprints and a logrotate audit, again without
|
||||
changing an existing file format.
|
||||
HTTP/2 probing, SSH host-key fingerprints and a logrotate audit; 1.27 added
|
||||
Kerberos discovery, NFS export and Samba audits, again without changing an
|
||||
existing file format.
|
||||
|
||||
Not yet wired into a fleet router, and there is no TLS interception.
|
||||
|
||||
|
||||
+4
-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.26.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.27.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,9 @@ 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.
|
||||
- **Exports and Samba checks are local reads.** `nfs_exports_audit` and
|
||||
`samba_audit` parse configuration files; `kerberos_discovery` only queries
|
||||
DNS SRV records for an in-scope domain.
|
||||
- **Protocol and key checks stay read-only.** `http2_probe` performs one ALPN
|
||||
handshake or one h2c preface; `ssh_hostkey_fingerprint` runs ssh-keyscan or
|
||||
parses a saved output; `logrotate_audit` reads config files.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.26.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.27.0" "User Commands"
|
||||
.SH NAME
|
||||
apex-twin \- scope\-gated offensive\-security MCP server
|
||||
.SH SYNOPSIS
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.26.0"
|
||||
#define APEX_VERSION "1.27.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -6018,6 +6018,355 @@ static void t_logrotate_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_free(&findings);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- nfs_exports_audit */
|
||||
|
||||
typedef struct {
|
||||
mcp_buf *b;
|
||||
int first;
|
||||
int count;
|
||||
int files;
|
||||
int exports;
|
||||
} nfs_ctx;
|
||||
|
||||
static void nfs_finding(nfs_ctx *ctx, const char *path, int line,
|
||||
const char *kind, const char *severity,
|
||||
const char *detail)
|
||||
{
|
||||
if (ctx->count >= 100)
|
||||
return;
|
||||
if (!ctx->first)
|
||||
mcp_buf_puts(ctx->b, ",");
|
||||
ctx->first = 0;
|
||||
ctx->count++;
|
||||
mcp_buf_puts(ctx->b, "{\"path\":");
|
||||
apex_json_str(ctx->b, path);
|
||||
mcp_buf_printf(ctx->b, ",\"line\":%d,\"kind\":", line);
|
||||
apex_json_str(ctx->b, kind);
|
||||
mcp_buf_puts(ctx->b, ",\"severity\":");
|
||||
apex_json_str(ctx->b, severity);
|
||||
mcp_buf_puts(ctx->b, ",\"detail\":");
|
||||
apex_json_str(ctx->b, detail);
|
||||
mcp_buf_puts(ctx->b, "}");
|
||||
}
|
||||
|
||||
static void nfs_scan_file(nfs_ctx *ctx, const char *path)
|
||||
{
|
||||
FILE *f;
|
||||
char *line = NULL;
|
||||
size_t cap = 0;
|
||||
int lineno = 0;
|
||||
|
||||
if (ctx->files >= 100)
|
||||
return;
|
||||
f = fopen(path, "rb");
|
||||
if (f == NULL)
|
||||
return;
|
||||
ctx->files++;
|
||||
while (getline(&line, &cap, f) >= 0) {
|
||||
char *t = line;
|
||||
char *save = NULL;
|
||||
char *tok;
|
||||
char *copy;
|
||||
int world = 0;
|
||||
int writable = 0;
|
||||
int no_root = 0;
|
||||
|
||||
lineno++;
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
trim_eol(t);
|
||||
if (*t == '\0' || *t == '#')
|
||||
continue;
|
||||
ctx->exports++;
|
||||
copy = strdup(t);
|
||||
if (copy == NULL)
|
||||
continue;
|
||||
tok = strtok_r(copy, " \t", &save);
|
||||
tok = strtok_r(NULL, " \t", &save);
|
||||
while (tok != NULL) {
|
||||
char opts[512];
|
||||
size_t w = 0;
|
||||
const char *paren = strchr(tok, '(');
|
||||
|
||||
opts[0] = '\0';
|
||||
if (paren != NULL) {
|
||||
const char *p = paren + 1;
|
||||
|
||||
while (*p != '\0' && *p != ')' && w + 1 < sizeof(opts))
|
||||
opts[w++] = *p++;
|
||||
opts[w] = '\0';
|
||||
}
|
||||
{
|
||||
size_t hl = paren != NULL ? (size_t)(paren - tok)
|
||||
: strlen(tok);
|
||||
|
||||
if (hl == 1 && tok[0] == '*')
|
||||
world = 1;
|
||||
}
|
||||
if (!mount_has_opt(opts, "ro"))
|
||||
writable = 1;
|
||||
if (mount_has_opt(opts, "no_root_squash"))
|
||||
no_root = 1;
|
||||
tok = strtok_r(NULL, " \t", &save);
|
||||
}
|
||||
if (world)
|
||||
nfs_finding(ctx, path, lineno, "world-export", "high",
|
||||
"export is open to every host (*)");
|
||||
if (writable)
|
||||
nfs_finding(ctx, path, lineno, "writable", "medium",
|
||||
"export is writable (no ro option)");
|
||||
if (no_root)
|
||||
nfs_finding(ctx, path, lineno, "no-root-squash", "high",
|
||||
"root is not squashed on this export");
|
||||
free(copy);
|
||||
}
|
||||
free(line);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void t_nfs_exports_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char base[512];
|
||||
char path[1024];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
nfs_ctx ctx;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) >= sizeof(base) - 2) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(base, sizeof(base), "%s", root);
|
||||
mcp_buf_init(&findings);
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.b = &findings;
|
||||
ctx.first = 1;
|
||||
snprintf(path, sizeof(path), "%s/etc/exports", base);
|
||||
nfs_scan_file(&ctx, path);
|
||||
snprintf(path, sizeof(path), "%s/etc/exports.d", base);
|
||||
{
|
||||
DIR *d = opendir(path);
|
||||
struct dirent *ent;
|
||||
|
||||
if (d != NULL) {
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
char full[1024];
|
||||
struct stat st;
|
||||
size_t nl = strlen(ent->d_name);
|
||||
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
if (nl < 9 ||
|
||||
strcmp(ent->d_name + nl - 8, ".exports") != 0)
|
||||
continue;
|
||||
snprintf(full, sizeof(full), "%.800s/%.160s", path,
|
||||
ent->d_name);
|
||||
if (stat(full, &st) != 0 || !S_ISREG(st.st_mode))
|
||||
continue;
|
||||
nfs_scan_file(&ctx, full);
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, base);
|
||||
mcp_buf_printf(&b, ",\"files\":%d,\"exports\":%d,\"findings_count\":%d,"
|
||||
"\"findings\":[", ctx.files, ctx.exports, ctx.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);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- samba_audit */
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char path[256];
|
||||
int line;
|
||||
int guest;
|
||||
int writable;
|
||||
int valid_users;
|
||||
int active;
|
||||
} smb_share;
|
||||
|
||||
typedef struct {
|
||||
mcp_buf *b;
|
||||
int first;
|
||||
int count;
|
||||
int shares;
|
||||
} smb_ctx;
|
||||
|
||||
static void smb_finding(smb_ctx *ctx, const smb_share *sh, const char *kind,
|
||||
const char *severity, const char *detail)
|
||||
{
|
||||
if (ctx->count >= 100)
|
||||
return;
|
||||
if (!ctx->first)
|
||||
mcp_buf_puts(ctx->b, ",");
|
||||
ctx->first = 0;
|
||||
ctx->count++;
|
||||
mcp_buf_puts(ctx->b, "{\"section\":");
|
||||
apex_json_str(ctx->b, sh->name);
|
||||
mcp_buf_printf(ctx->b, ",\"line\":%d,\"kind\":", sh->line);
|
||||
apex_json_str(ctx->b, kind);
|
||||
mcp_buf_puts(ctx->b, ",\"severity\":");
|
||||
apex_json_str(ctx->b, severity);
|
||||
mcp_buf_puts(ctx->b, ",\"detail\":");
|
||||
apex_json_str(ctx->b, detail);
|
||||
mcp_buf_puts(ctx->b, "}");
|
||||
}
|
||||
|
||||
static void smb_flush(smb_ctx *ctx, smb_share *sh)
|
||||
{
|
||||
if (!sh->active)
|
||||
return;
|
||||
sh->active = 0;
|
||||
if (strcmp(sh->name, "global") == 0)
|
||||
return;
|
||||
ctx->shares++;
|
||||
if (sh->path[0] != '\0' && strcmp(sh->path, "/") == 0)
|
||||
smb_finding(ctx, sh, "root-share", "high",
|
||||
"share exposes the filesystem root");
|
||||
if (sh->guest)
|
||||
smb_finding(ctx, sh, "guest-access", "high",
|
||||
"share allows guest access");
|
||||
if (sh->writable)
|
||||
smb_finding(ctx, sh, "writable-share", "medium",
|
||||
"share is writable");
|
||||
if (sh->guest && !sh->valid_users)
|
||||
smb_finding(ctx, sh, "no-valid-users", "low",
|
||||
"guest share has no valid users restriction");
|
||||
}
|
||||
|
||||
static void smb_scan_file(smb_ctx *ctx, const char *path)
|
||||
{
|
||||
FILE *f = fopen(path, "rb");
|
||||
char *line = NULL;
|
||||
size_t cap = 0;
|
||||
int lineno = 0;
|
||||
smb_share sh;
|
||||
|
||||
memset(&sh, 0, sizeof(sh));
|
||||
if (f == NULL)
|
||||
return;
|
||||
while (getline(&line, &cap, f) >= 0) {
|
||||
char *t = line;
|
||||
size_t n;
|
||||
|
||||
lineno++;
|
||||
while (*t == ' ' || *t == '\t')
|
||||
t++;
|
||||
n = strlen(t);
|
||||
while (n > 0 && (t[n - 1] == '\n' || t[n - 1] == '\r'))
|
||||
t[--n] = '\0';
|
||||
if (*t == '\0' || *t == '#' || *t == ';')
|
||||
continue;
|
||||
if (*t == '[') {
|
||||
char *close = strchr(t, ']');
|
||||
|
||||
smb_flush(ctx, &sh);
|
||||
memset(&sh, 0, sizeof(sh));
|
||||
if (close != NULL) {
|
||||
size_t w = (size_t)(close - t - 1);
|
||||
|
||||
if (w >= sizeof(sh.name))
|
||||
w = sizeof(sh.name) - 1;
|
||||
memcpy(sh.name, t + 1, w);
|
||||
sh.name[w] = '\0';
|
||||
sh.line = lineno;
|
||||
sh.active = 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!sh.active)
|
||||
continue;
|
||||
{
|
||||
char *eq = strchr(t, '=');
|
||||
char *key;
|
||||
char *value;
|
||||
size_t kl;
|
||||
|
||||
if (eq == NULL)
|
||||
continue;
|
||||
*eq = '\0';
|
||||
key = t;
|
||||
value = eq + 1;
|
||||
kl = strlen(key);
|
||||
while (kl > 0 && (key[kl - 1] == ' ' || key[kl - 1] == '\t'))
|
||||
key[--kl] = '\0';
|
||||
while (*value == ' ' || *value == '\t')
|
||||
value++;
|
||||
if (strcasecmp(key, "guest ok") == 0 ||
|
||||
strcasecmp(key, "public") == 0) {
|
||||
if (strcasecmp(value, "yes") == 0 ||
|
||||
strcasecmp(value, "true") == 0)
|
||||
sh.guest = 1;
|
||||
} else if (strcasecmp(key, "writable") == 0 ||
|
||||
strcasecmp(key, "writeable") == 0) {
|
||||
if (strcasecmp(value, "yes") == 0)
|
||||
sh.writable = 1;
|
||||
} else if (strcasecmp(key, "read only") == 0) {
|
||||
if (strcasecmp(value, "no") == 0)
|
||||
sh.writable = 1;
|
||||
} else if (strcasecmp(key, "valid users") == 0) {
|
||||
if (*value != '\0')
|
||||
sh.valid_users = 1;
|
||||
} else if (strcasecmp(key, "path") == 0) {
|
||||
snprintf(sh.path, sizeof(sh.path), "%.200s", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
smb_flush(ctx, &sh);
|
||||
free(line);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void t_samba_audit(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
const char *root = mcp_arg_string(args, "root");
|
||||
char base[512];
|
||||
char path[1024];
|
||||
mcp_buf b;
|
||||
mcp_buf findings;
|
||||
smb_ctx ctx;
|
||||
|
||||
(void)user;
|
||||
if (root == NULL)
|
||||
root = "";
|
||||
if (strlen(root) >= sizeof(base) - 2) {
|
||||
mcp_reply_error(c, "root path too long");
|
||||
return;
|
||||
}
|
||||
snprintf(base, sizeof(base), "%s", root);
|
||||
mcp_buf_init(&findings);
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.b = &findings;
|
||||
ctx.first = 1;
|
||||
snprintf(path, sizeof(path), "%s/etc/samba/smb.conf", base);
|
||||
smb_scan_file(&ctx, path);
|
||||
snprintf(path, sizeof(path), "%s/etc/smb.conf", base);
|
||||
smb_scan_file(&ctx, path);
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"root\":");
|
||||
apex_json_str(&b, base);
|
||||
mcp_buf_printf(&b, ",\"shares\":%d,\"findings_count\":%d,\"findings\":[",
|
||||
ctx.shares, ctx.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, "
|
||||
@@ -6366,6 +6715,19 @@ const mcp_tool TOOLS_BLUE[] = {
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_logrotate_audit },
|
||||
{ "nfs_exports_audit",
|
||||
"Parse /etc/exports and /etc/exports.d (root prefix): count exports and "
|
||||
"flag world exports (*), writable exports without ro and exports with "
|
||||
"no_root_squash, with file and line. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_nfs_exports_audit },
|
||||
{ "samba_audit",
|
||||
"Parse smb.conf (root prefix) and report shares that expose /, allow guest "
|
||||
"access, are writable or allow guests without valid users. Read-only.",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
|
||||
t_samba_audit },
|
||||
};
|
||||
|
||||
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
|
||||
+144
@@ -4670,6 +4670,139 @@ static void t_ssh_hostkey_fingerprint(mcp_conn *c, const mcp_json *args,
|
||||
free(text);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ kerberos_discovery */
|
||||
|
||||
static void kerb_parse(mcp_buf *b, int *first, int *count, const char *service,
|
||||
const char *text)
|
||||
{
|
||||
char *copy;
|
||||
char *save = NULL;
|
||||
char *line;
|
||||
|
||||
if (text == NULL)
|
||||
return;
|
||||
copy = strdup(text);
|
||||
if (copy == NULL)
|
||||
return;
|
||||
line = strtok_r(copy, "\n", &save);
|
||||
while (line != NULL) {
|
||||
int prio;
|
||||
int weight;
|
||||
int port;
|
||||
char target[256];
|
||||
|
||||
while (*line == ' ' || *line == '\t')
|
||||
line++;
|
||||
if (sscanf(line, "%d %d %d %255s", &prio, &weight, &port,
|
||||
target) == 4) {
|
||||
{
|
||||
size_t tl = strlen(target);
|
||||
|
||||
if (tl > 0 && target[tl - 1] == '.')
|
||||
target[tl - 1] = '\0';
|
||||
}
|
||||
if (!*first)
|
||||
mcp_buf_puts(b, ",");
|
||||
*first = 0;
|
||||
(*count)++;
|
||||
mcp_buf_puts(b, "{\"service\":");
|
||||
apex_json_str(b, service);
|
||||
mcp_buf_printf(b, ",\"priority\":%d,\"weight\":%d,\"port\":%d,"
|
||||
"\"target\":", prio, weight, port);
|
||||
apex_json_str(b, target);
|
||||
mcp_buf_puts(b, "}");
|
||||
}
|
||||
line = strtok_r(NULL, "\n", &save);
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static void t_kerberos_discovery(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *services[] = { "_kerberos._tcp", "_kerberos._udp",
|
||||
"_kpasswd._tcp", NULL };
|
||||
const char *domain = mcp_arg_string(args, "domain");
|
||||
const char *resolver = mcp_arg_string(args, "resolver");
|
||||
int port = mcp_arg_int(args, "port", 0);
|
||||
char reason[512];
|
||||
char portstr[16];
|
||||
char at_server[300];
|
||||
mcp_buf b;
|
||||
int qfirst = 1;
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
(void)user;
|
||||
if (domain == NULL || *domain == '\0') {
|
||||
mcp_reply_error(c, "domain is required");
|
||||
return;
|
||||
}
|
||||
if (port < 0 || port > 65535) {
|
||||
mcp_reply_error(c, "port out of range");
|
||||
return;
|
||||
}
|
||||
if (!apex_scope_check(domain, 0, reason, sizeof(reason))) {
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_printf(&b, "REFUSED by scope gate: %s", reason);
|
||||
mcp_reply_error(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
return;
|
||||
}
|
||||
if (resolver != NULL && *resolver != '\0' &&
|
||||
!apex_scope_check(resolver, port, reason, sizeof(reason))) {
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_printf(&b, "resolver is outside the scope: %s", reason);
|
||||
mcp_reply_error(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
return;
|
||||
}
|
||||
apex_audit("kerberos_discovery", domain, 0, 1, "SRV discovery",
|
||||
"_kerberos._tcp");
|
||||
snprintf(portstr, sizeof(portstr), "%d", port > 0 ? port : 53);
|
||||
snprintf(at_server, sizeof(at_server), "@%.200s",
|
||||
resolver != NULL ? resolver : "");
|
||||
mcp_buf_init(&b);
|
||||
mcp_buf_puts(&b, "{\"domain\":");
|
||||
apex_json_str(&b, domain);
|
||||
mcp_buf_puts(&b, ",\"queries\":[");
|
||||
for (i = 0; services[i] != NULL; i++) {
|
||||
char name[400];
|
||||
char *argv[10];
|
||||
int k = 0;
|
||||
apex_proc p;
|
||||
int qcount = 0;
|
||||
int rfirst = 1;
|
||||
|
||||
snprintf(name, sizeof(name), "%.40s.%.200s", services[i], domain);
|
||||
if (!qfirst)
|
||||
mcp_buf_puts(&b, ",");
|
||||
qfirst = 0;
|
||||
mcp_buf_puts(&b, "{\"name\":");
|
||||
apex_json_str(&b, name);
|
||||
mcp_buf_puts(&b, ",\"records\":[");
|
||||
argv[k++] = "dig";
|
||||
argv[k++] = "+short";
|
||||
argv[k++] = "+time=3";
|
||||
argv[k++] = "+tries=1";
|
||||
argv[k++] = "-p";
|
||||
argv[k++] = portstr;
|
||||
if (resolver != NULL && *resolver != '\0')
|
||||
argv[k++] = at_server;
|
||||
argv[k++] = name;
|
||||
argv[k++] = "SRV";
|
||||
argv[k] = NULL;
|
||||
if (apex_run(argv, 15000, 32 * 1024, &p) == 0) {
|
||||
kerb_parse(&b, &rfirst, &qcount, services[i], p.out);
|
||||
apex_proc_free(&p);
|
||||
}
|
||||
count += qcount;
|
||||
mcp_buf_puts(&b, "]}");
|
||||
}
|
||||
mcp_buf_printf(&b, "],\"kdc_count\":%d}", count);
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
const mcp_tool TOOLS_RED[] = {
|
||||
{ "vuln_check",
|
||||
"Non-destructive verification of exposed artifacts on one web target: "
|
||||
@@ -5080,6 +5213,17 @@ const mcp_tool TOOLS_RED[] = {
|
||||
"ssh-keyscan output\"}},"
|
||||
"\"required\":[\"target\"]}",
|
||||
t_ssh_hostkey_fingerprint },
|
||||
{ "kerberos_discovery",
|
||||
"Discover Kerberos services for a domain with gated dig SRV queries: "
|
||||
"_kerberos._tcp, _kerberos._udp and _kpasswd._tcp, reporting priority, "
|
||||
"weight, port and target for each KDC. Gate: the domain (and resolver).",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"domain\":{\"type\":\"string\"},"
|
||||
"\"resolver\":{\"type\":\"string\",\"description\":\"optional DNS "
|
||||
"server\"},"
|
||||
"\"port\":{\"type\":\"integer\",\"description\":\"dig -p, default 0\"}},"
|
||||
"\"required\":[\"domain\"]}",
|
||||
t_kerberos_discovery },
|
||||
};
|
||||
|
||||
const size_t TOOLS_RED_N = sizeof(TOOLS_RED) / sizeof(TOOLS_RED[0]);
|
||||
+1
-1
@@ -21,7 +21,7 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 146
|
||||
EXPECTED_TOOLS = 149
|
||||
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.
|
||||
|
||||
+125
-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("146 tools registered", len(tools) == 146, len(tools))
|
||||
check("149 tools registered", len(tools) == 149, 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"]) == 146)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 149)
|
||||
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
|
||||
@@ -6690,6 +6690,129 @@ shutil.rmtree(alpn_dir, ignore_errors=True)
|
||||
shutil.rmtree(lr_root, ignore_errors=True)
|
||||
shutil.rmtree(http2_home, ignore_errors=True)
|
||||
|
||||
print("\n== Kerberos, NFS exports and Samba ==")
|
||||
|
||||
|
||||
def dns_srv_agent():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
sock.settimeout(0.2)
|
||||
port = sock.getsockname()[1]
|
||||
stop = threading.Event()
|
||||
|
||||
def srv(prio, weight, sport, target):
|
||||
return (struct.pack(">HHH", prio, weight, sport) +
|
||||
dns_name_encode(target))
|
||||
|
||||
def loop():
|
||||
while not stop.is_set():
|
||||
try:
|
||||
data, addr = sock.recvfrom(2048)
|
||||
except socket.timeout:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
if len(data) < 12:
|
||||
continue
|
||||
tid = data[:2]
|
||||
name, off = dns_name_decode(data, 12)
|
||||
if off + 4 > len(data):
|
||||
continue
|
||||
qtype = struct.unpack(">H", data[off:off + 2])[0]
|
||||
question = data[12:off + 4]
|
||||
answers = []
|
||||
if qtype == 33:
|
||||
if name == "_kerberos._tcp.example.test":
|
||||
for prio, target in ((10, "kdc1.example.test"),
|
||||
(20, "kdc2.example.test")):
|
||||
rdata = srv(prio, 5, 88, target)
|
||||
answers.append(b"\xc0\x0c" + struct.pack(
|
||||
">HHIH", 33, 1, 300, len(rdata)) + rdata)
|
||||
elif name == "_kerberos._udp.example.test":
|
||||
rdata = srv(10, 0, 88, "kdc1.example.test")
|
||||
answers.append(b"\xc0\x0c" + struct.pack(
|
||||
">HHIH", 33, 1, 300, len(rdata)) + rdata)
|
||||
resp = (tid + struct.pack(">HHHHH", 0x8400, 1, len(answers), 0, 0) +
|
||||
question + b"".join(answers))
|
||||
sock.sendto(resp, addr)
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return sock, port, stop
|
||||
|
||||
|
||||
srv_sock, srv_port, srv_stop = dns_srv_agent()
|
||||
|
||||
nfs_root = tempfile.mkdtemp(prefix="apex-nfs-")
|
||||
os.makedirs(os.path.join(nfs_root, "etc", "exports.d"))
|
||||
with open(os.path.join(nfs_root, "etc", "exports"), "w") as f:
|
||||
f.write("/srv/data *(rw,no_root_squash)\n")
|
||||
f.write("/srv/public 10.0.0.0/24(ro)\n")
|
||||
f.write("/srv/team 10.0.0.0/24(rw,sync)\n")
|
||||
with open(os.path.join(nfs_root, "etc", "exports.d", "extra.exports"),
|
||||
"w") as f:
|
||||
f.write("/srv/backup 10.0.0.0/24(rw,no_root_squash)\n")
|
||||
|
||||
smb_root = tempfile.mkdtemp(prefix="apex-smb-")
|
||||
os.makedirs(os.path.join(smb_root, "etc", "samba"))
|
||||
with open(os.path.join(smb_root, "etc", "samba", "smb.conf"), "w") as f:
|
||||
f.write("[global]\n workgroup = TEST\n")
|
||||
f.write("[public]\n path = /srv/public\n guest ok = yes\n"
|
||||
" writable = yes\n browseable = yes\n")
|
||||
f.write("[data]\n path = /\n read only = no\n")
|
||||
f.write("[private]\n path = /srv/private\n valid users = alice\n")
|
||||
|
||||
smb_home = tempfile.mkdtemp(prefix="apex-smb-home-")
|
||||
write_scope(smb_home, {"label": "smb", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
||||
"allow_domain": ["example.test"],
|
||||
"allow_port": [str(srv_port)]})
|
||||
res, _ = run([
|
||||
call(1, "kerberos_discovery", domain="example.test",
|
||||
resolver="127.0.0.1", port=srv_port),
|
||||
call(2, "nfs_exports_audit", root=nfs_root),
|
||||
call(3, "samba_audit", root=smb_root),
|
||||
call(4, "kerberos_discovery", domain="evil.test"),
|
||||
call(5, "nfs_exports_audit", root="/nonexistent-nfs"),
|
||||
call(6, "samba_audit", root="/nonexistent-smb"),
|
||||
], home=smb_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
kerb = json.loads(text(by_id[1]))
|
||||
records = [rec for q in kerb["queries"] for rec in q["records"]]
|
||||
targets = {k["target"] for k in records}
|
||||
check("kerberos_discovery finds the KDCs",
|
||||
kerb["kdc_count"] == 3 and
|
||||
{"kdc1.example.test", "kdc2.example.test"} <= targets, kerb)
|
||||
check("kerberos_discovery keeps priorities and ports",
|
||||
any(k["priority"] == 20 and k["port"] == 88 for k in records),
|
||||
records)
|
||||
nfs = json.loads(text(by_id[2]))
|
||||
nkinds = [f["kind"] for f in nfs["findings"]]
|
||||
check("nfs_exports_audit reads both files and all exports",
|
||||
nfs["files"] == 2 and nfs["exports"] == 4, nfs)
|
||||
check("nfs_exports_audit flags world, writable and no_root_squash",
|
||||
nkinds.count("world-export") == 1 and
|
||||
nkinds.count("writable") == 3 and
|
||||
nkinds.count("no-root-squash") == 2, nkinds)
|
||||
smb = json.loads(text(by_id[3]))
|
||||
skinds = [(f["section"], f["kind"]) for f in smb["findings"]]
|
||||
check("samba_audit counts the shares", smb["shares"] == 3, smb)
|
||||
check("samba_audit flags guest, writable and root shares",
|
||||
("public", "guest-access") in skinds and
|
||||
("public", "writable-share") in skinds and
|
||||
("data", "root-share") in skinds and
|
||||
("public", "no-valid-users") in skinds, skinds)
|
||||
check("kerberos_discovery refuses an out-of-scope domain", err(by_id[4]),
|
||||
text(by_id[4]))
|
||||
check("nfs_exports_audit survives a missing root",
|
||||
json.loads(text(by_id[5]))["files"] == 0, text(by_id[5]))
|
||||
check("samba_audit survives a missing root",
|
||||
json.loads(text(by_id[6]))["shares"] == 0, text(by_id[6]))
|
||||
srv_stop.set()
|
||||
srv_sock.close()
|
||||
shutil.rmtree(nfs_root, ignore_errors=True)
|
||||
shutil.rmtree(smb_root, ignore_errors=True)
|
||||
shutil.rmtree(smb_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
esp_home = tempfile.mkdtemp(prefix="apex-esp-")
|
||||
write_scope(esp_home, {"label": "esp", "expires": "2099-12-31T23:59:59Z"})
|
||||
|
||||
Reference in new issue
Block a user