]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: adds debug check against too many warnings
authorPhilippe Antoine <contact@catenacyber.fr>
Wed, 15 Apr 2020 12:31:37 +0000 (14:31 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 23 Apr 2020 18:55:57 +0000 (20:55 +0200)
rules/http-events.rules
src/app-layer-htp.c
src/app-layer-htp.h

index 279f0eea6d6e1a1d17c9f6586b573b023c338b9b..023728c9aa9dc671fdf88e5009a75c967bec3a36 100644 (file)
@@ -81,4 +81,6 @@ alert http any any -> any any (msg:"SURICATA HTTP duplicate content length field
 
 alert http any any -> any any (msg:"SURICATA HTTP compression bomb"; flow:established; app-layer-event:http.compression_bomb; flowint:http.anomaly.count,+,1; classtype:protocol-command-decode; sid:2221049; rev:1;)
 
-# next sid 2221050
+alert http any any -> any any (msg:"SURICATA HTTP too many warnings"; flow:established; app-layer-event:http.too_many_warnings; flowint:http.anomaly.count,+,1; classtype:protocol-command-decode; sid:2221050; rev:1;)
+
+# next sid 2221051
index 1bf5b2fa173e6f3045d24e8f73d69a4e9a134d49..acf005aefa42080175afc4281817043b7e09f442 100644 (file)
@@ -87,6 +87,9 @@ static SCRadixTree *cfgtree;
 /** List of HTP configurations. */
 static HTPCfgRec cfglist;
 
+/** Limit to the number of libhtp messages that can be handled */
+#define HTP_MAX_MESSAGES 512
+
 SC_ATOMIC_DECLARE(uint32_t, htp_config_flags);
 
 #ifdef DEBUG
@@ -198,6 +201,9 @@ SCEnumCharMap http_decoder_event_table[ ] = {
     { "MULTIPART_INVALID_HEADER",
         HTTP_DECODER_EVENT_MULTIPART_INVALID_HEADER},
 
+    { "TOO_MANY_WARNINGS",
+        HTTP_DECODER_EVENT_TOO_MANY_WARNINGS},
+
     { NULL,                      -1 },
 };
 
@@ -689,6 +695,16 @@ static void HTPHandleError(HtpState *s, const uint8_t dir)
 
     size_t size = htp_list_size(s->conn->messages);
     size_t msg;
+    if(size >= HTP_MAX_MESSAGES) {
+        if (s->htp_messages_offset < HTP_MAX_MESSAGES) {
+            //only once per HtpState
+            HTPSetEvent(s, NULL, dir, HTTP_DECODER_EVENT_TOO_MANY_WARNINGS);
+            s->htp_messages_offset = HTP_MAX_MESSAGES;
+            DEBUG_VALIDATE_BUG_ON("Too many libhtp messages");
+        }
+        // ignore further messages
+        return;
+    }
 
     for (msg = s->htp_messages_offset; msg < size; msg++) {
         htp_log_t *log = htp_list_get(s->conn->messages, msg);
index b83b8c914da508fe5c137c77d3cabb4b842a1bb0..1b322c1c80e9b07b170442a195fc766bfffdf5d7 100644 (file)
@@ -132,6 +132,8 @@ enum {
     HTTP_DECODER_EVENT_MULTIPART_GENERIC_ERROR,
     HTTP_DECODER_EVENT_MULTIPART_NO_FILEDATA,
     HTTP_DECODER_EVENT_MULTIPART_INVALID_HEADER,
+
+    HTTP_DECODER_EVENT_TOO_MANY_WARNINGS,
 };
 
 typedef enum HtpSwfCompressType_ {