Guest User

Untitled

a guest
Jun 8th, 2015
347
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <TlHelp32.h>
  4.  
  5. using namespace std;
  6.  
  7. char fileToInject[250] = "C:\\Slrgrbrgr.dll";
  8. char processName[] = "csgo.exe";
  9.  
  10. typedef HINSTANCE (*fpLoadLibrary)(char*);
  11.  
  12. // Inject DLL
  13. bool injectDll(DWORD processId) {
  14.     HINSTANCE hDll = LoadLibrary("KERNEL32");
  15.  
  16.     fpLoadLibrary LoadLibraryAddr = (fpLoadLibrary)GetProcAddress(hDll, "LoadLibraryA");
  17.     HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
  18.  
  19.     LPVOID paramAddr = VirtualAllocEx(hProc, 0, strlen(fileToInject) + 1, MEM_COMMIT, PAGE_READWRITE);
  20.     int memoryWritten = WriteProcessMemory(hProc, paramAddr, fileToInject, strlen(fileToInject) + 1, NULL);
  21.  
  22.     // -----------------------
  23.     FILE * pFile;
  24.     fopen_s(&pFile, fileToInject, "r");
  25.    
  26.     cout << errno << endl;
  27.     // -----------------------
  28.    
  29.     HANDLE hRemoteThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, paramAddr, 0, 0);
  30.     CloseHandle(hProc);
  31.  
  32.     return memoryWritten != 0;
  33. }
  34.  
  35. // Entry function
  36. int main()
  37. {
  38.     DWORD processId = NULL;
  39.  
  40.     PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
  41.     HANDLE hProcSnap;
  42.  
  43.     // Look for right process
  44.     while (!processId) {
  45.         system("CLS");
  46.         cout << "Looking for " << processName << "..." << endl;
  47.  
  48.         hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  49.  
  50.         // Search in all processes for ProcessName[] and get id
  51.         if (Process32First(hProcSnap, &pe32)) {
  52.             while (Process32Next(hProcSnap, &pe32)) {
  53.                 if (!strcmp(pe32.szExeFile, processName)) {
  54.                     processId = pe32.th32ProcessID;
  55.                 }
  56.             }
  57.         }
  58.  
  59.         Sleep(1000);
  60.     }
  61.  
  62.     while (!injectDll(processId)) {
  63.         system("CLS");
  64.         cout << "DLL failed to inject" << endl;
  65.         Sleep(1000);
  66.     }
  67.  
  68.     cout << "DLL injected sucessfuly!" << endl << endl;
  69.     cout << "Closing in 5s...";
  70.  
  71.     CloseHandle(hProcSnap);
  72.     Sleep(5000);
  73.  
  74.     return 1;
  75. }
RAW Paste Data