Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // inject.cpp : Defines the entry point for the console application.
- //
- #include <windows.h>
- #include <tlhelp32.h>
- #include <shlwapi.h>
- #include <conio.h>
- #include <stdio.h>
- #include <comdef.h>
- #define WIN32_LEAN_AND_MEAN
- #define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ)
- BOOL Inject(DWORD pID, const char * DLL_NAME);
- DWORD GetTargetThreadIDFromProcName(const char * ProcName);
- int main(int argc, char * argv[])
- {
- //############### CHANGE HERE ONLY ###################
- char *Target_Process = "victim.exe"; //###
- //#######################################################
- char *buf;
- DWORD pID = GetTargetThreadIDFromProcName(Target_Process);
- buf = "C:\\DllRedirectAPI.dll";
- if(!Inject(pID, buf))
- {
- printf("DLL Not Loaded!");
- }else{
- printf("DLL is Injected in torget Process");
- }
- _getch();
- return 0;
- }
- BOOL Inject(DWORD pID, const char * DLL_NAME)
- {
- HANDLE Proc;
- char buf[50] = {0};
- LPVOID RemoteString, LoadLibAddy;
- if(!pID)
- return false;
- Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
- if(!Proc)
- {
- sprintf(buf, "OpenProcess() failed: %d", GetLastError());
- printf(buf);
- return false;
- }
- LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "LoadLibraryA");
- RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
- WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_NAME), NULL);
- // Load our DLL
- CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL);
- CloseHandle(Proc);
- return true;
- }
- DWORD GetTargetThreadIDFromProcName(const char * ProcName)
- {
- PROCESSENTRY32 pe;
- HANDLE thSnapShot;
- BOOL retval, ProcFound = false;
- thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if(thSnapShot == INVALID_HANDLE_VALUE)
- {
- printf("Error: Unable create toolhelp snapshot!");
- return false;
- }
- pe.dwSize = sizeof(PROCESSENTRY32);
- retval = Process32First(thSnapShot, &pe);
- while(retval)
- {
- if(_bstr_t(pe.szExeFile) == _bstr_t(ProcName) )
- {
- return pe.th32ProcessID;
- }
- retval = Process32Next(thSnapShot, &pe);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement