From df25c48f53953578875bf3dc6a15665b6ff84ee1 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Fri, 9 Mar 2018 11:26:24 -0300 Subject: [PATCH] Adds capture action to verifyCC --- CHANGES | 2 + Makefile.am | 1 + src/operators/verify_cc.cc | 17 +++++-- src/operators/verify_cc.h | 4 +- .../regression/operator-verifycc.json | 46 +++++++++++++++++++ 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 test/test-cases/regression/operator-verifycc.json diff --git a/CHANGES b/CHANGES index 4f1eea93..a1af9750 100644 --- a/CHANGES +++ b/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 diff --git a/Makefile.am b/Makefile.am index bd2ce1ec..f0a1fcd6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/operators/verify_cc.cc b/src/operators/verify_cc.cc index 9572ae93..02807663 100644 --- a/src/operators/verify_cc.cc +++ b/src/operators/verify_cc.cc @@ -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) { 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 diff --git a/src/operators/verify_cc.h b/src/operators/verify_cc.h index edd06c0a..47cbb057 100644 --- a/src/operators/verify_cc.h +++ b/src/operators/verify_cc.h @@ -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) override; bool init(const std::string ¶m, std::string *error) override; private: pcre *m_pc; diff --git a/test/test-cases/regression/operator-verifycc.json b/test/test-cases/regression/operator-verifycc.json new file mode 100644 index 00000000..c7e5fafb --- /dev/null +++ b/test/test-cases/regression/operator-verifycc.json @@ -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\"" + ] + } +]