
A Not So Very Intelligent Fuzzer: Un framework avanzato di fuzzing progettato per trovare vulnerabilità nel codice C/C++.
Un Fuzzer Non Molto Intelligente
Marshall Whittaker oxagast [email protected]
Man mano che la complessità di un sistema aumenta, aumenta anche il potenziale di problemi all'interno di quel sistema.
--Legge di Whittaker
Dipendenze di compilazione:
automake autoconf-archive zlib1g-dev g++ gcc (e libgtk2.0-dev se vuoi il supporto GTK)
Compilazione:
Linux:
$ aclocal && autoconf && automake -a && ./configure && make && make check
Oppure, se vuoi giocare con il fuzzer di syscall:
$ aclocal && autoconf && automake -a && ./configure --enable-syscalls && make && make check
Se vuoi disabilitare l'interfaccia GTK puoi fare:
$ aclocal && autoconf && automake -a && ./configure --disable-gtk && make && make check
FreeBSD
Supponendo che tu abbia installato g++ dai ports (come ti servirà per C++11):
$ aclocal && autoconf && automake -a && ./configure && make && make check
OpenBSD:
Supponendo che tu abbia installato g++ dai ports (come ti servirà per C++11):
$ CXX=$(find / -name 'eg++' 2>/dev/null | grep ports | head -n 1) AUTOCONF_VERSION=2.69 AUTOMAKE_VERSION=1.15 autoreconf -fmi
Windows:
I binari per Windows sono ora progettati per essere compilati con MinGW-W64 (poiché usiamo threading, scarica una versione di MinGW-W64 g++ con seh). Puoi provare a compilare dopo aver installato MinGW-W64 g++ con seh (solo) facendo clic sul script make_win.bat incluso. Se fallisce, probabilmente è dovuto all'ambiente, quindi prova il metodo seguente.
(Vai dove hai installato MinGW-W64 e fai clic su mingw-64.bat)
windres metadata.rc -O coff -o metadata.res
g++.exe src/common.cpp src/bin2hex.cpp src/popen2.cpp src/main.cpp src/help.cpp src/match_fault.cpp src/sys_string.cpp src/man_read.cpp src/randomizer.cpp src/trash.cpp src/log.cpp metadata.res src/version.h -I./ -I./include -std=c++11 -lstdc++ -lpthread -O2 -o ansvif.exe -static -static-libgcc -static-libstdc++
gcc src/win/printf.c -o printf.exe
Nota: i file esterni cygwin .dll non sono più necessari poiché ora compiliamo con g++ di MinGW. In Windows 7, Powershell v2 è installato per impostazione predefinita, tuttavia questo programma richiede almeno Powershell v5. Windows 10 include Powershell v5. Puoi andare sul sito di Microsoft e scaricare il Windows Management Framework (che include versioni più recenti di Powershell qui:
https://www.microsoft.com/en-us/download/details.aspx?id=50395
Test:
Se vuoi provare il codice di esempio, puoi compilare faulty.c con:
$ gcc faulty.c -o faulty
Puoi anche semplicemente eseguire make check.
Utilizzo:
Nota importante: gli utenti Windows dovranno eseguire ansvif.exe da Powershell per farlo funzionare!
$ ./find_suid /usr/bin/ /bin/ /sbin/
$ ./ansvif -[tm] [template/manpage] -c /path/to/executable -b buffersize
Esempi:
Linux/BSD:
$ ulimit -c unlimited
$ ./ansvif -m mount -c /bin/mount -e examples/mount_e.txt -x examples/mount_o.txt\
-f 8 -b 2048
$ ./ansvif -t examples/blank.txt -F tmp/tmphtml -x examples/htmltags.txt -c /usr/bin/iceweasel -b\
128 -A "file:///home/username/src/ansvif/tmp/tmphtml" -f 2 -n -R "sleep 3 && killall\
iceweasel" -S ">"
$ cat examples/linux_syscalls_implemented.list | xargs -P \
`cat examples/linux_syscalls_implemented.list | wc -l` -I {calls} ./ansvif -t examples/space.txt \
-B "{calls} " -c ./syscalls -o syscall_crash -f 1 -z -d -b 16
Windows:
PS C:\ansvif\bin\ansvif_win> .\ansvif -t ..\..\examples\space -F ..\..\tmp\tmphtml -x `
..\..\examples\htmltags -c `
'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' `
-b 128 -A "file:///C:\\Users\marsh\OneDrive\Documents\Code\ansvif\tmp\tmphtml" `
-f 2 -n -S ">" -R "sleep 2 ; Stop-Process -Name chrome"
Opzioni:
ansvif
-t This file should hold line by line command arguments as shown in the example file.
-e This file should hold line by line environment variables as shown in the example
file. You can usually get these by doing something like:
$ strings /bin/mount | perl -ne 'print if /[A-Z]=$/' > mount_envs
-c Specifies the command path.
-p Specifies the manpage location (as an integer, usually 1 or 8)
-m Specifies the commands manpage.
-D Dumps whats found in the manpage.
-f Number of threads to use. Default is 2.
-b Specifies the buffer size to fuzz with. 256-2048 Is usually sufficient.
-r Uses only random garbage data.
-o Writes output to log file.
-z Randomize the buffer size from 1 to what is specified by -b.
-x Other junk to put in. Usernames and such can go here.
-S Seperator between options.
-s Omitted character specification. Defaults are <>\\n |&\[]\()\{}:;\ and newline is mandatory.
-T Timeout for threads.
-W Timeout for threads.
-L Unpriviledged user to run as if root.
-A Always put whats after this after command to run.
-B Always put whats after this before the command to run.
-F File to feed into the program that -x along with normal fuzzing data will be put in.
-n Never use random data in the fuzz.
-R Run this command after each fuzz.
-C A Non standard error code to detect.
-V Use Valgrind if installed.
-1 Try to make it fault once, if it doesn't happen, throw error code 64. Useful for scripting.
-P Use % to represent binary in fuzz.
-M Max arguments to use in the fuzz.
-y Short for -b 0 and usually only useful with -A or -B.
-K Keep fuzzing after a crash in the target.
-E A command to be run before the fuzzed program.
-0 No NULL characters in the fuzz.
-N Shorthand for -R "pkill prog".
-v Verbose.
-d Debug data.
-h Shows the help page.
-i Prints version information.
ansvif_gtk
-l Shortcut for -p ./ansvif
-p The location of the ansvif binary
Raccomandazioni: Si consiglia che se si eseguono fuzz lunghi o fuzzing di file, se possibile mettere i file (incluso il binario che si sta fuzzando, se possibile) in memoria. Ciò significa metterli da qualche parte come /var/run/shm dove l'usura del disco sarà minima e il fuzzing sarà un po' più veloce, specialmente se vengono gestiti file grandi. Tuttavia, attenzione: perderai i file fuzzati se sono in shm e riavvii la macchina!
NON ESGUERE QUESTO CODICE IN UN AMBIENTE DI PRODUZIONE! Se provi a impostare l'output di faulty.c su suid(0), allora PER FAVORE fallo in una macchina virtuale. O almeno in una macchina di cui non ti importa. Per il resto, gioca e divertiti!
Note:
Gli utenti Windows devono eseguire ansvif da Powershell. Il codice Linux e Windows dovrebbe essere relativamente stabile. Il fuzzing di syscall su Linux è in fase di sviluppo intenso.
Ringraziamenti
Grazie a dll999 per le idee sul fuzzing di syscall. Grazie a moo di #2600 su 2600net per alcuni consigli nella stesura della wiki. Grazie a chissà quante persone su IRC e StackOverflow. Grazie a DarkSt0rm per aver corretto un bug nel Makefile.