rar文件爆破解压

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from threading import Thread
from unrar import rarfile
import os


def CreatePwd():
f = open('passdict.txt', 'w')
for id in range(10000):
password = str(id).zfill(4) + '\n'
f.write(password)
f.close()


def get_pwd(dict_path):
with open(dict_path, 'r') as f:
for pwd in f:
yield pwd.strip()


def decode_rar(fp, pwd, extract_path, path):
try:
fp.extractall(extract_path, pwd=pwd) #解压文件,extract_path为解压路径,pwd为解压密码
except:
pass
# print('【ERROR】', pwd)
else:
print('the pwd is>', pwd)
os._exit(0) #终止程序


def main():
CreatePwd()
extract_path = 'flag.txt'
dict_path = 'passdict.txt'
path='1.php'
filename = '基础破解.rar'
fp = rarfile.RarFile(filename) #待解压文件
pwds = get_pwd(dict_path)
'''使用多线程可提高速度'''
# for pwd in pwds:
# decode_rar(fp, pwd, extract_path)
for pwd in pwds:
t = Thread(target=decode_rar, args=(fp, pwd, extract_path,path))
t.start()


if __name__ == '__main__':
main()

由于rarfile库需要unrar系统文件,所以需要在http://www.rarlab.com/rar/UnRARDLL.exe下载UnRARDLL.exe软件,安装成功后,修改x64中的两个系统文件为unrar,并将x64文件夹路径写入到环境变量的path中即可。