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
| #include "addresshunter.h" #include <stdio.h> #include <inttypes.h>
typedef HMODULE(WINAPI* LOADLIBRARYA)(LPCSTR); typedef BOOL(WINAPI* CLOSEHANDLE)(HANDLE); typedef HANDLE(WINAPI* GETCURRENTPROCESS)();
typedef BOOL(WINAPI* OPENPROCESSTOKEN)(HANDLE, DWORD, PHANDLE); typedef BOOL(WINAPI* GETTOKENINFORMATION)(HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD); typedef BOOL(WINAPI* LOOKUPPRIVILEGENAMEW)(LPCWSTR, PLUID, LPWSTR, LPDWORD);
typedef int(WINAPI* WPRINTF)(const wchar_t* format, ...); typedef void*(WINAPI* CALLOC)(size_t num, size_t size);
void getprivs() { UINT64 kernel32dll, msvcrtdll, advapi32dll; UINT64 LoadLibraryAFunc, CloseHandleFunc, OpenProcessTokenFunc, GetCurrentProcessFunc, GetTokenInformationFunc, LookupPrivilegeNameWFunc, callocFunc, wprintfFunc;
kernel32dll = GetKernel32();
CHAR loadlibrarya_c[] = {'L', 'o', 'a', 'd', 'L', 'i', 'b', 'r', 'a', 'r', 'y', 'A', 0}; LoadLibraryAFunc = GetSymbolAddress((HANDLE)kernel32dll, loadlibrarya_c);
CHAR getcurrentprocess_c[] = {'G', 'e', 't', 'C', 'u', 'r', 'r', 'e', 'n', 't', 'P', 'r', 'o', 'c', 'e', 's', 's', 0}; GetCurrentProcessFunc = GetSymbolAddress((HANDLE)kernel32dll, getcurrentprocess_c);
CHAR closehandle_c[] = {'C', 'l', 'o', 's', 'e', 'H', 'a', 'n', 'd', 'l', 'e', 0}; CloseHandleFunc = GetSymbolAddress((HANDLE)kernel32dll, closehandle_c);
CHAR advapi32_c[] = {'a', 'd', 'v', 'a', 'p', 'i', '3', '2', '.', 'd', 'l', 'l', 0}; advapi32dll = (UINT64) ((LOADLIBRARYA)LoadLibraryAFunc)(advapi32_c); CHAR openprocesstoken_c[] = {'O', 'p', 'e', 'n', 'P', 'r', 'o', 'c', 'e', 's', 's', 'T', 'o', 'k', 'e', 'n', 0}; OpenProcessTokenFunc = GetSymbolAddress((HANDLE)advapi32dll, openprocesstoken_c); CHAR gettokeninformation_c[] = { 'G', 'e', 't', 'T', 'o', 'k', 'e', 'n', 'I', 'n', 'f', 'o', 'r', 'm', 'a', 't', 'i', 'o', 'n', 0 }; GetTokenInformationFunc = GetSymbolAddress((HANDLE)advapi32dll, gettokeninformation_c); CHAR lookupprivilegenamew_c[] = {'L', 'o', 'o', 'k', 'u', 'p', 'P', 'r', 'i', 'v', 'i', 'l', 'e', 'g', 'e', 'N', 'a', 'm', 'e', 'W', 0}; LookupPrivilegeNameWFunc = GetSymbolAddress((HANDLE)advapi32dll, lookupprivilegenamew_c);
CHAR msvcrt_c[] = {'m', 's', 'v', 'c', 'r', 't', '.', 'd', 'l', 'l', 0}; msvcrtdll = (UINT64) ((LOADLIBRARYA)LoadLibraryAFunc)(msvcrt_c); CHAR calloc_c[] = {'c', 'a', 'l', 'l', 'o', 'c', 0}; callocFunc = GetSymbolAddress((HANDLE)msvcrtdll, calloc_c); CHAR wprintf_c[] = {'w', 'p', 'r', 'i', 'n', 't', 'f', 0}; wprintfFunc = GetSymbolAddress((HANDLE)msvcrtdll, wprintf_c);
DWORD cbSize = sizeof(TOKEN_ELEVATION), tpSize, length; HANDLE hToken = NULL; TOKEN_ELEVATION Elevation; PTOKEN_PRIVILEGES tPrivs = NULL; WCHAR name[256]; WCHAR priv_enabled[] = { L'[', L'+', L']', L' ', L'%', L'-', L'5', L'0', L'l', L's', L' ', L'E', L'n', L'a', L'b', L'l', L'e', L'd', L' ', L'(', L'D', L'e', L'f', L'a', L'u', L'l', L't', L')', L'\n', 0 }; WCHAR priv_adjusted[] = { L'[', L'+', L']', L' ', L'%', L'-', L'5', L'0', L'l', L's', L' ', L'A', L'd', L'j', L'u', L's', L't', L'e', L'd', L'\n', 0 }; WCHAR priv_disabled[] = { L'[', L'+', L']', L' ', L'%', L'-', L'5', L'0', L'l', L's', L' ', L'D', L'i', L's', L'a', L'b', L'l', L'e', L'd', L'\n', 0 }; WCHAR priv_elevated[] = {L'[', L'+', L']', L' ', L'E', L'l', L'e', L'v', L'a', L't', L'e', L'd', 0}; WCHAR priv_restricted[] = {L'[', L'+', L']', L' ', L'R', L'e', L's', L't', L'r', L'i', L'c', L't', L'e', L'd', 0};
if (((OPENPROCESSTOKEN)OpenProcessTokenFunc)(((GETCURRENTPROCESS)GetCurrentProcessFunc)(), TOKEN_QUERY, &hToken)) { ((GETTOKENINFORMATION)GetTokenInformationFunc)(hToken, TokenPrivileges, tPrivs, 0, &tpSize); tPrivs = (PTOKEN_PRIVILEGES)((CALLOC)callocFunc)(tpSize+1, sizeof(TOKEN_PRIVILEGES));
if (tPrivs) { if (((GETTOKENINFORMATION)GetTokenInformationFunc)(hToken, TokenPrivileges, tPrivs, tpSize, &tpSize)) { for(int i=0; i<tPrivs->PrivilegeCount; i++){ length=256; ((LOOKUPPRIVILEGENAMEW)LookupPrivilegeNameWFunc)(NULL, &tPrivs->Privileges[i].Luid, name, &length); if (tPrivs->Privileges[i].Attributes == 3) { ((WPRINTF)wprintfFunc)(priv_enabled, name); } else if (tPrivs->Privileges[i].Attributes == 2) { ((WPRINTF)wprintfFunc)(priv_adjusted, name); } else if (tPrivs->Privileges[i].Attributes == 0) { ((WPRINTF)wprintfFunc)(priv_disabled, name); } } } }
if (((GETTOKENINFORMATION)GetTokenInformationFunc)(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) { if (Elevation.TokenIsElevated) { ((WPRINTF)wprintfFunc)(priv_elevated); } else { ((WPRINTF)wprintfFunc)(priv_restricted); } } ((CLOSEHANDLE)CloseHandleFunc)(hToken); } }
|