diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 1f0cece872..5b8e61c25f 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -2149,11 +2149,12 @@ static void HTPConfigSetDefaultsPhase1(HTPCfgRec *cfg_prec) cfg_prec->request.inspect_window = HTP_CONFIG_DEFAULT_REQUEST_INSPECT_WINDOW; cfg_prec->response.inspect_min_size = HTP_CONFIG_DEFAULT_RESPONSE_INSPECT_MIN_SIZE; cfg_prec->response.inspect_window = HTP_CONFIG_DEFAULT_RESPONSE_INSPECT_WINDOW; -#ifndef AFLFUZZ_NO_RANDOM - cfg_prec->randomize = HTP_CONFIG_DEFAULT_RANDOMIZE; -#else - cfg_prec->randomize = 0; -#endif + + if (!g_disable_randomness) { + cfg_prec->randomize = HTP_CONFIG_DEFAULT_RANDOMIZE; + } else { + cfg_prec->randomize = 0; + } cfg_prec->randomize_range = HTP_CONFIG_DEFAULT_RANDOMIZE_RANGE; htp_config_register_request_header_data(cfg_prec->cfg, HTPCallbackRequestHeaderData); @@ -2471,9 +2472,9 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s, (size_t)HTP_CONFIG_DEFAULT_FIELD_LIMIT_SOFT, (size_t)limit); } else if (strcasecmp("randomize-inspection-sizes", p->name) == 0) { -#ifndef AFLFUZZ_NO_RANDOM - cfg_prec->randomize = ConfValIsTrue(p->val); -#endif + if (!g_disable_randomness) { + cfg_prec->randomize = ConfValIsTrue(p->val); + } } else if (strcasecmp("randomize-inspection-range", p->name) == 0) { uint32_t range = atoi(p->val); if (range > 100) { diff --git a/src/defrag-hash.c b/src/defrag-hash.c index 6203baa28d..9087f26ace 100644 --- a/src/defrag-hash.c +++ b/src/defrag-hash.c @@ -133,10 +133,8 @@ void DefragInitConfig(char quiet) SC_ATOMIC_INIT(defragtracker_prune_idx); DefragTrackerQueueInit(&defragtracker_spare_q); -#ifndef AFLFUZZ_NO_RANDOM /* set defaults */ defrag_config.hash_rand = (uint32_t)RandomGet(); -#endif defrag_config.hash_size = DEFRAG_DEFAULT_HASHSIZE; defrag_config.memcap = DEFRAG_DEFAULT_MEMCAP; defrag_config.prealloc = DEFRAG_DEFAULT_PREALLOC; diff --git a/src/flow.c b/src/flow.c index 8512e954ec..6d199f7764 100644 --- a/src/flow.c +++ b/src/flow.c @@ -349,10 +349,8 @@ void FlowInitConfig(char quiet) FlowQueueInit(&flow_spare_q); FlowQueueInit(&flow_recycle_q); -#ifndef AFLFUZZ_NO_RANDOM /* set defaults */ flow_config.hash_rand = (uint32_t)RandomGet(); -#endif flow_config.hash_size = FLOW_DEFAULT_HASHSIZE; flow_config.memcap = FLOW_DEFAULT_MEMCAP; flow_config.prealloc = FLOW_DEFAULT_PREALLOC; diff --git a/src/host.c b/src/host.c index 2e9061cc7d..11a4ca8d4d 100644 --- a/src/host.c +++ b/src/host.c @@ -141,10 +141,8 @@ void HostInitConfig(char quiet) SC_ATOMIC_INIT(host_prune_idx); HostQueueInit(&host_spare_q); -#ifndef AFLFUZZ_NO_RANDOM /* set defaults */ host_config.hash_rand = (uint32_t)RandomGet(); -#endif host_config.hash_size = HOST_DEFAULT_HASHSIZE; host_config.memcap = HOST_DEFAULT_MEMCAP; host_config.prealloc = HOST_DEFAULT_PREALLOC; diff --git a/src/ippair.c b/src/ippair.c index 66fce1e5a5..5c35efa475 100644 --- a/src/ippair.c +++ b/src/ippair.c @@ -137,10 +137,8 @@ void IPPairInitConfig(char quiet) SC_ATOMIC_INIT(ippair_prune_idx); IPPairQueueInit(&ippair_spare_q); -#ifndef AFLFUZZ_NO_RANDOM /* set defaults */ ippair_config.hash_rand = (uint32_t)RandomGet(); -#endif ippair_config.hash_size = IPPAIR_DEFAULT_HASHSIZE; ippair_config.memcap = IPPAIR_DEFAULT_MEMCAP; ippair_config.prealloc = IPPAIR_DEFAULT_PREALLOC; diff --git a/src/suricata.c b/src/suricata.c index 6cd05f2c8a..27aa0b47f5 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -220,6 +220,13 @@ int sc_set_caps = FALSE; /** highest mtu of the interfaces we monitor */ int g_default_mtu = 0; +/** disable randomness to get reproducible results accross runs */ +#ifndef AFLFUZZ_NO_RANDOM +int g_disable_randomness = 0; +#else +int g_disable_randomness = 1; +#endif + int EngineModeIsIPS(void) { return (g_engine_mode == ENGINE_MODE_IPS); @@ -1461,6 +1468,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) {"netmap", optional_argument, 0, 0}, {"pcap", optional_argument, 0, 0}, {"simulate-ips", 0, 0 , 0}, + {"no-random", 0, &g_disable_randomness, 1}, /* AFL app-layer options. */ {"afl-http-request", required_argument, 0 , 0}, diff --git a/src/suricata.h b/src/suricata.h index aaee9fe535..c49b7f43a0 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -172,6 +172,7 @@ typedef struct SCInstance_ { void GlobalsInitPreConfig(); extern volatile uint8_t suricata_ctl_flags; +extern int g_disable_randomness; /* uppercase to lowercase conversion lookup table */ uint8_t g_u8_lowercasetable[256]; diff --git a/src/util-random.c b/src/util-random.c index 17bd74baed..08916ec494 100644 --- a/src/util-random.c +++ b/src/util-random.c @@ -31,6 +31,9 @@ long int RandomGet(void) { + if (g_disable_randomness) + return 0; + HCRYPTPROV p; if (!(CryptAcquireContext(&p, NULL, NULL, PROV_RSA_FULL, 0))) { @@ -50,6 +53,9 @@ long int RandomGet(void) #elif defined(HAVE_CLOCK_GETTIME) long int RandomGet(void) { + if (g_disable_randomness) + return 0; + struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); @@ -60,6 +66,9 @@ long int RandomGet(void) #else long int RandomGet(void) { + if (g_disable_randomness) + return 0; + struct timeval tv; memset(&tv, 0, sizeof(tv)); gettimeofday(&tv, NULL);