"""artex-ai-pentest-agent-what-defenders-should-know.py - two defender checks for the ARTEX article. 1. --outcomes CSV Reads the outcomes dataset (figures from the Microsoft, CrowdStrike and Check Point reports, each row with its source URL) and prints how often each reported ARTEX campaign actually succeeded. 2. --log FILE Scans a web server access log for the behaviour that published guidance associates with agent-driven intrusion tooling, and lists the client IPs that show it. Reads Apache/nginx "combined" format or IIS W3C format (the #Fields header is read automatically). --demo Builds a small SYNTHETIC log in memory (one ordinary visitor, one agent-like client) and scans it, so the output can be seen without a real log. Nothing in the demo is real traffic. What the log check looks for, and where each signal comes from: burst-pause bursts of requests about a second apart followed by a 20-35 second pause, the "think time" of a model between steps (Kodem Security, vendor guidance, 2026-11-17) error-recovery three or more 4xx answers on one path, then a 2xx on the same path within 60 seconds: the client is fixing its request from the error (Abstract Security, vendor guidance, 2026-11-10; the FBI's "failed attempts with iterative, incremental changes", FLASH-20261113-001) ua-rotation three or more user agents from one IP inside 30 minutes (Abstract Security; access logs carry no TLS fingerprint, so this is weaker than the JA3/JA4 version of the rule) auth-pressure 30 or more requests to login, reset, verify or token paths from one IP inside 10 minutes, at least 80% of them failing (the FBI's "sequential enumeration against login/search endpoints") map-then-sweep a fetch of an API description or source map (openapi, swagger, .map, .env, config.json) followed by 20 or more distinct paths in 10 minutes (Unit 42 and Abstract Security on "attack maps") tool-agent a user agent naming a scanner or an ARTEX component (artex, norma, infra-hunt, nuclei, sqlmap, ffuf); attackers change these freely, so it only supports the other signals Every threshold is a starting point to tune against your own traffic. Authorised testers and some monitoring tools trip the same rules: a flagged IP is a lead for a person to check, not proof of an attack. This script reads a log and prints; it sends nothing anywhere and blocks nothing. Standard library only. Python 3.9 or newer. python artex-ai-pentest-agent-what-defenders-should-know.py --outcomes artex-ai-pentest-agent-what-defenders-should-know.csv python artex-ai-pentest-agent-what-defenders-should-know.py --log /var/log/nginx/access.log python artex-ai-pentest-agent-what-defenders-should-know.py --demo """ from __future__ import annotations import argparse import csv import datetime as dt import random import re from collections import defaultdict COMBINED = re.compile( r'^(?P\S+) \S+ \S+ \[(?P[^\]]+)\] "(?P[A-Z]+) (?P\S+)[^"]*" ' r'(?P\d{3}) \S+(?: "[^"]*" "(?P[^"]*)")?') AUTH_PATH = re.compile(r"(?i)(login|signin|sign-in|logon|reset|forgot|password|verify|otp|token|auth)") MAP_PATH = re.compile(r"(?i)(openapi|swagger|api-docs|\.map$|\.env$|config\.json$)") TOOL_UA = re.compile(r"(?i)(artex|norma/|infra-hunt|nuclei|sqlmap|ffuf)") def parse_combined(line): m = COMBINED.match(line) if not m: return None ts = dt.datetime.strptime(m["ts"], "%d/%b/%Y:%H:%M:%S %z") return m["ip"], ts, m["path"].split("?")[0], int(m["status"]), m["ua"] or "-" def read_log(path): """Yield (ip, time, path, status, user_agent) from a combined or W3C log.""" fields = None with open(path, encoding="utf-8", errors="replace") as fh: for line in fh: line = line.rstrip("\n") if line.startswith("#Fields:"): fields = line.split()[1:] continue if line.startswith("#") or not line.strip(): continue if fields: # IIS W3C parts = line.split(" ") if len(parts) != len(fields): continue r = dict(zip(fields, parts)) try: ts = dt.datetime.fromisoformat(f"{r['date']}T{r['time']}+00:00") yield (r["c-ip"], ts, r["cs-uri-stem"], int(r["sc-status"]), r.get("cs(User-Agent)", "-").replace("+", " ")) except (KeyError, ValueError): continue else: rec = parse_combined(line) if rec: yield rec def scan(records): by_ip = defaultdict(list) for ip, ts, path, status, ua in records: by_ip[ip].append((ts, path, status, ua)) report = {} for ip, rows in by_ip.items(): rows.sort(key=lambda r: r[0]) hits = {} # burst-pause: bursts of >= 5 requests with gaps <= 2 s, followed by a 20-35 s pause bursts, size = 0, 1 for a, b in zip(rows, rows[1:]): gap = (b[0] - a[0]).total_seconds() if gap <= 2: size += 1 else: if size >= 5 and 20 <= gap <= 35: bursts += 1 size = 1 if bursts >= 3: hits["burst-pause"] = f"{bursts} bursts followed by a 20-35 s pause" # error-recovery: >= 3 client errors on a path, then a 2xx on it within 60 s recov = 0 errs = defaultdict(list) for ts, path, status, _ in rows: if 400 <= status < 500: errs[path].append(ts) elif 200 <= status < 300 and len(errs[path]) >= 3 and (ts - errs[path][-1]).total_seconds() <= 60: recov += 1 errs[path].clear() if recov: hits["error-recovery"] = f"{recov} path(s) fixed after 3+ client errors" # ua-rotation: >= 3 user agents inside any 30-minute window best = 0 for i, r in enumerate(rows): window = {x[3] for x in rows[i:] if (x[0] - r[0]).total_seconds() <= 1800} best = max(best, len(window)) if best >= 3: hits["ua-rotation"] = f"{best} user agents within 30 minutes" # auth-pressure: >= 30 auth-path requests in 10 minutes, >= 80% failing auth = [r for r in rows if AUTH_PATH.search(r[1])] for i, r in enumerate(auth): window = [x for x in auth[i:] if (x[0] - r[0]).total_seconds() <= 600] fails = sum(1 for x in window if x[2] >= 400) if len(window) >= 30 and fails / len(window) >= 0.8: hits["auth-pressure"] = f"{len(window)} login/reset/token requests in 10 min, {fails} failed" break # map-then-sweep: an API description or source map, then >= 20 distinct paths in 10 min for i, r in enumerate(rows): if MAP_PATH.search(r[1]): later = {x[1] for x in rows[i + 1:] if (x[0] - r[0]).total_seconds() <= 600} if len(later) >= 20: hits["map-then-sweep"] = f"fetched {r[1]}, then {len(later)} distinct paths in 10 min" break # tool-agent: supporting signal only tools = sorted({r[3] for r in rows if TOOL_UA.search(r[3])}) if tools: hits["tool-agent"] = "; ".join(tools)[:120] if hits: report[ip] = (len(rows), hits) return report def print_scan(report): if not report: print("No client matched any signal.") return ranked = sorted(report.items(), key=lambda kv: (-len([k for k in kv[1][1] if k != "tool-agent"]), -kv[1][0])) for ip, (n, hits) in ranked: strong = len([k for k in hits if k != "tool-agent"]) print(f"{ip} requests={n} behavioural signals={strong}") for name, detail in hits.items(): print(f" {name:15} {detail}") print("\nA flagged IP is a lead for a person to check, not proof: authorised testers trip the same rules.") def outcomes(path): print(f"{'case':34} {'attempted':>9} {'succeeded':>9} {'rate':>7} reporter") with open(path, encoding="utf-8", newline="") as fh: for row in csv.DictReader(fh): a, s = int(row["attempted"]), int(row["succeeded"]) rate = s / a * 100 if a else 0.0 floor = "+" if row["attempted_is_floor"] == "True" else " " print(f"{row['case'][:34]:34} {a:>8,}{floor} {s:>9,} {rate:>6.1f}% {row['reporter']} {row['report_date']}") print("\n'+' = the report gives a floor ('more than'), so the true rate is at most the one shown.") def demo_log(): """A SYNTHETIC log: one ordinary visitor and one agent-like client. Not real traffic.""" rnd = random.Random(7) t0 = dt.datetime(2026, 11, 18, 9, 0, 0, tzinfo=dt.timezone.utc) out = [] t = t0 for page in ["/", "/pricing", "/blog/", "/blog/post-1", "/login", "/account"]: t += dt.timedelta(seconds=rnd.randint(8, 40)) out.append(("198.51.100.20", t, page, 200, "Mozilla/5.0 (Windows NT 10.0) Firefox/133.0")) uas = ["Mozilla/5.0 (X11; Linux x86_64) Chrome/131.0", "Mozilla/5.0 (Macintosh) Safari/605.1", "python-requests/2.32", "Mozilla/5.0 (Windows NT 10.0) Edge/131.0"] t = t0 out.append(("203.0.113.9", t, "/swagger.json", 200, uas[0])) n = 0 for burst in range(6): for k in range(8): t += dt.timedelta(seconds=1) n += 1 out.append(("203.0.113.9", t, f"/api/v1/route{n}", 404 if k % 3 else 200, uas[burst % 4])) t += dt.timedelta(seconds=rnd.randint(25, 31)) for k in range(4): t += dt.timedelta(seconds=2) out.append(("203.0.113.9", t, "/api/v1/users", 400 if k < 3 else 200, uas[1])) for k in range(40): t += dt.timedelta(seconds=3) out.append(("203.0.113.9", t, "/login", 401, uas[k % 4])) return out def main(): ap = argparse.ArgumentParser(description=__doc__.split("\n")[0]) ap.add_argument("--outcomes", help="the outcomes CSV from the article") ap.add_argument("--log", help="an access log (combined or IIS W3C format)") ap.add_argument("--demo", action="store_true", help="scan a small synthetic log") args = ap.parse_args() if not (args.outcomes or args.log or args.demo): ap.error("give --outcomes, --log or --demo") if args.outcomes: outcomes(args.outcomes) if args.log: print_scan(scan(read_log(args.log))) if args.demo: print("SYNTHETIC demo log, not real traffic:\n") print_scan(scan(demo_log())) if __name__ == "__main__": main()