weblogchecker 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Superstar Telecom LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: weblogchecker
3
+ Version: 0.2.2
4
+ Summary: Free access-log compromise analyzer: reads Apache/nginx logs you own and reports webshell interactions, exploitation patterns and brute-force bursts - with severity, confidence and remediation. Read-only, no network.
5
+ Author: Superstar Telecom LLC
6
+ License: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # weblogchecker
13
+
14
+ **Your web server logs already know if you were attacked. weblogchecker reads them.**
15
+
16
+ `phpscan` tells you whether your PHP is exposed. `phpscan hunt` searches the
17
+ webroot for shells. weblogchecker answers the third question — *did anyone
18
+ actually use them?* — from the one record most sites already have and nobody
19
+ reads: the access log.
20
+
21
+ It streams Apache and nginx access logs **you own**, finds the interactions
22
+ that matter — a webshell answering requests, a brute-force burst that ends in
23
+ a redirect, an exploit pattern that got a 200 — and reports each one with
24
+ **severity, confidence, the actual log lines as evidence, and what to do
25
+ about it**.
26
+
27
+ ```bash
28
+ weblogchecker analyze /var/log/apache2/access.log
29
+ ```
30
+
31
+ Exit codes: `0` = no indicators, `1` = indicators found, `2` = usage error.
32
+ Add `--format json` for machine-readable output, `--since 2026-10-01` to
33
+ limit the window. `.gz` logs are read directly; `-` reads stdin.
34
+
35
+ **New in 0.2.0 — baseline diff.** Signature lists only know shells that
36
+ already have names. The shell that lands on *your* site has a random one.
37
+ Give weblogchecker a trusted older log from the same site and it reports
38
+ the executables that were never there before:
39
+
40
+ ```bash
41
+ weblogchecker analyze access.log --baseline access.log.last-month
42
+ ```
43
+
44
+ Every executable path (.php, .phtml, .cgi, .asp, .jsp…) that appears for
45
+ the first time is scored on five weak signals from the log alone —
46
+ answered 2xx/3xx, POST/PUT used, referrer-less, hit by at most 2 IPs,
47
+ sitting under an upload/cache/temp directory — and reported as `NEW`
48
+ with the signals, counts and log lines as evidence. First-seen alone is
49
+ a low-severity note; severity climbs only as signals stack (details
50
+ below), so a plugin you installed last week does not read as an
51
+ incident.
52
+
53
+ ## Install
54
+
55
+ One line, from PyPI (Python 3.11+, standard library only — zero dependencies):
56
+
57
+ ```bash
58
+ pip install weblogchecker
59
+ ```
60
+
61
+ > **First PyPI release pending.** Until the PyPI trusted publisher is
62
+ > configured, install the identical code from GitHub:
63
+ > `pip install git+https://github.com/PHPatch/weblogchecker.git`
64
+ > (or download the signed release tarball below). The `pip install
65
+ > weblogchecker` line above works as soon as the first PyPI release lands.
66
+
67
+ On systems that refuse with "externally-managed-environment"
68
+ (Debian/Ubuntu and Homebrew Pythons), use pipx instead:
69
+
70
+ ```bash
71
+ python3 -m pip install --user pipx # if you don't have pipx yet
72
+ pipx install weblogchecker
73
+ ```
74
+
75
+ Signed releases (sdist + wheel + PGP signatures + SBOM) are on the
76
+ [GitHub releases page](https://github.com/PHPatch/weblogchecker/releases).
77
+ Verify signatures with the key in `pgp-key.asc` — fingerprint
78
+ `BAA1 586A AD37 18C0 CE41 D288 FE23 A624 54E3 5307`. See `SECURITY.md`.
79
+
80
+ ## What it detects
81
+
82
+ | Pattern in your log | Severity / confidence | Why it matters |
83
+ | --- | --- | --- |
84
+ | Known webshell (c99, r57, FilesMan, b374k, WSO) answering 2xx | high / high | The shell exists and served a request |
85
+ | Same names probed but 404/403 | low / low | Someone looked; nothing found — context, not alarm |
86
+ | `eval-stdin.php` (phpunit) answering | high / high | The UnitTest shell from the Oct 2026 php2shell wave executes POSTed code |
87
+ | Executable (.php etc.) inside `/uploads/`, `/media/`, `/files/`… answering, esp. POST | high / high | Upload dirs must never run code |
88
+ | POST/PUT to a static file (.jpg, .css…) answered 2xx | high / medium | Browsers don't POST to images; the "image" is often a script |
89
+ | Exploit pattern in the URI (traversal, `eval(`, `php://`, long base64 token) answered 2xx | high / medium | The attempt may have worked |
90
+ | Same patterns blocked / 404 | low / low | Background noise; useful only as campaign context |
91
+ | Brute-force burst on wp-login.php / xmlrpc.php (≥20 POSTs / 10 min) | medium / medium | One IP, inhuman pace |
92
+ | A 302 inside that burst after repeated failures | high / medium | The shape of a correct password — possible takeover |
93
+ | Scanner user-agents (sqlmap, nuclei, nikto…) | low / low | Informational; scanning is not compromise |
94
+ | Executable path absent from your `--baseline` log, answering requests | low → high / ≤ medium | The unknown-named shell no blocklist knows; severity stacks with POSTs, missing referrers, few IPs, upload dirs |
95
+
96
+ Every finding class carries remediation text: quarantine the file, rotate
97
+ credentials, review everything that IP touched. Webshell findings point at
98
+ the companion tool — **`phpscan hunt`** (`pip install phpscan`,
99
+ [github.com/PHPatch/phpscan](https://github.com/PHPatch/phpscan)) — which
100
+ scans the webroot itself for the shells these log patterns point at.
101
+
102
+ ## Honesty rules
103
+
104
+ This tool was built under the same doctrine as phpscan:
105
+
106
+ - **Indicators, not verdicts.** A finding says "this pattern appears in your
107
+ log, with this confidence" — never "you were hacked". A clean result says
108
+ "none of these patterns appear in this window" — never "you are safe".
109
+ Attackers who arrive over SSH, a stolen session cookie, or a log the
110
+ server never wrote leave nothing for this tool to find.
111
+ - **Failed attempts stay low.** A 404 probe is someone knocking, not someone
112
+ inside. Severity follows the server's answer, not the request's intent.
113
+ - **False-positive discipline is tested, not promised.** The test suite
114
+ ships a fixture of a normal busy WordPress day — admin logins, plugin
115
+ updates, wp-cron, image uploads through wp-admin, Jetpack xmlrpc pings —
116
+ and asserts it produces **zero findings**. A second fixture pair covers
117
+ the baseline mode: a normal WordPress baseline plus a later log whose
118
+ only novelties are a plugin installed through wp-admin, a contact form
119
+ posting to a new handler, and a new post must produce **zero
120
+ medium/high findings**. If a detector ever fires on ordinary admin
121
+ work, that's a bug; please report it.
122
+ - **First-seen is a note, not an accusation.** In baseline mode a new
123
+ executable starts at low severity, climbs only when independent weak
124
+ signals stack (never on first appearance alone), is capped when its
125
+ first hit arrived from a wp-admin page — the shape of you installing
126
+ something — and its confidence never exceeds medium. The finding says
127
+ "this file was not in your baseline and behaves like this", with the
128
+ counts to judge for yourself.
129
+ - **Read-only and offline.** weblogchecker opens no network connections and
130
+ never modifies the log it analyzes. Your logs — which reveal your
131
+ visitors' IPs — never leave your machine.
132
+
133
+ ## Performance
134
+
135
+ Parsing is line-streaming: the file is never loaded into memory, and
136
+ aggregation keeps at most five evidence lines per finding. Measured on this
137
+ project's fixture generator (366,306 lines, 72 MB of realistic combined
138
+ log): **7.6 seconds, 12.8 MB peak RSS** on a modest VM. A 2 GB log is the
139
+ same memory, proportionally more time.
140
+
141
+ ## Example
142
+
143
+ ```
144
+ $ weblogchecker analyze access.log
145
+ weblogchecker 0.2.0 - access-log compromise analysis
146
+ Log: access.log
147
+ Lines read: 13 | parsed: 13 | unparseable (skipped): 0
148
+
149
+ Indicators found. These are leads for investigation, not proof of
150
+ compromise: work through the findings in severity order ...
151
+
152
+ SUMMARY: 10 findings (4 high, 1 medium, 5 low) across 9 incidents, 2 IPs flagged
153
+
154
+ INCIDENT TIMELINE (grouped by IP + path):
155
+ [HIGH] 198.51.100.66 /wp-content/uploads/2026/10/c99.php
156
+ classes: webshell-access, exec-in-upload-dir | requests: 6 | ...
157
+ ...
158
+
159
+ 1. [high severity / high confidence] Known webshell filename answered a request
160
+ 198.51.100.66 /wp-content/uploads/2026/10/c99.php - 3 request(s), ...
161
+ | 198.51.100.66 - - [28/Oct/2026:03:13:40 +0000] "GET /wp-content/..." 200 ...
162
+ Remediation: Treat the named file as a live webshell until you have
163
+ proven otherwise. Locate it in the webroot and quarantine it ...
164
+ ```
165
+
166
+ ## The family
167
+
168
+ - [phpscan](https://github.com/PHPatch/phpscan) — is your PHP exposed?
169
+ (version/CVE verdicts, composer audit, `hunt` for shells on disk)
170
+ - **weblogchecker** — did anyone exploit it? (this tool, from your logs)
171
+ - wpchecker — is your WordPress plugin stack exposed? (companion scanner)
172
+
173
+ All free, all open source, none of them send exploit probes.
174
+
175
+ ## License
176
+
177
+ MIT — see `LICENSE`. Security reports: see `SECURITY.md`.
@@ -0,0 +1,166 @@
1
+ # weblogchecker
2
+
3
+ **Your web server logs already know if you were attacked. weblogchecker reads them.**
4
+
5
+ `phpscan` tells you whether your PHP is exposed. `phpscan hunt` searches the
6
+ webroot for shells. weblogchecker answers the third question — *did anyone
7
+ actually use them?* — from the one record most sites already have and nobody
8
+ reads: the access log.
9
+
10
+ It streams Apache and nginx access logs **you own**, finds the interactions
11
+ that matter — a webshell answering requests, a brute-force burst that ends in
12
+ a redirect, an exploit pattern that got a 200 — and reports each one with
13
+ **severity, confidence, the actual log lines as evidence, and what to do
14
+ about it**.
15
+
16
+ ```bash
17
+ weblogchecker analyze /var/log/apache2/access.log
18
+ ```
19
+
20
+ Exit codes: `0` = no indicators, `1` = indicators found, `2` = usage error.
21
+ Add `--format json` for machine-readable output, `--since 2026-10-01` to
22
+ limit the window. `.gz` logs are read directly; `-` reads stdin.
23
+
24
+ **New in 0.2.0 — baseline diff.** Signature lists only know shells that
25
+ already have names. The shell that lands on *your* site has a random one.
26
+ Give weblogchecker a trusted older log from the same site and it reports
27
+ the executables that were never there before:
28
+
29
+ ```bash
30
+ weblogchecker analyze access.log --baseline access.log.last-month
31
+ ```
32
+
33
+ Every executable path (.php, .phtml, .cgi, .asp, .jsp…) that appears for
34
+ the first time is scored on five weak signals from the log alone —
35
+ answered 2xx/3xx, POST/PUT used, referrer-less, hit by at most 2 IPs,
36
+ sitting under an upload/cache/temp directory — and reported as `NEW`
37
+ with the signals, counts and log lines as evidence. First-seen alone is
38
+ a low-severity note; severity climbs only as signals stack (details
39
+ below), so a plugin you installed last week does not read as an
40
+ incident.
41
+
42
+ ## Install
43
+
44
+ One line, from PyPI (Python 3.11+, standard library only — zero dependencies):
45
+
46
+ ```bash
47
+ pip install weblogchecker
48
+ ```
49
+
50
+ > **First PyPI release pending.** Until the PyPI trusted publisher is
51
+ > configured, install the identical code from GitHub:
52
+ > `pip install git+https://github.com/PHPatch/weblogchecker.git`
53
+ > (or download the signed release tarball below). The `pip install
54
+ > weblogchecker` line above works as soon as the first PyPI release lands.
55
+
56
+ On systems that refuse with "externally-managed-environment"
57
+ (Debian/Ubuntu and Homebrew Pythons), use pipx instead:
58
+
59
+ ```bash
60
+ python3 -m pip install --user pipx # if you don't have pipx yet
61
+ pipx install weblogchecker
62
+ ```
63
+
64
+ Signed releases (sdist + wheel + PGP signatures + SBOM) are on the
65
+ [GitHub releases page](https://github.com/PHPatch/weblogchecker/releases).
66
+ Verify signatures with the key in `pgp-key.asc` — fingerprint
67
+ `BAA1 586A AD37 18C0 CE41 D288 FE23 A624 54E3 5307`. See `SECURITY.md`.
68
+
69
+ ## What it detects
70
+
71
+ | Pattern in your log | Severity / confidence | Why it matters |
72
+ | --- | --- | --- |
73
+ | Known webshell (c99, r57, FilesMan, b374k, WSO) answering 2xx | high / high | The shell exists and served a request |
74
+ | Same names probed but 404/403 | low / low | Someone looked; nothing found — context, not alarm |
75
+ | `eval-stdin.php` (phpunit) answering | high / high | The UnitTest shell from the Oct 2026 php2shell wave executes POSTed code |
76
+ | Executable (.php etc.) inside `/uploads/`, `/media/`, `/files/`… answering, esp. POST | high / high | Upload dirs must never run code |
77
+ | POST/PUT to a static file (.jpg, .css…) answered 2xx | high / medium | Browsers don't POST to images; the "image" is often a script |
78
+ | Exploit pattern in the URI (traversal, `eval(`, `php://`, long base64 token) answered 2xx | high / medium | The attempt may have worked |
79
+ | Same patterns blocked / 404 | low / low | Background noise; useful only as campaign context |
80
+ | Brute-force burst on wp-login.php / xmlrpc.php (≥20 POSTs / 10 min) | medium / medium | One IP, inhuman pace |
81
+ | A 302 inside that burst after repeated failures | high / medium | The shape of a correct password — possible takeover |
82
+ | Scanner user-agents (sqlmap, nuclei, nikto…) | low / low | Informational; scanning is not compromise |
83
+ | Executable path absent from your `--baseline` log, answering requests | low → high / ≤ medium | The unknown-named shell no blocklist knows; severity stacks with POSTs, missing referrers, few IPs, upload dirs |
84
+
85
+ Every finding class carries remediation text: quarantine the file, rotate
86
+ credentials, review everything that IP touched. Webshell findings point at
87
+ the companion tool — **`phpscan hunt`** (`pip install phpscan`,
88
+ [github.com/PHPatch/phpscan](https://github.com/PHPatch/phpscan)) — which
89
+ scans the webroot itself for the shells these log patterns point at.
90
+
91
+ ## Honesty rules
92
+
93
+ This tool was built under the same doctrine as phpscan:
94
+
95
+ - **Indicators, not verdicts.** A finding says "this pattern appears in your
96
+ log, with this confidence" — never "you were hacked". A clean result says
97
+ "none of these patterns appear in this window" — never "you are safe".
98
+ Attackers who arrive over SSH, a stolen session cookie, or a log the
99
+ server never wrote leave nothing for this tool to find.
100
+ - **Failed attempts stay low.** A 404 probe is someone knocking, not someone
101
+ inside. Severity follows the server's answer, not the request's intent.
102
+ - **False-positive discipline is tested, not promised.** The test suite
103
+ ships a fixture of a normal busy WordPress day — admin logins, plugin
104
+ updates, wp-cron, image uploads through wp-admin, Jetpack xmlrpc pings —
105
+ and asserts it produces **zero findings**. A second fixture pair covers
106
+ the baseline mode: a normal WordPress baseline plus a later log whose
107
+ only novelties are a plugin installed through wp-admin, a contact form
108
+ posting to a new handler, and a new post must produce **zero
109
+ medium/high findings**. If a detector ever fires on ordinary admin
110
+ work, that's a bug; please report it.
111
+ - **First-seen is a note, not an accusation.** In baseline mode a new
112
+ executable starts at low severity, climbs only when independent weak
113
+ signals stack (never on first appearance alone), is capped when its
114
+ first hit arrived from a wp-admin page — the shape of you installing
115
+ something — and its confidence never exceeds medium. The finding says
116
+ "this file was not in your baseline and behaves like this", with the
117
+ counts to judge for yourself.
118
+ - **Read-only and offline.** weblogchecker opens no network connections and
119
+ never modifies the log it analyzes. Your logs — which reveal your
120
+ visitors' IPs — never leave your machine.
121
+
122
+ ## Performance
123
+
124
+ Parsing is line-streaming: the file is never loaded into memory, and
125
+ aggregation keeps at most five evidence lines per finding. Measured on this
126
+ project's fixture generator (366,306 lines, 72 MB of realistic combined
127
+ log): **7.6 seconds, 12.8 MB peak RSS** on a modest VM. A 2 GB log is the
128
+ same memory, proportionally more time.
129
+
130
+ ## Example
131
+
132
+ ```
133
+ $ weblogchecker analyze access.log
134
+ weblogchecker 0.2.0 - access-log compromise analysis
135
+ Log: access.log
136
+ Lines read: 13 | parsed: 13 | unparseable (skipped): 0
137
+
138
+ Indicators found. These are leads for investigation, not proof of
139
+ compromise: work through the findings in severity order ...
140
+
141
+ SUMMARY: 10 findings (4 high, 1 medium, 5 low) across 9 incidents, 2 IPs flagged
142
+
143
+ INCIDENT TIMELINE (grouped by IP + path):
144
+ [HIGH] 198.51.100.66 /wp-content/uploads/2026/10/c99.php
145
+ classes: webshell-access, exec-in-upload-dir | requests: 6 | ...
146
+ ...
147
+
148
+ 1. [high severity / high confidence] Known webshell filename answered a request
149
+ 198.51.100.66 /wp-content/uploads/2026/10/c99.php - 3 request(s), ...
150
+ | 198.51.100.66 - - [28/Oct/2026:03:13:40 +0000] "GET /wp-content/..." 200 ...
151
+ Remediation: Treat the named file as a live webshell until you have
152
+ proven otherwise. Locate it in the webroot and quarantine it ...
153
+ ```
154
+
155
+ ## The family
156
+
157
+ - [phpscan](https://github.com/PHPatch/phpscan) — is your PHP exposed?
158
+ (version/CVE verdicts, composer audit, `hunt` for shells on disk)
159
+ - **weblogchecker** — did anyone exploit it? (this tool, from your logs)
160
+ - wpchecker — is your WordPress plugin stack exposed? (companion scanner)
161
+
162
+ All free, all open source, none of them send exploit probes.
163
+
164
+ ## License
165
+
166
+ MIT — see `LICENSE`. Security reports: see `SECURITY.md`.
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "weblogchecker"
7
+ version = "0.2.2"
8
+ description = "Free access-log compromise analyzer: reads Apache/nginx logs you own and reports webshell interactions, exploitation patterns and brute-force bursts - with severity, confidence and remediation. Read-only, no network."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "Superstar Telecom LLC" }]
13
+
14
+ [project.scripts]
15
+ weblogchecker = "weblogchecker.__main__:cli"
16
+
17
+ [tool.setuptools]
18
+ packages = ["weblogchecker"]
19
+
20
+ [tool.setuptools.package-data]
21
+ weblogchecker = ["data/*.json"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,205 @@
1
+ import io
2
+ import json
3
+ import unittest
4
+ from datetime import date
5
+ from pathlib import Path
6
+
7
+ from weblogchecker.analyze import Analyzer, parse_line, parse_timestamp
8
+
9
+ FIXTURES = Path(__file__).parent / "fixtures"
10
+
11
+
12
+ def analyze_fixture(name, since=None):
13
+ analyzer = Analyzer(since=since)
14
+ with open(FIXTURES / name, encoding="utf-8") as fh:
15
+ analyzer.run(fh)
16
+ return analyzer.report(name, "test")
17
+
18
+
19
+ def classes(report):
20
+ return {f["class"] for f in report["findings"]}
21
+
22
+
23
+ def by_class(report, class_id):
24
+ return [f for f in report["findings"] if f["class"] == class_id]
25
+
26
+
27
+ class ParserTests(unittest.TestCase):
28
+ def test_combined_line(self):
29
+ entry = parse_line(
30
+ '192.0.2.1 - frank [28/Oct/2026:13:55:36 -0700] '
31
+ '"GET /apache_pb.gif HTTP/1.0" 200 2326 '
32
+ '"http://www.example.com/start.html" '
33
+ '"Mozilla/4.08 [en] (Win98; I ;Nav)"')
34
+ self.assertIsNotNone(entry)
35
+ self.assertEqual(entry["ip"], "192.0.2.1")
36
+ self.assertEqual(entry["method"], "GET")
37
+ self.assertEqual(entry["path"], "/apache_pb.gif")
38
+ self.assertEqual(entry["status"], 200)
39
+ self.assertEqual(entry["ts"].utcoffset().total_seconds(), -7 * 3600)
40
+
41
+ def test_common_line_without_referer_ua(self):
42
+ entry = parse_line(
43
+ '192.0.2.1 - - [28/Oct/2026:13:55:36 +0000] '
44
+ '"POST /submit.php?a=1 HTTP/1.1" 302 0')
45
+ self.assertIsNotNone(entry)
46
+ self.assertEqual(entry["method"], "POST")
47
+ self.assertEqual(entry["path"], "/submit.php")
48
+ self.assertEqual(entry["query"], "a=1")
49
+ self.assertEqual(entry["ua"], "")
50
+
51
+ def test_garbage_lines_rejected(self):
52
+ self.assertIsNone(parse_line("this is not a log line"))
53
+ self.assertIsNone(parse_line(""))
54
+ self.assertIsNone(parse_line(
55
+ '192.0.2.1 - - [99/Zzz/2026:13:55:36 +0000] '
56
+ '"GET / HTTP/1.1" 200 1'))
57
+
58
+ def test_timestamp_parsing(self):
59
+ ts = parse_timestamp("01/Jan/2026:00:00:01 +0530")
60
+ self.assertEqual((ts.year, ts.month, ts.day), (2026, 1, 1))
61
+ self.assertEqual(ts.utcoffset().total_seconds(), 5.5 * 3600)
62
+ self.assertIsNone(parse_timestamp("not a timestamp"))
63
+
64
+
65
+ class CleanFixtureTests(unittest.TestCase):
66
+ """The false-positive discipline gate: a normal busy WordPress
67
+ day (admin logins, plugin updates, cron, image uploads via
68
+ wp-admin, Jetpack xmlrpc) must produce ZERO findings."""
69
+
70
+ def test_clean_wordpress_log_has_zero_findings(self):
71
+ report = analyze_fixture("clean_wp.log")
72
+ self.assertEqual(report["findings"], [],
73
+ "clean fixture produced findings: %s"
74
+ % json.dumps(report["findings"], indent=1))
75
+ self.assertEqual(report["summary"]["total_findings"], 0)
76
+
77
+ def test_clean_fixture_all_lines_parsed(self):
78
+ report = analyze_fixture("clean_wp.log")
79
+ self.assertEqual(report["stats"]["entries_parsed"], 34)
80
+ self.assertEqual(report["stats"]["lines_skipped"], 0)
81
+
82
+
83
+ class ShellInteractionTests(unittest.TestCase):
84
+ @classmethod
85
+ def setUpClass(cls):
86
+ cls.report = analyze_fixture("shell_interaction.log")
87
+
88
+ def test_webshell_access_high_high(self):
89
+ hits = by_class(self.report, "webshell-access")
90
+ self.assertEqual(len(hits), 1)
91
+ self.assertEqual(hits[0]["severity"], "high")
92
+ self.assertEqual(hits[0]["confidence"], "high")
93
+ self.assertEqual(hits[0]["count"], 3)
94
+ self.assertTrue(hits[0]["evidence"])
95
+ self.assertIn("phpscan hunt", hits[0]["remediation"])
96
+
97
+ def test_probes_are_low(self):
98
+ probes = by_class(self.report, "webshell-probe")
99
+ self.assertEqual(len(probes), 5)
100
+ for probe in probes:
101
+ self.assertEqual(probe["severity"], "low")
102
+ self.assertEqual(probe["confidence"], "low")
103
+
104
+ def test_exec_in_upload_dir(self):
105
+ hits = by_class(self.report, "exec-in-upload-dir")
106
+ self.assertEqual(len(hits), 1)
107
+ self.assertEqual(hits[0]["severity"], "high")
108
+ self.assertEqual(hits[0]["confidence"], "high")
109
+
110
+ def test_post_to_static(self):
111
+ hits = by_class(self.report, "post-to-static")
112
+ self.assertEqual(len(hits), 1)
113
+ self.assertEqual(hits[0]["path"],
114
+ "/wp-content/uploads/2026/10/logo.jpg")
115
+
116
+ def test_unit_shell_access(self):
117
+ hits = by_class(self.report, "unit-shell-access")
118
+ self.assertEqual(len(hits), 1)
119
+ self.assertEqual(hits[0]["severity"], "high")
120
+ self.assertIn("CVE-2026-109618", hits[0]["remediation"])
121
+
122
+ def test_dropper_access_medium(self):
123
+ hits = by_class(self.report, "dropper-access")
124
+ self.assertEqual(len(hits), 1)
125
+ self.assertEqual(hits[0]["severity"], "medium")
126
+
127
+
128
+ class BruteForceTests(unittest.TestCase):
129
+ @classmethod
130
+ def setUpClass(cls):
131
+ cls.report = analyze_fixture("bruteforce.log")
132
+
133
+ def test_bursts_flagged(self):
134
+ bursts = by_class(self.report, "brute-force")
135
+ self.assertEqual(len(bursts), 2)
136
+ for burst in bursts:
137
+ self.assertEqual(burst["severity"], "medium")
138
+
139
+ def test_possible_success_flagged(self):
140
+ hits = by_class(self.report, "brute-force-success")
141
+ self.assertEqual(len(hits), 1)
142
+ self.assertEqual(hits[0]["ip"], "203.0.113.99")
143
+ self.assertEqual(hits[0]["severity"], "high")
144
+
145
+ def test_no_other_findings(self):
146
+ self.assertEqual(classes(self.report),
147
+ {"brute-force", "brute-force-success"})
148
+
149
+
150
+ class TraversalFixtureTests(unittest.TestCase):
151
+ """Attempts that all failed must stay LOW - someone knocking
152
+ is not someone inside."""
153
+
154
+ @classmethod
155
+ def setUpClass(cls):
156
+ cls.report = analyze_fixture("traversal_404.log")
157
+
158
+ def test_only_low_severity(self):
159
+ for finding in self.report["findings"]:
160
+ self.assertEqual(finding["severity"], "low", finding)
161
+
162
+ def test_expected_classes(self):
163
+ found = classes(self.report)
164
+ self.assertIn("exploit-probe", found)
165
+ self.assertIn("scanner-ua", found)
166
+ self.assertIn("webshell-probe", found)
167
+
168
+ def test_encoded_traversal_detected(self):
169
+ probes = by_class(self.report, "exploit-probe")
170
+ paths = {p["path"] for p in probes}
171
+ self.assertIn("/download.php", paths) # %2e%2e%2f encoded form
172
+ self.assertIn("/assets/app.js", paths) # long base64 token
173
+
174
+
175
+ class SinceFilterTests(unittest.TestCase):
176
+ def test_since_skips_earlier_entries(self):
177
+ lines = (
178
+ '192.0.2.1 - - [27/Oct/2026:10:00:00 +0000] '
179
+ '"GET /c99.php HTTP/1.1" 200 10 "-" "curl/8"\n'
180
+ '192.0.2.1 - - [28/Oct/2026:10:00:00 +0000] '
181
+ '"GET /r57.php HTTP/1.1" 200 10 "-" "curl/8"\n'
182
+ )
183
+ analyzer = Analyzer(since=date(2026, 10, 28))
184
+ analyzer.run(io.StringIO(lines))
185
+ report = analyzer.report("inline", "test")
186
+ self.assertEqual(report["stats"]["entries_before_since"], 1)
187
+ self.assertEqual(len(report["findings"]), 1)
188
+ self.assertEqual(report["findings"][0]["path"], "/r57.php")
189
+
190
+
191
+ class EvidenceTests(unittest.TestCase):
192
+ def test_evidence_truncated(self):
193
+ long_line = ('192.0.2.1 - - [28/Oct/2026:10:00:00 +0000] '
194
+ '"GET /c99.php?pad=%s HTTP/1.1" 200 10 "-" "x"'
195
+ % ("A" * 900))
196
+ analyzer = Analyzer()
197
+ analyzer.run(io.StringIO(long_line + "\n"))
198
+ report = analyzer.report("inline", "test")
199
+ evidence = report["findings"][0]["evidence"][0]
200
+ self.assertLessEqual(len(evidence), 320)
201
+ self.assertTrue(evidence.endswith("[truncated]"))
202
+
203
+
204
+ if __name__ == "__main__":
205
+ unittest.main()