1

一个简单的初学者挑战;PDF 文档的密码破解器。

不知道为什么会这样。我会继续在网上自己寻找解决方案,但我相信这很可能是我可以花一天时间解决但仍然无法解决的问题。不过,我会将编码、unicode 等添加到我的列表中。

>>> 
 RESTART: C:\Users\Dave\Desktop\2016Coding\AutomateBoring\13-PDF\bruteforce.py 
2016-11-23 06:14:51,974 --  DEBUG -- variations: ['AARHUS', 'aarhus', 'Aarhus']
2016-11-23 06:14:52,010 --  DEBUG -- variation: AARHUS
Traceback (most recent call last):
  File "C:\Users\Dave\Desktop\2016Coding\AutomateBoring\13-PDF\bruteforce.py", line 64, in <module>
    main()
  File "C:\Users\Dave\Desktop\2016Coding\AutomateBoring\13-PDF\bruteforce.py", line 48, in main
    if pdf_reader.decrypt(variation) == 0:
  File "C:\Users\Dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyPDF2\pdf.py", line 1987, in decrypt
    return self._decrypt(password)
  File "C:\Users\Dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyPDF2\pdf.py", line 2017, in _decrypt
    val = utils.RC4_encrypt(new_key, val)
  File "C:\Users\Dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyPDF2\utils.py", line 181, in RC4_encrypt
    retval += b_(chr(ord_(plaintext[x]) ^ t))
  File "C:\Users\Dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\PyPDF2\utils.py", line 238, in b_
    r = s.encode('latin-1')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0195' in position 0: ordinal not in range(256)
>>> 

脚本:

#! python3

# Brute force password breaker

# 10th word = ABANDONS

import docx
import logging
import PyPDF2

logging.basicConfig(level=logging.DEBUG, format="%(asctime)s --  " +\
                    "%(levelname)s -- %(message)s")


def main():
    """Attempts to password break a pdf file using three variations of each
    word in a .txt file containing 44,000 total words"""


    with open("dictionary.txt", "r") as f:
        words = f.read().splitlines()

    with open("bruteforce2.pdf", "rb") as f:
        pdf_reader = PyPDF2.PdfFileReader(f)
        for word in words:
            variations = [word.upper(), word.lower(), word.title()]
            for variation in variations:
                logging.debug("variations: {}".format(variations))
                logging.debug("variation: {}".format(variation))
                if pdf_reader.decrypt(variation) == 0:
                    pass
                else:
                    print("\n*****The password is: {!r}  *****\n".format(word))
                    break



if __name__ == "__main__":
    main()
4

0 回答 0