95 Commits

Author SHA1 Message Date
heck-gd b53c2f7314 Add compatibility for VMProtect 3.6+ 2023-02-03 16:08:09 +01:00
Matthijs Lavrijsen 2276f14771 Add NtUserGetForegroundWindow hook
Fixes #116
2021-01-26 03:47:19 +01:00
Bill Bierman 706fec4350 Add 64 bit support for KiUserExceptionDispatcher (#106)
* Added manually generated trampoline for KiUserExceptionDispatcher on x86_64

* Preserve prologue of KiUserExceptionDispatcher for hook removal
2020-06-08 20:04:44 +02:00
Mattiwatti 59309a2057 Adjust OtherOperationCount after NtMapViewOfSection
https://everdox.blogspot.com/2013/11/debugger-detection-with.html
2020-05-17 00:27:27 +02:00
Mattiwatti 10ddb89fba ProcessDebugObjectHandle: handle overlapping buffer and return length
See https://github.com/mrexodia/TitanHide/issues/39
2019-12-12 11:39:23 +01:00
Mattiwatti a596f7f5d2 Add TLS to HookLibrary for InstrumentationCallbackDisabled field
This fixes potential race conditions with multiple threads active while the instrumentation callback is installed
2019-12-12 11:34:58 +01:00
Mattiwatti 684af33c46 Instrumentation callback improvements and fixes
- Fix "initialization error 1" on Windows 7/8/8.1 and supported (= with known syscall tables) versions of Windows 10
- Zero extend the value of RAX on x64 when returning an NTSTATUS
- Fix access violation on instrumentation callback removal on Windows 7/8/8.1
2019-06-03 03:14:45 +02:00
Mattiwatti f3f41ebe09 NtUserQueryWindow hook improvements
- Do not return the real PID or TID of any window with a bad owner process, window class name or title
- Instead of returning a bogus handle, return the debuggee's own client ID
2019-05-22 01:17:44 +02:00
Mattiwatti 7bc1fa7de7 Fix NtUserBuildHwndList hook on Windows 8 and later
NtUserBuildHwndList gained a boolean parameter in Windows 8, which breaks the call because the original syscall is called with one less argument (which results in STATUS_INVALID_HANDLE). Work around this by exporting a separate HookedNtUserBuildHwndList_Eight function that uses the new prototype. Replace the HOOK_NATIVE() invocation in ApplyHooking.cpp with a manual version that determines the hook to use based on the OS version
2019-05-18 04:51:25 +02:00
Mattiwatti 956fea4e6d Improve NtUserBuildHwndList hook
- Query NtUserGetClassName and NtUserInternalGetWindowText addresses using the new syscall lookup magic
- Add IsWindowBad() helper function which determines for a given HWND not only whether it belongs to the debugger process by PID, but also whether is has a forbidden class name or window text
- FilterHwndList: instead of only comparing against the protected PID, use IsWindowBad() both to determine which HWNDs to overwrite and which ones are good replacements. This allows you to have e.g. IDA and x64dbg open and both will be hidden, even if only x64dbg is actively debugging
2019-05-18 03:25:07 +02:00
Mattiwatti 6817d32581 Remove NtApiCollection.ini
- Get rid of NtApiLoader and replace it with a syscall lookup table (Windows XP through early 10) or win32u.dll addresses (later Windows 10 versions)
- Remove NtApiTool/PDBReader project since the NtApiCollection.ini file it generates is no longer used
- Rename BlockInput hook to NtUserBlockInput since they are the same function. The INI setting "BlockInputHook" is now also NtUserBlockInputHook
- Merge ApplyUser32Hook and ApplyWin32uHook into ApplyUserHook
2019-05-17 01:10:42 +02:00
Mattiwatti 1bd5c5c8fe Remove unused ntdll, kernel32/base and user32 handles from DLL data 2019-05-17 00:58:18 +02:00
Mattiwatti 0a03ffd378 Add Windows 10 WOW64 instrumentation callback hook 2019-05-03 23:23:07 +02:00
Mattiwatti d16ca2d1c2 Move RealGetSystemTime and RealGetLocalTime to HookHelper.cpp 2019-05-03 23:22:18 +02:00
Mattiwatti 66ec9ad514 Add x64 instrumentation callback hook 2019-04-05 13:00:11 +02:00
Mattiwatti dfec5d0e2f NtGetContextThread: if debug registers were requested, zero them 2019-03-25 23:26:47 +01:00
Mattiwatti 5cf2d494ee Add NtDuplicateObject hook
This is actually part of the NtClose hook (in that NtClose is the problem, not NtDuplicateObject), it's just that NtDuplicateObject with DUPLICATE_CLOSE_SOURCE is a very clever way of calling NtClose inside the kernel where our ntdll hook obviously doesn't fly

Reported by _BaZzi (https://forum.tuts4you.com/topic/35191-scyllahide/?page=9&tab=comments#comment-189015)
2019-01-14 16:32:56 +01:00
͏ c763dfd144 Fixed return length adjustment for SystemHandleInformation/Ex in HookedNtQuerySystemInformation (#59) 2018-10-11 11:41:37 +02:00
Mattiwatti a2ac0575d2 Fix VMProtect detection of NtQueryInformationProcess(ProcessDebugObjectHandle). Closes #51
This was caused by an incorrect order of operations (modifying return length after changing the return status).
In the interest of saving time on both sides, pre-emptively fix this for other syscalls/classes as well
2018-09-22 14:38:30 +02:00
Mattiwatti b2618a39cb Fix signed/unsigned comparison 2018-09-22 14:34:43 +02:00
Mattiwatti 77cd88f6d6 Fix a sliightly embarrassing bug where the debug object handle returned by NtQueryInformationProcess(ProcessDebugObjectHandle) was zeroed but not actually closed, causing this handle to remain in the debuggee's process handle table. (This can be repeated up to ~1300 times if needed to build a handy array of spare debug object handles - after that the process becomes unresponsive.)
This bug has been in ScyllaHide since the first commit to the repository.
2018-08-27 08:50:32 +02:00
Mattiwatti dfb6610981 NtUserBuildHwndList: do not assume the i+1th HWND is a safe replacement for the case of the HWND with i == 0 being the debugger process. This fixes EnumWindows() finding e.g. x64dbg despite the hook because it has multiple windows which can be obtained if i = 0, i = 1, i = 2... and so on 2018-01-05 02:14:14 +01:00
Mattiwatti 1caa98bd67 The required length for SystemCodeIntegrityUnlockInformation was changed in RS3, but the correct output is still 0. Simply zero SystemInformationLength bytes of memory to be compatible with both RS3 and earlier versions 2017-11-22 12:08:37 +01:00
Mattiwatti d2f20e7b9a NtSetDebugFilterState should not return STATUS_ACCESS_DENIED if the process has debug privileges 2017-11-14 21:08:10 +01:00
Mattiwatti c850825cf7 NtQueryObject hook: only set the total object and handle counts to 0 for ObjectTypesInformation, decrement by 1 for ObjectTypeInformation
This prevents the debuggee from doing
NtCreateDebugObject(&h);
NtQueryObject(h, ObjectTypeInformation);
if (TotalNumberOfObjects == 0) { /* something is wrong since we just made a debug object */ }

Found by Al-Khaser (https://github.com/LordNoteworthy/al-khaser)
2017-11-12 03:04:34 +01:00
Mattiwatti 6d6fa93678 NtQuerySystemInformation(SystemHandleInformation/SystemExtendedHandleInformation): more return length bookkeeping 2017-11-12 02:58:35 +01:00
Mattiwatti e4baef943c GetExplorerProcessId() really only has to exist in one place 2017-11-11 23:25:08 +01:00
Mattiwatti 1100da8b60 IsProcessBad(): we already have a length counted string. No need to throw away the length, allocate 800 bytes, zero them, copy the string, then do an equality comparison which requires length counting anyway. Instead just call RtlEqualUnicodeString
IsWindowClassBad and IsWindowNameBad still require 'wcsistr'. Added TODO note to wcsistr to rename it and make it take a PUNICODE_STRING in order to increase sanity levels
ScyllaTest: call FreeConsole before exiting
2017-11-09 20:56:00 +01:00
Mattiwatti 85daaf73b6 NtQueryInformationProcess/NtQuerySystemInformation/NtQueryObject hooks: if a return length is present and overlaps (is part of) the output buffer, store a backup of the return length prior to hooking, then restore the original return length afterwards. Fixes #47 and makes NtQuery_OverlappingReturnLength test succeed with hooks enabled 2017-11-08 19:50:36 +01:00
Mattiwatti 91441ba2b4 NtQueryInformationProcess and NtQueryObject hooks: check if the ProcessInformationClass or ObjectInformationClass is relevant prior to doing anything, similar to how the NtQuerySystemInformation hook already works
This is in preparation for the next commit which will be quite gruesome
2017-11-08 19:40:06 +01:00
Mattiwatti 315c4af39d Add SystemSessionProcessInformation to NtQuerySystemInformation hook (#42) 2017-10-28 00:45:43 +02:00
Mattiwatti 36617dde6e NtQuerySystemInformation hook: add SystemHandleInformation and SystemExtendedHandleInformation. Handles to objects of types DebugObject, Process and Thread are filtered out.
Currently this is done by PID *for the debugger process only* (i.e., it does not work when using the CLI, and it does not hide a process handle from windbg.exe to the debuggee if ScyllaHide is running as an x64dbg plugin)
2017-10-26 21:48:02 +02:00
Mattiwatti 19906ba66d Add new query classes to NtQuerySystemInformation hook:
- SystemExtendedProcessInformation
- SystemCodeIntegrityInformation
- SystemKernelDebuggerInformationEx
- SystemKernelDebuggerFlags
- SystemCodeIntegrityUnlockInformation
2017-10-11 21:41:31 +02:00
Mattiwatti a961f53e75 Do not call GetSystemTime or GetLocalTime since these functions use RIP-relative addressing in KernelBase, which breaks if they are moved without relocating.
Instead add replacment versions for the above functions and call these directly. #31
2017-08-17 00:29:40 +02:00
Mattiwatti a77aa2e9e3 Update ntdll.h 2017-06-14 22:10:58 +02:00
Mattiwatti 88a0a3b36f "explorer.exe" is an immutable string, no need to have it taking up space in .data and no need to length count it either. Use string literals and turn on the magic of /GF to fold them into one string
Do the same with functions and /Gy
2017-06-04 22:41:48 +02:00
Mattiwatti 289ba72610 _wcsicmp and _wcsnicmp: two come in, one comes out 2017-06-04 22:40:30 +02:00
Mattiwatti e8c396f07b No need to LdrGetDllHandle ntdll, its address is filled in by the injector 2017-06-04 21:56:17 +02:00
Mattiwatti b88e98b9cf 15/20: GetProcAddress 2017-06-04 21:07:50 +02:00
Mattiwatti f743d69335 13-14/20: GetLastError, SetLastError 2017-06-04 20:59:24 +02:00
Mattiwatti 6942be605d 11/20: GetCurrentProcessId 2017-06-04 20:54:32 +02:00
Mattiwatti 6561db2838 2/20: GetVersionExW 2017-06-04 19:29:13 +02:00
Mattiwatti 44d12cdf29 1/20: GetTickCount 2017-06-04 19:24:59 +02:00
Mattiwatti b77430f4dd Update ntdll.h. A lot (#26)
Some minor type cast and include changes in as part of the fallout of the ntdll change
2017-06-04 17:30:59 +02:00
Mattiwatti 0949ab4a48 Fix VS2017 pointer truncation warnings (all PIDs, ie false positives)
Remove unused GetCsrssProcessId() which was totally wrong anyway :P
2017-06-03 21:43:09 +02:00
Aleksey Katargin ab6d866511 rename HOOK_DLL_EXCHANGE -> HOOK_DLL_DATA 2017-03-03 18:58:52 +05:00
Aleksey Katargin 60e957b398 move hide settings to scylla lib (#20) 2017-01-04 12:41:33 +05:00
Aleksey Katargin b9aa9c156a fix for HookedNtUserBlockInput (#15) 2016-11-09 18:04:08 +01:00
Aleksey Katargin 2aab7f2cf0 improve win10 wow64 support (#10)
* remove useless size check of struct HOOK_DLL

* improved win10 wow64 support
2016-11-06 17:37:55 +01:00
Matthijs Lavrijsen 761f48a08c Make the ProcessInformation reported in the hooked NtQueryInformationProcess consistent with the the real NtQueryInformationProcess which is affected by the process debug inherit flag (#8)
Add ProcessInformationClass == ProcessDebugFlags to the NtSetInformationProcess hook so that the process debug inherit flag can't actually be modified, and keep track of the fake flags to report the right value in NtQIP
2016-10-26 17:59:21 +02:00