A trial-and-error method used to crack passwords, login credentials, or encryption keys by systematically trying every possible combination of characters.
Password policies often dictate specific requirements for password strength, such as minimum length, inclusion of certain character types, or exclusion of common patterns. grep combined with regular expressions can be a powerful tool for filtering wordlists to identify passwords that adhere to a given policy. Below is a table summarizing common password policy requirements and the corresponding grep regex patterns to apply:
Policy Requirement
Grep Regex Pattern
Explanation
Minimum Length (e.g., 8 characters)
grep -E '^.{8,}$' wordlist.txt
^ matches the start of the line, . matches any character, {8,} matches 8 or more occurrences, $ matches the end of the line.
[!@#$%^&*()_+-=[]{};':"\,.<>/?] matches any special character (symbol).
No Consecutive Repeated Characters
grep -E '(.)\1' wordlist.txt
(.) captures any character, \1 matches the previously captured character. This pattern will match any line with consecutive repeated characters. Use grep -v to invert the match.
Exclude Common Patterns (e.g., "password")
grep -v -i 'password' wordlist.txt
-v inverts the match, -i makes the search case-insensitive. This pattern will exclude any line containing "password" (or "Password", "PASSWORD", etc.).
Exclude Dictionary Words
grep -v -f dictionary.txt wordlist.txt
-f reads patterns from a file. dictionary.txt should contain a list of common dictionary words, one per line.
Combination of Requirements
grep -E '^.{8,}$' wordlist.txt \| grep -E '[A-Z]'
This command filters a wordlist to meet multiple password policy requirements. It first ensures that each word has a minimum length of 8 characters (grep -E '^.{8,}$'), and then it pipes the result into a second grep command to match only words that contain at least one uppercase letter (grep -E '[A-Z]'). This approach ensures the filtered passwords meet both the length and uppercase letter criteria.