Adds support to ARGS_COMBINED_SIZE variable

This commit is contained in:
Felipe Zimmerle 2015-07-14 14:17:12 -03:00
parent 76b769cc84
commit 228a5ce7cc
3 changed files with 329 additions and 2 deletions

View File

@ -139,7 +139,7 @@ class Assay {
std::list<std::string> resolve_variable(std::string var); std::list<std::string> resolve_variable(std::string var);
std::string* resolve_variable_first(std::string); std::string* resolve_variable_first(std::string);
void store_variable(std::string, std::string); void store_variable(std::string, const std::string &value);
ModSecurityStringVariables m_variables_strings; ModSecurityStringVariables m_variables_strings;
@ -175,6 +175,9 @@ class Assay {
std::string m_namesResponse; std::string m_namesResponse;
std::string m_namesRequest; std::string m_namesRequest;
double m_ARGScombinedSize;
/** TODO: Support to save double in the storage. */
std::string *m_ARGScombinedSizeStr;
std::ostringstream m_requestBody; std::ostringstream m_requestBody;
std::ostringstream m_responseBody; std::ostringstream m_responseBody;

View File

@ -90,10 +90,16 @@ Assay::Assay(ModSecurity *ms, Rules *rules)
do_not_save_in_auditlog(false), do_not_save_in_auditlog(false),
timeStamp(std::time(NULL)), timeStamp(std::time(NULL)),
httpCodeReturned(200), httpCodeReturned(200),
m_ARGScombinedSize(0),
m_ARGScombinedSizeStr(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());
m_rules->incrementReferenceCount(); m_rules->incrementReferenceCount();
store_variable("ARGS_COMBINED_SIZE", std::string("0"));
this->m_ARGScombinedSizeStr = resolve_variable_first("ARGS_COMBINED_SIZE");
this->debug(4, "Initialising transaction"); this->debug(4, "Initialising transaction");
} }
@ -212,6 +218,11 @@ 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]);
this->m_ARGScombinedSize = this->m_ARGScombinedSize + \
key_value[0].length() + key_value[1].length();
this->m_ARGScombinedSizeStr->assign(
std::to_string(this->m_ARGScombinedSize));
debug(4, "Adding request argument (QUERY_STRING): name \"" + \ debug(4, "Adding request argument (QUERY_STRING): name \"" + \
key_value[0] + "\", value \"" + key_value[1] + "\""); key_value[0] + "\", value \"" + key_value[1] + "\"");
store_variable("QUERY_STRING:" + key_value[0], key_value[1]); store_variable("QUERY_STRING:" + key_value[0], key_value[1]);
@ -379,6 +390,10 @@ 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]);
this->m_ARGScombinedSize = this->m_ARGScombinedSize + \
key_value[0].length() + key_value[1].length();
this->m_ARGScombinedSizeStr->assign(
std::to_string(this->m_ARGScombinedSize));
} }
} }
@ -1004,7 +1019,7 @@ std::string Assay::to_json(int parts) {
} }
void Assay::store_variable(std::string key, std::string value) { void Assay::store_variable(std::string key, const std::string &value) {
this->m_variables_strings.emplace(key, value); this->m_variables_strings.emplace(key, value);
} }

View File

@ -0,0 +1,309 @@
[
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - GET (1/7)",
"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: \"22."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"pass\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - GET (2/7)",
"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&a=b",
"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: \"24."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"pass\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - POST (3/7)",
"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&param2=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: \"24."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"phase:3,pass\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - POST (4/7)",
"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&param2=value2&a=b\n"
]
},
"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: \"27."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"phase:3,pass,t:trim\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - POST (5/7)",
"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": [
"a=%EC%A7%84%20%EB%A7%88%EC%9D%BC%20%EB%A6%AC"
]
},
"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: \"15."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"phase:3,pass,t:trim\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - GET (6/7)",
"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":"/?z=%EC%A7%84%20%EB%A7%88%EC%9D%BC%20%EB%A6%AC",
"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: \"15."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"phase:3,pass,t:trim\""
]
},
{
"enabled":1,
"version_min":300000,
"title":"Testing Variables :: ARGS_COMBINED_SIZE - GET (7/7)",
"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":"/?z=진 마일 리",
"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: \"15."
},
"rules":[
"SecRuleEngine On",
"SecDebugLog \/tmp\/modsec_debug.log",
"SecDebugLogLevel 9",
"SecRule ARGS_COMBINED_SIZE \"@gt 10 \" \"phase:3,pass,t:trim\""
]
}
]