Skip to content
Snippets Groups Projects
Commit 4ca1a6ef authored by Juan Diego Campo's avatar Juan Diego Campo
Browse files

Use JSON lib for json encoding

parent d237fd40
No related branches found
No related tags found
No related merge requests found
......@@ -35,57 +35,42 @@ end
function main()
local JSON = (loadfile "/etc/httpd/modsecurity.d/JSON.lua")()
local input = "{\n"
input = input.."\t\"unique_id\": \""..m.getvar("UNIQUE_ID").."\",\n"
input = input.."\t\"method\": \""..m.getvar("REQUEST_METHOD").."\",\n"
input = input.."\t\"protocol\": \""..m.getvar("REQUEST_PROTOCOL").."\",\n"
input = input.."\t\"uri\": \""..m.getvar("REQUEST_URI").."\",\n"
local data = {}
data["unique_id"] = m.getvar("UNIQUE_ID")
data["method"] = m.getvar("REQUEST_METHOD")
data["protocol"] = m.getvar("REQUEST_PROTOCOL")
data["uri"] = m.getvar("REQUEST_URI")
if m.getvar("REQUEST_BODY") then
input = input.."\t\"body\": \""..m.getvar("REQUEST_BODY").."\",\n"
data["body"] = m.getvar("REQUEST_BODY")
else
input = input.."\t\"body\": \"\",\n"
data["body"] = ""
end
input = input.."\t\"argsGet\": {\n"
data["argsGet"] = {}
local args_get = m.getvars("ARGS_GET")
for i = 1, #args_get do
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
data["argsGet"][split(args_get[i]["name"],":")[2]] = args_get[i]["value"]
end
input = input.."\t},\n"
input = input.."\t\"headers\": {\n"
data["headers"] = {}
local headers = m.getvars("REQUEST_HEADERS")
for i = 1, #headers do
input = input.."\t\t\""..split(headers[i]["name"],":")[2].."\": "
input = input.."\""..headers[i]["value"].."\""
if i < #headers then
input = input..",\n"
data["headers"][split(headers[i]["name"],":")[2]] = headers[i]["value"]
end
end
input = input.."\t},\n"
input = input.."\t\"argsPost\": {\n"
data["argsPost"] = {}
local args_post = m.getvars("ARGS_POST")
for i = 1, #args_post do
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
data["argsPost"][i] = { split(args_post[i]["name"],":")[2], args_post[i]["value"] }
end
input = input.."\t}\n"
input = input.."}\n"
-- As far as I can see, external program input can only be done
-- through a tmp file
local tmpfile = '/tmp/lua_pipe'
local f = io.open(tmpfile, 'w')
f:write(input)
f:write(JSON:encode(data))
f:close()
cmd = 'java -jar /etc/httpd/modsecurity.d/mlExample.jar <'..tmpfile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment