mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-01-13 09:19:49 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0d76b33d1 | ||
|
|
058f1d42e3 | ||
|
|
afb1a2a31d | ||
|
|
8be5853bc6 | ||
|
|
7d7b67c445 | ||
|
|
9838cfb9d0 | ||
|
|
88a952a63e | ||
|
|
0a1ca53689 | ||
|
|
d0c27c76af | ||
|
|
b72f3ee568 | ||
|
|
2fcc0458d1 | ||
|
|
fb1d2a8c89 | ||
|
|
6b524c9054 | ||
|
|
ffe7eb94f1 |
@@ -19,7 +19,7 @@ class ClientPlayback:
|
||||
def configure(self, options, updated):
|
||||
if "client_replay" in updated:
|
||||
if options.client_replay:
|
||||
ctx.log.info(options.client_replay)
|
||||
ctx.log.info("Client Replay: {}".format(options.client_replay))
|
||||
try:
|
||||
flows = flow.read_flows_from_paths(options.client_replay)
|
||||
except exceptions.FlowReadException as e:
|
||||
|
||||
@@ -208,6 +208,11 @@ def get_common_options(args):
|
||||
if args.quiet:
|
||||
args.verbose = 0
|
||||
|
||||
if args.addr in ("localhost", "127.0.0.1", "::1"):
|
||||
upstream_bind_address = ""
|
||||
else:
|
||||
upstream_bind_address = args.addr
|
||||
|
||||
return dict(
|
||||
app=args.app,
|
||||
app_host=args.app_host,
|
||||
@@ -251,6 +256,7 @@ def get_common_options(args):
|
||||
ignore_hosts = args.ignore_hosts,
|
||||
listen_host = args.addr,
|
||||
listen_port = args.port,
|
||||
upstream_bind_address = upstream_bind_address,
|
||||
mode = mode,
|
||||
no_upstream_cert = args.no_upstream_cert,
|
||||
spoof_source_address = args.spoof_source_address,
|
||||
|
||||
@@ -285,9 +285,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.logbuffer.pop(0)
|
||||
self.logbuffer.set_focus(len(self.logbuffer) - 1)
|
||||
|
||||
def add_log(self, e, level):
|
||||
signals.add_log(e, level)
|
||||
|
||||
def sig_call_in(self, sender, seconds, callback, args=()):
|
||||
def cb(*_):
|
||||
return callback(*args)
|
||||
@@ -668,11 +665,10 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
)
|
||||
|
||||
def process_flow(self, f):
|
||||
should_intercept = any(
|
||||
[
|
||||
self.state.intercept and flowfilter.match(self.state.intercept, f) and not f.request.is_replay,
|
||||
f.intercepted,
|
||||
]
|
||||
should_intercept = (
|
||||
self.state.intercept and flowfilter.match(self.state.intercept, f)
|
||||
and not f.request.is_replay
|
||||
and f.reply.state == "handled"
|
||||
)
|
||||
if should_intercept:
|
||||
f.intercept(self)
|
||||
@@ -703,9 +699,13 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
super(ConsoleMaster, self).tcp_message(f)
|
||||
message = f.messages[-1]
|
||||
direction = "->" if message.from_client else "<-"
|
||||
self.add_log("{client} {direction} tcp {direction} {server}".format(
|
||||
signals.add_log("{client} {direction} tcp {direction} {server}".format(
|
||||
client=repr(f.client_conn.address),
|
||||
server=repr(f.server_conn.address),
|
||||
direction=direction,
|
||||
), "info")
|
||||
self.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
|
||||
signals.add_log(strutils.bytes_to_escaped_str(message.content), "debug")
|
||||
|
||||
@controller.handler
|
||||
def log(self, evt):
|
||||
signals.add_log(evt.msg, evt.level)
|
||||
|
||||
@@ -14,6 +14,31 @@ from netlib import version_check
|
||||
from netlib import debug
|
||||
|
||||
|
||||
def py3():
|
||||
print("""
|
||||
Error: mitmproxy requires Python 3.5 or above
|
||||
|
||||
Starting with version 1.0 released in 12/2016, mitmproxy no longer supports Python 2.
|
||||
|
||||
To install the latest version of mitmproxy using pip on Python 3, run:
|
||||
|
||||
pip uninstall mitmproxy
|
||||
pip3 install mitmproxy
|
||||
|
||||
You can also use our standalone binaries that come with their own Python interpreter:
|
||||
|
||||
http://docs.mitmproxy.org/en/stable/install.html
|
||||
|
||||
To get rid of this message and use the last version of mitmproxy that supports Python 2, run:
|
||||
|
||||
pip install "mitmproxy==0.18.2"
|
||||
|
||||
|
||||
Apologies for the inconvenience!
|
||||
""")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def assert_utf8_env():
|
||||
spec = ""
|
||||
for i in ["LANG", "LC_CTYPE", "LC_ALL"]:
|
||||
@@ -47,6 +72,7 @@ def process_options(parser, options, args):
|
||||
|
||||
|
||||
def mitmproxy(args=None): # pragma: no cover
|
||||
py3()
|
||||
if os.name == "nt":
|
||||
print("Error: mitmproxy's console interface is not supported on Windows. "
|
||||
"You can run mitmdump or mitmweb instead.", file=sys.stderr)
|
||||
@@ -83,6 +109,7 @@ def mitmproxy(args=None): # pragma: no cover
|
||||
|
||||
|
||||
def mitmdump(args=None): # pragma: no cover
|
||||
py3()
|
||||
from . import dump
|
||||
|
||||
version_check.check_pyopenssl_version()
|
||||
@@ -117,6 +144,7 @@ def mitmdump(args=None): # pragma: no cover
|
||||
|
||||
|
||||
def mitmweb(args=None): # pragma: no cover
|
||||
py3()
|
||||
from . import web
|
||||
|
||||
version_check.check_pyopenssl_version()
|
||||
|
||||
@@ -67,6 +67,7 @@ class Options(optmanager.OptManager):
|
||||
ignore_hosts = (), # type: Sequence[str]
|
||||
listen_host = "", # type: str
|
||||
listen_port = LISTEN_PORT, # type: int
|
||||
upstream_bind_address = "", # type: str
|
||||
mode = "regular", # type: str
|
||||
no_upstream_cert = False, # type: bool
|
||||
rawtcp = False, # type: bool
|
||||
@@ -127,6 +128,7 @@ class Options(optmanager.OptManager):
|
||||
self.ignore_hosts = ignore_hosts
|
||||
self.listen_host = listen_host
|
||||
self.listen_port = listen_port
|
||||
self.upstream_bind_address = upstream_bind_address
|
||||
self.mode = mode
|
||||
self.no_upstream_cert = no_upstream_cert
|
||||
self.rawtcp = rawtcp
|
||||
|
||||
@@ -121,7 +121,7 @@ class ServerConnectionMixin(object):
|
||||
server_address, (self.ctx.client_conn.address.host, 0), True)
|
||||
else:
|
||||
self.server_conn = models.ServerConnection(
|
||||
server_address, (self.config.options.listen_host, 0))
|
||||
server_address, (self.config.options.upstream_bind_address, 0))
|
||||
|
||||
self.__check_self_connect()
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from mitmproxy import builtins
|
||||
from mitmproxy import controller
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy import flow
|
||||
from mitmproxy import flowfilter
|
||||
from mitmproxy import options
|
||||
from mitmproxy.web import app
|
||||
from netlib.http import authentication
|
||||
@@ -180,8 +181,12 @@ class WebMaster(flow.FlowMaster):
|
||||
self.shutdown()
|
||||
|
||||
def _process_flow(self, f):
|
||||
if self.state.intercept and self.state.intercept(
|
||||
f) and not f.request.is_replay:
|
||||
should_intercept = (
|
||||
self.state.intercept and flowfilter.match(self.state.intercept, f)
|
||||
and not f.request.is_replay
|
||||
and f.reply.state == "handled"
|
||||
)
|
||||
if should_intercept:
|
||||
f.intercept(self)
|
||||
return f
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import (absolute_import, print_function, division)
|
||||
|
||||
IVERSION = (0, 18, 1)
|
||||
IVERSION = (0, 18, 3)
|
||||
VERSION = ".".join(str(i) for i in IVERSION)
|
||||
PATHOD = "pathod " + VERSION
|
||||
MITMPROXY = "mitmproxy " + VERSION
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[flake8]
|
||||
max-line-length = 140
|
||||
max-complexity = 25
|
||||
ignore = E251,C901
|
||||
ignore = E251,C901,W503
|
||||
exclude = mitmproxy/contrib/*,test/mitmproxy/data/*
|
||||
builtins = file,open,basestring,xrange,unicode,long,cmp
|
||||
|
||||
|
||||
2
setup.py
2
setup.py
@@ -69,7 +69,7 @@ setup(
|
||||
"cryptography>=1.3, <1.6",
|
||||
"cssutils>=1.0.1, <1.1",
|
||||
"Flask>=0.10.1, <0.12",
|
||||
"h2>=2.4.1, <3",
|
||||
"h2>=2.4.1, <2.5",
|
||||
"html2text>=2016.1.8, <=2016.9.19",
|
||||
"hyperframe>=4.0.1, <5",
|
||||
"jsbeautifier>=1.6.3, <1.7",
|
||||
|
||||
@@ -379,14 +379,14 @@ class TestSNI(tservers.ServerTestBase):
|
||||
class TestServerCipherList(tservers.ServerTestBase):
|
||||
handler = ClientCipherListHandler
|
||||
ssl = dict(
|
||||
cipher_list='RC4-SHA'
|
||||
cipher_list='AES128-SHA'
|
||||
)
|
||||
|
||||
def test_echo(self):
|
||||
c = tcp.TCPClient(("127.0.0.1", self.port))
|
||||
with c.connect():
|
||||
c.convert_to_ssl(sni="foo.com")
|
||||
assert c.rfile.readline() == b"['RC4-SHA']"
|
||||
assert c.rfile.readline() == b"['AES128-SHA']"
|
||||
|
||||
|
||||
class TestServerCurrentCipher(tservers.ServerTestBase):
|
||||
@@ -399,14 +399,14 @@ class TestServerCurrentCipher(tservers.ServerTestBase):
|
||||
self.wfile.flush()
|
||||
|
||||
ssl = dict(
|
||||
cipher_list='RC4-SHA'
|
||||
cipher_list='AES128-SHA'
|
||||
)
|
||||
|
||||
def test_echo(self):
|
||||
c = tcp.TCPClient(("127.0.0.1", self.port))
|
||||
with c.connect():
|
||||
c.convert_to_ssl(sni="foo.com")
|
||||
assert b"RC4-SHA" in c.rfile.readline()
|
||||
assert b"AES128-SHA" in c.rfile.readline()
|
||||
|
||||
|
||||
class TestServerCipherListError(tservers.ServerTestBase):
|
||||
@@ -424,7 +424,7 @@ class TestServerCipherListError(tservers.ServerTestBase):
|
||||
class TestClientCipherListError(tservers.ServerTestBase):
|
||||
handler = ClientCipherListHandler
|
||||
ssl = dict(
|
||||
cipher_list='RC4-SHA'
|
||||
cipher_list='AES128-SHA'
|
||||
)
|
||||
|
||||
def test_echo(self):
|
||||
|
||||
Reference in New Issue
Block a user