Advertisement
Guest User

Parse John by Hans-Michael Varbaek

a guest
May 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. # Parse John
  2. # Developed by Hans-Michael Varbaek
  3. # VarBITS
  4. # Version 1.0
  5.  
  6. """
  7. SAMPLE INPUT FILE:
  8.  
  9. SAMPLEP         (domain.com\jdoe:1)
  10. BIKINIB         (domain.com\ssquarepants:1)
  11. RANDOMP         (domain.com\rrandomuser:1)
  12. OTTOM12         (domain.com\ssquarepants:2)
  13. ASSWORD         (domain.com\jdoe:2)
  14. ASSWORD         (domain.com\rrandomuser:2)
  15.  
  16. Note: Delete lines that do not look like the above before running this program/script.
  17. """
  18.  
  19.  
  20. input_filepointer = open("john.txt", "r")
  21. output_dict = {}
  22. output_filename = "john_parsed.txt"
  23.  
  24. # Clear the file and write a header
  25. with open(output_filename, "w") as filename:
  26.     output = "username,domain,password\n"  # Use \r\n for Windows
  27.     filename.write(output)
  28.  
  29. for line in input_filepointer:
  30.     line = line.strip()
  31.     newline = line.split('\t\t\t')  # Three "tabs" are assumed here, change this
  32.     password = newline[0]  # SAMPLEP
  33.     domain_and_user = newline[1].replace("(", "").replace(")", "").split("\\")  # ["domain.com", "jdoe:1"]
  34.     domain = domain_and_user[0]  # domain.com
  35.     user = domain_and_user[1].split(':')[0]  # jdoe
  36.     sequence = domain_and_user[1].split(':')[1]  # 1 or 2
  37.     if sequence == "1":
  38.         output_dict[user] = {"password": password, "domain": domain}
  39.     else:
  40.         output_dict[user]["password"] += password
  41.  
  42. for user in output_dict:
  43.     with open(output_filename, "a") as filename:
  44.         output = "{},{},{}\n".format(user, output_dict[user]["domain"], output_dict[user]["password"])
  45.         # Use \r\n for Windows
  46.         filename.write(output)
  47.  
  48. """
  49. SAMPLE OUTPUT:
  50.  
  51. username,domain,password
  52. ssquarepants,domain.com,BIKINIBOTTOM12
  53. rrandomuser,domain.com,RANDOMPASSWORD
  54. jdoe,domain.com,SAMPLEPASSWORD
  55.  
  56. You can load this in Excel or OpenOffice for example if you have a lot of entries.
  57. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement