-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update SQLi/XSS operators for libinjection v4.0.0 #3522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3/master
Are you sure you want to change the base?
Changes from 4 commits
289b6e3
38d9391
0c610c0
0b29169
46dabc0
c816add
d94cbeb
b4b81aa
15fd157
4bacc36
f9b2885
a8debeb
c67f876
7b5bf7f
e169d59
724b197
b9393e7
d1eaa04
de17a7c
0f8bc6c
7e1d08b
9b37043
830a340
84cdfdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
|
|
||
| #include "src/operators/operator.h" | ||
| #include "libinjection/src/libinjection.h" | ||
| #include "libinjection/src/libinjection_error.h" | ||
|
|
||
| namespace modsecurity { | ||
| namespace operators { | ||
|
|
@@ -28,32 +29,52 @@ | |
| bool DetectSQLi::evaluate(Transaction *t, RuleWithActions *rule, | ||
| const std::string& input, RuleMessage &ruleMessage) { | ||
| char fingerprint[8]; | ||
| int issqli; | ||
| injection_result_t sqli_result; | ||
| bool is_match = false; | ||
|
|
||
| issqli = libinjection_sqli(input.c_str(), input.length(), fingerprint); | ||
| sqli_result = libinjection_sqli(input.c_str(), input.length(), fingerprint); | ||
|
|
||
| if (!t) { | ||
| goto tisempty; | ||
| } | ||
|
|
||
| if (issqli) { | ||
| t->m_matched.push_back(fingerprint); | ||
| ms_dbg_a(t, 4, "detected SQLi using libinjection with " \ | ||
| "fingerprint '" + std::string(fingerprint) + "' at: '" + | ||
| input + "'"); | ||
| if (rule && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst( | ||
| "0", std::string(fingerprint)); | ||
| ms_dbg_a(t, 7, "Added DetectSQLi match TX.0: " + \ | ||
| std::string(fingerprint)); | ||
| } | ||
| } else { | ||
| ms_dbg_a(t, 9, "detected SQLi: not able to find an " \ | ||
| "inject on '" + input + "'"); | ||
| switch (sqli_result) { | ||
| case LIBINJECTION_RESULT_TRUE: | ||
| is_match = true; | ||
| t->m_matched.push_back(fingerprint); | ||
| ms_dbg_a(t, 4, "detected SQLi using libinjection with " \ | ||
| "fingerprint '" + std::string(fingerprint) + "' at: '" + | ||
| input + "'"); | ||
| if (rule && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst( | ||
| "0", std::string(fingerprint)); | ||
| ms_dbg_a(t, 7, "Added DetectSQLi match TX.0: " + \ | ||
| std::string(fingerprint)); | ||
| } | ||
| break; | ||
| case LIBINJECTION_RESULT_ERROR: | ||
| is_match = true; | ||
| ms_dbg_a(t, 4, "libinjection parser error during SQLi " | ||
| "analysis; treating as match (fail-safe). Input: '" + input + "'"); | ||
|
Check warning on line 58 in src/operators/detect_sqli.cc
|
||
| if (rule && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst( | ||
| "0", std::string(input)); | ||
| ms_dbg_a(t, 7, "Added DetectSQLi error input TX.0: " + \ | ||
| std::string(input)); | ||
|
Check warning on line 63 in src/operators/detect_sqli.cc
|
||
| } | ||
| break; | ||
|
Comment on lines
+59
to
+74
|
||
| case LIBINJECTION_RESULT_FALSE: | ||
| ms_dbg_a(t, 9, "detected SQLi: not able to find an " \ | ||
| "inject on '" + input + "'"); | ||
| break; | ||
| } | ||
|
|
||
| tisempty: | ||
| return issqli != 0; | ||
| if (t == nullptr) { | ||
| is_match = sqli_result == LIBINJECTION_RESULT_TRUE | ||
| || sqli_result == LIBINJECTION_RESULT_ERROR; | ||
| } | ||
| return is_match; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| #include "src/operators/operator.h" | ||
| #include "libinjection/src/libinjection.h" | ||
| #include "libinjection/src/libinjection_error.h" | ||
|
Comment on lines
22
to
+23
|
||
|
|
||
|
|
||
| namespace modsecurity { | ||
|
|
@@ -27,25 +28,46 @@ | |
|
|
||
| bool DetectXSS::evaluate(Transaction *t, RuleWithActions *rule, | ||
| const std::string& input, RuleMessage &ruleMessage) { | ||
| int is_xss; | ||
|
|
||
| is_xss = libinjection_xss(input.c_str(), input.length()); | ||
| injection_result_t xss_result = libinjection_xss(input.c_str(), | ||
| input.length()); | ||
| bool is_match = false; | ||
|
|
||
| if (t) { | ||
| if (is_xss) { | ||
| ms_dbg_a(t, 5, "detected XSS using libinjection."); | ||
| if (rule && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst( | ||
| "0", std::string(input)); | ||
| ms_dbg_a(t, 7, "Added DetectXSS match TX.0: " + \ | ||
| std::string(input)); | ||
| } | ||
| } else { | ||
| ms_dbg_a(t, 9, "libinjection was not able to " \ | ||
| "find any XSS in: " + input); | ||
| } | ||
| switch (xss_result) { | ||
| case LIBINJECTION_RESULT_TRUE: | ||
| is_match = true; | ||
| ms_dbg_a(t, 5, "detected XSS using libinjection."); | ||
| if (rule && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst( | ||
| "0", std::string(input)); | ||
| ms_dbg_a(t, 7, "Added DetectXSS match TX.0: " + \ | ||
| std::string(input)); | ||
| } | ||
| break; | ||
| case LIBINJECTION_RESULT_ERROR: | ||
| is_match = true; | ||
| ms_dbg_a(t, 4, "libinjection parser error during XSS " | ||
| "analysis; treating as match (fail-safe). Input: " + input); | ||
|
Check warning on line 50 in src/operators/detect_xss.cc
|
||
| if (rule && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst( | ||
| "0", std::string(input)); | ||
| ms_dbg_a(t, 7, "Added DetectXSS error input TX.0: " + \ | ||
| std::string(input)); | ||
|
Check warning on line 55 in src/operators/detect_xss.cc
|
||
| } | ||
| break; | ||
|
||
| case LIBINJECTION_RESULT_FALSE: | ||
| ms_dbg_a(t, 9, "libinjection was not able to " \ | ||
| "find any XSS in: " + input); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (t == nullptr) { | ||
| is_match = xss_result == LIBINJECTION_RESULT_TRUE | ||
| || xss_result == LIBINJECTION_RESULT_ERROR; | ||
| } | ||
| return is_xss != 0; | ||
|
|
||
| return is_match; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,5 +44,51 @@ | |||||
| "SecRuleEngine On", | ||||||
| "SecRule ARGS \"@detectSQLi\" \"id:1,phase:2,capture,pass,t:trim\"" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "enabled": 1, | ||||||
| "version_min": 300000, | ||||||
| "title": "Testing Operator :: @detectSQLi benign input", | ||||||
| "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": "18", | ||||||
|
||||||
| "Content-Length": "18", | |
| "Content-Length": "19", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New dependency on
libinjection/src/libinjection_error.h: please ensure this header is present in the vendored libinjection submodule version and is included in release artifacts (e.g., add it toothers/Makefile.amnoinst_HEADERSifmake dist/packaging relies on that list). Otherwise builds from distribution tarballs can fail with a missing-header error.