diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index d0e54dfe2..5111fdd86 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -362,11 +362,6 @@ def common_options(parser): action="store_true", dest="transparent_proxy", default=False, help="Set transparent proxy mode." ) - group.add_argument( - "-H", "--http-transparent", - action="store_true", dest="http_transparent_proxy", default=False, - help="Use the Host header to connect to server." - ) group.add_argument( "-U", "--upstream", action="store", @@ -375,6 +370,11 @@ def common_options(parser): default=None, help="Forward all requests to upstream proxy server: http://host[:port]" ) + group.add_argument( + "--spoof", + action="store_true", dest="spoof_mode", default=False, + help="Use Host header to connect to HTTP server." + ) group = parser.add_argument_group( "Advanced Proxy Options", diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index c7479b762..617826981 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -1330,19 +1330,22 @@ class HTTPHandler(ProtocolHandler): flow.server_conn = self.c.server_conn elif request.form_in == "relative": - if self.c.config.mode == "httptransparent": - h = request.headers.get_first("host") + if self.c.config.mode == "spoof": + # Host header + h = request.pretty_host(hostheader=True) if h is None: raise http.HttpError( 400, "Invalid request: No Host header" ) p = http.parse_url("http://" + h) - request.host, request.port = p[1], p[2] + request.host = p[1] + request.port = p[2] self.c.set_server_address((request.host, request.port)) flow.server_conn = self.c.server_conn return None + raise http.HttpError( 400, "Invalid HTTP request form (expected: %s, got: %s)" % ( self.expected_form_in, request.form_in diff --git a/libmproxy/proxy/config.py b/libmproxy/proxy/config.py index 2074d0bf7..7305d72aa 100644 --- a/libmproxy/proxy/config.py +++ b/libmproxy/proxy/config.py @@ -4,7 +4,7 @@ import re from OpenSSL import SSL from netlib import http_auth, certutils, tcp from .. import utils, platform, version -from .primitives import RegularProxyMode, HTTPTransparentProxyMode, TransparentProxyMode, UpstreamProxyMode, ReverseProxyMode, Socks5ProxyMode +from .primitives import RegularProxyMode, SpoofMode, TransparentProxyMode, UpstreamProxyMode, ReverseProxyMode, Socks5ProxyMode TRANSPARENT_SSL_PORTS = [443, 8443] CONF_BASENAME = "mitmproxy" @@ -70,8 +70,8 @@ class ProxyConfig: self.mode = ReverseProxyMode(upstream_server) elif mode == "upstream": self.mode = UpstreamProxyMode(upstream_server) - elif mode == "httptransparent": - self.mode = HTTPTransparentProxyMode() + elif mode == "spoof": + self.mode = SpoofMode() else: self.mode = RegularProxyMode() @@ -146,9 +146,9 @@ def process_proxy_options(parser, options): c += 1 mode = "upstream" upstream_server = options.upstream_proxy - if options.http_transparent_proxy: + if options.spoof_mode: c += 1 - mode = "httptransparent" + mode = "spoof" if c > 1: return parser.error( "Transparent, SOCKS5, reverse and upstream proxy mode " diff --git a/libmproxy/proxy/primitives.py b/libmproxy/proxy/primitives.py index a9718051f..f514d37f8 100644 --- a/libmproxy/proxy/primitives.py +++ b/libmproxy/proxy/primitives.py @@ -51,13 +51,17 @@ class RegularProxyMode(ProxyMode): return None -class HTTPTransparentProxyMode(ProxyMode): +class SpoofMode(ProxyMode): http_form_in = "relative" http_form_out = "relative" def get_upstream_server(self, client_conn): return None + @property + def name(self): + return "spoof" + class TransparentProxyMode(ProxyMode): http_form_in = "relative"