diff options
| author | Nathaniel Brough <[email protected]> | 2023-01-29 09:38:05 -0800 |
|---|---|---|
| committer | Nathaniel Brough <[email protected]> | 2023-01-29 09:38:05 -0800 |
| commit | 02f1f0569723611d591b8bdd72b12a084a4f39d0 (patch) | |
| tree | 6ea528dbf15a944bc3dcb41f384a0c9c1773fc8f | |
| parent | 8775d55adc7c9b0812b7d593b24518c046dd3d82 (diff) | |
feat(fuzz): Adds seed corpus for cdc and msc classes
| -rw-r--r-- | test/fuzz/device/cdc/cdc_seed_corpus.zip | bin | 0 -> 50127 bytes | |||
| -rw-r--r-- | test/fuzz/device/msc/msc_seed_corpus.zip | bin | 0 -> 50127 bytes | |||
| -rwxr-xr-x | tools/pcapng_to_corpus.py | 46 |
3 files changed, 46 insertions, 0 deletions
diff --git a/test/fuzz/device/cdc/cdc_seed_corpus.zip b/test/fuzz/device/cdc/cdc_seed_corpus.zip Binary files differnew file mode 100644 index 000000000..81bc2240d --- /dev/null +++ b/test/fuzz/device/cdc/cdc_seed_corpus.zip diff --git a/test/fuzz/device/msc/msc_seed_corpus.zip b/test/fuzz/device/msc/msc_seed_corpus.zip Binary files differnew file mode 100644 index 000000000..81bc2240d --- /dev/null +++ b/test/fuzz/device/msc/msc_seed_corpus.zip diff --git a/tools/pcapng_to_corpus.py b/tools/pcapng_to_corpus.py new file mode 100755 index 000000000..78b1f77a2 --- /dev/null +++ b/tools/pcapng_to_corpus.py @@ -0,0 +1,46 @@ +#!/bin/python3 +import argparse +import pcapng +import zipfile +import hashlib + +def extract_packets(pcap_file): + """Reads a wireshark packet capture and extracts the binary packets""" + packets = [] + with open(pcap_file, 'rb') as fp: + scanner = pcapng.FileScanner(fp) + for block in scanner: + if isinstance(block, pcapng.blocks.EnhancedPacket): + packets.append(block.packet_data) + return packets + +def build_corpus_zip(zip_file_output, packets): + """Builds a zip file with a file per packet + + The structure of this zip corpus is a simple content addressable storage + i.e. seed_file_name == sha256_digest(packet). + """ + with zipfile.ZipFile(zip_file_output, 'a') as out: + for packet in packets: + hash = hashlib.sha256(packet).hexdigest() + if hash not in out.namelist(): + out.writestr(hash, packet) + + +def main(pcap_file, output_zip_file): + packets = extract_packets(pcap_file) + build_corpus_zip(output_zip_file, packets) + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + prog = "pcapng_to_corpus.py", + description="""Converts a wireshark capture to a zip of binary packet + files suitable for an oss-fuzz corpus. In the case the + zip corpus already exists, this script will modify + the zip file in place adding seed entries.""") + parser.add_argument('pcapng_capture_file') + parser.add_argument('oss_fuzz_corpus_zip') + args = parser.parse_args() + main(args.pcapng_capture_file, args.oss_fuzz_corpus_zip) + + |
