{"id":6327,"date":"2017-01-23T15:50:22","date_gmt":"2017-01-23T23:50:22","guid":{"rendered":"http:\/\/www.palada.net\/index.php\/2017\/01\/23\/news-165\/"},"modified":"2017-01-23T15:50:22","modified_gmt":"2017-01-23T23:50:22","slug":"news-165","status":"publish","type":"post","link":"http:\/\/www.palada.net\/index.php\/2017\/01\/23\/news-165\/","title":{"rendered":"Reverse engineering DUBNIUM \u2013Stage 2 payload analysis"},"content":{"rendered":"<p>Recently, we\u00a0blogged about the basic functionality and features of the DUBNIUM advanced persistent threat (APT) activity group Stage 1 binary and Adobe Flash exploit used during the December 2015 incident (<a href=\"https:\/\/blogs.technet.microsoft.com\/mmpc\/2016\/06\/09\/reverse-engineering-dubnium-2\/\">Part 1<\/a>, <a href=\"https:\/\/blogs.technet.microsoft.com\/mmpc\/2016\/06\/20\/reverse-engineering-dubniums-flash-targeting-exploit\/\">Part 2<\/a>).<\/p>\n<p>In this blog, we will go through the overall infection chain structure and the Stage 2 executable details. Stage 2 executables are the core of this activity groups\u2019 operation, as it is the final payload delivered to possible targets that matches its profile.<\/p>\n<h1>Infection chain overview<\/h1>\n<p>The picture below shows the overall infection chain we analyzed.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8095 size-full\" title=\"Flow chart describing how Dubnium is installed\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-1.png\" alt=\"Flow chart describing how Dubnium is installed\" width=\"683\" height=\"688\" \/><\/a><\/p>\n<p><em>Figure 1: Infection chain overview<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>In most cases, the daily operation of the DUBNIUM APT depends on social engineering through spear-phishing. They are observed to mainly rely on an .<em>LNK<\/em> file that has an icon that looks like a Microsoft Word file. If the victim clicks the file thinking it\u2019s a Microsoft Office Word file, it downloads a simple dropper that will download and execute next stage binary \u2013 which in this case, has the file name of <em>kernelol21.exe<\/em>.<\/p>\n<p>The Stage 1 binary extensively checks-up on the system for the existence of security products or usual analysis tools for the reverse engineers or security analysts. It will pass the client\u2019s IP address, hostname, MAC address, software profile information, and locale information to the download server. When the server thinks that the client matches profile for possible prospect, the next stage dropper will be downloaded.<\/p>\n<p>&nbsp;<\/p>\n<h2>Stage 0: Social Engineering vs. Exploits<\/h2>\n<p>In our previous blogs we described the Adobe Flash Exploit the malware recently used. In this blog we want to provide a brief overview of the social engineering method DUBNIUM uses for its daily infection operations. The activity group uses the .<em>LNK<\/em> file with an icon image of a Word document as one of its social engineering methods.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-2.png\" rel=\"attachment wp-att-8105\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8105 size-full\" title=\"Shortcut icon disguised as Word document\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-2.png\" alt=\"Shortcut icon disguised as Word document\" width=\"162\" height=\"86\" \/><\/a><\/p>\n<p><em>Figure 2<\/em><em>: Shortcut icon disguised as Word document<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The shortcut contains commands to download and execute the next level executable or script. Unsuspecting victims will double click this icon and will be unknowingly launching a PowerShell command.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-3.png\" rel=\"attachment wp-att-8115\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8115 size-full\" title=\"The commands in the shortcut\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-3.png\" alt=\"The commands in the shortcut\" width=\"363\" height=\"509\" \/><\/a><\/p>\n<p><em>Figure 3: The commands in the shortcut<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>For example, the following shows the script that downloads a binary and executes it on the target system using PowerShell.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-4.png\" rel=\"attachment wp-att-8125\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8125 size-full\" title=\"PowerShell script for downloading and execution of next stage binary\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-4.png\" alt=\"PowerShell script for downloading and execution of next stage binary\" width=\"697\" height=\"60\" \/><\/a><\/p>\n<p><em>Figure 4: PowerShell script for downloading and execution of next stage binary<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>To make the attack more benign, the dropper drops an Office Word document and displays it on the screen. One of the samples we saw had content similar to the following screenshot:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-5.png\" rel=\"attachment wp-att-8135\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8135 size-full\" title=\"Fake document contents - North Korean style language and mentions on North Korean leaders with New year\u2019s celebration\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-5.png\" alt=\"Fake document contents - North Korean style language and mentions on North Korean leaders with New year\u2019s celebration\" width=\"363\" height=\"507\" \/><\/a><\/p>\n<p><em>Figure 5: Fake document contents &#8211; North Korean style language and mentions on North Korean leaders with New year\u2019s celebration<\/em><\/p>\n<p>&nbsp;<\/p>\n<h1>Stage 2 infection process<\/h1>\n<p>Acquiring a Stage 2 binary is very difficult for the analysts because the download server is very selective upon the infection targets. The main direction of the infection strategy is not to infect as many as it can, instead it focuses on infecting targets that matches the desired profile, and avoids detection from security products. One very interesting fact is that the command and control (C2) server we have been observing didn\u2019t go down for months. Overall security product coverage on Stage 2 executables is very poor, and so the strategy with this activity group (with a very selective Stage 2 infection) appears to have been effective.<\/p>\n<p>The following diagram shows the transition from Stage 1 to Stage 2 through the downloaded binary.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-6.png\" rel=\"attachment wp-att-8145\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8145 size-full\" title=\"Stage 1 to 2 transition\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-6.png\" alt=\"Stage 1 to 2 transition\" width=\"697\" height=\"389\" \/><\/a><\/p>\n<p><em>Figure 6: Stage 1 to 2 transition<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The dropped binary (Dropper PE module) is never written to disk and directly injected to a new process created. In this case <em>plasrv.exe<\/em> is used, but the process name can actually vary each time. The dropper PE module will drop <em>kbkernelolUpd.dll<\/em> and <em>kernelol21.exe<\/em> (which happens to have the same name as the Stage 1 binary \u2013 but different contents). The dropper PE module will look for usual system processes, for example <em>dwm.exe<\/em> in this case, and will inject <em>kbkernelolUpd.dll<\/em>.<\/p>\n<p>This is the main C2 client that will communicate with the C2 server and process downloaded commands. It performs the extra work of creating a process of usual Windows binary under systems folder and injecting the <em>kernelol21.exe<\/em> binary into it. This is a process persistency module, which will re-inject <em>kbkernelolUpd.dll<\/em> if the process is killed for some reason. The <em>kbkernelolUpd.dll<\/em> module also constantly monitors the existence of the <em>kernelol21.exe<\/em> injected process and will re-launch and re-inject the module if the infected host process is killed. This makes a process persistency loop.<\/p>\n<p>The following screenshot shows the typical process tree when the Stage 2 infection happens. The <em>dwm.exe<\/em> and <em>cipher.exe<\/em> processes are infected with <em>kbkernelolUpd.dll <\/em>and<em> kernelol21.exe.<\/em><\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-7.png\" rel=\"attachment wp-att-8155\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8155 size-full\" title=\"Typical process list with Stage 2 infection\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-7.png\" alt=\"Typical process list with Stage 2 infection\" width=\"665\" height=\"46\" \/><\/a><\/p>\n<p><em>Figure 7 Typical process list with Stage 2 infection<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The persistency of whole infection is carried by the Windows logon key shown in the following picture.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-8.png\" rel=\"attachment wp-att-8156\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8156\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-8.png\" alt=\"kernelol21.exe load key\" width=\"885\" height=\"99\" \/><\/a><\/p>\n<p><em>Figure 8 kernelol21.exe load key<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The following table shows the infection targets used for each stage. All infection target process files are default Windows executables under the <em>system32<\/em> folder.<\/p>\n<table style=\"width: 70%;border: 0.5px\">\n<tbody>\n<tr style=\"border: 0.5px solid #70AD47;background: #70AD47;vertical-align: top\">\n<td style=\"color: #ffffff;font-weight: 600;font-size: 1.1em;border-bottom: 0.5px solid white;text-align: left;padding: 4px\"><strong>Components<\/strong><\/td>\n<td style=\"color: #ffffff;font-weight: 600;font-size: 1.1em;border-bottom: 0.5px solid white;text-align: left;padding: 4px\"><strong>Injection targets<\/strong><\/td>\n<td style=\"color: #ffffff;font-weight: 600;font-size: 1.1em;border-bottom: 0.5px solid white;text-align: left;padding: 4px\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr style=\"border: 0.5px solid #70AD47;background: #E2EFDA;vertical-align: top\">\n<td style=\"padding: 4px\">Stage 1 dropper PE module<\/td>\n<td style=\"padding: 4px\">\n<ul>\n<li><em>plasrv.exe<\/em><\/li>\n<li><em>wksprt.exe<\/em><\/li>\n<li><em>raserver.exe<\/em><\/li>\n<li><em>mshta.exe<\/em><\/li>\n<li><em>taskhost.exe<\/em><\/li>\n<li><em>dwm.exe<\/em><\/li>\n<li><em>sdiagnhost.exe<\/em><\/li>\n<li><em>winrshost.exe<\/em><\/li>\n<li><em>wsmprovhost.exe<\/em><\/li>\n<\/ul>\n<\/td>\n<td style=\"padding: 4px\">Creates new process<\/td>\n<\/tr>\n<tr style=\"border: 0.5px solid #70AD47;background: #E2EFDA;vertical-align: top\">\n<td style=\"padding: 4px\">Stage 2 <em>kbkernelolUpd.dll<\/em><\/td>\n<td style=\"padding: 4px\">\n<ul>\n<li><em>dwm.exe<\/em><\/li>\n<li><em>wuauclt.exe<\/em><\/li>\n<li><em>ctfmon.exe<\/em><\/li>\n<li><em>wscntfy.exe<\/em><\/li>\n<\/ul>\n<\/td>\n<td style=\"padding: 4px\">Injects into existing process<\/p>\n<p>If the process is killed, <em>svchost.exe<\/em> will be created by stage <em>kernelol21.exe<\/em>.<\/td>\n<\/tr>\n<tr style=\"border: 0.5px solid #70AD47;background: #E2EFDA;vertical-align: top\">\n<td style=\"padding: 4px\">Stage 2 <em>kernelol21.exe<\/em><\/td>\n<td style=\"padding: 4px\">\n<ul>\n<li><em>cipher.exe<\/em><\/li>\n<li><em>gpupdate.exe<\/em><\/li>\n<li><em>services.exe<\/em><\/li>\n<li><em>sppsvc.exe<\/em><\/li>\n<li><em>winrshost.exe<\/em><\/li>\n<\/ul>\n<\/td>\n<td style=\"padding: 4px\">Creates new process<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>Table 1<\/em><em>: DUBNIUM infection targets<\/em><\/p>\n<p>&nbsp;<\/p>\n<h1>Process image replacement technique<\/h1>\n<p>When the main C2 client module, <em>kbkernelolUpd.dll,<\/em> is injected, it uses <em>LoadLibrary<\/em> call that is initiated through <em>CreateRemoteThread<\/em> API. This is a very typical technique used by many malware.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-9.png\" rel=\"attachment wp-att-8165\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8165 size-full\" title=\"Injected LoadLibrary code\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-9.png\" alt=\"Injected LoadLibrary code\" width=\"622\" height=\"359\" \/><\/a><\/p>\n<p><em>Figure 9: Injected LoadLibrary code<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>But, for dropper PE module in Stage 1 and <em>kernelol21.exe<\/em> injection in Stage 2, it uses a process image replacement technique. It creates the usual Windows process, injects the PE module to this process, fabricates PEB information and modifies startup code to achieve process injection.<\/p>\n<p>&nbsp;<\/p>\n<h2>Writing PE Image<\/h2>\n<p>The technique starts with creating a process from the executable under Windows system folder. Table 1 shows each target processes the injection will be made into, depending on the stage and the binary. The process is created as suspended and modifications will be performed on the image. The first step is injecting the infection PE image upon the process. It uses <em>WriteProcessMemory<\/em> APIs.<\/p>\n<p>Figure 10 shows the code that injects the PE header, and Figure 11 shows the memory of the target process where the PE header is injected.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-10.png\" rel=\"attachment wp-att-8175\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8175 size-full\" title=\"Injecting PE header\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-10.png\" alt=\"Injecting PE header\" width=\"447\" height=\"191\" \/><\/a><\/p>\n<p><em>Figure 10<\/em><em>: Injecting PE header<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-11.png\" rel=\"attachment wp-att-8185\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8185 size-full\" title=\"PE header written on target process\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-11.png\" alt=\"PE header written on target process\" width=\"609\" height=\"118\" \/><\/a><\/p>\n<p><em>Figure 11<\/em><em> PE header written on target process<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>After the injection of PE header, it will go through each section of the source PE image and inject them one by one to the target process memory space.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-12.png\" rel=\"attachment wp-att-8195\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8195 size-full\" title=\"PE section injection\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-12.png\" alt=\"PE section injection\" width=\"525\" height=\"247\" \/><\/a><\/p>\n<p><em>Figure 12: PE section injection<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The injected PE module has dependencies on the hardcoded base and section addresses. If <em>VirtualAlloc<\/em> function upon the desired base or section addresses fails, the whole injection process will fail.<\/p>\n<p>&nbsp;<\/p>\n<h2>Acquiring context and PEB information<\/h2>\n<p>The next step of infection is using <em>GetThreadContext<\/em> API to retrieve current context of the target process.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-13.png\" rel=\"attachment wp-att-8205\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8205 size-full\" title=\"GetThreadContext\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-13.png\" alt=\"GetThreadContext\" width=\"668\" height=\"323\" \/><\/a><\/p>\n<p><em>Figure 13: GetThreadContext<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>One of the thread contexts retrieved is shown in the following image.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-14.png\" rel=\"attachment wp-att-8215\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8215 size-full\" title=\"Retrieved Context\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-14.png\" alt=\"Retrieved Context\" width=\"408\" height=\"363\" \/><\/a><\/p>\n<p><em>Figure 14: Retrieved Context<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>When the process is started as suspended, the <em>ebx<\/em> register is initialized with the pointer to PEB structure. The following shows the original PEB data from the target process. The <em>ImageBaseAddress<\/em> member is at offset of +8 and the value is 0x00e0000 in this case. This is the image base of the main module of the target process.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-15.png\" rel=\"attachment wp-att-8225\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8225 size-full\" title=\"Original PEB structure\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-15.png\" alt=\"Original PEB structure\" width=\"557\" height=\"265\" \/><\/a><\/p>\n<p><em>Figure 15: Original PEB structure<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>After retrieving the <em>PEB.ImageBaseAddress<\/em> from the target process (Figure 16), it will replace it with the base address of the injected module (Figure 17).<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-16.png\" rel=\"attachment wp-att-8235\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8235 size-full\" title=\"Reading PEB.ImageBaseAddress\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-16.png\" alt=\"Reading PEB.ImageBaseAddress\" width=\"685\" height=\"239\" \/><\/a><\/p>\n<p><em>Figure 16<\/em><em>: Reading PEB.ImageBaseAddress<\/em><\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-17.png\" rel=\"attachment wp-att-8245\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8245 size-full\" title=\"Overwriting PEB.ImageBaseAddress\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-17.png\" alt=\"Overwriting PEB.ImageBaseAddress\" width=\"590\" height=\"263\" \/><\/a><\/p>\n<p><em>Figure 17<\/em><em>: Overwriting PEB.ImageBaseAddress<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The <em>PEB.ImageBaseAddress<\/em> of the target process is replaced, as in the following figure, to point to the base address of the injected PE module.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-18.png\" rel=\"attachment wp-att-8255\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8255\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-18.png\" alt=\"Overwritten PEB.ImageBaseAddress\" width=\"565\" height=\"240\" \/><\/a><\/p>\n<p><em>Figure 18: Overwritten PEB.ImageBaseAddress<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2>Overwriting wmainCRTStartup<\/h2>\n<p>&nbsp;<\/p>\n<p>After overwriting PEB.ImageBaseAddress to an injected module\u2019s base address, the next step is patching <em>wmainCRTStartup<\/em> code from the original main module.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-19.png\" rel=\"attachment wp-att-8265\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8265 size-full\" title=\"wmainCRTStartup patch code\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-19.png\" alt=\"wmainCRTStartup patch code\" width=\"487\" height=\"251\" \/><\/a><\/p>\n<p><em>Figure 19: wmainCRTStartup patch code<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The following code shows original disassembly from <em>wmainCRTStartup<\/em> code.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-20.png\" rel=\"attachment wp-att-8275\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8275 size-full\" title=\"Original code\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-20.png\" alt=\"Original code\" width=\"584\" height=\"92\" \/><\/a><\/p>\n<p><em>Figure 20: Original code<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>After patch, it will just jump to the entry code of the injected module located at address of 0x4053d0, which is the entry point of the injected module. When <em>ResumeThread<\/em> is called upon this thread, it will start the main module from the injected module\u2019s entry code.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-21.png\" rel=\"attachment wp-att-8285\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8285 size-full\" title=\"Patched code\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-21.png\" alt=\"Patched code\" width=\"414\" height=\"105\" \/><\/a><\/p>\n<p><em>Figure 21: Patched code<\/em><\/p>\n<p>&nbsp;<\/p>\n<h1>Main C2 Client (<em>kbkernelolUpd.dll<\/em>)<\/h1>\n<p>As <em>kbkernelolUpd.dll<\/em> is the main module of the infection chain, we are going to focus on the analysis of this binary. As we stated before, the detection coverage and information on this specific component is limited in the security industry.<\/p>\n<p>&nbsp;<\/p>\n<p>The string for the C2 server hostname and URI is encoded in a configuration block inside the binary.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-22.png\" rel=\"attachment wp-att-8295\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8295 size-full\" title=\"C2 server string decoding\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-22.png\" alt=\"C2 server string decoding\" width=\"624\" height=\"226\" \/><\/a><\/p>\n<p><em>Figure 22: C2 server string decoding<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>From the following disassembly list, <em>get_command<\/em> uses <em>wininet.dll<\/em> APIs to send basic client information and to retrieve commands from the server. The <em>process_command<\/em> is the routine that will parse message and execute designated commands.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-23.png\" rel=\"attachment wp-att-8305\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8305 size-full\" title=\"C2 command fetch &amp; execution loop\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-23.png\" alt=\"C2 command fetch &amp; execution loop\" width=\"716\" height=\"701\" \/><\/a><\/p>\n<p><em>Figure 23: C2 command fetch &amp; execution loop<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Between each contact to the C2 server, there is a timeout. The timeout value is saved inside the encoded configuration block in the binary. For example, the sample we worked on had a 30-minute time out between each contact request to the server.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-24.png\" rel=\"attachment wp-att-8315\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8315 size-full\" title=\"Sleep interval between C2 accesses\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-24.png\" alt=\"Sleep interval between C2 accesses\" width=\"819\" height=\"171\" \/><\/a><\/p>\n<p><em>Figure 24: Sleep interval between C2 accesses<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2>Cryptographic C2 channel and message format<\/h2>\n<p>The following diagram shows the basic message format of the C2 server payload that is downloaded when the client contacts the server.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-25.png\" rel=\"attachment wp-att-8325\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8325 size-full\" title=\"Decrypting C2 message\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-25.png\" alt=\"Decrypting C2 message\" width=\"639\" height=\"489\" \/><\/a><\/p>\n<p><em>Figure 25<\/em><em>: Decrypting C2 message<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The message from the C2 server can be encoded in various ways. The first byte in the payload is the XOR key that is used to decode following bytes. The encryption type byte indicates what encryption algorithm is used in the code. It has three different encryption schemes (0x50, 0x58, 0x70) supported.<\/p>\n<p>From our static analysis, 0x58 is for AES 256 encryption algorithm, 0x70 and 0x50 are for 3DES 168 algorithm. If this type is 0x40, no encryption will be used and it looks like 0x50 and 0x58 encryption type is not fully implemented yet. So 0x70 encryption type with 3DES 168 algorithm is the only encryption type that is fully working here.<\/p>\n<p>The decryption scheme is using an embedded RSA private key with the decryption key embedded in the binary. By calling <em>CryptHashData<\/em> upon the embedded password string and using <em>CryptDeriveKey<\/em>, it will acquire a key to decrypt the encrypted RSA private key. (Figure 26)<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-26.png\" rel=\"attachment wp-att-8335\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8335 size-full\" title=\"Setting encryption key\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-26.png\" alt=\"Setting encryption key\" width=\"919\" height=\"622\" \/><\/a><\/p>\n<p><em>Figure 26<\/em><em>: Setting encryption key<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>This decryption key is used to import 0x258 bytes of private key embedded inside the binary. And this private key is used to decrypt the encrypted key (Key data 02 from Figure 25) passed through the response packet from the C2 server. Next, the IV (Initialization Vector) passed through the response packet is set as a parameter to the key object.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-27.png\" rel=\"attachment wp-att-8336\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8336 size-full\" title=\"Importing keys and IV\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-27.png\" alt=\"Importing keys and IV\" width=\"829\" height=\"686\" \/><\/a><\/p>\n<p><em>Figure 27: Importing keys and IV<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Finally, the actual decryption of the payload happens through <em>CryptDecrypt<\/em> API call. The question still remains why the C2 server and the client are using such an overcomplicated encryption scheme.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-28.png\" rel=\"attachment wp-att-8345\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8345 size-full\" title=\"Decrypting message\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-28.png\" alt=\"Decrypting message\" width=\"477\" height=\"348\" \/><\/a><\/p>\n<p><em>Figure 28: Decrypting message<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2>Command processor<\/h2>\n<p>The C2 command processor looks very typical. It has a simple packet parser for TLV (type, length, value) data structure. The following picture shows the main routine that processes packet length and types. It will call relevant functions for each packet type.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-29.png\" rel=\"attachment wp-att-8355\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8355 size-full\" title=\"Main command processor function\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-29.png\" alt=\"Main command processor function\" width=\"900\" height=\"481\" \/><\/a><\/p>\n<p><em>Figure 29<\/em><em>: Main command processor function<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Each command provides usual functionalities that are typically seen in backdoors. They include registry, file system manipulations, and searching files with specific patterns, and retrieving and transferring them back to the server and gathering network status information.<\/p>\n<h1>Infections statistics<\/h1>\n<p>The following chart shows the relative prevalence of the threat overall. We included Stage 1 and Stage 2 payload detections in this map.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-30.png\" rel=\"attachment wp-att-8365\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8365 size-full\" title=\"Infection distribution by countries\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/07\/dub3-30.png\" alt=\"Bar chart showing countries with most infections in China and Japan\" width=\"1002\" height=\"589\" \/><\/a><\/p>\n<p><em>Figure 30: Infection distribution by countries<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Most of the infections we saw focused on East Asia\u2014mostly China and Japan. We already described that the Stage 1 dropper collects and sends IP and language locale of the machines it infected to the Stage 2 dropper distribution site. We think this distribution site has a logic to determine whether to drop next payload or not.<\/p>\n<p>The Stage 1 dropper is also known to collect information on culture-specific software like messengers and security software mainly used in mainland China. If the distribution site doesn\u2019t push back Stage 2 payload, Stage 1 payload doesn\u2019t have any means of persistency at all. This means that with all the cost of infiltrating into the machine, the malware simply gives up the machine if the machine doesn\u2019t fit into its profile. Based upon the actual infection map and the behavior of this Stage 1 dropper, it might be a good indication that the activity group has a good geolocation preference with their targets.<\/p>\n<p>&nbsp;<\/p>\n<h1>Conclusion<\/h1>\n<p>DUBNIUM is a very cautious actor. From the vendor detections for Stage 2 binaries, we can see that there are no serious detections upon them in the industry. This is partially due to the strategy that DUBNIUM employs. It doesn\u2019t try to infect as many machines as possible, instead it will potentially expose important components, like C2 client modules, to unintended targets. The very long lifespan of the domain it controls and uses for C2 operation supports the story.<\/p>\n<p>Other features with DUBNIUM is that it uses encoding and encryption schemes over the executables and network protocols. Each stage has different styles of encoding and decoding schemes. Some are complicated and some are relatively simple. Stage 1 binaries have a stronger obfuscation and payload encoding scheme than Stage 2 binaries. The C2 server payload has its own format with encrypted message support.<\/p>\n<p>The other feature with DUBNIUM is that over each stages, it always checks the running environment. It focuses on security products and analyst tools on Stage 1, but it is very cautious on debugging tools on Stage 2 binaries. From Stage 1, it also collects extensive information on the client system including locale, IP and MAC address and they are sent to the Stage 2 distribution site. The distribution site also serves each client once based upon this information. Getting served on the next stage binary is sometimes very challenging as we don\u2019t know the backend algorithm behind to determine whether to serve the next stage binary or not.<\/p>\n<p>&nbsp;<\/p>\n<h1>Appendix \u2013 Indicators of Compromise<\/h1>\n<p>&nbsp;<\/p>\n<h2>Stage 0<\/h2>\n<h2>Adobe Flash Player Exploit<\/h2>\n<p>3eda34ed9b5781682bcf7d4ce644a5ee59818e15 SWF File<\/p>\n<p>&nbsp;<\/p>\n<h3>LNK<\/h3>\n<p>25897d6f5c15738203f96ae367d5bf0cefa16f53<\/p>\n<p>624ac24611ef4f6436fcc4db37a4ceadd421d911<\/p>\n<p>&nbsp;<\/p>\n<h3>Droppers<\/h3>\n<p>09b022ef88b825041b67da9c9a2588e962817f6d<\/p>\n<p>35847c56e3068a98cff85088005ba1a611b6261f<\/p>\n<p>7f9ecfc95462b5e01e233b64dcedbcf944e97fca<\/p>\n<p>aee8d6f39e4286506cee0c849ede01d6f42110cc<\/p>\n<p>b42ca359fe942456de14283fd2e199113c8789e6<\/p>\n<p>cad21e4ae48f2f1ba91faa9f875816f83737bcaf<\/p>\n<p>ebccb1e12c88d838db15957366cee93c079b5a8e<\/p>\n<p>4627cff4cd90dc47df5c4d53480101bdc1d46720<\/p>\n<p>&nbsp;<\/p>\n<h3>Fake documents displayed from droppers<\/h3>\n<p>24eedf7db025173ef8edc62d50ef940914d5eb8a<\/p>\n<p>7dd3e0733125a124b61f492e950b28d0e34723d2<\/p>\n<p>24eedf7db025173ef8edc62d50ef940914d5eb8a<\/p>\n<p>afca20afba5b3cb2798be02324edacb126d15442<\/p>\n<p>&nbsp;<\/p>\n<h2>Stage 1<\/h2>\n<h3>Droppers<\/h3>\n<p>0ac65c60ad6f23b2b2f208e5ab8be0372371e4b3<\/p>\n<p>1949a9753df57eec586aeb6b4763f92c0ca6a895<\/p>\n<p>4627cff4cd90dc47df5c4d53480101bdc1d46720<\/p>\n<p>561db51eba971ab4afe0a811361e7a678b8f8129<\/p>\n<p>6e74da35695e7838456f3f719d6eb283d4198735<\/p>\n<p>8ff7f64356f7577623bf424f601c7fa0f720e5fb<\/p>\n<p>b8064052f7fed9120dda67ad71dbaf2ac7778f08<\/p>\n<p>dc3ab3f6af87405d889b6af2557c835d7b7ed588<\/p>\n<p>&nbsp;<\/p>\n<h2>Stage 2<\/h2>\n<h3>Dropper<\/h3>\n<p>2d14f5057a251272a7586afafe2e1e761ed8e6c0<\/p>\n<p>3d3b60549191c4205c35d3a9656377b82378a047<\/p>\n<p>&nbsp;<\/p>\n<h3>kernelol21.exe<\/h3>\n<p>6ce89ae2f1272e62868440cde00280f055a3a638<\/p>\n<p>&nbsp;<\/p>\n<h3>kbkernelolUpd.dll<\/h3>\n<p>b8ea4b531e120730c26f4720f12ea7e062781012<\/p>\n<p>0ea2ba966953e94034a9d4609da29fcf11adf2d5<\/p>\n<p>926ca36a62d0b520c54b6c3ea7b97eb1c2d203a9<\/p>\n<p>db56f474673233f9b62bef5dbce1be1c74f78625<\/p>\n<p>&nbsp;<\/p>\n<h3>UserData<\/h3>\n<p>147cb0d32f406687b0a9d6b1829fb45414ce0cba<\/p>\n<p>&nbsp;<\/p>\n<p>Acknowledgement: Special thanks to Mathieu Letourneau at MMPC for providing statistical coverage data on the DUBNIUM multi-stage samples and providing insight on the interpretation of the data. Special thanks to HeungSoo David Kang for providing screenshots from the fake Office Word document file.<\/p>\n<p>&nbsp;<\/p>\n<p><em>Jeong Wook Oh<br \/> MMPC<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/blogs.technet.microsoft.com\/mmpc\/2016\/07\/14\/reverse-engineering-dubnium-stage-2-payload-analysis\/\" target=\"bwo\" >https:\/\/blogs.technet.microsoft.com\/mmpc\/feed\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, we\u00a0blogged about the basic functionality and features of the DUBNIUM advanced persistent threat (APT) activity group Stage 1 binary and Adobe Flash exploit used during the December 2015 incident (Part 1, Part 2). In this blog, we will go through the overall infection chain structure and the Stage 2 executable details. Stage 2 executables&#8230;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[10759,10378],"tags":[10922,10864,10760,10923,10924,10925,10926],"class_list":["post-6327","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-security","tag-advanced-persistent-threat","tag-advanced-persistent-threats","tag-antimalware-research-for-it-pros-and-enthusiasts","tag-dubnium-apt","tag-dubnium-infection-chain","tag-dubnium-payload","tag-microsoft-threat-intelligence"],"_links":{"self":[{"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/6327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/comments?post=6327"}],"version-history":[{"count":0,"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/6327\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/media?parent=6327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/categories?post=6327"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/tags?post=6327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}