Project

General

Profile

Actions

Bug #9486

open
JL

file.data rule with filesize or a file hash misses large files

Bug #9486: file.data rule with filesize or a file hash misses large files

Added by Jeff Lucovsky about 22 hours ago. Updated about 6 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

A rule whose fast pattern is in file.data and that also uses filesize or a file hash keyword does not alert on an HTTP file larger than about 40 KiB, the default response-body-minimal-inspect-size. For example:

alert http any any -> any any (msg:"PE download over 1000 bytes"; flow:established,to_client; file.data; content:"MZ"; startswith; filesize:>1000; sid:1;)
alert http any any -> any any (msg:"known PE"; flow:established,to_client; file.data; content:"MZ"; startswith; filesha256:known.list; sid:2;)

With the default suricata.yaml, on a capture of 300 PE downloads between 24 KB and 100 KB, main alerts only on files smaller than 44,870 bytes: in 20 runs it alerted on 6 to 10 of the 10 such files, varying from run to run, and missed all 290 files of 44,870 bytes or more. Both rules miss a single 66,560-byte download. With the body limit and stream depth set to 0, sid 1 also misses the HTTP downloads of mimikatz (1,084,416 bytes) and of the 7-Zip installer (1,447,178 bytes). The second file of a multipart HTTP upload is missed the same way.

The fast pattern matches only in the first inspected part of the file. While the file is open, filesize and the hash keywords cannot decide, and DetectFileInspect returns NO_MATCH (src/detect-engine-file.c:111-121). DetectRunTxInspectRule then does not keep the rule's state, expecting the fast pattern to bring the rule back (src/detect.c:1588-1591). It does not: later parts of the file do not match the pattern again, so the rule is never inspected once the file closes.

Proposed fix: while a file the rule waits for is still open, keep the rule in the transaction's detection state so it is inspected again on later packets. Keeping these rules makes the per-packet sort of the stored state costly on large transfers, so a second change merges the stored state into the candidate list without sorting.

Affected: main. 8.0.8 and main-8.0.x behave the same; the fix is planned for main only.

JL Updated by Jeff Lucovsky about 6 hours ago Actions #1

  • Description updated (diff)
Actions

Also available in: PDF Atom