Spoofed SEC Emails Distribute Evolved DNSMessenger

ID TALOSBLOG:757077764FA7A1207F7E65D0F0E72DC3
Type talosblog
Reporter noreply@blogger.com (Edmund Brumaghin)
Modified 2017-10-16T11:47:06


<i>This post was authored by <a href="https://www.blogger.com/profile/10442669663667294759">Edmund Brumaghin</a>, <a href="https://twitter.com/ColinGrady">Colin Grady</a>, with contributions from <a href="https://twitter.com/Dave_Maynor">Dave Maynor</a> and <a href="https://twitter.com/Simpo13">@Simpo13</a>.</i><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-v5hP5QTDQxc/Wd5SOUdvcmI/AAAAAAAABZk/7Sv3k1iPyHQ1X02LBxPwsVxGfH-X35TYgCPcBGAYYCw/s1600/DNS_MessengerMalware2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="889" data-original-width="1600" height="354" src="https://2.bp.blogspot.com/-v5hP5QTDQxc/Wd5SOUdvcmI/AAAAAAAABZk/7Sv3k1iPyHQ1X02LBxPwsVxGfH-X35TYgCPcBGAYYCw/s640/DNS_MessengerMalware2.jpg" width="640" /></a></div><br /><h2 id="h.cru86zvioxhu">Executive Summary</h2><br />Cisco Talos previously published <a href="http://blog.talosintelligence.com/2017/03/dnsmessenger.html">research</a> into a targeted attack that leveraged an interesting infection process using DNS TXT records to create a bidirectional command and control (C2) channel. Using this channel, the attackers were able to directly interact with the Windows Command Processor using the contents of DNS TXT record queries and the associated responses generated on the attacker-controlled DNS server. <br /><br />We have since observed additional attacks leveraging this type of malware attempting to infect several target organizations. These attacks began with a targeted spear phishing email to initiate the malware infections and also leveraged compromised U.S. state government servers to host malicious code used in later stages of the malware infection chain. The spear phishing emails were spoofed to make them appear as if they were sent by the Securities and Exchange Commission (SEC) in an attempt to add a level of legitimacy and convince users to open them. The organizations targeted in this latest malware campaign were similar to those targeted during previous DNSMessenger campaigns. These attacks were highly targeted in nature, the use of obfuscation as well as the presence of a complex multi-stage infection process indicates that this is a sophisticated and highly motivated threat actor that is continuing to operate. <br /><a name='more'></a><br /><h2 id="h.q5wi2bt5bav0">Technical Details</h2><br />The emails associated with this malware campaign were spoofed to make them appear as if they had originated from the Securities and Exchange Commission (SEC) Electronic Data Gathering, Analysis, and Retrieval (EDGAR) system. For those not familiar with this system, EDGAR is an automated filing platform that organizations can use to submit filings which are legally required to be performed by publicly traded companies. This was likely done to increase the perceived legitimacy of the emails and increase the chances that the recipient would open the email and associated attachments. <br /><div class="separator" style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-sC3keQCmpio/Wd4_T0urIGI/AAAAAAAAAZ0/WkVFAtNiVbMA56m1lERGkpD9ZtMCwS3GwCLcBGAs/s1600/image4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="284" data-original-width="1347" height="134" src="https://2.bp.blogspot.com/-sC3keQCmpio/Wd4_T0urIGI/AAAAAAAAAZ0/WkVFAtNiVbMA56m1lERGkpD9ZtMCwS3GwCLcBGAs/s640/image4.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 1: Example Malicious Email</b></div><br />The emails themselves contained a malicious attachment that when opened would initiate a sophisticated multi-stage infection process leading to infection with DNSMessenger malware. The malicious attachments were Microsoft Word documents. Rather than leveraging macros or OLE objects, which are some of the most common ways that Microsoft Word documents are leveraged to execute code, these attachments leveraged Dynamic Data Exchange (DDE) to perform code execution. A description of this technique has been published <a href="https://sensepost.com/blog/2017/macro-less-code-exec-in-msword/">here</a>. This technique has recently been publicized following a Microsoft decision that this functionality is a feature by design and will not be removed. We are now seeing it actively being used by attackers in the wild, as demonstrated in this attack.<br /><br />Similar to the emails described above, the malicious attachments were made to appear as if they had originated from the SEC and include logos and branding as well as information that would be expected from any documents received from the SEC. When opened, victims would be greeted with a message informing them that the document contains links to external files, and asking them to allow/deny the content to be retrieved and displayed.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-I8SXrvUn1dA/Wd4_dIp41yI/AAAAAAAAAZ4/syx4SpWJ0i8sBzdO80HddHlar_gOTfsBwCLcBGAs/s1600/image2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="210" data-original-width="892" height="148" src="https://2.bp.blogspot.com/-I8SXrvUn1dA/Wd4_dIp41yI/AAAAAAAAAZ4/syx4SpWJ0i8sBzdO80HddHlar_gOTfsBwCLcBGAs/s640/image2.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 2: DDE Message Prompt</b></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-aejetHABA/Wd4_jmek8oI/AAAAAAAAAZ8/kny1Re5F1VgMM6IrGdfUAPsDzzsTmBVRQCLcBGAs/s1600/image7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="991" data-original-width="1437" height="440" src="https://4.bp.blogspot.com/-aejetHABA/Wd4_jmek8oI/AAAAAAAAAZ8/kny1Re5F1VgMM6IrGdfUAPsDzzsTmBVRQCLcBGAs/s640/image7.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 3: Example Malicious Document</b></div><br />In the case of this attack, if the user allows the external content to be retrieved, the malicious document will reach out to attacker hosted content to retrieve code that will be executed to initiate the malware infection. Interestingly, the DDEAUTO field used by this malicious document retrieved code that the attacker had initially hosted on a Louisiana state government website, which was seemingly compromised and used for this purpose. The DDEAUTO command that is executed is below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-3hzODR7AUWQ/Wd4_qHMAJ0I/AAAAAAAAAaA/9jHAdz2gn7Eu10JfYVH2FSJ9vu8R4-sSgCLcBGAs/s1600/image9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="45" data-original-width="762" height="36" src="https://1.bp.blogspot.com/-3hzODR7AUWQ/Wd4_qHMAJ0I/AAAAAAAAAaA/9jHAdz2gn7Eu10JfYVH2FSJ9vu8R4-sSgCLcBGAs/s640/image9.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 4: DDE Code Retrieval Command</b></div><br />The aforementioned command results in the code hosted at the referenced URL to be downloaded and executed directly using Powershell. The contents of the code that is retrieved from the server is Powershell code and includes a code blob that is both Base64 encoded and gzipped. The code is retrieved, deobfuscated, then passed to the Invoke-Expression (IEX) cmdlet and executed by Powershell.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-J6KIDlZSNWI/Wd4_w8PNxDI/AAAAAAAAAaE/SpVRs-Fay1IRc5hLjlrf3v9cg59m3sHyACLcBGAs/s1600/image3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="78" data-original-width="1105" height="44" src="https://2.bp.blogspot.com/-J6KIDlZSNWI/Wd4_w8PNxDI/AAAAAAAAAaE/SpVRs-Fay1IRc5hLjlrf3v9cg59m3sHyACLcBGAs/s640/image3.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 5: Stage 1 Code</b></div><br />The deobfuscated code is responsible for staging and kicking off subsequent stages of the infection process. It is also responsible for achieving persistence on systems. The code features a number of ways that persistence may be achieved depending on the operating environment of the malware. It determines the version of Powershell on the infected system as well as the access privileges of the user to determine how to proceed with achieving this persistence.<br /><br />First, a blob of code called $ServiceCode, which is also both base64 encoded and compressed using gzip, is written to the Windows registry using the following Powershell command:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-6lAEXvGsGxU/Wd4_2wT8R7I/AAAAAAAAAaI/PnaHNhVemvMOZdU1S2eX5mK-ya9d-Y6-wCLcBGAs/s1600/image11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="29" data-original-width="885" height="20" src="https://1.bp.blogspot.com/-6lAEXvGsGxU/Wd4_2wT8R7I/AAAAAAAAAaI/PnaHNhVemvMOZdU1S2eX5mK-ya9d-Y6-wCLcBGAs/s640/image11.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 6: Registry Creation</b></div><br />A second block of code present in the Powershell is called $stagerCode and is responsible for extracting and decoding the code that was previously stored in the registry, then executing this code, first checking for the presence of the mutex '1823821749'. If this mutex does not exist, execution continues.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://3.bp.blogspot.com/-PfGg1Aqwdj0/Wd4_97lnA0I/AAAAAAAAAaQ/4tg0SwjbTn86uAEcV1ReyUy3f5yQUBBrwCLcBGAs/s1600/image1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="71" data-original-width="1084" height="40" src="https://3.bp.blogspot.com/-PfGg1Aqwdj0/Wd4_97lnA0I/AAAAAAAAAaQ/4tg0SwjbTn86uAEcV1ReyUy3f5yQUBBrwCLcBGAs/s640/image1.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 7: Mutex Check and Execution</b></div><br />The malware then attempts to write the contents of $stagerCode along with the appropriate PowerShell command to execute it to the following registry locations, creating a new registry key called "IE"<br /><ul><li>HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run</li><li>HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce </li><li>HKLM:\Software\Microsoft\Windows\CurrentVersion\RunServices</li><li>HKCU:\Software\Microsoft\Windows\CurrentVersion</li><li>HKEY_USERS.Default\Software\Microsoft\Windows\CurrentVersion\Run</li><li>HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon</li><li>HKLM:\System\CurrentControlSet\Services\VxD</li><li>HKCR:\vbsfile\shell\open\command</li></ul><div class="separator" style="clear: both; text-align: center;"><a href="https://3.bp.blogspot.com/-7vz1M1nzSQg/Wd5AKknU06I/AAAAAAAAAaU/Wz_EX4i-osEdHZuB9JkIrImiZikEUCSaQCLcBGAs/s1600/image8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="628" data-original-width="1095" height="366" src="https://3.bp.blogspot.com/-7vz1M1nzSQg/Wd5AKknU06I/AAAAAAAAAaU/Wz_EX4i-osEdHZuB9JkIrImiZikEUCSaQCLcBGAs/s640/image8.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 8: Registry Activity</b></div><br />The malware also creates a new scheduled task called "IE" that is responsible for executing $stagerCode each time the system boots, using a random startup delay period.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-QbWPfhsExr0/Wd5ARILC28I/AAAAAAAAAaY/RDrDBt4lytQwlxWU0dFYDy3hFzlZqFWAQCLcBGAs/s1600/image5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="322" data-original-width="1042" height="196" src="https://1.bp.blogspot.com/-QbWPfhsExr0/Wd5ARILC28I/AAAAAAAAAaY/RDrDBt4lytQwlxWU0dFYDy3hFzlZqFWAQCLcBGAs/s640/image5.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 9: Scheduled Task Creation</b></div><br />The malware then queries the system to determine the characteristics of the environment in which it is operating to determine how to proceed. It specifically checks the version of Powershell that is installed on the system. If the system is running a Powershell version later than Powershell 2.0, the malware will write the contents of $ServiceCode to an Alternate Data Stream (ADS) of the the following file location:<br /><br />        <i>%PROGRAMDATA%\Windows:kernel32.dl</i>l<br /><br />The malware then checks to determine the privilege level of the user that was infected. If the user has administrative privileges on the infected system, it will set up a WMI event consumer and filter as an additional WMI-based persistence mechanism. The filter name is "kernel32_filter" and the consumer name is "kernel32_consumer". The Powershell code used for the performance of these tasks is below:<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://4.bp.blogspot.com/-M7I_j3ZrBK8/Wd5AapiGmcI/AAAAAAAAAac/MqXdTWr74r0dGDXs_Pfa9KgPy46LWJEtgCLcBGAs/s1600/image6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="554" data-original-width="1094" height="324" src="https://4.bp.blogspot.com/-M7I_j3ZrBK8/Wd5AapiGmcI/AAAAAAAAAac/MqXdTWr74r0dGDXs_Pfa9KgPy46LWJEtgCLcBGAs/s640/image6.png" width="640" /></a></div><div style="text-align: center;"><b>Figure 10: ADS and WMI Persistence</b></div><br />Once all of these tasks have completed, the malware then enters the next stage of the infection process by executing $stagerCode directly using the IEX Powershell cmdlet.<br /><br />This next stage of the malware infection was heavily obfuscated with both variables and function names obscured. Most of the strings within this code were also base64 encoded. The code associated with this stage starts by defining an array containing a list of domains that will be used for subsequent Command and Control (C2) communications. A list of the domains in this array is included in the Indicators of Compromise section of this blog.<br /><br />The malware also obtains the serial number of the system from the BIOS. It calculates the MD5 hash of the serial number and returns the first ten bytes.<br /><br /><ul><li><i><b>Example S/N:</b> VMware-56 4d 64 66 d0 7d f4 26-2c ad a5 8b f8 51 26 f8</i></li><i></i><li><i><b>Resulting Value:</b> EFA29DD310</i></li></ul><br />The malware then sets a counter value to zero. The aforementioned hash value, the hardcoded string "stage", the value of the counter, and a randomly selected domain from the array are then combined to create the initial hostname that will be used by the malware to start making DNS requests.<br /><br /><ul><li><i><b>Example Hostname:</b> EFA29DD310.stage.0.ns0.pw</i></li></ul><br />At this point the malware enters a loop which will continue until it receives an A record lookup result of or any lookup fails entirely. The A record result represents a checksum value, which will be explained below. The IPv4 value returned by the DNS server in response to the A record request is then converted to an integer, then a binary number.<br /><br /><ul><li><i><b>Example IP:</b></i></li><i></i><li><i><b>Integer Value:</b> 1798464372</i></li><i></i><li><i><b>Binary:</b> 1101011001100100110001101110100</i></li></ul><br />The same generated hostname is then used by the malware to make a TXT record request. The result of the TXT record query is then used to calculate an MD5 hash and the first eight bytes of the MD5 hash are then run through a checksum algorithm that returns an integer value which is converted into a binary number.<br /><br /><ul><li><b><i>Example TXT Query Result:</i></b></li></ul><pre>H4sIAIia3VkC/909a1fbSJafyTn5DxXhbkvYEpg8pgcjpnnkwXQgLNCTnnG8HdkqQGBLjiRDCPE5+x/2H+4v2XvrpdLLmE7m9J6lZ8BWVd133br3VpWyTE4vgoQkdJgGUUiSi2g68smAkmg8DlLqEy8hQUqgyySmCQ3hY0hOUu+cxo8fLRP3e/48ftTwo7EXhAlxyc+mESZrzuTGaLMPCVAjP068ofx8QweqpeMgjYn4rLesay1PM1BPNV</pre><ul><li><b>MD5:</b> 432B4077F72EE96CA70B57F10B68F35E</li><li><b>Selected Bytes:</b> 432B4077</li><li><b>Checksum:</b> 1126908023</li><li><b>Binary: </b>1000011001010110100000001110111</li></ul><br />Once the malware has both the binary values from the A record response and the above checksum calculation, they are compared. If the A record response and the TXT record response match, the result of the TXT record query response is appended to the end of a final resulting string, a new domain is then randomly selected from the array and the counter value previously mentioned, and included in the hostname used for queries, is incremented by one. If they don't match, the queries continue in kind until they do.<br /><br />This process continues until the result of the A record lookup is, which indicates a completion of the code collection via DNS, at which time the resulting string is returned for further processing. This result string is then decoded using Base64 and decompressed using gzip. It is then passed to the Powershell IEX cmdlet to execute the code that was retrieved using DNS.<br /><br />During analysis of this specific attack, we were unable to obtain this next stage of Powershell code from the C2 servers. Given the targeted nature of this attack it is likely that the attacker is restricting these communications in an attempt to evade analysis by information security companies and researchers. It's been reported that the stage 4 payload is documented <a href="https://wraithhacker.com/2017/10/11/more-info-on-evolved-dnsmessenger/" target="_blank">here</a>.<br /><br /><h2 id="h.5qdknn4alh9g">Conclusion</h2><h2 id="h.5qdknn4alh9g"> </h2>This attack shows the level of sophistication that is associated with threats facing organizations today. Attackers often employ multiple layers of obfuscation in an attempt to make analysis more difficult, evade detection and prevention capabilities, and continue to operate under the radar by limiting their attacks to only the organizations that they are targeting. It is also important for organizations to be aware of some of the more interesting techniques that malware is using to execute malicious code on systems and gain persistence on systems once they are infected. In this particular case, the malware featured the capability to leverage WMI, ADS, scheduled tasks, as well as registry keys to obtain persistence. The use of DNS as a conveyance for later stage code and C2 communications is also becoming more and more commonplace. Talos continues to monitor the threat landscape for unique and targeted attacks such as this one so that customers remain protected as attackers change the techniques they use to perform their malicious activities.<br /><br /><h2 id="h.drge4tmja5at">Coverage</h2><br />Additional ways our customers can detect and block this threat are listed below.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://3.bp.blogspot.com/-Z7N_NdAXg5w/Wd5A326hmcI/AAAAAAAAAag/Hei3WfxVMeU6-7g_SRAoSjyoAn8q1wHIwCLcBGAs/s1600/image10.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="268" data-original-width="320" src="https://3.bp.blogspot.com/-Z7N_NdAXg5w/Wd5A326hmcI/AAAAAAAAAag/Hei3WfxVMeU6-7g_SRAoSjyoAn8q1wHIwCLcBGAs/s1600/image10.png" /></a></div>Advanced Malware Protection (<a href="https://www.cisco.com/c/en/us/products/security/advanced-malware-protection">AMP</a>) is ideally suited to prevent the execution of the malware used by these threat actors.<br /><br /><a href="https://www.cisco.com/c/en/us/products/security/cloud-web-security/index.html">CWS</a> or<a href="https://www.cisco.com/c/en/us/products/security/web-security-appliance/index.html"> WSA</a> web scanning prevents access to malicious websites and detects malware used in these attacks.<br /><br /><a href="https://www.cisco.com/c/en/us/products/security/email-security-appliance/index.html">Email Security</a> can block malicious emails sent by threat actors as part of their campaign.<br /><br />Network Security appliances such as<a href="https://www.cisco.com/c/en/us/products/security/firewalls/index.html"> </a><a href="https://www.cisco.com/c/en/us/products/security/firewalls/index.html">NGFW</a>,<a href="https://www.cisco.com/c/en/us/products/security/intrusion-prevention-system-ips/index.html"> </a><a href="https://www.cisco.com/c/en/us/products/security/intrusion-prevention-system-ips/index.html">NGIPS</a>, and<a href="https://meraki.cisco.com/products/appliances"> </a><a href="https://meraki.cisco.com/products/appliances">Meraki MX</a> can detect malicious activity associated with this threat.<br /><br /><a href="https://www.cisco.com/c/en/us/solutions/enterprise-networks/amp-threat-grid/index.html">AMP Threat Grid</a> helps identify malicious binaries and build protection into all Cisco Security products.<br /><br /><a href="https://umbrella.cisco.com/">Umbrella</a>, our secure internet gateway (SIG), blocks users from connecting to malicious domains, IPs, and URLs, whether users are on or off the corporate network.<br /><br />Open Source Snort Subscriber Rule Set customers can stay up to date by downloading the latest rule pack available for purchase on <a href="https://www.snort.org/products">Snort.org</a>.<br /><br /><h2 id="h.690931o0tz4r">Indicators of Compromise (IOCs)</h2><br />The following Indicators of Compromise (IOCs) are associated with the attack described in this blog post.<br /><h3 id="h.7zvc4ji96iz7">Malicious Word Documents:</h3>1a1294fce91af3f7e7691f8307d07aebd4636402e4e6a244faac5ac9b36f8428<br />bf38288956449bb120bae525b6632f0294d25593da8938bbe79849d6defed5cb<br /><h3 id="h.hnnb5qyz3xvu">Stage 2 PowerShell</h3>8c5209671c9d4f0928f1ae253c40ce7515d220186bb4a97cbaf6c25bd3be53cf<br />ec3aee4e579e0d1db922252f9a15f1208c4f9ac03bd996af4884725a96a3fdf6<br /><h3 id="h.16wjq51avjof">Domains:</h3>trt[.]doe[.]louisiana[.]gov<br />ns0[.]pw<br />ns0[.]site<br />ns0[.]space<br />ns0[.]website<br />ns1[.]press<br />ns1[.]website<br />ns2[.]press<br />ns3[.]site<br />ns3[.]space<br />ns4[.]site<br />ns4[.]space<br />ns5[.]biz<br />ns5[.]online<br />ns5[.]pw<br /><h3 id="h.ldcn43blwnqu">IP Addresses:</h3>206[.]218[.]181[.]46<br /><br /><div class="feedflare"> <a href="http://feeds.feedburner.com/~ff/feedburner/Talos?a=xtHd2BrjDKk:bj1GRHddsic:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/feedburner/Talos?d=yIl2AUoC8zA" border="0"></img></a> </div><img src="http://feeds.feedburner.com/~r/feedburner/Talos/~4/xtHd2BrjDKk" height="1" width="1" alt=""/>