Last active
December 9, 2017 12:57
-
-
Save epcnt19/9309fc1a353d127676f4c1f6ae3b07d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <Windows.h> | |
using namespace std; | |
int main(int argc,char *argv[]) | |
{ | |
int pid; | |
char* dllpath = "C:\\users\\user\\documents\\visual studio 2015\\Projects\\injector\\x64\\Debug\\dllexample.dll"; | |
cout << "Input process id" << endl; | |
cin >> pid; | |
HANDLE target_process = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid); | |
if (target_process == NULL) { | |
cout << "Faild to OpenProcess()" << endl; | |
return -1; | |
} | |
LPVOID la_addr = (LPVOID)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA"); | |
if (la_addr == NULL) { | |
cout << "Faild to GetProcAddress()" << endl; | |
return -1; | |
} | |
LPVOID alloc_addr = (LPVOID)VirtualAllocEx(target_process, NULL, strlen(dllpath), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | |
if (alloc_addr == NULL) { | |
cout << "Faild to VirtualAllocEx()" << endl; | |
return -1; | |
} | |
int n = WriteProcessMemory(target_process, alloc_addr, dllpath, strlen(dllpath), NULL); | |
if (n == 0) { | |
cout << "Faild to WriteProcessMemory()" << endl; | |
return -1; | |
} | |
HANDLE thread_id = CreateRemoteThread(target_process, NULL, 0, (LPTHREAD_START_ROUTINE)la_addr, alloc_addr,0,NULL); | |
if (thread_id == NULL) { | |
cout << "Faild to CreateRemoteThread()" << endl; | |
cout << "GetLastError " << GetLastError() << endl; | |
return -1; | |
} | |
cout << "Success DLL Injection" << endl; | |
CloseHandle(target_process); | |
getchar(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment