From: Victor Julien Date: Tue, 10 Sep 2019 11:06:28 +0000 (+0200) Subject: htp: set lzma memlimit from config X-Git-Tag: suricata-5.0.0-rc1~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9c23d5cda94275f1459270f181a784b901fa985;p=thirdparty%2Fsuricata.git htp: set lzma memlimit from config --- diff --git a/configure.ac b/configure.ac index 82f5252300..0afed7d50a 100644 --- a/configure.ac +++ b/configure.ac @@ -1650,6 +1650,7 @@ AC_CHECK_LIB([htp], [htp_decode_query_inplace],AC_DEFINE_UNQUOTED([HAVE_HTP_DECODE_QUERY_INPLACE],[1],[Found htp_decode_query_inplace function in libhtp]) ,,[-lhtp]) 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]) ]) if test "x$enable_non_bundled_htp" = "xno"; then @@ -1670,6 +1671,7 @@ AC_DEFINE_UNQUOTED([HAVE_HTP_DECODE_QUERY_INPLACE],[1],[Assuming htp_decode_query_inplace function in bundled libhtp]) # 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]) else echo echo " ERROR: Libhtp is not bundled. Get libhtp by doing:" diff --git a/rules/http-events.rules b/rules/http-events.rules index b3197f5547..77a92b529e 100644 --- a/rules/http-events.rules +++ b/rules/http-events.rules @@ -74,4 +74,6 @@ alert http any any -> any any (msg:"SURICATA HTTP Request double encoded URI"; f alert http any any -> any any (msg:"SURICATA HTTP Invalid Request line"; flow:established,to_server; app-layer-event:http.request_line_invalid; flowint:http.anomaly.count,+,1; classtype:protocol-command-decode; sid:2221044; rev:1;) alert http any any -> any any (msg:"SURICATA HTTP Unexpected Request body"; flow:established,to_server; app-layer-event:http.request_body_unexpected; flowint:http.anomaly.count,+,1; classtype:protocol-command-decode; sid:2221045; rev:1;) -# next sid 2221046 +alert http any any -> any any (msg:"SURICATA HTTP LZMA reached its memory limit"; flow:established; app-layer-event:http.lzma_memlimit_reached; flowint:http.anomaly.count,+,1; classtype:protocol-command-decode; sid:2221046; rev:1;) + +# next sid 2221047 diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 7cdd727c51..b2ebf9d0a5 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -179,6 +179,9 @@ SCEnumCharMap http_decoder_event_table[ ] = { { "REQUEST_LINE_INCOMPLETE", HTTP_DECODER_EVENT_REQUEST_LINE_INCOMPLETE}, + { "LZMA_MEMLIMIT_REACHED", + HTTP_DECODER_EVENT_LZMA_MEMLIMIT_REACHED}, + /* suricata warnings/errors */ { "MULTIPART_GENERIC_ERROR", HTTP_DECODER_EVENT_MULTIPART_GENERIC_ERROR}, @@ -541,6 +544,7 @@ struct { { "Invalid response line: invalid response status", HTTP_DECODER_EVENT_RESPONSE_INVALID_STATUS}, { "Request line incomplete", HTTP_DECODER_EVENT_REQUEST_LINE_INCOMPLETE}, { "Unexpected request body", HTTP_DECODER_EVENT_REQUEST_BODY_UNEXPECTED}, + { "LZMA decompressor: memory limit reached", HTTP_DECODER_EVENT_LZMA_MEMLIMIT_REACHED}, }; #define HTP_ERROR_MAX (sizeof(htp_errors) / sizeof(htp_errors[0])) @@ -2635,6 +2639,21 @@ static void HTPConfigParseParameters(HTPCfgRec *cfg_prec, ConfNode *s, htp_config_set_field_limits(cfg_prec->cfg, (size_t)HTP_CONFIG_DEFAULT_FIELD_LIMIT_SOFT, (size_t)limit); +#ifdef HAVE_HTP_CONFIG_SET_LZMA_MEMLIMIT + } else if (strcasecmp("lzma-memlimit", p->name) == 0) { + uint32_t limit = 0; + if (ParseSizeStringU32(p->val, &limit) < 0) { + FatalError(SC_ERR_SIZE_PARSE, "failed to parse 'lzma-memlimit' " + "from conf file - %s.", p->val); + } + if (limit == 0) { + FatalError(SC_ERR_SIZE_PARSE, "'lzma-memlimit' " + "from conf file cannot be 0."); + } + /* set default soft-limit with our new hard limit */ + htp_config_set_lzma_memlimit(cfg_prec->cfg, + (size_t)limit); +#endif } else if (strcasecmp("randomize-inspection-sizes", p->name) == 0) { if (!g_disable_randomness) { cfg_prec->randomize = ConfValIsTrue(p->val); diff --git a/src/app-layer-htp.h b/src/app-layer-htp.h index 5e294bcf46..59a741aa36 100644 --- a/src/app-layer-htp.h +++ b/src/app-layer-htp.h @@ -119,6 +119,8 @@ enum { HTTP_DECODER_EVENT_REQUEST_LINE_INVALID, HTTP_DECODER_EVENT_REQUEST_BODY_UNEXPECTED, + HTTP_DECODER_EVENT_LZMA_MEMLIMIT_REACHED, + /* suricata errors/warnings */ HTTP_DECODER_EVENT_MULTIPART_GENERIC_ERROR, HTTP_DECODER_EVENT_MULTIPART_NO_FILEDATA,