mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Add parity transformations. See #516.
This commit is contained in:
@@ -477,6 +477,101 @@ static int msre_fn_normalisePathWin_execute(apr_pool_t *mptmp, unsigned char *in
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* parityEven7bit */
|
||||
|
||||
static int msre_fn_parityEven7bit_execute(apr_pool_t *mptmp, unsigned char *input,
|
||||
long int input_len, char **rval, long int *rval_len)
|
||||
{
|
||||
long int i;
|
||||
int changed = 0;
|
||||
|
||||
if (rval == NULL) return -1;
|
||||
*rval = NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (x != input[i]) changed = 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
*rval = (char *)input;
|
||||
*rval_len = input_len;
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* parityZero7bit */
|
||||
|
||||
static int msre_fn_parityZero7bit_execute(apr_pool_t *mptmp, unsigned char *input,
|
||||
long int input_len, char **rval, long int *rval_len)
|
||||
{
|
||||
long int i;
|
||||
int changed = 0;
|
||||
|
||||
if (rval == NULL) return -1;
|
||||
*rval = NULL;
|
||||
|
||||
i = 0;
|
||||
while(i < input_len) {
|
||||
unsigned char c = input[i];
|
||||
input[i] &= 0x7f;
|
||||
if (c != input[i]) changed = 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
*rval = (char *)input;
|
||||
*rval_len = input_len;
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* parityOdd7bit */
|
||||
|
||||
static int msre_fn_parityOdd7bit_execute(apr_pool_t *mptmp, unsigned char *input,
|
||||
long int input_len, char **rval, long int *rval_len)
|
||||
{
|
||||
long int i;
|
||||
int changed = 0;
|
||||
|
||||
if (rval == NULL) return -1;
|
||||
*rval = NULL;
|
||||
|
||||
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 & 0x7f;
|
||||
}
|
||||
else {
|
||||
input[i] = x | 0x80;
|
||||
}
|
||||
|
||||
if (x != input[i]) changed = 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
*rval = (char *)input;
|
||||
*rval_len = input_len;
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
@@ -597,6 +692,24 @@ void msre_engine_register_default_tfns(msre_engine *engine) {
|
||||
msre_fn_normalisePathWin_execute
|
||||
);
|
||||
|
||||
/* parityEven7bit */
|
||||
msre_engine_tfn_register(engine,
|
||||
"parityEven7bit",
|
||||
msre_fn_parityEven7bit_execute
|
||||
);
|
||||
|
||||
/* parityZero7bit */
|
||||
msre_engine_tfn_register(engine,
|
||||
"parityZero7bit",
|
||||
msre_fn_parityZero7bit_execute
|
||||
);
|
||||
|
||||
/* parityOdd7bit */
|
||||
msre_engine_tfn_register(engine,
|
||||
"parityOdd7bit",
|
||||
msre_fn_parityOdd7bit_execute
|
||||
);
|
||||
|
||||
/* removeWhitespace */
|
||||
msre_engine_tfn_register(engine,
|
||||
"removeWhitespace",
|
||||
|
34
apache2/t/tfn/parityEven7bit.t
Normal file
34
apache2/t/tfn/parityEven7bit.t
Normal file
@@ -0,0 +1,34 @@
|
||||
### Empty
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityEven7bit",
|
||||
input => "",
|
||||
output => "",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### Nothing
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityEven7bit",
|
||||
input => "cefijloqrtwx03569ABDGHKMNPSUVYZ",
|
||||
output => "cefijloqrtwx03569ABDGHKMNPSUVYZ",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### Parity
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityEven7bit",
|
||||
input => "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
output => "\xe1\xe2c\xe4ef\xe7\xe8ij\xebl\xed\xeeo\xf0qr\xf3t\xf5\xf6wx\xf9\xfa0\xb1\xb23\xb456\xb7\xb89AB\xc3D\xc5\xc6GH\xc9\xcaK\xccMN\xcfP\xd1\xd2S\xd4UV\xd7\xd8YZ",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityEven7bit",
|
||||
input => "abcdefghijklmnopqrstuvwxyz\x000123456789\x00ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
output => "\xe1\xe2c\xe4ef\xe7\xe8ij\xebl\xed\xeeo\xf0qr\xf3t\xf5\xf6wx\xf9\xfa\x000\xb1\xb23\xb456\xb7\xb89\x00AB\xc3D\xc5\xc6GH\xc9\xcaK\xccMN\xcfP\xd1\xd2S\xd4UV\xd7\xd8YZ",
|
||||
ret => 1,
|
||||
},
|
||||
|
34
apache2/t/tfn/parityOdd7bit.t
Normal file
34
apache2/t/tfn/parityOdd7bit.t
Normal file
@@ -0,0 +1,34 @@
|
||||
### Empty
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityOdd7bit",
|
||||
input => "",
|
||||
output => "",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### Nothing
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityOdd7bit",
|
||||
input => "abdghkmnpsuvyz12478CEFIJLOQRTW",
|
||||
output => "abdghkmnpsuvyz12478CEFIJLOQRTW",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### Parity
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityOdd7bit",
|
||||
input => "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
output => "ab\xe3d\xe5\xe6gh\xe9\xeak\xecmn\xefp\xf1\xf2s\xf4uv\xf7\xf8yz\xb012\xb34\xb5\xb678\xb9\xc1\xc2C\xc4EF\xc7\xc8IJ\xcbL\xcd\xceO\xd0QR\xd3T\xd5\xd6WX\xd9\xda",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityOdd7bit",
|
||||
input => "abcdefghijklmnopqrstuvwxyz\x000123456789\x00ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
output => "ab\xe3d\xe5\xe6gh\xe9\xeak\xecmn\xefp\xf1\xf2s\xf4uv\xf7\xf8yz\x80\xb012\xb34\xb5\xb678\xb9\x80\xc1\xc2C\xc4EF\xc7\xc8IJ\xcbL\xcd\xceO\xd0QR\xd3T\xd5\xd6WX\xd9\xda",
|
||||
ret => 1,
|
||||
},
|
||||
|
33
apache2/t/tfn/parityZero7bit.t
Normal file
33
apache2/t/tfn/parityZero7bit.t
Normal file
@@ -0,0 +1,33 @@
|
||||
### Empty
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityZero7bit",
|
||||
input => "",
|
||||
output => "",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### Nothing
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityZero7bit",
|
||||
input => "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
output => "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityZero7bit",
|
||||
input => "abcdefghijklmnopqrstuvwxyz\x000123456789\x00ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
output => "abcdefghijklmnopqrstuvwxyz\x000123456789\x00ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### Basic
|
||||
{
|
||||
type => "tfn",
|
||||
name => "parityZero7bit",
|
||||
input => "\x80\x00\x8f\xff",
|
||||
output => "\x00\x00\x0f\x7f",
|
||||
ret => 1,
|
||||
},
|
Reference in New Issue
Block a user