Offline Attacks
Module 12, Section 3 — The art of breaking captured hashes without interacting with the target system.
Table of Contents
1. Hash Cracking Methodology
1.1 What Is an Offline Attack?
An offline attack works on captured hashes rather than against a live authentication service. The attacker has already obtained the hash (via database extraction, credential dumping, log capture, or configuration file access) and can now attempt to recover the original plaintext password without any interaction with the target system.
This is the fundamental distinction:
| Characteristic | Online Attack | Offline Attack |
|---|---|---|
| Target | Live authentication service | Captured hash file |
| Speed | Slow (network-limited, rate-limited) | Fast (GPU-limited, no throttling) |
| Detection risk | High (logs, alerts, lockouts) | Low (no network traffic) |
| Attempts per second | ~1-100 (depends on service) | ~100M-100B+ (GPU-accelerated) |
| Account lockout risk | Yes | No |
| Examples | Hydra, Medusa, Ncrack | Hashcat, John the Ripper |
Because offline attacks can test billions of candidates per second on modern GPUs, they are orders of magnitude more powerful than online attacks. This is why capturing hashes is such a critical objective during penetration tests.
1.2 Complete Attack Workflow
The offline cracking process follows a structured workflow. Each step feeds into the next, and the process is iterative — if one strategy fails, you cycle back with a different approach.
┌─────────────────────────────────────────────────────────────┐
│ OFFLINE CRACKING WORKFLOW │
└─────────────────────────────────────────────────────────────┘
┌──────────────┐
│ Obtain Hash │ ← Dump SAM, NTDS.dit, /etc/shadow, etc.
└──────┬───────┘
▼
┌──────────────┐
│ Identify Hash │ ← Hashcat --help, hashes.com, hash-identifier
│ Type │
└──────┬───────┘
▼
┌──────────────┐
│ Select Tool │ ← Hashcat (GPU) or John (CPU)
└──────┬───────┘
▼
┌──────────────┐
│ Choose Mode │ ← -a 0 (dict), -a 1 (combo), -a 3 (mask)
└──────┬───────┘
▼
┌──────────────────────────────────────────────┐
│ ATTACK STRATEGY │
│ ┌──────────┐ ┌──────────┐ ┌────────────┐ │
│ │ Rainbow │ │ Dictionary│ │ Dict + │ │
│ │ Table │ │ (plain) │ │ Rules │ │
│ └──────────┘ └──────────┘ └────────────┘ │
│ ┌──────────┐ ┌──────────┐ │
│ │ Mask │ │ Brute │ │
│ │ Attack │ │ Force │ │
│ └──────────┘ └──────────┘ │
└──────────────┬───────────────────────────────┘
▼
┌────────────┐
│ Cracked? │
│ ┌──┐ ┌──┐│
│ │Y │ │N ││
│ └┬─┘ └┬─┘│
└───┤ ┌┴──────────────┐
▼ ▼ ▼
┌────────────┐ ┌─────────────────────┐
│ Recover │ │ Try Next Strategy │
│ Plaintext │ │ (cycle back) │
└─────┬──────┘ └─────────────────────┘
▼
┌────────────┐
│ Validate │ ← Re-hash to confirm match
│ Result │
└────────────┘
1.3 Strategy Priority Matrix
Not all strategies are created equal. The key to efficient cracking is trying the fastest, highest-yield strategies first and escalating to more expensive approaches only when necessary.
| Priority | Strategy | Relative Speed | Success Rate | Best For | Resource Cost |
|---|---|---|---|---|---|
| 1 | Rainbow Table Lookup | ⚡⚡⚡ Instant | Low (unsalted only) | LM Hash, unsalted MD5/SHA1/NTLM | Disk storage |
| 2 | Plain Dictionary | ⚡⚡⚡ Fast | Medium-High (30-60%) | Common passwords, default creds | Minimal |
| 3 | Dictionary + Rules | ⚡⚡ Fast | High (60-85%) | Modified common passwords | Moderate (rules multiply candidates) |
| 4 | Mask Attack | ⚡ Medium | Medium (pattern-dependent) | Known password structure | GPU compute |
| 5 | Pure Brute Force | 🐌 Slow | 100% (eventually) | Short passwords, small charset | Very high GPU compute |
Why This Order?
- Rainbow tables cost nothing at attack time (pre-computed). If the hash type is covered, you get instant results. But they only work for unsalted hashes.
- Plain dictionary is the cheapest compute operation — just hash each word and compare. Catches ~30-60% of real-world passwords.
- Dictionary + rules extends the dictionary with intelligent mutations. A 14M-word list with 64 rules generates 896M candidates — still fast on GPU.
- Mask attacks target known patterns (e.g., “first letter uppercase + 7 lowercase + 2 digits”). Efficient when you have intelligence.
- Brute force is the nuclear option — guaranteed to work eventually, but computationally prohibitive for anything beyond short passwords.
1.4 Decision Tree: Choosing Your Strategy
Use this decision framework to select the optimal cracking strategy:
┌──────────────────────┐
│ What hash type? │
└──────┬───────────────┘
▼
┌────────────────────────┐
│ Is it SALTED? │
│ (bcrypt, $6$, etc.) │
└──────┬───────────┬─────┘
YES │ │ NO
▼ ▼
┌─────────────────┐ ┌────────────────────────┐
│ Skip rainbow │ │ Rainbow tables? │
│ tables entirely │ │ ┌──────┬──────┐ │
└────────┬────────┘ │ │ YES │ NO │ │
▼ │ └──┬───┴──┬───┘ │
┌─────────────────┐ │ ▼ ▼ │
│ Dict → Dict+ │ │ RT Dict → Dict+ │
│ Rules → Mask │ │ Look Rules → Mask │
│ → Brute Force │ │ up → Brute Force │
└─────────────────┘ └────────────────────────┘
┌──────────────────────────────────────┐
│ Additional Intelligence Available? │
│ ┌──────────┬──────────┬───────────┐ │
│ │ Username │ Company │ Password │ │
│ │ hints │ name │ policy │ │
│ └────┬─────┴────┬─────┴─────┬─────┘ │
│ ▼ ▼ ▼ │
│ Custom wordlist Custom Mask │
│ with context rules attack │
└──────────────────────────────────────┘
Decision Factors Explained
Hash Type Determines Your Options:
| Hash Type | Salted? | Rainbow Tables? | GPU Speed | Recommended First Strategy |
|---|---|---|---|---|
| LM Hash | No | ✅ Excellent | ~5000+ MH/s | Rainbow table or instant dict |
| NTLM (NT) | No | ✅ Good | ~5000+ MH/s | Dict → Dict + Rules |
| MD5 | No | ✅ Good | ~30000+ MH/s | Dict → Dict + Rules |
| SHA-1 | No | ✅ Good | ~15000+ MH/s | Dict → Dict + Rules |
| SHA-256 | No | ⚠️ Limited | ~5000+ MH/s | Dict → Dict + Rules |
| Unix MD5 ($1$) | Yes | ❌ No | ~500+ MH/s | Dict → Dict + Rules |
| Unix SHA-512 ($6$) | Yes | ❌ No | ~50+ MH/s | Dict → Dict + Rules |
| bcrypt ($2b$) | Yes | ❌ No | ~500-2000 H/s | Dict → Dict + Rules |
| WPA2 | Yes | ❌ No | ~30-70k H/s | Dict → Dict + Rules |
| Kerberos AS-REP | Yes | ❌ No | ~500+ H/s | Dict → Dict + Rules |
Time Budget Determines Your Depth:
| Time Available | Strategy Depth |
|---|---|
| < 1 minute | Rainbow table lookup, plain dictionary |
| 1-10 minutes | Dictionary + small rule set (best64.rule) |
| 10-60 minutes | Dictionary + comprehensive rules (d3ad0ne.rule) |
| 1-4 hours | Dictionary + rules + targeted mask attacks |
| 4+ hours | Full rules + mask + incremental brute force |
> 💡 OSCP Exam Tip: On the OSCP exam, you typically have limited time per machine. Prioritize: (1) plain dictionary with rockyou.txt, (2) dictionary + best64.rule or one337.rule, (3) simple mask attacks based on any password hints. Don’t spend hours on brute force — move on and come back if needed.
1.5 Hash Identification — The Critical First Step
Before any cracking attempt, you must identify the hash type. Using the wrong mode in Hashcat wastes time and produces false results.
# Method 1: Hashcat built-in (check supported modes)
hashcat --help | grep -A 500 "Hash-modes"
# Method 2: Online identifier
# Visit https://hashes.com/en/tools/hash_identifier
# Method 3: Python hash-identifier
pip install hash-identifier
hash-identifier
# Paste the hash when prompted
# Method 4: Visual pattern matching
# $1$ → Unix MD5 Crypt
# $5$ → Unix SHA-256 Crypt
# $6$ → Unix SHA-512 Crypt
# $2a$/$2b$ → bcrypt
# $WPA$ → WPA2 handshake
# $krb5asrep$ → Kerberos AS-REP
# $krb5tgs$ → Kerberos TGS-REP
1.6 Validation — Confirm Your Crack
After a candidate password is found, always validate by re-hashing the plaintext and comparing:
# For NTLM, verify with hashcat
echo -n "found_password" | hashcat --stdout -m 1000 | md5sum
# Or use the --show flag to review results
hashcat -m 1000 --show hashes.txt
# For LM:NTLM format, check the pot file
cat ~/.hashcat/potfile
2. Rainbow Tables
2.1 The Time-Memory Tradeoff Concept
Rainbow tables solve a fundamental problem in hash cracking: the tension between computation time and storage space.
The Three Approaches
| Approach | Method | Time Cost | Storage Cost |
|---|---|---|---|
| Brute Force | Try every password | Very high | Minimal (just the algorithm) |
| Lookup Table | Pre-compute every hash→password pair | Minimal (instant lookup) | Extremely high (stores every hash) |
| Rainbow Table | Pre-compute chains, trade some time for storage | Low (chain replay) | Moderate (only chain endpoints) |
Rainbow tables, invented by Philippe Oechslin in 2003, find the optimal middle ground. Instead of storing every single hash-password pair (which would require exabytes of storage), they store only the start and end points of computed chains, achieving a dramatic reduction in storage while maintaining reasonable lookup speed.
2.2 Internal Mechanics — How Rainbow Tables Work
Step 1: The Building Blocks
A rainbow table relies on two functions:
-
Hash Function H(p) — Takes a plaintext password
pand produces a hash. This is the standard cryptographic hash (MD5, NTLM, etc.). -
Reduction Function R_i(h) — Takes a hash
hand produces a candidate password. The subscriptiindicates the position in the chain — different positions use different reduction functions (this is the key innovation of rainbow tables over simple distinguished-point tables).
Step 2: Chain Construction
A chain is built by alternating between hashing and reduction:
Chain: p₀ → h₁ → p₁ → h₂ → p₂ → h₃ → ... → pₙ → hₙ₊₁
Where:
h₁ = H(p₀) # Hash the starting password
p₁ = R₁(h₁) # Reduce hash to new password (position 1)
h₂ = H(p₁) # Hash the new password
p₂ = R₂(h₂) # Reduce hash to new password (position 2)
...
pₙ = Rₙ(hₙ) # Final reduction
hₙ₊₁ = H(pₙ) # Final hash (stored as endpoint)
Storage: Only (p₀, hₙ₊₁) pairs are stored — the start password and the final hash. A chain of length 10,000 requires storing just 2 values instead of 20,000.
Step 3: Why Different Reduction Functions?
In a naive chain (using the same reduction function everywhere), chain merging occurs: if two chains produce the same intermediate password, they merge into one, dramatically reducing coverage.
Rainbow tables solve this by using position-dependent reduction functions: R₁, R₂, R₃, …, Rₙ. Even if two chains converge at the same hash at position i, they will diverge again because Rᵢ₊₁ ≠ Rᵢ.
Without position-dependent reduction:
Chain A: ... → h₅ → R(h₅) = "password" → ...
Chain B: ... → h₃ → R(h₃) = "password" → ...
Both chains now merge and follow the same path ❌
With position-dependent reduction:
Chain A: ... → h₅ → R₅(h₅) = "password" → h₆ → R₆(h₆) = "xyz"
Chain B: ... → h₃ → R₃(h₃) = "password" → h₄ → R₄(h₄) = "abc"
Chains diverge because R₆ ≠ R₄ ✅
Step 4: Lookup Process
To crack a target hash h_target:
1. For each chain position i (from n down to 1):
a. Compute: p = Rᵢ(h_target)
b. Continue the chain: h = H(p), p' = Rᵢ₊₁(h), ..., until endpoint
c. Look up the endpoint in the table
d. If found, replay the full chain from the stored start point
e. During replay, check if any intermediate hash matches h_target
f. If match found, the preceding password is the answer
2. If no position yields a match, the password is not covered
2.3 Mathematical Analysis
Coverage Calculation
The probability that a rainbow table covers a given password depends on:
- C = number of chains
- L = chain length
- N = size of the password space
The theoretical coverage (ignoring collisions) is approximately:
Coverage ≈ (C × L) / N
But chain collisions reduce this. The actual coverage is approximately:
Coverage ≈ 1 - exp(-(C × L) / N)
For example, with a password space of 26⁸ ≈ 208 billion (8 lowercase letters):
| Chains (C) | Chain Length (L) | Theoretical Coverage | Actual Coverage |
|---|---|---|---|
| 10,000 | 10,000 | 0.48% | ~0.35% |
| 100,000 | 10,000 | 4.8% | ~3.8% |
| 1,000,000 | 10,000 | 48% | ~35% |
| 10,000,000 | 10,000 | 99.9% | ~95% |
Storage Requirements
Storage = C × (size_of_password + size_of_hash)
For NTLM (16-byte hash):
10 million chains × (8 bytes + 16 bytes) = 240 MB
For full 8-char alphanumeric NTLM tables:
~250 GB (commercial tables)
2.4 Why Rainbow Tables Fail Against Salted Hashes
A salt is random data prepended (or appended) to the password before hashing:
Unsalted: H("password") = 5f4dcc3b5aa765d61d8327deb882cf99
Salted: H("password" + "a3f8b2c1") = d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3
The salt problem:
| Aspect | Unsalted | Salted |
|---|---|---|
| Same password → same hash? | Yes | No (different salt = different hash) |
| One table covers all passwords? | Yes | No — need one table per salt value |
| Practical table size? | Feasible (GB-TB) | Impossible (each of billions of salts needs its own table) |
If a system uses 128-bit salts (like bcrypt), there are 2¹²⁸ ≈ 3.4 × 10³⁸ possible salt values. Creating a rainbow table for each salt is computationally and storage-wise impossible.
> 💡 OSCP Exam Tip: If you see a $6$ (SHA-512 crypt), $2b$ (bcrypt), or any hash with embedded salt, skip rainbow tables entirely. Go straight to dictionary + rules. Rainbow tables are only useful for LM Hash, unsalted MD5, and NTLM — and even for NTLM, dictionary + rules on a GPU is often faster than downloading and loading table files.
2.5 Rainbow Table Tools
RainbowCrack
The original implementation by the rainbow table research team.
# Generate a table (takes hours to days)
rtgen -c 10000000 -l 10000 -k 16 -w 8 -W 8 -o ntlm.tbl nt.txt
# Create index for fast lookup
rtindex ntlm.tbl
# Crack a hash
rtcalc ntlm.tbl 5f4dcc3b5aa765d61d8327deb882cf99
Parameters:
-c= number of chains-l= chain length-k= hash size in bytes-w= minimum password length-W= maximum password length
Ophcrack
Windows-focused rainbow table cracker, optimized for LM and NTLM hashes.
# Load table and crack
ophcrack -t ntlm_hashes.txt -l tables/ntlm_fast/
Pre-built table sets:
- Free tables: Cover ~80% of common passwords, ~5-10 GB
- Fast tables: Quick lookup, moderate coverage, ~10-20 GB
- Full tables: Maximum coverage, ~100+ GB
2.6 When Are Rainbow Tables Still Relevant?
| Scenario | Relevance |
|---|---|
| LM Hash cracking | ⭐⭐⭐ Still useful (trivial to crack anyway) |
| NTLM on old systems | ⭐⭐ Situational (GPU dict attack often faster) |
| CTF challenges with unsalted hashes | ⭐⭐ Quick wins |
| Modern salted hashes | ❌ Completely useless |
| Enterprise penetration testing | ⭐ Low (bring-your-own-GPU is more practical) |
> 💡 OSCP Exam Tip: Rainbow tables are rarely the primary cracking method on OSCP machines. The exam VMs typically have NTLM hashes that crack quickly with rockyou.txt + rules on Hashcat. Know the concept for the theory, but invest your study time in mastering dictionary + rule-based attacks instead.
3. Rule-Based Attacks
3.1 Why Rules Work — The Psychology of Passwords
Rule-based attacks exploit a fundamental truth: humans are predictable when creating passwords.
Users rarely use raw dictionary words. They modify them using a small set of common transformations:
| Transformation | Example | Frequency in Real Passwords |
|---|---|---|
| Capitalize first letter | password → Password |
~60-70% |
| Append numbers | password → password123 |
~40-50% |
| Leet speak substitution | password → p@ssw0rd |
~20-30% |
| Append special character | password → password! |
~15-25% |
| Capitalize all | password → PASSWORD |
~10-15% |
| Reverse | password → drowssap |
~2-5% |
| Duplicate | password → passwordpassword |
~1-3% |
| Year append | password → password2024 |
~10-20% |
The power of rules: A single rule file with 64 rules applied to a 14M-word dictionary generates 896 million candidates — covering a vast password space without storing 896M words on disk.
Dictionary size: 14,000,000 words
Rules applied: 64
Candidates: 14,000,000 × 64 = 896,000,000
Storage needed: ~80 MB (dictionary) + ~2 KB (rules)
vs. ~10 GB (if stored as explicit wordlist)
3.2 Complete Hashcat Rule Syntax Reference
Hashcat rules are processed sequentially — each rule is a program that transforms the input word. A rule file contains multiple rules, one per line. Each rule is applied independently to each dictionary word.
Character Case Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
l |
Lowercase first character | PASSWORD |
pASSWORD |
Only first char |
L |
Lowercase ALL characters | PASSWORD |
password |
Entire word |
u |
Uppercase first character | password |
Password |
Only first char |
U |
Uppercase ALL characters | password |
PASSWORD |
Entire word |
c |
Capitalize (toggle first char case) | password |
Password |
l if upper, u if lower |
C |
Toggle case of ALL characters | p@SSw0RD |
P@ssW0rd |
Each char flipped |
# Example: Capitalize first letter (most common transformation)
echo "password" | hashcat --stdout -r "<(echo c)"
# Output: Password
Position-Based Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
r |
Reverse the word | password |
drowssap |
Full reversal |
d |
Duplicate the word | password |
passwordpassword |
Concatenates with self |
p[NM] |
Permute chars at positions N and M | password |
apssword |
p alone = first two chars |
xN |
Swap first char with Nth char | password |
apssword |
x1 swaps pos 0 and 1 |
# Example: Reverse then capitalize
echo "password" | hashcat --stdout -r "<(printf 'r\nc')"
# r → drowssap
# c → Drowssap
Character Insertion Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
iN |
Increment char at position N | password |
qassword |
i = position 0, i1 = position 1 |
IN |
Decrement char at position N | qassword |
password |
I = position 0, I1 = position 1 |
oN |
Mirror: insert char at N, copy from N-1 | pass |
paass |
o = position 0 |
ON |
Mirror: insert char at N, copy from N+1 | pass |
ppass |
O = position 0 |
# Example: Increment first char (a→b, b→c, ... z→a)
echo "admin" | hashcat --stdout -r "<(echo i)"
# Output: bddin
Character Deletion Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
dN |
Delete character at position N | password |
assword |
d = position 0, d1 = position 1 |
DN |
Delete character at position N (from end) | password |
passwor |
D = last char, D1 = second-to-last |
# Example: Delete first character
echo "password" | hashcat --stdout -r "<(echo d)"
# Output: assword
Character Replacement Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
sXY |
Replace character X with Y | password |
p@ssword |
s a @ replaces all ‘a’ with ‘@’ |
tXY |
Replace char at position X with Y | password |
Password |
t0P sets position 0 to ‘P’ |
# Example: Common leet speak replacements
echo "password" | hashcat --stdout -r "<(printf 's a @\ns e 3\ns o 0\ns s \$')"
# Output: p@$$w0rd
Append / Prepend Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
+text |
Append text to end | password |
password123 |
+123 appends “123” |
^text |
Prepend text to beginning | password |
!password |
^! prepends “!” |
$text |
Insert text at current position | password |
pass123word |
Position tracked by previous ops |
# Example: Capitalize, append "123"
echo "password" | hashcat --stdout -r "<(printf 'c\n+123')"
# c → Password
# +123 → Password123
Advanced Operations
| Rule | Description | Input | Output | Notes |
|---|---|---|---|---|
q |
Quit (stop processing this rule) | — | — | Truncates rule execution |
Q |
Skip to next word | — | — | Skip this word entirely |
f |
Remove non-alphanumeric chars | p@ssw0rd! |
psswr |
Filters to letters only |
Fn |
Remove chars not in charset n | — | — | n = 0-9, custom charsets |
kN |
Keep only first N characters | password |
pass |
k4 keeps first 4 |
KN |
Keep only last N characters | password |
word |
K4 keeps last 4 |
jN |
Jump to position N | — | — | Moves internal position pointer |
vN |
Truncate at position N | password |
pass |
v4 truncates after 4th char |
V |
Truncate to current position | — | — | Uses internal position pointer |
h |
Remove duplicate chars | bookkeeper |
bokeper |
Consecutive duplicates only |
H |
Remove all duplicate chars | bookkeeper |
bokerp |
All duplicates removed |
gN |
Grab char at position N, append | password |
passwordp |
g0 grabs first char |
G |
Grab char at position N, prepend | password |
ppassword |
G0 prepends first char |
w |
Remove all non-word chars | p@ss!w0rd |
psswr |
Keeps [a-zA-Z0-9_] |
W |
Remove all word chars | p@ss!w0rd |
@!0 |
Keeps special chars only |
y |
Title case | hello world |
Hello World |
Capitalize first of each word |
Y |
Sentence case | HELLO WORLD |
Hello world |
First char upper, rest lower |
zn |
Remove chars at position n | — | — | Similar to d but different behavior |
Zn |
Remove chars from position n | — | — | Removes from n to end |
en |
Extract chars at position n | — | — | Keeps only char at position n |
En |
Extract chars from position n | — | — | Keeps from n to end |
rn |
Remove char n | — | — | Alias for d |
Rn |
Remove from char n | — | — | Alias for Z |
Rule Execution Order Matters
Rules are applied top to bottom within a single rule definition. The order of operations dramatically changes the output:
# Rule A: Append then capitalize
printf '+123\nc' > rule_a.rule
echo "password" | hashcat --stdout -r rule_a.rule
# +123 → password123
# c → Password123
# Rule B: Capitalize then append
printf 'c\n+123' > rule_b.rule
echo "password" | hashcat --stdout -r rule_b.rule
# c → Password
# +123 → Password123
# Same result in this case, but try:
# Rule C: Append then reverse
printf '+!\nr' > rule_c.rule
echo "admin" | hashcat --stdout -r rule_c.rule
# +! → admin!
# r → !nimda
# Rule D: Reverse then append
printf 'r\n+!' > rule_d.rule
echo "admin" | hashcat --stdout -r rule_d.rule
# r → nimda
# +! → nimda!
3.3 Built-in Hashcat Rule Files
Hashcat ships with several pre-built rule files in the rules/ directory:
| Rule File | Rules Count | Purpose | Best Use Case |
|---|---|---|---|
best64.rule |
64 | General-purpose starter | First rule-based attempt |
one337.rule |
~300 | Leet speak substitutions | When leet speak is suspected |
leet337.rule |
~600 | Extended leet speak | Comprehensive leet coverage |
d3ad0ne.rule |
~10,000 | Comprehensive ruleset | Thorough cracking attempt |
t00m53.rule |
~3,000 | Popular community ruleset | Balanced coverage/speed |
rule3zie-337.rule |
~3,000 | Aggressive leet + mutations | Heavy modification patterns |
piranha-30000.rule |
~30,000 | Very comprehensive | Maximum coverage (slow) |
incident-response-50M.rule |
~50M+ | Maximum coverage | Enterprise forensics |
Rule file sizes and performance impact:
| Rule File | Candidates from rockyou.txt | Time on RTX 3080 (NTLM) |
|---|---|---|
| Plain dict (no rules) | 14M | ~2 seconds |
| best64.rule | 896M | ~2 minutes |
| one337.rule | ~4.2B | ~8 minutes |
| d3ad0ne.rule | ~140B | ~4 hours |
| piranha-30000.rule | ~420B | ~12 hours |
3.4 Custom Rule Writing
Basic Rule File Format
# my_custom_rules.rule
# Each line is one rule
# Lines starting with # are comments
# Rule 1: Capitalize first letter
c
# Rule 2: Capitalize and append "123"
c
+123
# Rule 3: Leet speak (a→@, e→3, o→0)
s a @
s e 3
s o 0
# Rule 4: Reverse and capitalize
r
c
# Rule 5: Append current year
+2026
Advanced Custom Rule Patterns
# Company-specific rules (e.g., target company is "AcmeCorp")
# Capitalize + company name
c
+AcmeCorp
# Company name + year
c
+AcmeCorp2026
# Leet speak + numbers
s a @
s e 3
s o 0
+1
# Username-based rules (if username is "jsmith")
# Password might be username + numbers
+123
+2024
+!
# Common password policy compliance rules
# Many policies require: uppercase + lowercase + number + special
c
+1
+!
Rule Composition Strategies
Strategy 1: Layered Approach
# Pass 1: Plain dictionary
hashcat -m 1000 -a 0 hashes.txt rockyou.txt
# Pass 2: Dictionary + best64 rules
hashcat -m 1000 -a 0 hashes.txt rockyou.txt -r rules/best64.rule
# Pass 3: Dictionary + leet rules
hashcat -m 1000 -a 0 hashes.txt rockyou.txt -r rules/one337.rule
# Pass 4: Dictionary + comprehensive rules
hashcat -m 1000 -a 0 hashes.txt rockyou.txt -r rules/d3ad0ne.rule
Strategy 2: Rule Chaining (using –rules-file with multiple)
# Apply multiple rule files sequentially
hashcat -m 1000 -a 0 hashes.txt rockyou.txt \
-r rules/best64.rule \
-r rules/one337.rule
Strategy 3: Custom + Built-in Combination
# Apply custom company-specific rules + built-in leet
hashcat -m 1000 -a 0 hashes.txt rockyou.txt \
-r my_company_rules.rule \
-r rules/one337.rule
3.5 Performance Impact — The Multiplication Factor
Each rule effectively multiplies your dictionary size:
Total Candidates = Dictionary Size × Number of Rules
Example:
rockyou.txt = 14,344,392 words
best64.rule = 64 rules
Total candidates = 14,344,392 × 64 = 918,041,088
d3ad0ne.rule = ~10,000 rules
Total candidates = 14,344,392 × 10,000 = 143,443,920,000
GPU throughput considerations:
| GPU | NTLM Speed | Time for rockyou.txt + best64 | Time for rockyou.txt + d3ad0ne |
|---|---|---|---|
| RTX 3060 | ~25,000 MH/s | ~37 seconds | ~19 minutes |
| RTX 3080 | ~50,000 MH/s | ~18 seconds | ~9.5 minutes |
| RTX 4090 | ~100,000 MH/s | ~9 seconds | ~4.7 minutes |
| A100 | ~150,000 MH/s | ~6 seconds | ~3.1 minutes |
> 💡 OSCP Exam Tip: The attack VM typically has a decent GPU. Use hashcat -b to benchmark your GPU speed before starting. This helps you estimate how long a ruleset will take and decide whether to wait or move on.
3.6 Practical Rule-Based Attack Examples
Example 1: NTLM Hash with Common Password
# Step 1: Plain dictionary (catches ~30-50%)
hashcat -m 1000 -a 0 ntlm_hashes.txt /usr/share/wordlists/rockyou.txt -o cracked.txt
# Step 2: Dictionary + best64 rules (catches additional ~20-30%)
hashcat -m 1000 -a 0 ntlm_hashes.txt /usr/share/wordlists/rockyou.txt \
-r /usr/share/hashcat/rules/best64.rule -o cracked.txt --pot-file-update
# Step 3: Dictionary + leet rules (catches additional ~10-15%)
hashcat -m 1000 -a 0 ntlm_hashes.txt /usr/share/wordlists/rockyou.txt \
-r /usr/share/hashcat/rules/one337.rule -o cracked.txt --pot-file-update
Example 2: Targeted Attack with Intelligence
# If you know the password contains the company name "MegaCorp"
# Create a custom wordlist from recon
cat > megacorp_words.txt << 'EOF'
MegaCorp
megacorp
Mega
corp
MegaCorp2024
MegaCorp2025
MegaCorp2026
Welcome
Welcome1
Welcome123
EOF
# Attack with custom wordlist + rules
hashcat -m 1000 -a 0 ntlm_hashes.txt megacorp_words.txt \
-r /usr/share/hashcat/rules/best64.rule
Example 3: Mask Attack Based on Password Policy
# If password policy requires: 8+ chars, 1 uppercase, 1 lowercase, 1 digit
# Likely pattern: 1 uppercase + 6 lowercase + 1 digit
hashcat -m 1000 -a 3 ntlm_hashes.txt '?u?l?l?l?l?l?l?d'
# Or: dictionary word + 1 digit suffix
hashcat -m 1000 -a 6 ntlm_hashes.txt rockyou.txt '?d'
# Or: dictionary word + 2 digit suffix
hashcat -m 1000 -a 6 ntlm_hashes.txt rockyou.txt '?d?d'
3.7 Rule Debugging
Use Hashcat’s --stdout flag to see what candidates a rule generates:
# See what best64.rule does to "password"
echo "password" | hashcat --stdout -r /usr/share/hashcat/rules/best64.rule
# Expected output includes:
# Password
# PASSWORD
# password1
# password123
# p@ssword
# p@ssw0rd
# p@ssw0rd!
# ... and 57 more variations
# Count total candidates
echo "password" | hashcat --stdout -r /usr/share/hashcat/rules/best64.rule | wc -l
# Output: 64
3.8 Summary: Rule-Based Attack Best Practices
| Practice | Description |
|---|---|
| Start simple | Always try plain dictionary first before adding rules |
| Escalate gradually | best64 → one337 → d3ad0ne → custom |
| Use intelligence | Company name, username, password policy inform custom rules |
| Monitor progress | Use --status and --status-timer=60 to track |
| Save progress | Use --session name and --restore to resume |
| Validate results | Always verify cracked passwords by re-hashing |
| Know when to stop | If a ruleset takes too long, move on and return later |
> 💡 OSCP Exam Tip: The most common password patterns on OSCP machines are: (1) plain dictionary words from rockyou.txt, (2) dictionary words with capitalization (Password), (3) dictionary words with number suffixes (password123), and (4) simple leet speak (p@ssword). The best64.rule file covers most of these patterns and should be your go-to first ruleset. If that doesn’t work, try one337.rule for leet speak coverage.
Quick Reference Card
Hashcat Offline Attack Commands
# Identify hash type
hashcat --help | grep -A 500 "Hash-modes"
# Plain dictionary attack
hashcat -m <mode> -a 0 hashes.txt wordlist.txt
# Dictionary + rules
hashcat -m <mode> -a 0 hashes.txt wordlist.txt -r rules/best64.rule
# Mask attack
hashcat -m <mode> -a 3 hashes.txt ?u?l?l?l?l?d?d?d
# Hybrid: dict + mask suffix
hashcat -m <mode> -a 6 hashes.txt wordlist.txt ?d?d?d?d
# Show cracked passwords
hashcat -m <mode> --show hashes.txt
# Resume session
hashcat --restore
# Benchmark GPU
hashcat -m <mode> -b
# Debug rules
echo "testword" | hashcat --stdout -r rules/best64.rule
Common Hash Modes
| Mode | Hash Type |
|---|---|
0 |
MD5 |
10 |
MD5($salt.$pass) |
100 |
SHA1 |
1000 |
NTLM |
1400 |
SHA-256 |
1800 |
SHA-384 |
1700 |
SHA-512 |
3200 |
bcrypt |
900 |
Unix MD5 ($1$) |
1100 |
Unix SHA-256 ($5$) |
11100 |
Unix SHA-512 ($6$) |
5600 |
NTLMv2 |
13100 |
Kerberos 5 AS-REP |
18200 |
Kerberos 5 TGS-REP |
22000 |
WPA2 |