Featured image of post 忘記 PDF 的開啟密碼時如何破解

忘記 PDF 的開啟密碼時如何破解

📌 Introduction

分享如何在不知到 PDF 檔案的開啟密碼時,使用工具暴力破解出檔案的密碼。

📝 Steps

1. 安裝 pdf2john

請參考 GitHub 上 pdf2jhon 專案裡面的安裝流程操作: https://github.com/benjamin-awd/pdf2john?tab=readme-ov-file#install

2. 取得 PDF 的密碼雜湊值

$ pdf2john <加密的 PDF 檔案>.pdf > hash.txt && sed 's/[^:]*:\(.*\)/\1/' hash.txt > temp.txt && mv temp.txt hash.txt

執行範例(檔名用 Demo.pdf 為例):

(pdf2john) user@MacBook-Air % pdf2john Demo.pdf > hash.txt && sed 's/[^:]*:\(.*\)/\1/' hash.txt > temp.txt && mv temp.txt hash.txt
(pdf2john) user@MacBook-Air % cat hash.txt 
$pdf$4*4*128*-12*1*16*ee46c4e1d180ee754a71f8852eb9b442*32*57205d4479bad7472e6299614657ec5b00000000000000000000000000000000*32*93225ff18f925b7e18438149fe6b4872ad5118b424646ed3df31e2cb9dc92d30

3. 暴力破解 PDF 的密碼

執行範例

$ hashcat -a 3 -m 10500 --increment --increment-min 10 --increment-max 10 hash.txt '?u?d?d?d?d?d?d?d?d?d'
$pdf$4*4*128*-12*1*16*ee46c4e1d180ee754a71f8852eb9b442*32*57205d4479bad7472e6299614657ec5b00000000000000000000000000000000*32*93225ff18f925b7e18438149fe6b4872ad5118b424646ed3df31e2cb9dc92d30:A123456789

輸出字串中冒號後面的就是該檔案的密碼(例如:A123456789)。

最後的 ?u?d?d?d?d?d?d?d?d?d 代表是第一位數是大寫的英文字母,後面接 9 位數字,也就是台灣的身分證字號格式。

參數 -m 是設定雜湊的模式,詳細列表如下(來源):

      # | Name                                                       | Category
  ======+============================================================+======================================
  10400 | PDF 1.1 - 1.3 (Acrobat 2 - 4)                              | Document
  10410 | PDF 1.1 - 1.3 (Acrobat 2 - 4), collider #1                 | Document
  10420 | PDF 1.1 - 1.3 (Acrobat 2 - 4), collider #2                 | Document
  10510 | PDF 1.3 - 1.6 (Acrobat 4 - 8) w/ RC4-40                    | Document
  10500 | PDF 1.4 - 1.6 (Acrobat 5 - 8)                              | Document
  25400 | PDF 1.4 - 1.6 (Acrobat 5 - 8) - user and owner pass        | Document
  10600 | PDF 1.7 Level 3 (Acrobat 9)                                | Document
  10700 | PDF 1.7 Level 8 (Acrobat 10 - 11)                          | Document

📖 Ref.