MSoffice(excel,word,ppt)暴力破解密码

先直接上成品,拿来就可以用
https://download.csdn.net/download/wangzhenhaha12/87892912

再来谈思路

  • win32com.client
    Mac上用不了
  • msoffcrypto
pip install msoffcrypto-tool
  1. step1 穷举密码
    # digit
   for i in range(48, 58):
       print(chr(i))

三层for循环实现密码的穷举

    for length in range(1, 1 + 2):
        base = len(charset)
        for i in range(base ** length):
            # print('数%s' % i)
            for j in range(length, 0, -1):
                # print('位%s' % j)
import itertools

i = itertools.product('abcdefghigklmnopqrstuvwxyz1234567890', repeat=20)
for j in i:
    print(j)
  1. step2 逐个尝试
import msoffcrypto
import io
import pandas as pd

# BASIC
encrypted = open("encrypted.docx", "rb")
file = msoffcrypto.OfficeFile(encrypted)

file.load_key(password="Passw0rd")  # Use password

with open("decrypted.docx", "wb") as f:
    file.decrypt(f)

encrypted.close()

# IN MEMORY
decrypted = io.BytesIO()

with open("encrypted.xlsx", "rb") as f:
    file = msoffcrypto.OfficeFile(f)
    file.load_key(password="Passw0rd")  # Use password
    file.decrypt(decrypted)

df = pd.read_excel(decrypted)
print(df)