boku7 / BokuLoader

A proof-of-concept Cobalt Strike Reflective Loader which aims to recreate, integrate, and enhance Cobalt Strike's evasion features!
MIT License
1.26k stars 244 forks source link

fix some malleable C2 incompatibilities #10

Closed S4ntiagoP closed 2 years ago

S4ntiagoP commented 2 years ago

So I have been reading the UDRL documentation (about time, right?) and noticed that there are some edge cases we are not supporting.

changes:

Note that now all the behavior involving the headers is entirely defined in the Malleable C2, not by commenting or uncommenting a define in the code.
The syscalls and bypass options are still defined this way.

Also, we now compile all the possible combinations of flags and configs in the new dist folder and load the correct one by parsing the Malleable C2 config at runtime in the .cna file

Links:

Thanks to @vestjoe for beacon_health_check where I found the trick to read the Malleable C2 profile programatically šŸ˜„

boku7 commented 2 years ago

šŸ”„šŸ”„šŸ”„

vestjoe commented 2 years ago

Very nice !!!! This is a really good idea.

funnybananas commented 1 year ago

"If the Malleable C2 enables both sleep_mask and userwx, we now use RWX instead of RX (so that beacon doesn't crash)"

This seems related to an issue I've been having with the latest version. Seems that now, when sleep_mask and userwx are set to true, the beacon crashes when it attempts to mask itself (so right after callback).

Looks like this line forces memory protection of the loaded .text to RX, which causes beacon to crash if userwx and sleepmask are set to true in the C2 profile. Manually changing this line to PAGE_EXECUTE_READWRITE fixes the beacon crashing.

https://github.com/boku7/BokuLoader/blob/c6d67d66697f18cc3c143323f9e011161f804c3d/src/BokuLoader.c#L93

boku7 commented 1 year ago

I tested on CS 4.7.2 and with those options it works (at least in my test environment). Currently userwx is ignored by bokuloader. From my testing even though sleep mask is true, it is ignored by beacon. Previously we had different versions compiled which would be used for each case. I've moved it to one loader and have the aggressor script modifying the beacon. I will be releasing future versions which handle your specific configuration you mentioned. This will happen after the first blog post about UDRL I have scheduled for release. To avoid this issue with your setup, I recommend using the sleep mask kit with bokuloader. Specifically the src47 version with the Ekko implementation, as it can handle sleepmasking beacon when the .text section is RX.

boku7 commented 1 year ago

What you did with the memory as RWX in the code is a good patch for getting it to work with that config you want for now, until I release the version that can properly handle the RWX option from the C2 profile