Skip to content

Instantly share code, notes, and snippets.

@FrankSpierings
Last active April 29, 2024 14:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save FrankSpierings/99e216011ba9dff6b6c6 to your computer and use it in GitHub Desktop.
Save FrankSpierings/99e216011ba9dff6b6c6 to your computer and use it in GitHub Desktop.
Powershell - Brute force procedure
$charset = @()
$charset += ([char]'0'..[char]'9') |% {[char]$_}
$charset += ([char]'a'..[char]'z') |% {[char]$_}
$charset += ([char]'A'..[char]'Z') |% {[char]$_}
$charset = $charset | Select-Object -uniq
function Get-NextPassword() {
param(
$Password
)
if (($Password -eq $null) -or ($Password -eq '')) {
#Started with nothing, return the first item of the character set.
return [string]$charset[0]
}
else {
for ($pass_pos = ($Password.Length - 1); $pass_pos -ge 0; $pass_pos--) {
$charset_pos = [array]::indexOf($charset, [char]$Password[$pass_pos])
if ($charset_pos -eq $charset.Length - 1) {
#Overflow of the current password position.
$tempArray = $Password[0..$Password.Length]
$tempArray[$pass_pos] = $charset[0]
$Password = $tempArray -join ""
#Add character. Extend by 1 position.
if ($pass_pos -eq 0) {
$Password = $charset[0] + $Password
}
}
else {
#No overflow, update the current position +1 of the current character.
$tempArray = $Password[0..$Password.Length]
$tempArray[$pass_pos] = $charset[$charset_pos+1]
$Password = $tempArray -join ""
break #No overflow, therefore break the loop.
}
}
return $Password
}
}
$Password = $null
While ($true) {
$Password = Get-NextPassword $Password
$Password
}
@brotheralameen1
Copy link

Nice. This will really help in penetration testing.

@lixwayd
Copy link

lixwayd commented Dec 5, 2023

very nice code bru

@FBDev64
Copy link

FBDev64 commented Mar 11, 2024

bru nice code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment