JcGNeon

unixcracker.py

Aug 9th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. import crypt
  2. import optparse
  3. import os
  4. import sys
  5. from threading import Thread
  6.  
  7. def checkFiles(pass_file,dict_file):
  8.     if not (os.path.isfile(pass_file)) & (os.path.isfile(dict_file)):
  9.         print "[-] Specified file does not exist."
  10.         exit(0)
  11.     elif not (os.access(pass_file,os.R_OK)) & (os.access(dict_file,os.R_OK)):
  12.         print "[-] Unable to access specified file(s). Access denied."
  13.         exit(0)
  14.     else:
  15.         print "[+] Specified files exist."
  16.         main()
  17.  
  18. def testPass(dictFile,cryptPass):
  19.     salt = cryptPass[0:2]
  20.     for word in dictFile.readlines():
  21.         word = word.strip('\n')
  22.         cryptWord = crypt.crypt(word,salt)
  23.         if (cryptWord == cryptPass):
  24.             print "[+] Password found: " +str(word)
  25.             return
  26.     print "[-] Password not in dictionary."
  27.     return
  28.          
  29. def main():
  30.     parser = optparse.OptionParser("[%] usage: -f <filename> -d <dictionary>")
  31.     parser.add_option("-f", dest = "thefile", type = "string", help = "specify the target file")
  32.     parser.add_option("-d", dest = "thedict", type = "string", help = "specify the target dictionary.")
  33.     (options,args) = parser.parse_args()
  34.     if (options.thefile == None) | (options.thedict == None):
  35.         print parser.usage
  36.         exit(0)
  37.     else:
  38.         txtName = options.thefile
  39.         txtDict = options.thedict
  40.     dictFile = open(txtDict,'r')
  41.     passFile = open(txtName,'r')
  42.    
  43.     for line in passFile.readlines():
  44.         if ":" in line:
  45.             user = line.split(":")[0]
  46.             cryptPass = line.split(":")[1].strip(' ')
  47.             print "[*] Cracking Password for user: " +str(user)
  48.             t = Thread(target = testPass, args = (dictFile,cryptPass))
  49.             t.start()
  50.  
  51. if __name__ == "__main__":
  52.     pass_file = sys.argv[2]
  53.     dict_file = sys.argv[4]
  54.     checkFiles(pass_file,dict_file)
Add Comment
Please, Sign In to add comment