|
| 1 | +"""Scenario 4 - auditors / assessors: a POA&M workbook + a provable audit trail. |
| 2 | +
|
| 3 | +The artifact an auditor lives by is the Plan of Action & Milestones (POA&M): one |
| 4 | +row per (weakness, asset), with a CAT level, the security check (STIG/CCI), and a |
| 5 | +severity-driven scheduled-completion date. This demo builds the REAL eMASS-style |
| 6 | +POA&M with ``comint_osquery.fleet.poam_items`` and shows the columns, then uses |
| 7 | +the shipped hash-chained ``AuditLog`` to make the assessment itself |
| 8 | +tamper-evident — and proves the chain catches an edit. |
| 9 | +
|
| 10 | +Offline: reads the bundled ``demos/12-fleet-systemic`` snapshots; the audit log |
| 11 | +is written to a throwaway temp file. |
| 12 | +""" |
| 13 | +import csv |
| 14 | +import io |
| 15 | +import tempfile |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +from _common import fixture, rule, section |
| 19 | +from comint_osquery import fleet as fl |
| 20 | +from cognis_mil import AuditLog |
| 21 | + |
| 22 | + |
| 23 | +def main() -> None: |
| 24 | + rule("AUDITOR / ASSESSOR - eMASS POA&M + tamper-evident audit trail") |
| 25 | + |
| 26 | + target = fixture("12-fleet-systemic") |
| 27 | + hosts = fl.scan_fleet(target) |
| 28 | + |
| 29 | + section("POA&M workbook (one row per failing control, per host)") |
| 30 | + # assessed_at fixed so the scheduled-completion dates are deterministic. |
| 31 | + items = fl.poam_items(hosts, office="J6 / Cyber", assessed_at=0) |
| 32 | + print(f" {len(items)} POA&M item(s). eMASS columns: {len(fl.POAM_COLUMNS)}") |
| 33 | + print(f"\n {'Item ID':<13} {'CAT':<7} {'Control':<9} {'Sched. Complete':<16} Check") |
| 34 | + for it in items: |
| 35 | + print(f" {it['POA&M Item ID']:<13} {it['Raw Severity']:<7} " |
| 36 | + f"{it['Security Control Number (NC/NA)']:<9} " |
| 37 | + f"{it['Scheduled Completion Date']:<16} {it['Security Checks']}") |
| 38 | + |
| 39 | + # Render the real CSV and confirm it round-trips (eMASS import sanity). |
| 40 | + csv_text = fl.poam_to_csv(items) |
| 41 | + rows = list(csv.DictReader(io.StringIO(csv_text))) |
| 42 | + print(f"\n CSV renders {len(rows)} data row(s), RFC 4180 quoted, header = eMASS columns.") |
| 43 | + |
| 44 | + section("Tamper-evident audit trail (hash-chained, local-only)") |
| 45 | + log_path = Path(tempfile.mkdtemp(prefix="comint_audit_")) / "audit.log" |
| 46 | + log = AuditLog(log_path) |
| 47 | + log.append({"actor": "isso", "action": "scan", "target": "demos/12-fleet-systemic"}) |
| 48 | + for it in items: |
| 49 | + log.append({"actor": "isso", "action": "poam_item", "id": it["POA&M Item ID"]}) |
| 50 | + ok, msg = log.verify() |
| 51 | + print(f" appended {len(items) + 1} entries -> verify(): intact={ok} ({msg})") |
| 52 | + |
| 53 | + # Tamper: rewrite one line's body directly, bypassing append(). |
| 54 | + lines = log_path.read_text().splitlines() |
| 55 | + lines[1] = lines[1].replace("poam_item", "poam_item_HACKED") |
| 56 | + log_path.write_text("\n".join(lines) + "\n") |
| 57 | + ok2, msg2 = log.verify() |
| 58 | + print(f" after editing one row directly: intact={ok2} ({msg2})") |
| 59 | + print("\n The chain catches the edit -> the assessment record is provable, not asserted.") |
| 60 | + |
| 61 | + |
| 62 | +if __name__ == "__main__": |
| 63 | + main() |
0 commit comments