HTTP: Reset reply_message for HTTP/0.9

OSS-Fuzz tickled an assert when sending a HTTP response before a HTTP/0.9
request. Avoid this by resetting reply_message upon seeing a HTTP/0.9 request.

PCAP was generated artificially: Server sending a reply providing a
Content-Length. Because HTTP/0.9 processing would remove the ContentLine
support analyzer, more data was delivered to the HTTP_Message than
expected, triggering an assert.

This is a follow-up for zeek/zeek#2851.
This commit is contained in:
Arne Welzel 2023-03-13 10:47:34 +01:00
parent c5a9eb920c
commit fbf9d53c44
5 changed files with 45 additions and 0 deletions

View file

@ -987,6 +987,20 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig)
if ( request_method->ToStdString() != "GET" ) if ( request_method->ToStdString() != "GET" )
Weird("invalid_http_09_request_method", request_method->CheckString()); 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; reply_state = EXPECT_REPLY_HTTP09;
RemoveSupportAnalyzer(content_line_resp); RemoveSupportAnalyzer(content_line_resp);
} }

View file

@ -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> - - (empty) - - - - - - F7s8014qOBt9Gyy3w7 - text/plain
#close XXXX-XX-XX-XX-XX-XX

View file

@ -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

View file

@ -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