mbedtls/programs/fuzz
Gilles Peskine 7f72a06e02 Remove cruft
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-02-22 18:41:25 +01:00
..
corpuses
.gitignore pkcs7: provide fuzz harness 2022-09-01 19:45:41 -05:00
CMakeLists.txt Refactor common PThreads CMake code 2024-01-24 18:05:53 +00:00
common.c Fix warnings from clang-16 2023-07-26 17:11:51 +01:00
common.h Fix warnings from clang-16 2023-07-26 17:11:51 +01:00
fuzz_client.c Remove cruft 2024-02-22 18:41:25 +01:00
fuzz_client.options
fuzz_dtlsclient.c Remove cruft 2024-02-22 18:41:25 +01:00
fuzz_dtlsclient.options
fuzz_dtlsserver.c fuzz_dtlsserver: explicitly note the one access to a private field 2024-02-22 12:07:09 +01:00
fuzz_dtlsserver.options
fuzz_pkcs7.c Switch to the new code style 2023-01-11 14:50:10 +01:00
fuzz_pkcs7.options pkcs7: provide fuzz harness 2022-09-01 19:45:41 -05:00
fuzz_privkey.c fuzz_pubkey, fuzz_privkey: no real need to access private fields 2024-02-22 12:05:35 +01:00
fuzz_privkey.options
fuzz_pubkey.c fuzz_pubkey, fuzz_privkey: no real need to access private fields 2024-02-22 12:05:35 +01:00
fuzz_pubkey.options
fuzz_server.c Remove cruft 2024-02-22 18:41:25 +01:00
fuzz_server.options
fuzz_x509crl.c Remove cruft 2024-02-22 18:41:25 +01:00
fuzz_x509crl.options
fuzz_x509crt.c Remove cruft 2024-02-22 18:41:25 +01:00
fuzz_x509crt.options
fuzz_x509csr.c Remove cruft 2024-02-22 18:41:25 +01:00
fuzz_x509csr.options
Makefile Remove unneeded lines from fuzz/Makefile 2024-01-19 16:41:05 +00:00
onefile.c Fuzz programs: print an error if loading the reproducer fails 2023-05-12 13:18:08 +02:00
README.md

What is it?

This directory contains fuzz targets. Fuzz targets are simple codes using the library. They are used with a so-called fuzz driver, which will generate inputs, try to process them with the fuzz target, and alert in case of an unwanted behavior (such as a buffer overflow for instance).

These targets were meant to be used with oss-fuzz but can be used in other contexts.

This code was contributed by Philippe Antoine ( Catena cyber ).

How to run?

To run the fuzz targets like oss-fuzz:

git clone https://github.com/google/oss-fuzz
cd oss-fuzz
python infra/helper.py build_image mbedtls
python infra/helper.py build_fuzzers --sanitizer address mbedtls
python infra/helper.py run_fuzzer mbedtls fuzz_client

You can use undefined sanitizer as well as address sanitizer. And you can run any of the fuzz targets like fuzz_client.

To run the fuzz targets without oss-fuzz, you first need to install one libFuzzingEngine (libFuzzer for instance). Then you need to compile the code with the compiler flags of the wished sanitizer.

perl scripts/config.py set MBEDTLS_PLATFORM_TIME_ALT
mkdir build
cd build
cmake ..
make

Finally, you can run the targets like ./test/fuzz/fuzz_client.

Corpus generation for network traffic targets

These targets use network traffic as inputs :

  • client : simulates a client against (fuzzed) server traffic
  • server : simulates a server against (fuzzed) client traffic
  • dtls_client
  • dtls_server

They also use the last bytes as configuration options.

To generate corpus for these targets, you can do the following, not fully automated steps :

  • Build mbedtls programs ssl_server2 and ssl_client2
  • Run them one against the other with reproducible option turned on while capturing traffic into test.pcap
  • Extract tcp payloads, for instance with tshark : tshark -Tfields -e tcp.dstport -e tcp.payload -r test.pcap > test.txt
  • Run a dummy python script to output either client or server corpus file like python dummy.py test.txt > test.cor
  • Finally, you can add the options by appending the last bytes to the file test.cor

Here is an example of dummy.py for extracting payload from client to server (if we used tcp.dstport in tshark command)

import sys
import binascii

f = open(sys.argv[1])
for l in f.readlines():
    portAndPl=l.split()
    if len(portAndPl) == 2:
        # determine client or server based on port
        if portAndPl[0] == "4433":
            print(binascii.unhexlify(portAndPl[1].replace(":","")))