Last active
July 8, 2020 22:09
-
-
Save 0xbadjuju/8c7ac8677b6989b313abb45edfd79d53 to your computer and use it in GitHub Desktop.
Parse_Passwords.ps1
This file contains hidden or 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
################################################################################ | |
# | |
################################################################################ | |
function Create-Table | |
{ | |
param ( | |
[string] $DB_Path | |
) | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$command.CommandText = "CREATE TABLE [CRACKED_PASSWORDS] ([Username]VARCHAR(254), [Domain]VARCHAR(254), [ID]int, [Password]VARCHAR(128), [LMHash]VARCHAR(33),[NTHash]VARCHAR(33));" | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$dataReader = $command.ExecuteReader() | |
$command.Dispose() | |
$connection.Dispose() | |
} | |
################################################################################ | |
# | |
################################################################################ | |
function Insert-CrackedHashesJohn | |
{ | |
param ( | |
[string] $DB_Path, | |
[string] $Cracked_Path | |
) | |
Begin | |
{ | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
} | |
Process | |
{ | |
$cracked = Get-Content $Cracked_Path | |
foreach ($line in $cracked) | |
{ | |
$match = [regex]::Match($line,'([^:]+):(.+):([0-9]+):([a-z0-9]{32}):([a-z0-9]{32}):::') | |
$username_domain = $match.captures.groups[1].Value | |
$split = $username_domain.split('\') | |
$username = [string]::Empty | |
$domain = [string]::Empty | |
if ($split.length > 1) | |
{ | |
$username_domain | |
$username = $username_domain.split('\')[1] | |
$domain = $username_domain.split('\')[0] | |
} | |
else | |
{ | |
$username = $username_domain.split('\')[0] | |
} | |
Write-Verbose "$($username)" | |
$password = $match.captures.groups[2].Value | |
$userrid = $match.captures.groups[3].Value | |
$lmhash = $match.captures.groups[4].Value | |
$nthash = $match.captures.groups[5].Value | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$query = "INSERT INTO [CRACKED_PASSWORDS] Values('$username', '$domain', '$userrid', @password, '$lmhash', '$nthash');" | |
$command.CommandText = $query | |
$command.Parameters.Add("@password", $password) | Out-Null | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$command.ExecuteReader() | |
$command.Dispose() | |
} | |
} | |
End | |
{ | |
$connection.Dispose() | |
} | |
} | |
################################################################################ | |
# | |
################################################################################ | |
function Get-PasswordLengthCount | |
{ | |
param ( | |
[string] $DB_Path | |
) | |
Begin | |
{ | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
} | |
Process | |
{ | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$command.CommandText = "SELECT LEN(Password) FROM [CRACKED_PASSWORDS] GROUP BY LEN(Password) ORDER BY LEN(Password) ASC" | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$dataReader = $command.ExecuteReader() | |
$CommonPasswords = @() | |
while ($dataReader.Read()) | |
{ | |
$command2 = New-Object System.Data.OleDb.OleDbCommand | |
$command2.CommandText = "SELECT COUNT(*) FROM [CRACKED_PASSWORDS] WHERE LEN(Password) = $($dataReader[0])" | |
$command2.CommandType = "Text" | |
$command2.Connection = $connection | |
$dataReader2 = $command2.ExecuteReader() | |
while ($dataReader2.Read()) | |
{ | |
$CommonPasswords += New-Object PSCustomObject -Property @{ | |
Length = $dataReader[0] | |
Count = $dataReader2[0] | |
} | |
} | |
$command2.Dispose() | |
} | |
} | |
End | |
{ | |
$command.Dispose() | |
$connection.Dispose() | |
return $CommonPasswords | |
} | |
} | |
################################################################################ | |
# | |
################################################################################ | |
function Get-CommonPasswords | |
{ | |
param ( | |
[string] $DB_Path, | |
[int] $Count | |
) | |
Begin | |
{ | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
} | |
Process | |
{ | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$command.CommandText = "SELECT TOP $Count [Password], COUNT(Password) FROM [CRACKED_PASSWORDS] GROUP BY [password] ORDER BY COUNT(Password) DESC" | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$dataReader = $command.ExecuteReader() | |
$CrackedPasswords = @() | |
while ($dataReader.Read()) | |
{ | |
$CrackedPasswords += New-Object PSCustomObject -Property @{ | |
Password = $dataReader[0] | |
Count = $dataReader[1] | |
} | |
} | |
} | |
End | |
{ | |
$command.Dispose() | |
$connection.Dispose() | |
return $CrackedPasswords | |
} | |
} | |
################################################################################ | |
# | |
################################################################################ | |
function Get-CommonPasswordUsers | |
{ | |
param ( | |
[string] $DB_Path, | |
[int] $Count, | |
[string] $DestinationFile | |
) | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$command.CommandText = "SELECT TOP $Count [Password], COUNT(Password) FROM [CRACKED_PASSWORDS] GROUP BY [password] ORDER BY COUNT(Password) DESC" | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$dataReader = $command.ExecuteReader() | |
while ($dataReader.Read()) | |
{ | |
Write-Host $dataReader[0] | |
Get-UsersForPassword -DB_Path $DB_Path -Password $dataReader[0] | Out-File -Append $DestinationFile | |
} | |
$command.Dispose() | |
$connection.Dispose() | |
} | |
################################################################################ | |
# | |
################################################################################ | |
function Get-UsersForPassword | |
{ | |
param ( | |
[string] $DB_Path, | |
[string] $Password | |
) | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$command.CommandText = "SELECT [Username] FROM [CRACKED_PASSWORDS] WHERE [Password] = '$($Password)' ORDER BY [Username] ASC" | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$dataReader = $command.ExecuteReader() | |
while ($dataReader.Read()) | |
{ | |
$dataReader[0] | |
} | |
$command.Dispose() | |
$connection.Dispose() | |
} | |
################################################################################ | |
# | |
################################################################################ | |
function Get-PasswordForUser | |
{ | |
param ( | |
[string] $DB_Path, | |
[string] $Username | |
) | |
$connection = New-Object System.Data.OleDb.OleDbConnection | |
$connectstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$DB_Path;Extended Properties='Excel 12.0 Xml;HDR=YES;'" | |
$connection.ConnectionString = $connectstring | |
$connection.open() | |
$command = New-Object System.Data.OleDb.OleDbCommand | |
$command.CommandText = "SELECT [Password] FROM [CRACKED_PASSWORDS] WHERE [Username] = '$($Username)' ORDER BY [Password] ASC" | |
$command.CommandType = "Text" | |
$command.Connection = $connection | |
$dataReader = $command.ExecuteReader() | |
while ($dataReader.Read()) | |
{ | |
$dataReader[0] | |
} | |
$command.Dispose() | |
$connection.Dispose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment