mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds protocol and http version to processUri method's signature
Protocol and http version will be further used to fill some variables and the audit log.
This commit is contained in:
parent
2109910848
commit
278b513933
@ -36,7 +36,9 @@ int main (int argc, char **argv)
|
|||||||
assay = msc_new_assay(modsec, rules);
|
assay = msc_new_assay(modsec, rules);
|
||||||
|
|
||||||
msc_process_connection(assay, "127.0.0.1", 12345, "127.0.0.1", 80);
|
msc_process_connection(assay, "127.0.0.1", 12345, "127.0.0.1", 80);
|
||||||
msc_process_uri(assay, "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3&test=args&test=test");
|
msc_process_uri(assay,
|
||||||
|
"http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3",
|
||||||
|
"GET", "1.1");
|
||||||
msc_process_request_headers(assay);
|
msc_process_request_headers(assay);
|
||||||
msc_process_request_body(assay);
|
msc_process_request_body(assay);
|
||||||
msc_process_response_headers(assay);
|
msc_process_response_headers(assay);
|
||||||
|
@ -87,7 +87,8 @@ class Assay {
|
|||||||
/** TODO: Should be an structure that fits an IP address */
|
/** TODO: Should be an structure that fits an IP address */
|
||||||
int processConnection(const char *client, int cPort,
|
int processConnection(const char *client, int cPort,
|
||||||
const char *server, int sPort);
|
const char *server, int sPort);
|
||||||
int processURI(const char *uri);
|
int processURI(const char *uri, const char *protocol,
|
||||||
|
const char *http_version);
|
||||||
|
|
||||||
|
|
||||||
int processRequestHeaders();
|
int processRequestHeaders();
|
||||||
@ -141,6 +142,9 @@ class Assay {
|
|||||||
int m_clientPort;
|
int m_clientPort;
|
||||||
int m_serverPort;
|
int m_serverPort;
|
||||||
const char *m_uri;
|
const char *m_uri;
|
||||||
|
const char *m_protocol;
|
||||||
|
const char *m_httpVersion;
|
||||||
|
|
||||||
std::ostringstream m_requestBody;
|
std::ostringstream m_requestBody;
|
||||||
std::ostringstream m_responseBody;
|
std::ostringstream m_responseBody;
|
||||||
ModSecurityCollectionsVariables m_variables_collections;
|
ModSecurityCollectionsVariables m_variables_collections;
|
||||||
@ -194,7 +198,9 @@ int msc_append_response_body(Assay *assay,
|
|||||||
const unsigned char *body, size_t size);
|
const unsigned char *body, size_t size);
|
||||||
|
|
||||||
/** @ingroup ModSecurity_C_API */
|
/** @ingroup ModSecurity_C_API */
|
||||||
int msc_process_uri(Assay *assay, const char *uri);
|
int msc_process_uri(Assay *assay, const char *uri, const char *protocol,
|
||||||
|
const char *http_version);
|
||||||
|
|
||||||
/** @ingroup ModSecurity_C_API */
|
/** @ingroup ModSecurity_C_API */
|
||||||
const char *msc_get_response_body(Assay *assay);
|
const char *msc_get_response_body(Assay *assay);
|
||||||
/** @ingroup ModSecurity_C_API */
|
/** @ingroup ModSecurity_C_API */
|
||||||
|
25
src/assay.cc
25
src/assay.cc
@ -78,6 +78,8 @@ Assay::Assay(ModSecurity *ms, Rules *rules)
|
|||||||
m_clientPort(0),
|
m_clientPort(0),
|
||||||
m_serverPort(0),
|
m_serverPort(0),
|
||||||
m_uri(""),
|
m_uri(""),
|
||||||
|
m_protocol(""),
|
||||||
|
m_httpVersion(""),
|
||||||
m_rules(rules),
|
m_rules(rules),
|
||||||
save_in_auditlog(false),
|
save_in_auditlog(false),
|
||||||
do_not_save_in_auditlog(false),
|
do_not_save_in_auditlog(false),
|
||||||
@ -157,16 +159,24 @@ int Assay::processConnection(const char *client, int cPort, const char *server,
|
|||||||
* SecLanguage phase 1 and 2.
|
* SecLanguage phase 1 and 2.
|
||||||
* @note Remember to check for a possible intervention.
|
* @note Remember to check for a possible intervention.
|
||||||
*
|
*
|
||||||
* @param buf Uri.
|
* @param assay ModSecurity assay.
|
||||||
|
* @param uri Uri.
|
||||||
|
* @param protocol Protocol (GET, POST, PUT).
|
||||||
|
* @param http_version Http version (1.0, 1.2, 2.0).
|
||||||
*
|
*
|
||||||
* @returns If the operation was successful or not.
|
* @returns If the operation was successful or not.
|
||||||
* @retval true Operation was successful.
|
* @retval true Operation was successful.
|
||||||
* @retval false Operation failed.
|
* @retval false Operation failed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int Assay::processURI(const char *uri) {
|
int Assay::processURI(const char *uri, const char *protocol,
|
||||||
|
const char *http_version) {
|
||||||
debug(4, "Starting phase URI. (SecRules 0 + 1/2)");
|
debug(4, "Starting phase URI. (SecRules 0 + 1/2)");
|
||||||
|
|
||||||
|
m_protocol = protocol;
|
||||||
|
m_httpVersion = http_version;
|
||||||
|
m_uri = uri;
|
||||||
|
|
||||||
const char *pos = strchr(uri, '?');
|
const char *pos = strchr(uri, '?');
|
||||||
|
|
||||||
if (pos != NULL && strlen(pos) > 2) {
|
if (pos != NULL && strlen(pos) > 2) {
|
||||||
@ -197,7 +207,7 @@ int Assay::processURI(const char *uri) {
|
|||||||
store_variable("QUERY_STRING:" + key_value[0], key_value[1]);
|
store_variable("QUERY_STRING:" + key_value[0], key_value[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -752,15 +762,18 @@ extern "C" int msc_process_connection(Assay *assay, const char *client,
|
|||||||
* @note Remember to check for a possible intervention.
|
* @note Remember to check for a possible intervention.
|
||||||
*
|
*
|
||||||
* @param assay ModSecurity assay.
|
* @param assay ModSecurity assay.
|
||||||
* @param buf Uri.
|
* @param uri Uri.
|
||||||
|
* @param protocol Protocol (GET, POST, PUT).
|
||||||
|
* @param http_version Http version (1.0, 1.2, 2.0).
|
||||||
*
|
*
|
||||||
* @returns If the operation was successful or not.
|
* @returns If the operation was successful or not.
|
||||||
* @retval 1 Operation was successful.
|
* @retval 1 Operation was successful.
|
||||||
* @retval 0 Operation failed.
|
* @retval 0 Operation failed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
extern "C" int msc_process_uri(Assay *assay, const char *buf) {
|
extern "C" int msc_process_uri(Assay *assay, const char *uri,
|
||||||
return assay->processURI(buf);
|
const char *protocol, const char *http_version) {
|
||||||
|
return assay->processURI(uri, protocol, http_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
|
|||||||
std::cout << "There is an intervention" << std::endl;
|
std::cout << "There is an intervention" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
modsecAssay->processURI(request_uri);
|
modsecAssay->processURI(request_uri, "GET", "1.1");
|
||||||
if (modsecAssay->intervention()) {
|
if (modsecAssay->intervention()) {
|
||||||
std::cout << "There is an intervention" << std::endl;
|
std::cout << "There is an intervention" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
|
@ -85,13 +85,14 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
|
|||||||
if (r.status != 200) {
|
if (r.status != 200) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (t->uri.empty() == false) {
|
|
||||||
modsec_assay->processURI(t->uri.c_str());
|
modsec_assay->processURI(t->uri.c_str(), t->protocol.c_str(),
|
||||||
|
t->httpVersion.c_str());
|
||||||
|
|
||||||
actions(&r, modsec_assay->intervention());
|
actions(&r, modsec_assay->intervention());
|
||||||
if (r.status != 200) {
|
if (r.status != 200) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (std::pair<std::string, std::string> headers :
|
for (std::pair<std::string, std::string> headers :
|
||||||
t->request_headers) {
|
t->request_headers) {
|
||||||
|
@ -141,6 +141,12 @@ RegressionTest *RegressionTest::from_yajl_node(const yajl_val &node) {
|
|||||||
if (strcmp(key2, "uri") == 0) {
|
if (strcmp(key2, "uri") == 0) {
|
||||||
u->uri = YAJL_GET_STRING(val2);
|
u->uri = YAJL_GET_STRING(val2);
|
||||||
}
|
}
|
||||||
|
if (strcmp(key2, "protocol") == 0) {
|
||||||
|
u->protocol = YAJL_GET_STRING(val2);
|
||||||
|
}
|
||||||
|
if (strcmp(key2, "http_version") == 0) {
|
||||||
|
u->httpVersion = YAJL_GET_NUMBER(val2);
|
||||||
|
}
|
||||||
if (strcmp(key2, "headers") == 0) {
|
if (strcmp(key2, "headers") == 0) {
|
||||||
u->request_headers = yajl_array_to_map(val2);
|
u->request_headers = yajl_array_to_map(val2);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ class RegressionTest {
|
|||||||
int clientPort;
|
int clientPort;
|
||||||
int serverPort;
|
int serverPort;
|
||||||
|
|
||||||
|
std::string protocol;
|
||||||
|
std::string httpVersion;
|
||||||
std::string uri;
|
std::string uri;
|
||||||
|
|
||||||
static inline std::string yajl_array_to_str(const yajl_val &node);
|
static inline std::string yajl_array_to_str(const yajl_val &node);
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
@ -85,7 +87,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
@ -145,7 +149,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
@ -205,7 +211,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
@ -264,7 +272,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
@ -323,7 +333,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1=test¶2=test2",
|
"uri": "\/test.pl?param1=test¶2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
},
|
},
|
||||||
"request": {
|
"request": {
|
||||||
"headers": "",
|
"headers": "",
|
||||||
"body": ""
|
"body": "",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"headers": "",
|
"headers": "",
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= test ¶m2=test2",
|
"uri": "\/test.pl?param1= test ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
@ -84,7 +86,9 @@
|
|||||||
"Pragma": "no-cache",
|
"Pragma": "no-cache",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache"
|
||||||
},
|
},
|
||||||
"uri": "GET \/test.pl?param1= WHEE ¶m2=test2",
|
"uri": "\/test.pl?param1= WHEE ¶m2=test2",
|
||||||
|
"protocol": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
"body": ""
|
"body": ""
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user