-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhc_rule_gen.ps1
178 lines (143 loc) · 5.41 KB
/
hc_rule_gen.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<#
.SYNOPSIS
Genereate Hashcat rules file based on permutation of input files
.DESCRIPTION
Does not take parameters everything is hardcoded.
The main idea is that each rule can contain:
%Word Case Operator% : Example "l" which uses the word from the wordlist in lowercase
%Number or common chars% : Numbers like "123", "007", or common patterns like "aaa", "abc"
%Specialchar% : The common ".","!", or "?" which people use in their password
%Character replacement%: Replace "a" with an "@" or "s" with a "$"
Position matters: Example the "!" could be at the end (Summer2023!), in the middle (Summer!2023) or even at the start (!Summer2023).
But it could be 2023Summer!, 2023!Summer, !2023Summer, Summer2023, 2023Summer, Summer!, !Summer, Summer as well...
To cover all those cases the script will generate the rules for it.
Use input files with the correct Hashcat rule syntax.
Example content:
- prefix.txt: c
- numbers_append.txt: $1
- numbers_prepend.txt: ^1
- special_append.txt: $!
- special_prepend.txt: ^!
- charrep.txt: sa@
This will generate the rule file:
c
c $1
c $1 $!
c $! $1
c $1 $! sa@
c $! $1 sa@
c $1 ^!
c $1 ^! sa@
c ^1
c $! ^1
c ^1 $! sa@
c ^!
c ^! sa@
c $!
c $! sa@
.EXAMPLE
.\hc_rule_gen
.LINK
https://github.com/zh54321/hashcat_rule_gen
#>
# Output file
$File = 'big.rule'
#Input files
$prefix_file = "prefix.txt"
$numbers_append = "numbers_append.txt"
$numbers_prepend = "numbers_prepend.txt"
$specialchar_append = "special_append.txt"
$specialchar_prepend = "special_prepend.txt"
$char_replacement = "charrep.txt"
class cls {
[string] $txt
cls(
[string] $t
) {
$this.txt = $t
}
}
#Read files and store in lists
$list_prefix = new-object System.Collections.Generic.List[cls]
$prefix_read = Get-Content -Path $prefix_file
ForEach ($Line in $prefix_read ) {
$obj = [cls]::new($Line)
$list_prefix.add($obj)
}
$list_numbers_app = new-object System.Collections.Generic.List[cls]
$numbers_app_read = Get-Content -Path $numbers_append
ForEach ($Line in $numbers_app_read ) {
$obj = [cls]::new($Line)
$list_numbers_app.add($obj)
}
$list_numbers_prep = new-object System.Collections.Generic.List[cls]
$numbers_prep_read = Get-Content -Path $numbers_prepend
ForEach ($Line in $numbers_prep_read ) {
$obj = [cls]::new($Line)
$list_numbers_prep.add($obj)
}
$list_special_app = new-object System.Collections.Generic.List[cls]
$special_app_read = Get-Content -Path $specialchar_append
ForEach ($Line in $special_app_read ) {
$obj = [cls]::new($Line)
$list_special_app.add($obj)
}
$list_special_prep = new-object System.Collections.Generic.List[cls]
$special_prep_read = Get-Content -Path $specialchar_prepend
ForEach ($Line in $special_prep_read ) {
$obj = [cls]::new($Line)
$list_special_prep.add($obj)
}
$list_charrep = new-object System.Collections.Generic.List[cls]
$charrep_read = Get-Content -Path $char_replacement
ForEach ($Line in $charrep_read ) {
$obj = [cls]::new($Line)
$list_charrep.add($obj)
}
$Stream = [System.IO.StreamWriter]::new($File)
# I will never be able to understand this anymore...
foreach ($prefix in $list_prefix) {
$Stream.WriteLine("$($prefix.txt)")
foreach ($number in $list_numbers_app) {
$Stream.WriteLine("$($prefix.txt) $($number.txt)")
foreach ($special in $list_special_app) {
$Stream.WriteLine("$($prefix.txt) $($number.txt) $($special.txt)")
$Stream.WriteLine("$($prefix.txt) $($special.txt) $($number.txt)")
foreach ($charrep in $list_charrep) {
$Stream.WriteLine("$($prefix.txt) $($number.txt) $($special.txt) $($charrep.txt)")
$Stream.WriteLine("$($prefix.txt) $($special.txt) $($number.txt) $($charrep.txt)")
}
}
foreach ($special in $list_special_prep) {
$Stream.WriteLine("$($prefix.txt) $($number.txt) $($special.txt)")
foreach ($charrep in $list_charrep) {
$Stream.WriteLine("$($prefix.txt) $($number.txt) $($special.txt) $($charrep.txt)")
}
}
}
foreach ($number in $list_numbers_prep) {
$Stream.WriteLine("$($prefix.txt) $($number.txt)")
foreach ($special in $list_special_app) {
$Stream.WriteLine("$($prefix.txt) $($special.txt) $($number.txt)")
foreach ($charrep in $list_charrep) {
$Stream.WriteLine("$($prefix.txt) $($number.txt) $($special.txt) $($charrep.txt)")
}
}
}
# Loop for special char (prepend) without the number part (c ^!, c ^! sa@)
foreach ($special in $list_special_prep) {
$Stream.WriteLine("$($prefix.txt) $($special.txt)")
foreach ($charrep in $list_charrep) {
$Stream.WriteLine("$($prefix.txt) $($special.txt) $($charrep.txt)")
}
}
#Loop for special char (append) without the number part (c $!, c $! sa@)
foreach ($special in $list_special_app) {
$Stream.WriteLine("$($prefix.txt) $($special.txt)")
foreach ($charrep in $list_charrep) {
$Stream.WriteLine("$($prefix.txt) $($special.txt) $($charrep.txt)")
}
}
}
# Close the stream
$Stream.Close()