-
Notifications
You must be signed in to change notification settings - Fork 111
/
remote_service_enum.c
48 lines (38 loc) · 1.28 KB
/
remote_service_enum.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
#include <windows.h>
#include <stdio.h>
int main(int argc, char **argv) {
BYTE sid[SECURITY_MAX_SID_SIZE];
DWORD sidSize = sizeof(sid);
char domainName[256];
DWORD domainNameSize = sizeof(domainName);
SID_NAME_USE snu;
BOOL bResult = FALSE;
CHAR serviceName[256];
snprintf(serviceName, 255, "Nt Service\\%s", argv[2]);
if(strcmp(argv[1], ".") == 0) {
argv[1] = NULL;
}
if(argc > 3) {
CHAR* domain = argv[3];
CHAR* username = argv[4];
CHAR* password = argv[5];
HANDLE hToken = NULL;
printf("Username was provided attempting to call LogonUserA\n");
bResult = LogonUserA(username, domain, password, LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT, &hToken);
if(!bResult) {
printf("LogonUserA failed %ld\n", GetLastError());
ExitProcess(0);
}
bResult = FALSE;
bResult = ImpersonateLoggedOnUser(hToken);
if(!bResult) {
printf("ImpersonateLoggedOnUser failed %ld\n", GetLastError());
ExitProcess(0);
}
CloseHandle(hToken);
}
if(LookupAccountNameA(argv[1], serviceName, sid, &sidSize, domainName, &domainNameSize, &snu)) {
printf("%s was found\n", argv[2]);
}
return 0;
}