-
Notifications
You must be signed in to change notification settings - Fork 444
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
Generated shellcode is executable but not runnable with runshc64 #38
Comments
To follow up, I found a solution that I think confirms my suspicion. The default rust toolchain uses Visual Studio build tools (MSVC), switching to the gnu build tools fixes the issues I was coming across. Just run "rustup toolchain install stable-x86_64-pc-windows-gnu" then set it to your default with "rustup default stable-gnu". Testing further on the MSVC toolchain, even the simplest println!("Hello world") doesn't work with pe2shc.exe / runshc64.exe. I will test further with side by side with a debugger injecting into notepad.exe to see what the cause of the crash is! |
@Path-17 : I did some quick tests today, and it seems to me that the problem lies in the TLS. This is at RVA = So it seems that the value couldn't be fetched from the TLS. Another check I did, by tracing the original application vs the shellcodified version vs the original one with TLS removed. Those are the results (fragments of the tracelogs). Shellcodified:
Original:
Original with TLS directory removed:
We can see that the shellcodified version, and the version with TLS directory removed failed at the same point of execution. So there is a strong clue that inability to properly execute TLS caused the issue. Although pe_to_shellcode supports TLS in a way, but it is a very simplified version. The TLS is called only once, before the Entry Point is executed. This may not be enough in some cases. But implementing a proper TLS support is beyond the scope of this small loader, because it would require hooking of functions. If it is possible, I would recommend you to try compiling it with TLS disabled. Maybe the GNU compiler already did it, and that helped? Please let me know your thoughts. |
As far as I can tell there is no way to fully disable TLS with rust's compiler, I haven't found any flags for it. I guess it is just a quirk of the implementation between GNU and MSVC that made the difference! Thank you for your detailed explanation and work on this, I learned a lot from your explanation above :) |
Hi, I am running into some issues generating shellcode from my rust binary.
It works when run in a copy of the same process using a built-in shellcode runner command (VirtualAlloc, CreateThread), but when executed in the context of another process, either injected or using runshc64, it does not work.
I am thinking that it could be some kind of pre-main entrypoint that is relying on the current process' environment but I cannot figure out how to skip over it the past few days.
Have you run into this before?
For context the raw code can be found here https://github.com/Path-17/diet-c2/tree/main/implants/implant-v2/src
Thank you! I attached a copy of the executable (not the output of pe2shc.exe) as well
implant-v2.zip
The text was updated successfully, but these errors were encountered: