-
Notifications
You must be signed in to change notification settings - Fork 0
/
classicDLLInjection.cpp
71 lines (58 loc) · 1.78 KB
/
classicDLLInjection.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
DWORD GetProcId(const char* procName)
{
DWORD procId = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
if (Process32First(hSnap, &procEntry))
{
do
{
if (!_stricmp(procEntry.szExeFile, procName))
{
procId = procEntry.th32ProcessID;
break;
}
} while (Process32Next(hSnap, &procEntry));
}
}
CloseHandle(hSnap);
return procId;
}
int main()
{
const char* dllPath = "c:\\not_exported.dll";
const char* procName = "AutoClicker.exe";
DWORD procId = 0;
while (!procId)
{
procId = GetProcId(procName);
if (procId == NULL)
Sleep(30);
}
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, procId);
if (hProc && hProc != INVALID_HANDLE_VALUE)
{
void* loc = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
std::cout << "VirtualAllocEx Adresi :" << loc << std::endl;
if (WriteProcessMemory(hProc, loc, dllPath, strlen(dllPath), 0) > 0)
std::cout << "WriteProcessMemory basarili." << std::endl;
HANDLE hThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, loc, 0, 0);
if (hThread)
{
std::cout << "CreateRemoteThread basarili." << std::endl;
CloseHandle(hThread);
}
}
if (hProc)
{
CloseHandle(hProc);
}
getchar();
return 0;
}