mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 15:55:28 +00:00
Merge pull request #3989 from nikitastupin/master
Add minimal TCP interception and modification!
This commit is contained in:
commit
e39b52b159
@ -49,3 +49,7 @@ class Intercept:
|
|||||||
|
|
||||||
def response(self, f):
|
def response(self, f):
|
||||||
self.process_flow(f)
|
self.process_flow(f)
|
||||||
|
|
||||||
|
def tcp_message(self, f):
|
||||||
|
if self.filt and ctx.options.intercept_active:
|
||||||
|
f.intercept()
|
||||||
|
@ -385,22 +385,30 @@ class ConsoleAddon:
|
|||||||
"""
|
"""
|
||||||
Possible components for console.edit.focus.
|
Possible components for console.edit.focus.
|
||||||
"""
|
"""
|
||||||
return [
|
flow = self.master.view.focus.flow
|
||||||
"cookies",
|
focus_options = []
|
||||||
"urlencoded form",
|
|
||||||
"multipart form",
|
if type(flow) == tcp.TCPFlow:
|
||||||
"path",
|
focus_options = ["tcp-message"]
|
||||||
"method",
|
elif type(flow) == http.HTTPFlow:
|
||||||
"query",
|
focus_options = [
|
||||||
"reason",
|
"cookies",
|
||||||
"request-headers",
|
"urlencoded form",
|
||||||
"response-headers",
|
"multipart form",
|
||||||
"request-body",
|
"path",
|
||||||
"response-body",
|
"method",
|
||||||
"status_code",
|
"query",
|
||||||
"set-cookies",
|
"reason",
|
||||||
"url",
|
"request-headers",
|
||||||
]
|
"response-headers",
|
||||||
|
"request-body",
|
||||||
|
"response-body",
|
||||||
|
"status_code",
|
||||||
|
"set-cookies",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
|
return focus_options
|
||||||
|
|
||||||
@command.command("console.edit.focus")
|
@command.command("console.edit.focus")
|
||||||
@command.argument("flow_part", type=mitmproxy.types.Choice("console.edit.focus.options"))
|
@command.argument("flow_part", type=mitmproxy.types.Choice("console.edit.focus.options"))
|
||||||
@ -460,6 +468,10 @@ class ConsoleAddon:
|
|||||||
"console.command",
|
"console.command",
|
||||||
["flow.set", "@focus", flow_part]
|
["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):
|
def _grideditor(self):
|
||||||
gewidget = self.master.window.current("grideditor")
|
gewidget = self.master.window.current("grideditor")
|
||||||
|
@ -164,6 +164,10 @@ class FlowDetails(tabs.Tabs):
|
|||||||
|
|
||||||
from_client = not from_client
|
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))
|
widget_lines.insert(0, self._contentview_status_bar(viewmode.capitalize(), viewmode))
|
||||||
|
|
||||||
return searchable.Searchable(widget_lines)
|
return searchable.Searchable(widget_lines)
|
||||||
|
@ -42,3 +42,13 @@ def test_simple():
|
|||||||
f = tflow.tflow(resp=True)
|
f = tflow.tflow(resp=True)
|
||||||
tctx.cycle(r, f)
|
tctx.cycle(r, f)
|
||||||
assert f.intercepted
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user