Skip to content

Instantly share code, notes, and snippets.

@Froosh
Last active February 26, 2018 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Froosh/58450f3092f1b8bc4b0f00c486c931f8 to your computer and use it in GitHub Desktop.
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 :)
# 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 {
}
@Froosh
Copy link
Author

Froosh commented Feb 26, 2018

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.

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