apex-twin 1.28.0: WinRM probe, snmpd and rsyslog audits

Red:
- winrm_probe: one unauthenticated GET to /wsman (5985; TLS on 5986);
  401/405 with a Negotiate/NTLM/Kerberos challenge identifies WinRM, the
  response is saved as evidence.

Blue:
- snmpd_audit: snmpd.conf (root prefix) rocommunity/rwcommunity/community/
  com2sec; lists communities with mode and flags rw, public/private/default and
  com2sec rules accepting any source.
- rsyslog_audit: rsyslog.conf and rsyslog.d (root prefix): remote targets
  (@@ TCP, @ UDP), world-writable configs and a dedicated auth rule; flags
  missing auth logging and missing remote forwarding.

Tests: WinRM 401 fixture, plain HTTP server, snmpd.conf and full/sparse rsyslog
trees. 776 checks, ASan suite green, analyze clean, release-check green
including distcheck 1.28.0.

Fixture note: the community mode buffer was 8 bytes and truncated com2sec to
com2se; it is 16 now.
This commit is contained in:
lotherk committed 2026-11-21 19:20:01 +00:00
1 parent 0bfd94519d
commit 4d21af6535
9 files changed
+635 -15

No files matched your search

+17 -1
View File
@@ -8,7 +8,23 @@ 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.27.0 — 2026-11-21 — this change
## 1.28.0 — 2026-11-21 — this change
- **WinRM** (`winrm_probe`): one unauthenticated GET to /wsman (5985, TLS on
5986); 401/405 with a Negotiate/NTLM/Kerberos challenge identifies WinRM;
the response is evidence on a hit.
- **snmpd** (`snmpd_audit`): parses snmpd.conf (root prefix) for rocommunity,
rwcommunity, community and com2sec; lists each community with its mode and
flags rw communities, public/private/default strings and com2sec rules that
accept any source.
- **rsyslog** (`rsyslog_audit`): parses rsyslog.conf and rsyslog.d (root
prefix): remote targets (@@ TCP, @ UDP), world-writable configs and whether a
dedicated auth/authpriv rule exists; flags missing auth logging and missing
remote forwarding.
- Tests with a WinRM 401 fixture, a plain HTTP server, an snmpd.conf and full
and sparse rsyslog trees. 776 checks. Coverage 81.0%.
## 1.27.0 — 2026-11-21 — 0bfd945
- **Kerberos** (`kerberos_discovery`): gated dig SRV queries for
_kerberos._tcp, _kerberos._udp and _kpasswd._tcp, reporting priority, weight,
+13 -8
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.
**149 tools · 765 end-to-end checks · 340 fuzz cases · 81.0% line coverage · ~614 KiB**
**152 tools · 776 end-to-end checks · 340 fuzz cases · 81.0% line coverage · ~626 KiB**
```
$ ./apex-twin --check
{"version":"1.27.0","tools":149,...,"scope":{"loaded":true,...}}
{"version":"1.28.0","tools":152,...,"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 (149)
## Tools (152)
### Scope and bookkeeping
@@ -292,6 +292,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `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 |
| `winrm_probe` | GET /wsman: 401/405 with Negotiate/NTLM/Kerberos identifies WinRM; evidence on hit |
| `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 |
@@ -346,6 +347,8 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `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 |
| `snmpd_audit` | snmpd.conf communities: ro/rw/com2sec, public/private, default source |
| `rsyslog_audit` | rsyslog remote targets, world-writable configs, missing auth logging |
### ESP32
@@ -587,6 +590,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| Logrotate | 100 files, read-only |
| Kerberos | three SRV queries |
| NFS/Samba | config reads only; optional root prefix |
| WinRM | one unauthenticated GET; no auth attempt |
| snmpd/rsyslog | config reads only; optional root prefix |
| USB audit | 200 devices, sysfs reads only |
---
@@ -598,7 +603,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 765 end-to-end checks
make test # version check + gate audit + 776 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
@@ -713,7 +718,7 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
email_security_audit, smtp_open_relay, dns_open_resolver,
crlf_probe, dns_version_bind, oidc_discovery,
security_txt, http2_probe, ssh_hostkey_fingerprint,
kerberos_discovery
kerberos_discovery, winrm_probe
src/tools_blue.c hardening_audit, log_audit, ioc_scan, web_log_audit,
detect_rules, integrity_baseline, mitre_map,
process_snapshot, persistence_audit, net_baseline,
@@ -756,7 +761,7 @@ examples/ scope.json
## Status
1.27.0. Built and run: 149 tools, 765 checks, 340 fuzz cases and 81.0% line
1.28.0. Built and run: 152 tools, 776 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
@@ -800,8 +805,8 @@ 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; 1.27 added
Kerberos discovery, NFS export and Samba audits, again without changing an
existing file format.
Kerberos discovery, NFS export and Samba audits; 1.28 added a WinRM probe and
snmpd/rsyslog config audits, again without changing an existing file format.
Not yet wired into a fleet router, and there is no TLS interception.
+3 -1
View File
@@ -9,7 +9,7 @@ problem.
The supported line is the one printed by `apex-twin --version` for the tree you
built; this document ships with that same tree. At the time of writing the line
is **1.27.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.28.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
line. The 1.0 line promises that the on-disk JSON formats for findings, assets
and traffic only gain fields, so state stays readable; older builds are still
rebuilt rather than patched in place.
@@ -66,6 +66,8 @@ only narrow what the proxy does (the scope gate still runs first).
- **Firmware writing needs an explicit confirmation.** `esp_flash` refuses
without `confirm=true`, validates an absolute image path and audits the
attempt; it exists to provision the operator's own board.
- **Config audits are local reads.** `snmpd_audit` and `rsyslog_audit` parse
configuration files; `winrm_probe` issues one unauthenticated GET to /wsman.
- **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.
+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.27.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.28.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.27.0"
#define APEX_VERSION "1.28.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+378
View File
@@ -6367,6 +6367,368 @@ static void t_samba_audit(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&findings);
}
/* --------------------------------------------------------------- snmpd_audit */
typedef struct {
char community[64];
char mode[16];
} snmp_comm;
typedef struct {
mcp_buf *b;
int first;
int count;
int files;
snmp_comm comms[20];
int ncomms;
} snmpd_ctx;
static void snmpd_finding(snmpd_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 snmpd_comm_add(snmpd_ctx *ctx, const char *community,
const char *mode)
{
int i;
for (i = 0; i < ctx->ncomms; i++)
if (strcmp(ctx->comms[i].community, community) == 0 &&
strcmp(ctx->comms[i].mode, mode) == 0)
return;
if (ctx->ncomms < 20) {
snprintf(ctx->comms[ctx->ncomms].community,
sizeof(ctx->comms[0].community), "%.48s", community);
snprintf(ctx->comms[ctx->ncomms].mode,
sizeof(ctx->comms[0].mode), "%.12s", mode);
ctx->ncomms++;
}
}
static int snmpd_weak(const char *community)
{
return strcmp(community, "public") == 0 ||
strcmp(community, "private") == 0 ||
strcmp(community, "default") == 0;
}
static void snmpd_scan_file(snmpd_ctx *ctx, const char *path)
{
FILE *f = fopen(path, "rb");
char *line = NULL;
size_t cap = 0;
int lineno = 0;
if (f == NULL)
return;
ctx->files++;
while (getline(&line, &cap, f) >= 0) {
char *t = line;
char *tokens[6];
int ntok = 0;
char *save = NULL;
char *tok;
lineno++;
while (*t == ' ' || *t == '\t')
t++;
trim_eol(t);
if (*t == '\0' || *t == '#')
continue;
tok = strtok_r(t, " \t", &save);
while (tok != NULL && ntok < 6) {
tokens[ntok++] = tok;
tok = strtok_r(NULL, " \t", &save);
}
if (ntok < 2)
continue;
if (strcmp(tokens[0], "rocommunity") == 0 ||
strcmp(tokens[0], "rocommunity6") == 0) {
snmpd_comm_add(ctx, tokens[1], "ro");
if (snmpd_weak(tokens[1]))
snmpd_finding(ctx, path, lineno, "weak-community",
"medium",
"read-only community is public/private/default");
} else if (strcmp(tokens[0], "rwcommunity") == 0 ||
strcmp(tokens[0], "rwcommunity6") == 0) {
snmpd_comm_add(ctx, tokens[1], "rw");
snmpd_finding(ctx, path, lineno, "rw-community", "high",
"write community is configured");
} else if (strcmp(tokens[0], "community") == 0) {
snmpd_comm_add(ctx, tokens[1], "v1");
if (snmpd_weak(tokens[1]))
snmpd_finding(ctx, path, lineno, "weak-community",
"medium",
"SNMPv1 community is public/private/default");
} else if (strcmp(tokens[0], "com2sec") == 0 ||
strcmp(tokens[0], "com2sec6") == 0) {
if (ntok >= 4) {
snmpd_comm_add(ctx, tokens[3], "com2sec");
if (snmpd_weak(tokens[3]))
snmpd_finding(ctx, path, lineno, "weak-community",
"medium",
"com2sec uses a public/private/default community");
if (strcmp(tokens[2], "default") == 0)
snmpd_finding(ctx, path, lineno, "default-source",
"medium",
"com2sec accepts the community from any source");
}
}
}
free(line);
fclose(f);
}
static void t_snmpd_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;
snmpd_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/snmp/snmpd.conf", base);
snmpd_scan_file(&ctx, path);
snprintf(path, sizeof(path), "%s/etc/snmpd.conf", base);
snmpd_scan_file(&ctx, path);
snprintf(path, sizeof(path), "%s/etc/snmp/snmpd.conf.d", base);
{
DIR *d = opendir(path);
struct dirent *ent;
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char full[1024];
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (nl < 6 || strcmp(ent->d_name + nl - 5, ".conf") != 0)
continue;
snprintf(full, sizeof(full), "%.800s/%.160s", path,
ent->d_name);
snmpd_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,\"communities\":[", ctx.files);
{
int i;
for (i = 0; i < ctx.ncomms; i++) {
if (i > 0)
mcp_buf_puts(&b, ",");
mcp_buf_puts(&b, "{\"community\":");
apex_json_str(&b, ctx.comms[i].community);
mcp_buf_puts(&b, ",\"mode\":");
apex_json_str(&b, ctx.comms[i].mode);
mcp_buf_puts(&b, "}");
}
}
mcp_buf_printf(&b, "],\"findings_count\":%d,\"findings\":[", 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);
}
/* -------------------------------------------------------------- rsyslog_audit */
typedef struct {
mcp_buf *b;
int first;
int count;
int files;
int auth_logged;
char targets[10][256];
int ntargets;
} rsys_ctx;
static void rsys_finding(rsys_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 rsys_target_add(rsys_ctx *ctx, const char *target)
{
int i;
for (i = 0; i < ctx->ntargets; i++)
if (strcmp(ctx->targets[i], target) == 0)
return;
if (ctx->ntargets < 10)
snprintf(ctx->targets[ctx->ntargets++],
sizeof(ctx->targets[0]), "%.200s", target);
}
static void rsys_scan_file(rsys_ctx *ctx, const char *path)
{
FILE *f = fopen(path, "rb");
struct stat st;
char *line = NULL;
size_t cap = 0;
if (f == NULL)
return;
ctx->files++;
if (stat(path, &st) == 0 && (st.st_mode & 0002) != 0)
rsys_finding(ctx, path, 0, "world-writable", "high",
"rsyslog configuration is writable by anyone");
while (getline(&line, &cap, f) >= 0) {
char *t = line;
const char *at;
while (*t == ' ' || *t == '\t')
t++;
trim_eol(t);
if (*t == '\0' || *t == '#')
continue;
if (strstr(t, "auth,authpriv") != NULL ||
strstr(t, "authpriv.*") != NULL ||
strstr(t, "auth.*") != NULL)
ctx->auth_logged = 1;
at = strchr(t, '@');
if (at != NULL && at[1] != '\0') {
char target[256];
size_t w = 0;
while (*at != '\0' && *at != ' ' && *at != '\t' &&
w + 1 < sizeof(target))
target[w++] = *at++;
target[w] = '\0';
if (strchr(target, '.') != NULL)
rsys_target_add(ctx, target);
}
}
free(line);
fclose(f);
}
static void t_rsyslog_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;
rsys_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/rsyslog.conf", base);
rsys_scan_file(&ctx, path);
snprintf(path, sizeof(path), "%s/etc/rsyslog.d", base);
{
DIR *d = opendir(path);
struct dirent *ent;
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char full[1024];
size_t nl = strlen(ent->d_name);
if (ent->d_name[0] == '.')
continue;
if (nl < 6 || strcmp(ent->d_name + nl - 5, ".conf") != 0)
continue;
snprintf(full, sizeof(full), "%.800s/%.160s", path,
ent->d_name);
rsys_scan_file(&ctx, full);
}
closedir(d);
}
}
if (!ctx.auth_logged)
rsys_finding(&ctx, base, 0, "no-auth-logging", "medium",
"no dedicated auth/authpriv log rule");
if (ctx.ntargets == 0)
rsys_finding(&ctx, base, 0, "no-remote-logging", "low",
"logs are not forwarded to another host");
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, base);
mcp_buf_printf(&b, ",\"files\":%d,\"auth_logged\":%s,\"targets\":[",
ctx.files, ctx.auth_logged ? "true" : "false");
{
int i;
for (i = 0; i < ctx.ntargets; i++) {
if (i > 0)
mcp_buf_puts(&b, ",");
apex_json_str(&b, ctx.targets[i]);
}
}
mcp_buf_printf(&b, "],\"findings_count\":%d,\"findings\":[", 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, "
@@ -6728,6 +7090,22 @@ const mcp_tool TOOLS_BLUE[] = {
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_samba_audit },
{ "snmpd_audit",
"Parse snmpd.conf (root prefix): rocommunity/rwcommunity/community/"
"com2sec, listing each community with its mode and flagging rw "
"communities, public/private/default strings and com2sec sources set to "
"default. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_snmpd_audit },
{ "rsyslog_audit",
"Parse rsyslog.conf and rsyslog.d (root prefix): remote targets (@@ TCP, "
"@ UDP), world-writable configuration files and whether a dedicated "
"auth/authpriv rule exists. Flags missing auth logging and missing remote "
"forwarding. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_rsyslog_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+101
View File
@@ -4803,6 +4803,94 @@ static void t_kerberos_discovery(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* ----------------------------------------------------------------- winrm_probe */
static void t_winrm_probe(mcp_conn *c, const mcp_json *args, void *user)
{
const char *target = mcp_arg_string(args, "target");
const char *path = mcp_arg_string(args, "path");
int port = mcp_arg_int(args, "port", 5985);
int tls = mcp_arg_bool(args, "tls",
port == 5986 || apex_looks_tls(port));
char status[256];
char auth[512];
char server[256];
char *resp = NULL;
size_t len = 0;
int code;
int ntlm = 0;
int negotiate = 0;
int kerberos = 0;
int winrm = 0;
char *evidence = NULL;
mcp_buf b;
(void)user;
if (target == NULL || *target == '\0') {
mcp_reply_error(c, "target is required");
return;
}
if (port <= 0 || port > 65535) {
mcp_reply_error(c, "port out of range");
return;
}
if (path == NULL || *path == '\0')
path = "/wsman";
if (path[0] != '/') {
mcp_reply_error(c, "path must start with /");
return;
}
if (!gated(c, "winrm_probe", target, port))
return;
status[0] = '\0';
auth[0] = server[0] = '\0';
if (apex_http_once(target, port, tls, "GET", path, NULL, NULL, 8000,
&resp, &len, status, sizeof(status)) != 0) {
mcp_reply_error(c, "cannot reach the WinRM endpoint");
return;
}
code = apex_status_code(status);
response_header(resp, len, "WWW-Authenticate", auth, sizeof(auth));
response_header(resp, len, "Server", server, sizeof(server));
if (strcasestr(auth, "NTLM") != NULL)
ntlm = 1;
if (strcasestr(auth, "Negotiate") != NULL)
negotiate = 1;
if (strcasestr(auth, "Kerberos") != NULL)
kerberos = 1;
if ((code == 401 || code == 405) && (ntlm || negotiate || kerberos))
winrm = 1;
if (resp != NULL && find_bytes(resp, len, "WSMAN") &&
code == 200)
winrm = 1;
if (winrm)
evidence = apex_evidence_save("winrm", resp, len);
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"path\":", port);
apex_json_str(&b, path);
mcp_buf_printf(&b, ",\"status\":%d,\"server\":", code);
apex_json_str(&b, server);
mcp_buf_puts(&b, ",\"www_authenticate\":");
apex_json_str(&b, auth);
mcp_buf_printf(&b, ",\"ntlm\":%s,\"negotiate\":%s,\"kerberos\":%s,"
"\"winrm\":%s,\"evidence\":", ntlm ? "true" : "false",
negotiate ? "true" : "false",
kerberos ? "true" : "false", winrm ? "true" : "false");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
apex_audit("winrm_probe", target, port, !winrm,
winrm ? "WinRM endpoint detected" : "no WinRM endpoint", path);
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
free(evidence);
free(resp);
}
const mcp_tool TOOLS_RED[] = {
{ "vuln_check",
"Non-destructive verification of exposed artifacts on one web target: "
@@ -5224,6 +5312,19 @@ const mcp_tool TOOLS_RED[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"dig -p, default 0\"}},"
"\"required\":[\"domain\"]}",
t_kerberos_discovery },
{ "winrm_probe",
"Request /wsman on a Windows host (5985 plain, 5986 TLS) and report the "
"status, Server header and WWW-Authenticate schemes: 401/405 with "
"Negotiate/NTLM/Kerberos identifies WinRM. The response is saved as "
"evidence on a hit. Gate: the target must be in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 5985, "
"5986 selects TLS\"},"
"\"path\":{\"type\":\"string\",\"description\":\"default /wsman\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_winrm_probe },
};
const size_t TOOLS_RED_N = sizeof(TOOLS_RED) / sizeof(TOOLS_RED[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 = 149
EXPECTED_TOOLS = 152
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.
+120 -2
View File
@@ -134,7 +134,7 @@ res, _ = run([
], home=empty)
check("tools/list answers", any(r.get("id") == 1 for r in res))
tools = [r for r in res if r.get("id") == 1][0]["result"]["tools"]
check("149 tools registered", len(tools) == 149, len(tools))
check("152 tools registered", len(tools) == 152, 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"]) == 149)
check("http tools/list", len(listing["result"]["tools"]) == 152)
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
@@ -6813,6 +6813,124 @@ shutil.rmtree(nfs_root, ignore_errors=True)
shutil.rmtree(smb_root, ignore_errors=True)
shutil.rmtree(smb_home, ignore_errors=True)
print("\n== WinRM, snmpd and rsyslog ==")
class _WinrmHandler(http.server.BaseHTTPRequestHandler):
server_version = "Microsoft-HTTPAPI/2.0"
sys_version = ""
def do_GET(self):
body = b"denied"
self.send_response(401)
if urllib.parse.urlsplit(self.path).path == "/wsman":
self.send_header("WWW-Authenticate", "Negotiate")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
class _PlainHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
body = b"hello"
self.send_response(200)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
winrm_srv = http.server.HTTPServer(("127.0.0.1", 0), _WinrmHandler)
winrm_port = winrm_srv.server_address[1]
threading.Thread(target=winrm_srv.serve_forever, daemon=True).start()
plain_srv = http.server.HTTPServer(("127.0.0.1", 0), _PlainHandler)
plain_port = plain_srv.server_address[1]
threading.Thread(target=plain_srv.serve_forever, daemon=True).start()
snmpd_root = tempfile.mkdtemp(prefix="apex-snmpd-")
os.makedirs(os.path.join(snmpd_root, "etc", "snmp"))
with open(os.path.join(snmpd_root, "etc", "snmp", "snmpd.conf"), "w") as f:
f.write("rocommunity public 10.0.0.0/8\n")
f.write("rwcommunity private\n")
f.write("com2sec local default public\n")
rsys_root = tempfile.mkdtemp(prefix="apex-rsys-")
os.makedirs(os.path.join(rsys_root, "etc", "rsyslog.d"))
with open(os.path.join(rsys_root, "etc", "rsyslog.conf"), "w") as f:
f.write("auth,authpriv.* /var/log/auth.log\n")
f.write("*.* @@log.example.test:514\n")
rsys_extra = os.path.join(rsys_root, "etc", "rsyslog.d", "50-default.conf")
with open(rsys_extra, "w") as f:
f.write("*.info /var/log/syslog\n")
os.chmod(rsys_extra, 0o666)
rsys_sparse = tempfile.mkdtemp(prefix="apex-rsyss-")
os.makedirs(os.path.join(rsys_sparse, "etc"))
with open(os.path.join(rsys_sparse, "etc", "rsyslog.conf"), "w") as f:
f.write("*.* /var/log/all.log\n")
logs_home = tempfile.mkdtemp(prefix="apex-logs-home-")
write_scope(logs_home, {"label": "logs", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(winrm_port), str(plain_port)]})
res, _ = run([
call(1, "winrm_probe", target="127.0.0.1", port=winrm_port, tls=False),
call(2, "winrm_probe", target="127.0.0.1", port=plain_port, tls=False),
call(3, "snmpd_audit", root=snmpd_root),
call(4, "rsyslog_audit", root=rsys_root),
call(5, "rsyslog_audit", root=rsys_sparse),
call(6, "winrm_probe", target="198.51.100.9", port=5985),
call(7, "snmpd_audit", root="/nonexistent-snmpd"),
call(8, "rsyslog_audit", root="/nonexistent-rsyslog"),
], home=logs_home)
by_id = {r.get("id"): r for r in res}
wr = json.loads(text(by_id[1]))
check("winrm_probe detects the WinRM endpoint",
wr["winrm"] is True and wr["status"] == 401 and
wr["negotiate"] is True and wr["server"] == "Microsoft-HTTPAPI/2.0", wr)
check("winrm_probe keeps the response as evidence",
wr["evidence"] and os.path.isfile(wr["evidence"]), wr)
plain = json.loads(text(by_id[2]))
check("winrm_probe stays quiet on a plain HTTP server",
plain["winrm"] is False, plain)
snmpd = json.loads(text(by_id[3]))
comms = {(c["community"], c["mode"]) for c in snmpd["communities"]}
check("snmpd_audit lists the communities",
snmpd["files"] == 1 and
{("public", "ro"), ("private", "rw"), ("public", "com2sec")} <= comms,
snmpd)
check("snmpd_audit flags rw, weak and default-source communities",
{"rw-community", "weak-community", "default-source"} <=
{f["kind"] for f in snmpd["findings"]}, snmpd["findings"])
rsys = json.loads(text(by_id[4]))
check("rsyslog_audit reads both files and the auth rule",
rsys["files"] == 2 and rsys["auth_logged"] is True, rsys)
check("rsyslog_audit reports the remote target and writable config",
rsys["targets"] == ["@@log.example.test:514"] and
"world-writable" in {f["kind"] for f in rsys["findings"]}, rsys)
sparse = json.loads(text(by_id[5]))
check("rsyslog_audit flags missing auth and remote logging",
{"no-auth-logging", "no-remote-logging"} <=
{f["kind"] for f in sparse["findings"]}, sparse)
check("winrm_probe refuses an out-of-scope target", err(by_id[6]),
text(by_id[6]))
check("snmpd_audit survives a missing root",
json.loads(text(by_id[7]))["files"] == 0, text(by_id[7]))
check("rsyslog_audit survives a missing root",
json.loads(text(by_id[8]))["files"] == 0, text(by_id[8]))
winrm_srv.shutdown()
winrm_srv.server_close()
plain_srv.shutdown()
plain_srv.server_close()
shutil.rmtree(snmpd_root, ignore_errors=True)
shutil.rmtree(rsys_root, ignore_errors=True)
shutil.rmtree(rsys_sparse, ignore_errors=True)
shutil.rmtree(logs_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"})