Adds support to the cmd_line transformation

Details on #965
This commit is contained in:
Felipe Zimmerle 2016-05-05 15:47:21 -03:00
parent d0e0002283
commit c85529158e
2 changed files with 49 additions and 13 deletions

View File

@ -30,23 +30,57 @@ 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++;
}
return value;
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 ret;
}
} // namespace transformations
} // namespace actions

View File

@ -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;
};