mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-19 10:44:25 +03:00
Adds support to the transformations parity[even|odd|zero]7bit
Issues: #968, #969, #967
This commit is contained in:
@@ -30,25 +30,52 @@ namespace modsecurity {
|
||||
namespace actions {
|
||||
namespace transformations {
|
||||
|
||||
ParityEven7bit::ParityEven7bit(std::string action)
|
||||
: Transformation(action) {
|
||||
this->action_kind = 1;
|
||||
}
|
||||
|
||||
std::string ParityEven7bit::evaluate(std::string value,
|
||||
Transaction *transaction) {
|
||||
/**
|
||||
* @todo Implement the transformation ParityEven7bit
|
||||
*/
|
||||
if (transaction) {
|
||||
#ifndef NO_LOGS
|
||||
transaction->debug(4, "Transformation ParityEven7bit is not" \
|
||||
" implemented yet.");
|
||||
#endif
|
||||
std::string ret;
|
||||
unsigned char *input = NULL;
|
||||
|
||||
input = reinterpret_cast<unsigned char *>
|
||||
(malloc(sizeof(char) * value.length()+1));
|
||||
|
||||
if (input == NULL) {
|
||||
return "";
|
||||
}
|
||||
return value;
|
||||
|
||||
memcpy(input, value.c_str(), value.length()+1);
|
||||
|
||||
inplace(input, value.length());
|
||||
|
||||
ret.assign(reinterpret_cast<char *>(input), value.length());
|
||||
free(input);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ParityEven7bit::inplace(unsigned char *input, u_int64_t input_len) {
|
||||
u_int64_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < input_len) {
|
||||
unsigned int x = input[i];
|
||||
|
||||
input[i] ^= input[i] >> 4;
|
||||
input[i] &= 0xf;
|
||||
|
||||
if ((0x6996 >> input[i]) & 1) {
|
||||
input[i] = x | 0x80;
|
||||
} else {
|
||||
input[i] = x & 0x7f;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace transformations
|
||||
} // namespace actions
|
||||
} // namespace modsecurity
|
||||
|
||||
Reference in New Issue
Block a user