mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 13:26:01 +03:00
Adds capture action to verifyCC
This commit is contained in:
parent
77a885da5f
commit
df25c48f53
2
CHANGES
2
CHANGES
@ -1,6 +1,8 @@
|
||||
v3.0.x - YYYY-MMM-DD (To be released)
|
||||
-------------------------------------
|
||||
|
||||
- Adds capture action to verifyCC
|
||||
[Issue #1698 - @michaelgranzow-avi, @zimmerle]
|
||||
- Adds capture action to verifySSN
|
||||
[Issue #1698 - @zimmerle]
|
||||
- Adds capture action to verifyCPF
|
||||
|
@ -144,6 +144,7 @@ TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
|
||||
TESTS+=test/test-cases/regression/operator-rx.json
|
||||
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
|
||||
TESTS+=test/test-cases/regression/operator-validate-byte-range.json
|
||||
TESTS+=test/test-cases/regression/operator-verifycc.json
|
||||
TESTS+=test/test-cases/regression/operator-verifycpf.json
|
||||
TESTS+=test/test-cases/regression/operator-verifyssn.json
|
||||
TESTS+=test/test-cases/regression/request-body-parser-json.json
|
||||
|
@ -117,7 +117,8 @@ bool VerifyCC::init(const std::string ¶m2, std::string *error) {
|
||||
}
|
||||
|
||||
|
||||
bool VerifyCC::evaluate(Transaction *transaction, const std::string &i) {
|
||||
bool VerifyCC::evaluate(Transaction *t, Rule *rule,
|
||||
const std::string& i, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||
int offset = 0;
|
||||
bool is_cc = false;
|
||||
int target_length = i.length();
|
||||
@ -136,14 +137,22 @@ bool VerifyCC::evaluate(Transaction *transaction, const std::string &i) {
|
||||
if (ret < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ret > 0) {
|
||||
match = std::string(i, ovector[0], ovector[1] - ovector[0]);
|
||||
is_cc = luhnVerify(match.c_str(), match.size());
|
||||
if (is_cc) {
|
||||
if (transaction) {
|
||||
if (t) {
|
||||
if (rule && t
|
||||
&& rule->getActionsByName("capture").size() > 0) {
|
||||
t->m_collections.m_tx_collection->storeOrUpdateFirst(
|
||||
"0", std::string(match));
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(9, "CC# match \"" + m_param +
|
||||
t->debug(7, "Added VerifyCC match TX.0: " + \
|
||||
std::string(match));
|
||||
#endif
|
||||
}
|
||||
#ifndef NO_LOGS
|
||||
t->debug(9, "CC# match \"" + m_param +
|
||||
"\" at " + i + ". [offset " +
|
||||
std::to_string(offset) + "]");
|
||||
#endif
|
||||
|
@ -36,7 +36,9 @@ class VerifyCC : public Operator {
|
||||
~VerifyCC();
|
||||
|
||||
int luhnVerify(const char *ccnumber, int len);
|
||||
bool evaluate(Transaction *transaction, const std::string &input) override;
|
||||
bool evaluate(Transaction *t, Rule *rule,
|
||||
const std::string& input,
|
||||
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||
bool init(const std::string ¶m, std::string *error) override;
|
||||
private:
|
||||
pcre *m_pc;
|
||||
|
46
test/test-cases/regression/operator-verifycc.json
Normal file
46
test/test-cases/regression/operator-verifycc.json
Normal file
@ -0,0 +1,46 @@
|
||||
[
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @verifycc",
|
||||
"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": "27",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
"uri":"/",
|
||||
"method":"POST",
|
||||
"body": [
|
||||
"param1=5484605089158216¶m2=value2"
|
||||
]
|
||||
},
|
||||
"response":{
|
||||
"headers":{
|
||||
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
|
||||
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
|
||||
"Content-Type":"text/html"
|
||||
},
|
||||
"body":[
|
||||
"no need."
|
||||
]
|
||||
},
|
||||
"expected":{
|
||||
"debug_log":"Added VerifyCC match TX.0: 5484605089158216"
|
||||
},
|
||||
"rules":[
|
||||
"SecRuleEngine On",
|
||||
"SecRule ARGS \"@verifycc \\d{13,16}\" \"id:1,phase:2,capture,pass,t:trim\""
|
||||
]
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user