Created
July 29, 2013 03:05
-
-
Save 0xdevalias/6101928 to your computer and use it in GitHub Desktop.
A little PowerShell function and example to show how easy it is to reverse a 'SecureString' when you store the password and key in a script for automation purposes.
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
# Reverse-SecureString | |
# Version: 1.0 (20130729) | |
# Created By: Glenn 'devalias' Grant (http://devalias.net) | |
# License: The MIT License (MIT) - Copyright (c) 2013 Glenn 'devalias' Grant (see http://choosealicense.com/licenses/mit/ for full license text) | |
function Reverse-SecureString([string]$secureString,[string]$key) | |
{ | |
$objSecString=ConvertTo-SecureString -String $secureString -Key ([Byte[]]$key.Split(" ")) | |
$secString=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($objSecString) | |
$plaintext=[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($secString) | |
return $plaintext | |
} | |
# Example SecureString decryption | |
$password = "76492d1116743f0423413b16050a5345MgB8AFAAVwBiAGkAegBjAEcANQA5AEMAOABVAFoAUQBoADMAZAA1AEUAcgBGAHcAPQA9AHwAYgAxAGUAYwA0AGQA | |
YwBkADUANQAwAGUAYQBmADYAMwA5AGEANwAyADAAMwBmADAANwA3AGUANgA3ADYAYgA0AGIANgA4ADYAZAA3ADkAZgBkAGYAMgAzADcAMQA2ADkAYgA3AGMA | |
YwA0AGUAZQA1AGIANAA5ADEAZABjADQAZQA5ADgANQAxADUAYwBmADgAZQBjADMAMgBmADgANgBhADAANQBlADAANgBkAGIAZABlAGMAZAA2ADcAMwBmAGYA | |
YwA5ADMAZQAwADYAZAA5AGMAMwAyAGUANgAyAGUAMAA3ADcAYgBkADIAYQAzAGIAOAA3ADQAMwA2ADIAMAA2AA==" | |
$key = "114 138 230 113 215 43 58 173 155 129 196 29 105 162 10 25 187 79 18 221 142 29 155 43 28 20 19 40 103 83 110 240" | |
$passPlaintext = Reverse-SecureString "$password" "$key" | |
Write-Host $passPlaintext # This should output: TotallySecurePasswordLol! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment