Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
modsec-ml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GSI
modsec-ml
Commits
d237fd40
Commit
d237fd40
authored
7 years ago
by
root
Browse files
Options
Downloads
Patches
Plain Diff
Fixes to ARGS and HEADERS
parent
b73631ca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ml.lua
+34
-30
34 additions, 30 deletions
ml.lua
with
34 additions
and
30 deletions
ml.lua
+
34
−
30
View file @
d237fd40
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment