Skip to content

Commit df25c48

Browse files
author
Felipe Zimmerle
committed
Adds capture action to verifyCC
1 parent 77a885d commit df25c48

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
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 verifyCC
5+
[Issue #1698 - @michaelgranzow-avi, @zimmerle]
46
- Adds capture action to verifySSN
57
[Issue #1698 - @zimmerle]
68
- Adds capture action to verifyCPF

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
144144
TESTS+=test/test-cases/regression/operator-rx.json
145145
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
146146
TESTS+=test/test-cases/regression/operator-validate-byte-range.json
147+
TESTS+=test/test-cases/regression/operator-verifycc.json
147148
TESTS+=test/test-cases/regression/operator-verifycpf.json
148149
TESTS+=test/test-cases/regression/operator-verifyssn.json
149150
TESTS+=test/test-cases/regression/request-body-parser-json.json

src/operators/verify_cc.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ bool VerifyCC::init(const std::string &param2, std::string *error) {
117117
}
118118

119119

120-
bool VerifyCC::evaluate(Transaction *transaction, const std::string &i) {
120+
bool VerifyCC::evaluate(Transaction *t, Rule *rule,
121+
const std::string& i, std::shared_ptr<RuleMessage> ruleMessage) {
121122
int offset = 0;
122123
bool is_cc = false;
123124
int target_length = i.length();
@@ -136,14 +137,22 @@ bool VerifyCC::evaluate(Transaction *transaction, const std::string &i) {
136137
if (ret < 0) {
137138
return false;
138139
}
139-
140140
if (ret > 0) {
141141
match = std::string(i, ovector[0], ovector[1] - ovector[0]);
142142
is_cc = luhnVerify(match.c_str(), match.size());
143143
if (is_cc) {
144-
if (transaction) {
144+
if (t) {
145+
if (rule && t
146+
&& rule->getActionsByName("capture").size() > 0) {
147+
t->m_collections.m_tx_collection->storeOrUpdateFirst(
148+
"0", std::string(match));
149+
#ifndef NO_LOGS
150+
t->debug(7, "Added VerifyCC match TX.0: " + \
151+
std::string(match));
152+
#endif
153+
}
145154
#ifndef NO_LOGS
146-
transaction->debug(9, "CC# match \"" + m_param +
155+
t->debug(9, "CC# match \"" + m_param +
147156
"\" at " + i + ". [offset " +
148157
std::to_string(offset) + "]");
149158
#endif

src/operators/verify_cc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class VerifyCC : public Operator {
3636
~VerifyCC();
3737

3838
int luhnVerify(const char *ccnumber, int len);
39-
bool evaluate(Transaction *transaction, const std::string &input) override;
39+
bool evaluate(Transaction *t, Rule *rule,
40+
const std::string& input,
41+
std::shared_ptr<RuleMessage> ruleMessage) override;
4042
bool init(const std::string &param, std::string *error) override;
4143
private:
4244
pcre *m_pc;
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 :: @verifycc",
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=5484605089158216&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 VerifyCC match TX.0: 5484605089158216"
40+
},
41+
"rules":[
42+
"SecRuleEngine On",
43+
"SecRule ARGS \"@verifycc \\d{13,16}\" \"id:1,phase:2,capture,pass,t:trim\""
44+
]
45+
}
46+
]

0 commit comments

Comments
 (0)