]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2042 in SNORT/snort3 from ~NIHDESAI/snort3:abort_h2h to master
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 3 Mar 2020 14:49:29 +0000 (14:49 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 3 Mar 2020 14:49:29 +0000 (14:49 +0000)
Squashed commit of the following:

commit d5b1e259399fbcc38fa191291ef6c4b99264f809
Author: Nihal Desai <nihdesai@cisco.com>
Date:   Wed Feb 19 15:41:51 2020 -0500

    http2_inspect: aborts for nhi errors

src/service_inspectors/http2_inspect/http2_enum.h
src/service_inspectors/http2_inspect/http2_headers_frame.cc
src/service_inspectors/http2_inspect/http2_tables.cc

index be19f496ebc8326a88afb30817d056e2c28be52f..fdab3edbf9106df7af146c9c6f1e965f28e35a2e 100644 (file)
@@ -63,6 +63,7 @@ enum EventSid
     EVENT_SETTINGS_FRAME_UNKN_PARAM = 12,
     EVENT_FRAME_SEQUENCE = 13,
     EVENT_DYNAMIC_TABLE_OVERFLOW = 14,
+    EVENT_INVALID_STARTLINE = 15,
     EVENT__MAX_VALUE
 };
 
@@ -95,6 +96,8 @@ enum Infraction
     INF_DYNAMIC_TABLE_OVERFLOW = 22,
     INF_TABLE_SIZE_UPDATE_WITHIN_HEADER = 23,
     INF_TOO_MANY_TABLE_SIZE_UPDATES = 24,
+    INF_INVALID_STARTLINE = 25,
+    INF_INVALID_HEADER = 26,
     INF__MAX_VALUE
 };
 
index 07ab5632b92bfe439cfafab194556df432e727c5..87f84af670a56855a4c5a648260c1da9fa97b228 100644 (file)
@@ -24,7 +24,8 @@
 #include "http2_headers_frame.h"
 
 #include "protocols/packet.h"
-
+#include "service_inspectors/http_inspect/http_enum.h"
+#include "service_inspectors/http_inspect/http_flow_data.h"
 #include "service_inspectors/http_inspect/http_inspect.h"
 #include "service_inspectors/http_inspect/http_stream_splitter.h"
 
@@ -102,6 +103,7 @@ Http2HeadersFrame::Http2HeadersFrame(const uint8_t* header_buffer, const int32_t
         assert(copied == (unsigned)start_line->length());
     }
 
+    HttpFlowData* http_flow = session_data->get_current_stream(source_id)->get_hi_flow_data();
     // http_inspect eval() and clear() of start line
     {
         Http2DummyPacket dummy_pkt;
@@ -110,6 +112,13 @@ Http2HeadersFrame::Http2HeadersFrame(const uint8_t* header_buffer, const int32_t
         dummy_pkt.dsize = stream_buf.length;
         dummy_pkt.data = stream_buf.data;
         session_data->hi->eval(&dummy_pkt);
+        if (http_flow->get_type_expected(source_id) != HttpEnums::SEC_HEADER)
+        {
+            *session_data->infractions[source_id] += INF_INVALID_STARTLINE;
+            session_data->events[source_id]->create_event(EVENT_INVALID_STARTLINE);
+            hi_abort = true;
+            return;
+        }
         session_data->hi->clear(&dummy_pkt);
     }
 
@@ -122,13 +131,8 @@ Http2HeadersFrame::Http2HeadersFrame(const uint8_t* header_buffer, const int32_t
         const StreamSplitter::Status header_scan_result =
             session_data->hi_ss[source_id]->scan(&dummy_pkt, http1_header->start(),
             http1_header->length(), unused, &flush_offset);
-        if (header_scan_result == StreamSplitter::ABORT)
-        {
-            // eval() aborted the start line?
-            hi_abort = true;
-            return;
-        }
         assert(header_scan_result == StreamSplitter::FLUSH);
+        UNUSED(header_scan_result);
         assert((int64_t)flush_offset == http1_header->length());
     }
 
@@ -151,6 +155,17 @@ Http2HeadersFrame::Http2HeadersFrame(const uint8_t* header_buffer, const int32_t
         dummy_pkt.data = stream_buf.data;
         dummy_pkt.xtradata_mask = 0;
         session_data->hi->eval(&dummy_pkt);
+        //Following if condition won't get exercised until finish() is
+        //implemented for H2I. Without finish() H2I will only flush
+        //complete header blocks. Below ABORT is only possible if
+        //tcp connection closes unexpectedly in middle of a header.
+        if (http_flow->get_type_expected(source_id) == HttpEnums::SEC_ABORT)
+        {
+            *session_data->infractions[source_id] += INF_INVALID_HEADER;
+            session_data->events[source_id]->create_event(EVENT_INVALID_HEADER);
+            hi_abort = true;
+            return;
+        }
         detection_required = dummy_pkt.is_detection_required();
         xtradata_mask = dummy_pkt.xtradata_mask;
     }
index 29652cda1cc148e4faa2e077d53bf2eac34fff82..71557351e57bb826df9047a74fd63f8e1a23f94c 100644 (file)
@@ -45,6 +45,7 @@ const RuleMap Http2Module::http2_events[] =
     { EVENT_SETTINGS_FRAME_UNKN_PARAM, "unknown parameter in HTTP/2 settings frame" },
     { EVENT_FRAME_SEQUENCE, "invalid HTTP/2 frame sequence" },
     { EVENT_DYNAMIC_TABLE_OVERFLOW, "HTTP/2 dynamic table size limit exceeded" },
+    { EVENT_INVALID_STARTLINE, "invalid HTTP/2 start line" },
     { 0, nullptr }
 };