X-Git-Url: http://git.maemo.org/git/?p=pwnitter;a=blobdiff_plain;f=pwnitter.py;h=6995b0a76d8c201b21125162c9bc3c9971980a75;hp=3efd9678b89cf562cdeeb3927be1460ebafafdf5;hb=95c9e14469b6ce4dd23723e9d5d7aabf3190ca38;hpb=1efb778d2c0d4841cfcbb6b69371caf465b8a836 diff --git a/pwnitter.py b/pwnitter.py index 3efd967..6995b0a 100755 --- a/pwnitter.py +++ b/pwnitter.py @@ -7,13 +7,14 @@ import dbus.service import dbus.mainloop.glib import getopt, sys, pcap, dpkt, re, httplib, urllib +import logging import socket import time import gobject import select import subprocess -status = 'I browsed twitter insecurely on #fossdotin and all I got was this lousy tweet.' +status = 'I browsed twitter insecurely, got #pwned and all I got was this lousy tweet.' def usage(): print >>sys.stderr, 'Usage: %s [-i device]' % sys.argv[0] @@ -29,15 +30,20 @@ class Pwnitter(dbus.service.Object): self.status = status self.is_running = False - @dbus.service.method(NAME, - in_signature='', out_signature='') - def Start(self, device='mon0'): - # FIXME: Prevent double Start() + def setup_monitor(device='mon0'): # FIXME: Replace hardcoded interface cmd = '/usr/sbin/iw wlan0 interface add mon0 type monitor'.split() subprocess.call(cmd) cmd = '/sbin/ifconfig mon0 up'.split() subprocess.call(cmd) + + @dbus.service.method(NAME, + in_signature='', out_signature='') + def Start(self, filename=None): + # FIXME: Prevent double Start() + device = self.device + if filename is None: # Then we do *not* want to read from a PCap file but rather a monitor device + self.setup_monitor(device) self.is_running = True try: self.cap = pcap.pcap(device) @@ -47,6 +53,12 @@ class Pwnitter(dbus.service.Object): self.cap.setfilter('dst port 80') cap_fileno = self.cap.fileno() self.source_id = gobject.io_add_watch(cap_fileno, gobject.IO_IN, self.cap_readable_callback, device) + + @dbus.service.method(NAME, + in_signature='s', out_signature='') + def StartFromFile(self, filename): + return self.Start(filename=filename) + def cap_readable_callback(self, source, condition, device): return self.pwn(device, self.MessageSent) @@ -68,16 +80,20 @@ class Pwnitter(dbus.service.Object): def GetMessage(self): return self.status + + def tear_down_monitor(device='mon0'): + cmd = '/sbin/ifconfig mon0 down'.split() + subprocess.call(cmd) + cmd = '/usr/sbin/iw dev mon0 del'.split() + subprocess.call(cmd) + @dbus.service.method(NAME, in_signature='', out_signature='') def Stop(self): self.is_running = False print "Receive Stop" gobject.source_remove(self.source_id) - cmd = '/sbin/ifconfig mon0 down'.split() - subprocess.call(cmd) - cmd = '/usr/sbin/iw dev mon0 del'.split() - subprocess.call(cmd) + self.tear_down_monitor(self.device) loop.quit() @@ -209,10 +225,26 @@ def main(): if __name__ == '__main__': + from optparse import OptionParser + parser = OptionParser("usage: %prog [options]") + parser.add_option("-l", "--loglevel", dest="loglevel", + help="Sets the loglevel to one of debug, info, warn, error, critical") + parser.add_option("-s", "--session", dest="use_session_bus", + action="store_true", default=False, + help="Bind Pwnitter to the SessionBus instead of the SystemBus") + (options, args) = parser.parse_args() + loglevel = {'debug': logging.DEBUG, 'info': logging.INFO, + 'warn': logging.WARN, 'error': logging.ERROR, + 'critical': logging.CRITICAL}.get(options.loglevel, "warn") + logging.basicConfig(level=loglevel) + log = logging.getLogger("Main") + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - #session_bus = dbus.SessionBus() - session_bus = dbus.SystemBus() + if options.use_session_bus: + session_bus = dbus.SessionBus() + else: + session_bus = dbus.SystemBus() name = dbus.service.BusName(NAME, session_bus) pwnitter = Pwnitter(session_bus, '/Pwnitter') #object.Start()