Cracking PDFs using hashcat and pdfcrack-ng
INFO
For educational purpose only!
I've recently explored the world of Capture The Flag competitions, where cracking PDF passwords is a common challenge. This blog shares my journey, strategies, and tools used to conquer encrypted PDFs. Join me to master the art of PDF cracking, whether you're a CTF veteran or a curious newcomer.
Strategies
Researching is better than brute forcing : Brute force can take significant amount of time and is highly inefficient, so it's important to do some maths and reasoning before brute forcing.
Word-lists like rockyou.txt etc, can be also a great option.
Try to constraint your output range for password. eg, Password will only contain uppercase letters or numbers etc
If nothing works out, brute force is the key.
Tools
(Requires GPU)hashcat : Super high speed hash cracking tool, if you got an GPU.
john : Versatile tool-set, but we will use this for generating hashes from PDFs.
pdfcrack-ng : pdfcrack but a lot better, with baked in multi-threading support.
(Optional)hydra : Another password cracking tool.
crunch : Word-list generator based on given pattern
Getting Started
Download some common word-list
bashwget https://download.weakpass.com/wordlists/90/rockyou.txt.gz wget https://download.weakpass.com/wordlists/1851/hashesorg2019.gz #Optional, but more comprehensive gunzip rockyou.txt.gz # Decompresses files gunzip hashesorg2019.gz
Generating Password Hash using pdf2john
bashpdf2john filename.pdf > file.hash # Change filename.pdf with qualified name for your PDF
Copy the file hash
bashcut -d ':' -f2 file.hash
Copy the file hash.
Generating Wordlists using crunch
- bash
crunch <min-length> <max-length> -t <PATTERN> -o <OUTPUT-FILE> # Generate all combinations based on given Pattern crunch <min-length> <max-length> -p <string1> ..... <string n> -o <OUTPUT-FILE> # Outputs permutations of Strings crunch <min length> <max-length> -f /wordlist.txt-o out.txt # Filter wordlist, not all combinations # Example usage crunch 10 10 -t R,,,SH,VN, -o word.txt
Patterns cheat-sheet
, for all uppercase letters @ for all lowercase letters % for all numeric characters ^ for all special characters
Dictionary Attacks
Using pdfcrack-ng
bashpdfcrack-ng -w wordlist.txt -t 12 <filename>.pdf
Using hashcat
bashhashcat -w 3 -S -a <copied hash here> ./rockyou.txt # Or any other wordlist
Brute-forcing / Mask Attack
Using Hashcat
bashhashcat -w 3 -S -a 3 -m 10500 '<pdf-hash here>' '?u?u?u?u?u?u' --increment # Checking for 6 digit passwords containing upper case letters only! hashcat -w 3 -S -a 3 -m 10500 '<pdf-hash here>' 'ABC?u?u?u?u?u?u' # Start with ABC, without increment means fixed length password hashcat -w 3 -S -a 3 -m 10500 -O -1 'ABCDEF12345' '<pdf-hash here>' "?1?1?1?1?1?1?1?1?1?1?1?1?1" # Charset is ABCDEF12345 for 1 special symbol
?u : Uppercase letter ?l : Lowercase letter ?d : Digits ?s : Spaces
Using pdfcrack-ng
bashpdfcrack-ng -n 3 -m 10 -c "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" -t 12 <filename>.pdf
-n : Minimum Length -m : Maximum Length -c : charset -t : no of threads