diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 318a3f9774..190e2def0a 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -987,6 +987,20 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) if ( request_method->ToStdString() != "GET" ) Weird("invalid_http_09_request_method", request_method->CheckString()); + // If we already have a reply_message that means we saw + // an HTTP response before a request and interpreted + // it as HTTP/1.1 already. Reset the state here because + // we're removing the ContentLine support analyzer and + // any assumptions about expected delivery size state + // become invalid. + if ( reply_message ) + { + Weird("http_09_reply_before_request"); + reply_message->Done(); + delete reply_message; + reply_message = nullptr; + } + reply_state = EXPECT_REPLY_HTTP09; RemoveSupportAnalyzer(content_line_resp); } diff --git a/testing/btest/Baseline/scripts.base.protocols.http.http-09-content-length-confusion/http.log b/testing/btest/Baseline/scripts.base.protocols.http.http-09-content-length-confusion/http.log new file mode 100644 index 0000000000..9bca082c7f --- /dev/null +++ b/testing/btest/Baseline/scripts.base.protocols.http.http-09-content-length-confusion/http.log @@ -0,0 +1,12 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +#separator \x09 +#set_separator , +#empty_field (empty) +#unset_field - +#path http +#open XXXX-XX-XX-XX-XX-XX +#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p trans_depth method host uri referrer version user_agent origin request_body_len response_body_len status_code status_msg info_code info_msg tags username password proxied orig_fuids orig_filenames orig_mime_types resp_fuids resp_filenames resp_mime_types +#types time string addr port addr port count string string string string string string string count count count string count string set[enum] string string set[string] vector[string] vector[string] vector[string] vector[string] vector[string] vector[string] +XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 46982 127.0.0.1 80 1 GET - / - 1.1 - - 0 0 200 OK - - (empty) - - - - - - - - - +XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 46982 127.0.0.1 80 2 - - - - 0.9 - - 0 19 0 - - (empty) - - - - - - F7s8014qOBt9Gyy3w7 - text/plain +#close XXXX-XX-XX-XX-XX-XX diff --git a/testing/btest/Baseline/scripts.base.protocols.http.http-09-content-length-confusion/weird.log b/testing/btest/Baseline/scripts.base.protocols.http.http-09-content-length-confusion/weird.log new file mode 100644 index 0000000000..b6c643871a --- /dev/null +++ b/testing/btest/Baseline/scripts.base.protocols.http.http-09-content-length-confusion/weird.log @@ -0,0 +1,12 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +#separator \x09 +#set_separator , +#empty_field (empty) +#unset_field - +#path weird +#open XXXX-XX-XX-XX-XX-XX +#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p name addl notice peer source +#types time string addr port addr port string string bool string string +XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 46982 127.0.0.1 80 http_09_reply_before_request - F zeek HTTP +XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 127.0.0.1 46982 127.0.0.1 80 HTTP_version_mismatch - F zeek HTTP +#close XXXX-XX-XX-XX-XX-XX diff --git a/testing/btest/Traces/http/http-09-content-length-confusion.pcap b/testing/btest/Traces/http/http-09-content-length-confusion.pcap new file mode 100644 index 0000000000..f846fe2daf Binary files /dev/null and b/testing/btest/Traces/http/http-09-content-length-confusion.pcap differ diff --git a/testing/btest/scripts/base/protocols/http/http-09-content-length-confusion.zeek b/testing/btest/scripts/base/protocols/http/http-09-content-length-confusion.zeek new file mode 100644 index 0000000000..10e16c3da2 --- /dev/null +++ b/testing/btest/scripts/base/protocols/http/http-09-content-length-confusion.zeek @@ -0,0 +1,7 @@ +# @TEST-DOC: HTTP response with Content-Length followed by HTTP/0.9 request. This triggered an assert. +# @TEST-EXEC: zeek -b -Cr $TRACES/http/http-09-content-length-confusion.pcap %INPUT +# @TEST-EXEC: btest-diff http.log +# @TEST-EXEC: btest-diff weird.log + +@load base/frameworks/notice/weird +@load base/protocols/http