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

Bug fixes and new checks in ThreadHideFromDebugger. #235

Merged
merged 1 commit into from
Jun 10, 2021

Conversation

gsuberland
Copy link
Collaborator

Previously we were using BOOL for the hidden thread flag, but that's typedef int which is 4 bytes. This query call expects a 1-byte bool instead, so the NtQueryInformationThread call would always fail with a length mismatch. Due to the logic in the function, this resulted in silently returning no detection.

One important detail of note is that because bool is a single byte local variable, it is free to be allocated anywhere and isn't necessarily aligned. This commit introduces an AlignedBool struct that uses the alignas keyword to get around this issue.

Three new checks are added in this commit:

The first check detects if a length mismatch status is returned for legitimate calls, which might happen if someone writes a buggy hook that incorrectly assumes a BOOL is passed rather than a bool.

The second check detects if a length mismatch status is not returned when a BOOL is passed, which is likely to happen if someone writes a buggy hook that doesn't check the input length properly.

The third check detects if misaligned ThreadInformation pointers are properly rejected. This is not something a hook is likely to properly check for, so it's a good way to catch them out.

This resolves #230.

Previously we were using BOOL for the hidden thread flag, but that's typedef int which is 4 bytes. This query call expects a 1-byte bool instead, so the NtQueryInformationThread call would always fail with a length mismatch. Due to the logic in the function, this resulted in silently returning no detection.

One important detail of note is that because bool is a single byte local variable, it is free to be allocated anywhere and isn't necessarily aligned. This commit introduces an AlignedBool struct that uses the alignas keyword to get around this issue.

Three new checks are added in this commit:

The first check detects if a length mismatch status is returned for legitimate calls, which might happen if someone writes a buggy hook that incorrectly assumes a BOOL is passed rather than a bool.

The second check detects if a length mismatch status is not returned when a BOOL is passed, which is likely to happen if someone writes a buggy hook that doesn't check the input length properly.

The third check detects if misaligned ThreadInformation pointers are properly rejected. This is not something a hook is likely to properly check for, so it's a good way to catch them out.

This resolves #230.
@gsuberland gsuberland merged commit 8779645 into master Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant