Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WIN32_WINNT _WIN32_WINNT_WINXP
- #include <iostream>
- #include <windows.h>
- #include <tlhelp32.h>
- int gethd()
- {
- PROCESSENTRY32 pe32;
- pe32.dwSize = sizeof(pe32);
- HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if(hProcessSnap == INVALID_HANDLE_VALUE)
- return -1;
- else
- {
- if(!Process32First(hProcessSnap, &pe32))
- return -2;
- do
- {
- std::cout << pe32.szExeFile << "[" << pe32.th32ProcessID << "]\n";
- }while(Process32Next(hProcessSnap, &pe32));
- }
- return 0;
- }
- int main()
- {
- std::cout << "\n\n+-+-+-+-+-+-+-+-+\n";
- std::cout << "|1|n|j|3|k|t|0|r|\n";
- std::cout << "+-+-+-+-+-+-+-+-+\n\n\n\n";
- switch(gethd())
- {
- case -1:
- std::cout << "CreateToolhelp32Snapshot()";
- break;
- case -2:
- std::cout << "Process32First()";
- break;
- case 0:
- {
- int pid = 0;
- HANDLE hTarget, hThread;
- LPVOID pAddr, vAlloc;
- OPENFILENAME ofn;
- char dllName[256];
- ZeroMemory(&ofn, sizeof(ofn));
- memset(dllName, 0, 256);
- std::cout << "\n\n\nEnter the process PID: ";
- std::cin >> pid;
- hTarget = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
- if(hTarget == INVALID_HANDLE_VALUE)
- std::cout << "hTarget returned " << GetLastError();
- else
- {
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = FindWindow("ConsoleWindowClass", NULL);
- ofn.lpstrFile = dllName;
- ofn.lpstrFile[0] = '\0';
- ofn.nMaxFile = sizeof(dllName);
- ofn.lpstrFilter = "";
- ofn.nFilterIndex = 1;
- ofn.lpstrInitialDir = "C:\\";
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
- if(GetOpenFileName(&ofn))
- {
- pAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
- vAlloc = VirtualAllocEx(hTarget, NULL, strlen(dllName), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
- if(pAddr == NULL)
- std::cout << "pAddr returned " << GetLastError();
- else if(vAlloc == NULL)
- std::cout << "vAlloc returned " << GetLastError();
- else
- {
- if(!WriteProcessMemory(hTarget, vAlloc, dllName, strlen(dllName), NULL))
- std::cout << "WriteProcessMemory returned " << GetLastError();
- if((hThread = CreateRemoteThread(hTarget, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryA, vAlloc, NULL, NULL)) == NULL)
- std::cout << "CreateRemoteThread returned " << GetLastError();
- else
- {
- std::cout << "Injected " << dllName;
- WaitForSingleObject(hThread, WAIT_TIMEOUT);
- }
- }
- }
- else
- std::cout << "Please choose a DLL.";
- }
- }
- }
- VirtualFreeEx(hTarget, vAlloc, NULL, MEM_RELEASE);
- CloseHandle(hTarget);
- std::cin.ignore();
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement