apex-twin 1.6.0: TLS, Redis, SNMP and DNS zone-transfer checks
Red, deep service checks (tools_proto.c): - tls_audit: four openssl s_client probes (TLS 1.0/1.1/1.2/1.3) plus a -showcerts run, then openssl x509 for subject, issuer, validity and DNS SANs. Flags TLS 1.0/1.1 and RC4/3DES/NULL/EXPORT/MD5 ciphers. A failed handshake also prints a session block, so success is keyed on 'New, ..., Cipher is ...' and (NONE) counts as failure. - redis_probe: PING on one connection; when it answers without AUTH, INFO and DBSIZE follow. Reports open access (audited), version, role, connected clients, OS and database size. No password guessing. - snmp_probe: hand-built SNMPv1/v2c GET sysDescr.0 over UDP, two attempts per community (default public/private, max 4), raw answer saved as evidence. No net-snmp dependency. - dns_zone_transfer: dig AXFR against one in-scope server for one in-scope zone; record counts per type, up to 200 raw records, full output as evidence, and explicit refused/unreachable reasons. Shared gated_run(): gate, audit and run with the output returned to the caller, so multi-command tools keep the gate invariant. Tests: TLS server with a generated certificate, open and AUTH-required Redis servers, a UDP SNMP agent answering only 'public', an AXFR server with SOA/NS/A records plus a refusing variant, and the out-of-scope paths. 522 checks, ASan suite green, analyze clean (an analyzer uninitialised-field report was removed by initialising the token array), release-check green including distcheck 1.6.0.
This commit is contained in:
1 parent
b35500f0be
commit
539b552c3d
10 files changed
+1435
-20
No files matched your search
+25
-1
@@ -8,7 +8,31 @@ 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.5.0 — 2026-11-21 — this change
|
||||
## 1.6.0 — 2026-11-21 — this change
|
||||
|
||||
- **TLS** (`tls_audit`): four `openssl s_client` runs (TLS 1.0, 1.1, 1.2,
|
||||
1.3) plus one `-showcerts` run. Reports which versions negotiate, the cipher
|
||||
each picks, flags TLS 1.0/1.1 and RC4/3DES/NULL/EXPORT/MD5 ciphers, and pulls
|
||||
the first certificate through `openssl x509` for subject, issuer, validity
|
||||
and DNS SANs. A failed handshake prints a session block too, so the tool keys
|
||||
on `New, ..., Cipher is ...` and treats `(NONE)` as failure.
|
||||
- **Redis** (`redis_probe`): one connection, PING; if it answers without AUTH,
|
||||
also INFO and DBSIZE. Reports open access (audited), version, role,
|
||||
connected clients and database size. It does not guess passwords.
|
||||
- **SNMP** (`snmp_probe`): a hand-built SNMPv1/v2c GET for sysDescr.0 over UDP,
|
||||
two attempts per community (default public, private; max 4); the raw answer
|
||||
is saved as evidence. No net-snmp dependency.
|
||||
- **DNS** (`dns_zone_transfer`): `dig AXFR` against one in-scope server for one
|
||||
in-scope zone, with record counts per type, up to 200 raw records, the full
|
||||
output as evidence, and explicit refused/unreachable reasons.
|
||||
- Shared `gated_run()` helper: gate, audit, run and hand the output back, so
|
||||
multi-command tools keep one gate call per command path.
|
||||
- Tests with local fixtures: a Python TLS server with a generated certificate,
|
||||
open and AUTH-required Redis servers, a UDP SNMP agent answering only
|
||||
`public`, an AXFR server with SOA/NS/A records and a refusing variant, plus
|
||||
the out-of-scope paths. 522 checks. Coverage 79.9%.
|
||||
|
||||
## 1.5.0 — 2026-11-21 — b35500f
|
||||
|
||||
- **Red, protocols** (`tools_proto.c`): `ftp_probe` reads the 220 banner, asks
|
||||
FEAT and tries the literal anonymous pair (USER anonymous / PASS
|
||||
|
||||
@@ -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.
|
||||
|
||||
**69 tools · 506 end-to-end checks · 340 fuzz cases · 79.8% line coverage · ~342 KiB**
|
||||
**73 tools · 522 end-to-end checks · 340 fuzz cases · 79.9% line coverage · ~362 KiB**
|
||||
|
||||
```
|
||||
$ ./apex-twin --check
|
||||
{"version":"1.5.0","tools":69,...,"scope":{"loaded":true,...}}
|
||||
{"version":"1.6.0","tools":73,...,"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 (69)
|
||||
## Tools (73)
|
||||
|
||||
### Scope and bookkeeping
|
||||
|
||||
@@ -257,6 +257,10 @@ command in the allowlist: a receiver is a scanner, a transmitter is an attack.
|
||||
| `ftp_probe` | One FTP connection: banner, FEAT list, and whether the literal anonymous pair is accepted (audited) |
|
||||
| `smtp_probe` | One SMTP connection: banner, EHLO extensions, VRFY of up to 8 users classified exists/unknown/cannot-verify |
|
||||
| `ssh_audit` | Banner plus KEXINIT lists (kex, host key, ciphers, MACs) and deprecated algorithms flagged |
|
||||
| `tls_audit` | TLS 1.0–1.3 probes, negotiated ciphers, weak-version/cipher flags, certificate subject/issuer/dates/SANs |
|
||||
| `redis_probe` | PING/INFO/DBSIZE on one connection; reports open access, version, role, clients, dbsize |
|
||||
| `snmp_probe` | Hand-built SNMPv1/v2c GET sysDescr.0 over UDP for up to four communities; raw answer as evidence |
|
||||
| `dns_zone_transfer` | `dig AXFR` against one in-scope server and zone; record counts per type, raw records, evidence |
|
||||
|
||||
### Blue team
|
||||
|
||||
@@ -456,6 +460,9 @@ The full threat model, trust boundaries and a hardening checklist are in
|
||||
| SSRF probe | 3 loopback variants, 1.2 s callback wait |
|
||||
| Service probes | One connection each; SMTP VRFY at most 8 users |
|
||||
| Persistence audit | 2000 files per call, 1 MiB per file, 100 findings |
|
||||
| TLS audit | 4 protocol probes + 2 certificate runs per call |
|
||||
| SNMP | 4 communities, 2 attempts each, 1.8 s wait |
|
||||
| Zone transfer | one server, one in-scope zone, 30 s |
|
||||
|
||||
---
|
||||
|
||||
@@ -466,7 +473,7 @@ Flags are fixed: `-std=c99 -Wall -Wextra -Wpedantic -Werror` plus
|
||||
|
||||
```sh
|
||||
make # apex-twin
|
||||
make test # version check + gate audit + 506 end-to-end checks
|
||||
make test # version check + gate audit + 522 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
|
||||
@@ -571,7 +578,8 @@ src/tools_traffic.c traffic_list / traffic_read
|
||||
src/tools_red.c vuln_check, subdomain_enum, cred_test
|
||||
src/tools_blue.c hardening_audit, log_audit, ioc_scan
|
||||
src/tools_esp.c esp_info, esp_monitor, esp_read_flash, esp_flash
|
||||
src/tools_proto.c ftp_probe, smtp_probe, ssh_audit
|
||||
src/tools_proto.c ftp_probe, smtp_probe, ssh_audit, tls_audit,
|
||||
redis_probe, snmp_probe, dns_zone_transfer
|
||||
src/sha256.c SHA-256/HMAC for integrity_baseline and jwt_audit
|
||||
src/tools_guard.c guard_check
|
||||
src/apex-twin.c MCP stdio + HTTP face, --check, --version
|
||||
@@ -601,7 +609,7 @@ examples/ scope.json
|
||||
|
||||
## Status
|
||||
|
||||
1.5.0. Built and run: 69 tools, 506 checks, 340 fuzz cases and 79.8% line
|
||||
1.6.0. Built and run: 73 tools, 522 checks, 340 fuzz cases and 79.9% 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
|
||||
@@ -624,8 +632,9 @@ keeps the gaps visible.
|
||||
wordlist path brute-forcing and access-log analysis; 1.3 added SSRF
|
||||
verification, detection-rule export, integrity baselines and firmware writing
|
||||
(confirm-gated); 1.4 added offline JWT/hash analysis, ATT&CK mapping and a
|
||||
/proc snapshot; 1.5 added FTP/SMTP/SSH service probes and a persistence audit,
|
||||
again without changing an existing tool or file format.
|
||||
/proc snapshot; 1.5 added FTP/SMTP/SSH service probes and a persistence audit;
|
||||
1.6 added TLS, Redis, SNMP and DNS zone-transfer checks, again without changing
|
||||
an existing tool or file format.
|
||||
|
||||
Not yet wired into a fleet router, and there is no TLS interception.
|
||||
|
||||
|
||||
+6
-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.5.x** (`src/apex.h`, `APEX_VERSION`). Security fixes land on the current
|
||||
is **1.6.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,11 @@ 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.
|
||||
- **TLS, Redis, SNMP and AXFR stay read-only.** `tls_audit` performs TLS
|
||||
handshakes and reads the certificate; `redis_probe` sends PING, INFO and
|
||||
DBSIZE only; `snmp_probe` sends a GET for sysDescr.0; `dns_zone_transfer`
|
||||
asks one nameserver for one in-scope zone. No writes, no password guessing,
|
||||
no payloads.
|
||||
- **Service probes are handshakes, not attacks.** `ftp_probe` tries only the
|
||||
literal anonymous FTP pair, `smtp_probe` sends EHLO and at most 8 VRFY
|
||||
commands, and `ssh_audit` reads one KEXINIT and never authenticates. Each
|
||||
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
.\" apex-twin.1 - manual page for APEX TWIN
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.5.0" "User Commands"
|
||||
.TH APEX-TWIN 1 "2026-11-21" "apex-twin 1.6.0" "User Commands"
|
||||
.SH NAME
|
||||
apex-twin \- scope\-gated offensive\-security MCP server
|
||||
.SH SYNOPSIS
|
||||
@@ -37,10 +37,11 @@ It is not an exploit framework: there is no shell, no exploit payload, no
|
||||
post\-exploitation, no C2 and no persistence. Besides reconnaissance and web
|
||||
testing it carries offensive verification (vuln_check, subdomain_enum,
|
||||
cred_test, vhost_discovery, http_brute, ssrf_probe, jwt_audit, hash_id,
|
||||
ftp_probe, smtp_probe, ssh_audit), defensive audits (hardening_audit,
|
||||
log_audit, ioc_scan, web_log_audit, detect_rules, integrity_baseline,
|
||||
mitre_map, process_snapshot, persistence_audit) and ESP32 board tools
|
||||
(esp_info, esp_monitor, esp_read_flash, esp_flash).
|
||||
ftp_probe, smtp_probe, ssh_audit, tls_audit, redis_probe, snmp_probe,
|
||||
dns_zone_transfer), defensive audits (hardening_audit, log_audit, ioc_scan,
|
||||
web_log_audit, detect_rules, integrity_baseline, mitre_map, process_snapshot,
|
||||
persistence_audit) and ESP32 board tools (esp_info, esp_monitor,
|
||||
esp_read_flash, esp_flash).
|
||||
.SH MODES
|
||||
.TP
|
||||
.B apex-twin
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "1.5.0"
|
||||
#define APEX_VERSION "1.6.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
int gated(mcp_conn *c, const char *tool, const char *target, int port);
|
||||
int gated_cmd(mcp_conn *c, const char *tool, const char *target, int port,
|
||||
char *const argv[], int timeout_ms, int *exit_code);
|
||||
/*
|
||||
* Gate, audit and run a command, handing the output back instead of replying.
|
||||
* Returns 1 ran, 0 refused by the gate, -1 could not run, -2 dry run.
|
||||
*/
|
||||
int gated_run(const char *tool, const char *target, int port,
|
||||
char *const argv[], int timeout_ms, apex_proc *p);
|
||||
int tcp_probe(const char *host, int port, int timeout_ms);
|
||||
int tcp_connect_host(const char *host, int port, int timeout_ms);
|
||||
|
||||
|
||||
+1073
File diff suppressed because it is too large.
Load diff
@@ -112,6 +112,24 @@ int gated_cmd(mcp_conn *c, const char *tool, const char *target, int port,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int gated_run(const char *tool, const char *target, int port,
|
||||
char *const argv[], int timeout_ms, apex_proc *p)
|
||||
{
|
||||
char reason[512];
|
||||
int ok = apex_scope_check(target, port, reason, sizeof(reason));
|
||||
char *cmd = apex_join_argv(argv);
|
||||
int rc;
|
||||
|
||||
apex_audit(tool, target, port, ok, reason, cmd);
|
||||
free(cmd);
|
||||
if (!ok)
|
||||
return 0;
|
||||
if (g_cfg.dry_run)
|
||||
return -2;
|
||||
rc = apex_run(argv, timeout_ms, g_cfg.max_output, p);
|
||||
return rc == 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
/* A plain TCP connect with a millisecond budget. Returns 0 open, -1 closed. */
|
||||
int tcp_probe(const char *host, int port, int timeout_ms)
|
||||
{
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import re
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
EXPECTED_TOOLS = 69
|
||||
GATE = ("gated(", "gated_cmd(", "apex_scope_check(")
|
||||
EXPECTED_TOOLS = 73
|
||||
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.
|
||||
RECORD_FILTERS = {"asset_list", "finding_list", "report_markdown",
|
||||
|
||||
+281
-2
@@ -18,6 +18,7 @@ import select
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import ssl
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -133,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("69 tools registered", len(tools) == 69, len(tools))
|
||||
check("73 tools registered", len(tools) == 73, 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",
|
||||
@@ -1559,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"]) == 69)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 73)
|
||||
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
|
||||
@@ -3243,6 +3244,284 @@ empty = json.loads(text(by_id[2]))
|
||||
check("persistence_audit survives a missing root",
|
||||
empty["files_scanned"] == 0 and empty["findings_count"] == 0, empty)
|
||||
shutil.rmtree(persist_root, ignore_errors=True)
|
||||
|
||||
print("\n== tls, redis, snmp and zone transfer ==")
|
||||
|
||||
|
||||
def tls_server(cert, key):
|
||||
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
||||
ctx.load_cert_chain(cert, key)
|
||||
ctx.set_ciphers("ALL:@SECLEVEL=0")
|
||||
srv = socket.socket()
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind(("127.0.0.1", 0))
|
||||
srv.listen(8)
|
||||
port = srv.getsockname()[1]
|
||||
|
||||
def loop():
|
||||
while True:
|
||||
try:
|
||||
conn, _ = srv.accept()
|
||||
except OSError:
|
||||
return
|
||||
try:
|
||||
tls = ctx.wrap_socket(conn, server_side=True)
|
||||
try:
|
||||
tls.recv(1)
|
||||
except OSError:
|
||||
pass
|
||||
tls.close()
|
||||
except (ssl.SSLError, OSError):
|
||||
conn.close()
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return srv, port
|
||||
|
||||
|
||||
def redis_handler(require_auth):
|
||||
def handle(conn):
|
||||
f = conn.makefile("rb")
|
||||
while True:
|
||||
line = f.readline()
|
||||
if not line:
|
||||
return
|
||||
cmd = line.strip().upper()
|
||||
if cmd == b"PING":
|
||||
conn.sendall(b"-NOAUTH Authentication required.\r\n"
|
||||
if require_auth else b"+PONG\r\n")
|
||||
elif cmd == b"INFO":
|
||||
if require_auth:
|
||||
conn.sendall(b"-NOAUTH Authentication required.\r\n")
|
||||
continue
|
||||
info = (b"# Server\r\nredis_version:7.2.4\r\n"
|
||||
b"os:Linux 6.1 x86_64\r\n# Clients\r\n"
|
||||
b"connected_clients:3\r\n# Replication\r\n"
|
||||
b"role:master\r\n")
|
||||
conn.sendall(b"$" + str(len(info)).encode() + b"\r\n" +
|
||||
info + b"\r\n")
|
||||
elif cmd == b"DBSIZE":
|
||||
conn.sendall(b"-NOAUTH Authentication required.\r\n"
|
||||
if require_auth else b":5\r\n")
|
||||
else:
|
||||
conn.sendall(b"-ERR unknown command\r\n")
|
||||
return handle
|
||||
|
||||
|
||||
def snmp_tlv(tag, value):
|
||||
return bytes([tag, len(value)]) + value
|
||||
|
||||
|
||||
def snmp_agent(allow_community):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.bind(("127.0.0.1", 0))
|
||||
s.settimeout(0.2)
|
||||
port = s.getsockname()[1]
|
||||
stop = threading.Event()
|
||||
|
||||
def loop():
|
||||
while not stop.is_set():
|
||||
try:
|
||||
data, addr = s.recvfrom(2048)
|
||||
except socket.timeout:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
if len(data) < 9 or data[5] != 0x04:
|
||||
continue
|
||||
clen = data[6]
|
||||
community = data[7:7 + clen]
|
||||
if community != allow_community:
|
||||
continue
|
||||
oid = bytes([0x2b, 6, 1, 2, 1, 1, 1, 0])
|
||||
varbind = snmp_tlv(0x30, snmp_tlv(0x06, oid) +
|
||||
snmp_tlv(0x04, b"Test SNMP agent 1.0"))
|
||||
vbl = snmp_tlv(0x30, varbind)
|
||||
pdu = snmp_tlv(0xA2, b"\x02\x04\x00\x00\x00\x01" +
|
||||
b"\x02\x01\x00" + b"\x02\x01\x00" + vbl)
|
||||
resp = snmp_tlv(0x30, b"\x02\x01\x01" +
|
||||
snmp_tlv(0x04, community) + pdu)
|
||||
s.sendto(resp, addr)
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return s, port, stop
|
||||
|
||||
|
||||
def dns_name_decode(msg, off):
|
||||
labels = []
|
||||
while msg[off] != 0:
|
||||
n = msg[off]
|
||||
off += 1
|
||||
labels.append(msg[off:off + n].decode("ascii", "replace"))
|
||||
off += n
|
||||
return ".".join(labels), off + 1
|
||||
|
||||
|
||||
def dns_name_encode(name):
|
||||
out = b""
|
||||
for label in name.rstrip(".").split("."):
|
||||
out += bytes([len(label)]) + label.encode()
|
||||
return out + b"\x00"
|
||||
|
||||
|
||||
def dns_axfr_server(refuse):
|
||||
srv = socket.socket()
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind(("127.0.0.1", 0))
|
||||
srv.listen(4)
|
||||
port = srv.getsockname()[1]
|
||||
|
||||
def loop():
|
||||
while True:
|
||||
try:
|
||||
conn, _ = srv.accept()
|
||||
except OSError:
|
||||
return
|
||||
try:
|
||||
head = conn.recv(2)
|
||||
if len(head) < 2:
|
||||
continue
|
||||
need = struct.unpack(">H", head)[0]
|
||||
msg = b""
|
||||
while len(msg) < need:
|
||||
chunk = conn.recv(need - len(msg))
|
||||
if not chunk:
|
||||
break
|
||||
msg += chunk
|
||||
if len(msg) < 12:
|
||||
continue
|
||||
tid = msg[:2]
|
||||
name, off = dns_name_decode(msg, 12)
|
||||
question = msg[12:off + 4]
|
||||
if refuse:
|
||||
resp = (tid + struct.pack(">HHHHH", 0x8405, 1, 0, 0, 0) +
|
||||
question)
|
||||
else:
|
||||
ptr = b"\xc0\x0c"
|
||||
soa = (dns_name_encode("ns1." + name) +
|
||||
dns_name_encode("hostmaster." + name) +
|
||||
struct.pack(">IIIII", 2026112101, 3600, 600,
|
||||
86400, 300))
|
||||
|
||||
def rr(owner, rtype, rdata):
|
||||
return (owner + struct.pack(">HHIH", rtype, 1, 3600,
|
||||
len(rdata)) + rdata)
|
||||
|
||||
answers = [
|
||||
rr(ptr, 6, soa),
|
||||
rr(ptr, 2, dns_name_encode("ns1." + name)),
|
||||
rr(dns_name_encode("ns1." + name), 1,
|
||||
socket.inet_aton("127.0.0.1")),
|
||||
rr(ptr, 6, soa),
|
||||
]
|
||||
resp = (tid + struct.pack(">HHHHH", 0x8400, 1,
|
||||
len(answers), 0, 0) +
|
||||
question + b"".join(answers))
|
||||
conn.sendall(struct.pack(">H", len(resp)) + resp)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
threading.Thread(target=loop, daemon=True).start()
|
||||
return srv, port
|
||||
|
||||
|
||||
tls_dir = tempfile.mkdtemp(prefix="apex-tls-")
|
||||
tls_cert = os.path.join(tls_dir, "cert.pem")
|
||||
tls_key = os.path.join(tls_dir, "key.pem")
|
||||
subprocess.run(["openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
|
||||
"-keyout", tls_key, "-out", tls_cert, "-days", "2",
|
||||
"-subj", "/CN=localhost",
|
||||
"-addext", "subjectAltName=DNS:localhost"],
|
||||
check=True, capture_output=True)
|
||||
tls_srv, tls_port = tls_server(tls_cert, tls_key)
|
||||
redis_srv, redis_port = start_line_server(redis_handler(False))
|
||||
redis_auth_srv, redis_auth_port = start_line_server(redis_handler(True))
|
||||
snmp_sock, snmp_port, snmp_stop = snmp_agent(b"public")
|
||||
dns_srv, dns_port = dns_axfr_server(False)
|
||||
dns_refuse_srv, dns_refuse_port = dns_axfr_server(True)
|
||||
|
||||
deep_home = tempfile.mkdtemp(prefix="apex-deep-")
|
||||
write_scope(deep_home, {"label": "deep", "expires": "2099-12-31T23:59:59Z",
|
||||
"allow_private": True,
|
||||
"allow_ip": ["127.0.0.1"],
|
||||
"allow_domain": ["example.test"],
|
||||
"allow_port": [str(tls_port), str(redis_port),
|
||||
str(redis_auth_port), str(snmp_port),
|
||||
str(dns_port), str(dns_refuse_port)]})
|
||||
res, _ = run([
|
||||
call(1, "tls_audit", target="127.0.0.1", port=tls_port),
|
||||
call(2, "redis_probe", target="127.0.0.1", port=redis_port),
|
||||
call(3, "redis_probe", target="127.0.0.1", port=redis_auth_port),
|
||||
call(4, "snmp_probe", target="127.0.0.1", port=snmp_port,
|
||||
communities="public"),
|
||||
call(5, "snmp_probe", target="127.0.0.1", port=snmp_port,
|
||||
communities="private"),
|
||||
call(6, "dns_zone_transfer", server="127.0.0.1", port=dns_port,
|
||||
zone="example.test"),
|
||||
call(7, "dns_zone_transfer", server="127.0.0.1", port=dns_refuse_port,
|
||||
zone="example.test"),
|
||||
call(8, "dns_zone_transfer", server="127.0.0.1", port=dns_port,
|
||||
zone="other.invalid"),
|
||||
call(9, "tls_audit", target="198.51.100.9", port=443),
|
||||
], home=deep_home)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
tls = json.loads(text(by_id[1]))
|
||||
versions = {p["version"]: p for p in tls["protocols"]}
|
||||
check("tls_audit probes all four protocol versions", len(versions) == 4, tls)
|
||||
check("tls_audit finds the modern protocols",
|
||||
versions["TLSv1.2"]["enabled"] and versions["TLSv1.3"]["enabled"], tls)
|
||||
check("tls_audit names the negotiated cipher",
|
||||
versions["TLSv1.2"]["cipher"].startswith("ECDHE-") or
|
||||
versions["TLSv1.3"]["cipher"].startswith("TLS_"), tls)
|
||||
weak = set(tls["weak"])
|
||||
check("tls_audit flags every weak protocol it can negotiate",
|
||||
all(p["version"] in weak for p in tls["protocols"]
|
||||
if p["enabled"] and p["version"] in ("TLSv1.0", "TLSv1.1")), tls)
|
||||
cert = tls["certificate"]
|
||||
check("tls_audit extracts the certificate",
|
||||
cert is not None and "localhost" in cert["subject"] and
|
||||
cert["not_after"] != "" and "localhost" in cert["sans"], cert)
|
||||
redis = json.loads(text(by_id[2]))
|
||||
check("redis_probe reports an open instance",
|
||||
redis["redis"] is True and redis["requires_auth"] is False and
|
||||
redis["ping"] is True, redis)
|
||||
check("redis_probe reads version, role, clients and size",
|
||||
redis["version"] == "7.2.4" and redis["role"] == "master" and
|
||||
redis["connected_clients"] == "3" and redis["dbsize"] == 5, redis)
|
||||
redis_auth = json.loads(text(by_id[3]))
|
||||
check("redis_probe recognises an instance that wants AUTH",
|
||||
redis_auth["redis"] is True and redis_auth["requires_auth"] is True and
|
||||
redis_auth["ping"] is False, redis_auth)
|
||||
snmp_ok = json.loads(text(by_id[4]))
|
||||
check("snmp_probe accepts the public community",
|
||||
snmp_ok["responded"] is True and
|
||||
"Test SNMP agent" in snmp_ok["communities"][0]["sys_descr"], snmp_ok)
|
||||
snmp_no = json.loads(text(by_id[5]))
|
||||
check("snmp_probe reports a community that is ignored",
|
||||
snmp_no["responded"] is False, snmp_no)
|
||||
axfr = json.loads(text(by_id[6]))
|
||||
types = {t["type"]: t["count"] for t in axfr["types"]}
|
||||
check("dns_zone_transfer succeeds against the fixture",
|
||||
axfr["success"] is True and axfr["records_count"] == 4, axfr)
|
||||
check("dns_zone_transfer counts the records per type",
|
||||
types == {"SOA": 2, "NS": 1, "A": 1}, types)
|
||||
check("dns_zone_transfer returns the records and evidence",
|
||||
len(axfr["records"]) == 4 and axfr["evidence"] and
|
||||
os.path.isfile(axfr["evidence"]), axfr)
|
||||
axfr_no = json.loads(text(by_id[7]))
|
||||
check("dns_zone_transfer reports a refused transfer",
|
||||
axfr_no["success"] is False and axfr_no["reason"] == "transfer refused",
|
||||
axfr_no)
|
||||
check("dns_zone_transfer refuses a zone outside the scope", err(by_id[8]),
|
||||
text(by_id[8]))
|
||||
check("tls_audit refuses an out-of-scope target", err(by_id[9]),
|
||||
text(by_id[9]))
|
||||
|
||||
for srv in (tls_srv, redis_srv, redis_auth_srv, dns_srv, dns_refuse_srv):
|
||||
srv.close()
|
||||
snmp_stop.set()
|
||||
snmp_sock.close()
|
||||
shutil.rmtree(tls_dir, ignore_errors=True)
|
||||
shutil.rmtree(deep_home, ignore_errors=True)
|
||||
shutil.rmtree(proto_home, ignore_errors=True)
|
||||
|
||||
print("\n== esp32 tools ==")
|
||||
|
||||
Reference in new issue
Block a user