mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds support to the variable ARGS_NAMES
This commit is contained in:
parent
92c132b64c
commit
bc0553e726
@ -173,6 +173,7 @@ class Assay {
|
|||||||
const char *m_protocol;
|
const char *m_protocol;
|
||||||
const char *m_httpVersion;
|
const char *m_httpVersion;
|
||||||
|
|
||||||
|
std::string *m_namesArgs;
|
||||||
std::string m_namesResponse;
|
std::string m_namesResponse;
|
||||||
std::string m_namesRequest;
|
std::string m_namesRequest;
|
||||||
double m_ARGScombinedSize;
|
double m_ARGScombinedSize;
|
||||||
|
17
src/assay.cc
17
src/assay.cc
@ -92,6 +92,7 @@ Assay::Assay(ModSecurity *ms, Rules *rules)
|
|||||||
httpCodeReturned(200),
|
httpCodeReturned(200),
|
||||||
m_ARGScombinedSize(0),
|
m_ARGScombinedSize(0),
|
||||||
m_ARGScombinedSizeStr(NULL),
|
m_ARGScombinedSizeStr(NULL),
|
||||||
|
m_namesArgs(NULL),
|
||||||
m_ms(ms) {
|
m_ms(ms) {
|
||||||
id = std::to_string(this->timeStamp) + \
|
id = std::to_string(this->timeStamp) + \
|
||||||
std::to_string(generate_assay_unique_id());
|
std::to_string(generate_assay_unique_id());
|
||||||
@ -99,6 +100,8 @@ Assay::Assay(ModSecurity *ms, Rules *rules)
|
|||||||
|
|
||||||
store_variable("ARGS_COMBINED_SIZE", std::string("0"));
|
store_variable("ARGS_COMBINED_SIZE", std::string("0"));
|
||||||
this->m_ARGScombinedSizeStr = resolve_variable_first("ARGS_COMBINED_SIZE");
|
this->m_ARGScombinedSizeStr = resolve_variable_first("ARGS_COMBINED_SIZE");
|
||||||
|
store_variable("ARGS_NAMES", std::string(""));
|
||||||
|
this->m_namesArgs = resolve_variable_first("ARGS_NAMES");
|
||||||
|
|
||||||
this->debug(4, "Initialising transaction");
|
this->debug(4, "Initialising transaction");
|
||||||
}
|
}
|
||||||
@ -219,6 +222,13 @@ int Assay::processURI(const char *uri, const char *protocol,
|
|||||||
std::vector<std::string> key_value = split(t, sep2);
|
std::vector<std::string> key_value = split(t, sep2);
|
||||||
store_variable("ARGS:" + key_value[0], key_value[1]);
|
store_variable("ARGS:" + key_value[0], key_value[1]);
|
||||||
store_variable("ARGS_GET:" + key_value[0], key_value[1]);
|
store_variable("ARGS_GET:" + key_value[0], key_value[1]);
|
||||||
|
|
||||||
|
if (m_namesArgs->empty()) {
|
||||||
|
m_namesArgs->assign(key_value[0]);
|
||||||
|
} else {
|
||||||
|
m_namesArgs->assign(*m_namesArgs + " " + key_value[0]);
|
||||||
|
}
|
||||||
|
|
||||||
this->m_ARGScombinedSize = this->m_ARGScombinedSize + \
|
this->m_ARGScombinedSize = this->m_ARGScombinedSize + \
|
||||||
key_value[0].length() + key_value[1].length();
|
key_value[0].length() + key_value[1].length();
|
||||||
this->m_ARGScombinedSizeStr->assign(
|
this->m_ARGScombinedSizeStr->assign(
|
||||||
@ -392,6 +402,13 @@ int Assay::processRequestBody() {
|
|||||||
std::vector<std::string> key_value = split(t, sep2);
|
std::vector<std::string> key_value = split(t, sep2);
|
||||||
store_variable("ARGS:" + key_value[0], key_value[1]);
|
store_variable("ARGS:" + key_value[0], key_value[1]);
|
||||||
store_variable("ARGS_POST:" + key_value[0], key_value[1]);
|
store_variable("ARGS_POST:" + key_value[0], key_value[1]);
|
||||||
|
|
||||||
|
if (m_namesArgs->empty()) {
|
||||||
|
m_namesArgs->assign(key_value[0]);
|
||||||
|
} else {
|
||||||
|
m_namesArgs->assign(*m_namesArgs + " " + key_value[0]);
|
||||||
|
}
|
||||||
|
|
||||||
this->m_ARGScombinedSize = this->m_ARGScombinedSize + \
|
this->m_ARGScombinedSize = this->m_ARGScombinedSize + \
|
||||||
key_value[0].length() + key_value[1].length();
|
key_value[0].length() + key_value[1].length();
|
||||||
this->m_ARGScombinedSizeStr->assign(
|
this->m_ARGScombinedSizeStr->assign(
|
||||||
|
177
test/test-cases/regression/variable-ARGS_NAMES.json
Normal file
177
test/test-cases/regression/variable-ARGS_NAMES.json
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"enabled":1,
|
||||||
|
"version_min":300000,
|
||||||
|
"title":"Testing Variables :: ARGS_NAMES - GET (1/4)",
|
||||||
|
"client":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":123
|
||||||
|
},
|
||||||
|
"server":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":80
|
||||||
|
},
|
||||||
|
"request":{
|
||||||
|
"headers":{
|
||||||
|
"Host":"localhost",
|
||||||
|
"User-Agent":"curl/7.38.0",
|
||||||
|
"Accept":"*/*"
|
||||||
|
},
|
||||||
|
"uri":"/?key=value&key=other_value",
|
||||||
|
"protocol":"GET"
|
||||||
|
},
|
||||||
|
"response":{
|
||||||
|
"headers":{
|
||||||
|
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
|
||||||
|
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
|
||||||
|
"Content-Type":"text/html"
|
||||||
|
},
|
||||||
|
"body":[
|
||||||
|
"no need."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"expected":{
|
||||||
|
"debug_log":"Target value: \"key key\""
|
||||||
|
},
|
||||||
|
"rules":[
|
||||||
|
"SecRuleEngine On",
|
||||||
|
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||||
|
"SecDebugLogLevel 9",
|
||||||
|
"SecRule ARGS_NAMES \"@contains test \" \"pass,t:trim\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enabled":1,
|
||||||
|
"version_min":300000,
|
||||||
|
"title":"Testing Variables :: ARGS_NAMES - GET (2/4)",
|
||||||
|
"client":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":123
|
||||||
|
},
|
||||||
|
"server":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":80
|
||||||
|
},
|
||||||
|
"request":{
|
||||||
|
"headers":{
|
||||||
|
"Host":"localhost",
|
||||||
|
"User-Agent":"curl/7.38.0",
|
||||||
|
"Accept":"*/*"
|
||||||
|
},
|
||||||
|
"uri":"/?key=value&key=other_value",
|
||||||
|
"protocol":"GET"
|
||||||
|
},
|
||||||
|
"response":{
|
||||||
|
"headers":{
|
||||||
|
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
|
||||||
|
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
|
||||||
|
"Content-Type":"text/html"
|
||||||
|
},
|
||||||
|
"body":[
|
||||||
|
"no need."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"expected":{
|
||||||
|
"debug_log":"Target value: \"key key\""
|
||||||
|
},
|
||||||
|
"rules":[
|
||||||
|
"SecRuleEngine On",
|
||||||
|
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||||
|
"SecDebugLogLevel 9",
|
||||||
|
"SecRule ARGS_NAMES \"@contains test \" \"pass,t:trim\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enabled":1,
|
||||||
|
"version_min":300000,
|
||||||
|
"title":"Testing Variables :: ARGS_NAMES - POST (3/4)",
|
||||||
|
"client":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":123
|
||||||
|
},
|
||||||
|
"server":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":80
|
||||||
|
},
|
||||||
|
"request":{
|
||||||
|
"headers":{
|
||||||
|
"Host":"localhost",
|
||||||
|
"User-Agent":"curl/7.38.0",
|
||||||
|
"Accept":"*/*",
|
||||||
|
"Content-Length": "27",
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
"uri":"/",
|
||||||
|
"protocol":"POST",
|
||||||
|
"body": [
|
||||||
|
"param1=value1¶m2=value2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"response":{
|
||||||
|
"headers":{
|
||||||
|
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
|
||||||
|
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
|
||||||
|
"Content-Type":"text/html"
|
||||||
|
},
|
||||||
|
"body":[
|
||||||
|
"no need."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"expected":{
|
||||||
|
"debug_log":"Target value: \"param1 param2\""
|
||||||
|
},
|
||||||
|
"rules":[
|
||||||
|
"SecRuleEngine On",
|
||||||
|
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||||
|
"SecDebugLogLevel 9",
|
||||||
|
"SecRule ARGS_NAMES \"@contains test \" \"phase:3,pass,t:trim\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enabled":1,
|
||||||
|
"version_min":300000,
|
||||||
|
"title":"Testing Variables :: ARGS_NAMES - POST (4/4)",
|
||||||
|
"client":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":123
|
||||||
|
},
|
||||||
|
"server":{
|
||||||
|
"ip":"200.249.12.31",
|
||||||
|
"port":80
|
||||||
|
},
|
||||||
|
"request":{
|
||||||
|
"headers":{
|
||||||
|
"Host":"localhost",
|
||||||
|
"User-Agent":"curl/7.38.0",
|
||||||
|
"Accept":"*/*",
|
||||||
|
"Content-Length": "27",
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
"uri":"/",
|
||||||
|
"protocol":"POST",
|
||||||
|
"body": [
|
||||||
|
"param1=value1¶m2=value2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"response":{
|
||||||
|
"headers":{
|
||||||
|
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
|
||||||
|
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
|
||||||
|
"Content-Type":"text/html"
|
||||||
|
},
|
||||||
|
"body":[
|
||||||
|
"no need."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"expected":{
|
||||||
|
"debug_log":"Target value: \"param1 param2\""
|
||||||
|
},
|
||||||
|
"rules":[
|
||||||
|
"SecRuleEngine On",
|
||||||
|
"SecDebugLog \/tmp\/modsec_debug.log",
|
||||||
|
"SecDebugLogLevel 9",
|
||||||
|
"SecRule ARGS_NAMES \"@contains test \" \"phase:3,pass,t:trim\""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user