Open dzonerzy opened 2 years ago
The fuzzer won't be able to brute-force 32 bit values, usually. You can try to hand the values as token/dictionary to AFL and it should work. Alternatively, switch to QEMU mode and use complog or wait for upstream unicorn to fix CMP hooks, cc @wtdcode
Could you have a retry now?
Sure I'll let you know once tested.
I tried after updating I'm having a different issue now, here's the code:
import os
import sys
from qiling import Qiling
from qiling.const import QL_VERBOSE
from qiling.extensions.afl import ql_afl_fuzz
def start_afl(ql: Qiling, user_data):
def place_input_callback(_ql: Qiling, fuzzed: bytes, persistent_round: int):
size = len(fuzzed)
mem = _ql.reg.read("r0") # here r0 should point to buffer, instead I get 0, seems like uc context is lost
_ql.reg.write("r1", size)
_ql.mem.write(mem, fuzzed)
return True
try:
ql_afl_fuzz(ql, input_file=user_data, place_input_callback=place_input_callback, exits=[ql.os.exit_point])
except:
os.abort()
def emulate(binary, rootfs, fuzzed_binary):
ql = Qiling(binary, rootfs, verbose=QL_VERBOSE.DEBUG)
ql.restore(snapshot="./snap.bin")
ql.hook_address(start_afl, 0x00010b30, user_data=fuzzed_binary)
ql.emu_start(begin=0x00010b30, end=0x0010b34)
if __name__ == "__main__":
emulate(["./test", "./pier"], "./rootfs", sys.argv[1])
Inside the place_input_callback callback the Qiling context seems wrong, in fact r0 register inside the start_afl callback point to the buffer while inside the place_input_callback is zero. That wasn't happening with the previous version. cc @wtdcode
Any updates on this?
I have a bug I think is related. I have a very dumb target (see below) I compiled in ARM and try to fuzz with afl-unicorn.
int parse(char* p_buf, size_t d_len) {
if (d_len < 8) return -1;
uint64_t in = *((uint64_t*)p_buf);
if (in == 0x4041424344454647) {
// SEGFAULT;
int* a = 0;
*a = 0;
return 100;
}
return 0;
}
Unfortunately, no matter how long I fuzz this I only have two edges (<8 and >=8 length). I patched the cmplog hooks to check if they were executed at all and nope. They are not.
So, yeah it confirms what @domenukk said: seems like CMP hooks don't work on ARM in unicorn. Any idea / reference I can rely on to fix this? Perhaps it is fixed in current mainstream unicorn?
Thanks for reaching out. I have no idea at this moment and need further investigation.
From: FuzzTheWorld @.> Sent: Tuesday, November 12, 2024 1:42:20 AM To: AFLplusplus/unicornafl @.> Cc: lazymio @.>; Assign @.> Subject: Re: [AFLplusplus/unicornafl] Qiling + unicornafl seems like can't find an easy integer overflow (Issue #4)
I have a bug I think is related. I have a very dumb target (see below) I compiled in ARM and try to fuzz with afl-unicorn.
`int parse(char p_buf, size_t d_len) { if (d_len < 8) return -1; uint64_t in = ((uint64_t)p_buf); if (in == 0x4041424344454647) { // SEGFAULT; int a = 0; *a = 0;
return 100;
} return 0;
}`
Unfortunately, no matter how long I fuzz this I only have two edges (<8 and >=8 length). I patched the cmplog hooks to check if they were executed at all and nope. They are not.
So, yeah it confirms what @domenukkhttps://github.com/domenukk said: seems like CMP hooks don't work on ARM in unicorn. Any idea / reference I can rely on to fix this? Perhaps it is fixed in current mainstream unicorn?
― Reply to this email directly, view it on GitHubhttps://github.com/AFLplusplus/unicornafl/issues/4#issuecomment-2468715093, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHJULOYLSP6HXFQWBWQ6SAT2ADT7ZAVCNFSM6AAAAABRSKIIJWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRYG4YTKMBZGM. You are receiving this because you were assigned.Message ID: @.***>
Basically i created a vulnerable binary and linked it against uclib-ng (arm-eabihf), below the source code:
Then i created a simple qiling script which make first a snapshot the use the snapshot to fuzz the parsing function
Anyway seems like after 5 completed cycles it still can't find the vulnerable path, while forcing it into place_input_callback just works fine and make afl register the crash.
I run afl with
AFL_DEBUG=1 afl-fuzz -D -U -i input/ -o output/ -- python3 main.py @@
test-arm.tar.gz