Dear Doctor:
i had a problem in rule matching.
my rule is
alert http any any → any any (msg:“test”; flow:to_client; http.stat_code; content:“200”; sid:1111111;)
my suricata version 6.0.1 RELEASE
my suricata.yaml :
stream:
midstream: yes
memcap: 64mb
checksum-validation: no
inline: auto
reassembly:
memcap: 256mb
depth: 1mb
toserver-chunk-size: 1024
toclient-chunk-size: 1024
randomize-chunk-size: yes
my command:
suricata -r ./landray.pcap -v -c ./suricata.yaml
I could be wrong, but I don’t think there’s an issue with your rule. Rather, it seems to be something with that pcap. I have tried running your rule against that pcap and against live traffic, and I do get alerts from Suricata when it’s inspecting live traffic, but no alerts or even http event types show up in my logs when I run Suricata to inspect that provided pcap.
Unfortunately, my knowledge is limited, still, so I can’t explain why doesn’t that pcap generate alerts. I would just recommend you to test your rule against other pcap, or with live traffic. If you do, please share the resulting output log from eve.json or fast.log!
I tried looking at some of the http streams and I cannot see the SYN packets for most of them. Looks like the pcap has http coming over long running, reused, TCP sessions.
I would assume that midstream: yes would pick it up but seems like that is not the case.
Are you testing on live traffic or packet capture?
Is the traffic sent from some other TLS inspection box for instance that might mangle it a bit?
There are some streams with SYN packets (for instance tcp.stream eq 74 in wireshark), but the first packets in the stream do not look like http at all.
You might also need to change the http port variables since non-standard ones are in use in the pcap.
i tried live mode.
my command is ‘suricata -i eth0 -v -c /etc/suricata/suricata.yaml -k none -l ./log’
‘tcpreplay -i eth0 -M 100 landray.pcap’
my rule is
alert http any any → any any (msg:“test”; flow:to_client; http.stat_code; content:“200”; sid:1111111;)
but there is no alert. eve.json (24.5 KB)
It looks like Suricata isn’t identifying these packets as HTTP. In one flow that I looked at with an HTTP response, there is some data before the start of the HTTP request which could be causing this. Is there any not-normal about your configuration, or the traffic you are monitoring that you may be aware of?
It probably can’t be fixed, and we don’t know enough about the source of this pcap. As syoc mentioned, could it be from a TLS inspection box that re-generates non-TLS versions of the traffic?
So, I’m not an expert with lua scripts, but from what I could gather, it’s not the lua support that is not working.
I tried a similar version of your script with a local suricata verify test, and that worked. When I tried to use it with suri in live mode, it didn’t seem to work, so… I don’t know. I’m appending my script to the end of this answer.
The error suggests that Suricata doesn’t recognize the keyword type in your script’s specific context. It could be some small typo somewhere or a wrong symbol, or it can also be that the combination you’re using doesn’t work in the way you want to use it.
Right now, I’m unable to offer more help with this…
…
my script:
function init(args)
local needs = {}
needs["type"] = "packet"
needs["filter"] = "alerts"
return needs
end
function setup(args)
alert_count = 0
end
function log(args)
timestring = SCPacketTimeString()
sid, rev, gid = SCRuleIds()
msg = SCRuleMsg()
class, priority = SCRuleClass()
ip_version, src_ip, dst_ip, protocol, src_port, dst_port = SCPacketTuple()
if class == nil then
class = "unknown"
end
print (timestring .. " [**] [" .. gid .. ":" .. sid .. ":" .. rev .. "] " ..
msg .. " [**] [Classification: " .. class .. "] [Priority: " ..
priority .. "] {" .. protocol .. "} " ..
src_ip .. ":" .. src_port .. " -> " .. dst_ip .. ":" .. dst_port)
alert_count = alert_count + 1
end
function deinit(args)
print ("Alerted " .. alert_count .. " times");
end