IntelOwl icon indicating copy to clipboard operation
IntelOwl copied to clipboard

Bug: Memory Amplification in PCAP Suricata Result Processing

Open gks281263 opened this issue 10 months ago • 1 comments

Bug: Memory Amplification in PCAP Suricata Result Processing

Labels

bug, backend_simple

Location

integrations/pcap_analyzers/app.py::intercept_suricata_result (line 63)

Description

A single malformed JSON line in eve.json causes the entire remainder of the file to be read into memory, leading to potential memory exhaustion and DoS.

Code

def intercept_suricata_result(context, future: Future) -> None:
    # ...
    res["report"] = {"data": []}
    with open(f"{directory}/eve.json", "r", encoding="utf_8") as fp:
        for line in fp:
            try:
                res["report"]["data"].append(json.loads(line))
            except json.JSONDecodeError as e:
                logger.debug(e)
                res["report"]["data"].append(fp.read())  # ❌ BUG: Reads entire remainder of file

Trigger

When parsing eve.json line-by-line (JSONL format), if any line fails to parse as JSON, the exception handler executes fp.read() which reads the entire remainder of the file into memory.

Observed Behavior

  1. First malformed JSON line encountered
  2. json.JSONDecodeError raised
  3. Exception handler calls fp.read()
  4. Entire remainder of file (potentially gigabytes) loaded into memory
  5. Process may crash or consume excessive memory
  6. Single malformed line can cause DoS via memory exhaustion

Expected Behavior

Skip the malformed line and continue processing subsequent valid lines. Log a warning for visibility.

Impact

  • Memory exhaustion: Large/corrupted files cause process crashes
  • DoS risk: Maliciously crafted input can exhaust system memory
  • Resource amplification: Small input (single bad line) causes unbounded memory consumption

Security Implications

This is an input-triggered resource amplification vulnerability. An attacker could:

  • Craft a PCAP file that generates a large eve.json
  • Insert a single malformed JSON line early in the file
  • Cause the entire large file to be read into memory
  • Potentially crash the service or exhaust available memory

Proposed Fix

Replace the exception handler to skip malformed lines instead of reading the remainder:

except json.JSONDecodeError as e:
    logger.warning(f"Skipping malformed JSON line in eve.json: {e}")
    # Continue to next line - implicit skip

Complexity: < 5 LOC change

Why This Should Be Fixed

  • ✅ Concrete bug: Unambiguous incorrect behavior
  • ✅ Clear trigger: Single malformed JSON line
  • ✅ Obvious bad behavior: Reading entire file on error
  • ✅ Security-adjacent: DoS via memory exhaustion
  • ✅ Trivial fix: Simple line skip with logging
  • ✅ No opinion involved: Objectively wrong code

Additional Context

The eve.json file is in JSONL format (one JSON object per line). Each line should be parsed independently. There is no reason to read the remainder of the file when a single line fails to parse.

gks281263 avatar Jan 16 '26 12:01 gks281263

thanks, feel free to open a PR

mlodic avatar Jan 16 '26 14:01 mlodic