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
4ca1a6ef
Commit
4ca1a6ef
authored
7 years ago
by
Juan Diego Campo
Browse files
Options
Downloads
Patches
Plain Diff
Use JSON lib for json encoding
parent
d237fd40
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ml.lua
+17
-32
17 additions, 32 deletions
ml.lua
with
17 additions
and
32 deletions
ml.lua
+
17
−
32
View file @
4ca1a6ef
...
...
@@ -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
...
...
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