DEV Community

Rocky
Rocky

Posted on

The Log Parser That Passed Every Test And Still Missed The Attack

A SOC analyst gets pulled into a post-incident review for something that should have triggered days earlier: a repeated failed-login pattern against a service account, exactly the kind their detection rule is built to catch. The rule didn't fire. Not because the logic was wrong, because the events it needed were never in the parsed data to begin with. Somewhere between the vendor's log format and the alert, a batch of entries just disappeared, and nobody noticed because the pipeline kept reporting success the whole time.

The parser had been running fine for months. It read each log line, split it on commas, and pulled fields by position: line.split(",")[3] for the source IP, [7] for the outcome. That works exactly as long as the vendor's format never changes, and eventually it did: an update added one new field near the front of the line, and every position after it shifted by one. The IP field started returning a timestamp. The outcome field started returning something that was never a valid value, so a broad except: pass around the parse step caught it, moved on, and left no trace that anything had gone wrong.

Fixed-position parsing is the actual root cause here, not the vendor's update, because any format change breaks it silently, where a parser built around field names doesn't care what order they arrive in. JSON logs should be parsed as JSON, not string-split. Delimited logs without a schema should go through named capture groups, not index positions, so a shifted field produces a clear mismatch instead of a plausible-looking wrong value. And the except block matters as much as the parsing itself: catching narrowly and counting failures turns a silent data loss into a visible metric, and a parse-failure rate that spikes above baseline is a detection signal worth alerting on in its own right, not a nuisance to suppress with a broader catch.

None of this is exotic. It's the difference between a script that looks like it's working and one that's actually still parsing what it thinks it's parsing six months and one vendor update later. Python for Cybersecurity Automation Book: SOC Tools works through building that kind of production-grade log parser and threat-intel pipeline properly the first time, not after a review turns up a gap nobody meant to leave: https://resources.codelivly.com/product/python-for-cybersecurity-automation/

Top comments (0)