apex-twin 1.20.0: TLS cipher matrix, SMB null session, Docker audit

Red:
- tls_cipher_matrix: one openssl s_client per weak cipher (3DES, RC4, NULL,
  EXPORT, CBC by default) for TLS 1.2 or 1.3; reports which suites negotiate.
  The gate is checked once, then the handshakes run.
- smb_null_session: negotiate SMB 2.1, anonymous SESSION_SETUP with an empty
  security buffer, TREE_CONNECT to IPC$ on success; reports status/id and IPC$
  access. No share enumeration and no file access.

Blue:
- docker_audit: docker.sock mode (world-writable critical), docker group
  members from /etc/group, daemon.json TCP hosts, TLS and insecure registries;
  no daemon call.

Tests: a TLS server accepting AES128-SHA, SMB2 servers that allow and refuse
the anonymous session, and a Docker fixture tree. 695 checks, ASan suite green,
analyze clean, release-check green including distcheck 1.20.0.

Fixture lessons: the SMB negotiate helper already adds a NetBIOS header (double
wrapping shifts the SMB2 header by four bytes), and the Docker JSON closed the
daemon object twice.
This commit is contained in:
lotherk committed 2026-11-21 16:37:54 +00:00
1 parent 5392f911d1
commit 99649e2108
9 files changed
+716 -16

No files matched your search

+20 -1
View File
@@ -8,7 +8,26 @@ 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.19.0 — 2026-11-21 — this change
## 1.20.0 — 2026-11-21 — this change
- **TLS cipher matrix** (`tls_cipher_matrix`): one `openssl s_client` per weak
cipher (3DES, RC4, NULL, EXPORT, CBC by default) for TLS 1.2 or 1.3; reports
which suites negotiate. Gate checked once, then the handshakes run.
- **SMB null session** (`smb_null_session`): negotiates SMB 2.1, attempts an
anonymous SESSION_SETUP with an empty security buffer and, on success, a
TREE_CONNECT to IPC$. Reports session status/id and IPC$ access; no share
enumeration and no file access.
- **Docker** (`docker_audit`): docker.sock mode (world-writable is critical),
docker group members from /etc/group, and daemon.json (TCP hosts, TLS,
insecure registries); no daemon call.
- Tests with a TLS server accepting AES128-SHA, an SMB2 server that allows and
one that refuses the anonymous session, and a Docker fixture tree. 695
checks. Coverage 80.1%.
- Two fixture bugs caught: the SMB negotiate helper already adds a NetBIOS
header (double wrapping shifted the SMB2 header by four bytes), and the
Docker JSON closed the daemon object twice.
## 1.19.0 — 2026-11-21 — 5392f91
- **ESP app** (`esp_app_info`): parses an app image header (magic 0xE9,
segment count, entry address) and the `esp_app_desc_t` at 0x20 (magic
+15 -7
View File
@@ -5,11 +5,11 @@ no Python in the serving path. It gives an agent real reconnaissance and real we
testing behind a scope gate that refuses everything until a rules-of-engagement
file says otherwise.
**124 tools · 686 end-to-end checks · 340 fuzz cases · 79.9% line coverage · ~539 KiB**
**127 tools · 695 end-to-end checks · 340 fuzz cases · 80.1% line coverage · ~548 KiB**
```
$ ./apex-twin --check
{"version":"1.19.0","tools":124,...,"scope":{"loaded":true,...}}
{"version":"1.20.0","tools":127,...,"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 (124)
## Tools (127)
### Scope and bookkeeping
@@ -278,6 +278,8 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `ntp_probe` | NTPv4 client packet: version, mode, leap, stratum, refid, root delay/dispersion, time |
| `api_auth_audit` | Unauthenticated GETs over an endpoint list: status, JSON, open vs 401/403, evidence |
| `cache_audit` | Clean vs parameterized URL: Cache-Control/Age/Vary/X-Cache, parameterized-cacheable finding |
| `tls_cipher_matrix` | Weak cipher list per TLS version; reports which suites negotiate |
| `smb_null_session` | SMB 2.1 negotiate, anonymous session, IPC$ tree connect |
| `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 |
@@ -322,6 +324,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `ssh_config_audit` | sshd_config scoring: root login, passwords, tunnels, forwardings, legacy ciphers/MACs/kex |
| `pam_audit` | pam.d: pam_permit, pam_unix nullok, pam_exec and missing faillock/tally lockout |
| `log_timeline` | Merge auth and access logs into one sorted chronology with source tags |
| `docker_audit` | docker.sock mode, docker group members, daemon.json TCP/TLS/insecure registries |
### ESP32
@@ -542,6 +545,9 @@ The full threat model, trust boundaries and a hardening checklist are in
| sshd/PAM | read config files only; optional root prefix |
| API/cache | one GET per endpoint, two for cache_audit |
| Log timeline | 200 entries from up to 5000 lines per log |
| Cipher matrix | 12 ciphers, one handshake each, gated once |
| SMB null session | negotiate 2.1, session + IPC$ only |
| Docker audit | reads socket mode, group file, daemon.json |
---
@@ -552,7 +558,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 686 end-to-end checks
make test # version check + gate audit + 695 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
@@ -662,7 +668,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
elasticsearch_probe, imap_probe, pop3_probe, sip_probe,
telnet_probe, http_methods, websocket_probe, ike_probe,
snmp_walk, ldap_search, openapi_discovery, csrf_audit,
rpc_probe, ntp_probe, api_auth_audit, cache_audit
rpc_probe, ntp_probe, api_auth_audit, cache_audit,
tls_cipher_matrix, smb_null_session
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,
@@ -705,7 +712,7 @@ examples/ scope.json
## Status
1.19.0. Built and run: 124 tools, 686 checks, 340 fuzz cases and 79.9% line
1.20.0. Built and run: 127 tools, 695 checks, 340 fuzz cases and 80.1% 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
@@ -742,7 +749,8 @@ added SNMP walk, LDAP search and OpenAPI discovery plus a systemd audit; 1.17
added CSRF, kernel, sudoers and auditd checks and fixed evidence ordering for
same-second files; 1.18 added RPC and NTP probes plus sshd_config and PAM
audits; 1.19 added ESP app parsing, API auth and cache audits plus a log
timeline, again without changing an existing file format.
timeline; 1.20 added a TLS cipher matrix, SMB null-session check and Docker
audit, again without changing an existing file format.
Not yet wired into a fleet router, and there is no TLS interception.
+5 -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.19.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.20.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,10 @@ 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.
- **SMB stays at the session and IPC$.** `smb_null_session` negotiates SMB
2.1, tries an anonymous session setup and only connects to IPC$; it does not
enumerate shares or read files. `tls_cipher_matrix` performs one handshake
per cipher; `docker_audit` reads files and never calls the daemon.
- **API and cache probes are unauthenticated GETs.** `api_auth_audit` requests
a caller-supplied endpoint list without credentials, `cache_audit` fetches a
path twice, and `log_timeline` merges two local logs (restricted paths).
+1 -1
View File
@@ -1,5 +1,5 @@
.\" apex-twin.1 - manual page for APEX TWIN
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.19.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.20.0" "User Commands"
.SH NAME
apex-twin \- scope\-gated offensive\-security MCP server
.SH SYNOPSIS
+1 -1
View File
@@ -15,7 +15,7 @@
#include "mcp.h"
#define APEX_VERSION "1.19.0"
#define APEX_VERSION "1.20.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+175
View File
@@ -4771,6 +4771,173 @@ static void t_log_timeline(mcp_conn *c, const mcp_json *args, void *user)
free(ctx.entries);
}
/* --------------------------------------------------------------- docker_audit */
static void docker_finding(mcp_buf *b, int *first, const char *id,
const char *severity, const char *detail)
{
if (!*first)
mcp_buf_puts(b, ",");
*first = 0;
mcp_buf_puts(b, "{\"id\":");
apex_json_str(b, id);
mcp_buf_puts(b, ",\"severity\":");
apex_json_str(b, severity);
mcp_buf_puts(b, ",\"detail\":");
apex_json_str(b, detail);
mcp_buf_puts(b, "}");
}
static void t_docker_audit(mcp_conn *c, const mcp_json *args, void *user)
{
const char *root = mcp_arg_string(args, "root");
char base[512];
size_t bl;
char path[1024];
mcp_buf b;
int first = 1;
int findings = 0;
struct stat st;
int socket_exists = 0;
unsigned int socket_mode = 0;
int world_writable = 0;
int group_exists = 0;
char members[10][64];
int nmembers = 0;
int daemon_exists = 0;
int hosts_tcp = 0;
int tls_on = 0;
int insecure = 0;
(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);
bl = strlen(base);
while (bl > 0 && base[bl - 1] == '/')
base[--bl] = '\0';
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, base);
snprintf(path, sizeof(path), "%s/var/run/docker.sock", base);
if (stat(path, &st) == 0) {
socket_exists = 1;
socket_mode = (unsigned int)(st.st_mode & 07777);
world_writable = (st.st_mode & 0002) != 0;
}
mcp_buf_puts(&b, ",\"socket\":{\"path\":");
apex_json_str(&b, path);
mcp_buf_printf(&b, ",\"exists\":%s,\"mode\":\"%04o\","
"\"world_writable\":%s}", socket_exists ? "true" : "false",
socket_mode, world_writable ? "true" : "false");
snprintf(path, sizeof(path), "%s/etc/group", base);
{
FILE *f = fopen(path, "rb");
char *line = NULL;
size_t cap = 0;
if (f != NULL) {
while (getline(&line, &cap, f) >= 0) {
if (strncmp(line, "docker:", 7) == 0) {
char *fields[6];
int nf = 0;
char *save = NULL;
char *tok;
char *copy = strdup(line);
char *fsave = NULL;
char *member;
group_exists = 1;
if (copy == NULL)
continue;
tok = strtok_r(copy, ":", &save);
while (tok != NULL && nf < 6) {
fields[nf++] = tok;
tok = strtok_r(NULL, ":", &save);
}
if (nf >= 4) {
member = strtok_r(fields[3], ",\n", &fsave);
while (member != NULL && nmembers < 10) {
if (*member != '\0' && *member != '\n')
snprintf(members[nmembers++],
sizeof(members[0]), "%.48s",
member);
member = strtok_r(NULL, ",\n", &fsave);
}
}
free(copy);
break;
}
}
free(line);
fclose(f);
}
}
mcp_buf_printf(&b, ",\"docker_group\":{\"exists\":%s,\"members\":[",
group_exists ? "true" : "false");
{
int i;
for (i = 0; i < nmembers; i++) {
if (i > 0)
mcp_buf_puts(&b, ",");
apex_json_str(&b, members[i]);
}
}
mcp_buf_puts(&b, "]}");
snprintf(path, sizeof(path), "%s/etc/docker/daemon.json", base);
{
static char config[65536];
if (read_text(path, config, sizeof(config)) > 0) {
daemon_exists = 1;
hosts_tcp = strstr(config, "tcp://") != NULL;
tls_on = strstr(config, "\"tls\"") != NULL &&
strstr(config, "true") != NULL;
insecure = strstr(config, "insecure-registries") != NULL;
}
}
mcp_buf_puts(&b, ",\"daemon\":{\"path\":");
apex_json_str(&b, path);
mcp_buf_printf(&b, ",\"exists\":%s,\"hosts_tcp\":%s,\"tls\":%s,"
"\"insecure_registries\":%s}", daemon_exists ? "true" : "false",
hosts_tcp ? "true" : "false", tls_on ? "true" : "false",
insecure ? "true" : "false");
mcp_buf_puts(&b, ",\"findings\":[");
if (world_writable) {
docker_finding(&b, &first, "socket-world-writable", "high",
"the Docker socket is writable by any local user");
findings++;
}
if (group_exists && nmembers > 0) {
docker_finding(&b, &first, "docker-group-members", "medium",
"docker group members can become root through the daemon");
findings++;
}
if (hosts_tcp) {
docker_finding(&b, &first, "api-tcp", "high",
"the daemon listens on a TCP address");
findings++;
if (!tls_on) {
docker_finding(&b, &first, "tls-off", "high",
"the TCP API has no TLS configured");
findings++;
}
}
if (insecure) {
docker_finding(&b, &first, "insecure-registries", "medium",
"insecure registries are allowed");
findings++;
}
mcp_buf_printf(&b, "],\"findings_count\":%d}", findings);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_BLUE[] = {
{ "hardening_audit",
"Read-only posture audit of the local host: sshd_config (root login, "
@@ -5055,6 +5222,14 @@ const mcp_tool TOOLS_BLUE[] = {
"\"limit\":{\"type\":\"integer\",\"description\":\"entries, default "
"200\"}}}",
t_log_timeline },
{ "docker_audit",
"Audit the local Docker setup (optional root prefix): the docker.sock "
"mode (world-writable is critical), members of the docker group in "
"/etc/group, and daemon.json (TCP hosts, TLS, insecure registries). No "
"daemon call and no container access; read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_docker_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+350
View File
@@ -4267,6 +4267,332 @@ static void t_ntp_probe(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* -------------------------------------------------------- tls_cipher_matrix */
static void t_tls_cipher_matrix(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *defaults[] = {
"DES-CBC3-SHA", "RC4-SHA", "NULL-SHA", "EXP-RC4-MD5",
"AES128-SHA", "AES256-SHA", NULL
};
const char *target = mcp_arg_string(args, "target");
const char *list_arg = mcp_arg_string(args, "ciphers");
const char *version = mcp_arg_string(args, "version");
int port = mcp_arg_int(args, "port", 443);
char conn[320];
char names[12][64];
int nnames = 0;
mcp_buf b;
int first = 1;
int accepted = 0;
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 (!apex_have("openssl")) {
mcp_reply_error(c, "openssl is not installed on this host");
return;
}
if (version == NULL || *version == '\0')
version = "tls1_2";
if (strcmp(version, "tls1_2") != 0 && strcmp(version, "tls1_3") != 0) {
mcp_reply_error(c, "version must be tls1_2 or tls1_3");
return;
}
if (list_arg != NULL && *list_arg != '\0') {
char *copy = strdup(list_arg);
char *save = NULL;
char *tok;
if (copy == NULL) {
mcp_reply_error(c, "out of memory");
return;
}
tok = strtok_r(copy, ",", &save);
while (tok != NULL && nnames < 12) {
while (*tok == ' ' || *tok == '\t')
tok++;
if (*tok != '\0') {
snprintf(names[nnames], sizeof(names[0]), "%.48s", tok);
nnames++;
}
tok = strtok_r(NULL, ",", &save);
}
free(copy);
} else {
for (i = 0; defaults[i] != NULL && nnames < 12; i++)
snprintf(names[nnames++], sizeof(names[0]), "%s", defaults[i]);
}
if (nnames == 0) {
mcp_reply_error(c, "no cipher names given");
return;
}
if (!gated(c, "tls_cipher_matrix", target, port))
return;
tls_conn_string(target, port, conn, sizeof(conn));
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"version\":\"%s\",\"tested\":[", port,
version);
for (i = 0; i < nnames; i++) {
char *argv[12];
int k = 0;
apex_proc p;
int rc;
char proto[64];
char cipher[128];
int ok = 0;
argv[k++] = "openssl";
argv[k++] = "s_client";
argv[k++] = "-connect";
argv[k++] = conn;
argv[k++] = "-servername";
argv[k++] = (char *)target;
argv[k++] = strcmp(version, "tls1_3") == 0 ? "-tls1_3" : "-tls1_2";
if (strcmp(version, "tls1_3") == 0) {
argv[k++] = "-ciphersuites";
} else {
argv[k++] = "-cipher";
}
argv[k++] = names[i];
argv[k] = NULL;
proto[0] = cipher[0] = '\0';
rc = apex_run(argv, 15000, g_cfg.max_output, &p);
if (rc == 0 && p.out != NULL) {
tls_summary(p.out, proto, sizeof(proto), cipher,
sizeof(cipher));
ok = proto[0] != '\0' && cipher[0] != '\0';
apex_proc_free(&p);
}
if (ok)
accepted++;
if (!first)
mcp_buf_puts(&b, ",");
first = 0;
mcp_buf_puts(&b, "{\"cipher\":");
apex_json_str(&b, names[i]);
mcp_buf_printf(&b, ",\"accepted\":%s,\"negotiated\":",
ok ? "true" : "false");
apex_json_str(&b, ok ? cipher : "");
mcp_buf_puts(&b, "}");
}
mcp_buf_printf(&b, "],\"accepted_count\":%d}", accepted);
apex_audit("tls_cipher_matrix", target, port, accepted == 0,
accepted == 0 ? "no weak cipher accepted"
: "weak ciphers accepted", version);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
/* ------------------------------------------------------------ smb_null_session */
static void smb2_put64(unsigned char *p, unsigned long long v)
{
int i;
for (i = 0; i < 8; i++)
p[i] = (unsigned char)(v >> (i * 8));
}
static void smb2_req_header(unsigned char *h, int command,
unsigned long long msgid,
unsigned long long session)
{
memset(h, 0, 64);
memcpy(h, "\xfeSMB", 4);
h[4] = 64;
h[6] = 1; /* CreditCharge */
h[12] = (unsigned char)(command & 0xff);
h[13] = (unsigned char)(command >> 8);
h[14] = 1; /* CreditRequest */
smb2_put64(h + 24, msgid);
smb2_put64(h + 40, session);
}
static int smb2_exchange(int fd, const unsigned char *msg, size_t len,
unsigned char *resp, size_t cap, size_t *rlen)
{
unsigned char nbt[4];
unsigned long need;
nbt[0] = 0x00;
nbt[1] = (unsigned char)(len >> 16);
nbt[2] = (unsigned char)(len >> 8);
nbt[3] = (unsigned char)len;
if (write_bytes(fd, nbt, 4) != 0 || write_bytes(fd, msg, len) != 0)
return -1;
if (apex_net_exact(fd, nbt, 4) != 0)
return -1;
need = ((unsigned long)nbt[1] << 16) | ((unsigned long)nbt[2] << 8) |
nbt[3];
if (need < 64 || need > cap)
return -1;
if (apex_net_exact(fd, resp, need) != 0)
return -1;
*rlen = need;
return 0;
}
static void t_smb_null_session(mcp_conn *c, const mcp_json *args, void *user)
{
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 445);
unsigned char hdr[64];
unsigned char body[64];
unsigned char msg[160];
unsigned char resp[2048];
size_t rlen = 0;
unsigned int status;
unsigned long long session = 0;
int anonymous = 0;
int ipc = 0;
unsigned int ipc_status = 0;
char sess_hex[24];
char status_hex[16];
char ipc_hex[16];
unsigned char path[400];
size_t plen = 0;
mcp_buf b;
int fd;
size_t 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, "smb_null_session", target, port))
return;
fd = tcp_connect_host(target, port, 8000);
if (fd < 0) {
mcp_reply_error(c, "cannot connect to the SMB service");
return;
}
/* negotiate, dialect 2.1 only */
smb2_req_header(hdr, 0, 0, 0);
memset(body, 0, sizeof(body));
body[0] = 36;
body[2] = 1; /* one dialect */
body[4] = 1; /* signing enabled */
for (i = 0; i < 16; i++)
body[16 + i] = (unsigned char)(0x40 + i);
body[36] = 0x10; /* 0x0210 */
body[37] = 0x02;
memcpy(msg, hdr, 64);
memcpy(msg + 64, body, 38);
if (smb2_exchange(fd, msg, 102, resp, sizeof(resp), &rlen) != 0) {
close(fd);
mcp_reply_error(c, "no SMB negotiate response");
return;
}
status = le32_local(resp + 8);
if (status != 0) {
close(fd);
mcp_buf_init(&b);
mcp_buf_printf(&b, "SMB negotiate failed: 0x%08x", status);
mcp_reply_error(c, b.p);
mcp_buf_free(&b);
return;
}
/* anonymous session setup: empty security buffer */
smb2_req_header(hdr, 1, 1, 0);
memset(body, 0, 24);
body[0] = 25;
body[3] = 1; /* signing enabled */
body[12] = 0x58;
body[13] = 0x00;
body[14] = 0;
body[15] = 0;
memcpy(msg, hdr, 64);
memcpy(msg + 64, body, 24);
if (smb2_exchange(fd, msg, 88, resp, sizeof(resp), &rlen) != 0) {
close(fd);
mcp_reply_error(c, "no SMB session response");
return;
}
status = le32_local(resp + 8);
snprintf(status_hex, sizeof(status_hex), "0x%08x", status);
if (status == 0) {
anonymous = 1;
for (i = 0; i < 8; i++)
session |= (unsigned long long)resp[40 + i] << (i * 8);
}
snprintf(sess_hex, sizeof(sess_hex), "%016llx", session);
ipc_hex[0] = '\0';
if (anonymous) {
size_t w = 0;
const char *p;
path[w++] = '\\';
path[w++] = 0;
for (p = target; *p != '\0' && w + 12 < sizeof(path); p++) {
path[w++] = (unsigned char)*p;
path[w++] = 0;
}
plen = w;
{
static const char ipc_name[] = "\\IPC$";
size_t k;
path[w++] = '\\';
path[w++] = 0;
for (k = 1; k < sizeof(ipc_name); k++) {
path[w++] = (unsigned char)ipc_name[k];
path[w++] = 0;
}
plen = w;
}
smb2_req_header(hdr, 3, 2, session);
memset(body, 0, sizeof(body));
body[0] = 9;
body[4] = 0x48;
body[5] = 0x00;
body[6] = (unsigned char)(plen & 0xff);
body[7] = (unsigned char)((plen >> 8) & 0xff);
memcpy(msg, hdr, 64);
memcpy(msg + 64, body, 8);
memcpy(msg + 72, path, plen);
if (smb2_exchange(fd, msg, 72 + plen, resp, sizeof(resp),
&rlen) == 0) {
ipc_status = le32_local(resp + 8);
ipc = ipc_status == 0;
}
snprintf(ipc_hex, sizeof(ipc_hex), "0x%08x", ipc_status);
}
close(fd);
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"smb\":true,\"dialect\":\"SMB 2.1\","
"\"anonymous_session\":%s,\"session_status\":",
port, anonymous ? "true" : "false");
apex_json_str(&b, status_hex);
mcp_buf_puts(&b, ",\"session_id\":");
apex_json_str(&b, sess_hex);
mcp_buf_printf(&b, ",\"ipc_share\":%s,\"ipc_status\":",
ipc ? "true" : "false");
apex_json_str(&b, ipc_hex);
mcp_buf_puts(&b, "}");
apex_audit("smb_null_session", target, port, !anonymous,
anonymous ? "anonymous SMB session accepted"
: "anonymous SMB session refused", "SMB2");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
const mcp_tool TOOLS_PROTO[] = {
{ "ftp_probe",
"One-connection FTP check: read the 220 banner, ask FEAT, then try the "
@@ -4504,6 +4830,30 @@ const mcp_tool TOOLS_PROTO[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 123\"}},"
"\"required\":[\"target\"]}",
t_ntp_probe },
{ "tls_cipher_matrix",
"Probe one TLS endpoint with a list of weak cipher suites (3DES, RC4, "
"NULL, EXPORT, CBC by default) for TLS 1.2 or 1.3 and report which ones "
"negotiate. One openssl s_client per cipher, gated once. Gate: the target "
"must be in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 443\"},"
"\"version\":{\"type\":\"string\",\"enum\":[\"tls1_2\",\"tls1_3\"],"
"\"description\":\"default tls1_2\"},"
"\"ciphers\":{\"type\":\"string\",\"description\":\"comma list, "
"max 12\"}},"
"\"required\":[\"target\"]}",
t_tls_cipher_matrix },
{ "smb_null_session",
"Negotiate SMB 2.1, then try an anonymous SESSION_SETUP (empty security "
"buffer) and, if accepted, a TREE_CONNECT to \\\\host\\IPC$. Reports the "
"session status, session id and whether IPC$ is reachable. No share "
"enumeration, no file access. Gate: the target must be in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 445\"}},"
"\"required\":[\"target\"]}",
t_smb_null_session },
};
const size_t TOOLS_PROTO_N = sizeof(TOOLS_PROTO) / sizeof(TOOLS_PROTO[0]);
+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 = 124
EXPECTED_TOOLS = 127
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.
+148 -4
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("124 tools registered", len(tools) == 124, len(tools))
check("127 tools registered", len(tools) == 127, 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"]) == 124)
check("http tools/list", len(listing["result"]["tools"]) == 127)
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
@@ -4096,7 +4096,7 @@ def rdp_handler(failure):
return handle
def smb2_negotiate_response():
def smb2_negotiate_response(dialect=0x0311):
hdr = b"\xfeSMB" + struct.pack("<H", 64) + struct.pack("<H", 1)
hdr += struct.pack("<I", 0)
hdr += struct.pack("<H", 0) + struct.pack("<H", 1)
@@ -4106,7 +4106,7 @@ def smb2_negotiate_response():
hdr += b"\x00" * 16
body = struct.pack("<H", 65)
body += struct.pack("<H", 3)
body += struct.pack("<H", 0x0311)
body += struct.pack("<H", dialect)
body += struct.pack("<H", 0)
body += bytes(range(16))
body += struct.pack("<I", 0x0000000f)
@@ -5604,6 +5604,150 @@ cache_srv.server_close()
shutil.rmtree(app_dir, ignore_errors=True)
shutil.rmtree(timeline_home, ignore_errors=True)
print("\n== TLS cipher matrix, SMB null session and Docker ==")
tls2_dir = tempfile.mkdtemp(prefix="apex-tls2-")
tls2_cert = os.path.join(tls2_dir, "cert.pem")
tls2_key = os.path.join(tls2_dir, "key.pem")
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
"-keyout", tls2_key, "-out", tls2_cert, "-days", "2",
"-subj", "/CN=localhost"],
check=True, capture_output=True)
tls2_srv, tls2_port = tls_server(tls2_cert, tls2_key)
def smb_null_header(command, status, msgid, session):
hdr = bytearray(64)
hdr[0:4] = b"\xfeSMB"
hdr[4] = 64
hdr[6] = 1
struct.pack_into("<I", hdr, 8, status)
struct.pack_into("<H", hdr, 12, command)
struct.pack_into("<H", hdr, 14, 1)
struct.pack_into("<Q", hdr, 24, msgid)
struct.pack_into("<Q", hdr, 40, session)
return bytes(hdr)
def smb_nbt(msg):
return b"\x00" + len(msg).to_bytes(3, "big") + msg
def smb_null_handler(deny):
def handle(conn):
head = conn.recv(4)
if len(head) < 4:
return
need = int.from_bytes(head[1:4], "big")
body = b""
while len(body) < need:
chunk = conn.recv(need - len(body))
if not chunk:
return
body += chunk
conn.sendall(smb2_negotiate_response(0x0210))
head = conn.recv(4)
need = int.from_bytes(head[1:4], "big")
body = b""
while len(body) < need:
chunk = conn.recv(need - len(body))
if not chunk:
return
body += chunk
status = 0xC0000022 if deny else 0
resp = (smb_null_header(1, status, 1, 0x1122334455667788) +
struct.pack("<HHHH", 9, 0, 0, 0))
conn.sendall(smb_nbt(resp))
if deny:
return
head = conn.recv(4)
need = int.from_bytes(head[1:4], "big")
body = b""
while len(body) < need:
chunk = conn.recv(need - len(body))
if not chunk:
return
body += chunk
resp = (smb_null_header(3, 0, 2, 0x1122334455667788) +
struct.pack("<HBBII", 16, 2, 0, 0, 0x001f01ff))
conn.sendall(smb_nbt(resp))
time.sleep(0.05)
return handle
smb_ok_srv, smb_ok_port = start_line_server(smb_null_handler(False))
smb_deny_srv, smb_deny_port = start_line_server(smb_null_handler(True))
docker_root = tempfile.mkdtemp(prefix="apex-docker-")
os.makedirs(os.path.join(docker_root, "var", "run"))
os.makedirs(os.path.join(docker_root, "etc", "docker"))
sock_path = os.path.join(docker_root, "var", "run", "docker.sock")
with open(sock_path, "w") as f:
f.write("fake socket")
os.chmod(sock_path, 0o666)
with open(os.path.join(docker_root, "etc", "group"), "w") as f:
f.write("root:x:0:\n")
f.write("docker:x:999:alice,bob\n")
with open(os.path.join(docker_root, "etc", "docker", "daemon.json"), "w") as f:
f.write('{"hosts":["tcp://0.0.0.0:2375"],'
'"insecure-registries":["reg.local:5000"]}')
deep_home3 = tempfile.mkdtemp(prefix="apex-deep3-")
write_scope(deep_home3, {"label": "deep3", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(tls2_port), str(smb_ok_port),
str(smb_deny_port)]})
res, _ = run([
call(1, "tls_cipher_matrix", target="127.0.0.1", port=tls2_port,
ciphers="AES128-SHA,RC4-SHA"),
call(2, "smb_null_session", target="127.0.0.1", port=smb_ok_port),
call(3, "smb_null_session", target="127.0.0.1", port=smb_deny_port),
call(4, "docker_audit", root=docker_root),
call(5, "tls_cipher_matrix", target="198.51.100.9", port=443),
call(6, "docker_audit", root="/nonexistent-docker"),
], home=deep_home3)
by_id = {r.get("id"): r for r in res}
ciphers = json.loads(text(by_id[1]))
by_cipher = {e["cipher"]: e for e in ciphers["tested"]}
check("tls_cipher_matrix probes every cipher",
len(ciphers["tested"]) == 2 and
by_cipher["AES128-SHA"]["accepted"] is True, ciphers)
check("tls_cipher_matrix counts the accepted ciphers",
ciphers["accepted_count"] >= 1, ciphers)
smb_ok = json.loads(text(by_id[2]))
check("smb_null_session establishes the anonymous session",
smb_ok["anonymous_session"] is True and
smb_ok["session_status"] == "0x00000000" and
smb_ok["session_id"] == "1122334455667788", smb_ok)
check("smb_null_session connects to IPC$",
smb_ok["ipc_share"] is True and smb_ok["ipc_status"] == "0x00000000",
smb_ok)
smb_deny = json.loads(text(by_id[3]))
check("smb_null_session reports a refused anonymous session",
smb_deny["anonymous_session"] is False and
smb_deny["session_status"] == "0xc0000022" and
smb_deny["ipc_share"] is False, smb_deny)
docker = json.loads(text(by_id[4]))
check("docker_audit reads the socket and group",
docker["socket"]["exists"] is True and
docker["socket"]["world_writable"] is True and
docker["docker_group"]["members"] == ["alice", "bob"], docker)
check("docker_audit flags the exposed API and insecure registries",
{"socket-world-writable", "docker-group-members", "api-tcp", "tls-off",
"insecure-registries"} ==
{f["id"] for f in docker["findings"]}, docker)
check("docker_audit survives a missing root",
json.loads(text(by_id[6]))["socket"]["exists"] is False,
text(by_id[6]))
check("tls_cipher_matrix refuses an out-of-scope target", err(by_id[5]),
text(by_id[5]))
tls2_srv.close()
smb_ok_srv.close()
smb_deny_srv.close()
shutil.rmtree(tls2_dir, ignore_errors=True)
shutil.rmtree(docker_root, ignore_errors=True)
shutil.rmtree(deep_home3, 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"})