So, I have a quick question about a small password cracking program that I wrote. The syntax seems to be fine, but when run at the command terminal (I'm on a mac), the program doesn't really DO anything. I'll click "run in terminal" or I'll already have the terminal window open and just input "python crack.py" and it wont do anything, it just returns another new fresh command line prompt. Ideas?

#!/usr/bin/python

import crypt

def testPass(cryptPass):
    salt = cryptPass[0:2] 
    dictFile = open('/Users/some_user/Desktop/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('/Users/some_user/Desktop/passwords.txt')
    for line in passFile.readline():
        if ":" in line:
            user = line.split(":")[0]
            cryptPass = line.split(':')[1].strip(' ') 
            print("[*] Cracking Password for: " + user)
            testPass(cryptPass) 

if __name__ == "__main__":
    main() 

If no line of /Users/some_user/Desktop/passwords.txt contains a colon, your program won't print any output. Add a call to print() for every line in the loop.

Edit: I just noticed the call to readline(). It reads only a single line. Use readlines().

Any particular place after the if : line that I would need to place the call to print()? And thanks for catching that printline error!

Nevermind.

Okay so I modified the files a little bit, but its still not matching the hashed passwords to the passwords in the dictionary txt (the passwords.txt is a file containing 2 hashed passwords).

Any ideas?

import crypt
def testPass(cryptPass):
    salt = cryptPass[0:2] 
    dictFile = open('/Users/some_user/Desktop/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('/Users/some_user/Desktop/passwords.txt')
    for line in passFile.readline():
        if ":" in line:
            user = line.split(":")[0]
            cryptPass = line.split(':')[1].strip(' ') 
            print("[*] Cracking Password for: " + user)
            testPass(cryptPass) 
if __name__ == "__main__":
    main() 

I'm pretty sure the error is somewhere with the readlines, im trying a zipfile program to compare to the dictionary file and its not working either :/ I've tested the password with the actual zip file and it works perfect, but the program cant find a match.

import zipfile 
zFile = zipfile.ZipFile('/Users/some_user/Desktop/20130328/144046_dragonx.zip') 
passFile = open('/Users/some_user/Desktop/dictionary.txt') 
for line in passFile.readline():
    password = line.strip('\n')  
    try:
        zfile.extractall(pwd=password) 
        print '[+] Password = ' + password + '\n' 
        exit(0) 
    except Exception, e:
        print "Error"

readlines() like has been said or only passFile

Ive changed it to readlines, but it still doesnt read the lines right out of the dictionary file.

Got the first program figured out, all I needed was to subtract the if ":" bit and rewrite it from scratch again. Once I figure out whats preventing the zipfile from working I can close this thread out! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.