fuzz: add a new fuzzer to test TLS certificates (#1901)
This commit is contained in:
+20
-3
@@ -1,4 +1,4 @@
|
||||
bin_PROGRAMS = fuzz_process_packet fuzz_ndpi_reader fuzz_ndpi_reader_alloc_fail fuzz_quic_get_crypto_data fuzz_config fuzz_community_id fuzz_serialization
|
||||
bin_PROGRAMS = fuzz_process_packet fuzz_ndpi_reader fuzz_ndpi_reader_alloc_fail fuzz_quic_get_crypto_data fuzz_config fuzz_community_id fuzz_serialization fuzz_tls_certificate
|
||||
#Alghoritms
|
||||
bin_PROGRAMS += fuzz_alg_bins fuzz_alg_hll fuzz_alg_hw_rsi_outliers_da fuzz_alg_jitter fuzz_alg_ses_des fuzz_alg_crc32_md5 fuzz_alg_bytestream
|
||||
#Data structures
|
||||
@@ -292,7 +292,18 @@ fuzz_libinjection_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CXX) @NDPI_CFLAGS@ $(AM_CXXFLAGS) $(CXXFLAGS) \
|
||||
$(fuzz_libinjection_LDFLAGS) @NDPI_LDFLAGS@ $(LDFLAGS) -o $@
|
||||
|
||||
|
||||
fuzz_tls_certificate_SOURCES = fuzz_tls_certificate.c fuzz_common_code.c
|
||||
fuzz_tls_certificate_CFLAGS = @NDPI_CFLAGS@ $(CXXFLAGS)
|
||||
fuzz_tls_certificate_LDADD = ../src/lib/libndpi.a $(ADDITIONAL_LIBS)
|
||||
fuzz_tls_certificate_LDFLAGS = $(LIBS)
|
||||
if HAS_FUZZLDFLAGS
|
||||
fuzz_tls_certificate_CFLAGS += $(LIB_FUZZING_ENGINE)
|
||||
fuzz_tls_certificate_LDFLAGS += $(LIB_FUZZING_ENGINE)
|
||||
endif
|
||||
# force usage of CXX for linker
|
||||
fuzz_tls_certificate_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CXX) @NDPI_CFLAGS@ $(AM_CXXFLAGS) $(CXXFLAGS) \
|
||||
$(fuzz_tls_certificate_LDFLAGS) @NDPI_LDFLAGS@ $(LDFLAGS) -o $@
|
||||
|
||||
# required for Google oss-fuzz
|
||||
# see https://github.com/google/oss-fuzz/tree/master/projects/ndpi
|
||||
@@ -389,8 +400,12 @@ files_corpus_fuzz_libinjection := $(wildcard corpus/fuzz_libinjection/*)
|
||||
fuzz_libinjection_seed_corpus.zip: $(files_corpus_fuzz_libinjection)
|
||||
zip -j fuzz_libinjection_seed_corpus.zip $(files_corpus_fuzz_libinjection)
|
||||
|
||||
files_corpus_fuzz_tls_certificate := $(wildcard corpus/fuzz_tls_certificate/*)
|
||||
|
||||
corpus: fuzz_ndpi_reader_seed_corpus.zip fuzz_ndpi_reader_alloc_fail_seed_corpus.zip fuzz_quic_get_crypto_data_seed_corpus.zip fuzz_config_seed_corpus.zip fuzz_ds_patricia_seed_corpus.zip fuzz_ds_ahocorasick_seed_corpus.zip fuzz_alg_ses_des_seed_corpus.zip fuzz_alg_hw_rsi_outliers_da_seed_corpus.zip fuzz_alg_bins_seed_corpus.zip fuzz_alg_hll_seed_corpus.zip fuzz_alg_jitter_seed_corpus.zip fuzz_ds_libcache_seed_corpus.zip fuzz_community_id_seed_corpus.zip fuzz_ds_tree_seed_corpus.zip fuzz_serialization_seed_corpus.zip fuzz_ds_ptree_seed_corpus.zip fuzz_alg_crc32_md5_seed_corpus.zip fuzz_alg_bytestream_seed_corpus.zip fuzz_libinjection_seed_corpus.zip
|
||||
fuzz_tls_certificate_seed_corpus.zip: $(files_corpus_fuzz_tls_certificate)
|
||||
zip -j fuzz_tls_certificate_seed_corpus.zip $(files_corpus_fuzz_tls_certificate)
|
||||
|
||||
corpus: fuzz_ndpi_reader_seed_corpus.zip fuzz_ndpi_reader_alloc_fail_seed_corpus.zip fuzz_quic_get_crypto_data_seed_corpus.zip fuzz_config_seed_corpus.zip fuzz_ds_patricia_seed_corpus.zip fuzz_ds_ahocorasick_seed_corpus.zip fuzz_alg_ses_des_seed_corpus.zip fuzz_alg_hw_rsi_outliers_da_seed_corpus.zip fuzz_alg_bins_seed_corpus.zip fuzz_alg_hll_seed_corpus.zip fuzz_alg_jitter_seed_corpus.zip fuzz_ds_libcache_seed_corpus.zip fuzz_community_id_seed_corpus.zip fuzz_ds_tree_seed_corpus.zip fuzz_serialization_seed_corpus.zip fuzz_ds_ptree_seed_corpus.zip fuzz_alg_crc32_md5_seed_corpus.zip fuzz_alg_bytestream_seed_corpus.zip fuzz_libinjection_seed_corpus.zip fuzz_tls_certificate_seed_corpus.zip
|
||||
|
||||
#Create dictionaries exactly as expected by oss-fuzz.
|
||||
#This way, if we need to change/update/add something,
|
||||
@@ -399,6 +414,7 @@ dictionaries:
|
||||
cp dictionary.dict fuzz_ndpi_reader.dict
|
||||
cp dictionary.dict fuzz_ndpi_reader_alloc_fail.dict
|
||||
cp dictionary.dict fuzz_process_packet.dict
|
||||
cp dictionary_tls_certificate.dict fuzz_tls_certificate.dict
|
||||
|
||||
distdir:
|
||||
find . -type d | xargs -I'{}' mkdir -p '$(distdir)/{}'
|
||||
@@ -413,6 +429,7 @@ distdir:
|
||||
-o -path './corpus/fuzz_serialization/*' \
|
||||
-o -path './corpus/fuzz_community_id/*' \
|
||||
-o -path './corpus/fuzz_libinjection/*' \
|
||||
-o -path './corpus/fuzz_tls_certificate/*' \
|
||||
-o -path './corpus/fuzz_alg_ses_des/*' \
|
||||
-o -path './corpus/fuzz_alg_bins/*' \
|
||||
-o -path './corpus/fuzz_alg_hll/*' \
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
�H�
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
�В0��В0
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
H
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
�H�,
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
0�В0��В00
|
||||
@@ -0,0 +1 @@
|
||||
H�
|
||||
@@ -0,0 +1,8 @@
|
||||
"\x55\x04\x03"
|
||||
"\x55\x04\x06"
|
||||
"\x55\x04\x07"
|
||||
"\x55\x04\x08"
|
||||
"\x55\x04\x0A"
|
||||
"\x55\x04\x0B"
|
||||
"\x30\x1E\x17"
|
||||
"\x55\x1D\x11"
|
||||
@@ -0,0 +1,47 @@
|
||||
#define NDPI_LIB_COMPILATION
|
||||
|
||||
#include "ndpi_api.h"
|
||||
#include "fuzz_common_code.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
u_int16_t p_offset, u_int16_t certificate_len);
|
||||
struct ndpi_tcphdr tcph;
|
||||
struct ndpi_iphdr iph;
|
||||
struct ndpi_ipv6hdr iphv6;
|
||||
|
||||
struct ndpi_detection_module_struct *ndpi_struct = NULL;
|
||||
struct ndpi_flow_struct *ndpi_flow = NULL;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
struct ndpi_packet_struct *packet;
|
||||
int is_ipv6;
|
||||
|
||||
if (ndpi_struct == NULL) {
|
||||
fuzz_init_detection_module(&ndpi_struct);
|
||||
ndpi_flow = ndpi_calloc(1, sizeof(struct ndpi_flow_struct));
|
||||
}
|
||||
|
||||
if(size == 0)
|
||||
return -1;
|
||||
|
||||
packet = &ndpi_struct->packet;
|
||||
packet->payload = data;
|
||||
packet->payload_packet_len = size;
|
||||
is_ipv6 = data[size - 1] % 5 ? 1 : 0; /* "Random" ipv4 vs ipv6 */
|
||||
packet->iphv6 = is_ipv6 ? &iphv6 : NULL;
|
||||
packet->iph = is_ipv6 ? NULL : &iph;
|
||||
packet->tcp = &tcph;
|
||||
|
||||
memset(ndpi_flow, 0, sizeof(struct ndpi_flow_struct));
|
||||
strcpy(ndpi_flow->host_server_name, "doh.opendns.com");
|
||||
ndpi_flow->detected_protocol_stack[0] = NDPI_PROTOCOL_TLS;
|
||||
|
||||
processCertificateElements(ndpi_struct, ndpi_flow, 0, size);
|
||||
ndpi_free_flow_data(ndpi_flow);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user