

But if you properly set the memory protections for each section of Beacon, then calling VirtualQuery on the base address of Beacon will only return the size of the NT Header section, since it will have a different memory protection setting than the. So if Beacon is allocated entirely with RWX permissions then calling VirtualQuery twice works perfectly. When you call VirtualQuery on a region of memory, it will return results for all of the following pages in memory that share the same attributes (memory protection and page state). We need to account for the fact that Beacon might be loaded into memory in different ways that will break our VirtualQuery logic.
#RESUMES ACTORS ACCESS CODE#
If you’re unfamiliar with the internals of Beacon Object Files (BOFs), they’re essentially a way to write position independent code where Beacon handles loading and linking any dependencies. However, during normal BOF execution, Beacon is sitting in memory. This demonstrates that it is possible to have Beacon encrypted and sleeping during BOF execution.

As of Cobalt Strike 4.7, Sleep Mask is implemented as a BOF, which provides the operator with much more control over how Sleep Mask works.

This helps prevent detection by threat hunting tools or memory scanners that look for Beacon signatures or suspicious artifacts like unbacked executable memory. This can result in an EDR product finding your Beacon sitting in memory and killing the process.Ĭobalt Strike (somewhat) recently introduced the Sleep Mask functionality, which serves to hide Beacon in memory while it’s sleeping. While an initial beacon can go undetected, performing common post-exploitation activities from a Beacon Object File can trigger a memory scan of your process by EDR. You fire up your trusty BOF toolkit and watch the “last” timer tick up indefinitely. The hard part is over, time to do some post-exploitation. Picture this - you’re on a red team engagement and your phish went through, your initial access payload got past EDR, your beacon is now living in memory and calling back to you. In this post, we’ll review a simple technique that we’ve developed to encrypt Cobalt Strike’s Beacon in memory while executing BOFs to prevent a memory scan from detecting Beacon.
