mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Initial support for Lua script engine
This commit is contained in:
@@ -45,6 +45,7 @@ unit_tests_LDADD = \
|
||||
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
|
||||
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
|
||||
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
|
||||
$(LUA_LDFLAGS) $(LUA_LDADD) \
|
||||
$(LIBXML2_LDADD) \
|
||||
$(GLOBAL_LDADD)
|
||||
|
||||
@@ -82,6 +83,7 @@ regression_tests_LDADD = \
|
||||
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
|
||||
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
|
||||
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
|
||||
$(LUA_LDFLAGS) $(LUA_LDADD) \
|
||||
$(LIBXML2_LDADD) \
|
||||
$(GLOBAL_LDADD)
|
||||
|
||||
@@ -118,6 +120,7 @@ rules_optimization_LDADD = \
|
||||
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
|
||||
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
|
||||
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
|
||||
$(LUA_LDFLAGS) $(LUA_LDADD) \
|
||||
$(LIBXML2_LDADD) \
|
||||
$(GLOBAL_LDADD)
|
||||
|
||||
|
20
test/test-cases/data/match-getvar-transformation.lua
Normal file
20
test/test-cases/data/match-getvar-transformation.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
function main()
|
||||
ret = nil
|
||||
|
||||
var = m.getvar("tx.test");
|
||||
if var == nil then
|
||||
m.log(9, "Don't know what to say...");
|
||||
return ret
|
||||
end
|
||||
|
||||
if var == "FELIPE"
|
||||
m.log(9, "Ops.");
|
||||
elseif var == "felipe"
|
||||
m.log(9, "Just fine.");
|
||||
ret ="ok";
|
||||
else
|
||||
m.log(9, "Really?");
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
19
test/test-cases/data/match-getvar.lua
Normal file
19
test/test-cases/data/match-getvar.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
function main()
|
||||
ret = nil
|
||||
|
||||
num = m.getvar("tx.test");
|
||||
if num == nil then
|
||||
m.log(9, "Don't know what to say about this so called number.");
|
||||
return ret
|
||||
end
|
||||
num = tonumber(num)
|
||||
|
||||
if num > 1 then
|
||||
m.log(9, "Number is bigger than one.");
|
||||
ret = "Whee :)"
|
||||
else
|
||||
m.log(9, "Really?");
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
21
test/test-cases/data/match-getvars.lua
Normal file
21
test/test-cases/data/match-getvars.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
function main()
|
||||
ret = nil
|
||||
m.log(9, "Here I am");
|
||||
z = m.getvars("QUERY_STRING");
|
||||
m.log(9, "Z: " .. dump(z))
|
||||
|
||||
return ret
|
||||
end
|
4
test/test-cases/data/match-log.lua
Normal file
4
test/test-cases/data/match-log.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
function main()
|
||||
m.log(9, "echo 123");
|
||||
return "Lua script matched.";
|
||||
end
|
5
test/test-cases/data/match-set.lua
Normal file
5
test/test-cases/data/match-set.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
function main()
|
||||
m.log(9, "echo 123");
|
||||
m.setvar("tx.test", "whee");
|
||||
return "Lua script matched.";
|
||||
end
|
3
test/test-cases/data/match.lua
Normal file
3
test/test-cases/data/match.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
function main()
|
||||
return "Lua script matched.";
|
||||
end
|
0
test/test-cases/data/test.lua
Normal file
0
test/test-cases/data/test.lua
Normal file
@@ -112,5 +112,198 @@
|
||||
"SecRuleEngine On",
|
||||
"SecRule ARGS:res \"@inspectFile /bin/echo\" \"id:1,phase:2,pass,t:trim\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (1/1)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
},
|
||||
"server":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":80
|
||||
},
|
||||
"request":{
|
||||
"headers":{
|
||||
"Host":"localhost",
|
||||
"User-Agent":"curl/7.38.0",
|
||||
"Accept":"*/*",
|
||||
"Content-Length": "27",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
"uri":"/whee?res=whee",
|
||||
"method":"GET",
|
||||
"body": [ ]
|
||||
},
|
||||
"response":{
|
||||
"headers":{},
|
||||
"body":[
|
||||
"no need."
|
||||
]
|
||||
},
|
||||
"expected":{
|
||||
"debug_log":"Rule returned 1."
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecRule ARGS:res \"@inspectFile test-cases/data/match.lua\" \"id:1,phase:2,pass,t:trim\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (2/2)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
},
|
||||
"server":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":80
|
||||
},
|
||||
"request":{
|
||||
"headers":{
|
||||
"Host":"localhost",
|
||||
"User-Agent":"curl/7.38.0",
|
||||
"Accept":"*/*",
|
||||
"Content-Length": "27",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
"uri":"/whee?res=whee",
|
||||
"method":"GET",
|
||||
"body": [ ]
|
||||
},
|
||||
"response":{
|
||||
"headers":{},
|
||||
"body":[
|
||||
"no need."
|
||||
]
|
||||
},
|
||||
"expected":{
|
||||
"debug_log":"echo 123"
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecRule ARGS:res \"@inspectFile test-cases/data/match-log.lua\" \"id:1,phase:2,pass,t:trim\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (3/3)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
},
|
||||
"server":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":80
|
||||
},
|
||||
"request":{
|
||||
"headers":{
|
||||
"Host":"localhost",
|
||||
"User-Agent":"curl/7.38.0",
|
||||
"Accept":"*/*",
|
||||
"Content-Length": "27",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
"uri":"/whee?res=whee",
|
||||
"method":"GET",
|
||||
"body": [ ]
|
||||
},
|
||||
"response":{
|
||||
"headers":{},
|
||||
"body":[
|
||||
"no need."
|
||||
]
|
||||
},
|
||||
"expected":{
|
||||
"debug_log":"Target value: \"whee\" "
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecRule ARGS:res \"@inspectFile test-cases/data/match-set.lua\" \"id:1,phase:2,pass,t:trim\"",
|
||||
"SecRule TX:test \"whee\" \"id:2,phase:2,pass,t:trim\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (4/4)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
},
|
||||
"server":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":80
|
||||
},
|
||||
"request":{
|
||||
"headers":{
|
||||
"Host":"localhost",
|
||||
"User-Agent":"curl/7.38.0",
|
||||
"Accept":"*/*",
|
||||
"Content-Length": "27",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
"uri":"/whee?res=whee",
|
||||
"method":"GET",
|
||||
"body": [ ]
|
||||
},
|
||||
"response":{
|
||||
"headers":{},
|
||||
"body":[
|
||||
"no need."
|
||||
]
|
||||
},
|
||||
"expected":{
|
||||
"debug_log":"Number is bigger than one."
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecRule ARGS \".\" \"id:2,phase:2,setvar:tx.test=2\"",
|
||||
"SecRule ARGS:res \"@inspectFile test-cases/data/match-getvar.lua\" \"id:1,phase:2,pass,t:trim\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (5/5)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
},
|
||||
"server":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":80
|
||||
},
|
||||
"request":{
|
||||
"headers":{
|
||||
"Host":"localhost",
|
||||
"User-Agent":"curl/7.38.0",
|
||||
"Accept":"*/*",
|
||||
"Content-Length": "27",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
"uri":"/whee?res=whee&z=z&d=e",
|
||||
"method":"GET",
|
||||
"body": [ ]
|
||||
},
|
||||
"response":{
|
||||
"headers":{},
|
||||
"body":[
|
||||
"no need."
|
||||
]
|
||||
},
|
||||
"expected":{
|
||||
"debug_log":"Z: \\{ \\[1\\] = \\{ \\[\"value\"\\] = res=whee&z=z&d=e,\\[\"name\"\\] = QUERY_STRING,\\} ,\\}"
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecRule QUERY_STRING \".\" \"id:2,phase:2,setvar:tx.test=2\"",
|
||||
"SecRule ARGS:res \"@inspectFile test-cases/data/match-getvars.lua\" \"id:1,phase:2,pass,t:trim\""
|
||||
]
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user