Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #!/usr/bin/python
  2. ###############################################################################
  3. # IMPORTANT:
  4. # Place this script in $JOHN/run/ directory.
  5. #
  6. # USAGE:
  7. # $ python <scriptname>.py <passwdfile> <outfile>
  8. # Where -
  9. # scriptname = name of this script.
  10. # passwdfile = passwd file cracked by JtR.
  11. # outfile = file name/destination of the output file.
  12. #
  13. # OUTPUT:
  14. # The output file generated containt a combination of [user:password] on
  15. # every line for every pair of username and pasword cracked.
  16. # Example -
  17. # alice:alice
  18. # bob:bob
  19. ###############################################################################
  20.  
  21. import sys
  22. import subprocess
  23. import re
  24. import os
  25.  
  26.  
  27. def formatJohnShow(johnShowString):
  28. # Split the string into lines
  29. linesArr = johnShowString.splitlines(True)
  30. formattedShow = ""
  31. for line in linesArr:
  32. # Compile and run a regex on every line to get the formatted line
  33. m = re.search('(^\w+[:]+\w+)', line)
  34. # If regex match
  35. if m:
  36. # Add the formatted line to a string
  37. formattedShow += m.group(1)
  38. # Add a new line to seprate pairs
  39. formattedShow += '\n'
  40. return formattedShow
  41.  
  42.  
  43. def johnShow(passwdfile):
  44. # You know nothing John Sh(n)ow ;)
  45. # Command to run in bash
  46. johnCrackedPassCMD = "./john --show " + passwdfile
  47. process = subprocess.Popen(
  48. johnCrackedPassCMD.split(), stdout=subprocess.PIPE)
  49. # Get the output of the command execution
  50. output = process.communicate()[0]
  51. return output
  52.  
  53. if __name__ == '__main__':
  54.  
  55. # Get the name of this script
  56. script = sys.argv[0]
  57.  
  58. # Check the no. of arguments passed
  59. if len(sys.argv) == 3:
  60. # Get the passwd file
  61. passwdfile = sys.argv[1]
  62. # Name of the output file
  63. outfile = sys.argv[2]
  64.  
  65. # Get string generated from using john --show <passwdfile>
  66. johnShowString = johnShow(passwdfile)
  67. # Get formated string for writing to file
  68. userpass = formatJohnShow(johnShowString)
  69.  
  70. # Open the proper file
  71. f = open(outfile, 'w')
  72. # Write the formatted string to file
  73. f.write(userpass)
  74. # Close file
  75. f.close
  76.  
  77. # Display a confirmation message
  78. print "Created: %s" % os.path.abspath(outfile)
  79. else:
  80. print """
  81. Error: Missing arguments!
  82. USAGE: $ python %s <passwdfile> <outfile>
  83. """ % script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement