Last active
February 26, 2018 05:51
-
-
Save Froosh/58450f3092f1b8bc4b0f00c486c931f8 to your computer and use it in GitHub Desktop.
I had a need to decrypt some Cisco VPN enc_GroupPwd entries, but didn't want put client info into random web forms, and didn't to install python to use the first result I found. So I converted the python to PowerShell, and here we are :)
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
# Converted from https://github.com/axcheron/cisco_pwdecrypt/ | |
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', 'CiscoPassword')] | |
[CmdletBinding(PositionalBinding = $false)] | |
[OutputType([String])] | |
Param ( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$CiscoPassword | |
) | |
Begin { | |
$3DES = New-Object -TypeName Security.Cryptography.TripleDESCng | |
$SHA1 = New-Object -TypeName Security.Cryptography.SHA1Managed | |
} | |
Process { | |
$HexStrings = $CiscoPassword -split "(?<=\G\w{2})(?=\w{2})" | |
$ByteArray = $HexStrings | ForEach-Object -Process {[Convert]::ToByte($PSItem, 16)} | |
$ht = $ByteArray[0..19] | |
$enc = $ByteArray[40..($ByteArray.Count-1)] | |
$iv = $ByteArray | |
$ht[19] += 1 | |
$h2 = $SHA1.ComputeHash($ht) | |
$ht[19] += 2 | |
$h3 = $SHA1.ComputeHash($ht) | |
$key = $h2 + $h3[0..3] | |
$h3des = $3DES.CreateDecryptor($key, $iv[0..7]) | |
$cleartext = [Text.Encoding]::UTF8.GetString($h3des.TransformFinalBlock($enc, 0, $enc.Count)) | |
return $cleartext | |
} | |
End { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your mileage may vary. This worked for me, but I haven't tried to make it robust or work for all types of enc_GroupPwd, etc.