Skip to content

Commit 70ace0f

Browse files
author
Felipe Zimmerle
committed
Adds capture action to detectSQLi
1 parent 0f361b7 commit 70ace0f

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.x - YYYY-MMM-DD (To be released)
22
-------------------------------------
33

4+
- Adds capture action to detectSQLi
5+
[Issue #1698 - @zimmerle]
46
- Adds capture action to rbl
57
[Issue #1698 - @zimmerle]
68
- Adds capture action to verifyCC

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ TESTS+=test/test-cases/regression/issue-960.json
138138
TESTS+=test/test-cases/regression/misc.json
139139
TESTS+=test/test-cases/regression/misc-variable-under-quotes.json
140140
TESTS+=test/test-cases/regression/offset-variable.json
141+
TESTS+=test/test-cases/regression/operator-detectsqli.json
141142
TESTS+=test/test-cases/regression/operator-fuzzyhash.json
142143
TESTS+=test/test-cases/regression/operator-inpectFile.json
143144
TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json

src/operators/detect_sqli.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,35 @@ namespace modsecurity {
2525
namespace operators {
2626

2727

28-
bool DetectSQLi::evaluate(Transaction *transaction, const std::string &input) {
28+
bool DetectSQLi::evaluate(Transaction *t, Rule *rule,
29+
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
2930
char fingerprint[8];
3031
int issqli;
3132

3233
issqli = libinjection_sqli(input.c_str(), input.length(), fingerprint);
3334

3435
if (issqli) {
35-
if (transaction) {
36-
transaction->m_matched.push_back(fingerprint);
36+
if (t) {
37+
t->m_matched.push_back(fingerprint);
3738
#ifndef NO_LOGS
38-
transaction->debug(4, "detected SQLi using libinjection with " \
39+
t->debug(4, "detected SQLi using libinjection with " \
3940
"fingerprint '" + std::string(fingerprint) + "' at: '" +
4041
input + "'");
4142
#endif
43+
if (rule && t
44+
&& rule->getActionsByName("capture").size() > 0) {
45+
t->m_collections.m_tx_collection->storeOrUpdateFirst(
46+
"0", std::string(fingerprint));
47+
#ifndef NO_LOGS
48+
t->debug(7, "Added DetectSQLi match TX.0: " + \
49+
std::string(fingerprint));
50+
#endif
51+
}
4252
}
4353
} else {
44-
if (transaction) {
54+
if (t) {
4555
#ifndef NO_LOGS
46-
transaction->debug(9, "detected SQLi: not able to find an " \
56+
t->debug(9, "detected SQLi: not able to find an " \
4757
"inject on '" + input + "'");
4858
#endif
4959
}

src/operators/detect_sqli.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class DetectSQLi : public Operator {
3232
m_match_message.assign("detected SQLi using libinjection.");
3333
}
3434

35-
bool evaluate(Transaction *transaction, const std::string &input);
35+
bool evaluate(Transaction *t, Rule *rule,
36+
const std::string& input,
37+
std::shared_ptr<RuleMessage> ruleMessage) override;
3638
};
3739

3840
} // namespace operators
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"enabled":1,
4+
"version_min":300000,
5+
"title":"Testing Operator :: @detectSQLi",
6+
"client":{
7+
"ip":"200.249.12.31",
8+
"port":123
9+
},
10+
"server":{
11+
"ip":"200.249.12.31",
12+
"port":80
13+
},
14+
"request":{
15+
"headers":{
16+
"Host":"localhost",
17+
"User-Agent":"curl/7.38.0",
18+
"Accept":"*/*",
19+
"Content-Length": "27",
20+
"Content-Type": "application/x-www-form-urlencoded"
21+
},
22+
"uri":"/",
23+
"method":"POST",
24+
"body": [
25+
"param1=ascii(substring(version() from 1 for 1))&param2=value2"
26+
]
27+
},
28+
"response":{
29+
"headers":{
30+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
31+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
32+
"Content-Type":"text/html"
33+
},
34+
"body":[
35+
"no need."
36+
]
37+
},
38+
"expected":{
39+
"debug_log":"Added DetectSQLi match TX.0: f\\(f\\(f"
40+
},
41+
"rules":[
42+
"SecRuleEngine On",
43+
"SecRule ARGS \"@detectSQLi\" \"id:1,phase:2,capture,pass,t:trim\""
44+
]
45+
}
46+
]

0 commit comments

Comments
 (0)