I've made a simple injector and a very simple DLL. I tried to inject the DLL in both Notepad and Notepad++. However Notepad just doesn't show the messagebox and Notepad++ crashes when I inject it.
Injector:
main.cpp
#include <cstdio> #include <windows.h> #include <tlhelp32.h> DWORD GetProcessIdByName(char * procName); int main() { char dllName[] = "NotepadHack.dll"; printf("DLL Injector\n"); printf("____________\n"); printf("\n"); printf("Openening process notepad++.exe...\n"); HANDLE hProcess = NULL; hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetProcessIdByName("notepad++.exe")); if(hProcess == NULL) { printf("Process could not be opened.\n"); getchar(); return 1; } printf("Process opened successfully.\n"); getchar(); printf("Injecting DLL...\n"); LPVOID pLibAddress = GetProcAddress(GetModuleHandle("Kernel32.dll"), "LoadLibraryA"); LPVOID pDllAddress = VirtualAllocEx(hProcess, NULL, sizeof(dllName), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); WriteProcessMemory(hProcess, pDllAddress, dllName, sizeof(dllName), NULL); CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)&pLibAddress, pDllAddress, 0, NULL); printf("DLL injected successfully.\n"); printf("Closing process handle...\n"); CloseHandle(hProcess); getchar(); return 0; } DWORD GetProcessIdByName(char * procName) { PROCESSENTRY32 entry; DWORD procID = -1; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(Process32First(hSnapshot, &entry) == TRUE) { do { if(stricmp(entry.szExeFile, procName) == 0) { procID = entry.th32ProcessID; } }while(Process32Next(hSnapshot, &entry) == TRUE); } CloseHandle(hSnapshot); return procID; }
main.cpp
#include <windows.h> BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved) { switch(fdwReason) { case DLL_PROCESS_ATTACH: { MessageBox(NULL, "Hello World!", "Hack", 0); }break; } }
Thanks
Comment