Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 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. # Sorts the lines in order
  31. linesArr.sort()
  32. formattedShow = ""
  33. for line in linesArr:
  34. # Compile and run a regex on every line to get the formatted line
  35. m = re.search('(^\w+[:]+\w+)', line)
  36. # If regex match
  37. if m:
  38. # Add the formatted line to a string
  39. formattedShow += m.group(1)
  40. # Add a new line to seprate pairs
  41. formattedShow += '\n'
  42. return formattedShow
  43.  
  44.  
  45. def johnShow(passwdfile):
  46. # You know nothing John Sh(n)ow ;)
  47. # Command to run in bash
  48. johnCrackedPassCMD = "./john --show " + passwdfile
  49. process = subprocess.Popen(
  50. johnCrackedPassCMD.split(), stdout=subprocess.PIPE)
  51. # Get the output of the command execution
  52. output = process.communicate()[0]
  53. return output
  54.  
  55. if __name__ == '__main__':
  56.  
  57. # Get the name of this script
  58. script = sys.argv[0]
  59.  
  60. # Check the no. of arguments passed
  61. if len(sys.argv) == 3:
  62. # Get the passwd file
  63. passwdfile = sys.argv[1]
  64. # Name of the output file
  65. outfile = sys.argv[2]
  66.  
  67. # Get string generated from using john --show <passwdfile>
  68. johnShowString = johnShow(passwdfile)
  69. # Get formated string for writing to file
  70. userpass = formatJohnShow(johnShowString)
  71. try:
  72. # Open the proper file
  73. f = open(outfile, 'w')
  74. # Write the formatted string to file
  75. f.write(userpass)
  76. except IOError as e:
  77. print """
  78. Failed to open output file.
  79. I/O error(%d): %s" % (e.errno, e.strerror)
  80. """
  81. finally:
  82. try:
  83. # Close file
  84. f.close
  85. except IOError as e:
  86. print """
  87. Failed to close output file.
  88. I/O error(%d): %s" % (e.errno, e.strerror)
  89. """
  90. # Display a confirmation message
  91. print "Created: %s" % os.path.abspath(outfile)
  92. else:
  93. print """
  94. Error: Missing arguments!
  95. USAGE: $ python %s <passwdfile> <outfile>
  96. """ % script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement