diff --git a/src/Makefile.am b/src/Makefile.am index a0d085c0..b21ccc20 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -101,6 +101,7 @@ ACTIONS = \ actions/skip_after.cc \ actions/tag.cc \ actions/transformations/base64_decode.cc \ + actions/transformations/base64_encode.cc \ actions/transformations/base64_decode_ext.cc \ actions/transformations/cmd_line.cc \ actions/transformations/compress_whitespace.cc \ diff --git a/src/actions/transformations/base64_encode.cc b/src/actions/transformations/base64_encode.cc new file mode 100644 index 00000000..8440fcbd --- /dev/null +++ b/src/actions/transformations/base64_encode.cc @@ -0,0 +1,45 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + +#include "actions/transformations/base64_encode.h" + +#include +#include +#include +#include +#include +#include + +#include "modsecurity/transaction.h" +#include "actions/transformations/transformation.h" +#include "utils/base64.h" + + +namespace modsecurity { +namespace actions { +namespace transformations { + + +std::string Base64Encode::evaluate(std::string value, + Transaction *transaction) { + std::string ret = Utils::Base64::encode(value); + + return ret; +} + + +} // namespace transformations +} // namespace actions +} // namespace modsecurity diff --git a/src/actions/transformations/base64_encode.h b/src/actions/transformations/base64_encode.h new file mode 100644 index 00000000..0d47e7ad --- /dev/null +++ b/src/actions/transformations/base64_encode.h @@ -0,0 +1,45 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + +#include + +#include "actions/action.h" +#include "actions/transformations/transformation.h" + +#ifndef SRC_ACTIONS_TRANSFORMATIONS_BASE64_ENCODE_H_ +#define SRC_ACTIONS_TRANSFORMATIONS_BASE64_ENCODE_H_ + +#ifdef __cplusplus +namespace modsecurity { +class Transaction; + +namespace actions { +namespace transformations { + +class Base64Encode : public Transformation { + public: + explicit Base64Encode(std::string action) : Transformation(action) { }; + + std::string evaluate(std::string exp, + Transaction *transaction) override; +}; + +} // namespace transformations +} // namespace actions +} // namespace modsecurity + +#endif + +#endif // SRC_ACTIONS_TRANSFORMATIONS_BASE64_ENCODE_H_ diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index ae22f90a..8e6d3649 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -24,6 +24,7 @@ #include "actions/action.h" #include "actions/transformations/base64_decode_ext.h" #include "actions/transformations/base64_decode.h" +#include "actions/transformations/base64_encode.h" #include "actions/transformations/cmd_line.h" #include "actions/transformations/compress_whitespace.h" #include "actions/transformations/css_decode.h" @@ -75,6 +76,7 @@ std::string Transformation::evaluate(std::string value, Transformation* Transformation::instantiate(std::string a) { IF_MATCH(base64_decode_ext) { return new Base64DecodeExt(a); } IF_MATCH(base64Decode) { return new Base64Decode(a); } + IF_MATCH(base64Encode) { return new Base64Encode(a); } IF_MATCH(cmd_line) { return new CmdLine(a); } IF_MATCH(compress_whitespace) { return new CompressWhitespace(a); } IF_MATCH(cssDecode) { return new CssDecode(a); }