-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
54 lines (48 loc) · 1.69 KB
/
demo.py
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
49
50
51
52
53
54
# coding=utf-8
import argparse
import os
import zipfile
from os.path import *
def tryZipPwd(zipFile, password, savePath):
try:
zipFile.extractall(path=savePath, pwd=password.encode('utf-8'))
print('[+] Zip File decompression success,password: %s' % (password))
return True
except:
print('[-] Zip File decompression failed,password: %s' % (password))
return False
def main():
# 这里用描述创建了ArgumentParser对象
parser = argparse.ArgumentParser(description='Brute Crack Zip')
# 添加-H命令dest可以理解为咱们解析时获取-H参数后面值的变量名,help是这个命令的帮助信息
parser.add_argument('-f', dest='zFile', type=str,
help='The zip file path.')
parser.add_argument('-w', dest='pwdFile', type=str,
help='Password dictionary file.')
zFilePath = None
pwdFilePath = None
try:
options = parser.parse_args()
zFilePath = options.zFile
pwdFilePath = options.pwdFile
except:
print(parser.parse_args(['-h']))
exit(0)
if zFilePath == None or pwdFilePath == None:
print(parser.parse_args(['-h']))
exit(0)
with zipfile.ZipFile(zFilePath) as zFile:
with open(pwdFilePath) as f:
for pwd in f.readlines():
p, f = split(zFilePath)
dirName = f.split('.')[0]
dirPath = join(p, dirName)
try:
os.mkdir(dirPath)
except:
pass
ok = tryZipPwd(zFile, pwd.strip('\n'), dirPath)
if ok:
break
if __name__ == '__main__':
main()