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.
This commit is contained in:
Aldo Cortesi 2011-07-23 12:57:54 +12:00
parent 689f5f0d1f
commit 4043829cf2
3 changed files with 23 additions and 2 deletions

View File

@ -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',

View File

@ -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

View File

@ -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)