-
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 all commits
289b6e3
38d9391
0c610c0
0b29169
46dabc0
c816add
d94cbeb
b4b81aa
15fd157
4bacc36
f9b2885
a8debeb
c67f876
7b5bf7f
e169d59
724b197
b9393e7
d1eaa04
7e1d08b
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 |
|---|---|---|
|
|
@@ -18,36 +18,50 @@ | |
| #include <string> | ||
|
|
||
| #include "src/operators/operator.h" | ||
| #include "src/operators/libinjection_utils.h" | ||
| #include "libinjection/src/libinjection.h" | ||
| #include "libinjection/src/libinjection_error.h" | ||
|
Comment on lines
22
to
+23
|
||
|
|
||
|
|
||
| namespace modsecurity { | ||
| namespace operators { | ||
|
|
||
| namespace modsecurity::operators { | ||
|
|
||
| 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()); | ||
|
|
||
| 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)); | ||
|
|
||
| const injection_result_t xss_result = | ||
| libinjection_xss(input.c_str(), input.length()); | ||
|
|
||
| if (t == nullptr) { | ||
| return isMaliciousLibinjectionResult(xss_result); | ||
| } | ||
|
|
||
| switch (xss_result) { | ||
| case LIBINJECTION_RESULT_TRUE: | ||
| ms_dbg_a(t, 5, std::string("detected XSS using libinjection.")) | ||
| if (rule != nullptr && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst("0", input); | ||
| ms_dbg_a(t, 7, std::string("Added DetectXSS match TX.0: ") + input) | ||
| } | ||
| } else { | ||
| ms_dbg_a(t, 9, "libinjection was not able to " \ | ||
| "find any XSS in: " + input); | ||
| break; | ||
|
|
||
| case LIBINJECTION_RESULT_ERROR: | ||
| ms_dbg_a(t, 4, | ||
| std::string("libinjection parser error during XSS analysis (") | ||
| + libinjectionResultToString(xss_result) | ||
| + "); treating as match (fail-safe). Input: " | ||
| + input) | ||
| if (rule != nullptr && rule->hasCaptureAction()) { | ||
| t->m_collections.m_tx_collection->storeOrUpdateFirst("0", input); | ||
| ms_dbg_a(t, 7, std::string("Added DetectXSS error input TX.0: ") + input) | ||
| } | ||
| break; | ||
|
|
||
| case LIBINJECTION_RESULT_FALSE: | ||
| ms_dbg_a(t, 9, | ||
| std::string("libinjection was not able to find any XSS in: ") + input) | ||
| break; | ||
| } | ||
| return is_xss != 0; | ||
| } | ||
|
|
||
| return isMaliciousLibinjectionResult(xss_result); | ||
| } | ||
|
|
||
| } // namespace operators | ||
| } // namespace modsecurity | ||
| } // namespace modsecurity::operators | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * ModSecurity, http://www.modsecurity.org/ | ||
| * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/) | ||
| * | ||
| * You may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * If any of the files related to licensing are missing or if you have any | ||
| * other questions related to licensing please contact Trustwave Holdings, Inc. | ||
| * directly using the email address security@modsecurity.org. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef SRC_OPERATORS_LIBINJECTION_UTILS_H_ | ||
| #define SRC_OPERATORS_LIBINJECTION_UTILS_H_ | ||
|
|
||
| #include "libinjection/src/libinjection_error.h" | ||
|
|
||
| namespace modsecurity::operators { | ||
|
|
||
| /* | ||
| * libinjection parser errors are handled in fail-safe mode as suspicious | ||
| * results, so callers can block on both confirmed detections and parser | ||
| * failures. | ||
| */ | ||
| static inline bool isMaliciousLibinjectionResult(injection_result_t result) { | ||
| return result == LIBINJECTION_RESULT_TRUE | ||
| || result == LIBINJECTION_RESULT_ERROR; | ||
| } | ||
|
|
||
| static inline const char *libinjectionResultToString(injection_result_t result) { | ||
| switch (result) { | ||
| case LIBINJECTION_RESULT_TRUE: | ||
| return "attack-detected"; | ||
| case LIBINJECTION_RESULT_FALSE: | ||
| return "no-attack"; | ||
| case LIBINJECTION_RESULT_ERROR: | ||
| return "parser-error"; | ||
| } | ||
|
|
||
| return "unexpected-result"; | ||
| } | ||
|
|
||
| } // namespace modsecurity::operators | ||
|
|
||
| #endif // SRC_OPERATORS_LIBINJECTION_UTILS_H_ |
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.