Add a new fuzzer for QUIC (#1800)

QUIC packets are encrypted/obfuscated; that means that we need to
decrypt them before parsing the real (TLS) message.
Fuzzing is not effective here, since a random buffer is hardly a valid
encrypted QUIC packet.

Add a new fuzzer, testing *decrypted* QUIC packets.

Add a basic corpus.

Fix a few bugs already found by this fuzzer.
This commit is contained in:
Ivan Nardi
2022-12-01 12:21:04 +01:00
committed by GitHub
parent afb5c3e6ba
commit 02e7e3c23b
13 changed files with 194 additions and 19 deletions
+18 -17
View File
@@ -172,7 +172,7 @@ static int is_version_with_encrypted_header(uint32_t version)
((version & 0xFFFFFF00) == 0x51303500) /* Q05X */ ||
((version & 0xFFFFFF00) == 0x54303500) /* T05X */;
}
static int is_version_with_tls(uint32_t version)
int is_version_with_tls(uint32_t version)
{
return is_version_quic(version) ||
((version & 0xFFFFFF00) == 0x54303500) /* T05X */;
@@ -1126,11 +1126,11 @@ static const uint8_t *get_reassembled_crypto_data(struct ndpi_detection_module_s
return NULL;
}
static const uint8_t *get_crypto_data(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
uint32_t version,
u_int8_t *clear_payload, uint32_t clear_payload_len,
uint64_t *crypto_data_len)
const uint8_t *get_crypto_data(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
uint32_t version,
u_int8_t *clear_payload, uint32_t clear_payload_len,
uint64_t *crypto_data_len)
{
const u_int8_t *crypto_data = NULL;
uint32_t counter;
@@ -1222,12 +1222,12 @@ static const uint8_t *get_crypto_data(struct ndpi_detection_module_struct *ndpi_
case 0x06:
NDPI_LOG_DBG2(ndpi_struct, "CRYPTO frame\n");
counter += 1;
if(counter > clear_payload_len ||
counter + quic_len_buffer_still_required(clear_payload[counter]) > clear_payload_len)
if(counter >= clear_payload_len ||
counter + quic_len_buffer_still_required(clear_payload[counter]) >= clear_payload_len)
return NULL;
counter += quic_len(&clear_payload[counter], &frag_offset);
if(counter > clear_payload_len ||
counter + quic_len_buffer_still_required(clear_payload[counter]) > clear_payload_len)
if(counter >= clear_payload_len ||
counter + quic_len_buffer_still_required(clear_payload[counter]) >= clear_payload_len)
return NULL;
counter += quic_len(&clear_payload[counter], &frag_len);
if(frag_len + counter > clear_payload_len) {
@@ -1306,10 +1306,11 @@ static uint8_t *get_clear_payload(struct ndpi_detection_module_struct *ndpi_stru
return clear_payload;
}
static void process_tls(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const u_int8_t *crypto_data, uint32_t crypto_data_len,
uint32_t version)
void process_tls(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const u_int8_t *crypto_data, uint32_t crypto_data_len,
uint32_t version)
{
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
@@ -1341,9 +1342,9 @@ static void process_tls(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DOH_DOT, NDPI_PROTOCOL_QUIC, NDPI_CONFIDENCE_DPI);
}
}
static void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const u_int8_t *crypto_data, uint32_t crypto_data_len)
void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const u_int8_t *crypto_data, uint32_t crypto_data_len)
{
const uint8_t *tag;
uint32_t i;