Skip to content
Snippets Groups Projects
Commit d237fd40 authored by root's avatar root
Browse files

Fixes to ARGS and HEADERS

parent b73631ca
Branches
No related tags found
No related merge requests found
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 split(str, pat)
local t = {}
local fpat = "(.-)" .. pat
......@@ -18,7 +33,7 @@ function split(str, pat)
end
function main()
local JSON = (loadfile "JSON.lua")()
local JSON = (loadfile "/etc/httpd/modsecurity.d/JSON.lua")()
local input = "{\n"
input = input.."\t\"unique_id\": \""..m.getvar("UNIQUE_ID").."\",\n"
......@@ -31,16 +46,11 @@ function main()
input = input.."\t\"body\": \"\",\n"
end
-- FIXME: These var don't work: ARGS_GET, ARGS_POST, REQUEST_HEADERS
input = input.."\t\"argsGet\": {\n"
-- local args_get = m.getvars("ARGS_GET")
local args_get = split(m.getvar("REQUEST_URI"),"?")
args_get = split(args_get[#args_get],"&")
local args_get = m.getvars("ARGS_GET")
for i = 1, #args_get do
arg = split(args_get[i],"=")
input = input.."\t\t\""..arg[1].."\": "
input = input.."\""..arg[2].."\""
input = input.."\t\t\""..split(args_get[i]["name"],":")[2].."\": "
input = input.."\""..args_get[i]["value"].."\""
if i < #args_get then
input = input..",\n"
end
......@@ -48,13 +58,10 @@ function main()
input = input.."\t},\n"
input = input.."\t\"headers\": {\n"
-- local headers = m.getvars("REQUEST_HEADERS")
local headers = split(m.getvar("FULL_REQUEST"),"\n\n")[1]
headers = split(headers,"\n")
local headers = m.getvars("REQUEST_HEADERS")
for i = 1, #headers do
header = split(headers[i],": ")
input = input.."\t\t\""..header[1].."\": "
input = input.."\""..header[2].."\""
input = input.."\t\t\""..split(headers[i]["name"],":")[2].."\": "
input = input.."\""..headers[i]["value"].."\""
if i < #headers then
input = input..",\n"
end
......@@ -62,11 +69,10 @@ function main()
input = input.."\t},\n"
input = input.."\t\"argsPost\": {\n"
-- local args_post = m.getvars("ARGS_POST")
local args_post = {}
local args_post = m.getvars("ARGS_POST")
for i = 1, #args_post do
input = input.."\t\t\""..args_post[i].name.."\": "
input = input.."\""..args_post[i].value.."\""
input = input.."\t\t\""..split(args_post[i]["name"],":")[2].."\": "
input = input.."\""..args_post[i]["value"].."\""
if i < #args_post then
input = input..",\n"
end
......@@ -75,8 +81,6 @@ function main()
input = input.."}\n"
-- m.log(3, "ML - input: \n"..input)
-- As far as I can see, external program input can only be done
-- through a tmp file
local tmpfile = '/tmp/lua_pipe'
......@@ -84,15 +88,17 @@ function main()
f:write(input)
f:close()
cmd = 'java -jar /home/jdcampo/gsi/modsec/modsec-ml/mlExample.jar <'..tmpfile
cmd = 'java -jar /etc/httpd/modsecurity.d/mlExample.jar <'..tmpfile
local p = io.popen(cmd, 'r')
local output = ""
for line in p:lines() do
output = output..line.."\n"
end
-- os.remove(tmpfile)
os.remove(tmpfile)
print(output)
if (output == "") then
return "Error executing ML jar"
end
local result = JSON:decode(output)
m.log(3, "ML - res:\n")
......@@ -101,7 +107,5 @@ function main()
end
p:close()
m.setvar("tx.pepe","pepe")
return "ERROR"
return nil
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment