Skip to content

Instantly share code, notes, and snippets.

@ryancbutler
Last active March 2, 2018 21:13
Show Gist options
  • Save ryancbutler/3353ce1bc4807056b875fb3eba456f4a to your computer and use it in GitHub Desktop.
Save ryancbutler/3353ce1bc4807056b875fb3eba456f4a to your computer and use it in GitHub Desktop.
#RUN AS ADMIN. WILL ERROR OUT ON CONNECTION
CLS
#SET TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Function Get-StringHash([String] $String,$HashName = "MD5")
{
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
[Void]$StringBuilder.Append($_.ToString("x2"))
}
$StringBuilder.ToString()
}
#KEEPASS EXPORT CSV
$mycsvpath = "D:\temp\mykeepassexport.csv"
$passwordcsv = Import-Csv -Path $mycsvpath
$passwords = $passwordcsv|select password|sort password|get-unique -asstring
foreach ($password in $passwords)
{
$hash = Get-StringHash $password.password "SHA1"
$hash4 = $hash.Substring(0,5)
$hashsub = $hash.Substring(5)
$ami = Invoke-RestMethod "https://api.pwnedpasswords.com/range/$hash4" -UseBasicParsing -ContentType "application\json"
$amiarray = @()
$amiarray = ($ami -split '[\r\n]') |? {$_}
$found = $null
$found = $amiarray|?{$_ -like "$hashsub*"}
if ($found)
{
$temp = $found -split ":"
write-host "FOUND: $hash $($temp[1]) times for Password: $($password.password)" -ForegroundColor Red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment