Hashcat Rule Extractor
-
Title:
Hashcat Rule Extractor
Author:
chatgpt & A1131
Description
: Easily extract Hashcat rulesDownload Hashcat Rule Extractor
Hashcat Rule Extractor - Summary
Purpose:
The script analyzes complex passwords against a list of base words to automatically detect the transformation rules that convert base words into complex passwords. It outputs these transformations as Hashcat-style rules.Key Features:
-
Rule Detection:
Detects a wide range of rules including: -
Case changes (l, u, c, C, t, Tn)
-
Reversals (r)
-
Duplications (d, pN, q)
-
Rotations ({, })
-
Insertions, deletions, overwrites (iNX, DN, oNX)
-
Character appends/prepends ($X, ^X)
-
Truncations, replacements, removals ('N, sXY, @X)
-
Swaps and character shifts (k, K, *NM, L, R)
-
Duplications of parts (zN, ZN, yN, YN)
-
And fallback if no rules apply (:)
Multiprocessing:
Splits the base words across CPU cores for parallel processing to speed up rule detection.Progress Tracking:
Uses tqdm progress bar for user-friendly progress visualization.Rule Sanitization:
Converts any non-ASCII characters in detected rules into escaped hex format to ensure compatibility.Output:
Saves all unique detected rules into a specified .rule file.Optional Cleanup:
If available, runs an external cleanup-rules.bin utility to refine the rule set further.Logging:
Optionally logs every match showing which base word transforms into which complex password and by which rule.How it Works:
User Inputs:
Paths to base words file, complex passwords file, output file, and logging preference.Load Data:
Reads base words and complex passwords into memory.Detect Rules:
For each complex password, checks every base word to find transformation rules that map base → complex.Collect & Store:
Accumulates unique rules across all pairs.Save Results:
Writes unique rules to output file, optionally cleans up the rules.Finish:
Reports the number of unique rules found and ends.Use Case:
Ideal for security researchers or penetration testers who want to generate or reverse-engineer Hashcat rules from known password pairs to improve cracking efficiency.
Example Run:
$ python3 rules_extractor.py Hashcat Rule Extractor Enter path to base words file: base.txt Enter path to complex passwords file: passwords.txt Enter output dirty.rule path: dirty.rule Show match logs? (y/N): y ... +] Match: bonkers1 -> bonkers | Rule: x07 [+] Match: boners -> bonkers | Rule: i3k [+] Match: yonkers -> bonkers | Rule: o0b [+] Match: yonkers -> bonkers | Rule: syb [+] Match: bonkers -> bonkers | Rule: : [+] Match: bonkers -> bonkers | Rule: l [+] Match: bonker -> bonkers | Rule: $s [+] Match: bonker -> bonkers | Rule: i6s Analyzing: 9%|████████▉ | 2567/30000 [08:50<1:46:34, 4.29it/s] [+] Match: 2128506 -> 2128506 | Rule: C [+] Match: 2128506 -> 2128506 | Rule: : ... Found 131 unique rules. Saving to: dirty.rule Running cleanup utility: ./cleanup-rules.bin ... Cleanup complete. Cleaned rules saved to clean.rule Done! Custom Hashcat rules extraction complete.
---------- source --> https://hashcat.net/wiki/doku.php?id=rule_based_attack ----------
Supported rules
Rule Description Example Input Example Output : Do nothing (passthrough) p@ssW0rd p@ssW0rd l Lowercase all letters p@ssW0rd p@ssw0rd u Uppercase all letters p@ssW0rd P@SSW0RD c Capitalize first character, lowercase rest p@ssW0rd P@ssw0rd C Invert capitalize (lowercase first, uppercase rest) p@ssW0rd p@SSW0RD t Toggle case of all characters p@ssW0rd P@SSw0RD Tn Toggle case at position n (0-based index) p@ssW0rd (T3) p@sSW0rd r Reverse entire word p@ssW0rd dr0Wss@p d Duplicate entire word p@ssW0rd p@ssW0rdp@ssW0rd pN Duplicate entire word N times p2, p@ssW0rd p@ssW0rdp@ssW0rdp@ssW0rd f Reflect (append reversed word) p@ssW0rd p@ssW0rddr0Wss@p { Rotate left by 1 p@ssW0rd @ssW0rdp } Rotate right by 1 p@ssW0rd dp@ssW0r $X Append character(s) X $1$2, p@ssW0rd p@ssW0rd12 ^X Prepend character(s) X ^2^1, p@ssW0rd 12p@ssW0rd [ Truncate left (delete first char) p@ssW0rd @ssW0rd ] Truncate right (delete last char) p@ssW0rd p@ssW0r Dn Delete character at position n D3, p@ssW0rd p@sW0rd xNM Extract M chars starting at N x04, p@ssW0rd p@ss ONM Omit M chars starting at N O12, p@ssW0rd psW0rd iNX Insert character X at position N i4!, p@ssW0rd p@ss!W0rd oNX Overwrite character at position N with X o3$, p@ssW0rd p@s$W0rd 'N Truncate word at position N '6, p@ssW0rd p@ssW0 sXY Replace all instances of X with Y ss$, p@ssW0rd p@$$W0rd @X Purge all instances of X @s, p@ssW0rd p@W0rd zN Duplicate first character N times z2, p@ssW0rd ppp@ssW0rd ZN Duplicate last character N times Z2, p@ssW0rd p@ssW0rddd q Duplicate every character p@ssW0rd pp@@ssssWW00rrdd k Swap first two characters p@ssW0rd @pssW0rd K Swap last two characters p@ssW0rd p@ssW0dr *NM Swap character at position N with M *34, p@ssW0rd p@sWs0rd LN Bitwise shift left character at position N L2, p@ssW0rd p@æsW0rd RN Bitwise shift right character at position N R2, p@ssW0rd p@9sW0rd yN Duplicate first N characters y2, p@ssW0rd p@p@ssW0rd YN Duplicate last N characters Y2, p@ssW0rd p@ssW0rdrd
-