Merge pull request #3989 from nikitastupin/master

Add minimal TCP interception and modification!
This commit is contained in:
Maximilian Hils 2020-07-15 21:55:43 +02:00 committed by GitHub
commit e39b52b159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 16 deletions

View File

@ -49,3 +49,7 @@ class Intercept:
def response(self, f):
self.process_flow(f)
def tcp_message(self, f):
if self.filt and ctx.options.intercept_active:
f.intercept()

View File

@ -385,7 +385,13 @@ class ConsoleAddon:
"""
Possible components for console.edit.focus.
"""
return [
flow = self.master.view.focus.flow
focus_options = []
if type(flow) == tcp.TCPFlow:
focus_options = ["tcp-message"]
elif type(flow) == http.HTTPFlow:
focus_options = [
"cookies",
"urlencoded form",
"multipart form",
@ -402,6 +408,8 @@ class ConsoleAddon:
"url",
]
return focus_options
@command.command("console.edit.focus")
@command.argument("flow_part", type=mitmproxy.types.Choice("console.edit.focus.options"))
def edit_focus(self, flow_part: str) -> None:
@ -460,6 +468,10 @@ class ConsoleAddon:
"console.command",
["flow.set", "@focus", flow_part]
)
elif flow_part == "tcp-message":
message = flow.messages[-1]
c = self.master.spawn_editor(message.content or b"")
message.content = c.rstrip(b"\n")
def _grideditor(self):
gewidget = self.master.window.current("grideditor")

View File

@ -164,6 +164,10 @@ class FlowDetails(tabs.Tabs):
from_client = not from_client
if flow.intercepted:
markup = widget_lines[-1].get_text()[0]
widget_lines[-1].set_text(("intercept", markup))
widget_lines.insert(0, self._contentview_status_bar(viewmode.capitalize(), viewmode))
return searchable.Searchable(widget_lines)

View File

@ -42,3 +42,13 @@ def test_simple():
f = tflow.tflow(resp=True)
tctx.cycle(r, f)
assert f.intercepted
tctx.configure(r, intercept_active=False)
f = tflow.ttcpflow()
tctx.cycle(r, f)
assert not f.intercepted
tctx.configure(r, intercept_active=True)
f = tflow.ttcpflow()
tctx.cycle(r, f)
assert f.intercepted