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 100 101
| #include<windows.h> #include<stdio.h>
#pragma code_seg("shell")
#pragma comment(linker,"/entry:bt") void bt() { DWORD dwkernel32 = 0; _TEB* pTeb = NtCurrentTeb(); PDWORD pPeb = (PDWORD) * (PDWORD)((DWORD)pTeb + 0x30); PDWORD pLdr = (PDWORD) * (PDWORD)((DWORD)pPeb + 0xC); PDWORD InLoadOrderModuleList = (PDWORD)((DWORD)pLdr + 0xC); PDWORD pModuleExe = (PDWORD)*InLoadOrderModuleList; PDWORD pModuleNtdll = (PDWORD)*pModuleExe; PDWORD pModulekernel32 = (PDWORD)*pModuleNtdll; dwkernel32 = pModulekernel32[6]; DWORD dwBase = (DWORD)dwkernel32; PIMAGE_DOS_HEADER pDos = (PIMAGE_DOS_HEADER)dwBase; PIMAGE_NT_HEADERS pNt = (PIMAGE_NT_HEADERS)(pDos->e_lfanew + dwBase); PIMAGE_DATA_DIRECTORY pIde = pNt->OptionalHeader.DataDirectory; pIde = &(pIde[IMAGE_DIRECTORY_ENTRY_EXPORT]); DWORD dwOffset = pIde->VirtualAddress; PIMAGE_EXPORT_DIRECTORY pExport = (PIMAGE_EXPORT_DIRECTORY)(dwBase + dwOffset); DWORD dwFuncCount = pExport->NumberOfFunctions; DWORD dwFuncNameCount = pExport->NumberOfNames; PDWORD pEAT = (PDWORD)(dwBase + pExport->AddressOfFunctions); PDWORD pENT = (PDWORD)(dwBase + pExport->AddressOfNames); PWORD pEIT = (PWORD)(dwBase + pExport->AddressOfNameOrdinals); DWORD dwFuncAddress = 0; for (size_t i = 0; i < dwFuncCount; i++) { if (!pEAT[i]) { continue; } DWORD dwFuncAddrOffset = pEAT[i]; for (size_t index = 0; index < dwFuncNameCount; index++) { if (pEIT[index] == i) { DWORD dwNameOffset = pENT[i]; char* szFuncName = (char*)((DWORD)dwBase + dwNameOffset); char szGetProcAddress[] = { 'G','e','t','P','r','o','c','A','d','d','r','e','s','s' }; int nFlagCount = 0; for (size_t j = 0; j < 14; j++) { if (szFuncName[j] == szGetProcAddress[j]) { nFlagCount++; } } if (nFlagCount == 14) { dwFuncAddress = pEAT[pEIT[i]] + dwBase; } } } } typedef HMODULE (WINAPI _stdcall * fnLoadLibraryA)( _In_ LPCSTR lpLibFileName ); typedef FARPROC (WINAPI _stdcall* fnGetProcAddress)( _In_ HMODULE hModule, _In_ LPCSTR lpProcName ); typedef int (WINAPI _stdcall* fnMessageBoxA)( _In_opt_ HWND hWnd, _In_opt_ LPCSTR lpText, _In_opt_ LPCSTR lpCaption, _In_ UINT uType); typedef VOID (WINAPI _stdcall* fnExitProcess)( _In_ UINT uExitCode ); char szLoadLibraryA[] = { 'L','o','a','d','L','i','b','r','a','r','y','A','\0' }; char szGetProcAddress[] = { 'G','e','t','P','r','o','c','A','d','d','r','e','s','s' ,'\0' }; char szMessageBoxA[] = { 'M','e','s','s','a','g','e','B','o','x','A','\0' }; char szExitProcess[] = { 'E','x','i','t','P','r','o','c','e','s','s','\0' }; char szUser32[] = { 'U','s','e','r','3','2','.','d','l','l','\0' }; char szbt[] = { 'H','e','l','l','o',',','B','T','!','\0'}; fnGetProcAddress pFnGetProcAddress = (fnGetProcAddress)dwFuncAddress; int address = (int)GetProcAddress; HMODULE hkernel32 = (HMODULE)dwkernel32; fnLoadLibraryA pFnLoadLibrary = (fnLoadLibraryA)(pFnGetProcAddress(hkernel32, szLoadLibraryA)); HMODULE hUser32 = (HMODULE)pFnLoadLibrary(szUser32); fnMessageBoxA pFnMessageBoxA = (fnMessageBoxA)pFnGetProcAddress(hUser32, szMessageBoxA); fnExitProcess pFnExitProcess = (fnExitProcess)pFnGetProcAddress(hkernel32, szExitProcess); pFnMessageBoxA(NULL, szbt, szbt, MB_OK); pFnExitProcess(0); }
|