mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-16 01:22:18 +03:00
Adds support to Python scripts on ModSecurity core.
Analog of what we have for Lua, Python support is now added by this commit. This is very experimental.
This commit is contained in:
21
tests/regression/nginx/conf/script.py
Executable file
21
tests/regression/nginx/conf/script.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from modsecurity import ModSecurity
|
||||
|
||||
class ModSecurityExtension(ModSecurity):
|
||||
def process(self):
|
||||
self.log(8, "Python test message.")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
myExtension = ModSecurityExtension()
|
||||
|
||||
# Process the content.
|
||||
ret = myExtension.process()
|
||||
|
||||
if ret == True:
|
||||
print("Matched!")
|
||||
else:
|
||||
print("_not_ matched")
|
||||
|
||||
24
tests/regression/rule/01-python-script.t
Normal file
24
tests/regression/rule/01-python-script.t
Normal file
@@ -0,0 +1,24 @@
|
||||
### Test for SecRuleScript
|
||||
|
||||
# Python
|
||||
{
|
||||
type => "rule",
|
||||
comment => "SecRuleScript (Python match)",
|
||||
conf => qq(
|
||||
SecRuleEngine On
|
||||
SecDebugLog $ENV{DEBUG_LOG}
|
||||
SecDebugLogLevel 9
|
||||
SecRuleScript "script.py" "phase:2,deny"
|
||||
),
|
||||
match_log => {
|
||||
-error => [ qr/Python script matched\./, 1 ],
|
||||
debug => [ qr/Python test message\./, 1 ],
|
||||
},
|
||||
match_response => {
|
||||
status => qr/^200$/,
|
||||
},
|
||||
request => new HTTP::Request(
|
||||
GET => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt?foo=bar&foo2=bar2",
|
||||
),
|
||||
}
|
||||
|
||||
21
tests/regression/server_root/conf/script.py
Executable file
21
tests/regression/server_root/conf/script.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from modsecurity import ModSecurity
|
||||
|
||||
class ModSecurityExtension(ModSecurity):
|
||||
def process(self):
|
||||
self.log(8, "Python test message.")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
myExtension = ModSecurityExtension()
|
||||
|
||||
# Process the content.
|
||||
ret = myExtension.process()
|
||||
|
||||
if ret == True:
|
||||
print("Matched!")
|
||||
else:
|
||||
print("_not_ matched")
|
||||
|
||||
Reference in New Issue
Block a user