apex-twin 1.25.0: OIDC discovery, security.txt, known_hosts audit

Red:
- oidc_discovery: fetches /.well-known/openid-configuration and the OAuth
  authorization-server metadata; reports issuer, authorization, token, JWKS
  and userinfo endpoints with the document as evidence.
- security_txt: fetches /.well-known/security.txt and /security.txt; reports
  Contact entries, Expires and Policy and flags an Expires date in the past.

Blue:
- ssh_known_hosts_audit: /etc/ssh/ssh_known_hosts(2), root and user
  known_hosts (root prefix): entry count, hashed vs plain hosts, ssh-rsa/
  ssh-dss key types and duplicate host keys.

Tests: OIDC metadata, fresh vs expired security.txt, known_hosts tree with
hashed/plain/weak/duplicate entries. 747 checks, ASan suite green, analyze
clean, release-check green including distcheck 1.25.0.
This commit is contained in:
lotherk committed 2026-11-21 18:12:48 +00:00
1 parent 2afb34eb89
commit 492b29d494
9 files changed
+632 -14

No files matched your search

+15 -1
View File
@@ -8,7 +8,21 @@ 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.24.0 — 2026-11-21 — this change
## 1.25.0 — 2026-11-21 — this change
- **OIDC** (`oidc_discovery`): fetches /.well-known/openid-configuration and the
OAuth authorization-server metadata, reporting issuer, authorization, token,
JWKS and userinfo endpoints; the document is saved as evidence.
- **security.txt** (`security_txt`): fetches /.well-known/security.txt and
/security.txt, reports Contact entries, Expires and Policy, and flags an
Expires date in the past.
- **Blue** (`ssh_known_hosts_audit`): /etc/ssh/ssh_known_hosts(2), root and user
known_hosts (root prefix): entry count, hashed vs plain hosts, ssh-rsa/
ssh-dss key types and duplicate host keys.
- Tests with OIDC metadata, fresh and expired security.txt and a known_hosts
tree. 747 checks. Coverage 80.8%.
## 1.24.0 — 2026-11-21 — 2afb34e
- **NTP monlist** (`ntp_monlist_probe`): sends the 8-byte mode-7 MON_GETLIST
request and reports a mode-7 reply larger than the request as monlist
+14 -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.
**140 tools · 737 end-to-end checks · 340 fuzz cases · 80.6% line coverage · ~585 KiB**
**143 tools · 747 end-to-end checks · 340 fuzz cases · 80.8% line coverage · ~601 KiB**
```
$ ./apex-twin --check
{"version":"1.24.0","tools":140,...,"scope":{"loaded":true,...}}
{"version":"1.25.0","tools":143,...,"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 (140)
## Tools (143)
### Scope and bookkeeping
@@ -287,6 +287,8 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `crlf_probe` | Encoded CRLF in one parameter; detects an injected response header |
| `dns_version_bind` | CHAOS TXT version.bind/hostname.bind; reports version disclosure |
| `ntp_monlist_probe` | Mode-7 MON_GETLIST; monlist enabled, entry estimate, amplification |
| `oidc_discovery` | OpenID/OAuth metadata: issuer, auth/token/JWKS/userinfo endpoints, evidence |
| `security_txt` | security.txt Contact/Expires/Policy; expired documents flagged |
| `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 |
@@ -337,6 +339,7 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
| `selinux_audit` | enforce, SELINUX=/SELINUXTYPE=, boolean count; disabled/permissive findings |
| `audit_rules` | audit.rules/rules.d: rule count, -e 2, execve, watches on passwd/shadow/sudoers/group |
| `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 |
### ESP32
@@ -571,6 +574,8 @@ The full threat model, trust boundaries and a hardening checklist are in
| CRLF probe | one request, marker header only |
| Audit rules | 100 files, read-only |
| NTP/DNS version | one or two queries, no state |
| OIDC/security.txt | two well-known GETs each |
| Known hosts | 100 files, read-only |
| USB audit | 200 devices, sysfs reads only |
---
@@ -582,7 +587,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
```sh
make # apex-twin
make test # version check + gate audit + 737 end-to-end checks
make test # version check + gate audit + 747 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
@@ -695,7 +700,8 @@ src/tools_red.c vuln_check, subdomain_enum, cred_test, vhost_discovery,
rpc_probe, ntp_probe, api_auth_audit, cache_audit,
tls_cipher_matrix, smb_null_session, smb_shares,
email_security_audit, smtp_open_relay, dns_open_resolver,
crlf_probe, dns_version_bind
crlf_probe, dns_version_bind, oidc_discovery,
security_txt
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,
@@ -738,7 +744,7 @@ examples/ scope.json
## Status
1.24.0. Built and run: 140 tools, 737 checks, 340 fuzz cases and 80.6% line
1.25.0. Built and run: 143 tools, 747 checks, 340 fuzz cases and 80.8% 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
@@ -780,7 +786,8 @@ audit; 1.21 added SMB share probing, e-mail security checks and a web-root
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, again without changing an existing file format.
audit; 1.25 added OIDC discovery, security.txt and known-hosts checks, again
without changing an existing file format.
Not yet wired into a fleet router, and there is no TLS interception.
+4 -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.24.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
is **1.25.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.
- **Metadata fetches are plain GETs.** `oidc_discovery` and `security_txt`
request their well-known paths without credentials; `ssh_known_hosts_audit`
reads local key files.
- **NTP and DNS version checks are single queries.** `ntp_monlist_probe` sends
one mode-7 GETLIST and reports the reply size; `dns_version_bind` sends two
CHAOS TXT queries; `usb_audit` reads sysfs.
+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.24.0" "User Commands"
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.25.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.24.0"
#define APEX_VERSION "1.25.0"
#define APEX_MAX_OUT (1u << 20)
#define APEX_PATH_MAX 512
#define APEX_PATH_FULL 1024
+182
View File
@@ -5701,6 +5701,181 @@ static void t_usb_audit(mcp_conn *c, const mcp_json *args, void *user)
free(devs);
}
/* -------------------------------------------------------- ssh_known_hosts_audit */
typedef struct {
mcp_buf *b;
int first;
int count;
int files;
int hosts;
int hashed;
int plain;
int weak;
int duplicates;
char seen[128][200];
int nseen;
} kh_ctx;
static void kh_finding(kh_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 kh_scan_file(kh_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 *tokens[4];
int ntok = 0;
char *save = NULL;
char *tok;
char *copy;
char sig[200];
lineno++;
while (line[0] == ' ' || line[0] == '\t')
memmove(line, line + 1, strlen(line));
trim_eol(line);
if (line[0] == '\0' || line[0] == '#')
continue;
copy = strdup(line);
if (copy == NULL)
continue;
tok = strtok_r(copy, " \t", &save);
while (tok != NULL && ntok < 4) {
tokens[ntok++] = tok;
tok = strtok_r(NULL, " \t", &save);
}
if (ntok >= 2) {
ctx->hosts++;
if (strncmp(tokens[0], "|1|", 3) == 0)
ctx->hashed++;
else
ctx->plain++;
if (strcmp(tokens[1], "ssh-rsa") == 0 ||
strcmp(tokens[1], "ssh-dss") == 0) {
ctx->weak++;
kh_finding(ctx, path, lineno, "weak-key-type", "low",
"known_hosts entry uses ssh-rsa or ssh-dss");
}
snprintf(sig, sizeof(sig), "%.60s|%.20s|%.80s", tokens[0],
tokens[1], ntok >= 3 ? tokens[2] : "");
{
int i;
int dup = 0;
for (i = 0; i < ctx->nseen; i++)
if (strcmp(ctx->seen[i], sig) == 0)
dup = 1;
if (dup) {
ctx->duplicates++;
kh_finding(ctx, path, lineno, "duplicate", "low",
"the same host key appears more than once");
} else if (ctx->nseen < 128) {
snprintf(ctx->seen[ctx->nseen],
sizeof(ctx->seen[0]), "%s", sig);
ctx->nseen++;
}
}
}
free(copy);
}
free(line);
fclose(f);
}
static void t_ssh_known_hosts_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;
kh_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/ssh/ssh_known_hosts", base);
kh_scan_file(&ctx, path);
snprintf(path, sizeof(path), "%s/etc/ssh/ssh_known_hosts2", base);
kh_scan_file(&ctx, path);
snprintf(path, sizeof(path), "%s/root/.ssh/known_hosts", base);
kh_scan_file(&ctx, path);
snprintf(path, sizeof(path), "%s/home", base);
{
DIR *d = opendir(path);
struct dirent *ent;
if (d != NULL) {
while ((ent = readdir(d)) != NULL) {
char kh[1024];
if (ent->d_name[0] == '.')
continue;
snprintf(kh, sizeof(kh), "%.700s/%.160s/.ssh/known_hosts",
path, ent->d_name);
kh_scan_file(&ctx, kh);
}
closedir(d);
}
}
snprintf(path, sizeof(path), "%.450s%.450s/.ssh/known_hosts", base,
g_cfg.home);
kh_scan_file(&ctx, path);
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"root\":");
apex_json_str(&b, base);
mcp_buf_printf(&b, ",\"files\":%d,\"hosts\":%d,\"hashed\":%d,"
"\"plain\":%d,\"weak\":%d,\"duplicates\":%d,"
"\"findings_count\":%d,\"findings\":[",
ctx.files, ctx.hosts, ctx.hashed, ctx.plain, ctx.weak,
ctx.duplicates, 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, "
@@ -6035,6 +6210,13 @@ const mcp_tool TOOLS_BLUE[] = {
"\"limit\":{\"type\":\"integer\",\"description\":\"devices, default "
"200\"}}}",
t_usb_audit },
{ "ssh_known_hosts_audit",
"Audit known_hosts files (/etc/ssh/ssh_known_hosts, root and user .ssh, "
"optional root prefix): count entries, hashed vs plain hosts, ssh-rsa/"
"ssh-dss key types and duplicate host keys. Read-only.",
"{\"type\":\"object\",\"properties\":{"
"\"root\":{\"type\":\"string\",\"description\":\"prefix, default empty\"}}}",
t_ssh_known_hosts_audit },
};
const size_t TOOLS_BLUE_N = sizeof(TOOLS_BLUE) / sizeof(TOOLS_BLUE[0]);
+271
View File
@@ -4169,6 +4169,256 @@ static void t_dns_version_bind(mcp_conn *c, const mcp_json *args, void *user)
mcp_buf_free(&b);
}
/* --------------------------------------------------------------- oidc_discovery */
static void t_oidc_discovery(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = {
"/.well-known/openid-configuration",
"/.well-known/oauth-authorization-server", NULL
};
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 80);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port));
mcp_buf b;
int first = 1;
int found = 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 (!gated(c, "oidc_discovery", target, port))
return;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"specs\":[", port);
for (i = 0; paths[i] != NULL; i++) {
char status[256];
char *resp = NULL;
size_t len = 0;
int code;
char issuer[256];
char auth_ep[256];
char token_ep[256];
char jwks[256];
char userinfo[256];
char *evidence;
status[0] = '\0';
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
8000, &resp, &len, status, sizeof(status)) != 0)
continue;
code = apex_status_code(status);
if (code != 200 || resp == NULL ||
strstr(resp, "issuer") == NULL ||
(strstr(resp, "authorization_endpoint") == NULL &&
strstr(resp, "token_endpoint") == NULL)) {
free(resp);
continue;
}
json_field(resp, "issuer", issuer, sizeof(issuer));
json_field(resp, "authorization_endpoint", auth_ep,
sizeof(auth_ep));
json_field(resp, "token_endpoint", token_ep, sizeof(token_ep));
json_field(resp, "jwks_uri", jwks, sizeof(jwks));
json_field(resp, "userinfo_endpoint", userinfo, sizeof(userinfo));
evidence = apex_evidence_save("oidc", resp, len);
found++;
if (!first)
mcp_buf_puts(&b, ",");
first = 0;
mcp_buf_puts(&b, "{\"path\":");
apex_json_str(&b, paths[i]);
mcp_buf_puts(&b, ",\"issuer\":");
apex_json_str(&b, issuer);
mcp_buf_puts(&b, ",\"authorization_endpoint\":");
apex_json_str(&b, auth_ep);
mcp_buf_puts(&b, ",\"token_endpoint\":");
apex_json_str(&b, token_ep);
mcp_buf_puts(&b, ",\"jwks_uri\":");
apex_json_str(&b, jwks);
mcp_buf_puts(&b, ",\"userinfo_endpoint\":");
apex_json_str(&b, userinfo);
mcp_buf_puts(&b, ",\"evidence\":");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
free(evidence);
free(resp);
}
mcp_buf_printf(&b, "],\"count\":%d}", found);
apex_audit("oidc_discovery", target, port, found == 0,
found == 0 ? "no OIDC metadata" : "OIDC metadata exposed",
"well-known");
mcp_reply_json(c, b.p);
mcp_buf_free(&b);
}
/* ---------------------------------------------------------------- security_txt */
static int security_expired(const char *expires)
{
int y = 0;
int m = 0;
int d = 0;
time_t now = time(NULL);
struct tm tmv = *gmtime(&now);
if (sscanf(expires, "%d-%d-%d", &y, &m, &d) != 3)
return 0;
if (y < tmv.tm_year + 1900)
return 1;
if (y > tmv.tm_year + 1900)
return 0;
if (m < tmv.tm_mon + 1)
return 1;
if (m > tmv.tm_mon + 1)
return 0;
return d < tmv.tm_mday;
}
static void t_security_txt(mcp_conn *c, const mcp_json *args, void *user)
{
static const char *paths[] = { "/.well-known/security.txt",
"/security.txt", NULL };
const char *target = mcp_arg_string(args, "target");
int port = mcp_arg_int(args, "port", 80);
int tls = mcp_arg_bool(args, "tls", apex_looks_tls(port));
mcp_buf b;
int first = 1;
int found = 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 (!gated(c, "security_txt", target, port))
return;
mcp_buf_init(&b);
mcp_buf_puts(&b, "{\"target\":");
apex_json_str(&b, target);
mcp_buf_printf(&b, ",\"port\":%d,\"documents\":[", port);
for (i = 0; paths[i] != NULL; i++) {
char status[256];
char *resp = NULL;
size_t len = 0;
int code;
char contacts[5][256];
int ncontacts = 0;
char expires[128];
char policy[256];
char *copy;
char *save = NULL;
char *line;
int expired = 0;
char *evidence;
status[0] = '\0';
if (apex_http_once(target, port, tls, "GET", paths[i], NULL, NULL,
8000, &resp, &len, status, sizeof(status)) != 0)
continue;
code = apex_status_code(status);
if (code != 200 || resp == NULL ||
(strcasestr(resp, "Contact:") == NULL &&
strcasestr(resp, "Expires:") == NULL)) {
free(resp);
continue;
}
contacts[0][0] = '\0';
expires[0] = policy[0] = '\0';
copy = strdup(resp);
if (copy != NULL) {
line = strtok_r(copy, "\n", &save);
while (line != NULL) {
while (*line == ' ' || *line == '\t')
line++;
if (strncasecmp(line, "Contact:", 8) == 0) {
char *v = line + 8;
size_t w = 0;
while (*v == ' ' || *v == '\t')
v++;
if (ncontacts < 5) {
while (*v != '\0' && *v != '\r' &&
*v != '\n' && w + 1 < 256)
contacts[ncontacts][w++] = *v++;
contacts[ncontacts][w] = '\0';
if (w > 0)
ncontacts++;
}
} else if (strncasecmp(line, "Expires:", 8) == 0) {
char *v = line + 8;
while (*v == ' ' || *v == '\t')
v++;
snprintf(expires, sizeof(expires), "%.100s", v);
} else if (strncasecmp(line, "Policy:", 7) == 0) {
char *v = line + 7;
while (*v == ' ' || *v == '\t')
v++;
snprintf(policy, sizeof(policy), "%.200s", v);
}
line = strtok_r(NULL, "\n", &save);
}
free(copy);
}
expired = security_expired(expires);
evidence = apex_evidence_save("securitytxt", resp, len);
found++;
if (!first)
mcp_buf_puts(&b, ",");
first = 0;
mcp_buf_puts(&b, "{\"path\":");
apex_json_str(&b, paths[i]);
mcp_buf_puts(&b, ",\"contacts\":[");
{
int k;
for (k = 0; k < ncontacts; k++) {
if (k > 0)
mcp_buf_puts(&b, ",");
apex_json_str(&b, contacts[k]);
}
}
mcp_buf_puts(&b, "],\"expires\":");
apex_json_str(&b, expires);
mcp_buf_printf(&b, ",\"expired\":%s,\"policy\":",
expired ? "true" : "false");
apex_json_str(&b, policy);
mcp_buf_puts(&b, ",\"evidence\":");
if (evidence != NULL)
apex_json_str(&b, evidence);
else
mcp_buf_puts(&b, "null");
mcp_buf_puts(&b, "}");
free(evidence);
free(resp);
}
mcp_buf_printf(&b, "],\"count\":%d}", found);
apex_audit("security_txt", target, port, found == 0,
found == 0 ? "no security.txt" : "security.txt published",
"well-known");
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: "
@@ -4544,6 +4794,27 @@ const mcp_tool TOOLS_RED[] = {
"\"port\":{\"type\":\"integer\",\"description\":\"default 53\"}},"
"\"required\":[\"server\"]}",
t_dns_version_bind },
{ "oidc_discovery",
"Fetch the OpenID Connect discovery documents "
"(/.well-known/openid-configuration and the OAuth authorization-server "
"metadata) and report issuer, authorization, token, JWKS and userinfo "
"endpoints, with the document as evidence. Gate: target in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 80\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_oidc_discovery },
{ "security_txt",
"Fetch /.well-known/security.txt and /security.txt and report the Contact "
"entries, Expires and Policy fields, flagging an Expires date in the past; "
"the document is saved as evidence. Gate: target in scope.",
"{\"type\":\"object\",\"properties\":{"
"\"target\":{\"type\":\"string\"},"
"\"port\":{\"type\":\"integer\",\"description\":\"default 80\"},"
"\"tls\":{\"type\":\"boolean\"}},"
"\"required\":[\"target\"]}",
t_security_txt },
};
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 = 140
EXPECTED_TOOLS = 143
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.
+143 -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("140 tools registered", len(tools) == 140, len(tools))
check("143 tools registered", len(tools) == 143, 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"]) == 140)
check("http tools/list", len(listing["result"]["tools"]) == 143)
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
@@ -6394,6 +6394,147 @@ chaos_sock.close()
shutil.rmtree(usb_root, ignore_errors=True)
shutil.rmtree(usb_home, ignore_errors=True)
print("\n== OIDC, security.txt and known_hosts ==")
class _OidcHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
path = urllib.parse.urlsplit(self.path).path
if path == "/.well-known/openid-configuration":
doc = {
"issuer": "https://id.example.test",
"authorization_endpoint": "https://id.example.test/auth",
"token_endpoint": "https://id.example.test/token",
"jwks_uri": "https://id.example.test/jwks",
"userinfo_endpoint": "https://id.example.test/userinfo",
}
body = json.dumps(doc, separators=(",", ":")).encode()
code = 200
else:
body = b"not found"
code = 404
self.send_response(code)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
def security_txt_handler(expires):
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if urllib.parse.urlsplit(self.path).path == \
"/.well-known/security.txt":
body = ("Contact: mailto:security@example.test\n"
"Contact: https://example.test/report\n"
f"Expires: {expires}\n"
"Policy: https://example.test/policy\n").encode()
self.send_response(200)
else:
body = b"not found"
self.send_response(404)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
return Handler
oidc_srv = http.server.HTTPServer(("127.0.0.1", 0), _OidcHandler)
oidc_port = oidc_srv.server_address[1]
threading.Thread(target=oidc_srv.serve_forever, daemon=True).start()
fresh_srv = http.server.HTTPServer(("127.0.0.1", 0),
security_txt_handler(
"2030-01-01T00:00:00Z"))
fresh_port = fresh_srv.server_address[1]
threading.Thread(target=fresh_srv.serve_forever, daemon=True).start()
old_srv = http.server.HTTPServer(("127.0.0.1", 0),
security_txt_handler(
"2020-01-01T00:00:00Z"))
old_port = old_srv.server_address[1]
threading.Thread(target=old_srv.serve_forever, daemon=True).start()
kh_root = tempfile.mkdtemp(prefix="apex-kh2-")
os.makedirs(os.path.join(kh_root, "etc", "ssh"))
os.makedirs(os.path.join(kh_root, "home", "alice", ".ssh"))
with open(os.path.join(kh_root, "etc", "ssh", "ssh_known_hosts"), "w") as f:
f.write("example.test ssh-ed25519 AAAAB3NzaC1lZDI1NTE5AAAAIExample1\n")
f.write("example.test ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABExample2\n")
f.write("|1|abc=|def= ssh-ed25519 AAAAB3NzaC1lZDI1NTE5AAAAIHashed\n")
f.write("dup.test ssh-ed25519 AAAAB3NzaC1lZDI1NTE5AAAAIDup\n")
f.write("dup.test ssh-ed25519 AAAAB3NzaC1lZDI1NTE5AAAAIDup\n")
with open(os.path.join(kh_root, "home", "alice", ".ssh", "known_hosts"),
"w") as f:
f.write("alice.test ssh-dss AAAAB3NzaC1kc3MAAACBAlice\n")
oidc_home = tempfile.mkdtemp(prefix="apex-oidc-home-")
write_scope(oidc_home, {"label": "oidc", "expires": "2099-12-31T23:59:59Z",
"allow_private": True, "allow_ip": ["127.0.0.1"],
"allow_port": [str(oidc_port), str(fresh_port),
str(old_port)]})
res, _ = run([
call(1, "oidc_discovery", target="127.0.0.1", port=oidc_port,
tls=False),
call(2, "security_txt", target="127.0.0.1", port=fresh_port,
tls=False),
call(3, "security_txt", target="127.0.0.1", port=old_port, tls=False),
call(4, "ssh_known_hosts_audit", root=kh_root),
call(5, "oidc_discovery", target="198.51.100.9", port=80),
call(6, "ssh_known_hosts_audit", root="/nonexistent-kh"),
call(7, "security_txt", target="198.51.100.9", port=80),
], home=oidc_home)
by_id = {r.get("id"): r for r in res}
oidc = json.loads(text(by_id[1]))
spec = oidc["specs"][0] if oidc["count"] else {}
check("oidc_discovery reads the metadata",
oidc["count"] == 1 and
spec.get("issuer") == "https://id.example.test" and
spec.get("token_endpoint") == "https://id.example.test/token", oidc)
check("oidc_discovery reports the JWKS endpoint and evidence",
spec.get("jwks_uri") == "https://id.example.test/jwks" and
spec.get("evidence") and os.path.isfile(spec["evidence"]), spec)
fresh = json.loads(text(by_id[2]))
doc = fresh["documents"][0]
check("security_txt reads contacts and policy",
fresh["count"] == 1 and
doc["contacts"] == ["mailto:security@example.test",
"https://example.test/report"] and
doc["policy"] == "https://example.test/policy", doc)
check("security_txt accepts a future Expires",
doc["expired"] is False and doc["expires"].startswith("2030-01-01"),
doc)
old = json.loads(text(by_id[3]))
check("security_txt flags an expired document",
old["documents"][0]["expired"] is True, old)
kh = json.loads(text(by_id[4]))
check("ssh_known_hosts_audit counts hosts and hash styles",
kh["files"] == 2 and kh["hosts"] == 6 and kh["hashed"] == 1 and
kh["plain"] == 5, kh)
check("ssh_known_hosts_audit flags weak keys and duplicates",
kh["weak"] == 2 and kh["duplicates"] == 1 and
{"weak-key-type", "duplicate"} <=
{f["kind"] for f in kh["findings"]}, kh)
check("oidc_discovery refuses an out-of-scope target", err(by_id[5]),
text(by_id[5]))
check("ssh_known_hosts_audit survives a missing root",
json.loads(text(by_id[6]))["files"] == 0, text(by_id[6]))
check("security_txt refuses an out-of-scope target", err(by_id[7]),
text(by_id[7]))
oidc_srv.shutdown()
oidc_srv.server_close()
fresh_srv.shutdown()
fresh_srv.server_close()
old_srv.shutdown()
old_srv.server_close()
shutil.rmtree(kh_root, ignore_errors=True)
shutil.rmtree(oidc_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"})