diff --git a/src/assay.cc b/src/assay.cc index a372872f..f7290b5a 100644 --- a/src/assay.cc +++ b/src/assay.cc @@ -211,13 +211,22 @@ int Assay::processURI(const char *uri, const char *protocol, const char *pos = strchr(m_uri_decoded.c_str(), '?'); + std::string path_info; if (pos == NULL) { - store_variable("PATH_INFO", std::string(m_uri_decoded, 0)); + path_info = std::string(m_uri_decoded, 0); } else { - store_variable("PATH_INFO", std::string(m_uri_decoded, 0, - pos - m_uri_decoded.c_str())); + path_info = std::string(m_uri_decoded, 0, + pos - m_uri_decoded.c_str()); store_variable("QUERY_STRING", std::string(strchr(m_uri, '?'))); } + store_variable("PATH_INFO", path_info); + + size_t offset = path_info.find_last_of("/\\"); + if (offset != std::string::npos) { + std::string basename = std::string(path_info, offset, + path_info.length() - offset); + store_variable("REQUEST_BASENAME", basename); + } if (pos != NULL && strlen(pos) > 2) { /** @@ -550,6 +559,8 @@ int Assay::processRequestBody() { store_variable("FULL_REQUEST", fullRequest); store_variable("FULL_REQUEST_LENGTH", std::to_string(fullRequest.size())); + store_variable("REQUEST_BODY", m_requestBody.str()); + this->m_rules->evaluate(ModSecurity::RequestBodyPhase, this); return 0; } diff --git a/test/test-cases/regression/variable-REQUEST_BASENAME.json b/test/test-cases/regression/variable-REQUEST_BASENAME.json new file mode 100644 index 00000000..bf56d16d --- /dev/null +++ b/test/test-cases/regression/variable-REQUEST_BASENAME.json @@ -0,0 +1,45 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: REQUEST_BASENAME", + "client":{ + "ip":"200.249.12.31", + "port":123 + }, + "server":{ + "ip":"200.249.12.11", + "port":80 + }, + "request":{ + "headers":{ + "Host":"localhost", + "User-Agent":"curl/7.38.0", + "Accept":"*/*", + "Content-Length":"27", + "Content-Type":"application/x-www-form-urlencoded" + }, + "uri":"/one/two/login.php?key1=value1&key2=v%20a%20l%20u%20e%202", + "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: \"/login.php\" \\(Variable: REQUEST_BASENAME\\)" + }, + "rules":[ + "SecRuleEngine On", + "SecDebugLog \/tmp\/modsec_debug.log", + "SecDebugLogLevel 9", + "SecRule REQUEST_BASENAME \"@contains test \" \"phase:3,pass,t:trim\"" + ] + } +] \ No newline at end of file diff --git a/test/test-cases/regression/variable-REQUEST_BODY.json b/test/test-cases/regression/variable-REQUEST_BODY.json new file mode 100644 index 00000000..0af524c0 --- /dev/null +++ b/test/test-cases/regression/variable-REQUEST_BODY.json @@ -0,0 +1,63 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: REQUEST_BODY", + "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":"330", + "Content-Type":"multipart/form-data; boundary=--------------------------756b6d74fa1a8ee2", + "Expect":"100-continue" + }, + "uri":"/", + "protocol":"POST", + "body":[ + "--------------------------756b6d74fa1a8ee2", + "Content-Disposition: form-data; name=\"name\"", + "", + "test", + "--------------------------756b6d74fa1a8ee2", + "Content-Disposition: form-data; name=\"filedata\"; filename=\"small_text_file.txt\"", + "Content-Type: text/plain", + "", + "This is a very small test file..", + "--------------------------756b6d74fa1a8ee2", + "Content-Disposition: form-data; name=\"filedata\"; filename=\"small_text_file.txt\"", + "Content-Type: text/plain", + "", + "This is another very small test file..", + "--------------------------756b6d74fa1a8ee2--" + ] + }, + "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":"-------------------------756b6d74fa1a8ee2--\" \\(Variable: REQUEST_BODY\\)" + }, + "rules":[ + "SecRuleEngine On", + "SecDebugLog \/tmp\/modsec_debug.log", + "SecDebugLogLevel 9", + "SecRule REQUEST_BODY \"@contains small_text_file.txt\" \"phase:3,pass,t:trim\"" + ] + } +] \ No newline at end of file