apex-twin 0.19.0: a machine-readable JSON report
report_markdown gains format=json. The file report-<ts>.json contains:
generated, scope_label,
filters {target, min_severity, status},
counts {total, by_severity{crisis...}, by_status{open...}},
findings [{id, ts, updated, target, title, severity, confidence, status,
tool, cwe, evidence, remediation, tags, note}],
assets [...] when include_assets is set.
Filters behave as in Markdown/CSV; the counts are computed over the filtered
set, so 'confirmed findings only' is one status filter away. Assets are included
independently of the finding filter (an inventory is not a finding). The reply
envelope still carries format, findings, bytes, path and the rendered text;
Markdown and CSV are untouched.
Tests: a two-finding state (critical/open, medium/confirmed) produces a
parseable file with correct counts, sorted findings, null filters and two
assets when asked; status=open yields an empty report; CSV stays CSV. Red proof:
dropping the include_assets flag for JSON turned two checks red.
This commit is contained in:
1 parent
32cb05b691
commit
adf65477a4
4 files changed
+243
-26
No files matched your search
@@ -18,7 +18,7 @@ separate, explicitly armed switch.
|
||||
|
||||
```sh
|
||||
make # apex-twin, ~239 kB static-ish binary, zero warnings under -Werror
|
||||
make test # 287 end-to-end checks, no mocks
|
||||
make test # 298 end-to-end checks, no mocks
|
||||
make asan # apex-twin-asan with ASan + UBSan
|
||||
make test-asan # the whole suite against the sanitizer binary
|
||||
make analyze # gcc -fanalyzer over every translation unit
|
||||
@@ -117,7 +117,10 @@ the update is audited like every other decision.
|
||||
|
||||
`report_markdown` prints the status of each finding, counts them in a lifecycle
|
||||
table, and filters by status — which is what turns "confirmed findings only"
|
||||
from a promise into an artefact you can send.
|
||||
from a promise into an artefact you can send. `format: "json"` writes the same
|
||||
thing as a machine-readable document: the filters that were applied, counts by
|
||||
severity and status, the finding records, and the asset list when
|
||||
`include_assets` is set.
|
||||
|
||||
## The inventory
|
||||
|
||||
@@ -250,9 +253,9 @@ as a lead), `xss_probe` (marked payload, returns the reflection context), `curl`
|
||||
|
||||
**Findings** — `finding_add`, `finding_list`, `finding_read`, `finding_update`
|
||||
(status open/confirmed/false-positive/fixed, severity, note), `report_markdown`
|
||||
(Markdown or CSV, severity-sorted, filterable by target/severity/status, written
|
||||
to `$APEX_HOME/reports`), `evidence_list`, `evidence_read` (text, or base64 when
|
||||
the bytes are not text)
|
||||
(Markdown, CSV or JSON, severity-sorted, filterable by target/severity/status,
|
||||
written to `$APEX_HOME/reports`), `evidence_list`, `evidence_read` (text, or
|
||||
base64 when the bytes are not text)
|
||||
|
||||
**Notifications** — `notify_test` (fire the configured webhook once and report
|
||||
whether curl accepted it)
|
||||
@@ -322,6 +325,7 @@ $APEX_HOME/
|
||||
findings/f0001.json one finding per file
|
||||
evidence/<ts>-<label>.bin raw proof, 0600
|
||||
reports/report-<ts>.md rendered findings, 0600, never overwritten
|
||||
reports/report-<ts>.json machine-readable variant (same counts and records)
|
||||
assets/a0001.json one record per target, merged on the next look
|
||||
traffic/t0001.json one capture: target, method, status, byte counts
|
||||
traffic/t0001.http the request and the raw response, 0600
|
||||
@@ -338,7 +342,7 @@ finding and the next report no longer mentions it.
|
||||
make test
|
||||
```
|
||||
|
||||
287 checks, real binary, real DNS, real files written; no mocks. The suite was
|
||||
298 checks, real binary, real DNS, real files written; no mocks. The suite was
|
||||
seen red on purpose: with the "no scope" branch disabled by `if (0 && ...)`,
|
||||
three checks fail, because they assert the *reason* and not merely that an error
|
||||
came back — a gate that falls through to the next deny branch looks identical
|
||||
@@ -369,7 +373,7 @@ this host is an SSH forward to another machine, and a foreign server answered
|
||||
`{"serverInfo":{"name":"koder"}}` while the suite was green.
|
||||
|
||||
The suite is also run against `apex-twin-asan` (`make test-asan`), built with
|
||||
`-fsanitize=address,undefined`. All 287 checks pass with no ASan or UBSan report,
|
||||
`-fsanitize=address,undefined`. All 298 checks pass with no ASan or UBSan report,
|
||||
and a separate batch of error paths, network captures and report generation was
|
||||
run with leak detection on: no leaks. `make analyze` runs `gcc -fanalyzer` over
|
||||
every translation unit; it was red first on `vendor/libmcp/mcp.h`, where
|
||||
@@ -409,7 +413,7 @@ head) is rejected 2/2 with the exact `apex-twin.c` UBSan line.
|
||||
|
||||
`make coverage` builds `apex-twin-cov` with `-O0 --coverage`, runs the suite and
|
||||
prints per-file line coverage (`tests/coverage.py`, gcov only, no extra tools).
|
||||
The first measured pass was 55.9%; the gap tests brought it to **76.4%** —
|
||||
The first measured pass was 55.9%; the gap tests brought it to **76.7%** —
|
||||
`tools_kb.c` 100%, `tools_traffic.c` 81.8%, `tools_web.c` 71.6%,
|
||||
`tools_recon.c` 68.0%. A PTY-based Marauder simulator then raised
|
||||
`tools_radio.c` from 31.7% to 76.2% without hardware: firmware `info`/`help`,
|
||||
@@ -421,12 +425,12 @@ the copied scope reason is now bounded with a precision, not left to snprintf.
|
||||
|
||||
## Status
|
||||
|
||||
0.18.0. Built and run: 45 tools, 287 checks, 340 fuzz cases and 76.4% line
|
||||
0.19.0. Built and run: 45 tools, 298 checks, 340 fuzz cases and 76.7% 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
|
||||
graded lead, `report_markdown` turns findings and inventory into one Markdown or
|
||||
CSV file, and `evidence_read`/`traffic_read` get the proof back. `--proxy` puts
|
||||
graded lead, `report_markdown` turns findings and inventory into one Markdown,
|
||||
CSV or JSON file, and `evidence_read`/`traffic_read` get the proof back. `--proxy` puts
|
||||
the same gate in front of curl and a browser, forwards chunked and
|
||||
Content-Length bodies, and takes rewrite rules that can set or remove a header
|
||||
or block a path; `APEX_WEBHOOK` wakes someone when the severity floor is
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "0.18.0"
|
||||
#define APEX_VERSION "0.19.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
|
||||
+170
-11
@@ -307,6 +307,160 @@ static int save_report(const char *suffix, const char *body, size_t len,
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void json_finding(mcp_buf *b, const apex_finding *f)
|
||||
{
|
||||
mcp_buf_puts(b, "{\"id\":");
|
||||
apex_json_str(b, f->id);
|
||||
mcp_buf_puts(b, ",\"ts\":");
|
||||
apex_json_str(b, f->ts);
|
||||
mcp_buf_puts(b, ",\"updated\":");
|
||||
apex_json_str(b, f->updated);
|
||||
mcp_buf_puts(b, ",\"target\":");
|
||||
apex_json_str(b, f->target);
|
||||
mcp_buf_puts(b, ",\"title\":");
|
||||
apex_json_str(b, f->title);
|
||||
mcp_buf_puts(b, ",\"severity\":");
|
||||
apex_json_str(b, f->severity);
|
||||
mcp_buf_puts(b, ",\"confidence\":");
|
||||
apex_json_str(b, f->confidence);
|
||||
mcp_buf_puts(b, ",\"status\":");
|
||||
apex_json_str(b, status_of(f));
|
||||
mcp_buf_puts(b, ",\"tool\":");
|
||||
apex_json_str(b, f->tool);
|
||||
mcp_buf_puts(b, ",\"cwe\":");
|
||||
apex_json_str(b, f->cwe);
|
||||
mcp_buf_puts(b, ",\"evidence\":");
|
||||
apex_json_str(b, f->evidence);
|
||||
mcp_buf_puts(b, ",\"remediation\":");
|
||||
apex_json_str(b, f->remediation);
|
||||
mcp_buf_puts(b, ",\"tags\":");
|
||||
apex_json_str(b, f->tags);
|
||||
mcp_buf_puts(b, ",\"note\":");
|
||||
apex_json_str(b, f->note);
|
||||
mcp_buf_puts(b, "}");
|
||||
}
|
||||
|
||||
static void json_asset(mcp_buf *b, const apex_asset *a)
|
||||
{
|
||||
mcp_buf_puts(b, "{\"id\":");
|
||||
apex_json_str(b, a->id);
|
||||
mcp_buf_puts(b, ",\"ts\":");
|
||||
apex_json_str(b, a->ts);
|
||||
mcp_buf_puts(b, ",\"updated\":");
|
||||
apex_json_str(b, a->updated);
|
||||
mcp_buf_puts(b, ",\"target\":");
|
||||
apex_json_str(b, a->target);
|
||||
mcp_buf_puts(b, ",\"label\":");
|
||||
apex_json_str(b, a->label);
|
||||
mcp_buf_puts(b, ",\"kind\":");
|
||||
apex_json_str(b, a->kind[0] != '\0' ? a->kind : "host");
|
||||
mcp_buf_puts(b, ",\"ports\":");
|
||||
apex_json_str(b, a->ports);
|
||||
mcp_buf_puts(b, ",\"services\":");
|
||||
apex_json_str(b, a->services);
|
||||
mcp_buf_puts(b, ",\"tags\":");
|
||||
apex_json_str(b, a->tags);
|
||||
mcp_buf_puts(b, ",\"note\":");
|
||||
apex_json_str(b, a->note);
|
||||
mcp_buf_puts(b, "}");
|
||||
}
|
||||
|
||||
/* The machine-readable report: filters, counts and the records themselves. */
|
||||
static void render_json(mcp_buf *b, const apex_finding *rows, int n,
|
||||
const char *target, const char *min_sev,
|
||||
const char *status, const apex_asset *assets,
|
||||
int n_assets, int include_assets)
|
||||
{
|
||||
static const char *sev_names[] = { "critical", "high", "medium", "low",
|
||||
"info" };
|
||||
static const char *status_names[] = { "open", "confirmed",
|
||||
"false-positive", "fixed" };
|
||||
int counts[5] = { 0, 0, 0, 0, 0 };
|
||||
int scounts[4] = { 0, 0, 0, 0 };
|
||||
int other = 0;
|
||||
char *now = apex_now_iso();
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
int r;
|
||||
const char *c = sev_canonical(rows[i].severity, &r);
|
||||
const char *st = status_of(&rows[i]);
|
||||
|
||||
if (strcmp(c, "critical") == 0)
|
||||
counts[0]++;
|
||||
else if (strcmp(c, "high") == 0)
|
||||
counts[1]++;
|
||||
else if (strcmp(c, "medium") == 0)
|
||||
counts[2]++;
|
||||
else if (strcmp(c, "low") == 0)
|
||||
counts[3]++;
|
||||
else if (strcmp(c, "info") == 0)
|
||||
counts[4]++;
|
||||
else
|
||||
other++;
|
||||
if (strcmp(st, "confirmed") == 0)
|
||||
scounts[1]++;
|
||||
else if (strcmp(st, "false-positive") == 0)
|
||||
scounts[2]++;
|
||||
else if (strcmp(st, "fixed") == 0)
|
||||
scounts[3]++;
|
||||
else
|
||||
scounts[0]++;
|
||||
}
|
||||
|
||||
mcp_buf_puts(b, "{\"generated\":");
|
||||
apex_json_str(b, now != NULL ? now : "?");
|
||||
mcp_buf_puts(b, ",\"scope_label\":");
|
||||
apex_json_str(b, g_scope.label);
|
||||
mcp_buf_puts(b, ",\"filters\":{\"target\":");
|
||||
if (target != NULL && *target != '\0')
|
||||
apex_json_str(b, target);
|
||||
else
|
||||
mcp_buf_puts(b, "null");
|
||||
mcp_buf_puts(b, ",\"min_severity\":");
|
||||
if (min_sev != NULL && *min_sev != '\0')
|
||||
apex_json_str(b, min_sev);
|
||||
else
|
||||
mcp_buf_puts(b, "null");
|
||||
mcp_buf_puts(b, ",\"status\":");
|
||||
if (status != NULL && *status != '\0')
|
||||
apex_json_str(b, status);
|
||||
else
|
||||
mcp_buf_puts(b, "null");
|
||||
mcp_buf_printf(b, "},\"counts\":{\"total\":%d,\"by_severity\":{", n);
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (i > 0)
|
||||
mcp_buf_puts(b, ",");
|
||||
mcp_buf_printf(b, "\"%s\":%d", sev_names[i], counts[i]);
|
||||
}
|
||||
if (other > 0)
|
||||
mcp_buf_printf(b, ",\"other\":%d", other);
|
||||
mcp_buf_puts(b, "},\"by_status\":{");
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (i > 0)
|
||||
mcp_buf_puts(b, ",");
|
||||
mcp_buf_printf(b, "\"%s\":%d", status_names[i], scounts[i]);
|
||||
}
|
||||
mcp_buf_puts(b, "}},\"findings\":[");
|
||||
for (i = 0; i < n; i++) {
|
||||
if (i > 0)
|
||||
mcp_buf_puts(b, ",");
|
||||
json_finding(b, &rows[i]);
|
||||
}
|
||||
mcp_buf_puts(b, "]");
|
||||
if (include_assets) {
|
||||
mcp_buf_puts(b, ",\"assets\":[");
|
||||
for (i = 0; i < n_assets; i++) {
|
||||
if (i > 0)
|
||||
mcp_buf_puts(b, ",");
|
||||
json_asset(b, &assets[i]);
|
||||
}
|
||||
mcp_buf_puts(b, "]");
|
||||
}
|
||||
mcp_buf_puts(b, "}");
|
||||
free(now);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- handlers */
|
||||
|
||||
static void t_report_markdown(mcp_conn *c, const mcp_json *args, void *user)
|
||||
@@ -318,6 +472,7 @@ static void t_report_markdown(mcp_conn *c, const mcp_json *args, void *user)
|
||||
int save = mcp_arg_bool(args, "save", 1);
|
||||
int include_assets = mcp_arg_bool(args, "include_assets", 0);
|
||||
int is_csv = format != NULL && strcasecmp(format, "csv") == 0;
|
||||
int is_json = format != NULL && strcasecmp(format, "json") == 0;
|
||||
int min_rank = min_sev != NULL && *min_sev != '\0' ? sev_rank(min_sev) : 0;
|
||||
apex_finding *all;
|
||||
apex_finding *rows;
|
||||
@@ -365,6 +520,9 @@ static void t_report_markdown(mcp_conn *c, const mcp_json *args, void *user)
|
||||
/* one renderer writes into the same buffer, so the format decides */
|
||||
if (is_csv)
|
||||
render_csv(&body, rows, kept);
|
||||
else if (is_json)
|
||||
render_json(&body, rows, kept, target, min_sev, status, assets,
|
||||
n_assets, include_assets);
|
||||
else
|
||||
render_markdown(&body, rows, kept, target, min_sev, status,
|
||||
include_assets ? assets : NULL,
|
||||
@@ -373,12 +531,12 @@ static void t_report_markdown(mcp_conn *c, const mcp_json *args, void *user)
|
||||
|
||||
path[0] = '\0';
|
||||
if (save)
|
||||
saved = save_report(is_csv ? "csv" : "md", body.p, body.len, path,
|
||||
sizeof(path)) == 0;
|
||||
saved = save_report(is_csv ? "csv" : (is_json ? "json" : "md"), body.p,
|
||||
body.len, path, sizeof(path)) == 0;
|
||||
|
||||
mcp_buf_init(&out);
|
||||
mcp_buf_puts(&out, "{\"format\":\"");
|
||||
mcp_buf_puts(&out, is_csv ? "csv" : "markdown");
|
||||
mcp_buf_puts(&out, is_csv ? "csv" : (is_json ? "json" : "markdown"));
|
||||
mcp_buf_printf(&out, "\",\"findings\":%d,\"bytes\":%lu,\"saved\":%s,"
|
||||
"\"path\":", kept, (unsigned long)body.len,
|
||||
saved ? "true" : "false");
|
||||
@@ -458,12 +616,12 @@ static void t_evidence_read(mcp_conn *c, const mcp_json *args, void *user)
|
||||
const mcp_tool TOOLS_REPORT[] = {
|
||||
{ "report_markdown",
|
||||
"Render every recorded finding into one report that a human can send: "
|
||||
"Markdown (default) or CSV, sorted critical-first, with a severity table "
|
||||
"and a lifecycle table. Use it at the end of an engagement, and after a "
|
||||
"batch of findings, to produce the artefact. The file is written to "
|
||||
"$APEX_HOME/reports and its path is returned together with the rendered "
|
||||
"text. Filter by target, minimum severity and status (open, confirmed, "
|
||||
"false-positive, fixed).",
|
||||
"Markdown (default), CSV, or JSON for a machine. Markdown carries a "
|
||||
"severity and lifecycle table; JSON carries the filters, the same counts "
|
||||
"and the records themselves, so a script does not have to parse prose. "
|
||||
"Sorted critical-first; written to $APEX_HOME/reports with the rendered "
|
||||
"text also returned. Filter by target, minimum severity and status "
|
||||
"(open, confirmed, false-positive, fixed).",
|
||||
"{\"type\":\"object\",\"properties\":{"
|
||||
"\"target\":{\"type\":\"string\",\"description\":\"only findings for this "
|
||||
"exact target\"},"
|
||||
@@ -473,8 +631,9 @@ const mcp_tool TOOLS_REPORT[] = {
|
||||
"\"status\":{\"type\":\"string\",\"enum\":[\"open\",\"confirmed\","
|
||||
"\"false-positive\",\"fixed\"],\"description\":\"only findings in this "
|
||||
"lifecycle state\"},"
|
||||
"\"format\":{\"type\":\"string\",\"enum\":[\"markdown\",\"csv\"],"
|
||||
"\"description\":\"default markdown\"},"
|
||||
"\"format\":{\"type\":\"string\",\"enum\":[\"markdown\",\"csv\",\"json\"],"
|
||||
"\"description\":\"default markdown; json is the machine-readable "
|
||||
"document with filters and counts\"},"
|
||||
"\"save\":{\"type\":\"boolean\",\"description\":\"write under "
|
||||
"$APEX_HOME/reports, default true\"},"
|
||||
"\"include_assets\":{\"type\":\"boolean\",\"description\":\"append the "
|
||||
|
||||
+57
-3
@@ -591,6 +591,58 @@ check("asset writes are audited",
|
||||
for e in audit3),
|
||||
[e for e in audit3 if e["tool"] == "asset_add"][:3])
|
||||
|
||||
print("\n== json report ==")
|
||||
res, _ = run([
|
||||
call(1, "report_markdown", format="json"),
|
||||
call(2, "report_markdown", format="json", status="open", save=False),
|
||||
call(3, "report_markdown", format="json", target="no.example",
|
||||
include_assets=True),
|
||||
call(4, "report_markdown", format="csv", save=False),
|
||||
])
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
jenv = json.loads(text(by_id[1]))
|
||||
check("json report returns format json and a .json path",
|
||||
jenv["format"] == "json" and jenv["path"].endswith(".json") and
|
||||
jenv["saved"] is True, jenv)
|
||||
with open(jenv["path"]) as f:
|
||||
jdoc = json.load(f)
|
||||
check("json report is valid JSON with metadata",
|
||||
"generated" in jdoc and "scope_label" in jdoc, list(jdoc))
|
||||
check("json report counts total and severities",
|
||||
jdoc["counts"]["total"] == 2 and
|
||||
jdoc["counts"]["by_severity"]["critical"] == 1 and
|
||||
jdoc["counts"]["by_severity"]["medium"] == 1, jdoc["counts"])
|
||||
check("json report counts the lifecycle states",
|
||||
jdoc["counts"]["by_status"]["false-positive"] == 1 and
|
||||
jdoc["counts"]["by_status"]["fixed"] == 1, jdoc["counts"])
|
||||
check("json report lists the findings with their state",
|
||||
len(jdoc["findings"]) == 2 and
|
||||
all("id" in f and "status" in f and "title" in f
|
||||
for f in jdoc["findings"]), jdoc["findings"])
|
||||
check("json report is sorted critical-first",
|
||||
jdoc["findings"][0]["severity"] == "critical", jdoc["findings"][0])
|
||||
check("json report names no filters when none were given",
|
||||
jdoc["filters"] == {"target": None, "min_severity": None,
|
||||
"status": None}, jdoc["filters"])
|
||||
open_env = json.loads(text(by_id[2]))
|
||||
open_doc = json.loads(open_env["report"])
|
||||
check("json status filter excludes non-open findings",
|
||||
open_doc["counts"]["total"] == 0 and open_doc["findings"] == [] and
|
||||
open_doc["filters"]["status"] == "open", open_doc["counts"])
|
||||
assets_env = json.loads(text(by_id[3]))
|
||||
assets_doc = json.loads(assets_env["report"])
|
||||
check("json report includes the asset list when asked",
|
||||
len(assets_doc.get("assets") or []) == 2, assets_doc.get("assets"))
|
||||
check("json report keeps assets even when the target filter matches nothing",
|
||||
assets_doc["counts"]["total"] == 0 and
|
||||
len(assets_doc.get("assets") or []) == 2 and
|
||||
assets_doc["filters"]["target"] == "no.example", assets_doc["filters"])
|
||||
csv_still = json.loads(text(by_id[4]))
|
||||
check("csv output is unchanged",
|
||||
csv_still["format"] == "csv" and
|
||||
csv_still["report"].startswith("id,target,title,severity"),
|
||||
csv_still["report"][:80])
|
||||
|
||||
print("\n== traffic capture ==")
|
||||
res, _ = run([
|
||||
call(1, "http_capture", target="example.com", port=80, path="/",
|
||||
@@ -1109,10 +1161,12 @@ res, _ = run([
|
||||
call(2, "dns", target="example.com", type="A"),
|
||||
], extra_env={"APEX_DRY_RUN": "1"})
|
||||
check("dry_run prints the command instead of running nmap",
|
||||
not err(res[0]) and "DRY RUN" in text(res[0]), text(res[0])[:160])
|
||||
bool(res) and not err(res[0]) and "DRY RUN" in text(res[0]),
|
||||
text(res[0])[:160] if res else "no output")
|
||||
res2, _ = run([call(1, "dns", target="example.com", type="A")])
|
||||
check("dns runs dig through the gate", not err(res2[0]) and
|
||||
"exit=" in text(res2[0]), text(res2[0])[:160])
|
||||
check("dns runs dig through the gate", bool(res2) and not err(res2[0]) and
|
||||
"exit=" in text(res2[0]),
|
||||
text(res2[0])[:160] if res2 else "no output")
|
||||
|
||||
# --------------------------------------------------------------- transport
|
||||
print("\n== http transport ==")
|
||||
|
||||
Reference in new issue
Block a user