Skip to content

Instantly share code, notes, and snippets.

@msuiche
Created May 13, 2017 11:52
Show Gist options
  • Save msuiche/79c87f11d1d7a6f2883d4307fc92e9ba to your computer and use it in GitHub Desktop.
Save msuiche/79c87f11d1d7a6f2883d4307fc92e9ba to your computer and use it in GitHub Desktop.
/*
# 010 Template for t.wnry
typedef struct {
char Signature[8]; // WANACRY!
uint32 Part1Size; // Always 0x100
char DataPart1[Part1Size];
uint32 Part2Signature;
uint64 Part2Size;
char DataPart2[Part2Size];
} _WANNACRY_THEADER;
local char magic[8];
ReadBytes(magic, 0, 8);
if (Strncmp(magic, "WANACRY!", 8) == 0) {
FSeek(0);
_WANNACRY_THEADER Header;
}
*/
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <wincrypt.h>
#pragma comment(lib, "crypt32.lib")
// .data:0040EBF8 unk_40EBF8 db 7 ; DATA XREF: ImportKeyFromFileOrDefault+1Fo
// extracted from ed01ebfbc9eb5bbea545af4d01bf5f1071661840480439c6e5babe8e080e41aa
unsigned char defaultKey[1172] = {
0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x08, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x43, 0x2B, 0x4D, 0x2B, 0x04, 0x9C, 0x0A, 0xD9, 0x9F, 0x1E, 0xDA, 0x5F,
0xED, 0x32, 0xA9, 0xEF, 0xE1, 0xCE, 0x1A, 0x50, 0xF4, 0x15, 0xE7, 0x51, 0x7B, 0xEC, 0xB0, 0x27,
0x56, 0x05, 0x58, 0xB4, 0xF6, 0x83, 0xC9, 0xB6, 0x77, 0x5B, 0x80, 0x61, 0x18, 0x1C, 0xAB, 0x14,
0xD5, 0x6A, 0xFD, 0x3B, 0x70, 0x9D, 0x13, 0x3F, 0x2E, 0x21, 0x13, 0xF1, 0xE7, 0xAF, 0xE3, 0xFB,
0xAB, 0x6E, 0x43, 0x71, 0x25, 0x6D, 0x1D, 0x52, 0xD6,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, 0xB3, 0x8D, 0x49,
0x75, 0xEF, 0xB5, 0xD3, 0x0A, 0x6E, 0x45, 0x69, 0x37, 0x49, 0x93, 0x83, 0x9E, 0x80, 0x02, 0x38,
0xE9, 0x56, 0xBC, 0xF6, 0x3A, 0x46, 0xF3, 0xCB, 0x1F, 0xAC, 0x2D, 0x07, 0x91, 0xF2, 0xA1, 0x2C,
0xA4, 0xE0, 0x1D, 0xE7, 0xED, 0x90, 0x02, 0xD8, 0xAA, 0x87, 0x5C, 0x19, 0x97, 0xAD, 0xD1, 0xB2,
0x7D, 0xC9, 0x0C, 0x60, 0x31, 0x3F, 0xA7, 0x93, 0x6D, 0xF1, 0x15, 0x35, 0x67, 0xAE, 0x49, 0x27
};
int main() {
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
if (!CryptAcquireContext(
&hProv,
NULL,
MS_ENH_RSA_AES_PROV_W,
PROV_RSA_AES,
CRYPT_VERIFYCONTEXT)) {
printf("Error: CryptAcquireContext()\n");
return FALSE;
}
printf("0x494u == %x\n", sizeof(defaultKey));
if (!CryptImportKey(hProv, defaultKey, sizeof(defaultKey), 0, 0, &hKey)) {
printf("Error: CryptImportKey()\n");
return FALSE;
}
DWORD pdwDataLen = sizeof(inputDefaultData);
CryptDecrypt(hKey, NULL, TRUE, 0, inputDefaultData, &pdwDataLen);
// pdwDataLen == 0x10
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment