第 1 章 入门
第一个程序: UNIX 口令破解机
需要使用 UNIX 计算口令 hash 的 crypt() 算法,可以看到 Python 标准库中已自带 crypt
import crypt
crypt.crypt("egg", "HX") # => word, salt在基于 *Nix 的现代操作系统中,/etc/shadow 文件中存储了口令的 hash,并能使用更多安全的 hash 算法
第二个程序:一个 Zip 文件口令破解机
需要学习 zipfile 库,其中有 extractall() 方法,用可选参数指定密码
import zipfile
zFile = zipfile.ZipFile("evil.zip")
zFile.extractall(pwd="secret")如果用错误的口令执行脚本,可以看到抛出异常了
可以利用线程同时测试多个口令,而不是只能逐个测试词库中的单词
import zipfile
from threading import Thread
def extractFile(zFile, password):
try:
zFile.extractall(pwd=password)
print("[+] Found password {}".format(password))
except:
pass
def main():
zFile = zipfile.ZipFile("evil.zip")
passFile = open("dictionary.txt")
for line in passFile.readlines():
password = line.strip("\n")
t = Thread(target=extractFile, args=(zFile, password))
t.start()还可以用 optparse 库提供参数选择
Last updated
Was this helpful?