nDPI/fuzz/fuzz_dga_url.c
Raja Muhammad Awais 43b3731ea8
Detect DGA-like patterns in HTTP URL paths (fixes #2089) (#3228)
Some malware families (e.g. Emotet) encode DGA-generated tokens directly in
the HTTP URL path instead of the hostname, bypassing the existing hostname-
based DGA checks. This commit adds ndpi_check_dga_url_path(), which applies a
refined version of the DGA heuristic to URL path segments:

- Segments are stripped of file extensions, split into sub-tokens by
  '_', '-' and '.', and empty sub-tokens are ignored.
- Structured identifiers are excluded: hex hashes/numeric IDs, short
  alphanumeric resource IDs (alpha prefix followed by hex body), short
  tokens (at most two non-hex letters plus digits, a single letter group
  after up to four leading digits, and ASIN-style digit pairs followed by
  letters), and purely letter-based names.
- Remaining segments are flagged as DGA-like when they contain at least
  eight alphabetic characters with at most two vowels, or an identical-
  character run of eight or more, consistent with the hostname checks in
  ndpi_check_dga_name().

The check is invoked from the HTTP dissector when validating URLs and
emits the NDPI_SUSPICIOUS_DGA_DOMAIN risk with a descriptive info string.

Add a new fuzzer about it.

Close: #2089

Co-authored-by: RajaMuhammadAwais <1.19938988e+08+RajaMuhammadAwais@users.noreply.github.com>
Co-authored-by: Ivan Nardi <nardi.ivan@gmail.com>
2026-08-23 11:37:33 +02:00

36 lines
804 B
C

#include "ndpi_api.h"
#include "fuzz_common_code.h"
static struct ndpi_detection_module_struct *ndpi_struct = NULL;
static struct ndpi_flow_struct *ndpi_flow = NULL;
static char *path = NULL;
int LLVMFuzzerInitialize(int *argc, char ***argv) {
(void)argc;
path = dirname(strdup(*argv[0])); /* No errors; no free! */
return 0;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
char *name;
if (ndpi_struct == NULL) {
fuzz_init_detection_module(&ndpi_struct, NULL, path);
ndpi_flow = ndpi_calloc(1, sizeof(struct ndpi_flow_struct));
}
if (size == 0)
return 0;
name = ndpi_malloc(size + 1);
if (name) {
memcpy(name, data, size);
name[size] = '\0';
ndpi_check_dga_url_path(ndpi_struct, ndpi_flow, name);
ndpi_free(name);
}
return 0;
}