Squashed commit of the following:
commit
6d0b51f16b635cae70a2a143e07bacd8b672e909
Author: mdagon <mdagon@cisco.com>
Date: Fri Sep 18 13:35:20 2020 -0400
payload_injector: don't inject if stream id is even
{ ERR_HTTP2_MID_FRAME, "HTTP/2 - attempt to inject mid frame. Currently not supported." },
{ ERR_TRANSLATED_HDRS_SIZE,
"HTTP/2 translated header size is bigger than expected. Update max size." },
- { ERR_HTTP2_BODY_SIZE, "HTTP/2 body is > 16k. Currently not supported." }
+ { ERR_HTTP2_BODY_SIZE, "HTTP/2 body is > 16k. Currently not supported." },
+ { ERR_HTTP2_EVEN_STREAM_ID, "HTTP/2 - injection to server initiated stream" }
};
bool PayloadInjectorModule::configured = false;
if (control.stream_id == 0)
status = ERR_HTTP2_STREAM_ID_0;
+ else if (control.stream_id % 2 == 0)
+ {
+ // Don't inject against server initiated streams
+ status = ERR_HTTP2_EVEN_STREAM_ID;
+ }
else
{
// Check if mid frame
ERR_HTTP2_MID_FRAME = -6,
ERR_TRANSLATED_HDRS_SIZE = -7,
ERR_HTTP2_BODY_SIZE = -8,
+ ERR_HTTP2_EVEN_STREAM_ID = -9
// Update InjectionErrorToString when adding/removing error codes
};
delete flow.gadget;
}
+TEST(payload_injector_test, http2_even_stream_id)
+{
+ mod.set_configured(true);
+ Packet p(false);
+ p.packet_flags = PKT_STREAM_EST;
+ mock_api.base.name = "http2_inspect";
+ flow.gadget = new MockInspector();
+ p.flow = &flow;
+ control.stream_id = 2;
+ InjectionReturnStatus status = mod.inject_http_payload(&p, control);
+ CHECK(counts->http2_injects == 0);
+ CHECK(status == ERR_HTTP2_EVEN_STREAM_ID);
+ CHECK(flow.flow_state == Flow::FlowState::BLOCK);
+ const char* err_string = mod.get_err_string(status);
+ CHECK(strcmp(err_string, "HTTP/2 - injection to server initiated stream") == 0);
+ delete flow.gadget;
+}
+
TEST(payload_injector_test, http2_success)
{
mod.set_configured(true);