donut: Generated shellcode does not work
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
- Windows 10.0.18362 N/A Build 18362
- .NET Framework installed on the host:
- v4.0.0.0
- v4.8.03752
- Anti-Virus: Windows Defender is installed by default, but all options have been disabled
- Donut: latest version built from master as of 03/23/2020
What did you try to do ?
Use donut.exe to generate a shellcode based on the DemoCreateProcess 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:
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes("path\to\loader.bin")) | clip
Finally, replaced the base64 string in the DonutTest project, line 13. Then, I compiled the DonutTest project, started a new notepad.exe process (pid 5824), and ran:
.\DonutTest.exe 5824
What did you expect ?
calc.exe should be running as a child of notepad.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 generated instance 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
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 15 (2 by maintainers)
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:
For what it’s worth, I’m having a similar problem. Using the
devbranch and the same .NET Assembly (DemoCreateProcess), generating shellcode on Windows works fine while shellcode generated on Linux crashes the host process.I have a very different version of mingw than @lesnuages , though.
Well I had the same issues using the generated shellcode from donut on Linux, if that ever helps.