John the Ripper and Hashcat: Hacking Heches into CTF

Depov

Moderator
Staff member
MODERATOR
ULTIMATE
SUPREME
PREMIUM
MEMBER
Joined
Feb 18, 2025
Messages
627
Reaction score
1,218
Deposit
0$
John the Ripper and Hashcat for Beginners – What’s the difference

Beginners often ask: why two tools, if the task is one - the selection of a password on the hash? Everyone closes their niche. John the Ripper (JtR) is able to automatically determine the hash format, contains a set of utilities *2john to extract hashes from files (ZIP, RAR, SSH keys, KeePass-base, PDF) and works perfectly on CPU. Hashcat is sharpened under GPU acceleration and in the presence of a video card moves passwords dozens of times faster, but requires a clear indication of the type of hash through the flag -m. Read more - in our detailed analysis of the creation of ctf tasks.

According to HashKitty (arxiv, 2025), Hashcat supports a broader set of algorithms on the GPU and automatically spreads tasks between multiple graphics cards, whereas JtR requires a manual configuration for multi-GPUs. But JtR can determine the type of hash itself – and Hashcat without the right -m It won't even start.

In real attacks, hacking hashes is a Credential Access technique according to the MITRE ATT&CK classification (Password Cracking, T1110.002). The attacker first extracts the hashes (dump /etc/shadow, SAM or network intercept), then pick up the offline passwords. In CTF, the chain is usually simplified to “got hash – broke – introduced a flag”, but understanding the full workflow helps both at competitions and on the pentest.

According to the IBM X-Force Threat Intelligence Index 2025, 32% of all detected malware for 2024 are infostealers that steal including hashed passwords. So the ability to work with both tools is quite an applied skill.
Criterion John the Ripper Hashcat
Autodetermination of the hash Yeah No, you need a flag -m
GPU acceleration Through OpenCL, limited Natively (CUDA and OpenCL)
Multi-GPU Manual setup Automatic separation
Extracting hashes from files Yes, family *2john No
Convenience for CTF Fast start, fewer parameters Faster on GPU, flexible masks
View results john --show hash.txt hashcat -m X hash.txt --show

My approach for CTFs is simple: if the hash is in the file (archive, document, SSH key) – start with John because *2john will extract the hash in the desired format for one team. If the hash is already known and you need maximum overkill, I switch to Hashcat with GPU.
How to determine the hash format before password selection

Before you run any tool to crack the hashes, you need to understand what algorithm was used. Error in the format - and the tool will be threshing, as in my example with picoCTF.

The first is visual. Many hashes have characteristic features. MD5 – 32 characters in hex (d577273ff885c3f84dadb8578bb41399). SHA-1 – 40 characters. SHA-256 – 64 characters. SHA-512 – 128 characters. NTLM is visually similar to MD5 (also 32 hex symbols), but without salt and is used in Windows. Hashes with prefixes $1$, $5$, $6$ crypt-formats Unix (MD5, SHA-256 and SHA-512 respectively). Prefix $2a$ or $2b$ – bcrypt.

The second way is utilities. In Kali pre-installed hash-identifier and hashid. Launching hashid -m <хеш>, and the utility will show the likely formats along with the Hashcat mode numbers. Flag -j add the formats of John. Saves minutes that otherwise go on the gugling of the conformity tables.

The third way is John himself. Write a hash to a file and run john hash.txt without parameters. JtR will try to automatically define the format. In the output there will be a string of the view Loaded 1 password hash (Raw-SHA256 [SHA256 128/128 AVX 4x]) – ready, the format is defined.
Table of formats for frequent hashes in CTF
Algorithm Example/sign --format (John) -m (Hashcat)
MD5 32 hex symbols Raw-MD5 0
SHA-1 40 hex symbols Raw-SHA1 100
SHA-256 64 hex symbols Raw-SHA256 1400
SHA-512 128 hex symbols Raw-SHA512 1700
NTLM 32 hex symbols (Windows) NT 1000
bcrypt Prefix $2a$ or $2b$ bcrypt 3200
MD5 Unix crypt $1$ prefix md5crypt 500
SHA-512 Unix crypt $6$ prefix Sha512crypt 1800

Confusion between Raw-SHA512 (-m 1700, regular SHA-512) and sha512crypt (-m 1800, Unix crypt with salt and iterations) I observe in beginners most often. The first is a fast hash, moving in seconds. The second is slow, specially designed to protect passwords. The difference in the speed of selection is in order.
Vocabulary attacks on passwords: practice with rockyou.txt

A dictionary attack is the first thing to try in the CTF. Most of the hacking hashes of passwords use passwords from real leaks, which means that they are highly likely to be in popular dictionaries.

