diff options
-rw-r--r-- | mitmproxy/addons/intercept.py | 4 | ||||
-rw-r--r-- | mitmproxy/options.py | 5 | ||||
-rw-r--r-- | mitmproxy/tools/console/consoleaddons.py | 7 | ||||
-rw-r--r-- | mitmproxy/tools/console/defaultkeys.py | 1 | ||||
-rw-r--r-- | mitmproxy/tools/console/statusbar.py | 2 | ||||
-rw-r--r-- | mitmproxy/tools/web/app.py | 1 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_intercept.py | 12 |
7 files changed, 31 insertions, 1 deletions
diff --git a/mitmproxy/addons/intercept.py b/mitmproxy/addons/intercept.py index ac8c4c88..9e1a283e 100644 --- a/mitmproxy/addons/intercept.py +++ b/mitmproxy/addons/intercept.py @@ -11,12 +11,14 @@ class Intercept: if "intercept" in updated: if not ctx.options.intercept: self.filt = None + ctx.options.intercept_active = False return self.filt = flowfilter.parse(ctx.options.intercept) if not self.filt: raise exceptions.OptionsError( "Invalid interception filter: %s" % ctx.options.intercept ) + ctx.options.intercept_active = True def process_flow(self, f): if self.filt: @@ -24,7 +26,7 @@ class Intercept: self.filt(f), not f.request.is_replay, ]) - if should_intercept: + if should_intercept and ctx.options.intercept_active: f.intercept() # Handlers diff --git a/mitmproxy/options.py b/mitmproxy/options.py index a3042008..8a01cf40 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -386,6 +386,11 @@ class Options(optmanager.OptManager): ) self.add_option( + "intercept_active", bool, False, + "Intercept toggle" + ) + + self.add_option( "intercept", Optional[str], None, "Intercept filter expression." ) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index a65f0afe..0b0993c8 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -68,6 +68,13 @@ class ConsoleAddon: """ return ["single", "vertical", "horizontal"] + @command.command("intercept_toggle") + def intercept_toggle(self) -> None: + """ + Toggles interception on/off leaving intercept filters intact. + """ + ctx.options.intercept_active = not ctx.options.intercept_active + @command.command("console.layout.cycle") def layout_cycle(self) -> None: """ diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py index 105be2be..4634b1e2 100644 --- a/mitmproxy/tools/console/defaultkeys.py +++ b/mitmproxy/tools/console/defaultkeys.py @@ -24,6 +24,7 @@ def map(km): km.add("ctrl f", "console.nav.pagedown", ["global"], "Page down") km.add("ctrl b", "console.nav.pageup", ["global"], "Page up") + km.add("I", "console.command intercept_toggle", ["global"], "Toggle intercept") km.add("i", "console.command set intercept=", ["global"], "Set intercept") km.add("W", "console.command set save_stream_file=", ["global"], "Stream to file") km.add("A", "flow.resume @all", ["flowlist", "flowview"], "Resume all intercepted flows") diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py index a37ecbd8..7628c475 100644 --- a/mitmproxy/tools/console/statusbar.py +++ b/mitmproxy/tools/console/statusbar.py @@ -179,6 +179,8 @@ class StatusBar(urwid.WidgetWrap): r.append("CP:%d]" % len(self.master.options.tcp_hosts)) if self.master.options.intercept: r.append("[") + if not self.master.options.intercept_active: + r.append("X") r.append(("heading_key", "i")) r.append(":%s]" % self.master.options.intercept) if self.master.options.view_filter: diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index 9a447fe7..2a6f6c9e 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -410,6 +410,7 @@ class Settings(RequestHandler): self.write(dict( version=version.VERSION, mode=str(self.master.options.mode), + intercept_active=self.master.options.intercept_active, intercept=self.master.options.intercept, showhost=self.master.options.showhost, upstream_cert=self.master.options.upstream_cert, diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py index f436a817..d4999eb5 100644 --- a/test/mitmproxy/addons/test_intercept.py +++ b/test/mitmproxy/addons/test_intercept.py @@ -13,10 +13,12 @@ def test_simple(): assert not r.filt tctx.configure(r, intercept="~q") assert r.filt + assert tctx.options.intercept_active with pytest.raises(exceptions.OptionsError): tctx.configure(r, intercept="~~") tctx.configure(r, intercept=None) assert not r.filt + assert not tctx.options.intercept_active tctx.configure(r, intercept="~s") @@ -31,3 +33,13 @@ def test_simple(): f = tflow.tflow(resp=True) r.response(f) assert f.intercepted + + tctx.configure(r, intercept_active=False) + f = tflow.tflow(resp=True) + tctx.cycle(r, f) + assert not f.intercepted + + tctx.configure(r, intercept_active=True) + f = tflow.tflow(resp=True) + tctx.cycle(r, f) + assert f.intercepted |