- UNIX密码破解器代码(暴力破解 pwdpass.py):
# coding=UTF-8
import crypt
def testPass(cryptPass):
salt = cryptPass[0:2]
print("salt:",salt)
dictfile = open('dictionary.txt','r')
for word in dictfile.readlines():
word = word.strip('\n')
cryptWord = crypt.crypt(word,salt)
if cryptPass == cryptWord:
print('Found passed:', word)
return
print('Password not found!',word)
return
def main():
passfile = open('passwords.txt','r')
for line in passfile.readlines():
user = line.split(':')[0]
cryptPass = line.split(':')[1].strip('')
print("Cracking PasswordFor:",user)
print("test:",cryptPass)
testPass(cryptPass)
if __name__=='__main__':
main()
测试用例:
dictionary.txt:
sdq
we
qw
eqw
e
qw
d
sa
df
asdg
sd
g
dfas
g
asd
g
asdf
ase
df
asd
f
asdf
asd
f
asdf
sdaf
asdf
asd
f
asdf
asdgasdgsdag
asd
g
sdag
asd
g
asd
gasd
g
asdg
asdg
sda
root
egg
passwords.txt
hx:hxokzx4Ngzx5I:::
- ZIP文件破解(暴力破解)
# coding=UTF-8
"""
ZIP pass pwd
"""
import zipfile
import threading
def extractFile(zFile, password):
try:
zFile.extractall(pwd=password)
print("Found Passwd:",password)
return password
except:
pass
def main():
zFile = zipfile.ZipFile('unzip.zip')
passFile = open('dictionary.txt')
for line in passFile.readlines():
password = line.strip('\n')
t = threading.Thread(target=extractFile,args=(zFile,password))
t.start()
"""
guess = extractFile(zFile,password)
if guess:
print('Password=',password)
return
else:
print("can't find password")
return
"""
if __name__=='__main__':
main()
输入参数版(还未测试):
# coding=UTF-8
import zipfile
import threading
import optparse
def extractFile(zFile,password):
try :
zFile.extractall(pwd=password)
print("Found PassWd:",password)
except:
pass
def main():
parser=optparse.OptionParser('usage%prog -f<zipfile> -d<dictionary>')
parser.add_option('-f',dest='zname',type='string',help='specify zip file')
parser.add_option('-d',dest='dname',type='string',help='specify dictionary file')
options,args=parser.parse_args()
if str(options.zname) == str(None) | str(options.dname) == str(None):
print(parser.usage)
exit(0)
else:
zname = options.zname
dname = options.dname
zFile = zipfile.ZipFile(zname)
dFile = open(dname,'r')
for line in dFile.readlines():
password = line.strip('\n')
t = threading.Thread(target=extractFile,args=(zFile,password))
t.start()
if __name__=='__main__':
main()