-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (48 loc) · 1.52 KB
/
main.cpp
File metadata and controls
61 lines (48 loc) · 1.52 KB
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
#include <windows.h>
#include <detours.h>
#include <iostream>
#include <string>
#pragma comment(lib, "detours.lib")
void SetColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
bool SpawnWithDll(const std::wstring& exe)
{
STARTUPINFOW si{ sizeof(si) };
PROCESS_INFORMATION pi{};
// command line must be mutable buffer
std::wstring cmd = L"\"" + exe + L"\"";
BOOL ok = DetourCreateProcessWithDllExW(
exe.c_str(), // lpApplicationName
&cmd[0], // lpCommandLine
nullptr, nullptr,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
nullptr, // inherit environment
nullptr, // inherit CWD
&si,
&pi,
"C:\\Users\\sample.dll", // <‑‑ the injected DLL
nullptr); // use default CreateProcessW
if (!ok) {
SetColor(FOREGROUND_RED);
std::wcerr << L"[!] DetourCreateProcessWithDllExW failed: "
<< GetLastError() << L"\n";
return false;
}
SetColor(FOREGROUND_GREEN);
std::wcout << L"[+] Process startet with injected DLL..." << L"\n";
std::wcout << L"[+] PID: " << pi.dwProcessId << L"\n";
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return true;
}
int main()
{
std::wstring exe = L"C:\\Windows\\System32\\dllhost.exe";
if (!SpawnWithDll(exe))
return 1;
SetColor(FOREGROUND_INTENSITY);
return 0;
}