|
|
|
@ -571,7 +571,6 @@ static u8 its_fuzz(afl_state_t *afl, u8 *buf, u32 len, u8 *status) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #ifdef CMPLOG_SOLVE_TRANSFORM
|
|
|
|
|
static int strntoll(const char *str, size_t sz, char **end, int base,
|
|
|
|
|
long long *out) {
|
|
|
|
|
|
|
|
|
@ -656,7 +655,6 @@ static int is_hex(const char *str) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef CMPLOG_SOLVE_TRANSFORM_BASE64
|
|
|
|
|
// tests 4 bytes at location
|
|
|
|
|
static int is_base64(const char *str) {
|
|
|
|
|
|
|
|
|
@ -769,10 +767,6 @@ static void to_base64(u8 *src, u8 *dst, u32 dst_len) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
static u8 cmp_extend_encoding(afl_state_t *afl, struct cmp_header *h,
|
|
|
|
|
u64 pattern, u64 repl, u64 o_pattern,
|
|
|
|
|
u64 changed_val, u8 attr, u32 idx, u32 taint_len,
|
|
|
|
@ -797,42 +791,54 @@ static u8 cmp_extend_encoding(afl_state_t *afl, struct cmp_header *h,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fprintf(stderr,
|
|
|
|
|
// "Encode: %llx->%llx into %llx(<-%llx) at idx=%u "
|
|
|
|
|
// "taint_len=%u shape=%u attr=%u\n",
|
|
|
|
|
// o_pattern, pattern, repl, changed_val, idx, taint_len,
|
|
|
|
|
// hshape, attr);
|
|
|
|
|
/*
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Encode: %llx->%llx into %llx(<-%llx) at idx=%u "
|
|
|
|
|
"taint_len=%u shape=%u attr=%u\n",
|
|
|
|
|
o_pattern, pattern, repl, changed_val, idx, taint_len,
|
|
|
|
|
hshape, attr);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// #ifdef CMPLOG_SOLVE_TRANSFORM
|
|
|
|
|
// reverse atoi()/strnu?toll() is expensive, so we only to it in lvl 3
|
|
|
|
|
if (afl->cmplog_enable_transform && (lvl & LVL3)) {
|
|
|
|
|
|
|
|
|
|
u8 *endptr;
|
|
|
|
|
u8 use_num = 0, use_unum = 0;
|
|
|
|
|
unsigned long long unum;
|
|
|
|
|
long long num;
|
|
|
|
|
unsigned long long unum = 0;
|
|
|
|
|
long long num = 0;
|
|
|
|
|
|
|
|
|
|
if (afl->queue_cur->is_ascii) {
|
|
|
|
|
// if (afl->queue_cur->is_ascii) {
|
|
|
|
|
|
|
|
|
|
// we first check if our input are ascii numbers that are transformed to
|
|
|
|
|
// an integer and used for comparison:
|
|
|
|
|
|
|
|
|
|
endptr = buf_8;
|
|
|
|
|
if (strntoll(buf_8, len - idx, (char **)&endptr, 0, &num)) {
|
|
|
|
|
|
|
|
|
|
if (!strntoull(buf_8, len - idx, (char **)&endptr, 0, &unum))
|
|
|
|
|
if (!strntoull(buf_8, len - idx, (char **)&endptr, 0, &unum)) {
|
|
|
|
|
|
|
|
|
|
use_unum = 1;
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
use_num = 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
if (idx == 0)
|
|
|
|
|
fprintf(stderr, "ASCII is=%u use_num=%u use_unum=%u idx=%u %llx==%llx\n",
|
|
|
|
|
afl->queue_cur->is_ascii, use_num, use_unum, idx, num, pattern);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"ASCII is=%u use_num=%u>%lld use_unum=%u>%llu idx=%u "
|
|
|
|
|
"pattern=0x%llx\n",
|
|
|
|
|
afl->queue_cur->is_ascii, use_num, num, use_unum, unum, idx,
|
|
|
|
|
pattern);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// num is likely not pattern as atoi("AAA") will be zero...
|
|
|
|
|
// atoi("AAA") == 0 so !num means we have to investigate
|
|
|
|
|
if (use_num && ((u64)num == pattern || !num)) {
|
|
|
|
|
|
|
|
|
|
u8 tmp_buf[32];
|
|
|
|
@ -961,10 +967,12 @@ static u8 cmp_extend_encoding(afl_state_t *afl, struct cmp_header *h,
|
|
|
|
|
// test for arithmetic, eg. "if ((user_val - 0x1111) == 0x1234) ..."
|
|
|
|
|
s64 diff = pattern - b_val;
|
|
|
|
|
s64 o_diff = o_pattern - o_b_val;
|
|
|
|
|
/* fprintf(stderr, "DIFF1 idx=%03u shape=%02u %llx-%llx=%lx\n", idx,
|
|
|
|
|
/*
|
|
|
|
|
fprintf(stderr, "DIFF1 idx=%03u shape=%02u %llx-%llx=%lx\n", idx,
|
|
|
|
|
hshape, o_pattern, o_b_val, o_diff);
|
|
|
|
|
fprintf(stderr, "DIFF1 %016llx %llx-%llx=%lx\n", repl, pattern,
|
|
|
|
|
b_val, diff); */
|
|
|
|
|
b_val, diff);
|
|
|
|
|
*/
|
|
|
|
|
if (diff == o_diff && diff) {
|
|
|
|
|
|
|
|
|
|
// this could be an arithmetic transformation
|
|
|
|
@ -1275,7 +1283,6 @@ static u8 cmp_extend_encoding(afl_state_t *afl, struct cmp_header *h,
|
|
|
|
|
// 16 = modified float, 32 = modified integer (modified = wont match
|
|
|
|
|
// in original buffer)
|
|
|
|
|
|
|
|
|
|
// #ifdef CMPLOG_SOLVE_ARITHMETIC
|
|
|
|
|
if (!afl->cmplog_enable_arith || lvl < LVL3 || attr == IS_TRANSFORM) {
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
@ -2009,8 +2016,12 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
its_len = MIN(its_len, taint_len);
|
|
|
|
|
u32 saved_its_len = its_len;
|
|
|
|
|
|
|
|
|
|
if (its_len <= 1) { return 0; }
|
|
|
|
|
|
|
|
|
|
if (lvl & LVL3) {
|
|
|
|
|
|
|
|
|
|
if (memcmp(changed_val, repl, its_len) != 0) { return 0; }
|
|
|
|
|
|
|
|
|
|
u32 max_to = MIN(4U, idx);
|
|
|
|
|
if (!(lvl & LVL1) && max_to) { from = 1; }
|
|
|
|
|
to = max_to;
|
|
|
|
@ -2089,9 +2100,7 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
if (afl->cmplog_enable_transform && (lvl & LVL3)) {
|
|
|
|
|
|
|
|
|
|
u32 toupper = 0, tolower = 0, xor = 0, arith = 0, tohex = 0, fromhex = 0;
|
|
|
|
|
#ifdef CMPLOG_SOLVE_TRANSFORM_BASE64
|
|
|
|
|
u32 tob64 = 0, fromb64 = 0;
|
|
|
|
|
#endif
|
|
|
|
|
u32 from_0 = 0, from_x = 0, from_X = 0, from_slash = 0, from_up = 0;
|
|
|
|
|
u32 to_0 = 0, to_x = 0, to_slash = 0, to_up = 0;
|
|
|
|
|
u8 xor_val[32], arith_val[32], tmp[48];
|
|
|
|
@ -2144,7 +2153,8 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i < 16 && is_hex(repl + (i << 1))) {
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform && i < 16 &&
|
|
|
|
|
is_hex(repl + (i << 1))) {
|
|
|
|
|
|
|
|
|
|
++tohex;
|
|
|
|
|
|
|
|
|
@ -2163,7 +2173,7 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((i % 2)) {
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform && (i % 2)) {
|
|
|
|
|
|
|
|
|
|
if (len > idx + i + 1 && is_hex(orig_buf + idx + i)) {
|
|
|
|
|
|
|
|
|
@ -2187,7 +2197,8 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef CMPLOG_SOLVE_TRANSFORM_BASE64
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform) {
|
|
|
|
|
|
|
|
|
|
if (i % 3 == 2 && i < 24) {
|
|
|
|
|
|
|
|
|
|
if (is_base64(repl + ((i / 3) << 2))) tob64 += 3;
|
|
|
|
@ -2200,7 +2211,7 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((o_pattern[i] ^ orig_buf[idx + i]) == xor_val[i] && xor_val[i]) {
|
|
|
|
|
|
|
|
|
@ -2229,19 +2240,24 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
fprintf(stderr, "RTN %s %s %s %s\n", buf, pattern, orig_buf, o_pattern);
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"RTN idx=%u loop=%u xor=%u arith=%u tolower=%u toupper=%u "
|
|
|
|
|
"RTN idx=%u len=%u loop=%u xor=%u arith=%u tolower=%u toupper=%u "
|
|
|
|
|
"tohex=%u fromhex=%u to_0=%u to_slash=%u to_x=%u "
|
|
|
|
|
"from_0=%u from_slash=%u from_x=%u\n",
|
|
|
|
|
idx, i, xor, arith, tolower, toupper, tohex, fromhex, to_0,
|
|
|
|
|
to_slash, to_x, from_0, from_slash, from_x);
|
|
|
|
|
#ifdef CMPLOG_SOLVE_TRANSFORM_BASE64
|
|
|
|
|
fprintf(stderr, "RTN idx=%u loop=%u tob64=%u from64=%u\n", tob64,
|
|
|
|
|
fromb64);
|
|
|
|
|
#endif
|
|
|
|
|
idx, its_len, i, xor, arith, tolower, toupper, tohex, fromhex,
|
|
|
|
|
to_0, to_slash, to_x, from_0, from_slash, from_x);
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform) {
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "RTN idx=%u loop=%u tob64=%u from64=%u\n", idx, i,
|
|
|
|
|
tob64, fromb64);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef CMPLOG_SOLVE_TRANSFORM_BASE64
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform) {
|
|
|
|
|
|
|
|
|
|
// input is base64 and converted to binary? convert repl to base64!
|
|
|
|
|
if ((i % 4) == 3 && i < 24 && fromb64 > i) {
|
|
|
|
|
|
|
|
|
@ -2264,10 +2280,10 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// input is converted to hex? convert repl to binary!
|
|
|
|
|
if (i < 16 && tohex > i) {
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform && i < 16 && tohex > i) {
|
|
|
|
|
|
|
|
|
|
u32 off;
|
|
|
|
|
if (to_slash + to_x + to_0 == 2) {
|
|
|
|
@ -2292,8 +2308,8 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// input is hex and converted to binary? convert repl to hex!
|
|
|
|
|
if (i && (i % 2) && i < 16 && fromhex &&
|
|
|
|
|
fromhex + from_slash + from_x + from_0 > i) {
|
|
|
|
|
if (afl->cmplog_enable_xtreme_transform && i && (i % 2) && i < 16 &&
|
|
|
|
|
fromhex && fromhex + from_slash + from_x + from_0 > i) {
|
|
|
|
|
|
|
|
|
|
u8 off = 0;
|
|
|
|
|
if (from_slash && from_x) {
|
|
|
|
@ -2401,11 +2417,9 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
if ((i >= 7 &&
|
|
|
|
|
(i >= xor&&i >= arith &&i >= tolower &&i >= toupper &&i > tohex &&i >
|
|
|
|
|
(fromhex + from_0 + from_x + from_slash + 1)
|
|
|
|
|
#ifdef CMPLOG_SOLVE_TRANSFORM_BASE64
|
|
|
|
|
&& i > tob64 + 3 && i > fromb64 + 4
|
|
|
|
|
#endif
|
|
|
|
|
)) ||
|
|
|
|
|
(fromhex + from_0 + from_x + from_slash + 1) &&
|
|
|
|
|
(afl->cmplog_enable_xtreme_transform && i > tob64 + 3 &&
|
|
|
|
|
i > fromb64 + 4))) ||
|
|
|
|
|
repl[i] != changed_val[i] || *status == 1) {
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
@ -2418,8 +2432,6 @@ static u8 rtn_extend_encoding(afl_state_t *afl, u8 entry,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -2818,12 +2830,7 @@ u8 input_to_state_stage(afl_state_t *afl, u8 *orig_buf, u8 *buf, u32 len) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if ((lvl & LVL1)
|
|
|
|
|
|
|
|
|
|
// #ifdef CMPLOG_SOLVE_TRANSFORM
|
|
|
|
|
|| ((lvl & LVL3) && afl->cmplog_enable_transform)
|
|
|
|
|
// #endif
|
|
|
|
|
) {
|
|
|
|
|
} else if ((lvl & LVL1) || ((lvl & LVL3) && afl->cmplog_enable_transform)) {
|
|
|
|
|
|
|
|
|
|
if (unlikely(rtn_fuzz(afl, k, orig_buf, buf, cbuf, len, lvl, taint))) {
|
|
|
|
|
|
|
|
|
|