Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import hashlib, binascii
  5. import os,sys
  6. import crypt
  7. import codecs
  8. from datetime import datetime,timedelta
  9. import argparse
  10. today = datetime.today()
  11.  
  12. # Takes in user and the encrypted passwords and does a simple
  13. # Brute Force Attack useing the '==' operator. SHA* is defined by
  14. # a number b/w $, the char's b/w the next $ marker would be the
  15. # rounds, then the salt, and after that the hashed password.
  16. # object.split("some symbol or char")[#], where # is the
  17. # location/index within the list
  18. def testPass(cryptPass,user):
  19.  
  20. digest = hashlib.sha512
  21. dicFile = open ('Dictionary.txt','r')
  22. ctype = cryptPass.split("$")[1]
  23. if ctype == '6':
  24. print "[+] Hash type SHA-512 detected ..."
  25. print "[+] Be patien ..."
  26. rounds = cryptPass.split("$")[2].strip('rounds=')
  27. salt = cryptPass.split("$")[3]
  28. print "[DEBUG]: " + rounds
  29. print "[DEBUG]: " + salt
  30. # insalt = "$" + ctype + "$" + salt + "$" << COMMENTED THIS OUT
  31. for word in dicFile.readlines():
  32. word = word.strip('n')
  33. print "[DEBUG]: " + word
  34. cryptWord = hashlib.pbkdf2_hmac(digest().name,bytearray(word, 'utf-8'),bytearray(salt, 'utf-8'), rounds)
  35. if (cryptWord == cryptPass):
  36. time = time = str(datetime.today() - today)
  37. print "[+] Found password for the user: " + user + " ====> " + word + " Time: "+time+"n"
  38. return
  39. else:
  40. print "Nothing found, bye!!"
  41. exit
  42.  
  43. # argparse is used in main to parse arguments pass by the user.
  44. # Path to shadow file is required as a argument.
  45. def main():
  46.  
  47. parse = argparse.ArgumentParser(description='A simple brute force /etc/shadow .')
  48. parse.add_argument('-f', action='store', dest='path', help='Path to shadow file, example: '/etc/shadow'')
  49. argus=parse.parse_args()
  50. if argus.path == None:
  51. parse.print_help()
  52. exit
  53. else:
  54. passFile = open (argus.path,'r', 1) # ADDING A 1 INDICATES A BUFFER OF A
  55. for line in passFile.readlines(): # SINGLE LINE '1<=INDICATES
  56. line = line.replace("n","").split(":") # EXACT BUFFER SIZE
  57. if not line[1] in [ 'x', '*','!' ]:
  58. user = line[0]
  59. cryptPass = line[1]
  60. testPass(cryptPass,user)
  61.  
  62. if __name__=="__main__":
  63. main()
  64.  
  65. [+] Hash type SHA-512 detected ...
  66. [+] Be patien ...
  67. [DEBUG]: 65536
  68. [DEBUG]: A9UiC2ng
  69. [DEBUG]: hellocat
  70. Traceback (most recent call last):
  71. File "ShadowFileCracker.py", line 63, in <module>
  72. main()
  73. File "ShadowFileCracker.py", line 60, in main
  74. testPass(cryptPass,user)
  75. File "ShadowFileCracker.py", line 34, in testPass
  76. cryptWord = hashlib.pbkdf2_hmac(digest().name,bytearray(word, 'utf-8'),bytearray(salt, 'utf-8'), rounds)
  77. TypeError: an integer is required
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement