# coding=utf-8
from win32com.client import DispatchEx
from random import choice
import string
"""
仅供娱乐。
本方案只针对excel workbook密码,至于word,worksheet破解有漏洞哦。
真想破解。。。傻瓜操作,网上有不少跑字典的软件,都可以试试。
找软件漏洞,找字典跑,用C去写穷举。
工作薄打开密码唯有穷举、工作表保护密码,工作薄保护密码、vba代码保护密码。
"""
def read_excel_password(filename, password=None):
excel = DispatchEx("Excel.Application") # 启动excel
excel.Visible = False # 去掉可视化
try:
demo = excel.Workbooks.Open(filename,
UpdateLinks=False,
ReadOnly=False,
Format=None,
Password=password) # 打开文件并将密码传入
except BaseException:
print("错误密码:[%s]" % password)
return 0
else:
print("正确密码:[%s]" % password)
demo.Close(True)
return 666
def demo_keys(length=4, types="默认"):
# 导入字符集
chars_zd = {
"字母": string.ascii_letters,
"数字": string.digits,
"符号": "`-=[]\\;',./*-+~()_{}|:<>?\""
}
if types == "符号":
chars = chars_zd.values()
elif types == "默认":
chars = chars_zd['字母'] + chars_zd["数字"]
else:
chars = chars_zd[types]
password = ''.join([choice(chars) for i in range(length)])
return password
if __name__ == '__main__':
print("为了提升破解效率,请准确填写大概范围!填写符号则将进行最大穷举!!!")
print("密码类型默认是字母+数字组合")
print("密码位数默认是四位")
# types = input("请输入[字母,数字, 符号, 默认]:")
# length = input("请输入密码位数:")
types = "数字"
length = 4
# 导入文件地址
filename = r"加密.xlsx"
while True:
password = demo_keys(length=int(length), types=types)
biaozhi = read_excel_password(filename=filename, password=password)
if biaozhi == 666:
break
欢迎大神提供python破解excel工作簿更块更好的方法,我知道可以demo_keys可以做到更简便,但是这段程序效率最低的片段是read_excel_password。。。
觉得有趣的话,新人求赞啊。