Spoof mode

This commit is contained in:
iroiro123 2015-06-20 21:43:50 +09:00
parent 59ec291b6c
commit 378aa78324
4 changed files with 21 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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