-
Notifications
You must be signed in to change notification settings - Fork 117
/
entry.c
159 lines (134 loc) · 3.69 KB
/
entry.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
#include <windows.h>
#include "beacon.h"
#include "bofdefs.h"
#include "base.c"
DWORD config_service(const char* Hostname, const char* cpServiceName, const char * binpath, DWORD errmode, DWORD startmode)
{
DWORD dwResult = ERROR_SUCCESS;
SC_HANDLE scManager = NULL;
SC_HANDLE scService = NULL;
// Open the service control manager
scManager = ADVAPI32$OpenSCManagerA(Hostname, SERVICES_ACTIVE_DATABASEA, SC_MANAGER_CONNECT);
if (NULL == scManager)
{
dwResult = KERNEL32$GetLastError();
internal_printf("OpenSCManagerA failed (%lu)\n", dwResult);
goto config_service_end;
}
// Open the service
scService = ADVAPI32$OpenServiceA(scManager, cpServiceName, SERVICE_CHANGE_CONFIG);
if (NULL == scService)
{
dwResult = KERNEL32$GetLastError();
internal_printf("OpenServiceA failed (%lu)\n", dwResult);
goto config_service_end;
}
// Set the service configuration
if( FALSE == ADVAPI32$ChangeServiceConfigA(
scService,
SERVICE_NO_CHANGE,
startmode,
errmode,
binpath,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
)
)
{
dwResult = KERNEL32$GetLastError();
internal_printf("ChangeServiceConfigA failed (%lu)\n", dwResult);
goto config_service_end;
}
config_service_end:
if (scService)
{
ADVAPI32$CloseServiceHandle(scService);
scService = NULL;
}
if (scManager)
{
ADVAPI32$CloseServiceHandle(scManager);
scManager = NULL;
}
return dwResult;
}
#ifdef BOF
VOID go(
IN PCHAR Buffer,
IN ULONG Length
)
{
DWORD dwErrorCode = ERROR_SUCCESS;
datap parser;
const char * hostname = NULL;
const char * servicename = NULL;
const char * binpath = NULL;
DWORD ignoremode = 0;
DWORD startmode = 0;
BeaconDataParse(&parser, Buffer, Length);
hostname = BeaconDataExtract(&parser, NULL);
servicename = BeaconDataExtract(&parser, NULL);
binpath = BeaconDataExtract(&parser, NULL);
ignoremode = (DWORD)BeaconDataShort(&parser);
startmode = (DWORD)BeaconDataShort(&parser);
if(!bofstart())
{
return;
}
if(*binpath == 0) {binpath = NULL;}
internal_printf("config_service:\n");
internal_printf(" hostname: %s\n", hostname);
internal_printf(" servicename: %s\n", servicename);
internal_printf(" binpath: %s\n", (binpath) ? binpath : "(Unchanged)");
internal_printf(" ignoremode: %lX\n", ignoremode);
internal_printf(" startmode: %lX\n", startmode);
dwErrorCode = config_service(hostname, servicename, binpath, ignoremode, startmode);
if(ERROR_SUCCESS != dwErrorCode)
{
BeaconPrintf(CALLBACK_ERROR, "config_service failed: %lu\n", dwErrorCode);
goto go_end;
}
internal_printf("SUCCESS.\n");
go_end:
printoutput(TRUE);
bofstop();
};
#else
#define TEST_HOSTNAME ""
#define TEST_SVC_NAME "BOF_SVC_NAME"
#define TEST_BIN_PATH "C:\\Windows\\System32\\alg.exe"
int main(int argc, char ** argv)
{
DWORD dwErrorCode = ERROR_SUCCESS;
LPCSTR lpcszHostName = TEST_HOSTNAME;
LPCSTR lpcszServiceName = TEST_SVC_NAME;
LPCSTR lpcszBinPath = TEST_BIN_PATH;
DWORD dwErrorMode = SERVICE_ERROR_IGNORE;
DWORD dwStartMode = SERVICE_AUTO_START;
internal_printf("config_service:\n");
internal_printf(" lpcszHostName: %s\n", lpcszHostName);
internal_printf(" lpcszServiceName: %s\n", lpcszServiceName);
internal_printf(" lpcszBinPath: %s\n", lpcszBinPath);
internal_printf(" dwErrorMode: %lX\n", dwErrorMode);
internal_printf(" dwStartMode: %lX\n", dwStartMode);
dwErrorCode = config_service(
lpcszHostName,
lpcszServiceName,
lpcszBinPath,
dwErrorMode,
dwStartMode
);
if(ERROR_SUCCESS != dwErrorCode)
{
BeaconPrintf(CALLBACK_ERROR, "config_service failed: %lX\n", dwErrorCode);
goto main_end;
}
internal_printf("SUCCESS.\n");
main_end:
return dwErrorCode;
}
#endif