Skip to content

Instantly share code, notes, and snippets.

@fahimalizain
Created February 18, 2019 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahimalizain/0e6aef6d7709a8e9f0ce3783fa9992fc to your computer and use it in GitHub Desktop.
Save fahimalizain/0e6aef6d7709a8e9f0ce3783fa9992fc to your computer and use it in GitHub Desktop.
Brute force excel file with file level encryption
import pandas as pd
import win32com.client
import string, sys
xlApp = win32com.client.Dispatch("Excel.Application")
print("Excel library version:", xlApp.Version)
path = "Statement.xlsx"
tokens = [str(x) for x in list(range(0,4))]
# tokens.extend([x for x in string.ascii_lowercase])
# tokens.extend([x for x in string.ascii_uppercase])
print(tokens)
tt = [x + x.upper() for x in string.ascii_lowercase]
tt.extend([x.upper() + x for x in string.ascii_lowercase])
num = ["{0:03d}".format(x) for x in range(0, 1000)]
print(tt)
print(num)
def crack():
for a in tt:
for b in num:
pwd = a + b
print("Trying ", pwd)
try:
xlWb = xlApp.Workbooks.Open(path, False, True, None, pwd)
# make sure it was opened. This throws error if it wasnt
# Sheets -> 1-indexed
print(xlWb.Sheets(1).Name)
print("Password is", pwd)
return
except:
pass
crack()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment