-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
detect-lua: add tests #1086
detect-lua: add tests #1086
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test http buffer | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
%YAML 1.1 | ||
--- | ||
|
||
outputs: | ||
- eve-log: | ||
enabled: yes | ||
filetype: regular | ||
filename: eve.json | ||
types: | ||
- alert | ||
- flow | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For completeness, I think it's good to add |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
alert http any any -> any any (flow:to_server; lua:test1.lua; sid:1;) | ||
alert tcp any any -> any any (flow:to_server; lua:test2.lua; sid:2;) | ||
alert tcp any any -> any any (flow:to_server; lua:test3.lua; sid:3;) | ||
alert http any any -> any any (flow:to_server; lua:test4.lua; sid:4;) | ||
alert http any any -> any any (flow:to_server; lua:test4.lua; sid:5;) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that this rule is using |
||
alert http any any -> any any (flow:to_server; lua:test6.lua; sid:6;) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
requires: | ||
features: | ||
- HAVE_LUA | ||
|
||
args: | ||
- -k none | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove space in the beginning of the line. |
||
|
||
checks: | ||
- filter: | ||
count: 0 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 1 | ||
- filter: | ||
count: 0 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 2 | ||
- filter: | ||
count: 2 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 3 | ||
- filter: | ||
count: 0 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 4 | ||
- filter: | ||
count: 0 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 5 | ||
- filter: | ||
count: 0 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 6 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function init (args) | ||
local needs = {} | ||
needs["http.request_headers"] = tostring(true) | ||
needs["flowvar"] = {"cnt"} | ||
return needs | ||
end | ||
|
||
function match(args) | ||
a = ScFlowvarGet(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noticed that in the unittests the |
||
if a then | ||
a = tostring(tonumber(a)+1) | ||
print (a) | ||
ScFlowvarSet(0, a, #a) | ||
else | ||
a = tostring(1) | ||
print (a) | ||
ScFlowvarSet(0, a, #a) | ||
end | ||
|
||
print ("pre check: " .. (a)) | ||
if tonumber(a) == 2 then | ||
print "match" | ||
return 1 | ||
end | ||
return 0 | ||
end | ||
return 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function init (args) | ||
local needs = {} | ||
needs["payload"] = tostring(true) | ||
needs["flowvar"] = {"cnt"} | ||
return needs | ||
end | ||
|
||
function match(args) | ||
a = ScFlowvarGet(0) | ||
if a then | ||
a = tostring(tonumber(a)+1) | ||
print (a) | ||
ScFlowvarSet(0, a, #a) | ||
else | ||
a = tostring(1) | ||
print (a) | ||
ScFlowvarSet(0, a, #a) | ||
end | ||
|
||
print ("pre check: " .. (a)) | ||
if tonumber(a) == 2 then | ||
print "match" | ||
return 1 | ||
end | ||
return 0 | ||
end | ||
return 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function init (args) | ||
local needs = {} | ||
needs["packet"] = tostring(true) | ||
needs["flowvar"] = {"cnt"} | ||
return needs | ||
end | ||
|
||
function match(args) | ||
a = ScFlowvarGet(0) | ||
if a then | ||
a = tostring(tonumber(a)+1) | ||
print (a) | ||
ScFlowvarSet(0, a, #a) | ||
else | ||
a = tostring(1) | ||
print (a) | ||
ScFlowvarSet(0, a, #a) | ||
end | ||
|
||
print ("pre check: " .. (a)) | ||
if tonumber(a) == 2 then | ||
print "match" | ||
return 1 | ||
end | ||
return 0 | ||
end | ||
return 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function init (args) | ||
local needs = {} | ||
needs["http.request_headers"] = tostring(true) | ||
needs["flowint"] = {"cnt"} | ||
return needs | ||
end | ||
|
||
function match(args) | ||
print "inspecting" | ||
a = ScFlowintGet(0) | ||
if a then | ||
ScFlowintSet(0, a + 1) | ||
else | ||
ScFlowintSet(0, 1) | ||
end | ||
|
||
a = ScFlowintGet(0) | ||
if a == 2 then | ||
print "match" | ||
return 1 | ||
end | ||
return 0 | ||
end | ||
return 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function init (args) | ||
local needs = {} | ||
needs["http.request_headers"] = tostring(true) | ||
needs["flowint"] = {"cnt"} | ||
return needs | ||
end | ||
|
||
function match(args) | ||
print "inspecting" | ||
a = ScFlowintIncr(0) | ||
if a == 2 then | ||
print "match" | ||
return 1 | ||
end | ||
return 0 | ||
end | ||
return 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function init (args) | ||
local needs = {} | ||
needs["http.request_headers"] = tostring(true) | ||
needs["flowint"] = {"cnt"} | ||
return needs | ||
end | ||
|
||
function match(args) | ||
print "inspecting" | ||
a = ScFlowintGet(0) | ||
if a == nil then | ||
print "new var set to 2" | ||
ScFlowintSet(0, 2) | ||
end | ||
a = ScFlowintDecr(0) | ||
if a == 0 then | ||
print "match" | ||
return 1 | ||
end | ||
return 0 | ||
end | ||
return 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python | ||
from scapy.all import * | ||
|
||
pkts = [] | ||
|
||
pkts += Ether(dst='ff:ff:ff:ff:ff:ff', src='00:01:02:03:04:05')/ \ | ||
Dot1Q(vlan=6)/ \ | ||
IP(dst='192.168.1.1', src='192.168.1.5')/TCP(sport=53, dport=80, flags='P''A')/"POST / HTTP/1.1\r\nHost: www.emergingthreats.net\r\n\r\n" | ||
pkts += Ether(dst='ff:ff:ff:ff:ff:ff', src='00:01:02:03:04:05')/ \ | ||
Dot1Q(vlan=6)/ \ | ||
IP(dst='192.168.1.1', src='192.168.1.5')/TCP(sport=80, dport=53, flags='P''A')/"POST / HTTP/1.1\r\nHost: www.openinfosecfoundation.org\r\n\r\n" | ||
Comment on lines
+6
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the unittests, we have two requests to the server, while here we see packets to different directions. |
||
|
||
wrpcap('input.pcap', pkts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see more details here, like listing the different buffers that are mentioned to be tested by the unittests, and which scripts are covering what.