Improve HTTP detection heuristic (#7228)

* Improve HTTP checking heuristic

* fix changelog

* Fix checking

* [autofix.ci] apply automated fixes

* simplify condition

---------

Co-authored-by: Fata Nugraha <fata.nugraha@grabtaxi.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Hils <github@maximilianhils.com>
This commit is contained in:
Fata Nugraha 2024-10-04 23:22:26 +08:00 committed by GitHub
parent 870dd03b17
commit af88265f5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View File

@ -7,6 +7,8 @@
## Unreleased: mitmproxy next ## Unreleased: mitmproxy next
- Tighten HTTP detection heuristic to better support custom TCP-based protocols.
([#7228](https://github.com/mitmproxy/mitmproxy/pull/7228), @fatanugraha)
## 02 October 2024: mitmproxy 11.0.0 ## 02 October 2024: mitmproxy 11.0.0

View File

@ -182,9 +182,10 @@ class NextLayer:
probably_no_http = ( probably_no_http = (
# the first three bytes should be the HTTP verb, so A-Za-z is expected. # the first three bytes should be the HTTP verb, so A-Za-z is expected.
len(data_client) < 3 len(data_client) < 3
# HTTP would require whitespace before the first newline # HTTP would require whitespace...
# if we have neither whitespace nor a newline, it's also unlikely to be HTTP. or b" " not in data_client
or (data_client.find(b" ") >= data_client.find(b"\n")) # ...and that whitespace needs to be in the first line.
or (data_client.find(b" ") > data_client.find(b"\n"))
or not data_client[:3].isalpha() or not data_client[:3].isalpha()
# a server greeting would be uncharacteristic. # a server greeting would be uncharacteristic.
or data_server or data_server

View File

@ -103,7 +103,7 @@ dns_query = bytes.fromhex("002a01000001000000000000076578616d706c6503636f6d00000
# Custom protocol with just base64-encoded messages # Custom protocol with just base64-encoded messages
# https://github.com/mitmproxy/mitmproxy/pull/7087 # https://github.com/mitmproxy/mitmproxy/pull/7087
custom_base64_proto = b"AAAAAAAAAAAAAAAAAAAAAA==" custom_base64_proto = b"AAAAAAAAAAAAAAAAAAAAAA==\n"
http_get = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" http_get = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
http_get_absolute = b"GET http://example.com/ HTTP/1.1\r\n\r\n" http_get_absolute = b"GET http://example.com/ HTTP/1.1\r\n\r\n"