Mask attack
Table of Contents
Mask Attack
Description
A mask attack is a strategy used in the post-exploitation phase to recover passwords from stolen password hashes. It operates under the principle that most human-created passwords follow predictable patterns. By targeting these common patterns, the attacker dramatically reduces the total keyspace (the number of guesses) compared to a full, traditional brute-force attack.
How It Works
The attacker first performs reconnaissance on a set of cracked passwords (or common password behavior) to identify a pattern, such as: "The password is 8 characters long, starts with an uppercase letter, ends with four digits, and has a special character somewhere in the middle."
- Mask Definition: The attacker creates a specific mask using a combination of static characters and placeholders representing character sets.
- Targeted Brute Force: Password cracking software (like Hashcat or John the Ripper) then iterates only through combinations that match the defined mask, skipping all impossible or improbable combinations.
- Efficiency: This targeted approach converts an exponentially increasing search space into a linear, manageable task, allowing strong GPUs to crack common password patterns in minutes or hours instead of years.
Mask Attack vs. Brute Force vs. ictionary
- Traditional Brute Force: Tries every single possible character combination (e.g.,
aaaa,aaab,aaac, etc.). Takes the longest time. - Dictionary Attack: Tries only words found in a dictionary or common wordlist (e.g.,
password,qwert,soccer). - Mask Attack: Tries combinations based on a pattern template (e.g.,
Word+Year->Summer1988). It's a subset of the brute force attack tailored for efficiency.
Examples
The powerful password cracking tool Hashcat uses a specific syntax for defining masks, where a question mark (?) followed by a character defines a character class for that position.
. Common Character Sets
| Character Set | Description | Example Characters |
|---|---|---|
?l |
Lowercase letters | a, b, c, … |
?u |
Uppercase letters | A, B, C, … |
?d |
Digits (Numbers 0-9) | 0, 1, 2, … |
?s |
Special characters | !, @, #, $, … |
?a |
All printable ASCII characters | ?l + ?u + ?d + ?s |
2. Mask Pattern Scenarios
| Password Pattern Description | Hashcat Mask | Keyspace Example |
|---|---|---|
| 8-character PIN code | ?d?d?d?d?d?d?d?d |
\(10^8\) possibilities |
| 6 lowercase letters, 2 digits | ?l?l?l?l?l?l?d?d |
\(26^6 \times 10^2\) possibilities |
| Starts with Uppercase letter, ends with 4 digits | ?u?l?l?l?d?d?d?d |
\(26^4 \times 10^4\) possibilities |
| Known part, unknown suffix | Qwerty?d?d! |
QWERT00!, QWERTY99! |
3. Hashcat Mask Attack Command
A simplified example of running a mask attack against a file of stolen SHA-256 hashes (hashes.txt) for an 8-character password that is known to start with one uppercase letter, followed by four lowercase letters, and ending with three digits:
```bash hashcat -a 3 -m 1400 hashes.txt ?u?l?l?l?l?d?d?d