http rules: make the LogQL prefilter a superset of classify()
`http-sqli` was unreachable end to end: the prefilter admitted only `union select`, so boolean (`' OR '1'='1`, `%27%20OR%20…`) and time-based (`sleep(`, `waitfor delay`) payloads were dropped in Loki before Python saw them, and the canary passed because it used the one admitted shape. The prefilter now carries the missing shapes as plain literals (a nested `(?:...)` group made Loki's filter 10x slower, and re-ordering the alternation measured 20-60 s, so the old block stays first and the additions append). Over-match measured on 2026-11-27 06:00-07:00Z over 29 426 lines: 1 202 -> 1 548 lines/h (+29 %), 10-minute query 3.9 s. The extra lines are Forgejo browse URLs that classify() drops; a calm 10-minute window of 394 admitted lines yields 0 findings. Durability: tests/fixtures/attack-shapes.json is one table of 105 payload shapes iterated by both tests - classify() must flag each one and config.HTTP_LINE_FILTER must match its serialized access line. It fails with 44 dropped shapes on the old filter and passes now, so this class of drift (any rule kind, not just sqli) cannot come back silently. Docs also record the data-source limit the bug surfaced: Cloudflare collapses dot-segments in the path, so `/../../etc/passwd` arrives as `/etc/passwd` and path traversal is only detectable in a query string (or off-tunnel).
This commit is contained in:
parent
bdb1463630
commit
ef7e584d27
5 changed files with 867 additions and 18 deletions
659
tests/fixtures/attack-shapes.json
vendored
Normal file
659
tests/fixtures/attack-shapes.json
vendored
Normal file
|
|
@ -0,0 +1,659 @@
|
|||
{
|
||||
"_comment": "Contract table for the LogQL prefilter superset property (t_a3604aab). Every shape here must (a) be flagged by netsec_scan.http_rules.classify() with the recorded category/severity/rule and (b) match config.HTTP_LINE_FILTER on its serialized envoy access line. A shape classify() knows but the prefilter drops is invisible end to end: Loki never returns the line, so no test of classify() alone can catch it. Includes the four boolean/time-based sqli payloads that shipped unreachable.",
|
||||
"shapes": [
|
||||
{
|
||||
"path": "/?id=1%27%20OR%20%271%27=%271",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1' OR '1'='1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1%27%3BWAITFOR%20DELAY%20%270:0:5%27",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1%27%20AND%20sleep(5)--",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/index.php?q=union+select+1,2",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/item?id=1 union all select user,pass from users",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1%27+or+1%3D1--",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1 or 1=1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1%20or%201%3D1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1+or+1%3D1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1%2Bor%2B1%3D1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1)or 1=1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1%29or%201=1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1' and '1'='1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?id=1 or \"1\"=\"1\"",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/x.php?id=1;sleep(5)",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1;benchmark(100000,md5(1))",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1;pg_sleep(5)",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1;drop table users",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1%3Bdrop%20table%20users",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=information_schema.tables",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=sysobjects",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=extractvalue(1,concat(0x7e))",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=updatexml(1,1)",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=load_file('/etc/passwd')",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1 into outfile '/tmp/x'",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1;update users set x=1",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1;insert into t values(1)",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?q=1;delete from t",
|
||||
"rule": "http-sqli",
|
||||
"category": "sqli",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/../../etc/passwd",
|
||||
"rule": "http-traversal",
|
||||
"category": "traversal",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/%2e%2e%2fetc%2fpasswd",
|
||||
"rule": "http-traversal",
|
||||
"category": "traversal",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/..%2fetc/passwd",
|
||||
"rule": "http-traversal",
|
||||
"category": "traversal",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/%252e%252e/etc/passwd",
|
||||
"rule": "http-traversal",
|
||||
"category": "traversal",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/..\\windows\\win.ini",
|
||||
"rule": "http-traversal",
|
||||
"category": "traversal",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/?file=../../../etc/passwd",
|
||||
"rule": "http-traversal",
|
||||
"category": "traversal",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.env%00.txt",
|
||||
"rule": "http-nul-byte",
|
||||
"category": "nul-byte",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/a%2500b",
|
||||
"rule": "http-nul-byte",
|
||||
"category": "nul-byte",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.env",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/backup/.env",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "./.envrc",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.aws/credentials",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.ssh/id_rsa",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.ssh/id_dsa",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.ssh/id_ecdsa",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.ssh/id_ed25519",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.ssh/authorized_keys",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.docker/config.json",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.kube/config",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git-credentials",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.npmrc",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.pypirc",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.netrc",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.pgpass",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.my.cnf",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.htpasswd",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/client_secret.json",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/application_default_credentials.json",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/latest/meta-data/iam/security-credentials",
|
||||
"rule": "http-secret-probe",
|
||||
"category": "secret-file",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git/config",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git/HEAD",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git/index",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git/packed-refs",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git/logs/HEAD",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.git/credentials",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.svn/entries",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.hg/hgrc",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/.bzr/README",
|
||||
"rule": "http-vcs-probe",
|
||||
"category": "vcs-probe",
|
||||
"severity": "MEDIUM"
|
||||
},
|
||||
{
|
||||
"path": "/backup.zip",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/db.sql",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/site.tar.gz",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/config.php.bak",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/credentials.old",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/backup.rar",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/db.7z",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/site.bz2",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/db.gz",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/x.swo",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/x.orig",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/x.save",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/x.swp",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/x.dump",
|
||||
"rule": "http-backup-probe",
|
||||
"category": "backup-file",
|
||||
"severity": "LOW"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:sqlmap",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "sqlmap/1.8#stable (https://sqlmap.org)"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:nikto",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "Mozilla/5.00 (Nikto/2.5.0)"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:nuclei",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "Nuclei - Open-source project (github.com/projectdiscovery/nuclei)"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:masscan",
|
||||
"severity": "LOW",
|
||||
"user_agent": "masscan/1.3"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:zgrab",
|
||||
"severity": "LOW",
|
||||
"user_agent": "zgrab/0.x"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:nmap",
|
||||
"severity": "LOW",
|
||||
"user_agent": "Nmap Scripting Engine"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:wpscan",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "WPScan v3.8.25"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:gobuster",
|
||||
"severity": "MEDIUM",
|
||||
"user_agent": "gobuster/3.6"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:dirbuster",
|
||||
"severity": "MEDIUM",
|
||||
"user_agent": "dirbuster-1.0"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:dirb",
|
||||
"severity": "MEDIUM",
|
||||
"user_agent": "dirb/2.22"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:ffuf",
|
||||
"severity": "MEDIUM",
|
||||
"user_agent": "ffuf/2.1.0"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:feroxbuster",
|
||||
"severity": "MEDIUM",
|
||||
"user_agent": "feroxbuster/2.10.0"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:acunetix",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "Acunetix-Product"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:netsparker",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "Netsparker/6.0"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:nessus",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "Nessus SOAP"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:openvas",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "OpenVAS"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:hydra",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "hydra/9.5"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:w3af",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "w3af/1.7"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:zaproxy",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "Zaproxy/2.14.0"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:commix",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "commix/v3.9"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:jaeles",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "jaeles/v1.0"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:ysoserial",
|
||||
"severity": "HIGH",
|
||||
"user_agent": "ysoserial"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:whatweb",
|
||||
"severity": "LOW",
|
||||
"user_agent": "whatweb/0.5.5"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"rule": "http-scanner-ua",
|
||||
"category": "scanner-ua:gospider",
|
||||
"severity": "LOW",
|
||||
"user_agent": "gospider/1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -8,7 +8,10 @@ ending in `.gitignore`, one ending in `.env.example` behind an RSS route, and a
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from netsec_scan import config, http_rules
|
||||
|
||||
|
|
@ -86,6 +89,66 @@ class TestClassification(unittest.TestCase):
|
|||
self.assertIsNone(http_rules.classify(rec(path, code=200, ua=ua)), path)
|
||||
|
||||
|
||||
class TestPrefilterSuperset(unittest.TestCase):
|
||||
"""The LogQL prefilter must admit every shape `classify()` can flag.
|
||||
|
||||
A too-narrow prefilter is invisible from Python: Loki never returns the
|
||||
line, so no amount of testing `classify()` can catch it. That is how
|
||||
`http-sqli` shipped unreachable for weeks — only `union select` reached the
|
||||
classifier, and the canary happened to use exactly that shape.
|
||||
|
||||
One table, iterated by both tests: `tests/fixtures/attack-shapes.json` is
|
||||
the contract. Adding a rule or a payload shape to `http_rules` without
|
||||
adding it here (and to `config.HTTP_LINE_FILTER`) is the drift this catches.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def table():
|
||||
path = Path(__file__).with_name("fixtures") / "attack-shapes.json"
|
||||
return json.loads(path.read_text(encoding="utf-8"))["shapes"]
|
||||
|
||||
@staticmethod
|
||||
def record(shape):
|
||||
return {
|
||||
"path": shape["path"],
|
||||
"method": shape.get("method", "GET"),
|
||||
"response_code": shape.get("response_code", 404),
|
||||
"user_agent": shape.get("user_agent", "curl/8.23.0"),
|
||||
"authority": shape.get("authority", "siriusdevops.com"),
|
||||
"client_ip": shape.get("client_ip", "203.0.113.7"),
|
||||
"peer": "10.10.0.1",
|
||||
}
|
||||
|
||||
def test_table_matches_classify(self):
|
||||
for shape in self.table():
|
||||
with self.subTest(path=shape["path"]):
|
||||
hit = http_rules.classify(self.record(shape))
|
||||
self.assertIsNotNone(hit, shape["path"])
|
||||
self.assertEqual(
|
||||
hit, (shape["category"], shape["severity"], shape["rule"]))
|
||||
|
||||
def test_logql_prefilter_admits_every_classified_shape(self):
|
||||
prefilter = re.compile(config.HTTP_LINE_FILTER)
|
||||
missed = [
|
||||
shape["path"]
|
||||
for shape in self.table()
|
||||
if not prefilter.search(json.dumps(self.record(shape), separators=(",", ":")))
|
||||
]
|
||||
self.assertEqual(
|
||||
missed, [],
|
||||
"classify() flags these, but the Loki prefilter drops them before "
|
||||
"Python ever sees the line: %r" % missed[:8])
|
||||
|
||||
def test_the_four_reported_sqli_payloads_are_in_the_table(self):
|
||||
"""Regression pin for t_a3604aab: these four were dropped, verbatim."""
|
||||
shapes = {s["path"] for s in self.table()}
|
||||
for path in ("/?id=1%27%20OR%20%271%27=%271",
|
||||
"/?id=1' OR '1'='1",
|
||||
"/?id=1%27%3BWAITFOR%20DELAY%20%270:0:5%27",
|
||||
"/?q=1%27%20AND%20sleep(5)--"):
|
||||
self.assertIn(path, shapes)
|
||||
|
||||
|
||||
class TestForgejoFalsePositives(unittest.TestCase):
|
||||
"""The shapes that made a naive rule unusable on this stream."""
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue