_IsDebuggerPresent_DebugPort - calls NtQueryInformationProcess with PROCESS_INFORMATION_CLASS 0x07 to check for debuggers */
| 182 | _IsDebuggerPresent_DebugPort - calls NtQueryInformationProcess with PROCESS_INFORMATION_CLASS 0x07 to check for debuggers |
| 183 | */ |
| 184 | DetectionFlags DebuggerDetections::_IsDebuggerPresent_DebugPort() |
| 185 | { |
| 186 | typedef NTSTATUS(NTAPI* TNtQueryInformationProcess)(IN HANDLE ProcessHandle, IN PROCESS_INFORMATION_CLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength); |
| 187 | |
| 188 | HMODULE hNtdll = GetModuleHandleA("ntdll.dll"); |
| 189 | |
| 190 | if (hNtdll) |
| 191 | { |
| 192 | auto pfnNtQueryInformationProcess = (TNtQueryInformationProcess)GetProcAddress(hNtdll, "NtQueryInformationProcess"); |
| 193 | |
| 194 | if (pfnNtQueryInformationProcess) |
| 195 | { |
| 196 | const PROCESS_INFORMATION_CLASS ProcessDebugPort = (PROCESS_INFORMATION_CLASS)7; |
| 197 | DWORD dwProcessDebugPort, dwReturned; |
| 198 | NTSTATUS status = pfnNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort, &dwProcessDebugPort, sizeof(DWORD), &dwReturned); |
| 199 | |
| 200 | if (NT_SUCCESS(status) && (dwProcessDebugPort == -1)) |
| 201 | { |
| 202 | return DEBUG_DEBUG_PORT; |
| 203 | } |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | Logger::logf(Warning, "Failed to fetch NtQueryInformationProcess address @ _IsDebuggerPresent_DebugPort "); |
| 208 | return EXECUTION_ERROR; |
| 209 | } |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | Logger::logf(Warning, "Failed to fetch ntdll.dll address @ _IsDebuggerPresent_DebugPort "); |
| 214 | return EXECUTION_ERROR; |
| 215 | } |
| 216 | |
| 217 | return NONE; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | _IsDebuggerPresent_ProcessDebugFlags - calls NtQueryInformationProcess with PROCESS_INFORMATION_CLASS 0x1F to check for debuggers |
nothing calls this directly
no outgoing calls
no test coverage detected