UNIX口令破解
1.程序运行需求:

其中dictionary.txt文件为破解口令的字典文件,passwords.txt文件为临时存放UNIX系统密码的文件
2.程序源码:
import crypt # 以hash方式加密的unix口令,的一般形式为:HXajgneuer/jids 其中前两位“HX”一般称为salt ,剩下的字符不影响哈希结果 # salt是此哈希的盐值,长度是8位,超过8的后面的位数将不影响哈希的结果。 # 在正常情况下,进行加密的时候,这个盐值是随机字符串。 def testPass(cryptPass): # 根据字典通过crypt函数判断密码 salt = cryptPass[0:2] # 读哈希值得前两位 dictFile = open('dictionary.txt','r') for word in dictFile.readlines(): word = word.strip(' ') # 清除头尾空格,回车符等 # print(word,salt) cryptWord = crypt.crypt(word,salt) #使用字典数据利用crypt函数构造密码 # print(cryptWord,cryptPass) if cryptWord==cryptPass: print("[+] Found Fassword: " + word + " ") else: print("[-] PassWord Not Find ! ") def main(): passFile = open('passwords.txt') for line in passFile.readlines(): if ":" in line: user = line.split(':')[0] #将password中的数据以 “:” 分为user和password两部分,此为user部分 cryptPass = line.split(':')[1].strip(' ') #此为password部分 print("[*] Cracking Password For: "+user) testPass(cryptPass) #调用检测比对函数 if __name__ == '__main__': main()