-
Notifications
You must be signed in to change notification settings - Fork 0
/
KillSS1Console.c
240 lines (194 loc) · 6.41 KB
/
KillSS1Console.c
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
C:\Program Files (x86)\D.O.S\SS1Agent\SS1ACT.exe
C:\Program Files (x86)\D.O.S\SS1Agent\SS1UserAgent.exe
C:\Program Files (x86)\D.O.S\SS1Agent\SS1Loader.exe
"C:\Program Files (x86)\D.O.S\SS1Agent\SS1AutoUpdate.exe"
"C:\Program Files (x86)\D.O.S\SS1Agent\SS1CollectServer.exe"
"C:\Program Files (x86)\D.O.S\SS1Agent\SS1NetWatchServer.exe"
"C:\Program Files (x86)\D.O.S\SS1Agent\SS1RCD.exe" -port 21652 -service
"C:\Program Files (x86)\D.O.S\SS1Agent\SS1SnmpServer.exe"
"C:\Program Files (x86)\D.O.S\SS1Agent\RBP.exe" -d -f "C:\Program Files (x86)\D.O.S\SS1Agent\rbp.conf"
*/
#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#include <io.h> // for _access()
#include <errno.h>
#define F_OK 0 // Check for file existence
#pragma comment(lib, "ws2_32.lib")
#define MAX_BUFFER_SIZE 4096
#define SS1_COLLECT_SERVER_PORT 21650
char path[100];
char command[50];
FILE *fp;
void killProcess(const char* processName) {
sprintf(command, "TASKKILL /F /IM %s >nul 2>nul", processName);
system(command);
}
DWORD WINAPI TaskKillThread(LPVOID lpParam) {
char buffer[30];
time_t rawtime;
struct tm timeinfo;
do {
// 打å°å½“å‰æ—¶é—´
time(&rawtime);
localtime_s(&timeinfo, &rawtime);
asctime_s(buffer, sizeof buffer, &timeinfo);
strftime(buffer, 30, "%Y-%m-%d %H:%M:%S", &timeinfo);
printf("KillSS1Console %s Start \n", buffer);
// 1. SS1CollectServer.exe
killProcess("SS1CollectServer.exe");
// 2. SS1UserAgent.exe
killProcess("SS1UserAgent.exe");
// 3. SS1ACT.exe
killProcess("SS1ACT.exe");
// 4. SS1ChSvr.exe
killProcess("SS1ChSvr.exe");
// 5. SS1Loader.exe
killProcess("SS1Loader.exe");
// 6. SS1GH.exe
killProcess("SS1GH.exe");
// 7. SS1GHx64.exe
killProcess("SS1GHx64.exe");
// 8. SS1GHLoader.exe
killProcess("SS1GHLoader.exe");
// 9. SS1GHLoaderx64.exe
killProcess("SS1GHLoaderx64.exe");
// 10. ss1Injectx64.exe
killProcess("ss1Injectx64.exe");
// 11. ss1Inject2x64.exe
killProcess("ss1Inject2x64.exe");
// 打å°å½“å‰æ—¶é—´
time(&rawtime);
localtime_s(&timeinfo, &rawtime);
asctime_s(buffer, sizeof buffer, &timeinfo);
strftime(buffer, 30, "%Y-%m-%d %H:%M:%S", &timeinfo);
printf("KillSS1Console %s Stop \n", buffer);
Sleep(10000); // 10s
} while (1);
return 0;
}
DWORD WINAPI ServerThread(LPVOID lpParam) {
WSADATA wsaData;
SOCKET s, new_socket;
struct sockaddr_in server, client;
char buffer[MAX_BUFFER_SIZE];
int c, recv_size;
int iBindRet = 1;
// åˆå§‹åŒ–Winsock
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
printf("Failed to initialize winsock.\n");
return 1;
}
// 创建socket
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET)
{
printf("Failed to create socket.\n");
return 1;
}
// 设置æœåŠ¡å™¨åœ°å€å’Œç«¯å£
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(SS1_COLLECT_SERVER_PORT);
// é¢?ç•?3s?¼Œè®©å¦ä¸ªçº¿ç¨‹æ€æŽ‰å¼€ç«¯å£çš?进程,以å…端å£è¢«å?导致绑定失败
Sleep(3000);
do {
// 绑�
if (bind(s, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
{
printf("Binding failed. It will automatically try to bind again after 5 minutes.\n");
// 如果绑定失败?¼?5åˆ?é’ŸåŽå†ç»‘定一次?¼Œç›´åˆ°æˆåŠŸ
Sleep(300000);
} else {
printf("Binding successful.\n");
iBindRet = 0;
}
} while (iBindRet == 1);
// 监å¬
listen(s, 3);
// ç‰å¾?连接
printf("Waiting for incoming connections on %d ...\n", SS1_COLLECT_SERVER_PORT);
c = sizeof(struct sockaddr_in);
while ((new_socket = accept(s, (struct sockaddr *)&client, &c)) != INVALID_SOCKET)
{
puts("Connection accepted");
// 接收并打å°æ•°æ®
if ((recv_size = recv(new_socket, buffer, MAX_BUFFER_SIZE, 0)) == SOCKET_ERROR)
{
puts("recv failed");
}
buffer[recv_size] = '\0';
printf("Received data: %s\n", buffer);
}
if (new_socket == INVALID_SOCKET)
{
printf("Accept failed.\n");
return 1;
}
// å…³é—socket
closesocket(s);
// æ¸?ç?Winsock
WSACleanup();
return 0;
}
int file_exists(const char *path) {
return _access(path, F_OK) != -1;
}
int rename_file(const char *original_path, const char *new_path) {
if (rename(original_path, new_path) != 0) {
perror("Failed to rename the file");
return -1;
}
printf("File successfully renamed to %s\n", new_path);
return 0;
}
int backfile_SS1ACT() {
const char *file_path = "C:\\Program Files (x86)\\D.O.S\\SS1Agent\\SS1ACT.exe";
const char *new_file_path = "C:\\Program Files (x86)\\D.O.S\\SS1Agent\\SS1ACT.exe.bak";
if (file_exists(file_path)) {
printf("File %s exists.\n", file_path);
if (rename_file(file_path, new_file_path) != 0) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
int backfile_SS1UserAgent() {
const char *file_path = "C:\\Program Files (x86)\\D.O.S\\SS1Agent\\SS1UserAgent.exe";
const char *new_file_path = "C:\\Program Files (x86)\\D.O.S\\SS1Agent\\SS1UserAgent.exe.bak";
if (file_exists(file_path)) {
printf("File %s exists.\n", file_path);
if (rename_file(file_path, new_file_path) != 0) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
int backfile_SS1Loader() {
const char *file_path = "C:\\Program Files (x86)\\D.O.S\\SS1Agent\\SS1Loader.exe";
const char *new_file_path = "C:\\Program Files (x86)\\D.O.S\\SS1Agent\\SS1Loader.exe.bak";
if (file_exists(file_path)) {
printf("File %s exists.\n", file_path);
if (rename_file(file_path, new_file_path) != 0) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
int main(int argc, char **argv)
{
CreateThread(NULL, 0, TaskKillThread, NULL, 0, NULL);
CreateThread(NULL, 0, ServerThread, NULL, 0, NULL);
backfile_SS1ACT();
backfile_SS1UserAgent();
backfile_SS1Loader();
// 主线程进å?¥æ—?é™å¾ªçŽ¯?¼Œä»¥é˜²æ¢ç¨‹åºç«‹å³é€€å‡º
while (1) {
Sleep(60000);
}
return 0;
}