-
Notifications
You must be signed in to change notification settings - Fork 90
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
tests/luaxform: Lua transform tests #2090
Open
jlucovsky
wants to merge
2
commits into
OISF:master
Choose a base branch
from
jlucovsky:2290/2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lua transform test: returns input buffer in uppercase. The rule will match on the uppercase output |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:transform.lua;content:"EXEC_POST.PHP"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
|
||
checks: | ||
- filter: | ||
count: 1 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 1 | ||
http.url: /exec_post.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- Arguments supported | ||
local bytes_key = "bytes" | ||
local offset_key = "offset" | ||
function transform(input_len, input, argc, args) | ||
local bytes = input_len | ||
local offset = 0 | ||
|
||
local sub = string.sub(input, offset + 1, offset + bytes) | ||
return string.upper(sub), bytes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lua transform: Ensure non-existent lua scripts are detected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:no_filetransform.lua;content:"EXEC_POST.PHP"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
- --set logging.outputs.1.file.type=json | ||
- -T | ||
|
||
exit-code: 1 | ||
|
||
pcap: false | ||
checks: | ||
- filter: | ||
count: 1 | ||
filename: suricata.log | ||
match: | ||
event_type: engine | ||
engine.message.__startswith: "couldn't load file" | ||
engine.message.__find: "no_filetransform.lua: No such file or directory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lua transform test: ensure lua script has a transform function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:transform.lua;content:"EXEC_POST.PHP"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
- --set logging.outputs.1.file.type=json | ||
- -T | ||
|
||
pcap: false | ||
|
||
exit-code: 1 | ||
|
||
checks: | ||
- filter: | ||
count: 1 | ||
filename: suricata.log | ||
match: | ||
engine.message.__find: "no transform function in script" | ||
event_type: engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- Arguments supported | ||
local bytes_key = "bytes" | ||
local offset_key = "offset" | ||
function no_transform(input_len, input, argc, args) | ||
local bytes = input_len | ||
local offset = 0 | ||
|
||
local sub = string.sub(input, offset + 1, offset + bytes) | ||
return string.upper(sub), bytes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ensure Lua transform receives optional transform function arguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:transform.lua, bytes 0, offset 2;content:"EXEC_POST.PHP"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
|
||
pcap: ../lua-transform-01/test.pcap | ||
|
||
checks: | ||
|
||
- shell: | ||
args: grep "1 item.* bytes 0" stdout | wc -l | xargs | ||
expect: 1 | ||
|
||
- shell: | ||
args: grep "2 item.* offset 2" stdout| wc -l | xargs | ||
expect: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- Arguments supported | ||
local bytes_key = "bytes" | ||
local offset_key = "offset" | ||
function transform(input_len, input, argc, args) | ||
offset = 0 | ||
bytes = input_len | ||
for i, item in ipairs(args) do | ||
print(i .. " item: " .. item) | ||
end | ||
|
||
local sub = string.sub(input, offset + 1, offset + bytes) | ||
return string.upper(sub), bytes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ensure Lua transform that returns nil is treated as though no transformation took place and the buffer is unchanged. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:transform.lua, bytes 0, offset 2;content:"exec_post.php"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
|
||
pcap: ../lua-transform-01/test.pcap | ||
|
||
checks: | ||
|
||
- filter: | ||
count: 1 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 1 | ||
http.url: /exec_post.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function transform(input_len, input, argc, args) | ||
return nil, 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lua transform test: transform function returns 1 parameter when 2 are required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:transform.lua;content:"EXEC_POST.PHP"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
|
||
pcap: ../lua-transform-01/test.pcap | ||
|
||
checks: | ||
- filter: | ||
count: 0 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 1 | ||
http.url: /exec_post.php | ||
Comment on lines
+10
to
+16
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. won't there be a warning or error here that we could also check for? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- Arguments supported | ||
local bytes_key = "bytes" | ||
local offset_key = "offset" | ||
function transform(input_len, input, argc, args) | ||
local bytes = input_len | ||
local offset = 0 | ||
|
||
local sub = string.sub(input, offset + 1, offset + bytes) | ||
-- Note -- only one value is returned when 2 are expected: buffer, byte-count | ||
return string.upper(sub) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Ensure Lua transform receives optional transform function arguments. The Lua transform script | ||
is also provided as an example in the documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert http any any -> any any (msg:"TEST"; http.uri; luaxform:transform.lua, bytes 12, offset 2;content:"XEC_POST.PHP"; sid:1; rev:1;) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
args: | ||
- --set default-rule-path=${TEST_DIR} | ||
- --set security.lua.allow-rules=true | ||
|
||
pcap: ../lua-transform-01/test.pcap | ||
|
||
checks: | ||
|
||
- filter: | ||
count: 1 | ||
match: | ||
event_type: alert | ||
alert.signature_id: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function init() | ||
end | ||
|
||
local function get_value(item, key) | ||
if string.find(item, key) then | ||
local _, value = string.match(item, "(%a+)%s*(%d*)") | ||
if value ~= "" then | ||
return tonumber(value) | ||
end | ||
end | ||
|
||
return nil | ||
end | ||
|
||
-- Arguments supported | ||
local bytes_key = "bytes" | ||
local offset_key = "offset" | ||
function transform(input_len, input, argc, args) | ||
local bytes = input_len | ||
local offset = 0 | ||
|
||
-- Look for optional bytes and offset arguments | ||
for i, item in ipairs(args) do | ||
local value = get_value(item, bytes_key) | ||
if value ~= nil then | ||
bytes = value | ||
else | ||
value = get_value(item, offset_key) | ||
if value ~= nil then | ||
offset = value | ||
end | ||
end | ||
end | ||
|
||
local str_len = #input | ||
if offset < 0 or offset > str_len then | ||
print("offset is out of bounds: " .. offset) | ||
return nil | ||
end | ||
|
||
local avail_len = str_len - offset | ||
if bytes < 0 or bytes > avail_len then | ||
print("invalid bytes " .. bytes .. " or bytes exceeds available length " .. avail_len) | ||
return nil | ||
end | ||
|
||
local sub = string.sub(input, offset + 1, offset + bytes) | ||
return string.upper(sub), bytes | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe nit, but why not have a check for the alert, here, too?