From 4b4d97412ba2b58ee9a5f61751c14ceccacf608d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 12 May 2018 13:38:15 +1200 Subject: [PATCH 1/3] clientreplay: don't restrict outbound replay address to listen host Fixes #2647 --- mitmproxy/addons/clientplayback.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mitmproxy/addons/clientplayback.py b/mitmproxy/addons/clientplayback.py index e9fbadcef..99ba1d8df 100644 --- a/mitmproxy/addons/clientplayback.py +++ b/mitmproxy/addons/clientplayback.py @@ -59,9 +59,7 @@ class RequestReplayThread(basethread.BaseThread): # In all modes, we directly connect to the server displayed if self.options.mode.startswith("upstream:"): server_address = server_spec.parse_with_mode(self.options.mode)[1].address - server = connections.ServerConnection( - server_address, (self.options.listen_host, 0) - ) + server = connections.ServerConnection(server_address) server.connect() if r.scheme == "https": connect_request = http.make_connect_request((r.data.host, r.port)) @@ -85,10 +83,7 @@ class RequestReplayThread(basethread.BaseThread): r.first_line_format = "absolute" else: server_address = (r.host, r.port) - server = connections.ServerConnection( - server_address, - (self.options.listen_host, 0) - ) + server = connections.ServerConnection(server_address) server.connect() if r.scheme == "https": server.establish_tls( From 449b8b383deb8ba631bd708333c93638931d77db Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 12 May 2018 13:52:15 +1200 Subject: [PATCH 2/3] controller: add mysteriously missing comment portion Thanks to @tran-tien-dat --- mitmproxy/controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 6e2190663..39d3b74ac 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -96,8 +96,8 @@ class Reply: def commit(self): """ Ultimately, messages are committed. This is done either automatically by - if the message is not taken or manually by the entity which called - .take(). + the handler if the message is not taken or manually by the entity which + called .take(). """ if self.state != "taken": raise exceptions.ControlException( From 58ff51da10eff7090ff2a63436c558b1eb5150c3 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 12 May 2018 14:02:20 +1200 Subject: [PATCH 3/3] command: handle string without terminal escaped char Fixes #2810 --- mitmproxy/command.py | 5 ++++- test/mitmproxy/test_command.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mitmproxy/command.py b/mitmproxy/command.py index c94e8abb2..27f0921d8 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -236,7 +236,10 @@ class CommandManager(mitmproxy.types._CommandBase): """ Execute a command string. May raise CommandError. """ - parts = list(lexer(cmdstr)) + try: + parts = list(lexer(cmdstr)) + except ValueError as e: + raise exceptions.CommandError("Command error: %s" % e) if not len(parts) >= 1: raise exceptions.CommandError("Invalid command: %s" % cmdstr) return self.call_strings(parts[0], parts[1:]) diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 7c0dc06d9..029dbafd5 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -281,6 +281,8 @@ def test_simple(): c.execute("one.two too many args") with pytest.raises(exceptions.CommandError, match="Unknown"): c.call("nonexistent") + with pytest.raises(exceptions.CommandError, match="No escaped"): + c.execute("\\") c.add("empty", a.empty) c.execute("empty")