The main dictionary is rockyou.txt. 14+ million passwords from the RockYou service leak in 2009, is included in the standard delivery of Kali on the way /usr/share/wordlists/rockyou.txt. Similar dictionaries are collected from LinkedIn leaks (164 million hashes of passwords, according to Have I Been Pwned) and other major incidents. According to my estimate, rockyou.txt covers 70-80% of Crypto category CTF-tasks with hashes.

# John the Ripper — словарная атака на SHA-256
john --wordlist=/usr/share/wordlists/rockyou.txt --format=Raw-SHA256 hash.txt

# Hashcat — словарная атака на SHA-256
hashcat -m 1400 -a 0 hash.txt /usr/share/wordlists/rockyou.txt

# Посмотреть найденный пароль
john --show hash.txt
hashcat -m 1400 hash.txt --show

According to benchmarks (dev.to, comparison on Intel Core i7-9700K), the vocabulary attack on the password from rockyou.txt ends in 0 seconds in both tools - this is actually a lookup, not a too much. Hashcat at the first start can spend 10-15 seconds on building a dictionary cache, but when repeated starts, the time drops to 2 seconds.

If there is no password in rockyou.txt, try other dictionaries. There is in Kali /usr/share/wordlists/dirbuster/ with different lists, and to generate a target dictionary for a specific CTF-task, CeWL will be useful - the utility collects words from the specified site. For example, cewl -d 2 -w custom_wordlist.txt https://target-site.com create a word from words on the target resource. For the Tasks, where the description has clues (the character's name, the name of the company), the custom dictionary is often decisive.
Mask attack and brute force: hashcat attack modes in practice

When the dictionary does not help, the next step is a mask attack. This is an optimized brute force: you specify a password template – which characters can stand at each position. Instead of overkilling all possible combinations, the tool checks only those that match the mask.

In Hashcat masks are set through placeholders: ?l – lowercase letter, ?u – capital, ?d – number, ?s – special symbol, ?a Any printed symbol. John uses a similar syntax through the flag --mask.

# Hashcat: маска для пароля вида "Pass1234" (заглавная + строчные + цифры)
hashcat -m 0 -a 3 hash.txt ?u?l?l?l?d?d?d?d

# John: аналогичная маска для MD5
john --mask=?u?l?l?l?d?d?d?d --format=Raw-MD5 hash.txt

# Hashcat: полный brute force 6 символов (любые печатные)
hashcat -m 0 -a 3 hash.txt ?a?a?a?a?a?a

The difference in speed between a mask attack and a complete brute force is colossal. According to the benchmark on SHA-256, the mask indicating that the first symbol is a capital letter, accelerated the hacking 3 times for John and 2.5 times for Hashcat compared to the full overtaking of the same 5-character passwords.

Full Brute Force (?a?a?a?a?a?a – all combinations of 6 characters) on the CPU takes about 10 minutes for MD5. For 7 characters - already hours, for 8 - days. On the GPU, Hashcat copes faster, but even with a powerful brute force video card, passwords longer than 8 characters are not appropriate. In CTF, brute force only makes sense when you know exactly the length of the password and at least part of its structure.

The attack mode in Hashcat is set through -a. -a 0 – vocabulary attack, -a 3 – brute force/mask, -a 1 – combinatorial (glue of two dictionaries), -a 6 and -a 7 – hybrid (dictionary + mask). In John, modes are switched through separate flags: --wordlist, --mask, --incremental.
Mutation rules: how to crack a hash of a complex password

Type passwords password123 or P@ssw0rd! mutations of basic words. People take a simple word and add numbers, change the register, substitute special characters instead of letters (leet-speak). The rules of mutation (rules) automate these patterns.

In Hashcat rules are connected through the flag -r. Standard set best64.rule contains 64 of the most effective rules of mutation - each modifys the words from the dictionary: adds numbers to the end, changes the first letter to the capital, turns the word. Team hashcat -m 0 -a 0 hash.txt rockyou.txt -r /usr/share/hashcat/rules/best64.rule will drive all rockyou.txt through 64 mutations – it’s 14 million × 64 = almost a billion candidates. For a more aggressive bulkhead there is d3ad0ne.rule (over 34 thousand rules) and dive.rule.

In John, the rules work similarly, but are connected through --rules. By default, John applies its own set in Wordlist mode. Launch john --wordlist=rockyou.txt --rules --format=Raw-MD5 hash.txt uses standard modification rules: capitalization, suffixes, leet-replacements.

Hybrid attack in Hashcat (-a 6 or -a 7) combines the dictionary with the mask. Example: hashcat -m 0 -a 6 hash.txt rockyou.txt ?d?d?d takes each word from the dictionary and finishes three digits with it. If a CTF password is a dictionary word with added digits (a typical scenario), a hybrid attack will find it in minutes.

Combinatorial attack (-a 1) glues the words from two dictionaries: hashcat -m 0 -a 1 hash.txt wordlist1.txt wordlist2.txt. Each word from the first file is connected to each of the second. Suitable for passwords-phrases like sunflowerhouse.
Hacking hashes into CTF: typical scripts from file to flag

On CTF hash is usually given in the file or in the task description - you need to restore the original password. On the pentest, the hash still needs to be learned - a separate story from the arsenal of Credential Access. But the toolbox is the same.
Hashes from /etc/shadow and NTLM

In Forensics category CTFs or in pentest labs (HackTheBox, TryHackMe), a script is often found: access to the file is obtained /etc/shadow (Linux) or to the SAM base (Windows). In terms of MITRE ATT&CK this OS Credential Dumping – extraction of hashes from /etc/passwd and /etc/shadow (T1003.008) or from Security Account Manager (T1003.002).

# Linux: объединить passwd и shadow для John
unshadow /etc/passwd /etc/shadow > unshadowed.txt
john --wordlist=/usr/share/wordlists/rockyou.txt unshadowed.txt

# Извлечь хеш из ZIP-архива
zip2john protected.zip > zip_hash.txt
john --wordlist=/usr/share/wordlists/rockyou.txt zip_hash.txt

# Аналогично для RAR, SSH-ключей, KeePass
rar2john archive.rar > rar_hash.txt
ssh2john id_rsa > ssh_hash.txt
keepass2john database.kdbx > keepass_hash.txt

The utility unshadow from the package John combines /etc/passwd (user names) and /etc/shadow (hashi) into a single file that John can parse. For Windows NTLM hash, the format is simpler - the usual 32-character hex lines, you submit directly: john --format=NT ntlm_hashes.txt or hashcat -m 1000 ntlm_hashes.txt rockyou.txt.
Reserved archives and documents via *2john

Family of utilities *2john One of the strongest sides of John the Ripper, which Hascat does not have. These scripts (mostly in Python) extract the password hash from the protected file to a format that is understandable to John. The full list of converters can be seen by the team ls /usr/share/john/*.py | grep 2john - there are usually 50+ utilities.

Typical CTF-workflow: get a file (archive, PDF, SSH key with passphrase, KeePass database) → run the corresponding *2john → get the hash → break John or Hashcat. For Hashcat, you need to manually define the mode -m by the type of hash – for example, zip2john issues a hash in the format that Hashcat accepts with -m 13600 (WinZip) or -m 17200-17230 (PKZIP).

In practice, I often use John to extract and initially take over the dictionary, and if it didn’t help – copy the hash and switch to Hashcat with a mock-attack on the GPU. The conveyor works quickly: zip2john works in milliseconds, vocabulary attack with rockyou.txt — in seconds.
Beginner mistakes when hacking password hashes

In a couple of years of CTF-task solutions with hashes I have collected a collection of typical rakes. Each cost 10 minutes to an hour.

The wrong hash format is the leader of the anti-rating. In John, you can rely on autodetermination, but if it is wrong (and with NTLM vs MD5 it happens - both 32 hex symbols), the result will be empty. In Hashcat the wrong -m – guarantee of lost time. Rule: Always check the format through hashid -m before launch.

Forgotten --show – John keeps the passwords found in the file ~/.john/john.pot. If you start hacking again, John will say “No password hashes left to crack” – he has already found the password, just does not show. Team john --show hash.txt outputs previously found results. Hashcat works similarly: file hashcat.potfile in the working directory, viewing through --show.

Brute force instead of the dictionary — beginners often run a full overkill to the 8-character password, although it is in rockyou.txt. A dictionary attack would take 0 seconds, brute force days. The order of attacks: first the dictionary (rockyou.txt), then the dictionary with the rules (best64.rule), then the mask (if you know the structure), and only in extreme cases - a complete overkill.

Dictionary encoding — rockyou.txt in Kali by default is packed in gz. Don’t forget to unpack: gunzip /usr/share/wordlists/rockyou.txt.gz. Another nuance: some dictionaries in UTF-8, and the hash was created from a password to Latin-1 – John and Hashcat may not find a match due to the difference in encoding. Flag --encoding= in John helps in such cases.

Too long passwords in brute force – each additional symbol increases the space of overkill exponentially. For charset ?a (95 printed characters) 6 characters = 735 billion combinations, 7 characters = 69 trillion. Even on the GPU, too much 8+ characters in charset ?a It'll take weeks.

Ignoring salt – hashes of the format $6$rounds=5000$saltsalt$hash... contain salt that makes rainbow tables useless. John and Hashcat process salt automatically, but if you manually extracted only part of the hash without salt, the tool will not be able to pick up the password. Always copy the whole hash, including the prefix and salt.

A separate story — OWASP A07:2021 (Identification and Authentication Failures) The standard describes weak passwords as one of the key authentication issues. The fact that CTF passwords easily break through rockyou.txt demonstrates exactly this problem: users put predictable passwords, and no hash algorithm will save if the password itself – password123.
 
Top Bottom