-
Notifications
You must be signed in to change notification settings - Fork 443
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
access violation adding std #29
Comments
hi @phiber0 ! Please let me know if my binaries work for you. Also, please share the binaries from your builds, and I will check them. P.S. Although the |
Hi!, I have used your CMakeLists.txt to create my VS project and you are right, the dll is loaded if the compiled is set to 2019/2017, but crashed if we use 2015/2013. (tested on win10 and win7, same results). I have attached 4 compilations, one for each version if you can take a look. let me know if I can do anything else. Ps, SayGoodbye was in the original code, I just use it to have a place to insert the std::mutex to trigger the error. |
I see, you are right - the binaries created with the older Visual Studio indeed crash. I will check them in more details and let you know what I found. |
@phiber0 - I investigated it, and now I understand what causes it. The binaries compiled in older versions of Visual Studio have one more initialization function that they run in And the problem with that function is, that it makes use of the API function Due to the fact that the shellcodified PE is loaded manually, its base will not be retrieved. The function returns a NULL pointer, which will be further used as a base. And finally it causes exception: I tested it with a libPeConv-based manual loader, where I hooked the function This PoC confirms that this is where the problem is located. However, in the stub that I use in pe2shc, I don't want to use any function hooking, so I can't solve it the same way. PVOID NTAPI
RtlPcToFileHeader(IN PVOID PcValue,
PVOID* BaseOfImage)
{
PLIST_ENTRY ModuleListHead;
PLIST_ENTRY Entry;
PLDR_DATA_TABLE_ENTRY Module;
PVOID ImageBase = NULL;
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
if ((ULONG_PTR)PcValue >= (ULONG_PTR)Module->DllBase &&
(ULONG_PTR)PcValue < (ULONG_PTR)Module->DllBase + Module->SizeOfImage)
{
ImageBase = Module->DllBase;
break;
}
Entry = Entry->Flink;
}
RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
*BaseOfImage = ImageBase;
return ImageBase;
} It seems the only way to solve this would be to add the shellcode to the list of loaded modules. But doing so will make the injected shellcode to be less stealthy. I will probably make it optional. |
wow, you are amazing! I will wait for your pe2shc update!. this problem is also happening if you use ReflectiveDLLInjection so your solution could help a loot of people. thank you |
thank you! at least now we know the reason! but solving it seems not so easy as I thought earlier: I tried to add the shellcode to the list of the loaded modules, and it seemed to work fine (the module got added) - yet I was doing my experiments on Windows 10, and I ended up going down the function So, adding the module to the |
Hi hasherezade!
I have found a weird problem adding some std headers.
for example if you add < string > nothing happens and the dll is loaded 10/10 times, but if you add < thread > < mutex > or < condition_variable > the dll mostly crash before injection is complited. (works 1 of 10 times).
I have tested the dll compiled on VS 2013,2015 both /MT.
works just fine without < mutex >
basic dll code taked from ShellCodeRDI for testing.
can you share some light about this.
thank you!
edit: forgot to add my test steps.
The text was updated successfully, but these errors were encountered: