From: Philippe Antoine Date: Fri, 4 Sep 2020 07:39:44 +0000 (+0200) Subject: http: disables lzma by default for HTTP X-Git-Tag: suricata-6.0.0-rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b5c9233277bfc463459aa1a0878100c3e32e60e;p=thirdparty%2Fsuricata.git http: disables lzma by default for HTTP --- diff --git a/configure.ac b/configure.ac index 3783bc1082..363fba5181 100644 --- a/configure.ac +++ b/configure.ac @@ -1732,6 +1732,7 @@ return 0; AC_CHECK_LIB([htp], [htp_config_set_response_decompression_layer_limit],AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_RESPONSE_DECOMPRESSION_LAYER_LIMIT],[1],[Found htp_config_set_response_decompression_layer_limit function in libhtp]) ,,[-lhtp]) AC_EGREP_HEADER(htp_config_set_path_decode_u_encoding, htp/htp.h, AC_DEFINE_UNQUOTED([HAVE_HTP_SET_PATH_DECODE_U_ENCODING],[1],[Found usable htp_config_set_path_decode_u_encoding function in libhtp]) ) AC_CHECK_LIB([htp], [htp_config_set_lzma_memlimit],AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT],[1],[Found htp_config_set_lzma_memlimit function in libhtp]) ,,[-lhtp]) + AC_CHECK_LIB([htp], [htp_config_set_lzma_layers],AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_LZMA_LAYERS],[1],[Found htp_config_set_lzma_layers function in libhtp]) ,,[-lhtp]) AC_CHECK_LIB([htp], [htp_config_set_compression_bomb_limit],AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT],[1],[Found htp_config_set_compression_bomb_limit function in libhtp]) ,,[-lhtp]) ]) @@ -1754,6 +1755,7 @@ return 0; # enable when libhtp has been updated AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_RESPONSE_DECOMPRESSION_LAYER_LIMIT],[1],[Assuming htp_config_set_response_decompression_layer_limit function in bundled libhtp]) AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT],[1],[Assuming htp_config_set_lzma_memlimit function in bundled libhtp]) + AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_LZMA_LAYERS],[1],[Assuming htp_config_set_lzma_layers function in bundled libhtp]) AC_DEFINE_UNQUOTED([HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT],[1],[Assuming htp_config_set_compression_bomb_limit function in bundled libhtp]) else echo diff --git a/doc/userguide/configuration/suricata-yaml.rst b/doc/userguide/configuration/suricata-yaml.rst index 152d7977c0..a976df4a60 100644 --- a/doc/userguide/configuration/suricata-yaml.rst +++ b/doc/userguide/configuration/suricata-yaml.rst @@ -1358,8 +1358,8 @@ use of libhtp. # Default value of randomize-inspection-range is 10. #randomize-inspection-range: 10 - # Can disable LZMA decompression - #lzma-enabled: yes + # Can enable LZMA decompression + #lzma-enabled: false # Memory limit usage for LZMA decompression dictionary # Data is decompressed until dictionary reaches this size #lzma-memlimit: 1 Mb diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 08df37d654..8498f0730b 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -2382,6 +2382,10 @@ static void HTPConfigSetDefaultsPhase1(HTPCfgRec *cfg_prec) /* don't convert + to space by default */ htp_config_set_plusspace_decode(cfg_prec->cfg, HTP_DECODER_URLENCODED, 0); +#ifdef HAVE_HTP_CONFIG_SET_LZMA_LAYERS + // disable by default + htp_config_set_lzma_layers(cfg_prec->cfg, HTP_CONFIG_DEFAULT_LZMA_LAYERS); +#endif #ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT htp_config_set_lzma_memlimit(cfg_prec->cfg, HTP_CONFIG_DEFAULT_LZMA_MEMLIMIT); @@ -2712,10 +2716,20 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s, SCLogConfig("Setting HTTP LZMA memory limit to %"PRIu32" bytes", limit); htp_config_set_lzma_memlimit(cfg_prec->cfg, (size_t)limit); #endif -#ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT +#ifdef HAVE_HTP_CONFIG_SET_LZMA_LAYERS } else if (strcasecmp("lzma-enabled", p->name) == 0) { - if (ConfValIsFalse(p->val)) { - htp_config_set_lzma_memlimit(cfg_prec->cfg, 0); + if (ConfValIsTrue(p->val)) { + htp_config_set_lzma_layers(cfg_prec->cfg, 1); + } else if (!ConfValIsFalse(p->val)) { + int8_t limit; + if (StringParseInt8(&limit, 10, 0, (const char *)p->val) < 0) { + FatalError(SC_ERR_SIZE_PARSE, + "failed to parse 'lzma-enabled' " + "from conf file - %s.", + p->val); + } + SCLogConfig("Setting HTTP LZMA decompression layers to %" PRIu32 "", (int)limit); + htp_config_set_lzma_layers(cfg_prec->cfg, limit); } #endif #ifdef HAVE_HTP_CONFIG_SET_COMPRESSION_BOMB_LIMIT diff --git a/src/app-layer-htp.h b/src/app-layer-htp.h index dee49f5c19..2037e90655 100644 --- a/src/app-layer-htp.h +++ b/src/app-layer-htp.h @@ -52,6 +52,7 @@ #define HTP_CONFIG_DEFAULT_FIELD_LIMIT_SOFT 9000U #define HTP_CONFIG_DEFAULT_FIELD_LIMIT_HARD 18000U +#define HTP_CONFIG_DEFAULT_LZMA_LAYERS 0U /* default libhtp lzma limit, taken from libhtp. */ #define HTP_CONFIG_DEFAULT_LZMA_MEMLIMIT 1048576U #define HTP_CONFIG_DEFAULT_COMPRESSION_BOMB_LIMIT 1048576U diff --git a/suricata.yaml.in b/suricata.yaml.in index 1ba696ba61..74e7a5b390 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -889,8 +889,8 @@ app-layer: double-decode-path: no double-decode-query: no - # Can disable LZMA decompression - #lzma-enabled: yes + # Can enable LZMA decompression + #lzma-enabled: false # Memory limit usage for LZMA decompression dictionary # Data is decompressed until dictionary reaches this size #lzma-memlimit: 1mb