Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 02-Dec-2020 | - | ||||
corpus/ | H | 02-Dec-2020 | - | |||
dict/ | H | 02-Dec-2020 | - | |||
Makefile.frag | H A D | 02-Dec-2020 | 1.3 KiB | 25 | 16 | |
README.md | H A D | 02-Dec-2020 | 2.8 KiB | 78 | 59 | |
config.m4 | H A D | 02-Dec-2020 | 3.2 KiB | 94 | 79 | |
fuzzer-execute.c | H A D | 02-Dec-2020 | 2.9 KiB | 91 | 47 | |
fuzzer-exif.c | H A D | 02-Dec-2020 | 2.1 KiB | 73 | 38 | |
fuzzer-json.c | H A D | 02-Dec-2020 | 1.9 KiB | 63 | 32 | |
fuzzer-mbstring.c | H A D | 02-Dec-2020 | 2.2 KiB | 79 | 44 | |
fuzzer-parser.c | H A D | 02-Dec-2020 | 1.8 KiB | 50 | 20 | |
fuzzer-sapi.c | H A D | 02-Dec-2020 | 8 KiB | 305 | 200 | |
fuzzer-sapi.h | H A D | 02-Dec-2020 | 1.4 KiB | 26 | 8 | |
fuzzer-unserialize.c | H A D | 02-Dec-2020 | 1.9 KiB | 68 | 35 | |
fuzzer-unserializehash.c | H A D | 02-Dec-2020 | 2.3 KiB | 83 | 50 | |
fuzzer.h | H A D | 02-Dec-2020 | 1 KiB | 19 | 2 | |
generate_all.php | H A D | 02-Dec-2020 | 215 | 6 | 5 | |
generate_execute_corpus.php | H A D | 02-Dec-2020 | 982 | 39 | 33 | |
generate_parser_corpus.php | H A D | 02-Dec-2020 | 717 | 25 | 20 | |
generate_unserialize_dict.php | H A D | 02-Dec-2020 | 193 | 10 | 7 | |
generate_unserializehash_corpus.php | H A D | 02-Dec-2020 | 274 | 11 | 8 | |
json.dict | H A D | 02-Dec-2020 | 416 | 53 | 45 |
README.md
1Fuzzing SAPI for PHP 2-------------------- 3 4The following `./configure` options can be used to enable the fuzzing SAPI, as well as all availablefuzzers. If you don't build the exif/json/mbstring extensions, fuzzers for these extensions will not be built. 5 6```sh 7CC=clang CXX=clang++ \ 8./configure \ 9 --disable-all \ 10 --enable-fuzzer \ 11 --with-pic \ 12 --enable-debug-assertions \ 13 --enable-exif \ 14 --enable-mbstring 15``` 16 17The `--with-pic` option is required to avoid a linking failure. The `--enable-debug-assertions` option can be used to enable debug assertions despite the use of a release build. 18 19You will need a recent version of clang that supports the `-fsanitize=fuzzer-no-link` option. 20 21When running `make` it creates these binaries in `sapi/fuzzer/`: 22 23* `php-fuzz-parser`: Fuzzing language parser and compiler 24* `php-fuzz-unserialize`: Fuzzing unserialize() function 25* `php-fuzz-unserializehash`: Fuzzing unserialize() for HashContext objects 26* `php-fuzz-json`: Fuzzing JSON parser (requires --enable-json) 27* `php-fuzz-exif`: Fuzzing `exif_read_data()` function (requires --enable-exif) 28* `php-fuzz-mbstring`: Fuzzing `mb_ereg[i]()` (requires --enable-mbstring) 29* `php-fuzz-execute`: Fuzzing the executor 30 31Some fuzzers have a seed corpus in `sapi/fuzzer/corpus`. You can use it as follows: 32 33```sh 34cp -r sapi/fuzzer/corpus/exif ./my-exif-corpus 35sapi/fuzzer/php-fuzz-exif ./my-exif-corpus 36``` 37 38For the unserialize fuzzer, a dictionary of internal classes should be generated first: 39 40```sh 41sapi/cli/php sapi/fuzzer/generate_unserialize_dict.php 42cp -r sapi/fuzzer/corpus/unserialize ./my-unserialize-corpus 43sapi/fuzzer/php-fuzz-unserialize -dict=$PWD/sapi/fuzzer/dict/unserialize ./my-unserialize-corpus 44``` 45 46For the unserializehash fuzzer, generate a corpus of initial hash serializations: 47 48```sh 49sapi/cli/php sapi/fuzzer/generate_unserializehash_corpus.php 50cp -r sapi/fuzzer/corpus/unserializehash ./my-unserialize-corpus 51sapi/fuzzer/php-fuzz-unserializehash ./my-unserialize-corpus 52``` 53 54For the parser fuzzer, a corpus may be generated from Zend test files: 55 56```sh 57sapi/cli/php sapi/fuzzer/generate_parser_corpus.php 58mkdir ./my-parser-corpus 59sapi/fuzzer/php-fuzz-parser -merge=1 ./my-parser-corpus sapi/fuzzer/corpus/parser 60sapi/fuzzer/php-fuzz-parser -only_ascii=1 ./my-parser-corpus 61``` 62 63For the mbstring fuzzer, you may want to build the libonig dependency with instrumentation. At this time, libonig is not clean under ubsan, so only the fuzzer and address sanitizers may be used. 64 65```sh 66git clone https://github.com/kkos/oniguruma.git 67pushd oniguruma 68autoreconf -vfi 69./configure CC=clang CFLAGS="-fsanitize=fuzzer-no-link,address -O2 -g" 70make 71popd 72 73export ONIG_CFLAGS="-I$PWD/oniguruma/src" 74export ONIG_LIBS="-L$PWD/oniguruma/src/.libs -l:libonig.a" 75``` 76 77This will link an instrumented libonig statically into the PHP binary. 78