2014-11-22 78 views
-1

我正在學習python,並且正在研究其中一個早期練習,並按照說明創建了所有內容並放置了字典文件並指出腳本在我的/ etc/passwd文件中,但不斷收到此錯誤:AttributeError:'str'對象沒有屬性'salt'

AttributeError: 'str' object has no attribute 'salt' 

這裏是我使用的代碼:

import crypt 
def testPass(cryptPass): 
    salt = cryptPass[0:2] 
    dictFile = open('dictionary.txt','r') 
    for word in dictFile.readlines(): 
     word = word.strip('\n') 
     cryptWord = crypt.crypt(word.salt) 
     if (cryptWord == cryptPass): 
      print "[+] Found Password: "+word+"\n" 
      return 
    print "[-] Password Not Found.\n" 
    return 
def main(): 
    passFile = open('/etc/passwd') 
    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() 

回答

0

您試圖在字符串word使用salt屬性

cryptWord = crypt.crypt(word.salt) 
#      ^^^^^^^^^ 

你大概意思都使用逗號,在名稱salt傳遞作爲單獨的參數:

cryptWord = crypt.crypt(word, salt) 
+0

這確實是答案,非常感謝你:) – 2014-11-22 18:53:57