Skip to content

Instantly share code, notes, and snippets.

@dstd
Created March 2, 2026 21:18
Show Gist options
  • Select an option

  • Save dstd/b6f09ce8a4215eeefdaa3e1775ae90ea to your computer and use it in GitHub Desktop.

Select an option

Save dstd/b6f09ce8a4215eeefdaa3e1775ae90ea to your computer and use it in GitHub Desktop.
[mitmproxy][dirtyhack] Fixed version of flow.kill that really terminates the connections, rather just marking flows as killed
# Managed to workaround my problem via a dirty hack.
# Not quite good, but it works and solves my daily tasks.
class FlowKillFix:
def kill_flow(self, flow):
server = ctx.master.addons.get("proxyserver")
conn = flow.client_conn
handler = server.connections.get(conn.id)
dropped = []
if handler is not None:
handler.close_connection(conn, False)
dropped.append("client")
conn = flow.server_conn
handler = server.connections.get(conn.id)
if handler is not None:
handler.close_connection(conn, False)
dropped.append("server")
if len(dropped) > 0:
ctx.log.alert(f"dropped {"-".join(dropped)} for {flow.request.url}")
else:
ctx.log.error(f"dropped nothing for {flow.request.url}")
@command.command("flow.drop")
def flow_drop(self, flows: Sequence[flow.Flow]) -> None:
for f in flows:
if isinstance(f, http.HTTPFlow):
self.kill_flow(f)
else:
ctx.log.error(f"skipped non-http {f}")
addons = [FlowKillFix()]
# Kill focused flow by Ctrl+K with confirmation of operation by Enter
-
ctx: ["flowlist","flowview"]
key: ctrl k
cmd: console.command flow.drop @focus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment