Project

General

Profile

Bug #9486

Updated by Jeff Lucovsky about 6 hours ago

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: 

 <pre> 
 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;) 
 </pre> 

 With the default suricata.yaml, on a capture of 300 PE downloads between 24 KB and 100 KB, main alerts only on the 6 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, 36,621 bytes or less and missed all 290 files misses every file of 44,870 39,683 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. 

 

Back