"""Playbook: recent attack patterns (2024-2026) as behaviour signatures over what the engine already measures, each with the family it maps to, the action the policy should take, and a synthetic generator used by the tests. The engine's learned tiers find the unknown; the playbook makes sure the known shapes of today's attacks are named precisely and answered with the right action, and that every one of them is exercised in the test suite. | id | pattern | seen as | family | |------|-------------------------------------------|----------------------------------------------------|------------| | A01 | HTTP/2 Rapid Reset (CVE-2023-44487) | floods of request+cancel: huge request rate, tiny bytes, no replies, one host | dos | | A02 | HTTP/2 CONTINUATION flood (2024) | long header streams: very large request bytes per request, rate | dos | | A03 | L7 flood from a botnet / residential proxies| many new sources, same path, high rate per site, low per source | ddos | | A04 | credential stuffing / password spraying | repeated POST to login from one source with 4xx, or many sources one path | bruteforce | | A05 | AI / LLM scrapers and aggressive crawlers | one source walks many distinct paths at a steady cadence, bot UA or none | bot | | A06 | API enumeration / BOLA (OWASP API1) | sequential ids on one endpoint, many 404/403 | scan | | A07 | WordPress / CMS exploit waves (xmlrpc, plugin RCE, wp-login) | known paths with payloads; many hosts probed | webattack | | A08 | JNDI / Log4Shell-style injection | ${jndi: patterns in any field | rce | | A09 | reflection / amplification floods (DNS, NTP, SSDP, memcached) | UDP, huge bytes per packet to one destination, many spoofed sources | ddos | | A10 | slow scans (nmap -T1, masscan spread) | ports walked over hours by one source | portscan | | A11 | SSH / RDP brute force | same (host, port) again and again, short failed connects | bruteforce | | A12 | chain: JSON-RPC abuse (eth_getLogs / debug_ / trace_ floods) | expensive methods at high rate from one client | dos | | A13 | chain: peer / sybil flood (eclipse attempt) | many new peers from one prefix, connection churn | ddos | | A14 | chain: mempool spam / dust | high rate of sendRawTransaction from one client | dos | """ from __future__ import annotations import re import numpy as np from dibaguard.shield.rx import Gap, Sig JNDI = re.compile(r"\$\{\s*(jndi|j\$\{|lower:j|upper:j|::-j)", re.I) WP_PATHS = ("/xmlrpc.php", "/wp-login.php", "/wp-json/wp/v2/users", "/wp-content/plugins/", "/wp-admin/admin-ajax.php", "/?rest_route=") # platform-agnostic request signatures (detection patterns in the spirit of the OWASP Core Rule Set). They fire on # the decoded canonical request text, for any platform (WordPress, Joomla, Drupal, Laravel, Django, APIs, ...). # Branches shaped "X .* Y" are rx.Gap matchers, not regex branches: on crafted input ("", _I), # <\s*svg[^>]*\bon\w+\s*= # any event handler inside a tag; the HTML tokenizer also separates attributes with '/': # (V-04) # <\s*[a-z][^>]*[\s/]on[a-z]{3,}\s*= Gap([r"<\s*[a-z]", r"[\s/]on[a-z]{3,}\s*="], ">", _I), flags=_I), "A20": Sig(r"\{\{\s*\d+\s*\*\s*\d+\s*\}\}|\$\{\s*\d+\s*\*\s*\d+\s*\}|", _I), # ]*\[ flags=_I), "A21": Sig(r"/\.git/|/\.env\b|/\.svn/|/\.htpasswd|/\.aws/credentials|wp-config\.php\.(bak|old|save|swp|orig|txt)|/server-status|/phpinfo\.php" r"|/(backup|db|dump|database|site)\.(zip|tar|tar\.gz|tgz|sql|sql\.gz|7z)\b|/\.ds_store|/web\.config\.(bak|old)", flags=_I), # AI crawlers that declare themselves (the site's policy decides: challenge by default, 'bot': 'monitor' to allow) "A05": Sig(None, Gap([r"h:user-agent=", r"\b(gptbot|chatgpt-user|oai-searchbot|claudebot|claude-web|anthropic-ai|ccbot|bytespider|perplexitybot" r"|amazonbot|meta-externalagent|diffbot|omgilibot|youbot|cohere-ai|imagesiftbot|timpibot|ai2bot)\b"], r"\|", _I)), } # A07 (CMS exploit wave): only clear exploit shapes, never ordinary WordPress endpoints (admin-ajax heartbeat, wp-json posts) CMS_EXPLOIT = Sig(r"wp-file-manager/lib/php/connector|/wp-json/wp/v2/users/\d+", Gap([r"/xmlrpc\.php", r"system\.multicall"], None, _I), Gap([r"revslider", r"update_extract"], None, _I), Gap([r"revslider", r"show_image", r"\.\."], None, _I), Gap([r"/wp-admin/admin-ajax\.php", r"action=(revslider_show_image|duplicator_download)"], None, _I), Gap([r"com_fields", r"list\[fullordering\]"], None, _I), Gap([r"/user/register", r"element_parents", r"#value"], None, _I), flags=_I) EXPENSIVE_RPC = ("eth_getlogs", "debug_", "trace_", "eth_call", "eth_estimategas", "eth_sendrawtransaction") PLAYBOOK = [ {"id": "A01", "name": "HTTP/2 Rapid Reset", "family": "dos", "action": "rate_limit", "where": "edge-waf,net-sensor", "signature": "src_flows_h1 >= 200 and src_noreply_h1 > 0.8 and src_newport_h1 < 0.2 (one service hammered, nothing answered)"}, {"id": "A02", "name": "HTTP/2 CONTINUATION flood", "family": "dos", "action": "rate_limit", "where": "edge-waf", "signature": "request header bytes >> site p99 at high rate from one source"}, {"id": "A03", "name": "L7 botnet flood", "family": "ddos", "action": "challenge", "where": "edge-waf,net-sensor", "signature": "dst_newsrc_h1 > 0.5 and dst_flows_h1 >= 500: site pressure, many fresh sources, one path"}, {"id": "A04", "name": "credential stuffing", "family": "bruteforce", "action": "block", "where": "edge-waf", "signature": "repeated POST to a login path from one source with failures (status >= 400) -> session stream repeat + short"}, {"id": "A05", "name": "AI scraper / aggressive crawler", "family": "bot", "action": "challenge", "where": "edge-waf", "signature": "one source walks many distinct paths (newport share on the path hash high) at a steady cadence"}, {"id": "A06", "name": "API enumeration / BOLA", "family": "scan", "action": "challenge", "where": "edge-waf", "signature": "sequential ids on one endpoint with 4xx -> session stream newport high + noreply high"}, {"id": "A07", "name": "WordPress / CMS exploit wave", "family": "webattack", "action": "block", "where": "edge-waf", "signature": "known CMS paths with payloads; novelty high on a non-WordPress site"}, {"id": "A08", "name": "JNDI / Log4Shell", "family": "rce", "action": "block", "where": "edge-waf", "signature": "${jndi: (and its obfuscations) anywhere in the request"}, {"id": "A09", "name": "reflection / amplification", "family": "ddos", "action": "rate_limit", "where": "net-sensor", "signature": "UDP, large bytes per packet, one destination, many sources, dst_newsrc_h1 high"}, {"id": "A10", "name": "slow scan", "family": "portscan", "action": "block", "where": "net-sensor,host-firewall", "signature": "src_newport_h3 > 0.5 with noreply/synonly over the 30-min horizon (evidence accumulates for hours)"}, {"id": "A11", "name": "SSH / RDP brute force", "family": "bruteforce", "action": "block", "where": "net-sensor,host-firewall", "signature": "src_repeat_h2 > 0.6 with short / failed connects"}, {"id": "A12", "name": "chain RPC abuse", "family": "dos", "action": "rate_limit", "where": "chain-node", "signature": "expensive methods (eth_getLogs, debug_*, trace_*) at high rate from one client"}, {"id": "A13", "name": "chain peer / sybil flood", "family": "ddos", "action": "block", "where": "chain-node,net-sensor", "signature": "many new peers from one /24 with connection churn on the p2p port"}, {"id": "A14", "name": "chain mempool spam", "family": "dos", "action": "rate_limit", "where": "chain-node", "signature": "eth_sendRawTransaction at high rate from one client, tiny values"}, {"id": "A15", "name": "SQL injection", "family": "sqli", "action": "block", "where": "edge-waf", "signature": "UNION SELECT, boolean tautologies, error/time-based functions (updatexml, sleep, benchmark, pg_sleep), information_schema"}, {"id": "A16", "name": "NoSQL injection", "family": "nosqli", "action": "block", "where": "edge-waf", "signature": "MongoDB operators ($ne, $gt, $where, $regex) in JSON bodies or query arrays"}, {"id": "A17", "name": "path traversal / LFI", "family": "traversal", "action": "block", "where": "edge-waf", "signature": "../ chains, /etc/passwd, php://filter, file:// and other wrapper schemes"}, {"id": "A18", "name": "RCE / command injection", "family": "rce", "action": "block", "where": "edge-waf", "signature": "shell metacharacters + commands, PHP exec functions, Drupalgeddon render arrays, plugin connector exploits, Shellshock"}, {"id": "A19", "name": "cross-site scripting", "family": "xss", "action": "block", "where": "edge-waf", "signature": "