totorowldox的blog~

Thread Killer

Download: Thread Killer

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
#include<bits/stdc++.h>
#include <windows.h>
#include<Tlhelp32.h>
using namespace std;
int pid = -1;
HWND hWnd;
BOOL SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnable = TRUE)
{
OutputDebugString(lpszPrivilege);
BOOL bRet = FALSE;
HANDLE hToken = NULL;
HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, ::GetCurrentProcessId());
if (!::OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken))
{
goto __EXIT;
}
LUID Luid;
if (!::LookupPrivilegeValue(NULL, lpszPrivilege, &Luid))
{
goto __EXIT;
}
TOKEN_PRIVILEGES newPrivilege;
newPrivilege.PrivilegeCount = 1;
newPrivilege.Privileges[0].Luid = Luid;
newPrivilege.Privileges[0].Attributes =
bEnable ?
SE_PRIVILEGE_ENABLED :
SE_PRIVILEGE_ENABLED_BY_DEFAULT;
if (!::AdjustTokenPrivileges(hToken, FALSE, &newPrivilege,
sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{
TCHAR s[64] = { 0 };
sprintf(s, "AdjustTokenPrivileges error: %u\n", GetLastError());
OutputDebugString(s);
goto __EXIT;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
OutputDebugString("The token does not have the specified privilege. \n");
goto __EXIT;
}
bRet = TRUE;
OutputDebugString("Set OK");
__EXIT:
if (hProcess)
{
::CloseHandle(hProcess);
}
if (hToken)
{
::CloseHandle(hToken);
}
return bRet;
}
bool GetProcessIDByName(LPCTSTR szProcessName)
{
STARTUPINFO st;
PROCESS_INFORMATION pi;
PROCESSENTRY32 ps;
HANDLE hSnapshot;
ZeroMemory(&st, sizeof(STARTUPINFO));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
st.cb = sizeof(STARTUPINFO);
ZeroMemory(&ps, sizeof(PROCESSENTRY32));
ps.dwSize = sizeof(PROCESSENTRY32);
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return false;
if (!Process32First(hSnapshot, &ps))
return false;
do
{

if (lstrcmpi(ps.szExeFile, szProcessName) == 0)
{
pid = ps.th32ProcessID;
return true;
}
} while (Process32Next(hSnapshot, &ps));
CloseHandle(hSnapshot);
return false;
}
void th_function()
{
while(1)
{
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
ShowWindow(hWnd,SW_NORMAL);
Sleep(10);
}
}
int main(int argc, char* argv[])
{
hWnd=GetForegroundWindow();
std::thread t(th_function);
fir:int mod;
cout << "Method: 1.terminate 2.suspend 3.resume ";
cin >> mod;
string s;
cout << "\nProcess name: ";
cin >> s;
cout << "\nWaiting for process." << endl;
GetProcessIDByName(s.c_str());
while(pid == -1)
{
cout << ".";
GetProcessIDByName(s.c_str());
Sleep(10);
}
cout << "\npid getted : " << pid << endl;
cout << "\nTrying to set privilege.\n";
bool ok = SetPrivilege(SE_DEBUG_NAME);
if(!ok)
{
cout << "\n[Warning]Error while setting privilege : " << GetLastError() << endl;
//return 0;
}
else
cout << "\nSuccessefully sets privilege.\n";
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
cout << "\nTrying to open the process.\n";
if(hProcess == NULL)
{
cout << "\nUnable to open : " << GetLastError() << endl;
system("PAUSE");
//return 0;
}
else
cout << "\nSuccessefully opens the process: " << hProcess << endl;
if(mod == 1)
{
HANDLE hThread = CreateRemoteThread(hProcess, 0, 0, 0, 0, 0, NULL);
cout << "\nTrying to create remote thread.\n";
if(hThread == NULL)
{
cout << "\nUnable to create the thread : " << GetLastError() << endl;
system("PAUSE");
//return 0;
}
else
cout << "\nSuccessefully creates the thread: " << hThread << endl;
TerminateProcess(hProcess, NULL);
cout << "\nThread killed?Check by yourself lol.\n" << endl;
}
else if(mod == 2)
{
THREADENTRY32 te32;
te32.dwSize = sizeof(te32);
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, NULL);
Thread32First(hSnap, &te32);
printf("\nFinding a thread to suspend.\n");
while (Thread32Next(hSnap, &te32))
{
if (te32.th32OwnerProcessID == pid)
{
printf("\nThread found. Thread ID: %d\n", te32.th32ThreadID);
SuspendThread(OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID));
}
}
}
else
{
THREADENTRY32 te32;
te32.dwSize = sizeof(te32);
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, NULL);
Thread32First(hSnap, &te32);
printf("\nFinding a thread to resume.\n");
while (Thread32Next(hSnap, &te32))
{
if (te32.th32OwnerProcessID == pid)
{
printf("\nThread found. Thread ID: %d\n", te32.th32ThreadID);
ResumeThread(OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID));
}
}
}
system("PAUSE");
goto fir;
return 0;
}
打赏