Use python to crack Unix password | LSABLOG

首页 » NetworkSec » Penetration » 正文

Use python to crack Unix password

Environment:Ubuntu+python2.7

As we know,Unix use crypt() to encrypt password,so we can use crypt() to crack it.

#!/usr/bin/python
#coding:utf-8
#Author:LSA
#Description:Use crypt() to crack Unix password
#Date:20170219

import crypt

def crackUnixPass(cryptPassword):
    salt = cryptPassword[0:2]
    dFile = open('dictionary.txt','r')
    for word in dFile:
        word = word.strip('\r\n')
        cryptWord = crypt.crypt(word, salt)
        if cryptWord == cryptPassword:
            print 'Found password: '+word+'\n' 
            return
    print 'Password not found.'
    return


def main():
    pFile = open('passwords.txt')
    for line in pFile:
        if ':' in line:
            user = line.split(':')[0]
            cryptPassword = line.split(':')[1].strip(' ')
            print 'Cracking password for: '+user
            crackUnixPass(cryptPassword)


if __name__=='__main__':
    main()

Comment