-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDF_Decrypter.py
More file actions
35 lines (26 loc) · 1 KB
/
PDF_Decrypter.py
File metadata and controls
35 lines (26 loc) · 1 KB
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
import argparse
import subprocess
def process_arguments():
parser = argparse.ArgumentParser(description='Decrypts PDFs using qpdf')
parser.add_argument('pdf', help='Name of PDF to decrypt')
parser.add_argument('-o', '--output',
help='Name of output file of PDF without password, by default it is \'cracked.pdf\'')
try:
return parser.parse_args()
except IOError:
parser.error('Error')
arguments = process_arguments()
output_file = ''
if arguments.o is not None:
output_file = arguments.o
else:
output_file = 'cracked.pdf'
with open('1000MostCommonPasswords.txt', 'r') as handle:
for line in handle:
p = subprocess.Popen(['qpdf', '--password=' + line.strip(), '--decrypt', arguments.pdf, output_file],
stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
p.communicate()
if p.returncode == 0:
print('Password :', line)
subprocess.run(['rm', 'cracked.pdf'])
break