Loading extra dictionary fails
I try to us a dictionary but I get an error message:
C:\winafl\build32\Debug>afl-fuzz.exe -x dict -i in -o out -D C:\DynamoRIO-Windows-6.2.0-2\bin32 -t 2000 -- -coverage_module test.exe -fuzz_iteration s 1000 -target_module test.exe -target_offset 0x31A80 -nargs 2 -- test.exe @@
WinAFL 1.02 by [email protected] Based on AFL 1.96b by [email protected] [] Setting up output directories... [+] Output directory exists but deemed OK to reuse. [] Deleting old session data... [+] Output dir cleanup successful. [] Scanning 'in'... [+] No auto-generated dictionary tokens to reuse. [] Creating hard links for all input files... [*] Loading extra dictionary from 'dict' (level 0)...
[-] SYSTEM ERROR : Unable to access 'dict\test.txt' Stop location : load_extras(), C:\winafl\afl-fuzz.c:1636 OS message : No such file or directory
I created a file in the dict directory but it seems that WinAFL is looking for test.txt which is the input file ... What I'm doing wrong ?
You might be able to work around this by injecting them into a resumed session. I don't think it will matter much if this is done early in the fuzzing process.
- quickly run a session and generate the output directory structure
- place the raw tokens as separate files in \o\queue.state\auto_extras
- rename the files with this batch script if necessary:
@echo off
SET COUNT=0
setlocal EnableDelayedExpansion
SET PREFIX=auto
FOR /f "tokens=*" %%G IN ('dir /b *') DO (call :renum "%%G")
GOTO :eof
:renum
set "formattedValue=000000%count%"
ren %1 %PREFIX%_!formattedValue:~-6!
set /a count+=1
GOTO :eof
- resume the session by specifying a dash instead of an input dir ( e.g. "-o ./outdir -i - ")
don't forget to back up your results often
Admittedly I didn't do a lot of testing with dictionaries because I didn't use them myself so it's possible there are bugs with this. I'll take a look at this when I can find some spare cycles. Meanwhile, If you can point out the bug in the code it would be highly appreciated.
@mrpeppels or anyone else - Was -x working for you?
There are two bugs.
The first is in the load_extras function in afl-fuzz.c
It uses in_dir instead of dir
Actual:
static void load_extras(u8* dir) {
WIN32_FIND_DATA fdata;
HANDLE h;
u32 min_len = MAX_DICT_FILE, max_len = 0, dict_level = 0;
u8* x;
char *pattern;
if(in_dir[strlen(in_dir)-1] == '\\') {
pattern = alloc_printf("%s*", in_dir);
} else {
pattern = alloc_printf("%s\\*", in_dir);
}...
Fixed:
static void load_extras(u8* dir) {
WIN32_FIND_DATA fdata;
HANDLE h;
u32 min_len = MAX_DICT_FILE, max_len = 0, dict_level = 0;
u8* x;
char *pattern;
if(dir[strlen(dir)-1] == '\\') {
pattern = alloc_printf("%s*", dir);
} else {
pattern = alloc_printf("%s\\*", dir);
}...
The second bug is the MAX_DICT_FILE which is too litle -> By increasing this constant allows you to read dictionary files greater than 128 Bytes ;-)
Awesome! Thanks for spotting this! I had to change directory listing in several places due to different APIs on Linux and Windows and I must have copy-pasted this from another place and forgot to change the variable name. I just released the updated version with the fix.
MAX_DICT_FILE is the same as in linux AFL and I think it might be deliberate to limit the maximum size of a dictionary token.