PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/pentest/grabber/session.py

https://github.com/sullivanmatt/Raspberry-Pwn
Python | 73 lines | 62 code | 5 blank | 6 comment | 1 complexity | 9225ab10326864b00a74bc5045ef0e97 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, MPL-2.0-no-copyleft-exception, GPL-2.0, GPL-3.0
  1. #!/usr/bin/env python
  2. """
  3. Session Analyzer Module for Grabber v0.1
  4. Copyright (C) 2006 - Romain Gaucher - http://rgaucher.info
  5. """
  6. import sys,re,time,datetime
  7. from grabber import getContentDirectURL_GET
  8. sessions = {}
  9. def normalize_whitespace(text):
  10. return ' '.join(text.split())
  11. def getDirectSessionID(currentURL, sid):
  12. k = currentURL.find(sid)
  13. if k > 0:
  14. return currentURL[k+10:]
  15. return None
  16. def stripNoneASCII(output):
  17. # should be somepthing to do that.. :/
  18. newOutput = ""
  19. for s in output:
  20. try:
  21. s = s.encode()
  22. newOutput += s
  23. except UnicodeDecodeError:
  24. continue
  25. return newOutput
  26. regDate = re.compile(r'^Date: (.*)$', re.I)
  27. def lookAtSessionID(url, sidName, regSession):
  28. global sessions
  29. handle = getContentDirectURL_GET(url,"")
  30. if handle != None:
  31. output = handle.read()
  32. header = str(handle.info()).split('\n')
  33. for h in header:
  34. # extract date header information
  35. if regDate.match(h):
  36. out = regDate.search(h)
  37. date = out.group(1)
  38. # convert this date into the good GMT number
  39. # ie time in seconds since 01/01/1970 00:00:00
  40. gi = time.strptime(normalize_whitespace(date.replace('GMT','')), "%a, %d %b %Y %H:%M:%S")
  41. gi = time.mktime(gi) - time.mktime(time.gmtime(0))
  42. output = output.replace('\n','')
  43. output = output.replace('\t','')
  44. # print output[790:821]
  45. output = stripNoneASCII(output)
  46. if output.find(sidName) > 0:
  47. if regSession.match(output):
  48. out = regSession.search(output)
  49. ssn = out.group(2)
  50. if ssn != None:
  51. if gi != None:
  52. sessions[ssn] = gi
  53. else:
  54. sessions[ssn] = ''
  55. def process(url, database, sidName):
  56. regString = "(.*)" + sidName + "=([a-z|A-Z|0-9]+)(.*)"
  57. regSession = re.compile(regString,re.I)
  58. print url, sidName, regString
  59. for k in range(0,1000):
  60. lookAtSessionID(url, sidName, regSession)
  61. o = open('results/sessions.txt','w')
  62. for s in sessions:
  63. o.write("%s, %s\n" % (s, sessions[s]))
  64. o.close()