#include #include #include #pragma comment (lib, "crypt32.lib") #pragma comment (lib, "advapi32") int AESDecrypt(char * payload, unsigned int payload_len, char * key, size_t keylen) { HCRYPTPROV hProv; HCRYPTHASH hHash; HCRYPTKEY hKey; if (!CryptAcquireContextW(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)){ return -1; } if (!CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash)){ return -1; } if (!CryptHashData(hHash, (BYTE*)key, (DWORD)keylen, 0)){ return -1; } if (!CryptDeriveKey(hProv, CALG_AES_256, hHash, 0,&hKey)){ return -1; } if (!CryptDecrypt(hKey, (HCRYPTHASH) NULL, 0, 0, payload, &payload_len)){ return -1; } CryptReleaseContext(hProv, 0); CryptDestroyHash(hHash); CryptDestroyKey(hKey); return 0; } int main(void) { char AESkey[] = { 0x91, 0x55, 0xee, 0x3f, 0x32, 0x29, 0xae, 0x62, 0x8e, 0x83, 0x10, 0xe1, 0x7c, 0x37, 0x83, 0xd5 }; char shellcode[] = { 0x1c, 0xf7, 0x86, 0xa5, 0x78, 0x50, 0xce, 0x38, 0x95, 0x21, 0xeb, 0x7c, 0x49, 0xe3, 0x8d, 0xcd, 0x92, 0x70, 0x4c, 0x8a, 0xb1, 0xf5, 0xfc, 0xb8, 0xf8, 0x86, 0xfd, 0xf4, 0x67, 0x10, 0xc, 0xd4, 0xa2, 0x2f, 0x2d, 0x78, 0x2d, 0xcf, 0x21, 0x8d, 0x60, 0xb4, 0x9, 0x15, 0x4, 0x16, 0x98, 0xaf }; AESDecrypt((char *) shellcode, sizeof(shellcode), AESkey, sizeof(AESkey)); int idx = 0; while ( idx < sizeof(shellcode)) { if (idx == (sizeof(shellcode) - 1) ) { printf("0x%02x ", (unsigned char)shellcode[idx]); } else { printf("0x%02x, ", (unsigned char)shellcode[idx]); } idx++; } return 0; }