From c85529158e402dddc534bc36a12ab99875c32ed0 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 5 May 2016 15:47:21 -0300 Subject: [PATCH] Adds support to the cmd_line transformation Details on #965 --- src/actions/transformations/cmd_line.cc | 58 ++++++++++++++++++++----- src/actions/transformations/cmd_line.h | 4 +- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/actions/transformations/cmd_line.cc b/src/actions/transformations/cmd_line.cc index bd7d139f..7d567fcf 100644 --- a/src/actions/transformations/cmd_line.cc +++ b/src/actions/transformations/cmd_line.cc @@ -30,24 +30,58 @@ namespace modsecurity { namespace actions { namespace transformations { -CmdLine::CmdLine(std::string action) - : Transformation(action) { - this->action_kind = 1; -} std::string CmdLine::evaluate(std::string value, Transaction *transaction) { - /** - * @todo Implement the transformation CmdLine - */ - if (transaction) { -#ifndef NO_LOGS - transaction->debug(4, "Transformation CmdLine is not implemented yet."); -#endif + std::string ret; + int space = 0; + + for (auto& a : value) { + switch (a) { + /* remove some characters */ + case '"': + case '\'': + case '\\': + case '^': + //ret.append("i was here"); + break; + + /* replace some characters to space (only one) */ + case ' ': + case ',': + case ';': + case '\t': + case '\r': + case '\n': + if (space == 0) { + ret.append(" "); + space++; + } + break; + + /* remove space before / or ( */ + case '/': + case '(': + if (space) { + ret.pop_back(); + } + space = 0; + ret.append(&a, 1); + break; + + /* copy normal characters */ + default : + char b = std::tolower(a); + ret.append(&b); + space = 0; + break; + } } - return value; + + return ret; } + } // namespace transformations } // namespace actions } // namespace modsecurity diff --git a/src/actions/transformations/cmd_line.h b/src/actions/transformations/cmd_line.h index 95859f11..a6be5f87 100644 --- a/src/actions/transformations/cmd_line.h +++ b/src/actions/transformations/cmd_line.h @@ -30,7 +30,9 @@ namespace transformations { class CmdLine : public Transformation { public: - explicit CmdLine(std::string action); + explicit CmdLine(std::string action) + : Transformation(action) { } + std::string evaluate(std::string exp, Transaction *transaction) override; };