Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NtSetDebugFilterState anti-debug #3

Open
mrexodia opened this issue Mar 26, 2014 · 5 comments
Open

NtSetDebugFilterState anti-debug #3

mrexodia opened this issue Mar 26, 2014 · 5 comments

Comments

@mrexodia
Copy link
Owner

Originally reported by: Duncan (Bitbucket: mrexodia, GitHub: mrexodia)


see attached file for more information


@Mattiwatti
Copy link
Collaborator

Hello 5 year old issue...

I thought I'd add this feature since it's pretty simple, but then after looking at the ScyllaHide source I came to the conclusion that the hook as is in ScyllaHide is essentially useless since it is a subset of the remove debug privileges option.

There are two possible scenarios:

  • The process has debug privileges. In this case a call to NtSetDebugFilterState returns success.
  • The process doesn't have debug privileges. In this case a call to NtSetDebugFilterState returns STATUS_ACCESS_DENIED.

The anti-debug 'trick' is to call NtSetDebugFilterState, and if it succeeds, you know that you have debug privileges, which isn't the same thing as knowing if you're being debugged. But you can also just query your process token and find out if you have debug privileges. So the 'naive' hook (return STATUS_ACCESS_DENIED) would actually make it possible to detect TH by enabling debug privileges and seeing the incorrect return value, and this used to be true for SH too.

SH does this a bit better now because I fixed this a while ago, but it makes the hook basically useless since it just returns what the kernel would have returned anyway. The real problem is a process having debug privileges when it shouldn't. So should we add an option for that instead?

@mrexodia
Copy link
Owner Author

mrexodia commented Mar 10, 2019 via email

@Mattiwatti
Copy link
Collaborator

Not in x64dbg, no. Some other debuggers I tried (VS2017 and WinDbg) do let the process inherit debug privileges. So there is a point to be made for just calling it a bug in the debugger 😛 To be fair inheriting enabled process privileges is the default Windows behaviour I think.

@mrexodia
Copy link
Owner Author

mrexodia commented Mar 10, 2019 via email

@Mattiwatti
Copy link
Collaborator

Yeah. You don't actually need to be in the process address space to do it from kernel mode, so it could be applied without having to KeStackAttachProcess or wait for the process to set off some hook. It's basically PsReferencePrimaryToken with the EPROCESS to get its PACCESS_TOKEN, ObOpenObjectByPointer that to convert it to a handle, dereference object, NtAdjustPrivilegesToken on the handle to set the desired privileges, close handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants