-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjection.cpp
More file actions
45 lines (38 loc) · 900 Bytes
/
injection.cpp
File metadata and controls
45 lines (38 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<Windows.h>
using namespace std;
int main(int argc, char **argv)
{
if(argc != 2)
return -1;
int pid;
void *lla;
char *strdll;
HMODULE dllHandle;
HANDLE thrHandle;
HANDLE pHandle;
LPVOID pMem;
pid = atoi(argv[1]);
const size_t sstrdll = strlen(argv[2])+1;
strdll = argv[2];
pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(pHandle==NULL)
return -1;
pMem = VirtualAllocEx(pHandle, NULL, strdll, MEM_COMMIT, PAGE_READWRITE);
if(pMem)
{
if(WriteProcessMemory(pHandle, pMem, strdll, sstrdll))
{
dllHandle = GetModuleHandle("Kernel32.dll");
if(dllHandle)
{
lla = GetProcAddress(dllHandle, "LoadLibraryA");
if(lla)
{
DWORD dwThrId=0;
thrHandle = CreateRemoteThread(pHandle, NULL, 0, (LPTHREAD_START_ROUTINE)lla, pMem, 0, &dwThrId);
}
}
}
}
}