-
Notifications
You must be signed in to change notification settings - Fork 636
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 does not work #45
Comments
Thanks for the issue. Will test and see if I can reproduce. |
For what it's worth, I used the same options and file, then injected loader.bin into notepad. Two instances of calc.exe were created, so I'm not sure what the problem is. EDIT: Did you build from master yourself? Did you use MSVC 2019 for this? |
I built from master on Linux, using Here's the version I have
|
Any chance you can attach loader.bin generated with DemoCreateProcess.dll ? |
Sure, here you go: |
It's some problem related to compiling with MingW that I haven't noticed before. Looking into it. |
Well I had the same issues using the generated shellcode from donut on Linux, if that ever helps. |
For what it's worth, I'm having a similar problem. Using the I have a very different version of mingw than @lesnuages , though.
|
I'm not sure what the problem is at the moment. This is what I have on Debian, installed from packages.
It works fine with my version of MingW, so I'm wondering about the build of GCC you both have installed. Was it built from source/repo? When I debugged the loader uploaded by @lesnuages RtlInitUnicodeString was initialized instead of RtlExitUserProcess. That leads me to think it's related to the size of ULONG_PTR or..the structure is not aligned by 8 bytes even though -fpack-struct=8 is specified. len is defined as uint32_t at the start of the DONUT_INSTANCE structure in include/donut.h. What happens if you change this to uint64_t and recompile everything? I'll try getting the version you have installed. |
Try compiling and running this against the loader you generated. Here's what I get:
|
Here's the output of debugging your loader. First API should be VirtualAlloc. No problem there. Second should be VirtualFree No problem there either. The third API should be RtlExitUserProcess (B2038712DAAC1A44), but as you can see, the hash for RtlInitUnicodeString (2992de171f478173) is used instead. I have seen this kind of behavior in the past and it was usually the result of the donut generator and the loader using different structures. They were not in sync. That's what this looks like, but obviously that isn't the case here if you both experience the same problem. I'll try get my hands on the version of MingW you're using, but right now I've no solution. |
Thanks for the investigation @odzhan, I'll try to have a look this weekend. I'm compiling from a Fedora 31, gcc installed from the Fedora repos, version is:
MinGW is also installed from the Fedora repos. I'll test the |
Here you go:
|
I'm not sure if this is the same issue, but I am able to reproduce the GCC vs MinGW issue. In my case, the shellcode created with MinGW/Windows donut.exe works but the shellcode created with GCC/Linux donut fails. Generated via:
Build versions:
And here's the output to dumpcfg for both versions:
|
I suspect I am facing the same issue. From my naive attempt to debug it, I believe the problem is rooted in wrong offsets used in the generated shellcode. I was stepping through MainProc in x64dbg and noticed that some values (but not all) were not matching configuration. Few more bits of observation:
NOTE: I added Hopefully, it might give a clue where to look next.... I am out of ideas :) |
What's wrong ?
The generated
loader.bin
shellcode does not seem to work on a specific system configuration. It makes the host process crash when loaded.System configuration
What did you try to do ?
Use
donut.exe
to generate a shellcode based on theDemoCreateProcess
assembly with the following command:.\donut.exe -e 1 -b 1 -z 1 -c TestClass -m RunProcess -p "calc.exe calc.exe" C:\Users\lab\source\repos\donut\DemoCreateProcess\bin\Release\DemoCreateProcess.dll
Then converted the shellcode to a base64 string using the following powershell snippet:
Finally, replaced the base64 string in the
DonutTest
project, line 13. Then, I compiled theDonutTest
project, started a newnotepad.exe
process (pid 5824), and ran:What did you expect ?
calc.exe
should be running as a child ofnotepad.exe
(process 5824)What happened ?
The notepad process crashed.
More information
I initially had the issue with another assembly, and another shellcode injector, but even trying with the ones provided within the donut repo, I am able to reproduce this behavior. Building and using a debug version of donut results in the same behavior, although running
.\loader64.exe .\instance
on the generatedinstance
file works well. So my best guess would be that something is wrong in the loader embedded in the final shellcode, but I have honestly no clue about what.Here are the log files for the debug build:
https://gist.github.com/lesnuages/f27ef9b33676ac4f0e882c738ed0fb10
The text was updated successfully, but these errors were encountered: