~/cracking

Cracking

CPTS Notes4 min read

TL;DR

A hash is one-way, so you never reverse it. You guess a candidate, hash it, and compare. Cracking is that loop at scale with hashcat or john.

Two things set the run: the hash type, which fixes the tool’s mode and the speed, and the attack mode, which runs a dictionary, then rules or a mask, then brute force last. Which wordlist is its own call in Wordlists.

Identify the hash first

The hash type fixes the hashcat mode and how fast it cracks, so name it before anything:

hashid '<hash>' # candidate hash types
hashid -m '<hash>' # same, with the hashcat -m mode number
hashcat --identify hashes.txt # hashcat's own guess at the mode

A prefix often gives it away: $2b$ is bcrypt, $6$ is sha512crypt, $krb5tgs$ is a Kerberos ticket. Match it to the hashcat -m number before the run.

Common -m modes:

-m Hash Source
0 MD5 web apps, databases
100 SHA1 web apps
1400 SHA2-256 web apps
1000 NTLM Windows SAM, LSASS, and NTDS.dit
5600 NetNTLMv2 Responder and SMB capture
13100 Kerberos TGS-REP Kerberoasting
18200 Kerberos AS-REP AS-REP roasting
1800 sha512crypt $6$ Linux /etc/shadow
500 md5crypt $1$ old Linux, Cisco IOS
3200 bcrypt $2*$ modern apps, /etc/shadow
2100 DCC2 cached domain creds (mscash2)
13400 KeePass .kdbx database

Attack modes

hashcat is the GPU workhorse. The run is one line:

hashcat -a <mode> -m <type> <hashes> [wordlist | rule | mask] # -a attack mode, -m hash type

<hashes> is a hash string or a file of same-type hashes.

Dictionary (-a 0). Each wordlist entry, as is:

hashcat -a 0 -m 0 hashes.txt /usr/share/wordlists/rockyou.txt # -m 0 is MD5
hashcat -a 0 -m 0 hashes.txt /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/best64.rule # transform each word

Rules (-r) apply transformations (append digits, leet-swap), so one list becomes many candidates. best64.rule is the quick default, rockyou-30000.rule the wider one.

Mask (-a 3). A targeted brute force: you define the keyspace instead of trying everything. Each placeholder is a character set:

Mask Set
?l / ?u lowercase / uppercase letters
?d digits
?s symbols
?a all of the above
?h / ?H lowercase / uppercase hex
hashcat -a 3 -m 0 hash '?u?l?l?l?l?d?s' # upper, four lower, digit, symbol: a 7-character shape

Define your own set with -1 to -4, then reference it as ?1 to ?4. A mask only wins when you know the password shape, otherwise it is full brute force.

hashcat or john

Reach for hashcat by default: GPU speed on raw hashes (MD5, NTLM, /etc/shadow, Kerberos tickets). Reach for john (the jumbo build) for the two things hashcat lacks: the *2john extractors in Protected files, and single crack mode below. The extractors feed either cracker, so the split is about the tool, not the hash.

Single crack mode

john only. It builds candidates from the account’s own details (username, full name, and home directory from the GECOS fields), which catches the Bob Smith to Smith1 habit. Point it at a passwd or shadow file:

john --single passwd # candidates from the username and GECOS fields
john --show passwd # print what cracked

Let speed set the plan

Crack speed swings by orders of magnitude with the algorithm:

Hash Rough speed, typical hardware Plan
MD5, NTLM millions per second rockyou, then rules
bcrypt, sha512crypt, DCC2 thousands per second a short list first, a big one only if time allows

A fast hash takes rockyou and rules head-on. A slow hash makes a 14-million-line list a waste, so lead with a short one. That tradeoff is the Wordlists online-and-offline split.

Salt

A salt is random bytes added to a password before hashing, then stored alongside the hash. It is not secret, but it makes each hash crack on its own, so one precomputed table can never cover many hashes. That is why rainbow tables, the precomputed hash-to-password maps, barely matter against salted hashes.