-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix: Allows 64-bit processes to modify the import table of 32-bit processes. #161
base: main
Are you sure you want to change the base?
Conversation
influence function: DetourUpdateProcessWithDll/DetourUpdateProcessWithDllEx |
In fact, on a 64-bit system, 32-bit processes can also read and write the memory of 64-bit processes. Through the NtWow64WriteVirtualMemory64/NtWow64ReadVirtualMemory64/NtWow64QueryInformationProcess64 series of APIs, rundll32 and this direct memory read and write operation are all ways to access memory across processes. So you can also implement UpdateImports64 from a 32-bit process, if you want. |
This is not a documented API and may be changed in future versions. detours will automatically detect the size of IMAGE_NT_HEADERS(32/64), so this patch is not a problem. |
What I mean is that you tried to remove the use of rundll32 in this way, but you did not completely remove it. Presumably the official team knew that it can be done like this. Maybe considering the undocumented API, they decided to use rundll32. Realize reading and writing the memory of non-current architecture processes |
Its main modification is not DetourCreateProcessWithDll, but an improvement to DetourUpdateProcessWithDll/DetourUpdateProcessWithDllEx. |
DetourUpdateProcessWithDll/DetourUpdateProcessWithDllEx is just an internal call of DetourCreateProcessWithDll. |
Some third-party programs may directly call DetourUpdateProcessWithDll/DetourUpdateProcessWithDllEx, such as anti-virus software. |
After the process is started, it is useless to update its import table. |
e.g.: Set PsCreateProcessNotifyRoutine in the kernel, and then notify the user-level program. |
So since you have used the kernel-level modification, why not do the UpdateImports64 from 32bit process as well, so that the dependency on rundll32 is completely removed. Now you only remove one situation, which is incomplete. The kernel should It is easy to access the memory of a 32-bit process. |
Under normal circumstances, a 32-bit process cannot access the address space of a 64-bit process. On the contrary, 64-bit can easily access the 32-bit address space. Of course, there is an exception. The use of undocumented APIs is not reliable. Another reason is that the 32-bit operating system may not provide the Wow64 API you mentioned. Because the driver needs to notify the user-level program to do some related operations, and the kernel does not provide VirtualProtect-related APIs, you cannot safely modify the user-level memory protection. So for 64-bit processes you need to consider two cases, the child is 32-bit or 64-bit. |
32-bit systems do not have 64-bit processes at all, so there is no need to use these WOW64 API functions |
@number201724 can you rebase and add a test case to cover this scenario? (maybe in the new |
Rebase |
1 similar comment
Rebase |
It seems that the test is more troublesome, because I use the software that drives the notification application layer to call DetourUpdateProcessWithDll/DetourUpdateProcessWithDllEx, I did not test other cases. |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. |
Separately, please change to C++ template. |
Yes, |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. |
I added those NtWow64ReadVirtualMemory64 functions, way back when. Keep in mind, Detours does not patch IAT. |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. |
I think if it is modified as a C++ template, a lot of code needs to be modified. |
Allows 64bit process to inject 32bit DLLs into 32bit process.
Since the modification is IAT, it seems that there is no problem.