-
Notifications
You must be signed in to change notification settings - Fork 0
/
bruteForcePdf.py
44 lines (32 loc) · 985 Bytes
/
bruteForcePdf.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
#! python3
# bruteForcePdf.py - Brute force guesses
# password to specified PDF in argument.
import sys, PyPDF2
# Cycle through dictionary until successful decryption.
def search_dictionary(filename):
pdfFile = open(filename, 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFile)
dictionaryFile = open('dictionary.txt')
dictionary = dictionaryFile.readlines()
for entry in dictionary:
# Clean the entry.
entry = entry.replace('\n','')
# Create switch for breaking out of search.
isFound = False
# Note that entry comes in uppercase as default.
if (pdfReader.decrypt(entry)):
isFound = True
# Also try entry as lowercase.
elif (pdfReader.decrypt(entry.lower())):
entry = entry.lower()
isFound = True
# Present password and break search once found.
if isFound:
print('Password is: %s' % entry)
dictionaryFile.close()
pdfFile.close()
return
try:
search_dictionary(sys.argv[1])
except:
print('Please give a valid .pdf in argument.')