-
Notifications
You must be signed in to change notification settings - Fork 6
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
Shell injection detection operator #308
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #308 +/- ##
==========================================
+ Coverage 83.68% 84.28% +0.60%
==========================================
Files 137 141 +4
Lines 6086 6554 +468
Branches 2882 3023 +141
==========================================
+ Hits 5093 5524 +431
- Misses 369 374 +5
- Partials 624 656 +32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
BenchmarksBenchmark execution time: 2024-07-15 12:35:05 Comparing candidate commit 5985929 in PR branch Found 5 performance improvements and 3 performance regressions! Performance is the same for 11 metrics, 0 unstable metrics. scenario:ip_match_matcher.random
scenario:is_xss_matcher.random
scenario:phrase_match_matcher.enforce_word_boundary.random
scenario:regex_match_matcher.case_insensitive_flag.random
scenario:regex_match_matcher.case_insensitive_option.random
scenario:regex_match_matcher.lowercase_transformer.random
scenario:regex_match_matcher.random
scenario:string_equals_matcher.random
|
… without interesting tokens
|
||
namespace ddwaf { | ||
|
||
template <typename T> struct base_token { |
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.
it would make the code more readable if you had start(), end(), size(). In particular end
, because token.index + token.str.size()
is a bigger expression. Or just an interval()
method, as mentioned.
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.
Since this comment and the one below affect other tokenizers as well, I'll try to address them together in a separate PR.
std::size_t i = 0; | ||
for (; i < resource_tokens.size(); ++i) { | ||
const auto &token = resource_tokens[i]; | ||
if (end_index >= token.index && param_index < (token.index + token.str.size())) { |
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.
this would be easier to understand if you had an interval abstraction with contains
, overlaps
, ...
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.
Since this comment and the one above affect other tokenizers as well, I'll try to address them together in a separate PR.
This PR introduces support for a new operator
shi_detector
which can be used for detecting Shell injections given a set of request parameters and a shell command. The heuristic primarily attempts to find injected executables and redirections, with most of the work being done by the tokenizer.In this instance, the tokenizer does a bit more work than just finding simple tokens, as it attempts to minimise the number of needed tokens and keeps sufficient context to track nested commands and their boundaries. It currently consists in two phases, the first one generates low and high level tokens, while the second one finds executables and strips whitespaces.
And some work which will be done in a subsequent PR:
To use this new operator,a rule such as the following could be used:
Related Jira: APPSEC-52939