Reverse Engineeringexebatchpowershellconversionwindowspayload

exe2hexbat

A Python script to convert a Windows PE executable file to a batch file and vice versa. It supports output methods like DEBUG.exe for x86 and PowerShell for x86/x64.

Description

exe2hexbat is designed to transform Windows PE executable files into batch files or PowerShell scripts, facilitating the obfuscation and deployment of executables in Windows environments. This tool is particularly useful for penetration testers and red teamers who need to deliver payloads without triggering antivirus detection through direct EXE execution.

The primary use case involves converting an EXE into a self-contained batch or PowerShell script that can reconstruct and run the original binary. It supports reading from files or STDIN, with options for URL encoding and custom prefixes/suffixes to integrate into larger scripts or bypass basic filters.

Installed via Kali's package manager, it depends on Python 3 and provides exe2hex as the main binary. While the page shows core options, additional flags are available in the man page.

How It Works

The tool reads a Windows PE EXE file (or from STDIN), converts its binary content into a hexadecimal representation, and embeds it into a batch file using the DEBUG.exe method (x86) or a PowerShell script (x86/x64). The output script includes commands to decode the hex data and execute it in memory, avoiding disk writes. Options like URL encoding modify the hex output for web transport, while prefix/suffix flags allow line-by-line customization for evasion.

Installation

bash
sudo apt install exe2hexbat

Flags

-h, --helpshow this help message and exit
-x EXEThe EXE binary file to convert
-sRead from STDIN
-b BATBAT output file (DEBUG.exe method - x86)
-p POSHPoSh output file (PowerShell method - x86/x64)
-eURL encode the output
-r TEXTpRefix - text to add before the command on each line
-f TEXTsuFfix - text to add after the command on each line

Examples

Show the help message and usage information for the tool
exe2hex -h
Convert the specified EXE binary file to default output format
exe2hex -x payload.exe
Read EXE data from STDIN and convert it
exe2hex -s
Convert EXE to a batch file using DEBUG.exe method (x86)
exe2hex -x payload.exe -b output.bat
Convert EXE to a PowerShell output file (x86/x64)
exe2hex -x payload.exe -p output.ps1
Convert EXE to batch file with URL-encoded output
exe2hex -x payload.exe -e -b encoded.bat
Convert EXE to batch with custom prefix and suffix on each line
exe2hex -x payload.exe -r "echo." -f "&rem" -b custom.bat
Updated 2026-04-16kali.org ↗