From 4043829cf2d60388133974e12bf45c7e61805189 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 23 Jul 2011 12:57:54 +1200 Subject: Add an eventlog option to mitmdump This shows client connections, disconnections and requests (before a complete flow is assembled). We need to add an analogous display to mitmproxy. --- libmproxy/cmdline.py | 6 ++++++ libmproxy/dump.py | 14 ++++++++++++++ test/test_dump.py | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index f4d0e430..5f51b854 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -19,6 +19,7 @@ def get_common_options(options): anticomp = options.anticomp, autodecode = options.autodecode, client_replay = options.client_replay, + eventlog = options.eventlog, kill = options.kill, no_server = options.no_server, refresh_server_playback = not options.norefresh, @@ -45,6 +46,11 @@ def common_options(parser): action="store_true", dest="autodecode", help="Automatically decode compressed server responses." ) + parser.add_option( + "-e", + action="store_true", dest="eventlog", + help="Show event log." + ) parser.add_option( "--confdir", action="store", type = "str", dest="confdir", default='~/.mitmproxy', diff --git a/libmproxy/dump.py b/libmproxy/dump.py index e547d78d..75628631 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -10,6 +10,7 @@ class Options(object): "anticomp", "autodecode", "client_replay", + "eventlog", "keepserving", "kill", "no_server", @@ -58,6 +59,7 @@ class DumpMaster(flow.FlowMaster): self.anticache = options.anticache self.anticomp = options.anticomp self.autodecode = options.autodecode + self.eventlog = options.eventlog self.refresh_server_playback = options.refresh_server_playback if filtstr: @@ -130,8 +132,20 @@ class DumpMaster(flow.FlowMaster): "%s: %s\n%s"%(script, e.args[0], eout) ) + def handle_clientconnect(self, c): + if self.eventlog: + print >> self.outfile, "Connection from: %s:%s"%c.address + return flow.FlowMaster.handle_clientconnect(self, c) + + def handle_clientdisconnect(self, c): + if self.eventlog: + print >> self.outfile, "Disconnect from: %s:%s"%c.client_conn.address + return flow.FlowMaster.handle_clientconnect(self, c) + def handle_request(self, r): f = flow.FlowMaster.handle_request(self, r) + if self.eventlog: + print >> self.outfile, "Request: %s"%str_request(r) if f: r.ack() return f diff --git a/test/test_dump.py b/test/test_dump.py index f860d1e0..95e7a98c 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -1,7 +1,7 @@ import os from cStringIO import StringIO import libpry -from libmproxy import dump, flow +from libmproxy import dump, flow, proxy import tutils class uStrFuncs(libpry.AutoTree): @@ -27,6 +27,7 @@ class uDumpMaster(libpry.AutoTree): m.handle_clientconnect(cc) m.handle_request(req) m.handle_response(resp) + m.handle_clientdisconnect(proxy.ClientDisconnect(cc)) def _dummy_cycle(self, filt, content, **options): cs = StringIO() @@ -73,7 +74,7 @@ class uDumpMaster(libpry.AutoTree): def test_basic(self): for i in (1, 2, 3): - assert "GET" in self._dummy_cycle("~s", "", verbosity=i) + assert "GET" in self._dummy_cycle("~s", "", verbosity=i, eventlog=True) assert "GET" in self._dummy_cycle("~s", "\x00\x00\x00", verbosity=i) assert "GET" in self._dummy_cycle("~s", "ascii", verbosity=i) -- cgit v1.2.3