1*08b48e0bSAndroid Build Coastguard Worker# Environment variables 2*08b48e0bSAndroid Build Coastguard Worker 3*08b48e0bSAndroid Build Coastguard Worker This document discusses the environment variables used by AFL++ to expose 4*08b48e0bSAndroid Build Coastguard Worker various exotic functions that may be (rarely) useful for power users or for 5*08b48e0bSAndroid Build Coastguard Worker some types of custom fuzzing setups. For general information about AFL++, see 6*08b48e0bSAndroid Build Coastguard Worker [README.md](../README.md). 7*08b48e0bSAndroid Build Coastguard Worker 8*08b48e0bSAndroid Build Coastguard Worker Note: Most tools will warn on any unknown AFL++ environment variables; for 9*08b48e0bSAndroid Build Coastguard Worker example, because of typos. If you want to disable this check, then set the 10*08b48e0bSAndroid Build Coastguard Worker `AFL_IGNORE_UNKNOWN_ENVS` environment variable. 11*08b48e0bSAndroid Build Coastguard Worker 12*08b48e0bSAndroid Build Coastguard Worker## 1) Settings for all compilers 13*08b48e0bSAndroid Build Coastguard Worker 14*08b48e0bSAndroid Build Coastguard WorkerStarting with AFL++ 3.0, there is only one compiler: afl-cc. 15*08b48e0bSAndroid Build Coastguard Worker 16*08b48e0bSAndroid Build Coastguard WorkerTo select the different instrumentation modes, use one of the following options: 17*08b48e0bSAndroid Build Coastguard Worker 18*08b48e0bSAndroid Build Coastguard Worker - Pass the --afl-MODE command-line option to the compiler. Only this option 19*08b48e0bSAndroid Build Coastguard Worker accepts further AFL-specific command-line options. 20*08b48e0bSAndroid Build Coastguard Worker - Use a symlink to afl-cc: afl-clang, afl-clang++, afl-clang-fast, 21*08b48e0bSAndroid Build Coastguard Worker afl-clang-fast++, afl-clang-lto, afl-clang-lto++, afl-g++, afl-g++-fast, 22*08b48e0bSAndroid Build Coastguard Worker afl-gcc, afl-gcc-fast. This option does not accept AFL-specific command-line 23*08b48e0bSAndroid Build Coastguard Worker options. Instead, use environment variables. 24*08b48e0bSAndroid Build Coastguard Worker - Use the `AFL_CC_COMPILER` environment variable with `MODE`. To select 25*08b48e0bSAndroid Build Coastguard Worker `MODE`, use one of the following values: 26*08b48e0bSAndroid Build Coastguard Worker 27*08b48e0bSAndroid Build Coastguard Worker - `GCC` (afl-gcc/afl-g++) 28*08b48e0bSAndroid Build Coastguard Worker - `GCC_PLUGIN` (afl-g*-fast) 29*08b48e0bSAndroid Build Coastguard Worker - `LLVM` (afl-clang-fast*) 30*08b48e0bSAndroid Build Coastguard Worker - `LTO` (afl-clang-lto*). 31*08b48e0bSAndroid Build Coastguard Worker 32*08b48e0bSAndroid Build Coastguard WorkerThe compile-time tools do not accept AFL-specific command-line options. The 33*08b48e0bSAndroid Build Coastguard Worker--afl-MODE command line option is the only exception. The other options make 34*08b48e0bSAndroid Build Coastguard Workerfairly broad use of environment variables instead: 35*08b48e0bSAndroid Build Coastguard Worker 36*08b48e0bSAndroid Build Coastguard Worker - Some build/configure scripts break with AFL++ compilers. To be able to pass 37*08b48e0bSAndroid Build Coastguard Worker them, do: 38*08b48e0bSAndroid Build Coastguard Worker 39*08b48e0bSAndroid Build Coastguard Worker ``` 40*08b48e0bSAndroid Build Coastguard Worker export CC=afl-cc 41*08b48e0bSAndroid Build Coastguard Worker export CXX=afl-c++ 42*08b48e0bSAndroid Build Coastguard Worker export AFL_NOOPT=1 43*08b48e0bSAndroid Build Coastguard Worker ./configure --disable-shared --disabler-werror 44*08b48e0bSAndroid Build Coastguard Worker unset AFL_NOOPT 45*08b48e0bSAndroid Build Coastguard Worker make 46*08b48e0bSAndroid Build Coastguard Worker ``` 47*08b48e0bSAndroid Build Coastguard Worker 48*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_AS`, `AFL_CC`, and `AFL_CXX` lets you use alternate downstream 49*08b48e0bSAndroid Build Coastguard Worker compilation tools, rather than the default 'as', 'clang', or 'gcc' binaries 50*08b48e0bSAndroid Build Coastguard Worker in your `$PATH`. 51*08b48e0bSAndroid Build Coastguard Worker 52*08b48e0bSAndroid Build Coastguard Worker - If you are a weird person that wants to compile and instrument asm text 53*08b48e0bSAndroid Build Coastguard Worker files, then use the `AFL_AS_FORCE_INSTRUMENT` variable: 54*08b48e0bSAndroid Build Coastguard Worker `AFL_AS_FORCE_INSTRUMENT=1 afl-gcc foo.s -o foo` 55*08b48e0bSAndroid Build Coastguard Worker 56*08b48e0bSAndroid Build Coastguard Worker - Most AFL tools do not print any output if stdout/stderr are redirected. If 57*08b48e0bSAndroid Build Coastguard Worker you want to get the output into a file, then set the `AFL_DEBUG` environment 58*08b48e0bSAndroid Build Coastguard Worker variable. This is sadly necessary for various build processes which fail 59*08b48e0bSAndroid Build Coastguard Worker otherwise. 60*08b48e0bSAndroid Build Coastguard Worker 61*08b48e0bSAndroid Build Coastguard Worker - By default, the wrapper appends `-O3` to optimize builds. Very rarely, this 62*08b48e0bSAndroid Build Coastguard Worker will cause problems in programs built with -Werror, because `-O3` enables 63*08b48e0bSAndroid Build Coastguard Worker more thorough code analysis and can spew out additional warnings. To disable 64*08b48e0bSAndroid Build Coastguard Worker optimizations, set `AFL_DONT_OPTIMIZE`. However, if `-O...` and/or 65*08b48e0bSAndroid Build Coastguard Worker `-fno-unroll-loops` are set, these are not overridden. 66*08b48e0bSAndroid Build Coastguard Worker 67*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_HARDEN` automatically adds code hardening options when invoking 68*08b48e0bSAndroid Build Coastguard Worker the downstream compiler. This currently includes `-D_FORTIFY_SOURCE=2` and 69*08b48e0bSAndroid Build Coastguard Worker `-fstack-protector-all`. The setting is useful for catching non-crashing 70*08b48e0bSAndroid Build Coastguard Worker memory bugs at the expense of a very slight (sub-5%) performance loss. 71*08b48e0bSAndroid Build Coastguard Worker 72*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_INST_RATIO` to a percentage between 0 and 100 controls the 73*08b48e0bSAndroid Build Coastguard Worker probability of instrumenting every branch. This is (very rarely) useful when 74*08b48e0bSAndroid Build Coastguard Worker dealing with exceptionally complex programs that saturate the output bitmap. 75*08b48e0bSAndroid Build Coastguard Worker Examples include ffmpeg, perl, and v8. 76*08b48e0bSAndroid Build Coastguard Worker 77*08b48e0bSAndroid Build Coastguard Worker (If this ever happens, afl-fuzz will warn you ahead of the time by 78*08b48e0bSAndroid Build Coastguard Worker displaying the "bitmap density" field in fiery red.) 79*08b48e0bSAndroid Build Coastguard Worker 80*08b48e0bSAndroid Build Coastguard Worker Setting `AFL_INST_RATIO` to 0 is a valid choice. This will instrument only 81*08b48e0bSAndroid Build Coastguard Worker the transitions between function entry points, but not individual branches. 82*08b48e0bSAndroid Build Coastguard Worker 83*08b48e0bSAndroid Build Coastguard Worker Note that this is an outdated variable. A few instances (e.g., afl-gcc) 84*08b48e0bSAndroid Build Coastguard Worker still support these, but state-of-the-art (e.g., LLVM LTO and LLVM PCGUARD) 85*08b48e0bSAndroid Build Coastguard Worker do not need this. 86*08b48e0bSAndroid Build Coastguard Worker 87*08b48e0bSAndroid Build Coastguard Worker - `AFL_NO_BUILTIN` causes the compiler to generate code suitable for use with 88*08b48e0bSAndroid Build Coastguard Worker libtokencap.so (but perhaps running a bit slower than without the flag). 89*08b48e0bSAndroid Build Coastguard Worker 90*08b48e0bSAndroid Build Coastguard Worker - `AFL_PATH` can be used to point afl-gcc to an alternate location of afl-as. 91*08b48e0bSAndroid Build Coastguard Worker One possible use of this is utils/clang_asm_normalize/, which lets you 92*08b48e0bSAndroid Build Coastguard Worker instrument hand-written assembly when compiling clang code by plugging a 93*08b48e0bSAndroid Build Coastguard Worker normalizer into the chain. (There is no equivalent feature for GCC.) 94*08b48e0bSAndroid Build Coastguard Worker 95*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_QUIET` will prevent afl-as and afl-cc banners from being 96*08b48e0bSAndroid Build Coastguard Worker displayed during compilation, in case you find them distracting. 97*08b48e0bSAndroid Build Coastguard Worker 98*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_USE_...` automatically enables supported sanitizers - provided 99*08b48e0bSAndroid Build Coastguard Worker that your compiler supports it. Available are: 100*08b48e0bSAndroid Build Coastguard Worker - `AFL_USE_ASAN=1` - activates the address sanitizer (memory corruption 101*08b48e0bSAndroid Build Coastguard Worker detection) 102*08b48e0bSAndroid Build Coastguard Worker - `AFL_USE_CFISAN=1` - activates the Control Flow Integrity sanitizer (e.g. 103*08b48e0bSAndroid Build Coastguard Worker type confusion vulnerabilities) 104*08b48e0bSAndroid Build Coastguard Worker - `AFL_USE_LSAN` - activates the leak sanitizer. To perform a leak check 105*08b48e0bSAndroid Build Coastguard Worker within your program at a certain point (such as at the end of an 106*08b48e0bSAndroid Build Coastguard Worker `__AFL_LOOP()`), you can run the macro `__AFL_LEAK_CHECK();` which will 107*08b48e0bSAndroid Build Coastguard Worker cause an abort if any memory is leaked (you can combine this with the 108*08b48e0bSAndroid Build Coastguard Worker `__AFL_LSAN_OFF();` and `__AFL_LSAN_ON();` macros to avoid checking for 109*08b48e0bSAndroid Build Coastguard Worker memory leaks from memory allocated between these two calls. 110*08b48e0bSAndroid Build Coastguard Worker - `AFL_USE_MSAN=1` - activates the memory sanitizer (uninitialized memory) 111*08b48e0bSAndroid Build Coastguard Worker - `AFL_USE_TSAN=1` - activates the thread sanitizer to find thread race 112*08b48e0bSAndroid Build Coastguard Worker conditions 113*08b48e0bSAndroid Build Coastguard Worker - `AFL_USE_UBSAN=1` - activates the undefined behavior sanitizer 114*08b48e0bSAndroid Build Coastguard Worker 115*08b48e0bSAndroid Build Coastguard Worker - `TMPDIR` is used by afl-as for temporary files; if this variable is not set, 116*08b48e0bSAndroid Build Coastguard Worker the tool defaults to /tmp. 117*08b48e0bSAndroid Build Coastguard Worker 118*08b48e0bSAndroid Build Coastguard Worker## 2) Settings for LLVM and LTO: afl-clang-fast / afl-clang-fast++ / afl-clang-lto / afl-clang-lto++ 119*08b48e0bSAndroid Build Coastguard Worker 120*08b48e0bSAndroid Build Coastguard WorkerThe native instrumentation helpers (instrumentation and gcc_plugin) accept a 121*08b48e0bSAndroid Build Coastguard Workersubset of the settings discussed in section 1, with the exception of: 122*08b48e0bSAndroid Build Coastguard Worker 123*08b48e0bSAndroid Build Coastguard Worker - `AFL_AS`, since this toolchain does not directly invoke GNU `as`. 124*08b48e0bSAndroid Build Coastguard Worker 125*08b48e0bSAndroid Build Coastguard Worker - `AFL_INST_RATIO`, as we use collision free instrumentation by default. Not 126*08b48e0bSAndroid Build Coastguard Worker all passes support this option though as it is an outdated feature. 127*08b48e0bSAndroid Build Coastguard Worker 128*08b48e0bSAndroid Build Coastguard Worker - LLVM modes support `AFL_LLVM_DICT2FILE=/absolute/path/file.txt` which will 129*08b48e0bSAndroid Build Coastguard Worker write all constant string comparisons to this file to be used later with 130*08b48e0bSAndroid Build Coastguard Worker afl-fuzz' `-x` option. 131*08b48e0bSAndroid Build Coastguard Worker 132*08b48e0bSAndroid Build Coastguard Worker - An option to `AFL_LLVM_DICT2FILE` is `AFL_LLVM_DICT2FILE_NO_MAIN=1` which 133*08b48e0bSAndroid Build Coastguard Worker skill not parse `main()`. 134*08b48e0bSAndroid Build Coastguard Worker 135*08b48e0bSAndroid Build Coastguard Worker - `TMPDIR` and `AFL_KEEP_ASSEMBLY`, since no temporary assembly files are 136*08b48e0bSAndroid Build Coastguard Worker created. 137*08b48e0bSAndroid Build Coastguard Worker 138*08b48e0bSAndroid Build Coastguard Worker - LLVM modes compiling C++ will normally set rpath in the binary if LLVM is 139*08b48e0bSAndroid Build Coastguard Worker not in a usual location (/usr or /lib). Setting `AFL_LLVM_NO_RPATH=1` 140*08b48e0bSAndroid Build Coastguard Worker disables this behaviour in case it isn't desired. For example, the compiling 141*08b48e0bSAndroid Build Coastguard Worker toolchain might be in a custom location, but the target machine has LLVM 142*08b48e0bSAndroid Build Coastguard Worker runtime libs in the search path. 143*08b48e0bSAndroid Build Coastguard Worker 144*08b48e0bSAndroid Build Coastguard WorkerThen there are a few specific features that are only available in 145*08b48e0bSAndroid Build Coastguard Workerinstrumentation mode: 146*08b48e0bSAndroid Build Coastguard Worker 147*08b48e0bSAndroid Build Coastguard Worker### Select the instrumentation mode 148*08b48e0bSAndroid Build Coastguard Worker 149*08b48e0bSAndroid Build Coastguard Worker`AFL_LLVM_INSTRUMENT` - this configures the instrumentation mode. 150*08b48e0bSAndroid Build Coastguard Worker 151*08b48e0bSAndroid Build Coastguard WorkerAvailable options: 152*08b48e0bSAndroid Build Coastguard Worker 153*08b48e0bSAndroid Build Coastguard Worker - CLANG - outdated clang instrumentation 154*08b48e0bSAndroid Build Coastguard Worker - CLASSIC - classic AFL (map[cur_loc ^ prev_loc >> 1]++) (default) 155*08b48e0bSAndroid Build Coastguard Worker 156*08b48e0bSAndroid Build Coastguard Worker You can also specify CTX and/or NGRAM, separate the options with a comma "," 157*08b48e0bSAndroid Build Coastguard Worker then, e.g.: `AFL_LLVM_INSTRUMENT=CLASSIC,CTX,NGRAM-4` 158*08b48e0bSAndroid Build Coastguard Worker 159*08b48e0bSAndroid Build Coastguard Worker Note: It is actually not a good idea to use both CTX and NGRAM. :) 160*08b48e0bSAndroid Build Coastguard Worker - CTX - context sensitive instrumentation 161*08b48e0bSAndroid Build Coastguard Worker - GCC - outdated gcc instrumentation 162*08b48e0bSAndroid Build Coastguard Worker - LTO - LTO instrumentation 163*08b48e0bSAndroid Build Coastguard Worker - NATIVE - clang's original pcguard based instrumentation 164*08b48e0bSAndroid Build Coastguard Worker - NGRAM-x - deeper previous location coverage (from NGRAM-2 up to NGRAM-16) 165*08b48e0bSAndroid Build Coastguard Worker - PCGUARD - our own pcguard based instrumentation (default) 166*08b48e0bSAndroid Build Coastguard Worker 167*08b48e0bSAndroid Build Coastguard Worker#### CMPLOG 168*08b48e0bSAndroid Build Coastguard Worker 169*08b48e0bSAndroid Build Coastguard WorkerSetting `AFL_LLVM_CMPLOG=1` during compilation will tell afl-clang-fast to 170*08b48e0bSAndroid Build Coastguard Workerproduce a CmpLog binary. 171*08b48e0bSAndroid Build Coastguard Worker 172*08b48e0bSAndroid Build Coastguard WorkerFor afl-gcc-fast, set `AFL_GCC_CMPLOG=1` instead. 173*08b48e0bSAndroid Build Coastguard Worker 174*08b48e0bSAndroid Build Coastguard WorkerFor more information, see 175*08b48e0bSAndroid Build Coastguard Worker[instrumentation/README.cmplog.md](../instrumentation/README.cmplog.md). 176*08b48e0bSAndroid Build Coastguard Worker 177*08b48e0bSAndroid Build Coastguard Worker#### CTX 178*08b48e0bSAndroid Build Coastguard Worker 179*08b48e0bSAndroid Build Coastguard WorkerSetting `AFL_LLVM_CTX` or `AFL_LLVM_INSTRUMENT=CTX` activates context sensitive 180*08b48e0bSAndroid Build Coastguard Workerbranch coverage - meaning that each edge is additionally combined with its 181*08b48e0bSAndroid Build Coastguard Workercaller. It is highly recommended to increase the `MAP_SIZE_POW2` definition in 182*08b48e0bSAndroid Build Coastguard Workerconfig.h to at least 18 and maybe up to 20 for this as otherwise too many map 183*08b48e0bSAndroid Build Coastguard Workercollisions occur. 184*08b48e0bSAndroid Build Coastguard Worker 185*08b48e0bSAndroid Build Coastguard WorkerFor more information, see 186*08b48e0bSAndroid Build Coastguard Worker[instrumentation/README.llvm.md#6) AFL++ Context Sensitive Branch Coverage](../instrumentation/README.llvm.md#6-afl-context-sensitive-branch-coverage). 187*08b48e0bSAndroid Build Coastguard Worker 188*08b48e0bSAndroid Build Coastguard Worker#### INSTRUMENT LIST (selectively instrument files and functions) 189*08b48e0bSAndroid Build Coastguard Worker 190*08b48e0bSAndroid Build Coastguard WorkerThis feature allows selective instrumentation of the source. 191*08b48e0bSAndroid Build Coastguard Worker 192*08b48e0bSAndroid Build Coastguard WorkerSetting `AFL_LLVM_ALLOWLIST` or `AFL_LLVM_DENYLIST` with a file name and/or 193*08b48e0bSAndroid Build Coastguard Workerfunction will only instrument (or skip) those files that match the names listed 194*08b48e0bSAndroid Build Coastguard Workerin the specified file. 195*08b48e0bSAndroid Build Coastguard Worker 196*08b48e0bSAndroid Build Coastguard WorkerFor more information, see 197*08b48e0bSAndroid Build Coastguard Worker[instrumentation/README.instrument_list.md](../instrumentation/README.instrument_list.md). 198*08b48e0bSAndroid Build Coastguard Worker 199*08b48e0bSAndroid Build Coastguard Worker#### INJECTIONS 200*08b48e0bSAndroid Build Coastguard Worker 201*08b48e0bSAndroid Build Coastguard WorkerThis feature is able to find simple injection vulnerabilities in insecure 202*08b48e0bSAndroid Build Coastguard Workercalls to mysql/mariadb/nosql/postgresql/ldap and XSS in libxml2. 203*08b48e0bSAndroid Build Coastguard Worker 204*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_INJECTIONS_ALL` will enable all injection hooking 205*08b48e0bSAndroid Build Coastguard Worker 206*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_INJECTIONS_SQL` will enable SQL injection hooking 207*08b48e0bSAndroid Build Coastguard Worker 208*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_INJECTIONS_LDAP` will enable LDAP injection hooking 209*08b48e0bSAndroid Build Coastguard Worker 210*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_INJECTIONS_XSS` will enable XSS injection hooking 211*08b48e0bSAndroid Build Coastguard Worker 212*08b48e0bSAndroid Build Coastguard Worker#### LAF-INTEL 213*08b48e0bSAndroid Build Coastguard Worker 214*08b48e0bSAndroid Build Coastguard WorkerThis great feature will split compares into series of single byte comparisons to 215*08b48e0bSAndroid Build Coastguard Workerallow afl-fuzz to find otherwise rather impossible paths. It is not restricted 216*08b48e0bSAndroid Build Coastguard Workerto Intel CPUs. ;-) 217*08b48e0bSAndroid Build Coastguard Worker 218*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_LAF_TRANSFORM_COMPARES` will split string compare 219*08b48e0bSAndroid Build Coastguard Worker functions. 220*08b48e0bSAndroid Build Coastguard Worker 221*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_LAF_SPLIT_COMPARES` will split all floating point and 64, 222*08b48e0bSAndroid Build Coastguard Worker 32 and 16 bit integer CMP instructions. 223*08b48e0bSAndroid Build Coastguard Worker 224*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_LAF_SPLIT_FLOATS` will split floating points, needs 225*08b48e0bSAndroid Build Coastguard Worker `AFL_LLVM_LAF_SPLIT_COMPARES` to be set. 226*08b48e0bSAndroid Build Coastguard Worker 227*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_LAF_SPLIT_SWITCHES` will split all `switch` constructs. 228*08b48e0bSAndroid Build Coastguard Worker 229*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_LAF_ALL` sets all of the above. 230*08b48e0bSAndroid Build Coastguard Worker 231*08b48e0bSAndroid Build Coastguard WorkerFor more information, see 232*08b48e0bSAndroid Build Coastguard Worker[instrumentation/README.laf-intel.md](../instrumentation/README.laf-intel.md). 233*08b48e0bSAndroid Build Coastguard Worker 234*08b48e0bSAndroid Build Coastguard Worker#### LTO 235*08b48e0bSAndroid Build Coastguard Worker 236*08b48e0bSAndroid Build Coastguard WorkerThis is a different way of instrumentation: first it compiles all code in LTO 237*08b48e0bSAndroid Build Coastguard Worker(link time optimization) and then performs an edge inserting instrumentation 238*08b48e0bSAndroid Build Coastguard Workerwhich is 100% collision free (collisions are a big issue in AFL and AFL-like 239*08b48e0bSAndroid Build Coastguard Workerinstrumentations). This is performed by using afl-clang-lto/afl-clang-lto++ 240*08b48e0bSAndroid Build Coastguard Workerinstead of afl-clang-fast, but is only built if LLVM 11 or newer is used. 241*08b48e0bSAndroid Build Coastguard Worker 242*08b48e0bSAndroid Build Coastguard Worker`AFL_LLVM_INSTRUMENT=CFG` will use Control Flow Graph instrumentation. (Not 243*08b48e0bSAndroid Build Coastguard Workerrecommended for afl-clang-fast, default for afl-clang-lto as there it is a 244*08b48e0bSAndroid Build Coastguard Workerdifferent and better kind of instrumentation.) 245*08b48e0bSAndroid Build Coastguard Worker 246*08b48e0bSAndroid Build Coastguard WorkerNone of the following options are necessary to be used and are rather for manual 247*08b48e0bSAndroid Build Coastguard Workeruse (which only ever the author of this LTO implementation will use). These are 248*08b48e0bSAndroid Build Coastguard Workerused if several separated instrumentations are performed which are then later 249*08b48e0bSAndroid Build Coastguard Workercombined. 250*08b48e0bSAndroid Build Coastguard Worker 251*08b48e0bSAndroid Build Coastguard Worker - `AFL_LLVM_DOCUMENT_IDS=file` will document to a file which edge ID was given 252*08b48e0bSAndroid Build Coastguard Worker to which function. This helps to identify functions with variable bytes or 253*08b48e0bSAndroid Build Coastguard Worker which functions were touched by an input. 254*08b48e0bSAndroid Build Coastguard Worker - `AFL_LLVM_LTO_DONTWRITEID` prevents that the highest location ID written 255*08b48e0bSAndroid Build Coastguard Worker into the instrumentation is set in a global variable. 256*08b48e0bSAndroid Build Coastguard Worker - `AFL_LLVM_LTO_STARTID` sets the starting location ID for the 257*08b48e0bSAndroid Build Coastguard Worker instrumentation. This defaults to 1. 258*08b48e0bSAndroid Build Coastguard Worker - `AFL_LLVM_MAP_ADDR` sets the fixed map address to a different address than 259*08b48e0bSAndroid Build Coastguard Worker the default `0x10000`. A value of 0 or empty sets the map address to be 260*08b48e0bSAndroid Build Coastguard Worker dynamic (the original AFL way, which is slower). 261*08b48e0bSAndroid Build Coastguard Worker - `AFL_LLVM_MAP_DYNAMIC` sets the shared memory address to be dynamic. 262*08b48e0bSAndroid Build Coastguard Worker - `AFL_LLVM_LTO_SKIPINIT` skips adding initialization code. Some global vars 263*08b48e0bSAndroid Build Coastguard Worker (e.g. the highest location ID) are not injected. Needed to instrument with 264*08b48e0bSAndroid Build Coastguard Worker [WAFL](https://github.com/fgsect/WAFL.git). 265*08b48e0bSAndroid Build Coastguard Worker For more information, see 266*08b48e0bSAndroid Build Coastguard Worker [instrumentation/README.lto.md](../instrumentation/README.lto.md). 267*08b48e0bSAndroid Build Coastguard Worker 268*08b48e0bSAndroid Build Coastguard Worker#### NGRAM 269*08b48e0bSAndroid Build Coastguard Worker 270*08b48e0bSAndroid Build Coastguard WorkerSetting `AFL_LLVM_INSTRUMENT=NGRAM-{value}` or `AFL_LLVM_NGRAM_SIZE` activates 271*08b48e0bSAndroid Build Coastguard Workerngram prev_loc coverage. Good values are 2, 4, or 8 (any value between 2 and 16 272*08b48e0bSAndroid Build Coastguard Workeris valid). It is highly recommended to increase the `MAP_SIZE_POW2` definition 273*08b48e0bSAndroid Build Coastguard Workerin config.h to at least 18 and maybe up to 20 for this as otherwise too many map 274*08b48e0bSAndroid Build Coastguard Workercollisions occur. 275*08b48e0bSAndroid Build Coastguard Worker 276*08b48e0bSAndroid Build Coastguard WorkerFor more information, see 277*08b48e0bSAndroid Build Coastguard Worker[instrumentation/README.llvm.md#7) AFL++ N-Gram Branch Coverage](../instrumentation/README.llvm.md#7-afl-n-gram-branch-coverage). 278*08b48e0bSAndroid Build Coastguard Worker 279*08b48e0bSAndroid Build Coastguard Worker#### NOT_ZERO 280*08b48e0bSAndroid Build Coastguard Worker 281*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_NOT_ZERO=1` during compilation will use counters that skip 282*08b48e0bSAndroid Build Coastguard Worker zero on overflow. This is the default for llvm >= 9, however, for llvm 283*08b48e0bSAndroid Build Coastguard Worker versions below that this will increase an unnecessary slowdown due a 284*08b48e0bSAndroid Build Coastguard Worker performance issue that is only fixed in llvm 9+. This feature increases path 285*08b48e0bSAndroid Build Coastguard Worker discovery by a little bit. 286*08b48e0bSAndroid Build Coastguard Worker 287*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_LLVM_SKIP_NEVERZERO=1` will not implement the skip zero test. 288*08b48e0bSAndroid Build Coastguard Worker If the target performs only a few loops, then this will give a small 289*08b48e0bSAndroid Build Coastguard Worker performance boost. 290*08b48e0bSAndroid Build Coastguard Worker 291*08b48e0bSAndroid Build Coastguard Worker#### Thread safe instrumentation counters (in all modes) 292*08b48e0bSAndroid Build Coastguard Worker 293*08b48e0bSAndroid Build Coastguard WorkerSetting `AFL_LLVM_THREADSAFE_INST` will inject code that implements thread safe 294*08b48e0bSAndroid Build Coastguard Workercounters. The overhead is a little bit higher compared to the older non-thread 295*08b48e0bSAndroid Build Coastguard Workersafe case. Note that this disables neverzero (see NOT_ZERO). 296*08b48e0bSAndroid Build Coastguard Worker 297*08b48e0bSAndroid Build Coastguard Worker## 3) Settings for GCC / GCC_PLUGIN modes 298*08b48e0bSAndroid Build Coastguard Worker 299*08b48e0bSAndroid Build Coastguard WorkerThere are a few specific features that are only available in GCC and GCC_PLUGIN 300*08b48e0bSAndroid Build Coastguard Workermode. 301*08b48e0bSAndroid Build Coastguard Worker 302*08b48e0bSAndroid Build Coastguard Worker - GCC mode only: Setting `AFL_KEEP_ASSEMBLY` prevents afl-as from deleting 303*08b48e0bSAndroid Build Coastguard Worker instrumented assembly files. Useful for troubleshooting problems or 304*08b48e0bSAndroid Build Coastguard Worker understanding how the tool works. 305*08b48e0bSAndroid Build Coastguard Worker 306*08b48e0bSAndroid Build Coastguard Worker To get them in a predictable place, try something like: 307*08b48e0bSAndroid Build Coastguard Worker 308*08b48e0bSAndroid Build Coastguard Worker ``` 309*08b48e0bSAndroid Build Coastguard Worker mkdir assembly_here 310*08b48e0bSAndroid Build Coastguard Worker TMPDIR=$PWD/assembly_here AFL_KEEP_ASSEMBLY=1 make clean all 311*08b48e0bSAndroid Build Coastguard Worker ``` 312*08b48e0bSAndroid Build Coastguard Worker 313*08b48e0bSAndroid Build Coastguard Worker - GCC_PLUGIN mode only: Setting `AFL_GCC_INSTRUMENT_FILE` or 314*08b48e0bSAndroid Build Coastguard Worker `AFL_GCC_ALLOWLIST` with a filename will only instrument those files that 315*08b48e0bSAndroid Build Coastguard Worker match the names listed in this file (one filename per line). 316*08b48e0bSAndroid Build Coastguard Worker 317*08b48e0bSAndroid Build Coastguard Worker Setting `AFL_GCC_DENYLIST` or `AFL_GCC_BLOCKLIST` with a file name and/or 318*08b48e0bSAndroid Build Coastguard Worker function will only skip those files that match the names listed in the 319*08b48e0bSAndroid Build Coastguard Worker specified file. See 320*08b48e0bSAndroid Build Coastguard Worker [instrumentation/README.instrument_list.md](../instrumentation/README.instrument_list.md) 321*08b48e0bSAndroid Build Coastguard Worker for more information. 322*08b48e0bSAndroid Build Coastguard Worker 323*08b48e0bSAndroid Build Coastguard Worker Setting `AFL_GCC_OUT_OF_LINE=1` will instruct afl-gcc-fast to instrument the 324*08b48e0bSAndroid Build Coastguard Worker code with calls to an injected subroutine instead of the much more efficient 325*08b48e0bSAndroid Build Coastguard Worker inline instrumentation. 326*08b48e0bSAndroid Build Coastguard Worker 327*08b48e0bSAndroid Build Coastguard Worker Setting `AFL_GCC_SKIP_NEVERZERO=1` will not implement the skip zero test. If 328*08b48e0bSAndroid Build Coastguard Worker the target performs only a few loops, then this will give a small 329*08b48e0bSAndroid Build Coastguard Worker performance boost. 330*08b48e0bSAndroid Build Coastguard Worker 331*08b48e0bSAndroid Build Coastguard Worker## 4) Settings for afl-fuzz 332*08b48e0bSAndroid Build Coastguard Worker 333*08b48e0bSAndroid Build Coastguard WorkerThe main fuzzer binary accepts several options that disable a couple of sanity 334*08b48e0bSAndroid Build Coastguard Workerchecks or alter some of the more exotic semantics of the tool: 335*08b48e0bSAndroid Build Coastguard Worker 336*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_AUTORESUME` will resume a fuzz run (same as providing `-i -`) 337*08b48e0bSAndroid Build Coastguard Worker for an existing out folder, even if a different `-i` was provided. Without 338*08b48e0bSAndroid Build Coastguard Worker this setting, afl-fuzz will refuse execution for a long-fuzzed out dir. 339*08b48e0bSAndroid Build Coastguard Worker 340*08b48e0bSAndroid Build Coastguard Worker - Benchmarking only: `AFL_BENCH_JUST_ONE` causes the fuzzer to exit after 341*08b48e0bSAndroid Build Coastguard Worker processing the first queue entry; and `AFL_BENCH_UNTIL_CRASH` causes it to 342*08b48e0bSAndroid Build Coastguard Worker exit soon after the first crash is found. 343*08b48e0bSAndroid Build Coastguard Worker 344*08b48e0bSAndroid Build Coastguard Worker - `AFL_CMPLOG_ONLY_NEW` will only perform the expensive cmplog feature for 345*08b48e0bSAndroid Build Coastguard Worker newly found test cases and not for test cases that are loaded on startup 346*08b48e0bSAndroid Build Coastguard Worker (`-i in`). This is an important feature to set when resuming a fuzzing 347*08b48e0bSAndroid Build Coastguard Worker session. 348*08b48e0bSAndroid Build Coastguard Worker 349*08b48e0bSAndroid Build Coastguard Worker - `AFL_IGNORE_SEED_PROBLEMS` will skip over crashes and timeouts in the seeds 350*08b48e0bSAndroid Build Coastguard Worker instead of exiting. 351*08b48e0bSAndroid Build Coastguard Worker 352*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_CRASH_EXITCODE` sets the exit code AFL++ treats as crash. For 353*08b48e0bSAndroid Build Coastguard Worker example, if `AFL_CRASH_EXITCODE='-1'` is set, each input resulting in a `-1` 354*08b48e0bSAndroid Build Coastguard Worker return code (i.e. `exit(-1)` got called), will be treated as if a crash had 355*08b48e0bSAndroid Build Coastguard Worker occurred. This may be beneficial if you look for higher-level faulty 356*08b48e0bSAndroid Build Coastguard Worker conditions in which your target still exits gracefully. 357*08b48e0bSAndroid Build Coastguard Worker 358*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_CUSTOM_MUTATOR_LIBRARY` to a shared library with 359*08b48e0bSAndroid Build Coastguard Worker afl_custom_fuzz() creates additional mutations through this library. If 360*08b48e0bSAndroid Build Coastguard Worker afl-fuzz is compiled with Python (which is autodetected during building 361*08b48e0bSAndroid Build Coastguard Worker afl-fuzz), setting `AFL_PYTHON_MODULE` to a Python module can also provide 362*08b48e0bSAndroid Build Coastguard Worker additional mutations. If `AFL_CUSTOM_MUTATOR_ONLY` is also set, all 363*08b48e0bSAndroid Build Coastguard Worker mutations will solely be performed with the custom mutator. This feature 364*08b48e0bSAndroid Build Coastguard Worker allows to configure custom mutators which can be very helpful, e.g., fuzzing 365*08b48e0bSAndroid Build Coastguard Worker XML or other highly flexible structured input. For details, see 366*08b48e0bSAndroid Build Coastguard Worker [custom_mutators.md](custom_mutators.md). 367*08b48e0bSAndroid Build Coastguard Worker 368*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_CYCLE_SCHEDULES` will switch to a different schedule every time 369*08b48e0bSAndroid Build Coastguard Worker a cycle is finished. 370*08b48e0bSAndroid Build Coastguard Worker 371*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_DEBUG_CHILD` will not suppress the child output. This lets you 372*08b48e0bSAndroid Build Coastguard Worker see all output of the child, making setup issues obvious. For example, in an 373*08b48e0bSAndroid Build Coastguard Worker unicornafl harness, you might see python stacktraces. You may also see other 374*08b48e0bSAndroid Build Coastguard Worker logs that way, indicating why the forkserver won't start. Not pretty but 375*08b48e0bSAndroid Build Coastguard Worker good for debugging purposes. Note that `AFL_DEBUG_CHILD_OUTPUT` is 376*08b48e0bSAndroid Build Coastguard Worker deprecated. 377*08b48e0bSAndroid Build Coastguard Worker 378*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_DISABLE_TRIM` tells afl-fuzz not to trim test cases. This is 379*08b48e0bSAndroid Build Coastguard Worker usually a bad idea! 380*08b48e0bSAndroid Build Coastguard Worker 381*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_KEEP_TIMEOUTS` will keep longer running inputs if they reach 382*08b48e0bSAndroid Build Coastguard Worker new coverage 383*08b48e0bSAndroid Build Coastguard Worker 384*08b48e0bSAndroid Build Coastguard Worker - On the contrary, if you are not interested in any timeouts, you can set 385*08b48e0bSAndroid Build Coastguard Worker `AFL_IGNORE_TIMEOUTS` to get a bit of speed instead. 386*08b48e0bSAndroid Build Coastguard Worker 387*08b48e0bSAndroid Build Coastguard Worker - `AFL_EXIT_ON_SEED_ISSUES` will restore the vanilla afl-fuzz behavior which 388*08b48e0bSAndroid Build Coastguard Worker does not allow crashes or timeout seeds in the initial -i corpus. 389*08b48e0bSAndroid Build Coastguard Worker 390*08b48e0bSAndroid Build Coastguard Worker - `AFL_CRASHING_SEEDS_AS_NEW_CRASH` will treat crashing seeds as new crash. these 391*08b48e0bSAndroid Build Coastguard Worker crashes will be written to crashes folder as op:dry_run, and orig:<seed_file_name>. 392*08b48e0bSAndroid Build Coastguard Worker 393*08b48e0bSAndroid Build Coastguard Worker - `AFL_EXIT_ON_TIME` causes afl-fuzz to terminate if no new paths were found 394*08b48e0bSAndroid Build Coastguard Worker within a specified period of time (in seconds). May be convenient for some 395*08b48e0bSAndroid Build Coastguard Worker types of automated jobs. 396*08b48e0bSAndroid Build Coastguard Worker 397*08b48e0bSAndroid Build Coastguard Worker - `AFL_EXIT_WHEN_DONE` causes afl-fuzz to terminate when all existing paths 398*08b48e0bSAndroid Build Coastguard Worker have been fuzzed and there were no new finds for a while. This would be 399*08b48e0bSAndroid Build Coastguard Worker normally indicated by the cycle counter in the UI turning green. May be 400*08b48e0bSAndroid Build Coastguard Worker convenient for some types of automated jobs. 401*08b48e0bSAndroid Build Coastguard Worker 402*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_EXPAND_HAVOC_NOW` will start in the extended havoc mode that 403*08b48e0bSAndroid Build Coastguard Worker includes costly mutations. afl-fuzz automatically enables this mode when 404*08b48e0bSAndroid Build Coastguard Worker deemed useful otherwise. 405*08b48e0bSAndroid Build Coastguard Worker 406*08b48e0bSAndroid Build Coastguard Worker - `AFL_FAST_CAL` keeps the calibration stage about 2.5x faster (albeit less 407*08b48e0bSAndroid Build Coastguard Worker precise), which can help when starting a session against a slow target. 408*08b48e0bSAndroid Build Coastguard Worker `AFL_CAL_FAST` works too. 409*08b48e0bSAndroid Build Coastguard Worker 410*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_FORCE_UI` will force painting the UI on the screen even if no 411*08b48e0bSAndroid Build Coastguard Worker valid terminal was detected (for virtual consoles). 412*08b48e0bSAndroid Build Coastguard Worker 413*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_FORKSRV_INIT_TMOUT` allows you to specify a different timeout 414*08b48e0bSAndroid Build Coastguard Worker to wait for the forkserver to spin up. The specified value is the new timeout, in milliseconds. 415*08b48e0bSAndroid Build Coastguard Worker The default is the `-t` value times `FORK_WAIT_MULT` from `config.h` (usually 10), so for a `-t 100`, the default would wait for `1000` milliseconds. 416*08b48e0bSAndroid Build Coastguard Worker The `AFL_FORKSRV_INIT_TMOUT` value does not get multiplied. It overwrites the initial timeout afl-fuzz waits for the target to come up with a constant time. 417*08b48e0bSAndroid Build Coastguard Worker Setting a different time here is useful if the target has a very slow startup time, for example, when doing 418*08b48e0bSAndroid Build Coastguard Worker full-system fuzzing or emulation, but you don't want the actual runs to wait 419*08b48e0bSAndroid Build Coastguard Worker too long for timeouts. 420*08b48e0bSAndroid Build Coastguard Worker 421*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_HANG_TMOUT` allows you to specify a different timeout for 422*08b48e0bSAndroid Build Coastguard Worker deciding if a particular test case is a "hang". The default is 1 second or 423*08b48e0bSAndroid Build Coastguard Worker the value of the `-t` parameter, whichever is larger. Dialing the value down 424*08b48e0bSAndroid Build Coastguard Worker can be useful if you are very concerned about slow inputs, or if you don't 425*08b48e0bSAndroid Build Coastguard Worker want AFL++ to spend too much time classifying that stuff and just rapidly 426*08b48e0bSAndroid Build Coastguard Worker put all timeouts in that bin. 427*08b48e0bSAndroid Build Coastguard Worker 428*08b48e0bSAndroid Build Coastguard Worker - If you are Jakub, you may need `AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES`. 429*08b48e0bSAndroid Build Coastguard Worker Others need not apply, unless they also want to disable the 430*08b48e0bSAndroid Build Coastguard Worker `/proc/sys/kernel/core_pattern` check. 431*08b48e0bSAndroid Build Coastguard Worker 432*08b48e0bSAndroid Build Coastguard Worker - If afl-fuzz encounters an incorrect fuzzing setup during a fuzzing session 433*08b48e0bSAndroid Build Coastguard Worker (not at startup), it will terminate. If you do not want this, then you can 434*08b48e0bSAndroid Build Coastguard Worker set `AFL_IGNORE_PROBLEMS`. If you additionally want to also ignore coverage 435*08b48e0bSAndroid Build Coastguard Worker from late loaded libraries, you can set `AFL_IGNORE_PROBLEMS_COVERAGE`. 436*08b48e0bSAndroid Build Coastguard Worker 437*08b48e0bSAndroid Build Coastguard Worker - When running with multiple afl-fuzz or with `-F`, setting `AFL_IMPORT_FIRST` 438*08b48e0bSAndroid Build Coastguard Worker causes the fuzzer to import test cases from other instances before doing 439*08b48e0bSAndroid Build Coastguard Worker anything else. This makes the "own finds" counter in the UI more accurate. 440*08b48e0bSAndroid Build Coastguard Worker 441*08b48e0bSAndroid Build Coastguard Worker - When running with multiple afl-fuzz or with `-F`, setting `AFL_FINAL_SYNC` 442*08b48e0bSAndroid Build Coastguard Worker will cause the fuzzer to perform a final import of test cases when 443*08b48e0bSAndroid Build Coastguard Worker terminating. This is beneficial for `-M` main fuzzers to ensure it has all 444*08b48e0bSAndroid Build Coastguard Worker unique test cases and hence you only need to `afl-cmin` this single 445*08b48e0bSAndroid Build Coastguard Worker queue. 446*08b48e0bSAndroid Build Coastguard Worker 447*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_INPUT_LEN_MIN` and `AFL_INPUT_LEN_MAX` are an alternative to 448*08b48e0bSAndroid Build Coastguard Worker the afl-fuzz -g/-G command line option to control the minimum/maximum 449*08b48e0bSAndroid Build Coastguard Worker of fuzzing input generated. 450*08b48e0bSAndroid Build Coastguard Worker 451*08b48e0bSAndroid Build Coastguard Worker - `AFL_KILL_SIGNAL`: Set the signal ID to be delivered to child processes 452*08b48e0bSAndroid Build Coastguard Worker on timeout. Unless you implement your own targets or instrumentation, you 453*08b48e0bSAndroid Build Coastguard Worker likely don't have to set it. By default, on timeout and on exit, `SIGKILL` 454*08b48e0bSAndroid Build Coastguard Worker (`AFL_KILL_SIGNAL=9`) will be delivered to the child. 455*08b48e0bSAndroid Build Coastguard Worker 456*08b48e0bSAndroid Build Coastguard Worker - `AFL_FORK_SERVER_KILL_SIGNAL`: Set the signal ID to be delivered to the 457*08b48e0bSAndroid Build Coastguard Worker fork server when AFL++ is terminated. Unless you implement your 458*08b48e0bSAndroid Build Coastguard Worker fork server, you likely do not have to set it. By default, `SIGTERM` 459*08b48e0bSAndroid Build Coastguard Worker (`AFL_FORK_SERVER_KILL_SIGNAL=15`) will be delivered to the fork server. 460*08b48e0bSAndroid Build Coastguard Worker If only `AFL_KILL_SIGNAL` is provided, `AFL_FORK_SERVER_KILL_SIGNAL` will 461*08b48e0bSAndroid Build Coastguard Worker be set to same value as `AFL_KILL_SIGNAL` to provide backward compatibility. 462*08b48e0bSAndroid Build Coastguard Worker If `AFL_FORK_SERVER_KILL_SIGNAL` is also set, it takes precedence. 463*08b48e0bSAndroid Build Coastguard Worker 464*08b48e0bSAndroid Build Coastguard Worker NOTE: Uncatchable signals, such as `SIGKILL`, cause child processes of 465*08b48e0bSAndroid Build Coastguard Worker the fork server to be orphaned and leaves them in a zombie state. 466*08b48e0bSAndroid Build Coastguard Worker 467*08b48e0bSAndroid Build Coastguard Worker - `AFL_MAP_SIZE` sets the size of the shared map that afl-analyze, afl-fuzz, 468*08b48e0bSAndroid Build Coastguard Worker afl-showmap, and afl-tmin create to gather instrumentation data from the 469*08b48e0bSAndroid Build Coastguard Worker target. This must be equal or larger than the size the target was compiled 470*08b48e0bSAndroid Build Coastguard Worker with. 471*08b48e0bSAndroid Build Coastguard Worker 472*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_MAX_DET_EXTRAS` will change the threshold at what number of 473*08b48e0bSAndroid Build Coastguard Worker elements in the `-x` dictionary and LTO autodict (combined) the 474*08b48e0bSAndroid Build Coastguard Worker probabilistic mode will kick off. In probabilistic mode, not all dictionary 475*08b48e0bSAndroid Build Coastguard Worker entries will be used all of the time for fuzzing mutations to not slow down 476*08b48e0bSAndroid Build Coastguard Worker fuzzing. The default count is `200` elements. So for the 200 + 1st element, 477*08b48e0bSAndroid Build Coastguard Worker there is a 1 in 201 chance, that one of the dictionary entries will not be 478*08b48e0bSAndroid Build Coastguard Worker used directly. 479*08b48e0bSAndroid Build Coastguard Worker 480*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_AFFINITY` disables attempts to bind to a specific CPU core 481*08b48e0bSAndroid Build Coastguard Worker on Linux systems. This slows things down, but lets you run more instances of 482*08b48e0bSAndroid Build Coastguard Worker afl-fuzz than would be prudent (if you really want to). 483*08b48e0bSAndroid Build Coastguard Worker 484*08b48e0bSAndroid Build Coastguard Worker - `AFL_NO_ARITH` causes AFL++ to skip most of the deterministic arithmetics. 485*08b48e0bSAndroid Build Coastguard Worker This can be useful to speed up the fuzzing of text-based file formats. 486*08b48e0bSAndroid Build Coastguard Worker 487*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_AUTODICT` will not load an LTO generated auto dictionary 488*08b48e0bSAndroid Build Coastguard Worker that is compiled into the target. 489*08b48e0bSAndroid Build Coastguard Worker 490*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_COLOR` or `AFL_NO_COLOUR` will omit control sequences for 491*08b48e0bSAndroid Build Coastguard Worker coloring console output when configured with USE_COLOR and not 492*08b48e0bSAndroid Build Coastguard Worker ALWAYS_COLORED. 493*08b48e0bSAndroid Build Coastguard Worker 494*08b48e0bSAndroid Build Coastguard Worker - The CPU widget shown at the bottom of the screen is fairly simplistic and 495*08b48e0bSAndroid Build Coastguard Worker may complain of high load prematurely, especially on systems with low core 496*08b48e0bSAndroid Build Coastguard Worker counts. To avoid the alarming red color for very high CPU usages, you can 497*08b48e0bSAndroid Build Coastguard Worker set `AFL_NO_CPU_RED`. 498*08b48e0bSAndroid Build Coastguard Worker 499*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_FORKSRV` disables the forkserver optimization, reverting to 500*08b48e0bSAndroid Build Coastguard Worker fork + execve() call for every tested input. This is useful mostly when 501*08b48e0bSAndroid Build Coastguard Worker working with unruly libraries that create threads or do other crazy things 502*08b48e0bSAndroid Build Coastguard Worker when initializing (before the instrumentation has a chance to run). 503*08b48e0bSAndroid Build Coastguard Worker 504*08b48e0bSAndroid Build Coastguard Worker Note that this setting inhibits some of the user-friendly diagnostics 505*08b48e0bSAndroid Build Coastguard Worker normally done when starting up the forkserver and causes a pretty 506*08b48e0bSAndroid Build Coastguard Worker significant performance drop. 507*08b48e0bSAndroid Build Coastguard Worker 508*08b48e0bSAndroid Build Coastguard Worker - `AFL_NO_SNAPSHOT` will advise afl-fuzz not to use the snapshot feature if 509*08b48e0bSAndroid Build Coastguard Worker the snapshot lkm is loaded. 510*08b48e0bSAndroid Build Coastguard Worker 511*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_UI` inhibits the UI altogether and just periodically prints 512*08b48e0bSAndroid Build Coastguard Worker some basic stats. This behavior is also automatically triggered when the 513*08b48e0bSAndroid Build Coastguard Worker output from afl-fuzz is redirected to a file or to a pipe. 514*08b48e0bSAndroid Build Coastguard Worker 515*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_STARTUP_CALIBRATION` will skip the initial calibration 516*08b48e0bSAndroid Build Coastguard Worker of all starting seeds, and start fuzzing at once. Use with care, this 517*08b48e0bSAndroid Build Coastguard Worker degrades the fuzzing performance! 518*08b48e0bSAndroid Build Coastguard Worker 519*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_NO_WARN_INSTABILITY` will suppress instability warnings. 520*08b48e0bSAndroid Build Coastguard Worker 521*08b48e0bSAndroid Build Coastguard Worker - In QEMU mode (-Q) and FRIDA mode (-O), `AFL_PATH` will be searched for 522*08b48e0bSAndroid Build Coastguard Worker afl-qemu-trace and afl-frida-trace.so. 523*08b48e0bSAndroid Build Coastguard Worker 524*08b48e0bSAndroid Build Coastguard Worker - If you are using persistent mode (you should, see 525*08b48e0bSAndroid Build Coastguard Worker [instrumentation/README.persistent_mode.md](../instrumentation/README.persistent_mode.md)), 526*08b48e0bSAndroid Build Coastguard Worker some targets keep inherent state due which a detected crash test case does 527*08b48e0bSAndroid Build Coastguard Worker not crash the target again when the test case is given. To be able to still 528*08b48e0bSAndroid Build Coastguard Worker re-trigger these crashes, you can use the `AFL_PERSISTENT_RECORD` variable 529*08b48e0bSAndroid Build Coastguard Worker with a value of how many previous fuzz cases to keep prior a crash. If set to 530*08b48e0bSAndroid Build Coastguard Worker e.g., 10, then the 9 previous inputs are written to out/default/crashes as 531*08b48e0bSAndroid Build Coastguard Worker RECORD:000000,cnt:000000 to RECORD:000000,cnt:000008 and 532*08b48e0bSAndroid Build Coastguard Worker RECORD:000000,cnt:000009 being the crash case. NOTE: This option needs to be 533*08b48e0bSAndroid Build Coastguard Worker enabled in config.h first! 534*08b48e0bSAndroid Build Coastguard Worker 535*08b48e0bSAndroid Build Coastguard Worker - Note that `AFL_POST_LIBRARY` is deprecated, use `AFL_CUSTOM_MUTATOR_LIBRARY` 536*08b48e0bSAndroid Build Coastguard Worker instead. 537*08b48e0bSAndroid Build Coastguard Worker 538*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_PRELOAD` causes AFL++ to set `LD_PRELOAD` for the target binary 539*08b48e0bSAndroid Build Coastguard Worker without disrupting the afl-fuzz process itself. This is useful, among other 540*08b48e0bSAndroid Build Coastguard Worker things, for bootstrapping libdislocator.so. 541*08b48e0bSAndroid Build Coastguard Worker 542*08b48e0bSAndroid Build Coastguard Worker - In QEMU mode (-Q), setting `AFL_QEMU_CUSTOM_BIN` will cause afl-fuzz to skip 543*08b48e0bSAndroid Build Coastguard Worker prepending `afl-qemu-trace` to your command line. Use this if you wish to 544*08b48e0bSAndroid Build Coastguard Worker use a custom afl-qemu-trace or if you need to modify the afl-qemu-trace 545*08b48e0bSAndroid Build Coastguard Worker arguments. 546*08b48e0bSAndroid Build Coastguard Worker 547*08b48e0bSAndroid Build Coastguard Worker - `AFL_SHUFFLE_QUEUE` randomly reorders the input queue on startup. Requested 548*08b48e0bSAndroid Build Coastguard Worker by some users for unorthodox parallelized fuzzing setups, but not advisable 549*08b48e0bSAndroid Build Coastguard Worker otherwise. 550*08b48e0bSAndroid Build Coastguard Worker 551*08b48e0bSAndroid Build Coastguard Worker - When developing custom instrumentation on top of afl-fuzz, you can use 552*08b48e0bSAndroid Build Coastguard Worker `AFL_SKIP_BIN_CHECK` to inhibit the checks for non-instrumented binaries and 553*08b48e0bSAndroid Build Coastguard Worker shell scripts; and `AFL_DUMB_FORKSRV` in conjunction with the `-n` setting 554*08b48e0bSAndroid Build Coastguard Worker to instruct afl-fuzz to still follow the fork server protocol without 555*08b48e0bSAndroid Build Coastguard Worker expecting any instrumentation data in return. Note that this also turns off 556*08b48e0bSAndroid Build Coastguard Worker auto map size detection. 557*08b48e0bSAndroid Build Coastguard Worker 558*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_SKIP_CPUFREQ` skips the check for CPU scaling policy. This is 559*08b48e0bSAndroid Build Coastguard Worker useful if you can't change the defaults (e.g., no root access to the system) 560*08b48e0bSAndroid Build Coastguard Worker and are OK with some performance loss. 561*08b48e0bSAndroid Build Coastguard Worker 562*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_STATSD` enables StatsD metrics collection. By default, AFL++ 563*08b48e0bSAndroid Build Coastguard Worker will send these metrics over UDP to 127.0.0.1:8125. The host and port are 564*08b48e0bSAndroid Build Coastguard Worker configurable with `AFL_STATSD_HOST` and `AFL_STATSD_PORT` respectively. To 565*08b48e0bSAndroid Build Coastguard Worker enable tags (banner and afl_version), you should provide 566*08b48e0bSAndroid Build Coastguard Worker `AFL_STATSD_TAGS_FLAVOR` that matches your StatsD server (see 567*08b48e0bSAndroid Build Coastguard Worker `AFL_STATSD_TAGS_FLAVOR`). 568*08b48e0bSAndroid Build Coastguard Worker 569*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_STATSD_TAGS_FLAVOR` to one of `dogstatsd`, `influxdb`, 570*08b48e0bSAndroid Build Coastguard Worker `librato`, or `signalfx` allows you to add tags to your fuzzing instances. 571*08b48e0bSAndroid Build Coastguard Worker This is especially useful when running multiple instances (`-M/-S` for 572*08b48e0bSAndroid Build Coastguard Worker example). Applied tags are `banner` and `afl_version`. `banner` corresponds 573*08b48e0bSAndroid Build Coastguard Worker to the name of the fuzzer provided through `-M/-S`. `afl_version` 574*08b48e0bSAndroid Build Coastguard Worker corresponds to the currently running AFL++ version (e.g., `++3.0c`). Default 575*08b48e0bSAndroid Build Coastguard Worker (empty/non present) will add no tags to the metrics. For more information, 576*08b48e0bSAndroid Build Coastguard Worker see [rpc_statsd.md](rpc_statsd.md). 577*08b48e0bSAndroid Build Coastguard Worker 578*08b48e0bSAndroid Build Coastguard Worker - `AFL_SYNC_TIME` allows you to specify a different minimal time (in minutes) 579*08b48e0bSAndroid Build Coastguard Worker between fuzzing instances synchronization. Default sync time is 30 minutes, 580*08b48e0bSAndroid Build Coastguard Worker note that time is halved for -M main nodes. 581*08b48e0bSAndroid Build Coastguard Worker 582*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_TARGET_ENV` causes AFL++ to set extra environment variables for 583*08b48e0bSAndroid Build Coastguard Worker the target binary. Example: `AFL_TARGET_ENV="VAR1=1 VAR2='a b c'" afl-fuzz 584*08b48e0bSAndroid Build Coastguard Worker ... `. This exists mostly for things like `LD_LIBRARY_PATH` but it would 585*08b48e0bSAndroid Build Coastguard Worker theoretically allow fuzzing of AFL++ itself (with 'target' AFL++ using some 586*08b48e0bSAndroid Build Coastguard Worker AFL_ vars that would disrupt work of 'fuzzer' AFL++). Note that when using 587*08b48e0bSAndroid Build Coastguard Worker QEMU mode, the `AFL_TARGET_ENV` environment variables will apply to QEMU, as 588*08b48e0bSAndroid Build Coastguard Worker well as the target binary. Therefore, in this case, you might want to use 589*08b48e0bSAndroid Build Coastguard Worker QEMU's `QEMU_SET_ENV` environment variable (see QEMU's documentation because 590*08b48e0bSAndroid Build Coastguard Worker the format is different from `AFL_TARGET_ENV`) to apply the environment 591*08b48e0bSAndroid Build Coastguard Worker variables to the target and not QEMU. 592*08b48e0bSAndroid Build Coastguard Worker 593*08b48e0bSAndroid Build Coastguard Worker - `AFL_TESTCACHE_SIZE` allows you to override the size of `#define 594*08b48e0bSAndroid Build Coastguard Worker TESTCASE_CACHE` in config.h. Recommended values are 50-250MB - or more if 595*08b48e0bSAndroid Build Coastguard Worker your fuzzing finds a huge amount of paths for large inputs. 596*08b48e0bSAndroid Build Coastguard Worker 597*08b48e0bSAndroid Build Coastguard Worker - `AFL_TMPDIR` is used to write the `.cur_input` file to if it exists, and in 598*08b48e0bSAndroid Build Coastguard Worker the normal output directory otherwise. You would use this to point to a 599*08b48e0bSAndroid Build Coastguard Worker ramdisk/tmpfs. This increases the speed by a small value but also reduces 600*08b48e0bSAndroid Build Coastguard Worker the stress on SSDs. 601*08b48e0bSAndroid Build Coastguard Worker 602*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_TRY_AFFINITY` tries to attempt binding to a specific CPU core 603*08b48e0bSAndroid Build Coastguard Worker on Linux systems, but will not terminate if that fails. 604*08b48e0bSAndroid Build Coastguard Worker 605*08b48e0bSAndroid Build Coastguard Worker - The following environment variables are only needed if you implemented 606*08b48e0bSAndroid Build Coastguard Worker your own forkserver or persistent mode, or if __AFL_LOOP or __AFL_INIT 607*08b48e0bSAndroid Build Coastguard Worker are in a shared library and not the main binary: 608*08b48e0bSAndroid Build Coastguard Worker - `AFL_DEFER_FORKSRV` enforces a deferred forkserver even if none was 609*08b48e0bSAndroid Build Coastguard Worker detected in the target binary 610*08b48e0bSAndroid Build Coastguard Worker - `AFL_PERSISTENT` enforces persistent mode even if none was detected 611*08b48e0bSAndroid Build Coastguard Worker in the target binary 612*08b48e0bSAndroid Build Coastguard Worker 613*08b48e0bSAndroid Build Coastguard Worker - If you need an early forkserver in your target because of early 614*08b48e0bSAndroid Build Coastguard Worker constructors in your target, you can set `AFL_EARLY_FORKSERVER`. 615*08b48e0bSAndroid Build Coastguard Worker Note that this is not a compile time option but a runtime option :-) 616*08b48e0bSAndroid Build Coastguard Worker 617*08b48e0bSAndroid Build Coastguard Worker - Set `AFL_PIZZA_MODE` to 1 to enable the April 1st stats menu, set to -1 618*08b48e0bSAndroid Build Coastguard Worker to disable although it is 1st of April. 0 is the default and means enable 619*08b48e0bSAndroid Build Coastguard Worker on the 1st of April automatically. 620*08b48e0bSAndroid Build Coastguard Worker 621*08b48e0bSAndroid Build Coastguard Worker - If you need a specific interval to update fuzzer_stats file, you can 622*08b48e0bSAndroid Build Coastguard Worker set `AFL_FUZZER_STATS_UPDATE_INTERVAL` to the interval in seconds you'd 623*08b48e0bSAndroid Build Coastguard Worker the file to be updated. 624*08b48e0bSAndroid Build Coastguard Worker Note that will not be exact and with slow targets it can take seconds 625*08b48e0bSAndroid Build Coastguard Worker until there is a slice for the time test. 626*08b48e0bSAndroid Build Coastguard Worker 627*08b48e0bSAndroid Build Coastguard Worker## 5) Settings for afl-qemu-trace 628*08b48e0bSAndroid Build Coastguard Worker 629*08b48e0bSAndroid Build Coastguard WorkerThe QEMU wrapper used to instrument binary-only code supports several settings: 630*08b48e0bSAndroid Build Coastguard Worker 631*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_COMPCOV_LEVEL` enables the CompareCoverage tracing of all cmp 632*08b48e0bSAndroid Build Coastguard Worker and sub in x86 and x86_64 and memory comparison functions (e.g., strcmp, 633*08b48e0bSAndroid Build Coastguard Worker memcmp, ...) when libcompcov is preloaded using `AFL_PRELOAD`. More info at 634*08b48e0bSAndroid Build Coastguard Worker [qemu_mode/libcompcov/README.md](../qemu_mode/libcompcov/README.md). 635*08b48e0bSAndroid Build Coastguard Worker 636*08b48e0bSAndroid Build Coastguard Worker There are two levels at the moment, `AFL_COMPCOV_LEVEL=1` that instruments 637*08b48e0bSAndroid Build Coastguard Worker only comparisons with immediate values / read-only memory and 638*08b48e0bSAndroid Build Coastguard Worker `AFL_COMPCOV_LEVEL=2` that instruments all the comparisons. Level 2 is more 639*08b48e0bSAndroid Build Coastguard Worker accurate but may need a larger shared memory. 640*08b48e0bSAndroid Build Coastguard Worker 641*08b48e0bSAndroid Build Coastguard Worker - `AFL_DEBUG` will print the found entry point for the binary to stderr. Use 642*08b48e0bSAndroid Build Coastguard Worker this if you are unsure if the entry point might be wrong - but use it 643*08b48e0bSAndroid Build Coastguard Worker directly, e.g., `afl-qemu-trace ./program`. 644*08b48e0bSAndroid Build Coastguard Worker 645*08b48e0bSAndroid Build Coastguard Worker - `AFL_ENTRYPOINT` allows you to specify a specific entry point into the 646*08b48e0bSAndroid Build Coastguard Worker binary (this can be very good for the performance!). The entry point is 647*08b48e0bSAndroid Build Coastguard Worker specified as hex address, e.g., `0x4004110`. Note that the address must be 648*08b48e0bSAndroid Build Coastguard Worker the address of a basic block. 649*08b48e0bSAndroid Build Coastguard Worker 650*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_INST_LIBS` causes the translator to also instrument the code 651*08b48e0bSAndroid Build Coastguard Worker inside any dynamically linked libraries (notably including glibc). 652*08b48e0bSAndroid Build Coastguard Worker 653*08b48e0bSAndroid Build Coastguard Worker - You can use `AFL_QEMU_INST_RANGES=0xaaaa-0xbbbb,0xcccc-0xdddd` to just 654*08b48e0bSAndroid Build Coastguard Worker instrument specific memory locations, e.g. a specific library. 655*08b48e0bSAndroid Build Coastguard Worker Excluding ranges takes priority over any included ranges or `AFL_INST_LIBS`. 656*08b48e0bSAndroid Build Coastguard Worker 657*08b48e0bSAndroid Build Coastguard Worker - You can use `AFL_QEMU_EXCLUDE_RANGES=0xaaaa-0xbbbb,0xcccc-0xdddd` to **NOT** 658*08b48e0bSAndroid Build Coastguard Worker instrument specific memory locations, e.g. a specific library. 659*08b48e0bSAndroid Build Coastguard Worker Excluding ranges takes priority over any included ranges or `AFL_INST_LIBS`. 660*08b48e0bSAndroid Build Coastguard Worker 661*08b48e0bSAndroid Build Coastguard Worker - It is possible to set `AFL_INST_RATIO` to skip the instrumentation on some 662*08b48e0bSAndroid Build Coastguard Worker of the basic blocks, which can be useful when dealing with very complex 663*08b48e0bSAndroid Build Coastguard Worker binaries. 664*08b48e0bSAndroid Build Coastguard Worker 665*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_QEMU_COMPCOV` enables the CompareCoverage tracing of all cmp 666*08b48e0bSAndroid Build Coastguard Worker and sub in x86 and x86_64. This is an alias of `AFL_COMPCOV_LEVEL=1` when 667*08b48e0bSAndroid Build Coastguard Worker `AFL_COMPCOV_LEVEL` is not specified. 668*08b48e0bSAndroid Build Coastguard Worker 669*08b48e0bSAndroid Build Coastguard Worker - With `AFL_QEMU_FORCE_DFL`, you force QEMU to ignore the registered signal 670*08b48e0bSAndroid Build Coastguard Worker handlers of the target. 671*08b48e0bSAndroid Build Coastguard Worker 672*08b48e0bSAndroid Build Coastguard Worker - When the target is i386/x86_64, you can specify the address of the function 673*08b48e0bSAndroid Build Coastguard Worker that has to be the body of the persistent loop using 674*08b48e0bSAndroid Build Coastguard Worker `AFL_QEMU_PERSISTENT_ADDR=start addr`. 675*08b48e0bSAndroid Build Coastguard Worker 676*08b48e0bSAndroid Build Coastguard Worker - With `AFL_QEMU_PERSISTENT_GPR=1`, QEMU will save the original value of 677*08b48e0bSAndroid Build Coastguard Worker general purpose registers and restore them in each persistent cycle. 678*08b48e0bSAndroid Build Coastguard Worker 679*08b48e0bSAndroid Build Coastguard Worker - Another modality to execute the persistent loop is to specify also the 680*08b48e0bSAndroid Build Coastguard Worker `AFL_QEMU_PERSISTENT_RET=end addr` environment variable. With this variable 681*08b48e0bSAndroid Build Coastguard Worker assigned, instead of patching the return address, the specified instruction 682*08b48e0bSAndroid Build Coastguard Worker is transformed to a jump towards `start addr`. 683*08b48e0bSAndroid Build Coastguard Worker 684*08b48e0bSAndroid Build Coastguard Worker - With `AFL_QEMU_PERSISTENT_RETADDR_OFFSET`, you can specify the offset from 685*08b48e0bSAndroid Build Coastguard Worker the stack pointer in which QEMU can find the return address when `start 686*08b48e0bSAndroid Build Coastguard Worker addr` is hit. 687*08b48e0bSAndroid Build Coastguard Worker 688*08b48e0bSAndroid Build Coastguard Worker - With `AFL_USE_QASAN`, you can enable QEMU AddressSanitizer for dynamically 689*08b48e0bSAndroid Build Coastguard Worker linked binaries. 690*08b48e0bSAndroid Build Coastguard Worker 691*08b48e0bSAndroid Build Coastguard Worker - The underlying QEMU binary will recognize any standard "user space 692*08b48e0bSAndroid Build Coastguard Worker emulation" variables (e.g., `QEMU_STACK_SIZE`), but there should be no 693*08b48e0bSAndroid Build Coastguard Worker reason to touch them. 694*08b48e0bSAndroid Build Coastguard Worker 695*08b48e0bSAndroid Build Coastguard Worker - Normally a `README.txt` is written to the `crashes/` directory when a first 696*08b48e0bSAndroid Build Coastguard Worker crash is found. Setting `AFL_NO_CRASH_README` will prevent this. Useful when 697*08b48e0bSAndroid Build Coastguard Worker counting crashes based on a file count in that directory. 698*08b48e0bSAndroid Build Coastguard Worker 699*08b48e0bSAndroid Build Coastguard Worker## 7) Settings for afl-frida-trace 700*08b48e0bSAndroid Build Coastguard Worker 701*08b48e0bSAndroid Build Coastguard WorkerThe FRIDA wrapper used to instrument binary-only code supports many of the same 702*08b48e0bSAndroid Build Coastguard Workeroptions as `afl-qemu-trace`, but also has a number of additional advanced 703*08b48e0bSAndroid Build Coastguard Workeroptions. These are listed in brief below (see 704*08b48e0bSAndroid Build Coastguard Worker[frida_mode/README.md](../frida_mode/README.md) for more details). These 705*08b48e0bSAndroid Build Coastguard Workersettings are provided for compatibility with QEMU mode, the preferred way to 706*08b48e0bSAndroid Build Coastguard Workerconfigure FRIDA mode is through its [scripting](../frida_mode/Scripting.md) 707*08b48e0bSAndroid Build Coastguard Workersupport. 708*08b48e0bSAndroid Build Coastguard Worker 709*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_DEBUG_MAPS` - See `AFL_QEMU_DEBUG_MAPS` 710*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_DRIVER_NO_HOOK` - See `AFL_QEMU_DRIVER_NO_HOOK`. When using the 711*08b48e0bSAndroid Build Coastguard Worker QEMU driver to provide a `main` loop for a user provided 712*08b48e0bSAndroid Build Coastguard Worker `LLVMFuzzerTestOneInput`, this option configures the driver to read input from 713*08b48e0bSAndroid Build Coastguard Worker `stdin` rather than using in-memory test cases. 714*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_EXCLUDE_RANGES` - See `AFL_QEMU_EXCLUDE_RANGES` 715*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_COVERAGE_FILE` - File to write DynamoRio format coverage 716*08b48e0bSAndroid Build Coastguard Worker information (e.g., to be loaded within IDA lighthouse). 717*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_DEBUG_FILE` - File to write raw assembly of original blocks 718*08b48e0bSAndroid Build Coastguard Worker and their instrumented counterparts during block compilation. 719*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_JIT` - Enable the instrumentation of Just-In-Time compiled 720*08b48e0bSAndroid Build Coastguard Worker code. Code is considered to be JIT if the executable segment is not backed by 721*08b48e0bSAndroid Build Coastguard Worker a file. 722*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_NO_DYNAMIC_LOAD` - Don't instrument the code loaded late at 723*08b48e0bSAndroid Build Coastguard Worker runtime. Strictly limits instrumentation to what has been included. 724*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_NO_OPTIMIZE` - Don't use optimized inline assembly coverage 725*08b48e0bSAndroid Build Coastguard Worker instrumentation (the default where available). Required to use 726*08b48e0bSAndroid Build Coastguard Worker `AFL_FRIDA_INST_TRACE`. 727*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_NO_BACKPATCH` - Disable backpatching. At the end of executing 728*08b48e0bSAndroid Build Coastguard Worker each block, control will return to FRIDA to identify the next block to 729*08b48e0bSAndroid Build Coastguard Worker execute. 730*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_NO_PREFETCH` - Disable prefetching. By default, the child will 731*08b48e0bSAndroid Build Coastguard Worker report instrumented blocks back to the parent so that it can also instrument 732*08b48e0bSAndroid Build Coastguard Worker them and they be inherited by the next child on fork, implies 733*08b48e0bSAndroid Build Coastguard Worker `AFL_FRIDA_INST_NO_PREFETCH_BACKPATCH`. 734*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_NO_PREFETCH_BACKPATCH` - Disable prefetching of stalker 735*08b48e0bSAndroid Build Coastguard Worker backpatching information. By default, the child will report applied 736*08b48e0bSAndroid Build Coastguard Worker backpatches to the parent so that they can be applied and then be inherited by 737*08b48e0bSAndroid Build Coastguard Worker the next child on fork. 738*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_RANGES` - See `AFL_QEMU_INST_RANGES` 739*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_SEED` - Sets the initial seed for the hash function used to 740*08b48e0bSAndroid Build Coastguard Worker generate block (and hence edge) IDs. Setting this to a constant value may be 741*08b48e0bSAndroid Build Coastguard Worker useful for debugging purposes, e.g., investigating unstable edges. 742*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_TRACE` - Log to stdout the address of executed blocks, implies 743*08b48e0bSAndroid Build Coastguard Worker `AFL_FRIDA_INST_NO_OPTIMIZE`. 744*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_TRACE_UNIQUE` - As per `AFL_FRIDA_INST_TRACE`, but each edge 745*08b48e0bSAndroid Build Coastguard Worker is logged only once, requires `AFL_FRIDA_INST_NO_OPTIMIZE`. 746*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_INST_UNSTABLE_COVERAGE_FILE` - File to write DynamoRio format 747*08b48e0bSAndroid Build Coastguard Worker coverage information for unstable edges (e.g., to be loaded within IDA 748*08b48e0bSAndroid Build Coastguard Worker lighthouse). 749*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_JS_SCRIPT` - Set the script to be loaded by the FRIDA scripting 750*08b48e0bSAndroid Build Coastguard Worker engine. See [frida_mode/Scripting.md](../frida_mode/Scripting.md) for details. 751*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_OUTPUT_STDOUT` - Redirect the standard output of the target 752*08b48e0bSAndroid Build Coastguard Worker application to the named file (supersedes the setting of `AFL_DEBUG_CHILD`) 753*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_OUTPUT_STDERR` - Redirect the standard error of the target 754*08b48e0bSAndroid Build Coastguard Worker application to the named file (supersedes the setting of `AFL_DEBUG_CHILD`) 755*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_PERSISTENT_ADDR` - See `AFL_QEMU_PERSISTENT_ADDR` 756*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_PERSISTENT_CNT` - See `AFL_QEMU_PERSISTENT_CNT` 757*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_PERSISTENT_DEBUG` - Insert a Breakpoint into the instrumented code 758*08b48e0bSAndroid Build Coastguard Worker at `AFL_FRIDA_PERSISTENT_HOOK` and `AFL_FRIDA_PERSISTENT_RET` to allow the 759*08b48e0bSAndroid Build Coastguard Worker user to detect issues in the persistent loop using a debugger. 760*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_PERSISTENT_HOOK` - See `AFL_QEMU_PERSISTENT_HOOK` 761*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_PERSISTENT_RET` - See `AFL_QEMU_PERSISTENT_RET` 762*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_SECCOMP_FILE` - Write a log of any syscalls made by the target to 763*08b48e0bSAndroid Build Coastguard Worker the specified file. 764*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_STALKER_ADJACENT_BLOCKS` - Configure the number of adjacent blocks 765*08b48e0bSAndroid Build Coastguard Worker to fetch when generating instrumented code. By fetching blocks in the same 766*08b48e0bSAndroid Build Coastguard Worker order they appear in the original program, rather than the order of execution 767*08b48e0bSAndroid Build Coastguard Worker should help reduce locality and adjacency. This includes allowing us to 768*08b48e0bSAndroid Build Coastguard Worker vector between adjacent blocks using a NOP slide rather than an immediate 769*08b48e0bSAndroid Build Coastguard Worker branch. 770*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_STALKER_IC_ENTRIES` - Configure the number of inline cache entries 771*08b48e0bSAndroid Build Coastguard Worker stored along-side branch instructions which provide a cache to avoid having to 772*08b48e0bSAndroid Build Coastguard Worker call back into FRIDA to find the next block. Default is 32. 773*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_STATS_FILE` - Write statistics information about the code being 774*08b48e0bSAndroid Build Coastguard Worker instrumented to the given file name. The statistics are written only for the 775*08b48e0bSAndroid Build Coastguard Worker child process when new block is instrumented (when the 776*08b48e0bSAndroid Build Coastguard Worker `AFL_FRIDA_STATS_INTERVAL` has expired). Note that just because a new path is 777*08b48e0bSAndroid Build Coastguard Worker found does not mean a new block needs to be compiled. It could be that the 778*08b48e0bSAndroid Build Coastguard Worker existing blocks instrumented have been executed in a different order. 779*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_STATS_INTERVAL` - The maximum frequency to output statistics 780*08b48e0bSAndroid Build Coastguard Worker information. Stats will be written whenever they are updated if the given 781*08b48e0bSAndroid Build Coastguard Worker interval has elapsed since last time they were written. 782*08b48e0bSAndroid Build Coastguard Worker* `AFL_FRIDA_TRACEABLE` - Set the child process to be traceable by any process 783*08b48e0bSAndroid Build Coastguard Worker to aid debugging and overcome the restrictions imposed by YAMA. Supported on 784*08b48e0bSAndroid Build Coastguard Worker Linux only. Permits a non-root user to use `gcore` or similar to collect a 785*08b48e0bSAndroid Build Coastguard Worker core dump of the instrumented target. Note that in order to capture the core 786*08b48e0bSAndroid Build Coastguard Worker dump you must set a sufficient timeout (using `-t`) to avoid `afl-fuzz` 787*08b48e0bSAndroid Build Coastguard Worker killing the process whilst it is being dumped. 788*08b48e0bSAndroid Build Coastguard Worker 789*08b48e0bSAndroid Build Coastguard Worker## 8) Settings for afl-cmin 790*08b48e0bSAndroid Build Coastguard Worker 791*08b48e0bSAndroid Build Coastguard WorkerThe corpus minimization script offers very little customization: 792*08b48e0bSAndroid Build Coastguard Worker 793*08b48e0bSAndroid Build Coastguard Worker - `AFL_ALLOW_TMP` permits this and some other scripts to run in /tmp. This is 794*08b48e0bSAndroid Build Coastguard Worker a modest security risk on multi-user systems with rogue users, but should be 795*08b48e0bSAndroid Build Coastguard Worker safe on dedicated fuzzing boxes. 796*08b48e0bSAndroid Build Coastguard Worker 797*08b48e0bSAndroid Build Coastguard Worker - `AFL_KEEP_TRACES` makes the tool keep traces and other metadata used for 798*08b48e0bSAndroid Build Coastguard Worker minimization and normally deleted at exit. The files can be found in the 799*08b48e0bSAndroid Build Coastguard Worker `<out_dir>/.traces/` directory. 800*08b48e0bSAndroid Build Coastguard Worker 801*08b48e0bSAndroid Build Coastguard Worker - Setting `AFL_PATH` offers a way to specify the location of afl-showmap and 802*08b48e0bSAndroid Build Coastguard Worker afl-qemu-trace (the latter only in `-Q` mode). 803*08b48e0bSAndroid Build Coastguard Worker 804*08b48e0bSAndroid Build Coastguard Worker - `AFL_PRINT_FILENAMES` prints each filename to stdout, as it gets processed. 805*08b48e0bSAndroid Build Coastguard Worker This can help when embedding `afl-cmin` or `afl-showmap` in other scripts. 806*08b48e0bSAndroid Build Coastguard Worker 807*08b48e0bSAndroid Build Coastguard Worker## 9) Settings for afl-tmin 808*08b48e0bSAndroid Build Coastguard Worker 809*08b48e0bSAndroid Build Coastguard WorkerVirtually nothing to play with. Well, in QEMU mode (`-Q`), `AFL_PATH` will be 810*08b48e0bSAndroid Build Coastguard Workersearched for afl-qemu-trace. In addition to this, `TMPDIR` may be used if a 811*08b48e0bSAndroid Build Coastguard Workertemporary file can't be created in the current working directory. 812*08b48e0bSAndroid Build Coastguard Worker 813*08b48e0bSAndroid Build Coastguard WorkerYou can specify `AFL_TMIN_EXACT` if you want afl-tmin to require execution paths 814*08b48e0bSAndroid Build Coastguard Workerto match when minimizing crashes. This will make minimization less useful, but 815*08b48e0bSAndroid Build Coastguard Workermay prevent the tool from "jumping" from one crashing condition to another in 816*08b48e0bSAndroid Build Coastguard Workervery buggy software. You probably want to combine it with the `-e` flag. 817*08b48e0bSAndroid Build Coastguard Worker 818*08b48e0bSAndroid Build Coastguard Worker## 10) Settings for afl-analyze 819*08b48e0bSAndroid Build Coastguard Worker 820*08b48e0bSAndroid Build Coastguard WorkerYou can set `AFL_ANALYZE_HEX` to get file offsets printed as hexadecimal instead 821*08b48e0bSAndroid Build Coastguard Workerof decimal. 822*08b48e0bSAndroid Build Coastguard Worker 823*08b48e0bSAndroid Build Coastguard Worker## 11) Settings for libdislocator 824*08b48e0bSAndroid Build Coastguard Worker 825*08b48e0bSAndroid Build Coastguard WorkerThe library honors these environment variables: 826*08b48e0bSAndroid Build Coastguard Worker 827*08b48e0bSAndroid Build Coastguard Worker - `AFL_ALIGNED_ALLOC=1` will force the alignment of the allocation size to 828*08b48e0bSAndroid Build Coastguard Worker `max_align_t` to be compliant with the C standard. 829*08b48e0bSAndroid Build Coastguard Worker 830*08b48e0bSAndroid Build Coastguard Worker - `AFL_LD_HARD_FAIL` alters the behavior by calling `abort()` on excessive 831*08b48e0bSAndroid Build Coastguard Worker allocations, thus causing what AFL++ would perceive as a crash. Useful for 832*08b48e0bSAndroid Build Coastguard Worker programs that are supposed to maintain a specific memory footprint. 833*08b48e0bSAndroid Build Coastguard Worker 834*08b48e0bSAndroid Build Coastguard Worker - `AFL_LD_LIMIT_MB` caps the size of the maximum heap usage permitted by the 835*08b48e0bSAndroid Build Coastguard Worker library, in megabytes. The default value is 1 GB. Once this is exceeded, 836*08b48e0bSAndroid Build Coastguard Worker allocations will return NULL. 837*08b48e0bSAndroid Build Coastguard Worker 838*08b48e0bSAndroid Build Coastguard Worker - `AFL_LD_NO_CALLOC_OVER` inhibits `abort()` on `calloc()` overflows. Most of 839*08b48e0bSAndroid Build Coastguard Worker the common allocators check for that internally and return NULL, so it's a 840*08b48e0bSAndroid Build Coastguard Worker security risk only in more exotic setups. 841*08b48e0bSAndroid Build Coastguard Worker 842*08b48e0bSAndroid Build Coastguard Worker - `AFL_LD_VERBOSE` causes the library to output some diagnostic messages that 843*08b48e0bSAndroid Build Coastguard Worker may be useful for pinpointing the cause of any observed issues. 844*08b48e0bSAndroid Build Coastguard Worker 845*08b48e0bSAndroid Build Coastguard Worker## 11) Settings for libtokencap 846*08b48e0bSAndroid Build Coastguard Worker 847*08b48e0bSAndroid Build Coastguard WorkerThis library accepts `AFL_TOKEN_FILE` to indicate the location to which the 848*08b48e0bSAndroid Build Coastguard Workerdiscovered tokens should be written. 849*08b48e0bSAndroid Build Coastguard Worker 850*08b48e0bSAndroid Build Coastguard Worker## 12) Third-party variables set by afl-fuzz & other tools 851*08b48e0bSAndroid Build Coastguard Worker 852*08b48e0bSAndroid Build Coastguard WorkerSeveral variables are not directly interpreted by afl-fuzz, but are set to 853*08b48e0bSAndroid Build Coastguard Workeroptimal values if not already present in the environment: 854*08b48e0bSAndroid Build Coastguard Worker 855*08b48e0bSAndroid Build Coastguard Worker - By default, `ASAN_OPTIONS` are set to (among others): 856*08b48e0bSAndroid Build Coastguard Worker 857*08b48e0bSAndroid Build Coastguard Worker ``` 858*08b48e0bSAndroid Build Coastguard Worker abort_on_error=1 859*08b48e0bSAndroid Build Coastguard Worker detect_leaks=0 860*08b48e0bSAndroid Build Coastguard Worker malloc_context_size=0 861*08b48e0bSAndroid Build Coastguard Worker symbolize=0 862*08b48e0bSAndroid Build Coastguard Worker allocator_may_return_null=1 863*08b48e0bSAndroid Build Coastguard Worker ``` 864*08b48e0bSAndroid Build Coastguard Worker 865*08b48e0bSAndroid Build Coastguard Worker If you want to set your own options, be sure to include `abort_on_error=1` - 866*08b48e0bSAndroid Build Coastguard Worker otherwise, the fuzzer will not be able to detect crashes in the tested app. 867*08b48e0bSAndroid Build Coastguard Worker Similarly, include `symbolize=0`, since without it, AFL++ may have 868*08b48e0bSAndroid Build Coastguard Worker difficulty telling crashes and hangs apart. 869*08b48e0bSAndroid Build Coastguard Worker 870*08b48e0bSAndroid Build Coastguard Worker - Similarly, the default `LSAN_OPTIONS` are set to: 871*08b48e0bSAndroid Build Coastguard Worker 872*08b48e0bSAndroid Build Coastguard Worker ``` 873*08b48e0bSAndroid Build Coastguard Worker exit_code=23 874*08b48e0bSAndroid Build Coastguard Worker fast_unwind_on_malloc=0 875*08b48e0bSAndroid Build Coastguard Worker symbolize=0 876*08b48e0bSAndroid Build Coastguard Worker print_suppressions=0 877*08b48e0bSAndroid Build Coastguard Worker ``` 878*08b48e0bSAndroid Build Coastguard Worker 879*08b48e0bSAndroid Build Coastguard Worker Be sure to include the first ones for LSAN and MSAN when customizing 880*08b48e0bSAndroid Build Coastguard Worker anything, since some MSAN and LSAN versions don't call `abort()` on error, 881*08b48e0bSAndroid Build Coastguard Worker and we need a way to detect faults. 882*08b48e0bSAndroid Build Coastguard Worker 883*08b48e0bSAndroid Build Coastguard Worker - In the same vein, by default, `MSAN_OPTIONS` are set to: 884*08b48e0bSAndroid Build Coastguard Worker 885*08b48e0bSAndroid Build Coastguard Worker ``` 886*08b48e0bSAndroid Build Coastguard Worker exit_code=86 (required for legacy reasons) 887*08b48e0bSAndroid Build Coastguard Worker abort_on_error=1 888*08b48e0bSAndroid Build Coastguard Worker symbolize=0 889*08b48e0bSAndroid Build Coastguard Worker msan_track_origins=0 890*08b48e0bSAndroid Build Coastguard Worker allocator_may_return_null=1 891*08b48e0bSAndroid Build Coastguard Worker ``` 892*08b48e0bSAndroid Build Coastguard Worker 893*08b48e0bSAndroid Build Coastguard Worker - By default, `LD_BIND_NOW` is set to speed up fuzzing by forcing the linker 894*08b48e0bSAndroid Build Coastguard Worker to do all the work before the fork server kicks in. You can override this by 895*08b48e0bSAndroid Build Coastguard Worker setting `LD_BIND_LAZY` beforehand, but it is almost certainly pointless. 896