<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[insomniacs - Medium]]></title>
        <description><![CDATA[reverse engineering away those sleepless nights - Medium]]></description>
        <link>https://medium.com/insomniacs?source=rss----8dea5b1882ca---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>insomniacs - Medium</title>
            <link>https://medium.com/insomniacs?source=rss----8dea5b1882ca---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:31:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/insomniacs" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Analysis Walkthrough: APT32’s {79828CC5–8979–43C0–9299–8E155B397281}.dll]]></title>
            <link>https://medium.com/insomniacs/analysis-walkthrough-apt32s-79828cc5-8979-43c0-9299-8e155b397281-dll-32da9d336ca0?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/32da9d336ca0</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[apt32]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 16:44:24 GMT</pubDate>
            <atom:updated>2022-06-23T16:44:24.270Z</atom:updated>
            <content:encoded><![CDATA[<p>It has been some time since I did any reverse engineering! Time to refresh? And so I reached my hand into my stash of old malware…</p><p>This set of APT32’s binaries fell into my hands a long time ago and the anti-reversing stuff inside set me back for a long while. Don’t get excited yet, these are old binaries. Back then when I saw them, I didn’t think I have it in me to be able to analyze them. Now, let’s try!</p><p>This post will be organized into two parts: The first part will be on the unpacking of the payload; the second part will be on the analysis of the payload’s features. Lengthy post ahead, be warned!</p><p>Other researchers’ work on the same malware payload ({79828CC5–8979–43C0–9299–8E155B397281}.dll) are linked at the end of this post.</p><p>OK let’s go!</p><p>Files I started out with:</p><p>· xwizard.dll</p><p>· xwizard.dtd</p><p>Legitimate copies of these files are found in Windows (C:\Windows\System32) by default:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*CJItLDDjsAlTKEv3Z4UABw.png" /></figure><p>However, the set of malware looks different if you are sharp eyed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*CuibiWetDyrkJUo8sb6mqA.png" /></figure><p>Just by seeing the DLL and DTD files reminds me of file trinity (as seen in PlugX and ShadowPad, just to drop some familiar names).</p><p>Then I came across this old article: <a href="https://www.hexacorn.com/blog/2017/07/31/the-wizard-of-x-oppa-plugx-style/">https://www.hexacorn.com/blog/2017/07/31/the-wizard-of-x-oppa-plugx-style/</a></p><p>This is very likely how the malicious files are being executed.</p><p>Alright, let’s start with simple static analysis as usual, then we’ll deep dive.</p><p>Scrolling through the DLL file, this caught my eye:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*wJB1B6O_m5Ct80cyuAdrog.png" /></figure><p>That looks like some magic chant.</p><p>There’s also another set of similar nonsense in Unicode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*KxJ-I4SBf7PgZ4E13-B9Gg.png" /></figure><p>And this is how these words are being used in the DLL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*MS1VdoM9-bj1aP4nwIt2xQ.png" /></figure><p>Essentially, the contents of the “random nonsense” does nothing at all. So why are these there? To waste our time. Quite typical of what APT32 does in their malware.</p><p>The meat of the malware lies in the DTD file. The content of this file gets read into memory and executed in a new thread.</p><p><strong>Welcome to junkyard.</strong></p><p>Up ahead is a whole bunch of anti-reversing techniques purely to make us suffer :)</p><p>The DTD file starts with some instructions followed by stuff that resembles the PE header (actually just the DOS stub and RICH header are there, at a glance).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*rh-dW7-vzflAgLeMN1ww7g.png" /></figure><p>It just feels like the DOS stub and RICH header are deliberately left there just for tease — why else are they not removed or obfuscated along with everything else?</p><p>Unsurprisingly, the instructions at the beginning of the file are calls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*K6F-qn7ZB52dG16TV89bjw.png" /></figure><p>Which leads to a function that looks like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*FautDaua8hjrBATZHK3FYQ.png" /></figure><p>Uh.. ok..</p><p>One look at the first few instructions within this “function” already makes me go yikesssss…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*oZw0tboQvT3heoRCONZ3SQ.png" /></figure><p>What we are seeing is what other researchers [3] have noted about APT32’s usage of junk code and jumps.</p><p>Amidst the junk code, we see familiar code blocks. For example, these look like the typical GetProcAddress calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*pm3WJ-dYvQdDgD873vvbHA.png" /></figure><p>And also loops like this that resembles decryption of sorts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*2vBKQblQPwhznzw_9ZA63g.png" /></figure><p>I decided to leave the heavylifting to the malware itself by executing it. Then we can look for interesting parts to analyse in depth.</p><p>I wrote a quick binary loader with python to load the DTD directly into memory without going through the DLL (since we already know it does nothing interesting).</p><pre>import sys<br>import ctypes.windll.kernel32 as kernel32<br>import ctypes.wintypes as wintype</pre><pre>MEM_COMMIT = 0x1000<br>PAGE_READWRITE_EXECUTE = 0x40</pre><pre>VirtualAlloc = kernel32.VirtualAlloc<br>VirtualAlloc.argtypes = [wintype.LPVOID, ctypes.c_size_t, wintype.DWORD, wintype.DWORD]<br>VirtualAlloc.restype = wintype.LPVOID</pre><pre>RtlMoveMemory = kernel32.RtlMoveMemory<br>RtlMoveMemory.argtypes = [wintype.LPVOID, wintype.LPVOID, ctypes.c_size_t]<br>RtlMoveMemory.restype = wintype.LPVOID</pre><pre>CreateThread = kernel32.CreateThread<br>CreateThread.argtypes = [wintype.LPVOID, ctypes.c_size_t, wintype.LPVOID, wintype.LPVOID, wintype.DWORD, wintype.LPVOID]<br>CreateThread.restype = wintype.HANDLE</pre><pre>WaitForSingleObject = kernel32.WaitForSingleObject<br>WaitForSingleObject.argtypes = [wintype.HANDLE, wintype.DWORD]<br>WaitForSingleObject.restype = wintype.DWORD</pre><pre># Read binary filename<br>with open(sys.argv[1], &quot;rb&quot;) as input_binfile:<br> bin = input_binfile.read()</pre><pre># Inject into memory<br>mem_addr = VirtualAlloc(0, len(bin), MEM_COMMIT, PAGE_READWRITE_EXECUTE)<br>print(&quot;Loaded at address {:08X}&quot;.format(mem_addr))<br>RtlMoveMemory(mem_addr, bin, len(bin))<br>thread = CreateThread(0, 0, mem_addr, 0, 0, 0)<br>WaitForSingleObject(thread, 0xFFFFFFFF)</pre><p>Andddd we run it.</p><p>There we go! DNS queries!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*hMOpgAqPxtBnu26-qPxZMg.png" /></figure><p>Let’s see if we can figure out where the config data is in the memory, using these domain names as clues. The idea is: if we can find the config data, then we are closer to the malware payload.</p><p>With hasherezade’s pe-sieve, this step is easy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*3KfiAXL9KNtJx3TaOoNNXQ.png" /></figure><p>We find the domain names within one of the DLL PEs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*u17H0SFSfRluyYQtiTNCnA.png" /></figure><p>It looks like there is a registry key name nearby as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*mckB4lgQZNfckAyP-t5K7A.png" /></figure><p>Also notice that the DNS queries are done in the order that the domain names appear within the config data.</p><p>Because we are reverse engineers, and here I am writing an analysis, we cant just completely rely on tools’ output, can we? :D Let’s have some more fun.</p><p>We can work backwards a little to see how this payload got loaded amidst the junk code.</p><p>To get started, we can get abit more help from an API monitor tool — we see allocations of 2 memory blocks, one for the headers and the other for the code, followed by a CreateThread that starts execution of the code. We can put a breakpoint onto VirtualAlloc to find out where the payload was hiding in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*It_wIgTI_9PiJ1YkJuTIXQ.png" /></figure><p>In order to hook into the binary with a debugger, we can patch the first two bytes of the DTD file to “EB FE”, which is the instruction for an infinite loop (EB FE means JMP -2, which effectively causes this 2 byte instruction to be executed repeatedly).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*nd1bmy4Qp4K4ZLgAvvcgXQ.png" /></figure><p>Once our debugger is hooked in, we can revert these two bytes to their original in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*38QIN6XtYAV-BhcQCdLP4Q.png" /></figure><p>The first call to VirtualAlloc is here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*zDFHmZ3Xa7_St67U_NPnFg.png" /></figure><p>Followed by another VirtualAlloc and some memcpy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LxkaZUAI6SNPfRyVW31bDA.png" /></figure><p>Turns out that the content being copied is..</p><p>0x40 bytes of DOS header from the stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*Jc1QIxOrg-8EhswWD0REMg.png" /></figure><p>0xF8 bytes of the PE header, also from the stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*D3rHYcU8ESjVdy4oFyClow.png" /></figure><p>The result of the memcpy looks like a proper PE file forming. And I think there is a good chance that this is the PE file we are looking for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*I6sulA2utSXoVNq1aPSHbQ.png" /></figure><p>The next part that we can expect to be copied would be the section headers.</p><p>True enough. But there is something different this time. The data is being copied from the mapped DTD file and is encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Yzyia7Fzq1C4bc2wi33dOw.png" /></figure><p>Which brings us to this loop that prepares a value in AL that gets XOR-ed with the above data to reveal the section headers. Decryption!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*q0VEWT1hq3ZUNx5wid36Mw.png" /></figure><p>The next strange thing that the malware does is populate the .text section with 0x90 (NOPs) and execute it with a lot of new threads. There are many ways of slowing down analysis and the malware author decided to use this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*pIudCjIrvqfHFF-CntVNXQ.png" /></figure><p>After an eternity of waiting (just joking, it didn’t take that long. But we should short-circuit that in the future), the real contents get copied over. Again, the contents came from the mapped DTD file and is encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*-jTmN7hNdSG1lhbzk0tmag.png" /></figure><p>From this point onwards, the malware just performs VirtualAllocs, copy encrypted sections from DTD in memory, decrypting the sections… and the final outcome is indeed the file that we recovered with pe-sieve!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*1IL0zXN0wYRnPtW1IvLh-A.png" /></figure><p>At this point, I would like to point out that what we have just experienced is an unpacking routine. This packer contains a few anti-analysis mechanisms, including junk code, data assembly using the stack and encryption.</p><p>Let’s find out what is this encryption algorithm used to protect the code of the payload.</p><p>Before we can talk about algorithms, we have to be aware that the malware assembles data on the stack with code that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*5w6pEIAmXcD8a4BYA7lHsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*w-CVKlZBkmluUBIXZhvY5g.png" /></figure><p>Following the GetProcAddress resolution of</p><p>· WaitForSingleObject</p><p>· VirtualAlloc</p><p>· CloseHandle</p><p>· CreateThread</p><p>The malware copies 0x100 bytes of data onto the stack like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*I4vArA4VdKUyAQ7subIpmg.png" /></figure><p>There are even some sneaky edits to this chunk of data, following some junk code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*eeU8mKKsO4dQToKEPsnv6A.png" /></figure><p>That is not all. 0x47 bytes of values found near the beginning of the DTD file is used to XOR with the first 0x47 bytes of this data chunk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*AAq3g7jnY2K4m5w6kT6iWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Pkge3b1bQxS88bCqIYWw1Q.png" /></figure><p>If we had dumped this chunk of data too early, we would have gotten the wrong values in some places.</p><p>Immediately after doing these, the malware proceeds to initialize 0x100 bytes on the stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*ehDMVNNrTbb-gIX8hEGBEg.png" /></figure><p>Now this starts to look familiar. Here’s the mystery solved: what is this chunk of data that is so carefully protected? That’s the RC4 key! A very long one — exactly 0x100 bytes.</p><p>Pseudo-code of RC4 Key Scheduling:</p><pre><strong>for</strong> i <strong>from</strong> 0 <strong>to</strong> 255</pre><pre>S[i] := i</pre><pre><strong>endfor</strong></pre><pre>j := 0</pre><pre><strong>for</strong> i <strong>from</strong> 0 <strong>to</strong> 255</pre><pre>j := (j + S[i] + key[i mod keylength]) mod 256</pre><pre>swap values of S[i] and S[j]</pre><pre><strong>endfor</strong></pre><p>This is the exact loop implemented in the malware:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*jBRl-KpWt5n01T_z8aDcvQ.png" /></figure><p>To ensure that malware did not introduce any sneaky arithmetic into the loop, I wrote a quick python script to perform the KSA and verified the output against the malware’s result.</p><pre>S = bytearray(0x100)<br>with open(&quot;key&quot;,&quot;rb&quot;) as finput:<br> key = bytearray(finput.read())</pre><pre>for i in range(0,0x100):<br> S[i] = i<br>j=0</pre><pre>for i in range(0,0x100):<br> j = (j + S[i] + key[i]) % 0x100<br> t = S[i]<br> S[i] = S[j]<br> S[j] = t</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*GbJnqTIS2Xu23traIA7CnA.png" /><figcaption>output from my script</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*-opN31AR7wZaSK7_0a_gKw.png" /><figcaption>generated by malware</figcaption></figure><p>Perfect.</p><p>Next we are looking for the PRGA that generates the stream key for decrypting data. But before we found it, we see that the malware prepares another 0x100 bytes of data on the stack.</p><p>Looking onwards in the malware code, we can find the RC4 PRGA logic here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*MnOcwZAdhaLrRmmULZ6U1Q.png" /></figure><p>Here’s the RC4 PRGA pseudo-code from Wikipedia:</p><pre>i := 0</pre><pre>j := 0</pre><pre><strong>while</strong> GeneratingOutput:</pre><pre>i := (i + 1) mod 256</pre><pre>j := (j + S[i]) mod 256</pre><pre>swap values of S[i] and S[j]</pre><pre>K := S[(S[i] + S[j]) mod 256]</pre><pre>output K</pre><pre><strong>endwhile</strong></pre><p>Then comes the surprise. Instead of using a byte from the S array as the key to XOR with the data, the malware chose to use another array as the key pool instead! This is the purpose of the second 0x100-byte chunk of data prepared.</p><p>Once again, we can reproduce and check this with a quick python script like this:</p><pre>with open(&quot;xwizard.dtd&quot;, &quot;rb&quot;) as dtd_input:<br> packed_file = dtd_input.read()</pre><pre>ciphertext = bytearray(packed_file[0x5F:0x5F+0x40])<br>plaintext = bytearray()</pre><pre>i = 0<br>j = 0</pre><pre>for c in ciphertext:<br> i = i + 1<br> j = (j + S[i]) % 0x100<br> t = S[i]<br> S[i] = S[j]<br> S[j] = t<br> k = S[(S[i] + S[j]) % 0x100]<br> final_K = S_1[k]<br> plaintext.append(final_K ^ c)</pre><p>Tada~ Successful decryption, just as what the malware did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ly5SkHnBNpMmV8cKDQM18w.png" /></figure><p>From here onwards, everything clicks into place. Putting together all the observations from debugging the malware, we have to keep in mind the following order of decryption:</p><p>1. 0x40 bytes DOS header</p><p>2. 0xF8 bytes PE header</p><p>3. 0x28 bytes section header</p><p>4. 0x?? bytes section (read virtual/raw* size from section header)</p><p>5. Repeat 3,4 until all sections are decrypted</p><p>There is a little check for the section’s virtual size and raw size as defined in the decrypted section header, and the malware chooses the smaller number to use as the number of bytes to decrypt (look at the instruction cmovbe ecx, [esi] in the screenshot below). Because a stream cipher is used, the size and order of the data going into the decryption routine has to be correct, else the results will be gibberish. It sure does feel like the author is putting little traps to deter analysts trying to defeat this malware’s decryption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*tZD_FyfyUvuDRl0IWlyBiQ.png" /></figure><p>I’ve included my unpacking script on GitHub. Unfortunately it cannot be a master solution for all samples of this malware, since there is a need to recover the RC4 key and the key pool (S_1) from memory because of the heavy usage of the stack to re-assemble these data.</p><p><a href="https://github.com/asuna-amawaka/APT32_Malware">GitHub - asuna-amawaka/APT32_Malware</a></p><p>Now we can look into the payload’s features.</p><p>I’m going to refer to this payload as “{79828CC5–8979–43C0–9299–8E155B397281}.dll” — this is the name of the DLL given by its author.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*GaCp2Tml9b-ndr3G90YsGw.png" /></figure><p>When we touch a new malware, everything is an unknown — how would we know where to start looking? What I usually do is to look at the imports and pick up interesting API functions to set breakpoints on. This doesn’t always work — for example if the malware performs dynamic resolution (with LoadLibrary and GetProcAddress). Fortunately for this case, the import table looks long enough for us to get started with this approach.</p><p>In order for IDA to load the sections correctly, I would usually fix the section tables by copying the virtual values into the raw values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*fvNEpxujjgc4GMBlvjFuKQ.png" /></figure><p>The import and export tables would then be parsed correctly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*WQ8aTgmV_MizzpiWHfqM-g.png" /><figcaption>a happy import table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*5RvZBtnKfvlmfUwJ10-Brw.png" /><figcaption>a happy export table</figcaption></figure><p>When these are done, IDA is happy too.</p><p>We can start to identify interesting APIs.</p><p>Evergreen interesting API that I always put breakpoints on:</p><p>- VirtualAlloc</p><p>Possibly related to gathering victim machine information:</p><p>- GetUserNameW</p><p>- GetAdaptersInfo</p><p>- GetDriveTypeW</p><p>- GetComputerNameW</p><p>Possibly for decrypting stuff:</p><p>- CryptGetHashParam</p><p>- CryptCreateHash</p><p>- CryptAcquireContextW</p><p>- CryptHashData</p><p>- CryptImportKey</p><p>Possibly for managing persistency:</p><p>- RegQueryInfoKey</p><p>- RegOpenKeyExW</p><p>- RegCreateKeyExW</p><p>- RegSetValueExW</p><p>- CreateMutexW</p><p>File interactions are always interesting:</p><p>- WriteFile</p><p>- CreateFileW</p><p>- ReadFile</p><p>Resource section is often a place for hiding encrypted stuff:</p><p>- FindResourceExW</p><p>- LoadResource</p><p>- SizeofResource</p><p>These hint at interesting capabilities of the malware:</p><p>- ShellExecuteW</p><p>- CreateProcessW</p><p>- CreateThread</p><p>Also, notice that among the imports there is no network-related APIs (and we know there should be some, since the malware did DNS queries), so there should be another set of APIs being loaded at runtime.</p><p>Let’s use API Monitor to see how many of the above API predictions are correct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*JiIQ2zgNLcR-u16k7p01aw.png" /></figure><p>We can be certain that there are network activities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*B4rlx2DyxTqF92REcFgSFw.png" /></figure><p>Looks like I did not get hits on the other API functions, yet. Now we can delve a little deeper, starting with VirtualAllocs.</p><p>The first VirtualAlloc that gets a hit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*v2FqFbX55FXIMV_g7xqthA.png" /></figure><p>Following that is a call to a function that we are going to find out to be a decryption and decompression routine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*VqX_mHZurfsIVCD1Kgm__A.png" /></figure><p>Does this look familiar? Yes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*yKasV05alcHhX5sWPUk_jg.png" /></figure><p>The encrypted data is found in the rdata section, with the size of the data being pushed onto the stack as one of the parameters for decryption/decompression. The 0x20 bytes RC4 key is also prepared on the stack (no surprise). And finally, the RC4 algorithm used here is the standard one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*tRiKzvBHa6NNwPnGNwRWcQ.png" /></figure><p>The output from the RC4 decryption starts with “5D” which is the magic value for a LZMA-compressed file.</p><p>Fingers-crossed that this is a standard LZMA decompression… and bingo!</p><pre>from Crypto.Cipher import ARC4<br>import lzma</pre><pre>with open(&quot;encrypted_rdata_1005D2F8&quot;, &quot;rb&quot;) as enc_datafile:<br> ciphertext = enc_datafile.read()<br> <br>key = bytearray(b&quot;\x23\xb6\xb4\x67\xa3\x03\x26\x02\xb6\x87\x5c\x51\xce\x69\x39\x7d\x58\xf3\xc0\xba\xfb\xbc\x63\xbd\xef\x0a\x4c\x41\xa9\xb8\x98\x71&quot;)<br>rc4 = ARC4.new(key)<br>plaintext = rc4.decrypt(ciphertext)</pre><pre>props = lzma._decode_filter_properties(lzma.FILTER_LZMA1, plaintext[0:5])<br>decompressor = lzma.LZMADecompressor(lzma.FORMAT_RAW, filters=[props])</pre><pre>with open(&quot;decrypted_rdata_1005D2F8&quot;, &quot;wb&quot;) as dec_datafile:<br>    dec_datafile.write(decompressor.decompress(plaintext[5:]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*2z8jZHAx_9sabL7K2zCycw.png" /></figure><p>Notice that the PE header of the decrypted file looks like there are some missing values e.g. the section headers.</p><p>For the ease of following the rest of this post, note that the decrypted rdata PE starts at address 0x42E0000 in my instance. From this point on, whenever I mention any functions at address larger than 0x42E1000, I would be referring to a function within this decrypted rdata PE.</p><p>Let’s get back to it.</p><p>First thing that the malware did after decryption/decompression, is to dynamically load libraries that are defined within part of the decrypted file that is supposed to be the “imports table”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*AOT41Tc19nbG-z4aFeZRNQ.png" /></figure><p>This is followed by a long series of function calls that loads API calls and fix the offsets within memory (because of memory relocation?).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*BI-V_GjtDGHcEiM0J4xGsw.png" /></figure><p>These calls ended abruptly (the entire code block is too big for IDA to display it in graph form) at this part of the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*NK6mvc6MRjChK-MN2UasMA.png" /></figure><p>Which eventually led to the execution of a function beginning at 0x10056030 that reads 4 pieces of data from the resource section of malware, namely “100”, “2”, “1” and “200”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*yMERCSQ6AVsFq3Cr6qInlA.png" /></figure><p>Using Resource Hacker we can check what is in the resource section, to help us make sense of the function during analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*1esOnSggb0BC7AeEtOx9Ow.png" /></figure><p>We don’t find a resource named “100” from our binary.</p><p>Resource “2” contains the domain names and ports as observed earlier in this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*EdwAqUJRN9XaVlKQIjjjRA.png" /></figure><p>Resource “1” contains two visible chunks of data. The first looks like some encoded/encrypted data, and the second is a registry keyname.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*y3TydWIo7r10ykqgE68DDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Lx0V3g3vhSS6m8Kd6VIkuQ.png" /></figure><p>Resource “200” reminds me of the LZMA header.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*t67ISH23cMfJ4yOisJLelg.png" /></figure><p>Once we dive into the function at 0x10056030, we notice that it calls into code that is in the RC4/LZMA decrypted-decompressed PE in the rdata that we handled earlier on.</p><p>As we proceed, we will also find that these code within the rdata are generously plumped with junk code and ROP-style jumps i.e. return addresses are pushed onto the stack and a jump is made by using the “ret” opcode. Such as this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*O38xJ2Jq1gAQIvLG4vH43w.png" /></figure><p>Until this point, perhaps you would ask — how does the malware know what exact value to push onto the stack such that it returns to the correct code? Afterall, in real ROP attacks, the return values are manipulated with ROP chains specially crafted to read EIP and other addresses to achieve outcomes. But this is not the case here — the return addresses appear to be hardcoded in the instructions.</p><p>Remember that we saw a very long sequence of offset-fixing just after decryption/decompression of the rdata PE? It turns out that the “offset” values that were fixed are the operands of the PUSH instructions that sets the return addresses!</p><p>On junk code: some of them form code blocks that begin and end with complementary jumps e.g. “JNZ and JZ”, “JNS and JS”. Upon further look, we would notice that the execution flow would end up at the same place after the jump — which means that if we are able to identify these code blocks, we can safely ignore them.</p><p>Someone at Checkpoint already wrote a really nice python plugin for Cutter and radare2 back in 2019 to clean up these junk blocks: <a href="https://research.checkpoint.com/2019/deobfuscating-apt32-flow-graphs-with-cutter-and-radare2/">https://research.checkpoint.com/2019/deobfuscating-apt32-flow-graphs-with-cutter-and-radare2/</a></p><p>Unfortunately not all of the junk code huddle together in neat blocks, so we would still need to battle against some of them.</p><p>Let’s get back to understanding what the malware does with the content read from the resource sections.</p><p>We do not have any resource named “100” within our binary, so other than knowing that the malware does not expect there to be any NULL bytes within the data, we know that the content read is being used in the function call to 0x432AA30. We can try to deduce what this function call does using subsequent occurrences of calls to this function, and then come back to predict what content a resource named “100” would hold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*468r678f8Po1oKq3ZkuvoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*CLq25_UM8KLoR8MXyw3_UA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*egLXL_VfCedmTisiWmRo0Q.png" /></figure><p>Arguments to call subroutine within decrypted rdata at 0x432AA30:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*VbppooK5gHDElAEyDCcpHA.png" /></figure><p>It looks like the first argument is the name of the configuration, while the second and third arguments are the values and size respectively.</p><p>Notice that the configuration “{12C044FA-A4AB-88A2–32C3451476CE}” holds a pointer to a function at 0x10056650. This function looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*2UBdj1RP74p9uifCoJAEuA.png" /></figure><p>That is a very nice shape of a switch-table. Let’s see how that looks like in the decompiler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*jslhxKGAP9s6HPKVOIU9qQ.png" /></figure><p>This function expects and checks some input value. If the first value is a 2, then the malware exits. If the first value is a 4, then a new copy of the malware process is started. Nothing very fancy here.</p><p>After everything is done with the resource section, the malware continues to execute code within rdata, at function 0x04329130. (In fact, the decrypted PE within rdata is the main component of this malware from this point on.)</p><p>There is a whole lot of merry-go-rounds in there, before finally ending up at a decent looking function at 0x43B4B0A. There is a createthread call there too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*mdsJVYoXwzcP003cowtTXA.png" /></figure><p>It gets a little boring at this point because there are just so many anti-analysis stuff. So once again, I fell back to using API calls to identify interesting functions.</p><p>Remember that we are still looking for network communications. So here is a function that seems to load ws2_32’s APIs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*oQ8bayPdaM9WdmynKLAVyg.png" /></figure><p>Since we know that the malware is going to do some DNS queries, we can put a breakpoint on ws2_32’s API calls that would perform domain name resolutions, for example getaddrinfo and gethostbyname. The usual API for sending and receiving data (send and recv respectively) should also be watched.</p><p>Turns out that the malware uses getaddrinfo, and a hit on this breakpoint leads us to the function at 0x43B0120:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*CEnc57HNxyGkfzt_j-SfFA.png" /></figure><p>Here is another anti-analysis technique used — the API is called through a small trampoline function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*8Vci-2Ag2DWv3kDBVW6j7w.png" /><figcaption>trampoline function to call an API</figcaption></figure><p>Continuing onwards, we would see a send:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*hAAPEGchmoz0ggFsyqkpLg.png" /></figure><p>First the malware sends out 0x8 bytes of data, followed quickly by 0x4C bytes and then a variable-length chunk that changes on every execution.</p><p>This is how the buffers looked like in memory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*llFGhceGRQajnQc0sSuywQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*285XlkJNfp0bqxKiGIoy6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*yLsDcde9HKIGyHB_RZuFGg.png" /></figure><p>From Wireshark’s point of view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*DR6lpYNsv9XRxa3dQ8ElHg.png" /></figure><p>On first look, these looked like encrypted data — we shouldn’t be surprised.</p><p>Tracing these turned out to be a very frustrating task, involving hardware breakpoints, a lot of VM reverts and a lot of netcatting with experimental values. So as not to bore you all, I’ll skip directly to the answer!</p><p>Standard RC4 is used to encrypt the traffic and we can see the encryption loop right here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LKuQbEXTRDQOqJTbxHm2Yw.png" /></figure><p>The RC4 key used to encrypt/decrypt the traffic is communicated between the malware and the C2 via the first 8 bytes sent in each communication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*g87U4MMauLfDS1HnjK3U1A.png" /></figure><p>The structure of the data communicated is as follows:</p><p>[QWORD RC4key]</p><p>[DWORD unknown] [WORD magicbytes] [DWORD unknown] [DWORD size1] [DWORD size2] [DWORD size3] [WORD datatype] [24bytes id_1] [24bytes id_2] [DWORD checksum]</p><p>The “magicbytes” is fixed to 0x69FD. The malware checks for the presence of this value before proceeding.</p><p>There are 3 fields reserved for sizes, and they indicate the length of the next chunk of data to be expected.</p><p>A 2-byte value indicates the type of data that follows. 0x0 implies data is in plaintext, 0x1 means zlib-deflate compressed.</p><p>There are two long fields, each of 24 bytes. The first appears to be filled with value randomly generated by the malware. And the second is to be received from the C2, presumably random too.</p><p>The last 4 bytes is a CRC checksum.</p><p>And we have finally come to the end of this post! It has been a very tiring but fulfilling week tearing apart this malware as an exercise for my brains.</p><p>Until next time!</p><p>===</p><p>[1] <a href="https://blogs.blackberry.com/en/2019/04/report-oceanlotus-apt-group-leveraging-steganography">https://blogs.blackberry.com/en/2019/04/report-oceanlotus-apt-group-leveraging-steganography</a></p><p>[2] <a href="https://ti.qianxin.com/blog/articles/oceanlotus-targets-chinese-university/">https://ti.qianxin.com/blog/articles/oceanlotus-targets-chinese-university/</a></p><p>[3] <a href="https://www.welivesecurity.com/wp-content/uploads/2018/03/ESET_OceanLotus.pdf">https://www.welivesecurity.com/wp-content/uploads/2018/03/ESET_OceanLotus.pdf</a></p><p>~~</p><p>Asuna | <a href="https://twitter.com/AsunaAmawaka">https://twitter.com/AsunaAmawaka</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32da9d336ca0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/analysis-walkthrough-apt32s-79828cc5-8979-43c0-9299-8e155b397281-dll-32da9d336ca0">Analysis Walkthrough: APT32’s {79828CC5–8979–43C0–9299–8E155B397281}.dll</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CDRThief 新变种/New CDRThief Variant!]]></title>
            <link>https://medium.com/insomniacs/cdrthief-%E6%96%B0%E5%8F%98%E7%A7%8D-new-cdrthief-variant-73fb648accf3?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/73fb648accf3</guid>
            <category><![CDATA[cdrthief]]></category>
            <category><![CDATA[welivesecurity]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[eset]]></category>
            <dc:creator><![CDATA[luxingzhe]]></dc:creator>
            <pubDate>Sun, 06 Mar 2022 18:38:28 GMT</pubDate>
            <atom:updated>2022-03-06T18:38:27.899Z</atom:updated>
            <content:encoded><![CDATA[<h4>Discovering and analyzing a new CDRThief Variant</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h7WOtM9GWJN9kAl9" /><figcaption>Photo by <a href="https://unsplash.com/@chrisyangchrisfilm?utm_source=medium&amp;utm_medium=referral">Chris Yang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In recent days, I have had the opportunity to challenge myself thanks to an old acquaintance of mine. I received a relatively rare and interesting malicious GoLang sample that turned out to be a new variant of CDRThief upon analysis. CDRThief is a malware specifically targeting call data records from Linknat VOS2009/VOS3000 soft switches.</p><h4>Highlights</h4><ul><li>New CDRThief variant</li><li>Suspect strings encrypted with XXTEA and base64 encoded; Key: <strong>fhu84ygf8643</strong></li><li>Forks a child process of itself to replace parent binary</li><li>Hides PID</li><li>Uses IPTables to ensure C2 communications.</li><li>Steals CDR data records from Linknat VOS2009/VOS3000 softswitches</li><li>Exfiltrated data is Gzipped and encoded</li></ul><h3>Analysis of the Thief</h3><p>The sample was a 32-bit ELF file packed with an unknown packer. I was able to access the unpacked sample by dumping the memory using GDB. The hashes of the files can be found under the annex.</p><p>I have also come up with a basic diagram summarizing the main execution flow of the malware in hopes that it will be easier for you readers to follow along.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*XadebAkFtXagRfhei0bHvw.png" /><figcaption>Execution flow of malware</figcaption></figure><h4>Defense Evasion &amp; Preparation for C2 Communications</h4><p>With the packer code out of the way, analysis of the GoLang binary can begin in proper. Amongst the multitude of strings (GoLang binaries come with tons of strings), what caught my eye were numerous base64 strings. On further analysis, these strings appear to be used in a string decryption function — <em>main.strDec</em>. Analysis of this function show that these base64 strings were first encrypted with XXTEA using <strong>fhu84ygf8643</strong> as the key and subsequently base64 encoded. When decrypted, these strings form a collection of IP addresses, possible URL paths, Linux commands, file paths and SQL commands.</p><p>It is quite clear that the reason for the author to encrypt suspect strings was to avoid immediate detection via static analysis of strings.</p><p>I decided to start my analysis with the <em>main.init</em> function as it contains the earliest use of the string decryption function. From the decrypted strings, it would appear that the purpose of — <em>main.init</em>, is to prepare the C2 paths/URIs and C2 IPs along with some strings for use by other functions within the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*hY5FlgUc-HEOaRsZhhjvAg.png" /><figcaption>Figure 1. String decryption (C2 IP)</figcaption></figure><p>The malware contains functionality to create a log file(<em>/dev/shm/.log</em>) for logging purposes and to prepare a C2 IP (<strong><em>hxxp://101.32[.]181.186:8888/</em></strong>). The creation of the log file and the preparation of this C2 IP <strong>do not occur</strong> due to hard-coded flags (See Figure 2). As the log file is not created, the logging functionality can be considered “<em>disabled</em>”. One possible hypothesis is that this functionality (log file and C2 IP) is used by the author for testing purposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*8j2-ARclkH5BtniOm83xxw.png" /><figcaption>Figure 2. Hard-coded flag</figcaption></figure><p>In addition, the malware also contains two techniques for stealth and detection evasion.</p><p>It first makes a call to a forking function — <em>main.fork</em>. The purpose of this function is to execute a copy of itself and impersonate the device event managing daemon, udevd with the “detach and run in the background” flag. When concatenated, the command is as follows:</p><pre>exec –a ‘/sbin/udevd –d’&lt;/Filepath/E5ECF01E7A68F3F19200E40D3EBB3D<br>B9C91B032F340BA6FDD536E7B22D9401F3&gt; &amp;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*la4QXfA9dR9qqpLUhrfOEQ.png" /><figcaption>Figure 3. Command to impersonate as “udevd –d”</figcaption></figure><p>Once a copy of itself has been successfully executed, the parent process will exit. There is a PPID check before the decryption of the “exec –a” command string. This check will ensure that only one child process is executed when the child process reaches the forking function.</p><p>The malware is able to hide its PID via the function — <em>main.hidePid</em>. It achieves this by creating an empty directory, mounting the empty directory to the process ID before removing this empty directory. The commands to achieve this is as follows:</p><pre>mkdir /dev/shm/.hsperfdata</pre><pre>mount -o bind /dev/shm/.hsperfdata /proc/ &lt;PID&gt;</pre><pre>rm -rf /dev/shm/.hsperfdata</pre><h3>Main functionality</h3><p>We can finally get to the meat of the binary. The malware creates a file using a pre-prepared string, <em>“/dev/shm/java_pid132”</em>. This naming convention is an attempt to look innocuous by imitating the legitimate file created by java in the tmp folder e.g. <em>/tmp/.java_pid&lt;number&gt;</em>. One notable point is that <em>“/dev/shm”</em> is a temporary file system kept in virtual memory. This means that the created file gets removed upon shutdown much like the <em>/tmp/</em> folder.</p><p>From this point on, my analysis findings will be categorized by common functionality (functions that work together to achieve a common goal).</p><h4>C2 IP Testing &amp; Preparation</h4><p>The C2 IPs are first chosen then verified operational. The <em>main.pingNet </em>function will check if the C2 IP is operational. Otherwise, it will proceed to select the next C2 IP in the list. If the C2 IP is operational, it will assign this C2 IP to be used by other functions. When it <strong>fails to get an operational C2 IP</strong> after 10 tries, the malware prepares 2 IP ranges and 2 IP table rules.</p><pre><strong>IP Ranges (Decrypted with XXTEA)</strong></pre><pre>101.32.181.0/24<br>35.220.128.0/24</pre><p>The 2 IP ranges will be used to form the following command to display existing iptable rules with specified range:</p><pre>iptables -n -L INPUT --line-numbers |grep –E &#39;101.32.181.0/24| 35.220.128.0/24&#39; |awk &#39;{print $1}&#39;</pre><p>This command checks for the presence of iptable rules that potentially block/affect traffic to and from the 2 IP ranges.</p><p>The malware will then execute the following iptable rules.</p><pre>iptables -I INPUT -p tcp -j ACCEPT -s 101.32.181.0/24<br>iptables -I INPUT -p tcp -j ACCEPT -s 35.220.128.0/24</pre><p>The author has provisioned for the possibility where there is an iptable rule restricting the C2 IPs. The 2 iptable rules are intended as a test for connectivity as these rules are activated as a result of the malware being unable to connect to the C2 after 10 failed tries. What I find most peculiar is that <strong>none of the C2 IPs found in this malware</strong> <strong>fit the IP range</strong> <strong>35.220.128.0/24</strong>.</p><p>Once the malware has an operational C2 IP, it is placed into a buffer for use by other functions.</p><h4>Retrieval of credentials from VOS2009/VOS3000 configuration files</h4><p>In order for the malware to gain access to the VOS2009/VOS3000 MySQL database, a bunch of file paths for the VOS2009/VOS3000 configuration files is decrypted (See Figure 4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*pUbO7n4HOdgWtgaX9Tv0Ag.png" /><figcaption>Figure 4. Decryption of configuration file paths</figcaption></figure><pre><strong>List of configuration files(Decrypted with XXTEA)</strong></pre><pre>/usr/kunshi/vos2009/server/etc/server_db_config.xml<br>/usr/kunshi/vos3000/server/etc/server_db_config.xml<br>/home/kunshi/vos2009/server/etc/server_db_config.xml<br>/home/kunshi/vos3000/server/etc/server_db_config.xml<br>/home/kunshi/vos2009/etc/server_db_config.xml<br>/home/kunshi/vos3000/etc/server_db_config.xml<br>/usr/kunshi/vos2009/server/etc/serverdbconfig.xml<br>/usr/kunshi/vos3000/server/etc/serverdbconfig.xml</pre><p>I found that the malware then iterates through each possible configuration file path, utilising a regular expression to search for the username and password in the configuration file. If a password is found, the malware calls on <em>main.Decrypt</em> to decrypt this password. The password is AES-128 CBC encrypted. The AES Key and IV required for this decryption, is hardcoded and similarly encrypted with XXTEA along with base64 encoding.</p><h4>Functions that steal VOS2009/VOS3000 Data</h4><p>There are 3 tables within the MySQL database that the malware queries to access the data it requires.</p><p>The malware accesses 2 tables, using <em>main.syslog</em> and <em>main.gatewaymapping </em>using goroutines. The <em>e_syslog</em> table contains system events while the <em>e_gatewaymapping</em> table contains VoIP gateway data.</p><p>The third table, <em>e_cdr</em>, is what gives this malware its namesake and is likely what the attacker is interested in. I observed 2 functions, <em>main.cdr0</em> and <em>main.cdr1</em> that appear identical to each other (likely as a redundancy mechanism). The purpose of this function is to steal <em>e_cdr</em> tables and the only main difference is that <em>main.cdr0</em> is launched as a goroutine while <em>main.cdr1</em> is directly called by function — <em>main.onStart</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*usmvNMeMP9vPMwyh0IkuJA.png" /><figcaption>Figure 5. Accessed Tables — Calling sequence</figcaption></figure><p>All stolen data from these tables are Gzipped and then encoded via function — <em>main.encDec</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTnjL2qd6nCRtHp7CV7A9w.png" /><figcaption>Figure 6. Encoding function — main.encDec</figcaption></figure><h4>Functions that communicate with C2s</h4><p>The functions that use the C2 IPs and URL paths prepared by the function — <em>main.init</em> will be detailed in this section.</p><p>During my analysis, there were a total of 5 unique URL paths that I observed to be for specific use by certain functions. The URL paths come in the form of “<em>log/167653879713&lt;*&gt;</em>” where * is a number from 1 to 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*17cOAUJUHs37miOeRL7AsQ.png" /></figure><h4>How did I establish the link to CDRThief?</h4><p>It is a habit of mine to conduct quick Google searches on unique strings and IOCs from samples that I work on. In this case, my search on the XXTEA key, <strong>fhu84ygf8643</strong>, returned an interesting article(<a href="https://www.welivesecurity.com/2020/09/10/who-callin-cdrthief-linux-voip-softswitches/"><strong>Who is calling? CDRThief targets Linux VoIP softswitches</strong></a>) from ESET on a Linux malware that targets Linux VoIP soft switches.</p><p>A quick glance through the function names in the ESET article followed by a cursory comparison of the function names in the sample under analysis showed striking similarities and somewhat major differences of which I will elaborate on later.</p><p>Was I possibly looking at a sample belonging to the same family? Perhaps.</p><p>Fortunately, I was able to find and download an unpacked sample mentioned in the ESET article for a quick look.</p><pre><strong>Unpacked ELF 64-Bit Binary sample from ESET</strong></pre><pre>SHA256: 665ACB48F9AD6317806231E52E5D3D05E91A93B20F40771A55E634192E8B094B</pre><p>It turns out that some of the decrypted strings from the ESET sample were different from the decrypted strings in the sample I was analysing.</p><p>From the similar decrypted strings and function names in both samples, I was able to ascertain that the sample I was analysing had a relatively strong relationship to the malware described in the ESET report; that it was very likely a variant of CDRThief.</p><h4>What’s new?</h4><p>It was mentioned earlier that there were differences in the decrypted strings. So what else is different? During my analysis, it became apparent that the author(s) of CDRThief introduced a couple of fundamental changes since the first report by ESET in September of 2020.</p><p>The first fundamental difference I observed was that the CDRThief ESET sample had suspect strings (but excluding C2 IPs and domains) encrypted with XXTEA and then base64 encoded. In contrast, the sample detailed in this article had its C2 IPs encrypted.</p><p>Another fundamental change I observed, were changes to the URL paths. The table below is a list of URL paths from the ESET article and the sample detailed in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*4-Via4LhA6wHvDp27C7d6A.png" /></figure><p>The URL paths in the latest sample is organised and the last number (represented by *) in “log/167653879713*” represents a particular functionality. E.g. log/1676538797135 represents exfiltrated data from VOS2009/VOS3000 tables.</p><p>The attackers also introduced new functionality like the hiding of PID and checks for potential restrictive iptable rules upon failure to get a “working” C2 IP.</p><p>One other interesting difference is the removal of RSA-1024 encryption for exfiltrated data.</p><p>Lastly, the ESET article also mentioned that CDRThief had functionality for uploading malware error logs. The sample detailed in this article does not contain this functionality and implies that the tool may have reached a certain maturity in the development roadmap.</p><p>These fundamental changes lead me to believe that the sample I analysed is likely a new variant.</p><h4>Conclusion</h4><p>This is my first time coming across a malware that specifically targets a VoIP soft switch. The malware’s ability to gain access to the VoIP data from the SQL database indicate that the author(s) have great depth and intimate knowledge of the inner workings of this line of VoIP soft switches. Although I have not taken a look at the VoIP software itself, one cannot help but wonder how in the world the author(s) were able to gain access to the AES Key and IV that is used to decrypt the password in the configuration file. Did they reverse engineer the VoIP soft switch binary or could it have been acquired through some other means?</p><p>The fundamental changes and improvements to the malware tell us that the attackers continue to have a vested interest in the data that the VOS2009/VOS3000 switches provide. The new additions (techniques to evade detection and iptable rules) tell us that the attackers have become more cautious. This suggests that the attackers may have been discovered at some point in time and subsequently had access denied.</p><p>If you would like to continue this discussion, you may contact me via twitter <a href="https://twitter.com/woshiluxingzhe">@woshiluxingzhe</a></p><p>Till next time.</p><p>XingZhe</p><h3>Acknowledgements</h3><p>I am very grateful to my friends TC &amp; LY for their assistance in translating and proofreading this article. They have done a terrific job of making the unreadable readable.</p><h3>Annex</h3><h4>File Information</h4><p>Packed ELF 32-Bit Binary — Packer: unknown</p><p>SHA256: E5ECF01E7A68F3F19200E40D3EBB3DB9C91B032F340BA6FDD536E7B22D9401F3</p><p>Unpacked ELF 32-Bit Binary</p><p>SHA256: 4B0803CA6CE5FC6E6BD160921B21A856B9A68934D8814743DA3BFE4D4D25586B</p><h4>Network IOCs</h4><p>hxxp://101.32[.]181.186:8888/<br>hxxp://1.13.173[.]45:1202/<br>hxxp://124.156[.]214.224:1203/<br>hxxp://129.211[.]157.244:1203/<br>hxxp://129.226[.]134.180:1203/</p><p>101.32[.]181.0/24<br>35.220[.]128.0/24</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73fb648accf3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/cdrthief-%E6%96%B0%E5%8F%98%E7%A7%8D-new-cdrthief-variant-73fb648accf3">CDRThief 新变种/New CDRThief Variant!</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[It’s a BEE! It’s a… no, it’s ShadowPad.]]></title>
            <link>https://medium.com/insomniacs/its-a-bee-it-s-a-no-it-s-shadowpad-aff6a970a1c2?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/aff6a970a1c2</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[shadowpad]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Fri, 19 Nov 2021 17:15:10 GMT</pubDate>
            <atom:updated>2021-11-19T17:15:10.151Z</atom:updated>
            <content:encoded><![CDATA[<p>ShadowPad, a malware name that is familiar to many, became widely known since 2017 through its participation in a series of supply-chain attacks in CCleaner, NetSarang and ASUS. There has been a lot of good work describing how clusters of activities by different threat actors (APT41, Fishmonger, Tonto Team, RedFoxTrot, BackdoorDiplomacy are all the “big names” we know) are linked by ShadowPad. I thought to join in the fun of reverse engineering one of the variant of ShadowPad that I found from VirusTotal. So let’s begin!</p><p>Side-note: Kaspersky calls this variant “ShadowShredder” [1]. This variant has also been documented by PTSecurity [2] in Jan 2021 and was also recently in TeamT5’s presentation in VB2021localhost conference [3].</p><p>The malware trinity (DLL load-order attack) analyzed in this post:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*7lidgR2n26Rj1HhHBarc_A.png" /></figure><p>Legitimate EXE, bdreinit.exe (Bitdefender’s Crash Handler) — SHA256: 386EB7AA33C76CE671D6685F79512597F1FAB28EA46C8EC7D89E58340081E2BD</p><p>Malicious DLL, log.dll — SHA256: 8D1A5381492FE175C3C8263B6B81FD99AACE9E2506881903D502336A55352FEF</p><p>Encrypted Payload, log.dll.dat — SHA256: 0371FC2A7CC73665971335FC23F38DF2C82558961AD9FC2E984648C9415D8C4E</p><p>I found these files separately, so they may not be originally intended as a package. I managed to piece them together based on their filenames, and they work fine as a set. These files happened to have debugging strings included, which makes the analysis slightly more pleasing to follow.</p><p>Let’s start with observations from dynamic analysis.</p><p>Here’s what the log looked like in the debugger upon execution without breakpoints:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kzk6qtzjQKlFVzs0AM0qGg.png" /><figcaption>logged by x32dbg</figcaption></figure><p>The same debugging information is also written into a file C:\ProgramData\bee.log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zh10eB1SwHouiZK4KIdnGg.png" /><figcaption>bee.log</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*dYDhmyauqjLl7p877GCAVw.png" /><figcaption>more of bee.log</figcaption></figure><p>It seems that I’ve picked up a test sample. The C2 domain configured within is a subdomain of wikimedia[.]vip, which has been associated with Funnydll and other ShadowPad samples.</p><p>I’m curious about the author’s choice of name — What does “BEE” stand for?</p><p>I extracted all the interesting filename strings, for reference if anyone is interested at guessing the full suite of capabilities within ShadowPad:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*u69cEJCTLOs7ZUTZgkWa2g.png" /><figcaption>source filenames</figcaption></figure><p>And here’s the list of debugging messages found in memory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*kInAuCINNuludgnNPlXWhw.png" /><figcaption>debugging messages</figcaption></figure><p>The processes created are as such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*jonPUPXMbhKlTlCvaSzYlg.png" /><figcaption>logged with APIMonitor</figcaption></figure><p>“Test.exe” is a copy of bdreinit.exe and is part of the persistency mechanism of the malware — The EXE and DLL are started via Services, and the encrypted payload is loaded from Registry. I supposed if service installation fails, then the malware shall persist through Run regkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*uxj5ELvkbWKse_hBxWN7oA.png" /></figure><p>The EXE and DLL are copied to C:\ProgramData\DRM\Test (specified by configuration), while the DAT payload file is deleted after the first execution. For subsequent executions, the payload is read from Registry.</p><p>The payload is re-encrypted by the malware before it is being written into the Registry for persistency. For some reasons, the initialization value used in the re-encryption algorithm is the compilation timestamp of the malicious DLL file, while the initialization value used in the original encryption algorithm is the first 4 bytes within the dat file, hence the encrypted data seen in the registry differs from the log.dll.dat file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*jmf_WEik_RtNOvgS14Qe-w.png" /><figcaption>encrypted payload in registry</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*iibhI_qrmE-iZ95t-OwpyQ.png" /><figcaption>encrypted payload file</figcaption></figure><p>Here is the python script I used to decrypt the payload file log.dll.dat:</p><p><a href="https://github.com/asuna-amawaka/SHADOWPAD-analysis/blob/main/decrypt_payload_dat.py">SHADOWPAD-analysis/decrypt_payload_dat.py at main · asuna-amawaka/SHADOWPAD-analysis</a></p><p>And here is the script for decrypting the payload from registry:</p><p><a href="https://github.com/asuna-amawaka/SHADOWPAD-analysis/blob/main/decrypt_payload_reg.py">SHADOWPAD-analysis/decrypt_payload_reg.py at main · asuna-amawaka/SHADOWPAD-analysis</a></p><p>The malware has keystroke logging capabilities, and the keystroke log file is encrypted and saved to a random-looking filepath in %PROGRAMDATA% like this:</p><blockquote>C:\ProgramData\MOO\JKISIQ\EWGSE\LECIIOGK</blockquote><p>Decryption of the keystroke log file is done in the same manner as the configuration data (I’ll talk about how to get this in awhile):</p><p><a href="https://github.com/asuna-amawaka/SHADOWPAD-analysis/blob/main/decrypt_keystroke_log.py">SHADOWPAD-analysis/decrypt_keystroke_log.py at main · asuna-amawaka/SHADOWPAD-analysis</a></p><p><strong>Anti-reverse engineering obfuscation</strong></p><p>Now, here comes details on how I handled the reverse engineering. This is slightly harder than usual, because of the obfuscation technique used in the malware. The original malware binary is “shredded” into pieces, with 1 instruction per piece, and put back together with a “jumper” function as glue. Oh, and there are some junk “cmp” followed by “jb” instructions just to make your eyes hurt.</p><p>Let’s see what it looks like in IDA.</p><p>Up till this point at address 0x100011D6, everything is normal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*BJr8HSJEc1Te6Vw74vZoFA.png" /><figcaption>disassembly at beginning of malware logic</figcaption></figure><p>Then came this jmp:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*vYfA3i-OvDvnzDbMjb419w.png" /></figure><p>Followed by another call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*diINwSwGNhZEe0yGaMC3pQ.png" /></figure><p>If we follow the instructions starting from 0x10004465, you will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*ZmjctWfFHkKzMlxzTxztVg.png" /><figcaption>within “jumper” function</figcaption></figure><p>It looks terribly complicated, but all it does is to read the next dword after the call and add it to original intended return address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*daMt3zlsTgww_vb0F8CGOA.png" /><figcaption>illustrate jumper (1)</figcaption></figure><p>And these “bits and pieces” of instructions occur from here onwards, throughout the whole malware. The “real” instruction that is part of the malware’s logic is the single instruction before the call to jumper. Trying to recover these instructions makes me feel like I am picking up the pieces from the shredding machine and gluing them back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*h_-87b49RTxe04MJusayrQ.png" /><figcaption>illustrate jumper (2)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*Oy5YyfUiGKhJPJ2AvMO2cw.png" /><figcaption>illustrate jumper (3)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*GJCBNIFhv4bishon5jtn_Q.png" /><figcaption>illustrate jumper (4)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Wl52v-8klOnoiDUj4F-Czw.png" /><figcaption>illustrate jumper (5)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*9Cbdnuh8oKezNq05F3AT5g.png" /><figcaption>illustrate jumper (6)</figcaption></figure><p>After doing away with the jumper calls, here’s a snippet of recovered “shreds” of instructions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*hoH-3Zz-h7b3w-ckDd88IA.png" /></figure><p>I greyed out the junk “cmp” and “jb” instructions. Up till this point, the process of recovery is very manual, with abit of help from this IDAPython script I wrote:</p><p><a href="https://github.com/asuna-amawaka/SHADOWPAD-analysis/blob/main/ida_get_next_instr.py">SHADOWPAD-analysis/ida_get_next_instr.py at main · asuna-amawaka/SHADOWPAD-analysis</a></p><p>The python script is not perfect — at some point it will fail to work as intended, and I will have to apply the script again at the position where it failed. Furthermore, this manner of “advancing” through the disassembly in IDA didn’t feel very efficient. As it turns out, using the “trace” feature in the debugger produced the expected results with ease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*XOTU-8JU64CWI5ZR7bkjsA.png" /><figcaption>trace in x32dbg</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*QrczMJsez1Q5hWSxR92Tlw.png" /><figcaption>traced log</figcaption></figure><p>After some cleaning up, here’s the code logic that decrypts the payload from registry, for a taste of what we can see after doing away with the jumper calls and junk cmp-jbs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*6eNTXi5lWUYR96yNKKVaFg.png" /><figcaption>traced instructions for decrypting payload from registry</figcaption></figure><p><strong>Malware Configuration</strong></p><p>In order to recover the configuration data, it helps to know what it looks like from older variants of ShadowPad (without the shredding obfuscation) — so that we can recognize it in memory. I used APIMonitor to look out for memory copies, because I knew that was what ShadowPad will do with its configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*rkZRlmncjLh8QGxDm-EbIA.png" /><figcaption>APIMonitor log of memcpy</figcaption></figure><p>One visual characteristic of the configuration data is that it will start and end with many zeroes, and it is not very long (the part that looks like encrypted data is approx. ~400 bytes long). In this particular sample, the memory size expected for the configuration is 2198 bytes long. This can perhaps be a helping value to look out for the memcpy call dealing with the configuration.</p><p>Decryption of the configuration data uses the exact same algorithm as what is used to decrypt the keystroke log file. Earlier I shared the standalone python script used to decrypt the keystroke log file. Here’s the IDAPython version to handle the configuration data in IDA:</p><p><a href="https://github.com/asuna-amawaka/SHADOWPAD-analysis/blob/main/ida_decrypt_config.py">SHADOWPAD-analysis/ida_decrypt_config.py at main · asuna-amawaka/SHADOWPAD-analysis</a></p><p>And here’s the decrypted configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*WeKbLDuacbG8Exa6fK_kBA.png" /><figcaption>ShadowPad configuration decrypted</figcaption></figure><p>Hmmm~ it looks like someone was testing his BEE some 3 months ago, based on that timestamp in the configuration.</p><p>Well then, that is all I have. Come chat with me on Twitter if you have any idea how I can automate this analysis; I seem to have done most stuff in the painful way :|</p><p><strong>Network IOC:</strong></p><p>ti0wddsnv[.]wikimedia[.]vip:443</p><p><strong>Host IOCs:</strong></p><p>log.dll — SHA256: 8D1A5381492FE175C3C8263B6B81FD99AACE9E2506881903D502336A55352FEF</p><p>log.dll.dat — SHA256: 0371FC2A7CC73665971335FC23F38DF2C82558961AD9FC2E984648C9415D8C4E</p><p>Scripts mentioned in this post are here:</p><p><a href="https://github.com/asuna-amawaka/SHADOWPAD-analysis">GitHub - asuna-amawaka/SHADOWPAD-analysis</a></p><p>[1] <a href="https://securelist.com/apt-trends-report-q3-2021/104708/">https://securelist.com/apt-trends-report-q3-2021/104708/</a></p><p>[2] Higaisa or Winnti? APT41 backdoors, old and new - PTSecurity (<a href="https://ptsecurity.com/ww-en/analytics/pt-esc-threat-intelligence/higaisa-or-winnti-apt-41-backdoors-old-and-new">https://ptsecurity.com/ww-en/analytics/pt-esc-threat-intelligence/higaisa-or-winnti-apt-41-backdoors-old-and-new</a>)</p><p>[3] Evolution after prosecution: Psychedelic APT41 - TeamT5 at VB2021 (<a href="https://vblocalhost.com/conference/presentations/evolution-after-prosecution-psychedelic-apt41">https://vblocalhost.com/conference/presentations/evolution-after-prosecution-psychedelic-apt41</a>)</p><p>~~</p><p>Asuna | <a href="https://twitter.com/AsunaAmawaka">https://twitter.com/AsunaAmawaka</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aff6a970a1c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/its-a-bee-it-s-a-no-it-s-shadowpad-aff6a970a1c2">It’s a BEE! It’s a… no, it’s ShadowPad.</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aria-Body Loader? Is that you?]]></title>
            <link>https://medium.com/insomniacs/aria-body-loader-is-that-you-53bdd630f8a1?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/53bdd630f8a1</guid>
            <category><![CDATA[analysis]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[aria-body]]></category>
            <dc:creator><![CDATA[BlueMonkey]]></dc:creator>
            <pubDate>Wed, 29 Sep 2021 06:28:34 GMT</pubDate>
            <atom:updated>2021-09-29T06:28:34.425Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello! This is my first time writing a blog on a loader which I had gotten hold of. So, I am a new analyst in the Malware Analysis field and I am trying to do a research into cobalt strike. Recently, I ran a modified public YARA rule for cobalt strike on Virus Total and from the scan, I found two samples which I find interesting.</p><blockquote>1e56c3f05bb53d2dfa60bc016e8509b12fd3beb5f567d274a184bb67af1eb19c</blockquote><blockquote>c5696e660f3cfa9232756418e40ad18729cfe32fb284bba2314dd523ba527258</blockquote><p>These two samples have a relative large size (17.05 MB) as compared to other files and their size is exactly the same. Additionally, their upload timing is quite close to each other, around 3 minutes apart. I started to analyze the files and from my finding, it doesn’t look anything like a cobalt strike loader. Turning to my friend who have much more experience in malware analysis, I told him my findings and he told me that from what I had described, it sounds a little bit like Aria-Body instead. So I did some read up on Aria-Body and here are what I had found….</p><p>In 2020, Check Point Research release a write up (http://research[.]checkpoint[.]com/2020/nikon-apt-cyber-espionage-reloaded) describing how Naikon APT group is using Aria-body. In the report, they summarized the loader to have these capabilities:</p><p><em>1. Establish persistence via the Startup folder or the Run registry key [some variants].</em></p><p><em>2. Inject itself to another process such as rundll32.exe and dllhost.exe [some variants].</em></p><p><em>3. Decrypt two blobs: Import Table and the loader configuration.</em></p><p><em>4. Utilize a DGA algorithm if required</em></p><p><em>5. Contact the embedded / calculated C&amp;C address in order to retrieve the next stage payload.</em></p><p><em>6. Decrypt the received payload DLL (Aria-Body backdoor).</em></p><p><em>7. Load and execute an exported function of the DLL — calculated using djb2 hashing algorithm.</em></p><p>Take note on these points as I will be mentioning some of them in this post.</p><h4>Analysis of the samples</h4><p>As I had mentioned in the intro, the first thing that I noticed about the two sample is that both of them have exactly the same size. When I loaded them into PE studio, I noticed that they share the same compiler, debugger and exports timestamp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9vZ65tN3upoIQYw55o3tg.png" /><figcaption>Similar Timestamp</figcaption></figure><p>Now looking at the section’s metadata, we can see that all but two of them have the same hash. The two sections with the different hash is the <em>.text</em> and the <em>.data</em> section. Although they have a different hash, we can see that the raw-size, virtual-size, raw-address and virtual-address are the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvaCL7o1Ijr8-TWKWEvMbQ.png" /><figcaption>Similar Section</figcaption></figure><p>Looking into the import and export section, this two samples also have a same import and export.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKgMnE9_Nb7iox7L3w8POw.png" /><figcaption>Similar Export</figcaption></figure><p>Looking at the static properties analysis, these two files seems like twins. They could have the same origins or they might be built using a builder. But this is just my speculation at this point as there are not enough information to support the claim.</p><h4>Looking for the “action”</h4><p>Now that I had done the analysis on the files properties and confirmed that it is a 64 bit DLL, it’s time to throw the sample 1e56c3f05bb53d2dfa60bc016e8509b12fd3beb5f567d274a184bb67af1eb19c into IDA for analysis. After IDA has finished loading, the first thing that it displayed is this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*5vtZwVrEwteIpMAFYrKlGA.png" /><figcaption>DllMain</figcaption></figure><p>That’s all ._. not helpful at all. Seems like I have to find the “action” through other means~~</p><p>Since this is a DLL, we can try to look for the “action” by checking the export functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*-dzCdvCIilTP-J5IsA9eGA.png" /><figcaption>Export Functions</figcaption></figure><p>From this list of 30 export functions, two of them <em>DllEntryPoint</em> and<em> ILCreateFromPath</em> caught my attention. After looking through the two functions, I had determined that the <em>ILCreateFromPath </em>function contains the “actions” that we are interested in.</p><h4>Obfuscation</h4><p>While scrolling through the <em>ILCreateFromPath</em> function, I noticed a pattern:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*M2HnbuePBIAmA7TTaHfBHQ.png" /><figcaption>Encoded String</figcaption></figure><p>Noticed that the value “<em>]prt-.p,^p,0tnpN.,wSlyowp,b</em>” in the variable <em>aPrtPP0tnpnWsly</em> was lea into <em>rcx</em> followed by calling the sub function <em>sub_180001010</em> then followed by a <em>call rax</em>. From my analysis, the function sub_18001010 consist of two parts.</p><p>1 — Decode the string</p><p>First it will decode a string that is passed in as argument which in this case is the value in the variable <em>aPrtPP0tnpnWsly</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*1fDVGzUIIlQUFCVbTsr8EQ.png" /><figcaption>Decode Section</figcaption></figure><p>This function decodes the characters by applying the concept of Substitution cipher where it takes the ASCII value of each character, add 28 follow by mod 81 and finally add 42. This is the formula for the substitution cipher that I had just describe: <em>plain_text = (cipher_text + 28) % 81 + 42</em>. Thus, the value of variable <em>aPrtPP0tnpnWsly</em> decodes into <em>RegisterServiceCtrlHandlerW</em> which is a Win32 API.</p><p>Using this formula, I wrote a simple python script to do the decryption and ran it on all the strings found in the same data section as <em>aPrtPP0tnpnWsly</em> and here are the decrypted strings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*imYgfwe_5zIVR_GgR7Kkqg.png" /><figcaption>Decoded String</figcaption></figure><p>Looking at the de-obfuscated strings, it seems like they are hiding function calls in strings and decode them during runtime so that we cannot most of its capabilities just from looking at imports table. From the list of the De-obfuscated strings, we can see that some of the capabilities of this malware includes creating thread and writing into memory.</p><p>2 — GetProcAddress</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*wZ-OwrVFEeybiXlQ-ZPvkw.png" /><figcaption>getProcAddress</figcaption></figure><p>Once the string is decoded, the function will then call <em>LoadLibraryA</em> and <em>GetProcAddress</em> before returning the address of the call.</p><p>Alright, now that we know that this malware has the ability to hide its function calls what’s next?</p><h4>Threading and New Processes</h4><p>Following down the <em>ILCreateFromPath</em>, I saw that the malware creates a new thread to execute the function called <em>StartAddress</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*JnmO7BANBe7wzn2vhNeplA.png" /><figcaption>Create New Thread</figcaption></figure><p>So the only thing to do is to follow and look at what does the <em>StartAddress</em> function do.</p><p>Looking through the <em>StartAddress</em> function, the first thing that caught my eyes is a variable containing the string “<em>%s\\dllhost.exe /Processid:{%s}</em>” followed by <em>CreateProcessW</em>. It looks like the malware is trying to create a <em>dllhost</em> process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*84VV5_zNgygRGFSfQvwUCQ.png" /><figcaption>Create New Process</figcaption></figure><p>After calling <em>CreateProcessW</em>, the malware then proceeds to call <em>VirtualAllocEx</em> followed by <em>WriteProcessMemory</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*0DU6GqY7MiTNEyq9j03c9Q.png" /><figcaption>Allocate And Write To Memory</figcaption></figure><p>From the above code, we can see that the malware used the <em>WriteProcessMemory</em> function to write the function <em>sub_181064570</em> into <em>dllhost</em> process created earlier. Although this seems to be a common process injection, it matches the checkpoint’s report, where it mentions that it injects itself to another process such as rundll32.exe and dllhost.exe.</p><h4>Decoding Embedded Data</h4><p>Finally, we have reached the part where we can see what this malware actually wants to do! This is how the first few lines of the function written into the process’s memory looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*_TCIJsAgMDb6fNGqrEf12w.png" /><figcaption>Write to Memory</figcaption></figure><p>It looks like the malware copying two sets of data located at <em>qword_181065CC0</em> into the memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*CQU_wgsOH3WshxmB4bHclQ.png" /><figcaption>Encoded Blob in Memory</figcaption></figure><p>After copying the data into the memory, the malware calls a function which will decode the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ICQfaKgR3QFBCAENBuqeA.png" /><figcaption>First Decoded Blob</figcaption></figure><p>The first blob of data contains the URL of the C2 server “<em>news.nyhedmgtxck.com</em>” and a string of characters which doesn’t seems to be used in any part of the execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*ZJneAXOsOoDmoG3sUp3onw.png" /><figcaption>Second Decoded Blob</figcaption></figure><p>And the second blob of data contains the imports table which the malware will use in the next phase of its activity. Wait a minute… does the 2 blobs of data sounds familiar?</p><p>From checkpoint’s report on aria-body loader, they mentioned that one of the functionality of the loader is to decrypt two blobs of data into an Import Table and a loader configuration.</p><h4>Download and execute payload</h4><p>By using the decoded import tables, the malware attempts to connects to the C2 URL to download a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*UZ-wT1RcxAS1WqrZW7d2NQ.png" /><figcaption>Download Payload</figcaption></figure><p>To this point, it actually matches the points mentioned in Check Point’s report where Aria-body contact the embedded / calculated C&amp;C address in order to download retrieve the next stage payload.</p><p>Too bad for us, the URL has already been sinkhole. Therefore, I am not be able download the sample for analysis ):</p><p>It’s not the end yet! Although I am not able to analyze the next stage payload, I am still able to see what this loader does before passing control to the next stage payload :D</p><p>Once the payload is downloaded, the malware will first decode the payload with a XOR function. The decoded payload will then reside only in the memory. Which suggest that it could be a file-less malware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*3IPpiSjY6wsVWxeMUcSjjg.png" /><figcaption>Decode Payload and Copy to Memory</figcaption></figure><p>Next, the malware then calls a function which checks if the payload contains the magic number “MZ” and “PE”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*AHnahoKLf_s74T5v2HLMfg.png" /><figcaption>Check for PE and Section Header</figcaption></figure><p>Once verified, the malware will finally get the entry point to the payload by calculating the djb2 hash of the payload’s export and comparing it with 0x2E9AD5FB. Without the second stage payload, I am unable to determine what is the export name based on that hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*TnxRH77UqIRdIiEMs_j5Xg.png" /><figcaption>DJB2 Hash</figcaption></figure><p>Finally, the malware then passes the execution control to the payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*VPkjI7kLjrHk7YzQEQWQuw.png" /></figure><p>The way this malware get the entry point also matches what Check Point had described where the loader loads and execute an exported function of the DLL — calculated using djb2 hashing algorithm.</p><h4>Conclusion</h4><p>Phew… Finally! We’ve reached the conclusion~~ v^^v</p><p>From the analysis, this malware looks like a loader which will download a payload from the C2 and execute the payload on the memory. The capabilities of this sample is very similar to the Aria-body loader that is described by Check Point where 5 out of the 7 points matching the analysis. I am unable to determine if this sample “establishes persistence via startup folder or run registry” and the “utilization of the DGA algorithm”. Putting the capabilities aside, I had look through the sample with the hash “40c49ecbe1b7bdodbb935138661b6ca4” mentioned in Check Point’s report and code wise, it looks vastly different from this sample.</p><p>Noticed that up to this point, I have only talked about the analysis of one of the samples. Well, I had done the analysis on both of the sample and in regards of the code executions, they are the same. The only difference between the two sample in regards to what is relevant to the execution and its function, is that the C2 string and the string of character in the first blob of data is different. Instead of going to “<em>news[.]nyhedmgtxck[.]com</em>”, the C2 of the other sample is “<em>www[.]etnwtmrkh[.]com</em>” both of which are sinkholed.</p><p>Therefore, based on the capabilities, am I right to say that this could be a variant of Aria-Body loader?</p><p>Hashes Analyzed:</p><blockquote>1e56c3f05bb53d2dfa60bc016e8509b12fd3beb5f567d274a184bb67af1eb19c</blockquote><blockquote>c5696e660f3cfa9232756418e40ad18729cfe32fb284bba2314dd523ba527258</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53bdd630f8a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/aria-body-loader-is-that-you-53bdd630f8a1">Aria-Body Loader? Is that you?</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quarians, Turians and…QuickHeal]]></title>
            <link>https://medium.com/insomniacs/quarians-turians-and-quickheal-670b24523b42?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/670b24523b42</guid>
            <category><![CDATA[quick-heal]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[quarian]]></category>
            <category><![CDATA[turian]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Sun, 29 Aug 2021 16:49:45 GMT</pubDate>
            <atom:updated>2021-08-29T16:51:54.057Z</atom:updated>
            <content:encoded><![CDATA[<p>I know, that third name in the title didn’t quite fit into the “Mass Effect” bucket. But hey, I was not the one who named this malware family ;)</p><p>A month or so ago, I took notice of a set of malware identified as “QuickHeal”, and I thought of looking into researching it. Turned out to be a pretty interesting piece of work I started. I found resemblances between QuickHeal and a malware detailed by ESET (1) dubbed as Turian. And this malware seemed to have been associated with many threat actors e.g. Nomad Panda, APT15, RedFoxTrot — all of which has somewhat similar victimology. Does that mean these groups are related somehow? Or perhaps they are in fact the same group that went by a different name to various security companies?</p><p>I’m going to share my findings on QuickHeal and its variants, hopefully someone out there finds it useful. And of course, I’ll be happy to chat on Twitter :)</p><p>The samples analyzed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RG6MeYL6I1lfQYOF62wyYg.png" /></figure><p>My starting point was the sample with hash C6B84755AF54768C0B8676CB6551DF1A29B4DFDDB04FAF4BBF7AE3E6DC3636E2.</p><p>This sample was identified as “QuickHeal” by FireEye researcher Ashley Shen in her “Return of IceFog APT” presentation in 2019. I analyzed this file in 2019, along with another sample I took notice from the presentation (FunRun, analysis of it here: <a href="https://medium.com/insomniacs/analysis-walkthrough-fun-clientrun-part-1-b2509344ebe6">https://medium.com/insomniacs/analysis-walkthrough-fun-clientrun-part-1-b2509344ebe6</a>)</p><p>Then recently, I found other samples that resembled QuickHeal which led to digging up many more other files. Coincidentally, I managed to get at least 1 sample with compilation year from 2012–2021. This allowed some comparison of features’ development across the years.</p><p><strong>A common feature: Faking SSL traffic</strong></p><p>This family of malware is sneaky! Its communications are made up of XOR-encrypted data that comes prepended with TLS/SSL header (I’m just going to refer to the protocol generally as SSL, the intricate differences doesn’t really matter since the malware just faked it). Network defenses would not suspect anything and allow these data to strut through port 443. Even if there is content inspection done by perimeter appliances, these traffic will not be decrypted properly like standard SSL. To make things even more believable, QuickHeal’s communications protocol even involve a SSL-like handshake procedure to exchange the XOR key with the C2. Let’s take a deep look at the protocol:</p><p><em>1 — Prepare and send “Client Hello”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*yKdjrCOMmf5NSvWKxYqBHQ.png" /><figcaption>Figure 1 Hardcoded SSL header seen within c6b84755af54768c0b8676cb6551df1a29b4dfddb04faf4bbf7ae3e6dc3636e2</figcaption></figure><p>The malware hardcodes a SSL header within itself, and generates random values at runtime that overwrites part of this header to give the impression of a real SSL handshake.</p><p>In the example shown in the screenshot above, 0x34 bytes of “Client Hello” header is loaded, and 0x1C bytes starting from offset 0xF of this header is replaced with random values (strictly speaking, the original values are XORed with random values). This header is then sent to the C2.</p><p>A breakdown of the hardcoded header shows that it follows the definition of SSL Client Hello structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*FY5Lv5x9WRfhe0oXqiwtyw.png" /><figcaption>Figure 2 breakdown of header structure using hardcoded value from c6b84755af54768c0b8676cb6551df1a29b4dfddb04faf4bbf7ae3e6dc3636e2</figcaption></figure><p>Here is another example of hardcoded header in a different sample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*T61aA_hEQ3SG7aN2f8H51g.png" /><figcaption>Figure 3 Hardcoded SSL header seen within 727093e220e39f73b341acf9cc5bff2c4fa727013173bdf4afac3e81399139e0</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*CwZabAoOlCKU6kzbtDnmVA.png" /><figcaption>Figure 4 breakdown of header structure using hardcoded value from 727093e220e39f73b341acf9cc5bff2c4fa727013173bdf4afac3e81399139e0</figcaption></figure><p><em>2 — Receive response from Server</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*oU8M0Op5WjvaiQdo3yPvbA.png" /><figcaption>Figure 5 disassembly snippet on first 5 bytes of data expected to be received in response to “Client Hello”, from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>The malware then expects to receive a response from the C2 server that would start with the byte “16”, followed by 2 bytes of length information in the 4th and 5th position, exactly like a standard SSL server response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*rRywtNXWdgANSe9U5TvgaA.png" /></figure><p>The length is read (ntoh) and checked to be smaller or equal to 0x3FF9. The malware then proceeds to continue to receive that number of bytes from the server, 1 byte at a time. The content received is not checked by the malware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*rHPH9tsi4J5dRATAiWxPiA.png" /><figcaption>Figure 6 disassembly snippet on rest of data expected to be received in response to “Client Hello”, from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p><em>3 — Prepare and send “Client Key Exchange”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*uH3bh4Sa0iqH-6efbV9Xiw.png" /><figcaption>Figure 7 disassembly snippet on next part of handshake sent to C2, from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>After all expected bytes have been received from the server, the malware then replaces bytes at 3 locations within another hardcoded SSL-like data with random values. One of these random values is to be used to derive XOR key after an exchange with the C2 server. The structure breakdown is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*mxjTXu_gPiYiefGdjS5KZA.png" /><figcaption>Figure 8 breakdown of next header structure using hardcoded value from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>Here is an example from another sample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*NnuKcnHWYpc36sDh_rRRMg.png" /><figcaption>Figure 9 breakdown of next header structure using hardcoded value from d014bf062872eb8ba138bf3a70f96cdcf90f6bae7369e62971821e0ddbd2cc5f</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*WLHrUggNbwUmzy5q-UXKvQ.png" /><figcaption>Figure 10 disassembly snippet on generating malware-side random value to form final XOR key for communications, from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>The 28 bytes of malware-side value(client key) is generated within a function during the malware initialization stage. This client key is used with the 28 bytes (server key) received from the C2 server to derive the final XOR key used to XOR-encrypt subsequent communications between the malware and the C2, where the encrypted is appended to the SSL Application Data header to pass off as standard SSL communications.</p><p><em>4 — Receive response from Server</em></p><p>The expected response from the server comes in 2 parts:</p><p>First the malware receives 5 bytes, check that it begins with 0x14, check for the length (just like before), and continue to receive the remaining bytes (the contents are not checked);</p><p>The second part expected contains important content. The malware also starts with receiving 5 bytes, check that it begins with 0x16, and then check the length of data to receive, followed by receiving the rest of the data. This data contains the server key, and along with the earlier generated client key, the final communications’ XOR key is derived in an algorithm as such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*i4eYbblnnmw_dd4GlzYNpg.png" /><figcaption>Figure 11 decompiled function from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>The above 4 steps that I’ve describe correspond (sort of, with some length differences) with a diagram from ESET, which was how I was able to correlate the QuickHeal sample that I had started with, to the Turian malware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*7QJkHE_xp34qz_7N2QTZ5g.png" /><figcaption>Credits: ESET</figcaption></figure><p><strong>Aliens, aliens everywhere: Comparison analysis</strong></p><p>I’ve checked across all the samples and found similar fake SSL handshake exchange. There are some changes in the samples as the years go by. For example…</p><p><em>The final XOR key</em></p><p>The algorithm to derive the final XOR key differs slightly between the oldest sample (compiled 2012) and the newer ones. The keylength is also different — used to be 8 bytes, and latest sample we are seeing 28 bytes keys. Here’s how the function that derives the final XOR key differs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*yn4MhLYVo5cD12UxE9O2gw.png" /><figcaption>Figure 12 comparing 0ae045cad78021e0772ee49c1c135091bc64a91c8e940e3746785603178a10f6 and 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>The 8-bytes XOR key derivation within the 2012 sample has been documented by Cisco Talos (2).</p><p>I tried to compare across all the samples and found one interesting observation. The 8 bytes key was replaced with 28 bytes from 2013 onwards. But one particular sample compiled in 2020 also used 8 bytes key. And I found that the 2012 sample and 2020 sample are of the same variant (with similar command IDs supported). More on this later. Based on VirusTotal’s submission information, this sample was uploaded by a user in China on 15 Jul 2021. Is this a test sample uploaded by the malware author or operator?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fQxLaV1KGM9bFRioJA_e1g.png" /><figcaption>Figure 13 compare get_final_xorkey from samples across the years</figcaption></figure><p><em>A more believable handshake</em></p><p>The “SSL” handshake observed within the 2012 sample is much shorter (only 1 send and 1 receive involved) than the later samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*WRDBda39PMPSBO89ylEEyA.png" /><figcaption>Figure 14 disassembly snippet on simple handshake, from 0ae045cad78021e0772ee49c1c135091bc64a91c8e940e3746785603178a10f6</figcaption></figure><p>Another interesting observation when doing comparison between 2012 sample and 2020 sample — the “SSL” handshake process in the 2020 sample is the “better” one (or at least, bear closer resemblance to the real SSL handshake). However, when examining the shape of the graph, it still looks different from the other samples. So it is not the case of simply recompiling old code. From Figure 15, notice how the 2021 sample’s graph for the same function also changed from earlier samples. Suggests that this malware family is still under active development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z9sSEOwQlF3rZLuQ1p9nRQ.png" /><figcaption>Figure 15 compare graphs of “SSL” handshake process across all samples</figcaption></figure><p><em>C2 configuration</em></p><p>I will go through each sample by the years, to see how the “evolution” happened for how the malware handles its C2 configuration.</p><p>In the 2012 sample, the C2 configuration is embedded within the code in the form of a singlebyte XOR-encoded string:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*kqOrxQhNzj7XyV-PuPknxw.png" /><figcaption>Figure 16 disassembly snippet on reading C2 data, from 0ae045cad78021e0772ee49c1c135091bc64a91c8e940e3746785603178a10f6</figcaption></figure><p>The decryption algorithm is as follows, where the XOR key value is incremented starting with 0x38.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*G430BC_UcD-wlnjwc6qIRQ.png" /><figcaption>Figure 17 disassembly snippet on decrypting C2 string, from 0ae045cad78021e0772ee49c1c135091bc64a91c8e940e3746785603178a10f6</figcaption></figure><p>Here’s a quick python snippet to decrypt the C2 address:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*tWuu8zj4VsRMdxZyP1gXbw.png" /></figure><p>The algorithm found in the 2013 and 2015 samples is slightly different from the above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*yBl7bGpow_VrOccxR8JlLw.png" /><figcaption>Figure 18 disassembly snippet on reading C2 data, from 836f7cf5190efd313cad36acd794c19b199d6d1807675d453eedf270116a12ee</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*E9D5adqVHl-i9C-f0hriyw.png" /><figcaption>Figure 19 disassembly snippet on reading C2 data, from a3a7faa58dac9b5d3e4640df62cce2d41605d5d43153630b796cb53fcd19a6ff</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*n0oRrzGBBOl3skaEqdvf3w.png" /><figcaption>Figure 20 disassembly snippet on decrypting C2 string, from 836f7cf5190efd313cad36acd794c19b199d6d1807675d453eedf270116a12ee</figcaption></figure><p>In the 2014 sample, there are no encrypted C2 addresses — we are able to see the configuration in plain. The malware writes a secondary set of configuration information into an .ini file (the ini filename follows the malware’s filename). The configuration information written include: the secondary C2 IP address, port number, username and password.</p><p>The malware will first try to establish connection with the primary C2 address, if that fails, then it will read proxy settings from the victim machine and try again. If that still fails, then it proceeds to read the ini file for the secondary C2 configuration and try connection with that second address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*NjEs_TeGfiR5ZxOJWaAd0Q.png" /><figcaption>Figure 21 disassembly snippet on reading C2 data, from 3af4f3a9a0210a1021d01b18b623367699bab6273fb42d2f028c1600ecda3ddb</figcaption></figure><p>C2 configuration in 2016 sample is also not encrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*Xr8X5L3hG0KcLMbpzcGS0w.png" /><figcaption>Figure 22 disassembly snippet on reading C2 data, from 727093e220e39f73b341acf9cc5bff2c4fa727013173bdf4afac3e81399139e0</figcaption></figure><p>2016 sample is a nice sample to reverse engineer, because it comes with many debugging comments :D I’ll show some of these in the next section, when I talk about the RAT features.</p><p>The 2017 sample’s C2 configuration is also in plain, and looks similar to what was found in the 2015 sample. However there is no “.ini” file being used in here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*hUrUtPH2mpI4QOIrddBoIA.png" /><figcaption>Figure 23 disassembly snippet on reading C2 data, from c6b84755af54768c0b8676cb6551df1a29b4dfddb04faf4bbf7ae3e6dc3636e2</figcaption></figure><p>The 2018 sample is worth taking a good look at — it comes with RTTI, so we can see helpful names which helps us to understand the other samples as well :D Let’s see how it stores its C2 configuration — no encryption, and looks similar to the earlier samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*LvXAJKqb6XE0fDc1O5UoOA.png" /><figcaption>Figure 24 disassembly snippet on reading C2 data, from aa5a313d1f0cbbf6900e55a16a6737068d9d8831a7ad49b285d5796aa589036a</figcaption></figure><p>I have 2 samples which are compiled in 2019. Previously, we have noticed that the function graphs of “SSL” handshake as well as the derivation of final XOR key differ in these two samples. Here, we see that the C2 configuration function in both samples are identical. Seems to suggest that there is one source code shared between the two binaries, yet each has its own changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*6tBpHzWgwZ4KsZ5mB1w8zA.png" /><figcaption>Figure 25 disassembly snippet on reading C2 data, from 7bb281fb5bce830c60610c4b75bd024ccb9b18f8e38f7ad9991259071eeb0350</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*ra05FwfvO3j4iNMR27BeUA.png" /><figcaption>Figure 26 disassembly snippet on reading C2 data, from 271d4b9ee4d563953f41193c98a6687418166b96185e8b87052863f0ae705048</figcaption></figure><p>Notice how the functions in these samples so far sort-of resemble one another, despite the differences in how the C2 strings are being read. This changed in the sample compiled in 2020.</p><p>In the 2020 sample, the C2 configuration and the function that handles the startup of the malware is vastly different from the earlier samples. There was also an attempt to look for a running process named “cvnjmpcp.exe” which I would think is the name of the malware process (so this is to ensure there is only 1 instance of malware executing on the victim).</p><p>There is a loopback address found in plain. There is also a “fallback” encrypted C2 address, but this secondary C2 address is not found alongside the loopback address within the function unlike earlier samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*WbUZiHvd24IYGmuJHCo6Ag.png" /><figcaption>Figure 27 disassembly snippet on decrypting secondary C2 address, from d014bf062872eb8ba138bf3a70f96cdcf90f6bae7369e62971821e0ddbd2cc5f</figcaption></figure><p>The secondary C2 address is found when following the malware’s attempts to connect to the C2.</p><p>The decryption algorithm is also different from earlier samples (2012, 2013 and 2015). Although it is also a XOR-decryption, but the XOR key used is not a simple incremented counter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*SNG7BMdNI7Jg5qDXLeb2DQ.png" /><figcaption>Figure 28 disassembly snippet on C2 string’s decryption function, from d014bf062872eb8ba138bf3a70f96cdcf90f6bae7369e62971821e0ddbd2cc5f</figcaption></figure><p>Here’s a python snippet to decrypt the C2 string for this sample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*57n4ifPQ7eZyjh7m0w6rNw.png" /></figure><p>There are also additional configuration and log files being used by the malware, named “cf” and “the.db” respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*DWXTekhZ-SeMAVEG7fslHQ.png" /><figcaption>Figure 29 disassembly snippet on writing error message into “the.db” file, from d014bf062872eb8ba138bf3a70f96cdcf90f6bae7369e62971821e0ddbd2cc5f</figcaption></figure><p>The configuration file only seems to contain a 4 byte value that is used as sleep interval. In earlier samples, this configuration file would be named “.ini” and contain C2 information as well. This is yet another change found within this sample.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*lB-DC7yLwJqoDwE5ThQAJA.png" /><figcaption>Figure 30 disassembly snippet on reading sleep interval from “cf” file, from d014bf062872eb8ba138bf3a70f96cdcf90f6bae7369e62971821e0ddbd2cc5f</figcaption></figure><p>The latest sample compiled in 2021 contains C2 configuration decrypted in a different manner as the previous samples. The XOR key used is an incremented counter XORed with the value 0x7E (previously the key used was an incremented counter added to a fixed value). The way that the encrypted string is being stored and used within the code is a little different from the other samples. These changes suggest that there is an effort from the adversary to keep changing the binary (especially in recent years) in attempt to make reverse engineering less convenient. It may also not be a deliberate effort, but an unintended side effect due to different teams editing and recompiling the malware (stemmed from the same source code).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*uv-ME7EEc0dO_U00WOG2sQ.png" /><figcaption>Figure 31 disassembly snippet on decrypting C2 string, from e4fdb279a4792ad516592076ce9a6a40c803af84bcc2e2e4f9ee48df6af9e88b</figcaption></figure><p><em>Persistency Mechanism</em></p><p>The code for setting persistency also changed across the years:</p><p>In the earliest sample, the approach is to directly set the Run regkey:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*FO6P5eP644oZHe-_tMt9Zw.png" /><figcaption>Figure 32 decompiled snippet on modifications to registry values, from 836f7cf5190efd313cad36acd794c19b199d6d1807675d453eedf270116a12ee</figcaption></figure><p>Later on, the malware does the Run regkey insertion and removal through the use of a .bat file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*YaaRiwXBZqs6LfbVk7IDIQ.png" /><figcaption>Figure 33 decompiled snippet on writing commands to modify registry values to bat file, from 3af4f3a9a0210a1021d01b18b623367699bab6273fb42d2f028c1600ecda3ddb</figcaption></figure><p>The malware also seems to like using a mix of upper and lowercase letters to be written into the bat file, possibly to avoid string matching detections (but ironically made it possible for us to write YARA rules for them).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*CHAv9CS7_YuRUscm7cCj_Q.png" /><figcaption>Figure 34 disassembly snippet on hardcoded commands used to modify registry key, from a3a7faa58dac9b5d3e4640df62cce2d41605d5d43153630b796cb53fcd19a6ff</figcaption></figure><p><strong>Here’s where the roads diverge: The commands / RAT features</strong></p><p>While the network-related functions are almost the same, and the other features that I compared suggested minor changes to the code, the command IDs accepted by the RAT can be used to clearly classified into 2 variants (though the actual features are more or less the same). I’m not exactly sure how the community now differentiates “Quarian” and “Turian”, and I’m not going to contribute more confusing names to this set of malware. They shall just be QuickHeal variants to me.. I’m more than happy to chat about this, drop me a DM on Twitter :)</p><p>I was able to figure out the command IDs being accepted by the malware, based on the big switch table found that handles data received from the C2 server. Here’s the breakdown of command IDs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*PJEVBT2-7wRxeUzH1pXEjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*XJMQkqTDDqf77vSH-i5JNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOaireycBiycP-jHFpWxGg.png" /></figure><p>Two of the samples (compiled in 2016 and 2018) made understanding the other samples much easier with RTTI and debugging strings compiled into the binaries :)</p><p>Some of the debugging strings (printed via OutputDebugString) within the 2016 sample are:</p><p>· [%08X]: CClient::Connect(%S:%d)…</p><p>· [%08X]: CProtocolClient::ShakeHands() OK</p><p>· [%08X]: CProtocolClient::Connect() OK</p><p>The malware refers to the function that performs the fake SSL handshake as “ShakeHands”. Cute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*yJlR7wQhV000dh560scing.png" /><figcaption>Figure 35 disassembly snippet showing debugging strings to denote status of connection to C2 and fake SSL handshake, from 727093e220e39f73b341acf9cc5bff2c4fa727013173bdf4afac3e81399139e0</figcaption></figure><p>The 2018 sample comes compiled with RTTI. The classes in the malware are:</p><p>· CClient<br>· CProtocolClient<br>· CNetwork<br>· CCrypt<br>· ProxyOperation<br>· TransferParam</p><p>Notice how some of these class names were also in the 2016 sample (within the debugging strings).</p><p>If you’re interested, here are details of how the set of Command IDs in each sample are different from one another.</p><p><em>2012 Sample</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*2pynKfG0-ZuBtjR9Grn-IA.png" /></figure><p>Victim information collected includes:</p><ul><li>OS Version</li><li>Memory</li><li>Hostname</li><li>IP address</li><li>Username</li></ul><p><em>2013/2014 Samples</em></p><p>The overlapped commands e.g. file-related commands, look very much like in the 2012 sample, though the command IDs changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DcGWP-KIqksjHsnvy85QVw.png" /></figure><p>Victim information collected includes:</p><ul><li>OS Version</li><li>Memory</li><li>Hostname</li><li>IP address</li><li>Username</li><li>Malware configuration (C2 addresses, ports, username, password)</li></ul><p><em>2015 Sample</em></p><p>The command IDs look similar to the 2013/2014 samples. The differences/improvements are:</p><ul><li>1 new command ID supported 0x100 that serves as a server heartbeat</li><li>1 new command ID supported 0x800 that gives the ability to update the C2 address</li><li>change in 0x600 that turned it into a dedicated malware removal command</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNe-uRsO5Fv9J36ej671ig.png" /></figure><p><em>2016 Sample</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TDtIIb71tB_o2CFBTyRQuw.png" /></figure><p>Victim information collected includes:</p><ul><li>OS Version</li><li>Memory</li><li>Hostname</li><li>IP address</li><li>Username</li><li>Computer role (acronyms used within data sent to C2)<br> o Standalone Workstation — [WW]<br> o Domain Workstation — [DW]<br> o Standalone Server — [WS]<br> o Domain Server — [DS]<br> o Domain Backup Controller — [DC]<br> o Domain Primary Controller — [DP]<br> o Unknown — [UK]</li><li>Malware configuration (C2 addresses, ports, username, password)</li></ul><p><em>2017 Sample</em></p><p>This sample’s command IDs look very much like the ones found in 2015 sample. It comes with the set/unset Run regkey in command 0x600 and the close connection command in 0x400 (I’m not sure why there are 2 command IDs that does connection closure). The ability to update C2 address with command ID 0x800 is gone in this variant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u0w0zPlXOTlzgjFRk8qVoA.png" /></figure><p><em>2018 Sample</em></p><p>This sample introduced 2 major features as an improvement from earlier samples of the same variant:</p><ul><li>Command ID 0x5 which starts interactive shell</li><li>Command ID 0x6 which starts a relay between newly defined sockets and the C2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dyw5aLxC0qJemfj1QqK_tQ.png" /></figure><p><em>2019 Sample</em></p><p>The samples compiled in 2019 are different from the others: the command IDs/RAT features seem to be minimal. Nevertheless, the code overlaps within the implementation of these features remain to be seen, so I’m still certain these are QuickHeal variants.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZMOzjE8qjptDhCm1jfDRQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZBB0yTI4JkFr42_lxODwA.png" /></figure><p><em>2020 Sample</em></p><p>The sample that was compiled in 2020 bear strong resemblances to the sample compiled in 2012. The only difference in the command IDs supported is that 0x4 will now terminate the malware instead of doing nothing.</p><p><em>2021 Sample</em></p><p>This latest sample has command ID 0x600 “removed”, otherwise all the other command IDs and implementations are identical to the 2018 sample.</p><p><strong>Last Words</strong></p><p>As I lack the telemetry on the victims receiving these malware, I’m not able to provide further insights on whether these samples are different because they are used on different geographical campaigns (and thus edited by different operators), or because there are many versions of QuickHeal builder (which was improved over the years). I can almost guess that there is some sort of a “checkbox” that the user can click on to select Command IDs (features) to be compiled into the binary. Really would be interesting if there can be more information available :)</p><p>===</p><p>Hashes analyzed in this post:</p><p>0AE045CAD78021E0772EE49C1C135091BC64A91C8E940E3746785603178A10F6</p><p>836F7CF5190EFD313CAD36ACD794C19B199D6D1807675D453EEDF270116A12EE</p><p>3AF4F3A9A0210A1021D01B18B623367699BAB6273FB42D2F028C1600ECDA3DDB</p><p>A3A7FAA58DAC9B5D3E4640DF62CCE2D41605D5D43153630B796CB53FCD19A6FF</p><p>727093E220E39F73B341ACF9CC5BFF2C4FA727013173BDF4AFAC3E81399139E0</p><p>C6B84755AF54768C0B8676CB6551DF1A29B4DFDDB04FAF4BBF7AE3E6DC3636E2</p><p>AA5A313D1F0CBBF6900E55A16A6737068D9D8831A7AD49B285D5796AA589036A</p><p>7BB281FB5BCE830C60610C4B75BD024CCB9B18F8E38F7AD9991259071EEB0350</p><p>271D4B9EE4D563953F41193C98A6687418166B96185E8B87052863F0AE705048</p><p>D014BF062872EB8BA138BF3A70F96CDCF90F6BAE7369E62971821E0DDBD2CC5F</p><p>E4FDB279A4792AD516592076CE9A6A40C803AF84BCC2E2E4F9EE48DF6AF9E88B</p><p>===</p><p>[1] BackdoorDiplomacy: Upgrading from Quarian to Turian</p><p>[2] Quarian: Reversing the C&amp;C Protocol</p><p>~~</p><p>Asuna | <a href="https://twitter.com/AsunaAmawaka">https://twitter.com/AsunaAmawaka</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=670b24523b42" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/quarians-turians-and-quickheal-670b24523b42">Quarians, Turians and…QuickHeal</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Volatility 3 — Downloading Windows Symbols for Volatility 3 on Air-gapped Machines]]></title>
            <link>https://medium.com/insomniacs/volatility-3-downloading-windows-symbols-for-volatility-3-on-air-gapped-machines-7bf7a63521c7?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/7bf7a63521c7</guid>
            <category><![CDATA[volatility-3]]></category>
            <category><![CDATA[windows-symbols]]></category>
            <category><![CDATA[isolated]]></category>
            <category><![CDATA[airgapped]]></category>
            <dc:creator><![CDATA[geumland]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 02:26:03 GMT</pubDate>
            <atom:updated>2021-01-28T04:04:03.338Z</atom:updated>
            <content:encoded><![CDATA[<h3>Volatility 3 — Downloading Windows Symbols for Volatility 3 on Air-gapped Machines</h3><p>For those who does or had done memory analysis before would most likely have heard of volatility, and are most likely using it for your own analysis work.</p><p>In 2019, Volatility 3 which is a complete re-write of the previous framework, is released. The new version aims to address many of the technical and performance challenges see in previous versions. For me, I feel that the biggest benefit of transiting to the use of Volatility 3 is that there is no need to worry about the windows profiles to be used.</p><p>Most of the time when I have the time, I usually try to hone my knowledge in malware analysis. Seldom do I try out memory analysis actually. But the few times which I tried in the past, especially when dealing with memories captured from Windows 10, I remember having the struggles of getting the right profile. Also, if the Windows 10 has the latest update, and the corresponding profiles and structures has not been released in Volatility, then I would not be able to analyse the memory unless I am able to create the structures on my own which is too technical for me xp. Imagine if this happens in a real investigation, then the memory (which may contain many significant evidence) may be deemed useless.</p><p>So when I realised, a few days ago when I try out memory analysis again, that there is a new Volatility 3, and that profiles had been done away with, I was super excited.</p><p>True enough, Volatility 3 is much more straightforward and I do not have to worry about the type of OS the memory capture was from. In order for Volatility to examine the memory capture correctly, the corresponding symbol table for the OS are needed. The symbol tables for various OS had been pre-packed into symbol table packs available for download at the github of Volatility. However, according to Volatility, the pre-packaged symbol table pack is <strong>only complete at the point of creation of the OS</strong>. Simply said, the pre-packaged symbol table pack is not complete. In fact, I tried doing analysis on a few different memory images from different Windows OS versions and of different updates, and most of the times, there are missing windows symbols.</p><p>So what happens if there is missing windows symbols?</p><p>According to the documentation on Volatility 3, for Windows systems,</p><p><em>“Volatility accepts a string made up of the GUID and Age of the required PDB file. It then searches all files under the configured symbol directories under the windows subdirectory. Any that match the filename pattern of </em><em>&lt;pdb-name&gt;/&lt;GUID&gt;-&lt;AGE&gt;.json (or any compressed variant) will be used. If such a symbol table cannot be found, then the associated PDB file will be downloaded from Microsoft’s Symbol Server and converted into the appropriate JSON format, and will be saved in the correct location.”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*bz_zAH5gfzBMumP4BOSiCg.png" /><figcaption>Files in symbols folder of Volatility 3</figcaption></figure><p>But what if, you do not have internet connection? Obviously Volatility 3 would not be able to download the required windows symbols, and you will get the following error without having your memory capture analysed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*BX0hfn796lQ1RKuY9L6LIg.png" /><figcaption>Volatility 3 is unable to connect to internet</figcaption></figure><p>So what do we do? We would have to do what Volatility would do, manually. I.e. we would have to find the name of the required pdb, the pdb’s GUID and AGE, download it from Microsoft public symbol server, convert it into json and put it in Volatility’s symbols folder.</p><p>In case you need, I had described the steps in details below.</p><p>*Note: If anyone has better idea, please feel free to share.</p><h3>Step 1: Run Volatility with -vvv</h3><p>I am not exactly sure what -vvv does, but apparently it outputs all the debug messages of Volatility. Using this, you will be able to find out the exact windows symbols Volatility needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2csPCQovE_zgcBZPG_jfBQ.png" /></figure><p>“http://msdl.microsoft.com/download/symbols” is Microsoft public symbols server. This is the location where Volatility will try to download the missing symbols from. “ntkrnlmp.pdb” is the pdb file of the symbol Volatility 3 requires, while “A641F14B11335DF730C980BC383D20291” is the combination of the GUID (first 32 characters) and AGE (last digit) of the pdb file.</p><h3>Step 2: Create Manifest File</h3><p>Although Microsoft do not provide offline windows symbols packages anymore, they still recognise that there are cases where one would need to retrieve symbols for file on an isolated computer.</p><p>Therefore, SymChk (a utility in Windows debugging kit), is made available, and when used with the <strong><em>/om</em></strong> parameter, it creates a manifest file that describes the files for the symbols to be retrieved. Using SymChk again, but with the parameter <strong><em>/im</em></strong> instead, it takes in the Manifest file and downloads the required from the public server. In normal circumstances, this is what you can do. Unfortunately, for Volatility 3, SymChk with <strong><em>/om </em></strong>parameter cannot be used. Having said that, even though we cannot create the manifest file automatically, we can create our own manifest file manually.</p><p>The format of the manifest file is very simple. Each row correspond to the respective pdb file to be download. It contains the name of the pdb, the combination of GUID and AGE, and the last field an integer number which I am not sure what it represents (I just put “1”). An example of the manifest file I had created based on the required symbol file shown in Step 1 is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*lXXQgIT7QV80KAFl1fQIYA.png" /><figcaption>Create manifest file manually</figcaption></figure><h3>Step 3: Download the Required Windows Symbols PDB</h3><p>To do so, move the created Manifest file onto a machine with internet connection. Make sure you have Windows debugging kit installed.</p><p>Traverse to the folder of your debugging kit. For me, it is “C:\Program Files (x86)\Windows Kits\10\Debuggers\x64”.</p><p>Then run the SymChk command as follows:</p><p>symchk.exe /im &lt;path of manifest file&gt; /s srv*&lt;path to store the downloaded pdb&gt;*https://msdl.microsoft.com/download/symbols</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIH0K3H_i62sv3GcwYEdJw.png" /></figure><p>Note that you need to make sure the path to store the downloaded pdb exists, else the download would fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*s0da7Hv-Qwl7SuqCjAnp1A.png" /><figcaption>Pdb downloaded and stored in the specified location</figcaption></figure><h3>Step 4: Convert the PDB to JSON</h3><p>The next step is to copy and move the downloaded pdb back to your isolated machine with Volatility 3.</p><p>In Volatility 3, the python script that is responsible to convert pdb to json is <em>“</em><strong><em>volatility/framework/symbols/windows/pdbconv.py”</em></strong>. So feel free to use this script to convert your newly downloaded pdb to json manually. Example shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*BCpRizU9_Q4u3OkXeGd-_w.png" /><figcaption>Converting pdb to json</figcaption></figure><h3>Step 5: Move the converted JSON to Volatility Symbols folder</h3><p>Once successfully converted, name the converted JSON to <strong><em>“&lt;GUID&gt;_&lt;AGE&gt;.json”</em></strong>. Then move the file into the respective odb folder in <strong><em>“volatility\symbols\windows\”.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*laN0rTQzQtqijSwCiU8N2A.png" /></figure><p>Note: It does not matter if the file is “<strong><em>.json</em></strong>” (not compressed) or “<strong><em>.json.xz</em></strong>” (compressed). If it is compressed, Volatility would uncompressed it before using.</p><h3>Step 6: Examine Your Memory Capture</h3><p>Now with all things set, you can go ahead and examine your memory capture without any issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*f-qM5HShhaz4hf6Uo1Dqng.png" /><figcaption>Executing Info plugin on memory without error</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nsZnsbVipCDM1c8z_dKTw.png" /><figcaption>Info plugin results</figcaption></figure><p>Although I could not really think of situations where we would need to run Volatility on an isolated machine, I still continue to write this post in case someone really needs it, as I find that there is a lack of solutions and answers online with regards to the problem I tried to address in this post. In fact, most of the solutions I found to solve the problem are just “connect your machine to internet”. But what if someone really do not want or could not connect their analysis machine with internet? For this someone, I hope my post would be of help to you. =)</p><p>~Back to geumland</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bf7a63521c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/volatility-3-downloading-windows-symbols-for-volatility-3-on-air-gapped-machines-7bf7a63521c7">Volatility 3 — Downloading Windows Symbols for Volatility 3 on Air-gapped Machines</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Look into SUNBURST’s DGA]]></title>
            <link>https://medium.com/insomniacs/a-look-into-sunbursts-dga-ba4029193947?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/ba4029193947</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[sunburst]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Sun, 20 Dec 2020 17:02:01 GMT</pubDate>
            <atom:updated>2020-12-22T17:51:58.632Z</atom:updated>
            <content:encoded><![CDATA[<p>Many fellow researchers have written very good analysis on SUNBURST malware, so I shall not do a walkthrough on reverse engineering it. But I’ve been intrigued by the domain generation algorithm. The RedDrip Team wrote a nice decoder [1]. Folks at NETRESEC has an improved version [2]. However, there are still some generated DGA strings that cannot be decoded. I want to know what these are! *Edit: Just moments before I click on Publish for this post, I saw that Kaspersky’s analysts wrote their code in C [3] with nice writeup [4] that also handled decoding of all two types of DGA string. But hey, I got Python :)</p><p>Before I go on to explain what I did to decode these DGA strings, I would like to summarize the related functions and variable names so you won’t be lost.</p><p>Victims of SUNBURST are uniquely identified with a GUID that is created within <em>OrionImprovementBusinessLayer.GetOrCreateUserID()</em>. This GUID is a 8-byte value made up of the victim machine’s MAC address, MachineGUID value read from HKLM\Software\Microsoft\Cryptography\MachineGuid and the victim machine’s domain name. These three information are concatenated and MD5-hashed. The MD5 value is then “cut” into 2 and XORed (where 1st byte is XORed with the 9th byte; 8th byte is XORed with 16th byte), hence we end up with a 8-byte irreversible unique identifier.</p><p><em>OrionImprovementBusinessLayer.Update()</em> is the function that calls the respective functions to generate the DGA strings and responsible for handling the stuff that happens after a DNS response is received.</p><p><em>OrionImprovementBusinessLayer.CryptoHelper.GetStatus() </em>returns the concatenation of “.appsync-api.&lt;one of four below&gt;.avsvmcloud.com”.</p><ul><li>eu-west-1</li><li>us-west-2</li><li>us-east-1</li><li>us-east-2</li></ul><p>Four functions within <em>OrionImprovementBusinessLayer.CryptoHelper </em>are the ones that are called upon to generate the DGA strings:</p><p><em>GetNextStringEx()</em>, <em>GetNextString()</em>, <em>GetPreviousString() </em>and <em>GetCurrentString()</em>.</p><p>Within them, the functions <em>CreateSecureString()</em>, <em>CreateString()</em>, <em>DecryptShort()</em>, <em>Base64Decode()</em> and <em>Base64Encode()</em> are responsible for the encoding process.</p><p>(At this point, I would like to comment on the names of the functions and variables — geez most of them are not in any way descriptive of the actual meaning of the task they perform or the value they hold. If anything, they are there to mislead the analyst.)</p><p><em>CreateSecureString()</em> does nothing to create secure strings. What it really does is XOR-encode some data with a random byte as XOR key, prepend this byte to the data and then return a Base32-like encoded string of the data. The Base32-like encoding is performed by <em>Base64</em><strong><em>En</em></strong><em>code()</em>. Look at that nasty confusing name!</p><p>The other related function, <em>Base64</em><strong><em>De</em></strong><em>code() </em>is sort of a substitution cipher where by default the characters’ are shifted by 4 to the right according to a custom alphabet. If a special character “0”, “.”, “-“ or “_” is encountered, then a random shift value is selected. Either <em>Base64</em><strong><em>De</em></strong><em>code() </em>and <em>Base64</em><strong><em>En</em></strong><em>code() </em>is called within <em>DecryptShort().</em></p><p><em>CreateString()</em> creates a 1 byte value that encodes the index of the DGA string. In the event that multiple DGA strings are required to fully represent the victims’ domain, this index numbering (I call it the “chunk index”, and it ranges from 0 to 35) will help the receiving end to piece back the domain. This is because the DGA string is capped at 32 bytes (excluding the fixed “.appsync-api…avsvmcloud.com”), so encoded victim’s domain that is longer than 16 bytes would have to be expressed across multiple DGA strings (the first 16 bytes in each of such DGA string is taken up by victim’s GUID and the chunk index). Having a chunk index of 35 means that this DGA string is the last piece.</p><p>To explain this concept of “index numbering”, let’s look at the output of my decoder. After decoding the victim GUID and the index, I was able to link up two DGA strings (involving abit of manual searching) that makes up one victim’s domain. Chunk Index of “0” means it is the first piece, and Chunk Index of “35” means it is the last. If there had been another piece in the middle, it would be index “1”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*NUHPuDRf-m1iVohSneOEkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*AlkSK60H2ewxUpIcYqVNaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xbmi9gEAErbzxLTb0sSexQ.png" /></figure><p>What made decoding the victims’ domain possible is because the malware generated the DGA string via GetPreviousString() and GetCurrentString(). The victims’ domain is encoded and included in the DGA string through the variables dnStr and dnStrLower. The decoders out there would try to reverse the DGA string to decode dnStrLower to retrieve the victim’s domain.</p><p>This is how the DGA string would look like. I call this “Type 1” DGA string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rOo2UUA7L9lTAixSatBZjg.png" /></figure><p>Notice that in GetNextString() and GetNextStringEx(), dnStr and dnStrLower are not used. Instead, another function UpdateBuffer() is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*on0_mTFVEnv8qS0e8JzGpw.png" /></figure><p>As such, a different kind of DGA string is generated. I call this “Type 2” DGA string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BX2j6J4RkRQ_v-SlUJtemA.png" /></figure><p>Within UpdateBuffer(), a 3-bytes time value is calculated through GetStringHash(). The last two bytes of this time value is going to be used as the XOR key to encode the 8-bytes victim GUID. UpdateBuffer() returns a 11-bytes value made up of 8-bytes encoded GUID and 3-bytes time/XOR key. If data is provided to the function (data that describes the number of security tools’ processes present somehow), then UpdateBuffer() returns a 13-bytes value, with the additional 2 bytes appended behind the time/XOR key.</p><p>The value is then encoded through CreateSecureString(), which applies the Base32-like encoding. The ending DGA value is a 20 or 23 bytes string. Interesting. I can use this as a condition to identify this form of DGA string.</p><p><strong>Alright, stop talking. Let’s decode!</strong></p><p>I made 2 assumptions to try to differentiate between the two types DGA strings.</p><p>- If the decoded chunk index is 0, the length of the DGA string cannot be less than 32 bytes (which should not be happening, because if data is “overflowing” into another DGA string, then the first should be filled up to the max length). Else, it could be a Type 2 DGA string.</p><p>- If chunk index is successfully decoded to 35, then it is a Type 1 DGA string.(what are the chances of getting this exact value using the 16th byte and the 1st byte? I think low enough for this assumption to work.)</p><p>Along with the expected length for Type 2 DGA strings, I’m able to come up with the following if-else checks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*9uCvbLMFICvjFw2xIAiNKA.png" /></figure><p>With the decoded Victim GUIDs from Type 1 and Type 2 DGA strings, we can identify the related DNS queries, and how many different machines are infected within the same domain.</p><p>Let’s see some examples. I worked with data from here: <a href="https://github.com/bambenek/research/blob/main/sunburst/uniq-hostnames.txt">https://github.com/bambenek/research/blob/main/sunburst/uniq-hostnames.txt</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*A3yCqMegYek7AWy33MJDDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FXsysKOpKNeVCsnG7g61Hw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*kub8rK3j2GDWCoCQ8f3mOw.png" /></figure><p>If anyone has a list of all such DNS queries from within their network, I guess it would also be helpful to be able to decode Type 2 DGA strings to identify all the different affected machines.</p><p>Here’s the link to the script on Github:</p><p><a href="https://github.com/asuna-amawaka/SUNBURST-Analysis">https://github.com/asuna-amawaka/SUNBURST-Analysis</a></p><p>If anyone is keen to discuss (or point out where I can improve in the code), DM me on Twitter!</p><p>References:</p><p>[1] <a href="https://github.com/RedDrip7/SunBurst_DGA_Decode">https://github.com/RedDrip7/SunBurst_DGA_Decode</a></p><p>[2] <a href="https://www.netresec.com/?page=Blog&amp;month=2020-12&amp;post=Reassembling-Victim-Domain-Fragments-from-SUNBURST-DNS">https://www.netresec.com/?page=Blog&amp;month=2020-12&amp;post=Reassembling-Victim-Domain-Fragments-from-SUNBURST-DNS</a></p><p>[3] <a href="https://github.com/2igosha/sunburst_dga">https://github.com/2igosha/sunburst_dga</a></p><p>[4] <a href="https://securelist.com/sunburst-connecting-the-dots-in-the-dns-requests/99862/">https://securelist.com/sunburst-connecting-the-dots-in-the-dns-requests/99862/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba4029193947" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/a-look-into-sunbursts-dga-ba4029193947">A Look into SUNBURST’s DGA</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you want to bake a donut? Come on, let’s go update~ Go away, Maria.]]></title>
            <link>https://medium.com/insomniacs/do-you-want-to-bake-a-donut-come-on-lets-go-update-go-away-maria-e8e2b33683b1?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/e8e2b33683b1</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 09:10:56 GMT</pubDate>
            <atom:updated>2020-11-30T09:10:56.572Z</atom:updated>
            <content:encoded><![CDATA[<p>I have not done any proper analysis for a while now, so here I am, trying to keep my itchy fingers busy after getting revved up by FlareOn last month.</p><p>I saw this interesting post [1] and jumped right into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*tbfcqBnsGGY4wwubF6HTuA.png" /></figure><p>Preliminary research got me these:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DlORSqFr1ZAT_vL57zFDaw.png" /></figure><p>I found additional samples on VirusTotal using RTF creation date: 2019:12:26 11:48:00</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GZkkGHS05ge9Cu-3tt37g.png" /></figure><p>These samples are related to the same threat actor because of the overlapping C2 domains used, the similarities in file naming and the same payload deployed.</p><p>After pivoting and researching, “Donot” and “Confucius” are two APT names that are closely related to the samples found. I don’t have enough data on my hands to say if these two groups are the same or if they are simply sharing infrastructure. Nonetheless, I shall concentrate on technical analysis while folks with more telemetry can worry about attribution.</p><p>The maldocs deployed by the actor use the following techniques to initiate the infection: Template injection, macros and/or exploits (e.g. CVE-2017–11882). After going through some trouble of deobfuscation/decoding/decrypting strings and code, the final payload (AVEMARIA, aka WARZONE RAT) is fetched and executed using one of two ways. One is via a loader (comes in a pair of files made up of a DLL and a XOR-encrypted data file), which I named as <strong>DonutLoader</strong> since there is no existing catchy names for this; the other way is via a different pair of files made up of a shellcode and a gif.</p><p>This long post shall be organized in this manner:</p><ul><li>Template injection</li><li>Malicious RTFs (walkthrough of my analysis of the shellcode deployed by the exploits) to execute DonutLoader and/or AVEMARIA</li><li>Macros to execute DonutLoader</li><li>DonutLoader Analysis</li><li>Brief comment on AVEMARIA</li></ul><p><strong>Template Injection</strong></p><p>In the case of “Suparco Vacancy Notification.docx”, the next stage malicious RTF is downloaded via relationship templates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*EJVikQSxvHOpBswNCeIEIw.png" /></figure><p>The exact same settings.xml.rels file is observed within “Testing.docx”.</p><p>“mal testin.docx” contains a different download link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*pC2l530ZKBsbf6fOEn9JGw.png" /></figure><p><strong>Malicious RTFs and the shellcode within</strong></p><p><em>RTF: 8E85C62E5D7FA9A6D2E176BCA6F6526B53EBFDA6EF3DF208E1E60434BD26EFFC</em></p><p>The file “IN4447832” is a malicious RTF that downloads a pair of gif/shellcode files that in turns download the final payload. The whole series of activities is triggered with the exploitation of CVE-2017–11882. Let’s see how it’s done.</p><p>At the end of the RTF file, we can see an embedded object:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*ArEpaVQFXKk00QWTqDsKbQ.png" /></figure><p>Extract this object and look at it again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*yZO7nohGFAAisH5aLgqENw.png" /></figure><p>There it is, an exploit for the equation editor. We can find the beginning of the exploit shellcode after identifying the “Font record” header (0x8 denotes Font record). Put it into IDA:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*Unqj8KBb1nx-Y7IpGb8L8A.png" /></figure><p>We can follow where the instructor pointer goes to within a debugger. Gflags come in handy again for this. Set the debugger for “eqnedt32.exe” to “C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb -server tcp:port=5505”, click Apply and OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*UYIOsew3HQ9C9BKxAoOPPA.png" /></figure><p>Execute the RTF file and with windbg, connect to remote session “tcp:port=5505,server=localhost”.</p><p>Put a breakpoint “ba r4 0x45BD3C” (taken from the shellcode 0x1271EB44 XOR 0x12345678) which will break on access read/write on the address.</p><p>When the breakpoint hits, we see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*CNl54yHfJmMUT_ISP3IHIg.png" /></figure><p>The shellcode followed the addresses three times, let’s do the same and arrive at:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*nbiPoB8hrtykiLigzoUFuA.png" /></figure><p>That looks like the MTEF data followed by font record, isn’t it? The shellcode then jumps to offset 0x43 from here, 0x5da358 + 0x43 = 0x5DA39B.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*BL2Gc80BFPVjsm7ijnsNEA.png" /></figure><p>Now, you know what to do. Put a breakpoint here of course.</p><p>&gt; bp 0x5DA39B</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*jrI2jaXRp2gD0xbP8jmmOQ.png" /></figure><p>The shellcode then did a little “polymorphism” and we find out that deobfuscation is done on the last 0x315 bytes of the extracted object — first a NOT, followed by XOR 0xE0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*q8thOfTnom_AoRdA6zEIhw.png" /></figure><p>After deobfuscation, we can then see the strings and code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*kVowME9r_pzFwopt4YyQjQ.png" /></figure><p>Analyzing the deobfuscated code will lead us to know that the file “updte” is another shellcode that executes code (again, XOR encrypted) in sant.gif.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*2Z-r3BTEBqEtNyilVOcNzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*9R1TQVRwYHbvV_lEqpOg2w.png" /></figure><p>The decryption within updte goes like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*J69thdItETlPU935LBG8OA.png" /></figure><p>Which leads to me writing this little piece of python script to assist in decrypting the gif file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*cFKGC2_yp6WJ1fCtM9FgJA.png" /></figure><p>After decryption, the data looks like the following. But somehow, some parts of it looks like they are still obfuscated…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*92Po8DHQCdV2QYGcaNWF8Q.png" /></figure><p>Well, IDA confirms our suspicions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*tb1J-Yro4my8QuBvmlTheg.png" /></figure><p>Easy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*RsVL0uYKnJ66wmAU2IS_TQ.png" /></figure><p><em>RTF: 686847B331ACE1B93B48528BA50507CBF0F9B59AEF5B5F539A7D6F2246135424</em></p><p>The file “KB466432” is also a malicious RTF that executes a loader via exploitation of eqnedt32. This is different from the above RTF I analyzed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*9iS_xHJVRv6D82l7_U4GZw.png" /></figure><p>A cursory look at the RTF reveals an embedded object like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*8pf5Q9IhRVPQeEDwaBfjgQ.png" /></figure><p>Which turns out to be a PE named “muka.dll”. Take note of the path “C:\Users\Dev\Desktop\07082020_8570_S\”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*3qvhky05vKUS7pKew8iQ9A.png" /></figure><p>Then there is also this other embedded object. Notice how there is a very long NOP sled within, which hints to us that this object is some code (probably the exploit):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*VNtdP0Jt7uXEY5h9BKMAkA.png" /></figure><p>Indeed, when we inspect this object, there’s a suspicious “tion.3” string in there, which reminds us of “Equation.3”. Very likely, we are looking at a CVE-2017–11882 or CVE-2018–0802 exploit again. Let’s see what the exploit tries to do. We can find the beginning of the exploit shellcode after identifying the “Font record” header.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*oamIrgEGwfK47vpEcL5Cyw.png" /></figure><p>In the earlier RTF analysis, we found an address that leads to where the MTEF data is found. Maybe use it again here:</p><p>&gt; ba r4 0x45BD3C</p><p>Bingo!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*ghQ_FoqqzbNr_m2pcs3sYQ.png" /></figure><p>Put a breakpoint on where the shellcode begins (in this case, 0x618efa). But it didn’t get hit. Maybe it got copied somewhere else before getting executed? Try</p><p>&gt; ba r1 0x618efa</p><p>Looks like we are right!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*MBjxNxRk39pjZzTUx-0w2g.png" /></figure><p>&gt; bp 0x18f318</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*QqVqoMli4kNKs_7igpitcQ.png" /></figure><p>Notice that the shellcode is seeking an address 2*0x7F starting from the MTEF header (0x5B8F0 + 0x7F + 0x7F), push this address to the stack, and then return to this address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*YOCtxOqSOnGUejzHuAe3bQ.png" /></figure><p>Taking a quick look at the shellcode in IDA, seems that the shellcode is trying to load muka.dll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*hkI5lLKkQO9C4draYnes8A.png" /></figure><p>Confirm this with the debugger. The shellcode calls the export “zenu” of muka.dll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*nN-ed1KKsufoKz4_WON9yQ.png" /></figure><p>It turns out that muka.dll is a DonutLoader. I’ll get to its analysis in awhile.</p><p><strong>Macros and DonutLoader</strong></p><p>DonutLoader can also be embedded within the maldoc and executed via macro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*vzpm0BEF-raR5i6EkNABdw.png" /><figcaption>macro</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*yAKqpqTrV-aVuhOa3X7NUA.png" /><figcaption>embedded object 1 filename</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*5azvE6T9iKrrxIKkEwXzmw.png" /><figcaption>embedded object 2 filename</figcaption></figure><p>Within 1d9ede11b34a20d4947f01432cea088dbefa911f02afaae9095673f56a76eafa, there are 2 embedded objects (as shown in screen captures above):</p><p>· C:\Users\Dev\AppData\Local\Temp\written.dll</p><p>· C:\Users\Dev\AppData\Local\Temp\s</p><p>Note also the paths “C:\Users\Dev\Desktop\Macro_Xls_1704_S” and “C:\Users\Dev\Desktop\01052020_MacroXlsEmb_S” which will help us to find more samples.</p><p>Written.dll is a PE in plain, while s is a 0x98-XORed PE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*2lyjzQLwyEUIILvyNdKX1g.png" /><figcaption>embedded object 1: written.dll</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*Nh-TliyxXhEcZ0v8xsLT1g.png" /><figcaption>embedded object 2: s</figcaption></figure><p>These files are DonutLoaders. OK, coming up next is their analysis finally!</p><p><strong>DonutLoader</strong></p><p>The name came about because I repeatedly mistyped the group name “Donot” as “Donut” when writing notes about these samples. Folks at PTSecurity [2] did analysis on some similar samples and called them “Lo2 loaders”.</p><p>From the RTFs I found from VirusTotal, most of them have a pair of files embedded — a DLL and a XOR-encoded data file. The following collates all the DonutLoader samples that I looked at.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9v9T9kTEcHvRUKZ4W6lSZg.png" /></figure><p>The DLL binaries make use of base64 and XOR operations to obfuscate its configuration data/strings so that our lives become a little bit harder.</p><p>I was able to decode strings from these binaries with the help of a small python script:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9nnZkXK1orMO7MwoY-NBCA.png" /></figure><p>This python script does the same thing as the one found in PT Security’s article, which said that this algorithm has been in use since October 2019.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*f1PF78z5yhfTxbwYwm2ZAA.png" /></figure><p>There is one binary that is “odd”. It had the latest compilation datetime amongst the files I looked at (which were compiled around Jun/Jul 2020). It uses a different algorithm to decode the strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysf6bsjKzbT5CBav3Y6exg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*TiAjY7uxWeExJskvPDhFaQ.png" /></figure><p>From within the DLL, the XOR-encoded file is read, decoded and executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*cgn8SA15DlyC36lBgM3qJg.png" /></figure><p>Within this second XOR-encoded executable, the same tricks are used to obfuscate strings from our prying eyes, consisting of base64 and XOR encoding, as well as byte additions. Interestingly, not all the strings can be decoded. But from what could be decoded, we can see where the next stage malware is downloaded from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*aWpIvxd3FfW4ZiJbeg8d7A.png" /></figure><p>muka.dll (SHA256: <em>1C41A03C65108E0D965B250DC9B3388A267909DF9F36C3FEFFFBD26D512A2126</em>)</p><p>(This file came from the RTF “KB466432”, SHA256: <em>686847B331ACE1B93B48528BA50507CBF0F9B59AEF5B5F539A7D6F2246135424</em>, analyzed above<em>)</em></p><p>This particular DonutLoader is more straightforward that those that occur in a pair. It uses just one type of string obfuscation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*96knTJTlYMwLgyQAFhlxvQ.png" /></figure><p>A quick look at the deobfuscated strings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*rjogMwkpFczndTZSUy4PKQ.png" /></figure><p>At runtime, the strings are used in the following manner:</p><ul><li>CreateDirectoryA(“C:/intel”, ..)</li><li>URLDownloadToFileA(…, “hxxp://wordupdate.com/recent/update”, “C:/intel/new.exe”, …)</li><li>Persistence is established with a shortcut to execute new.exe at startup: “C:/Users/user/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/new.lnk”</li></ul><p><strong>AVEMARIA</strong></p><p>The final payload malware is in fact WARZONE RAT (researchers named it AVEMARIA because of this string found within earlier versions of the RAT). Many folks have done analysis on this RAT so I’m not going to go into deepdive.</p><p>Some findings that I found interesting regarding the AVEMARIAs executed by DonutLoader:</p><ul><li>The PDB path is intentionally misleading. That path “VCSamples-master\VC2010Samples\ATL\General\ATLCollections\Client” is identical to Microsoft’s “VCSample” project on Github and the executable has nothing to do with what the path describes. I found lots of other AVEMARIAs based on PDBs like this. This could be part of the builder/encrypter in the WARZONE suite.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*gzHcfMbEMx4y6WAxDAVMYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9KSJ58-eSwGahh28jXJ8A.png" /><figcaption>Microsoft’s VCSamples project on Github</figcaption></figure><ul><li>The actual AVEMARIA payload (the one that calls back to the C2) is decoded and executed in memory and I dumped it to look at the strings. The keyword “warzone160” can be found, and this dumped executable matches YARA rules describing AVEMARIA.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*vg9bEEIRYA-hyHpL6NtWTA.png" /></figure><ul><li>Many more similar AVEMARIAs calling back to the same C2 can be found on VirusTotal, with relations to the known domain names used by the maldocs/DonutLoaders. Looks like AVEMARIA is a tool of choice to this APT group.</li></ul><p><strong>Last words</strong></p><p>Analyzing this set of malicious docs and executables has been fun, I’ll just leave you all with a set of IOCs and YARA rule for detecting DonutLoader. If anyone is interested to discuss, DM me on Twitter!</p><blockquote>import “pe”</blockquote><blockquote>rule MAL_DonutLoader_DonotAPT {</blockquote><blockquote>meta:<br> author = “Asuna Amawaka”<br> description = “This rule hopes to capture parents of DonutLoader as well as DonutLoader binaries”<br> date = “30 Nov 2020”</blockquote><blockquote>strings:<br> $filename1 = “wavs.bin” wide ascii nocase<br> $filename2 = “ogg.bin” wide ascii nocase<br> $filename3 = “muka.dll” wide ascii nocase<br> $filename4 = “linknew.dll” wide ascii nocase <br> $filename5 = “kpryt.dll” wide ascii nocase<br> $filename6 = “cvent.dll” wide ascii nocase<br> $filename7 = “trui19o2.dll” wide ascii nocase<br> $filename8 = “lioj86.dll” wide ascii nocase<br> $filename9 = “fuitel.dll” wide ascii nocase<br> $filename10 = “dpur.dll” wide ascii nocase<br> $filename11 = “mecru.dll” wide ascii nocase<br> $filename12 = “eupol.dll” wide ascii nocase<br> $filename13 = “mentn.dll” wide ascii nocase<br> $filename14 = “made.dll” wide ascii nocase<br> $filename15 = “notr.dll” wide ascii nocase<br> $filename16 = “vetu.dll” wide ascii nocase<br> $filename17 = “detr.dll” wide ascii nocase<br> $filename18 = “bese.dll” wide ascii nocase<br> $filename19 = “NumberAlgo.dll” wide ascii nocase<br> $filename20 = “JacaPM.dll” wide ascii nocase<br> $filename21 = “maroork.dll” wide ascii nocase<br> $filename22 = “fli0.dll” wide ascii nocase<br> $filename23 = “nuityr.dll” wide ascii nocase<br> $filename24 = “jgasf.dll” wide ascii nocase<br> $filename25 = “tuyrt.dll” wide ascii nocase<br> $filename26 = “lefbu.dll” wide ascii nocase<br> $filename27 = “pult.dll” wide ascii nocase<br> $filename28 = “quep.dll” wide ascii nocase<br> $filename29 = “nmwell.dll” wide ascii nocase<br> $filename30 = “yello.dll” wide ascii nocase<br> $filename31 = “lokr.js” wide ascii nocase<br> $filename32 = “falin.js” wide ascii nocase<br> $filename33 = “obile.js” wide ascii nocase<br> $filename34 = “vqiw.js” wide ascii nocase<br> $filename35 = “gb.bat” wide ascii nocase<br> $filename36 = “iksm.bat” wide ascii nocase<br> $filename37 = “trrt.bat” wide ascii nocase<br> $filename38 = “blo.bat” wide ascii nocase<br> $filename39 = “SystemService.exe” wide ascii nocase</blockquote><blockquote>$path1 = “C:\\Users\\Dev\\Desktop\\07082020_8570_S\\” wide ascii nocase<br> $path1_wild = {5c 55 73 65 72 73 5c 44 65 76 5c 44 65 73 6b 74 6f 70 5c [8] 5f [4] 5f 53 5c}<br> $path2 = “AppData\\Roaming\\EvMGR” wide ascii nocase<br> $path3 = “C:\\Users\\Dev\\Desktop\\Macro_Xls_1704_S” wide ascii nocase<br> $path3_wild = {5c 55 73 65 72 73 5c 44 65 76 5c 44 65 73 6b 74 6f 70 5c 4d 61 63 72 6f 5f 58 6c 73 5f [4] 5f 53}<br> $path4 = “C:\\Users\\Dev\\Desktop\\01052020_MacroXlsEmb_S” wide ascii nocase<br> $path4_wild = {5c 55 73 65 72 73 5c 44 65 76 5c 44 65 73 6b 74 6f 70 5c [8] 5f 4d 61 63 72 6f 58 6c 73 45 6d 62 5f 53}</blockquote><blockquote>$str1 = “MJuego” wide ascii nocase<br> $str2 = “0007E9E4CE4D” wide ascii nocase<br> $str3 = “Bensun” wide ascii nocase<br> $str4 = “Menner” wide ascii nocase</blockquote><blockquote>$pdbpath1 = “Soft\\DevelopedCode_Last\\BitDefenderTest\\m0\\New_Single_File\\Lo2\\SingleV2\\Release\\BinWork.pdb” wide ascii nocase<br> $pdbpath1_wild = {5c 53 6f 66 74 5c 44 65 76 65 6c 6f 70 65 64 43 6f 64 65 5f 4c 61 73 74 5c 42 69 74 44 65 66 65 6e 64 65 72 54 65 73 74}<br> $pdbpath2 = “Users\\admin\\Documents\\dll\\linknew\\Release\\linknew.pdb” wide ascii nocase</blockquote><blockquote>condition:</blockquote><blockquote>uint16(0) == 0x5a4d and filesize &lt; 600KB and ((1 of ($filename*)) or (any of ($path*, $str*, $pdbpath*)) or pe.exports(“zenu”) or pe.exports(“flis”) or pe.exports(“jrgbeg”) or pe.exports(“csytu”) or pe.exports(“neeu”) or pe.exports(“vile”))</blockquote><blockquote>}</blockquote><ul><li>wordupdate[.]com/recent/update</li><li>cheaperlive[.]xyz/xolto/mikix</li><li>tampotrust[.]top/tax/lodi/pkra</li><li>remindme[.]top/tax/lodi/pkra</li><li>recent.wordupdate[.]com/ver/update12/KB466432</li><li>the-moondelight[.]96[.]lt/latest/updte</li><li>the-moondelight[.]96[.]lt/optra/sant.gif</li><li>the-moondelight[.]96[.]lt/latest/version/secure/download/IN4447832</li><li>the-moondelight[.]96[.]lt/windw-sec/append</li><li>1C41A03C65108E0D965B250DC9B3388A267909DF9F36C3FEFFFBD26D512A2126</li><li>8CFBFECFE475C3621277EE7F680E3A0CB9C650802363DAA256C1057ADFB817A9</li><li>7A987295229D2514D99916D53F196B87758CE08FD8621CF68BC419DC99B80D6D</li><li>D279DDB6B2A566BC24E789B5181663491B8C2818CB91E28AAE5721DCB0BF30B6</li><li>AB04BF258CF71B4A1CB934491CF942ECDA0EC82D4F6A80B5108D7607BE6FC2BE</li><li>7F4B7D0C6076E197A509C01C0794EBC450229FF5D555BE8D7F89F98B3C43A298</li><li>684F68429F8BAC224E6FDC68195C89B54BA469FBCC2184EC2B5FC689E585CA54</li><li>0EA05331E775DE6B329FF1FA22F11809C2C1BCB6E17683552219CB32F52A47F5</li><li>83847C527F713B6E13849028D66B08686ADDE26B8E9ECD8DDC78AD178EF7BDCB</li><li>E291A146F79D927D18392A04D238D829C0DF156410E4D93636AEE1B5663DB914</li><li>E6753EB498F58F95C8FC931B6CD53647CE2F4F8F7AD4274C22CA2B6284FB5308</li><li>67C0C937E049083193649449519A57E42945CA2ABE19756F4E76D95CAA44A062</li><li>70D41C8C25CB8E75296576D3DBB37720E03F96691691763953FEA0FE00F50EB4</li><li>9B34F53DDC20D5EA2F7B47818ED2E7D626948256268CB4E2B11E47ECAF9A839A</li><li>891ACF7B729183945F209C915BA2BB57B541E2EA350899A541DB9A63428711A5</li><li>FB46324757D0EC8B0AC02729E281E47EF1C367DEED483F14481441C2F9B6CA34</li><li>66F3134E3E040F50ED59629379C0750D896969ACFDC55105BE7FEF81839BA035</li><li>1C4B8A1F48FF1B9511AEC0704983E45242F01C2109AB4602F7952481429DDC84</li><li>88672DF33B02275660EC3995F3BAD63FE994C09BA8E978E7F18D4F8C9A97637A</li><li>7609034E7473869B3A5767F9543B6067998F4DB68E3BA26966C115535337337F</li><li>ADE6D291C870A9F59D4A22FF4D61E6B2A913538701517E8D0AA275855FD80A76</li><li>E99AE9163F6DBBA22E1357C2164EB0F9971A264A481813EC11DC598784435B95</li><li>1E6E568E2FCCFEB2E0275982D5637E0BE6D0BA4575685126D957061BF2D19678</li><li>4C5C43F4932AC497C716BB5EC30A7636E5056775A4D5F3F48B9E5C1414B9F7B3</li><li>7305E08AB7812F44EA42E89AE7D473B1F373C151CA8D12F77B79E85C942366FC</li><li>59CCFFF73BDB8567E7673A57B73F86FC082B0E4EEAA3FAF7E92875C35BF4F62C</li><li>A3CD781B14D75DE94E5263CE37A572CDF5FE5013EC85FF8DAEEE3783FF95B073</li><li>904E966DA7B38514F6AC23BBA1DAC1858888CD48FA77B73C770156B19A88A4C8</li><li>8E85C62E5D7FA9A6D2E176BCA6F6526B53EBFDA6EF3DF208E1E60434BD26EFFC</li><li>5C9477C16DF8EF4434C042E69B473A44452CAEE96219A56EB2DA30F0B5E85976</li><li>686847B331ACE1B93B48528BA50507CBF0F9B59AEF5B5F539A7D6F2246135424</li><li>1D9EDE11B34A20D4947F01432CEA088DBEFA911F02AFAAE9095673F56A76EAFA</li></ul><p>References:</p><p>[1] <a href="https://twitter.com/RedDrip7/status/1324205510380322816?s=20">https://twitter.com/RedDrip7/status/1324205510380322816?s=20</a></p><p>[2] “Studying Donot Team”, 28 May 2020 <a href="https://www.ptsecurity.com/ww-en/analytics/pt-esc-threat-intelligence/studying-donot-team/">https://www.ptsecurity.com/ww-en/analytics/pt-esc-threat-intelligence/studying-donot-team/</a></p><p>~Asuna~</p><p><a href="https://twitter.com/AsunaAmawaka">https://twitter.com/AsunaAmawaka</a></p><p>Drop me a DM if you would like to share findings or samples ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8e2b33683b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/do-you-want-to-bake-a-donut-come-on-lets-go-update-go-away-maria-e8e2b33683b1">Do you want to bake a donut? Come on, let’s go update~ Go away, Maria.</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Journal: FlareOn7 (Part3)]]></title>
            <link>https://medium.com/insomniacs/journal-flareon7-part3-e81536c14855?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/e81536c14855</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[flareon7]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Sat, 31 Oct 2020 15:12:33 GMT</pubDate>
            <atom:updated>2020-10-31T15:18:45.257Z</atom:updated>
            <content:encoded><![CDATA[<h3>Journal: FlareOn7 (Part 3)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*PPvVdEG_bBpq1TwN.png" /></figure><p>This is the last part of the series :)</p><p><strong>(Linux, Signals, Crypto, Maths) 10_-_break</strong></p><p>I love and hate this particular level. While I was solving it, there were too many hair-pulling moments. The few hours after I submitted the flag for it, I told myself and many others, “I’m not gonna solve that again!”. A few days after finishing the entire challenge, I revisited it after a chat with a friend about the ingenious mechanisms behind it and couldn’t help being in awe of the design of this binary. Now I’m grateful for this binary for teaching me so much :)</p><p>When I was solving this challenge, I was blind to the exact mechanisms behind it. Mostly I took the approach of “just run it and see what happens”. But for the sake of maximizing learning value of this journal, I’ve included some of my thoughts and learning points post-solving here. Without further ado, let’s get into the land of sunshine and rainbows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*vPaSHtndVelAM1n8VP6Q_g.png" /></figure><p>First thing we see when we execute the binary is that my input got stolen with a smile. The audacity!</p><p>We are going to do quite a fair bit of static analysis before embarking on dynamic-assisted analysis. Let’s get started by looking around the functions with IDA Pro. Very quickly we can see two interesting functions with some switch cases in them. It sure looks like these two functions will be the most visited code during our analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*fCkauasx8x7JunqyZX1AKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*QXXluMgJi17DFdsgIwdF_g.png" /></figure><p>During the initialization of the binary, a fork() was called and the parent process is made to run the first big function (for ease of reference, let’s call it very_big_function_80490C4 as you would see in my screen captures). The child process is made to “refuse debugging” by restricting ptrace scope with pctl().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*UehtoP3Aohkojb53RZJ_uw.png" /></figure><p>Lets take a cursory look at very_big_function_80490C4. One of the most common thing done in this function is calls to this function that loads and call ptrace().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*NU7CPXXw3D93K-kubbbgew.png" /></figure><p>This function dynamically loads the “ptrace” function from “libc.so.6” and then calls ptrace with the given arguments e.g. PTRACE_ATTACH. This is an important function and it directly affects how we code our solution. Because ptrace is explicitly loaded from “libc.so.6”, when we want to install a hook for ptrace, we would need to patch this within the binary so that our hook will succeed. We’ll get to that later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*yGXg9TtSzJxW6PFRKJdiuA.png" /></figure><p>In the first part of very_big_function_80490C4, it does some checking on who is debugging who and it is hard to “trick” the binary into letting us debug it with GDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*SrgVquwoziswNA5FC4CCIw.png" /></figure><p>It might help if you refer to sys/wait.h and signal.h for understanding the signal checking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ByRjnf9FQSSnxx2akJLIzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*p4_AHSx7XZrR5J2-js39MQ.png" /></figure><p>When the binary is convinced that nobody else is spying on it other than its own components, it will then execute the intended job it has.</p><p>After this challenge, we will all become very familiar with the man page of ptrace. Before we go further, I just want to briefly highlight a few types of requests that can be made to ptrace() which we would find useful later.</p><p>The ptrace function signature is as follows:</p><blockquote>long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);</blockquote><p>The requests that we would find useful:</p><p>· PTRACE_POKEDATA: Copy the word data to the address addr in the tracee’s memory.</p><p>· PTRACE_GETREGS: Copy the tracee’s general-purpose or floating-point registers, respectively, to the address data in the tracer.</p><p>· PTRACE_PEEKDATA: Read a word at the address addr in the tracee’s memory, returning the word as the result of the ptrace() call.</p><p>Ok, now we are ready to analyse.</p><p>The first “task” that binary performs is to make the function that compares our input with “sunsh1n3_4nd_r41nb0ws@flare-on.com” raise a signal when executed. Such a neat way to start off the series of actions to steal our input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*bBHYIIMscz-sMJ8ObWNbmQ.png" /></figure><p>So the first word of the string comparison function gets overwritten with the value “0xB0F”, which is an undefined instruction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*UTDAYDnIbHCw-apcBOK6Zw.png" /></figure><p>Then another fork() is done and the signal handler is put in place. First thing that this signal handler does is to ignore all attempts to stop the binary. If we try to Ctrl-C while the binary is running we’ll see the binary yelling at us :&lt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*neZ_9XVtZIQttAnz3Bqu1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*XZMh3u3cpOYbR0QuBf2YKw.png" /></figure><p>This function conch_and_interrupts_8049C9C is in fact the second big function with switch cases which I mentioned in the beginning of this post. When SIGSEGV is detected, then it does some stuff.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*eYhAmZP50dasIb2mt9HIiw.png" /></figure><p>Back to very_big_function_80490C4. A while loop is started and a value is calculated based on the “orig_eax” register. This value is to be used as the switch case that decides what is being executed. A little research into this mechanism later on revealed that the value stored in the “orig_eax” register is in fact the syscall number. Hence, what is happening throughout the binary is interception of syscalls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*KxIpp3HI3Tym0JuWYvN7Tg.png" /></figure><p>Ok let’s think about what we need to do from here on to reach the flag. We are not able to debug the binary, but we can hook onto ptrace() to see what the binary is doing with all these calls to ptrace. Since we are writing hooks, then we should also write for the other API calls that the binary uses. The difference between hooking ptrace() and all these other API calls is that only ptrace() needs to be handled separately due to it being dynamically loaded. Confusing? Maybe taking a look at my code will make things clearer — <a href="https://github.com/asuna-amawaka/Flareon7-2020">https://github.com/asuna-amawaka/Flareon7-2020</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*nrwbXP5YsbN_gznNZmi87A.png" /></figure><p>There are only so many imported functions. We can start small by hooking onto those API functions that does comparison first. Perhaps the flag is being derived through some comparison checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*nqjRuHAk2Cgw9ykFp-_Fzw.png" /></figure><p>Compile it with:</p><blockquote>gcc -shared -ldl -m32 myhooks.c -o libz.so.6</blockquote><p>Then execute the binary with LD_PRELOAD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*JC6LVsYdDQvPNY0CboL85g.png" /></figure><p>Wow, what was that? w3lc0mE_t0_Th3_l…..?</p><p>Anyway, this shows my hook is working, and we got part 1 of the flag easily.</p><p>Patch the binary and we can try hooking ptrace next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FcIGDgd-vqF3z_qr4JtgSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*QP93SmRRGML99WtWLtAdqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*lxP2V7uHK9ICmGl3q-3QMg.png" /></figure><p>Great! Now with this set of logs, we can follow the execution flow and make sense out of the binary.</p><p>I’m going to move quickly to solving for the second part of the flag. Whatever that happens between this point and the next “crucial” part of the binary has only smokescreens and lies :&lt; For example, in the first interesting switch case that we encounter when the value is 0x83411ce4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*U7TmAAdQMEkX7cJjCMoIxw.png" /></figure><p>The strings that can get decrypted look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FAkPRqqi2QWfDJy5lVIHbA.png" /></figure><p>Here is another function that decrypts a set of strings that wasted our time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*FV1M5I-4csbnA2fyRTyMKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*yw7pfK3c9-4FZ2wrIYFChw.png" /></figure><p>Ok, let’s move on from the time wasting strings. The next “crucial” part of the binary happens when our input gets compared with “w3lc0mE_t0_Th3_l”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*GDZ_I3kTsG_RcX5AA4Pa_Q.png" /></figure><p>Word of caution: Patch out the execve call here or avoid pressing enter without typing an input when testing the binary. I’ve lost two VM images because failed to notice this call until I lost one image.. and the second time was when I was writing this post and I forgot about this fact :&lt;</p><p>Now, here comes the fun part. The first 16 bytes of our input is expected to be “w3lc0mE_t0_Th3_l”, and then the remaining is checked in the function get_2nd_part_flag_8048F05.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*lEphUXAogy0jyIfaEAiG8A.png" /></figure><p>When we get into analyzing the function decrypt_data_804C369, this is where things start to look abnormal. There are calls to _pivot_root, _mlockall, _uname and _chmod, and none of these calls makes any sense in the context of this binary. Let’s hook onto the calls to try and figure out what is going on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*YxMgeQVEd3gxWirjguguuA.png" /></figure><p>It looks like some looping is going on, but this is not apparent from the disassembled code. This is because of the signaling mechanism in place! As I’ve mentioned earlier, when I was solving this, I had no idea what this underlying mechanism is. I only knew that the binary was able to loop based on the output of my hook trace. I spent 2 days staring at these traces, with only a vague idea that some decryption is happening amongst these loops. I’m looking at an algorithm that is building a set of 16 round keys via pivot_root/mlockall/uname and then these round keys are used to decrypt 0x9C40 bytes of data. The process of decryption also involves some XOR and swapping. I resorted to writing down with pen and paper the process that went on within decrypt_data_804C369, trying to identify the algorithm and finally realised the algorithm is in fact the most fundamental concept in many block cryptography.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*Ng1028JzN8YDWzSQMOxZWA.png" /></figure><p>The Fiestal Cipher. What’s left to do now is to figure out the flag. The first 0x20 bytes of the encrypted buffer has some placeholder values. We can see that the next 0x20 bytes of our input (after “w3lc0mE_t0_Th3_l”) is overwrites the placeholder within the buffer to be decrypted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*KTqdptH4yxxPS2lxaBArCA.png" /></figure><p>We would need to know the resulting values in order to deduce our flag. Let’s see how we can print the output of the decryption function.</p><p>Notice from the trace logs printout that a syscall #5C was being intercepted. This is the call for truncate. Although when I was solving this, I was not aware that this is actually the syscall interception for truncate, I noticed that the execution flow was directed to the switch case for 0x4a51739a. Either way, we are led to analyze the code snippet for this switch case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*rK4skQuF2P91sFh0WLVlCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Q8Ta6KTBJKU0606vFLmtFA.png" /></figure><p>There it is: the expected value of the 0x20 bytes of the flag after “decryption”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*hPZsbshkO6J-eHpebI_DBw.png" /></figure><p>Also notice in the trace that there seems to be some ASCII text in the decrypted output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*4sMKzFz0pHHMHh2UWdMfuQ.png" /></figure><p>That looks like… bee movie stuff again? This observation is critical to lead us to the flag. It seems that the first 0x20 bytes (which is our input) of the 0x9C40 buffer is to be “encrypted”, while the rest is to be “decrypted” into bee movie text. We can use this bee movie text and their corresponding ciphertext to help us with testing our attempt to reverse the fiestal cipher. I used the first 8 bytes of the bee movie in the following illustration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*iiCXuySDY1-n01lM8sPGFg.png" /></figure><p>Take a while to figure this whole “flip the round keys around” out, maybe pen and paper will help (like it helped me).</p><p>Anyway, after figuring out that we simply need to reverse the round keys used, just use our hooks to do some memory manipulation and we will get the flag.</p><p>Firstly we shall copy 0x2<strong>8</strong> bytes of ciphertext in 0x81A5100 into the buffer that the decryption algorithm acts on. Note that I created an extra 8 bytes of “padding” within the buffer (I duplicated the first 8 bytes, you can do anything you want), because I need to use one extra loop during the decryption phase to get the round keys’ address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*D77KI_pkofszMiY2Ul60pA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*0z7RdHCgTWU6kOamwS5_Dg.png" /></figure><p>Then we do the roundkey reversal within chmod’s hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*lclBisN7QKOXlq23L0iRQA.png" /></figure><p>You might have noticed that this decryption takes very very very long because it works hard to decrypt 0x9C40 bytes. We only need to decrypt the first 0x20 bytes, hence we can patch the binary to change the size check to 0x40 (more than enough) so that we don’t need to wait too long.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*0oPhc7eAJX0Q-NbfMG6h-Q.png" /></figure><p>Now, finally we can run it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*zT52dDGxcf9MjNORji3gjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*_-AKSEPk4ZpWDdbgNkIRUA.png" /></figure><p>Yes! 2nd part of the flag in the bag.</p><p>We’ve got the hardest part of the flag out of the way. Finding the clue to the next part of the flag took me awhile, because I kept working with the “shortened” binary I made. Apparently, there’s shellcode among the decrypt bee movie text. Sneaky sneaky..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Gaezwt6WZjwwrxApMfmpaA.png" /></figure><p>I took the static analysis approach for this shellcode because I can’t get the binary to execute it. Buffer overflow perhaps? Doesn’t matter, static analysis works fine.</p><p>The two important things that will lead us to the flag after we are able to identify that the shellcode:</p><p>- Works with big integers</p><p>- Is implementing the Elgamal public-key cryptosystem</p><p>The second fact took me awhile to click and realise what I’m supposed to be doing. Googling for it led me to this library on Github:</p><p><a href="https://github.com/kokke/tiny-bignum-c">https://github.com/kokke/tiny-bignum-c</a></p><p>And it’s the perfect match with the stuff found in the shellcode!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*xBn96vhnnr6d6eNUiQSiEw.png" /></figure><p>After some analysis and reading, we can confirm that the algorithm is Elgamal. The binary also enforced 2 conditions that made our work easier — one gets rid of the “randomness” and unknowns (the value k) and the other gives us an equation to work with.</p><p>The notation I’m using follows the explanation given on this site: <a href="https://www.geeksforgeeks.org/elgamal-encryption-algorithm/">https://www.geeksforgeeks.org/elgamal-encryption-algorithm/</a></p><p>k = random % q (q is known)</p><p>S = h^k mod q (h is known)</p><p>p = g^k mod q</p><p>g = g^k mod q (check condition 1)</p><p>hence p = g, k = 1 (got rid of randomness)</p><p>At this point, we know S, q and c.</p><p>(M*S) mod q = c (check condition 2)</p><p>The idea is to solve for M, using modular inverse (I found this great material that helped me with the steps to solving this maths — <a href="https://courses.cs.washington.edu/courses/cse311/15au/documents/ModularEquivalences.pdf)">https://courses.cs.washington.edu/courses/cse311/15au/documents/ModularEquivalences.pdf)</a></p><p>I wrote my solution with Java because I thought using Java’s BigInteger class is the most straightforward.</p><p>Anyway, here is my Java solution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*vkBQUMnDqEm5B4uXLEusvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*jp2Dmpk97ndnle0b0RMhlg.png" /></figure><p>I also wrote a C version, just for fun. The modular inverse function did not work as expected, hence I took the S^-1 value from the Java output :X</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*TfLXgQULNKK66QFuGV4zRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*cbyJ22s5ysOrSBYUzXyaDw.png" /></figure><p>That’s it, we have the whole flag: w3lc0mE_t0_Th3_l4nD_0f_De4th_4nd_d3strUct1oN_4nd_n0_puppi3s@flare-on.com</p><p>Phew! We are done with #10.</p><p><strong>(Malware Analysis) 11_-_rabbithole</strong></p><p>The last one is always the most painful to work through but I enjoyed this one a lot despite the pain. I don’t think I can do a better job detailing the malware analysis than those that are already out there (all of them helped me a lot during the solving process too). Let’s do a quick one for this writeup!</p><p>First thing to do is to find where is the fileless malware within the given registry hive. When told that we are looking for fileless stuff, some keywords (powershell, function, eval, wscript…) would come to mind. Use these keywords as a start to search.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ptYz1yxrRq5V-YtBd8jDQQ.png" /></figure><p>That regkey look suspicious — especially when the variable name looks so random.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*mZLuyaeHWz0yujEF-d6wZA.png" /></figure><p>The powershell script that we found does an injection of binary into powershell.exe and this binary turns out to be the Gozi ISFB malware. In retrospect, “malware analysis” of this binary is considered to be the easy part, given that the source code is on Github and the encryption algorithms involved are more or less the same — the difficult part is figuring out where might the flag be hiding and then how to get to it..</p><p>I was able to execute the binary by executing the powershell script found from the registry. Simply modify the shellcode to start with EB FE (infinite loop), print the allocated memory address and attach to the powershell process with the debugger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*stytDedTVUXk-rUbCR6G6g.png" /></figure><p>After cursory analysis of the binary, we would find out that the binary is reading registry keys and the names of the registry keys to be retrieved depended on the user SID value XORed with a hardcoded value 0xEDB88320. The result of this XOR operation is the variable g_machinerandseed. We will need this value later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6xr7Xnw0OAdZ5W9pi5_GmA.png" /></figure><p>To make the binary read the registry keys from our NTUSER.dat, we would have to change the SID being used in the binary. For me, I put a breakpoint here during runtime and fixed the memory directly. What we would need to do next is to get the binary help us decrypt all of the keys in Timerpro\Columncurrent and Timerpro\LanguageTheme. These are the plugin modules loaded by the malware to perform specific tasks. There is a nice article here to help understand these modules: <a href="https://vms.drweb.com/virus/?i=16014468&amp;lng=en">https://vms.drweb.com/virus/?i=16014468&amp;lng=en</a></p><p>My approach is rather crude and did not involve writing any code. To get the plugin modules decrypted:</p><ul><li>Rename the regkey that you want to decrypt to “WebsoftwareProcesstemplate”. I’m doing this manually in regedit, with a VM snapshot taken right before the key is read by the binary. Rinse and repeat these steps as many times as the number of regkeys that needed to be decrypted.</li><li>Put a breakpoint after RSA and serpent decryption is done, dump the decrypted contents from memory</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*64fZb8jgu-NQANogYWj1pA.png" /></figure><ul><li>Run the decrypted contents through aplib-decompression (https://github.com/snemes/aplib/blob/master/aplib.py)</li><li>Use hasherezade’s tool to convert PX to PE (https://github.com/hasherezade/funky_malware_formats/tree/master/isfb_parser)</li></ul><p>You know this is the right way to go when you get taunted by the challenge author…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*xEJMQYbBeYT5tjiMn_svLQ.png" /></figure><p>Also, a C2 configuration-like data can be found in MonitornewWarningmap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ecf9KZdgnIcWIRsD9d5rcw.png" /></figure><p>Intuitively, that looks like a key or password that would definitely come useful later. Now we can pause and think about where to get our flag.</p><p>One of the suspected place where the flag could be hiding would be in the registry, as we can see that there are quite a few that have not been used so far under Timerpro. Guessing from the length of the registry keys, if the flag is in there somewhere, it should be in TimerPro\DiMap. The challenge hinted at us to work on the malware’s file exfiltration feature, which means we are probably looking for a compressed file (e.g. .zip or .rar).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*KrfrjzW412X4zo-R45OOOA.png" /></figure><p>A clue could be found in TimerPro\WordTimer\MAIN, which decrypts to this (via rsa and serpent followed by aplib decompression):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*u8OU7T8YqNQGQzCsiOi11Q.png" /></figure><p>Here’s the hypothesis: the flag is within a text file that is the target of exfiltration (probably zipped). The contents of this file ready to be exfiltrated is most likely stored in TimerPro\DiMap. What we need to do is to find the function within the binary or its plugin modules that reads from/writes to the registry and within close proximity of such a function, there is code that performs encryption (because the regkey value is obviously encrypted).</p><p>Sounds easy, but I spent a good long time trying to find code that matches the above requirement. We can try to infer the roles of each plugin extracted by looking at their export functions. Also, each of these plugins seem to be dependent on some other plugins based on their imports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*HP6AAzNxZlx1dJ_ZyOxC2Q.png" /></figure><p>Notice that all the imports are named with some number. These happen to be the calculated value used to “choose” the random words that happen at this code snippet (refer to screenshot below). We can make use of this code snippet to tell us which regkey name is which DLL, by manipulating the value of ECX. For example, if I want to know the regkey of “d6306e08.dll”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*a7uuXbZ4KQtFu3tpRFze1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*uHTj2QzmklVXGy7D6Bo_UA.png" /></figure><p>Look at how the regkey name is selected to be “WordlibSystemser”.</p><p>Through analysis of export functions and API calls, we can identify that WordlibSystemser is the plugin that interacts with the registry.</p><p>From here, I inspected every function involving registry operations and found this within RowmapGuiprotocol that used export functions from WordlibSystemser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*VAeRJuXfeEnuv-21AVVbKQ.png" /></figure><p>From the source code, I found this set of crypto algorithms that seem to correspond to the above seen “XOREncryptBuffer” and “XORDecryptBuffer”. Upon closer look at the implementation, note that they are a little different. This has to be it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Lplc7h5qa_B34cQw-Pxfbw.png" /></figure><p>We can then find the function at sub_B4F4 that is identical to “XORDecryptBuffer” in the main binary, that’s good. We can use the binary to help us decrypt dynamically later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*VUXh_bi0i5yFRmGle3Z3jw.png" /></figure><p>When looking up how this function is being used in the source code, it looks like it uses this variable g_machinerandseed as the key. Remember we figured this value out earlier as the result of 0xEDB88320 XORed with the victim’s SID. Take note of the value to be 0xFB307BFA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*P1Is32nLAStArMKVZ9WkvA.png" /></figure><p>This means that the key/password that we saw in MonitornewWarningmap is not used. That cannot be! I dropped into a few more rabbit holes at this point trying to find where that key could have been used. But a friend liberated me from my torture by telling me I was right about the XORDecryptBuffer and after that it’s just serpent decryption again. Hurray? I was about to go into all of these, thank goodness..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*dGTeuDf_T3RHWdMoVMS1DA.png" /></figure><p>Let’s make the binary do the work for us. Put the contents in DiMap through XORDecryptBuffer by setting RCX, RDX, R8 and R9 with the respective values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*UCwaAqhhUTSzUdGg67twcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*VyAAqC_D53pXeP7YPrUEaA.png" /></figure><p>Followed by serpent decryption with the key “GSPyrv3C79ZbR0k1” gives us..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*EESrXNFR9hSQM8gsiT3f3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*hSqRq3L796Va3nZIDmpneQ.png" /></figure><p>Andddd we are done :)</p><p>That’s it for FlareOn7, my friends. See you again next year!</p><p>~~~</p><p>Asuna<br><a href="https://twitter.com/AsunaAmawaka">https://twitter.com/AsunaAmawaka</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e81536c14855" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/journal-flareon7-part3-e81536c14855">Journal: FlareOn7 (Part3)</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Journal: FlareOn7 (Part 2)]]></title>
            <link>https://medium.com/insomniacs/journal-flareon7-part-2-88baa92ffc9b?source=rss----8dea5b1882ca---4</link>
            <guid isPermaLink="false">https://medium.com/p/88baa92ffc9b</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[flareon7]]></category>
            <dc:creator><![CDATA[asuna amawaka]]></dc:creator>
            <pubDate>Sun, 25 Oct 2020 08:11:33 GMT</pubDate>
            <atom:updated>2020-10-25T08:39:18.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*0VVH6sfyZ2xCaVzA.png" /></figure><p>Continuing on levels 7–9…</p><p><em>(edit: I’m sorry that some of the screencaptures for the solution python scripts are really low resolution. Go to my GitHub repo to download them! </em><a href="https://github.com/asuna-amawaka/Flareon7-2020"><em>https://github.com/asuna-amawaka/Flareon7-2020</em></a><em>)</em></p><p><strong>(WebDav exploit, pcap) 7_-_re_crowd</strong></p><p>This is a cool one that taught me about CVE-2017–7269. Before I started on solving this level, I spent some time reading up on the vulnerability and the exploit POC on: <a href="https://www.anquanke.com/post/id/85811">https://www.anquanke.com/post/id/85811</a>. The English translation by Google works well for this page :) I’ll be relying very heavily on this post for solving this level.</p><p>You might be asking, in the first place, how did I know the pcap is about an exploit, and the exploit is for CVE-2017–7269?</p><p>There was a conversation from the employees in the IT department (from “The IT Crowd”) that tells us the flag is most probably in C:\accounts.txt or whatever is in this file will lead us to the flag. Then we see streams like this in the pcap:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*tXh5ITFulWtSqUER4tTpGQ.png" /></figure><p>Streams 33 to 48 looks like some unsuccessful attempts at doing something, with decreasing length of contents sent to the server and the server replying with a 500 error. Stream 49 looks like whatever is being done was finally successful (no 500 error) and is followed by Streams 50 and 51 that tell us some data is being exchanged. Looking up the keywords “PROPFIND”, “locktoken:write”, “webdav” will bring us to CVE-2017–7269 and articles on the exploit of this vulnerability.</p><p>We can concentrate on the contents sent in Stream 49, because that is the successful exploit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*CK7FQvFnwtzOmhrWwzCcHA.png" /></figure><p>The most direct way to tackle this level would be to do a dynamic analysis. First off, set up the environment: Windows Server 2003 r2 32bit (get the CD images here <a href="http://download.microsoft.com/download/5/1/C/51C53A00-7F8B-423C-A841-8B9C49B910BF/X13-04795.img">http://download.microsoft.com/download/5/1/C/51C53A00-7F8B-423C-A841-8B9C49B910BF/X13-04795.img</a> and <a href="http://download.microsoft.com/download/5/1/C/51C53A00-7F8B-423C-A841-8B9C49B910BF/X13-04874.img">http://download.microsoft.com/download/5/1/C/51C53A00-7F8B-423C-A841-8B9C49B910BF/X13-04874.img</a>), with IIS6.0 installed, webdav enabled and WebClient service running. Also install python 2.7 and process explorer of your liking. We will debug the exploit with windbg (I’ll run through how to set this up in abit).</p><p>Next I used the POC python script and edited it with the shellcode extracted from the pcap. I reused the “pay” variable contents from the POC, because it helped me to follow the steps from the abovementioned blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwywR2Aa0geZRwvSmYiwew.png" /></figure><p>Now, we set up the tools within the WS2003r2 image. Download and install Windbg with this SDK: <a href="https://download.microsoft.com/download/F/1/0/F10113F5-B750-4969-A255-274341AC6BCE/GRMSDK_EN_DVD.iso">https://download.microsoft.com/download/F/1/0/F10113F5-B750-4969-A255-274341AC6BCE/GRMSDK_EN_DVD.iso</a>. You might also need this .Net framework: <a href="https://download.microsoft.com/download/0/8/c/08c19fa4-4c4f-4ffb-9d6c-150906578c9e/NetFx20SP1_x86.exe">https://download.microsoft.com/download/0/8/c/08c19fa4-4c4f-4ffb-9d6c-150906578c9e/NetFx20SP1_x86.exe</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*0Z4xETuxSi8F2KgjCfUbng.png" /></figure><p>We are going to make use of gflags (Global flags) to help us with the debugging. This is a nifty trick that I usually use for debugging Windows Services, but looks like it is also helpful in this situation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*mhUZ5iZi74tdafMbn3Djow.png" /></figure><p>We know that the exploit will be executed under httpext.dll via w3wp.exe, hence we want to put our debugger into w3wp.exe so that we may step into the DLL. Fill in this page like this and click on Apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*NzwPHHoPK6AsQCutNaTcyA.png" /></figure><p>Ok, now we can execute our python script. Notice the processes that are created: svchost.exe &gt; cdb.exe &gt; w3wp.exe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*GIbaDMZEaq5lSxDzVdkRdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*knLSvpzc-UpS8Pc4YalXWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*KP53bRpZPtsCWY8fmBQ9cw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*czJndAmsBy-9UJqhOXmkyg.png" /></figure><p>Our target is “httpext.dll”, so let’s set a bp upon load of this dll with “sxe ld httpext.dll”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*BkZUhiNXJjk7_SHouS2jrA.png" /></figure><p>The abovementioned blog post provided a lot of details on how the whole exploit worked, so I’m not going to go through the parts on the exploitation. What is interesting to us here is the shellcode that is executed that will lead to our flag.</p><p>The beginning of the shellcode execution is at address 0x68031460. However, we should not put a breakpoint here from the start, because this address will get overflowed as part of the exploit. Hence I put a breakpoint at 0x671335f3 and wait till the address 0x68016082 is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*PqFyIjyuf-c5O158vKbWvA.png" /></figure><p>This address 0x68016082 is where the pre-ROP chains are found — the return at 0x6801608a marks the beginning of the ROP chain, all the way until the shellcode is called at 0x68031460.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*F2ec3kMn8vWU8lYyfLtPqw.png" /></figure><p>The shellcode then starts to perform some decoding on itself, which means that breakpointing here has to be done carefully after the decoding is done, else you will end up crashing or the shellcode will not decode correctly. The decoding loop starts from 0x68031544 and will only be done when the code calls 0x68031553. It’s abit complex to describe the entire loop here in words, so I apologise for not going to try to confuse you. But you can try to step instruction by instruction to get a feel of what is happening here in the decoding loop. The ultimate outcome is that we get a properly decoded shellcode starting at 0x68031553.</p><p>It is safe to breakpoint at 0x68031553 after seeing that the memory at 0x68031550 looks like the one in the following screencapture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*1lrHNq5YHuXRyvgVmpREtA.png" /></figure><p>At this point, I also dumped the shellcode out to look at it in IDA Pro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*mUO80-Yn-LrXkbD2HqlwEw.png" /></figure><p>I’ll continue to use dynamic analysis to help me make sense of what I see in IDA Pro. In the screenshot above, “call ebp” is calling 0x68031558, which performs hash-decoding and then call the function. So for example, at 0x6803165C, VirtualAlloc is being called and the allocated memory address is returned in eax.</p><p>What is happening in here is that the shellcode expects to receive something which starts with 4 bytes that is XORed with “ROXK” and then used as a size expected of subsequent data to be received.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*MCdyDs4dpgiOH6Pz_vCq8g.png" /></figure><p>Next, RC4 decryption is being applied onto the received data. The key used is also hardcoded within the shellcode — “killervulture123”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*xrDGjHREUiZjlsmP-vz1_Q.png" /></figure><p>From the pcap, we have this data! We can feed it into the shellcode via ncat. Opening the decrypted data in another IDA instance, we see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Hkx7IjW5VsqkhYDzxQ-Sjw.png" /></figure><p>The interesting function is at 0x1CA048F. Whatever happened before the call to this function is just hash decoding of API calls. With a little bit more help from dynamic analysis, and a little bit of intuitive guessing, I was able to tell that the 2nd piece of data found in the pcap that is received from the server is RC4-encrypted with the key “intrepidmango” read from C:\accounts.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*eRmyjGw17PnjiSRs8CUe4Q.png" /></figure><p>Let’s confirm this guess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*oTu3jUuH4sgyw8GfWaIQxA.png" /></figure><p>Didn’t work for you? Have you tried turning it off and on again? :D</p><p><strong>(WSL) 8_-_Aardvark</strong></p><p>This challenge is pretty straightforward. I think the “hurdle” presented here is a psychological one. We were all looking for a flag that looked like.. well, a flag. But this one came up to be a gibberish flag.. But nonetheless, still an interesting binary, I had fun playing tic tac toe for a while before I got to solving it.</p><p>First we need a Win10 environment because Windows Subsystem for Linux (WSL) is required for this binary to run. Get one here: <a href="https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/">https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/</a>.</p><p>While the Win10 is downloading and installing, I was poking around the binary and found the Linux component in the resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*fVGKbtq_prEOlYOPA7DtHw.png" /></figure><p>This ELF does not have many functions but the main function looked like this @.@</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*821qLkLshUherZv_n83aVQ.png" /></figure><p>Statically analyzing the instructions slowly, we can kind of tell that it is preparing the game board, waiting for moves from the user and checking the moves. At one point, the winner is being checked and if the winner is “O”, the binary proceeds to do a series of value fetching e.g. opening /proc/modules, /proc/mounts, /proc/version_signatures etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*8Vx1aICGXHaeHE7G2M6S6Q.png" /></figure><p>Now, after all this static analysis is done, your Win10 environment should be ready. Let’s play tic tac toe for awhile..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*-rOw2BNP6oIPflSdr5Op_g.png" /></figure><p>You might notice you will never win :&lt;</p><p>Ok back to breaking the game because YOU WANT TO WIN!</p><p>Now, notice that only when ‘O’ wins, we can get to hit line 220 in the decompiled view below. Which means that we need to patch the jumps so that even with “X” wins, we can get where we want to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*maUN7zOtN3cUGVCuO6DLog.png" /></figure><p>So we patched these two jumps here..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*4K7eBDAUIjTdWqRij6trHg.png" /></figure><p>Also, we need to cheat the binary into acknowledging that the winner is ‘O’, else the XOR operation that we saw previously that acts on the encrypted flag will not give us the right output. Hence, patch the binary here to set EAX to 0x4F:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*CfbKBJzq1JGbe5Xcduzokg.png" /></figure><p>Now, play the game!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*AQGS9F05PbPQHAxMvxb9kw.png" /></figure><p>I don’t care who wins, just give me the flag :D</p><p>I’ll like to thank the kind soul who mentioned on Twitter about submitting the flag the moment you see readable ASCII. Else I think I would smash my computer if I only realised that this gibberish is the real flag 2 days later…</p><p><strong>(Kernel debugging, COM) 9_-_crackinstaller</strong></p><p>In summary, this level is just lots of hardwork debugging, and then a stroke of luck and a tinge of intuition and it’s done.</p><p>The hardwork begins with trying to set up kernel debugging. It’s not that hard actually. Follow these instructions and it’s a smooth ride: <a href="https://voidsec.com/windows-kernel-debugging-exploitation/">https://voidsec.com/windows-kernel-debugging-exploitation/</a></p><p>If you are planning on doing FlareOn8 next year, keep a snapshot of this environment after you get it up.. I’ve been using my snapshots from the previous years — there is always one kernel debugging level in FlareOn :P</p><p>With the help of a debugger (may not be windbg here, you can use anything you like because we still in user space), we can do a cursory analysis of the crackinstaller binary. Then we notice that it creates a file cfs.dll, followed by a call to DeviceIoControl (not immediately, but the code leads one way)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*aQWbQBETXt80snu5sWcNBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*rAH-oOz0P9f2GXbh5J8dow.png" /></figure><p>That IoControlCode looks kind of strange. Google it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*mrPXB80UcxqTYzyC6ciJeA.png" /></figure><p>Ahah! Now we can find out what’s happening here. Again, Google’s translation to English works well for this post too. I’ll recommend reading this great post before continuing.</p><p>After reading, we understand that there is code execution via this cfs.dll driver , and we want to follow this code execution. Looking at cfs.dll with IDA Pro, we can see the function being executed when DeviceIoControl is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*o1xE12_lrMzv_SgttRRHFQ.png" /></figure><p>From this function sub_FFFFF88004BFE590, we can see that a shellcode subsequently gets loaded and called:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*iFmPLxHBHoFgSr_Jp5tHRQ.png" /></figure><p>Looks like what we are looking for — Let’s get right into kernel space debugging then!</p><p>In order to hook onto cfs.dll, we have to do a “bu cfs!DriverEntry”, followed by a “lm” to find out where the driver was loaded in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*kgKqQviSe94FJjHfM1ZDMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*kb3vB90xBnoYI2rCPR4IIg.png" /></figure><p>Put a breakpoint at where we expect the shellcode to be loaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*D_YDeLzV-POPyL9uCmjuSQ.png" /></figure><p>The code execution goes into the shellcode. Dump this shellcode and look at it in IDA. Nothing fancy, just a way to jump to another address 0x13F002A10 in the exe (look at sub_2A10 in crackinstaller).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*v8YfRW1HuzpRsBDCWYio0w.png" /></figure><p>Personally I think my approach for analysing this binary is very rudimentary. Basically I copied output from windbg into my IDA Pro so that I can keep track of the values and then figure out what happened. So bear with my screen captures for the rest of this post, because you will see a lot of “bloated” comments in my IDA view :X</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*OHraoNTXxV__9poRMsurPg.png" /></figure><p>So when we enter this function, it starts to do a sort of dynamic loading of API functions. In windbg, I used the command “ln &lt;addr&gt;” to get the name of the API that is being retrieved. For example, in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*AzWyO9cU62-K2PP5MhchRA.png" /></figure><p>The result returned from the call at 0x140002A9C in RAX is 0xfffff80002e6df20. Executing the command “ln 0xfffff80002e6df20” in windbg gives us this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6YaJe3qXl4tiOgUMoW6lIQ.png" /></figure><p>And thus we know r12 is loaded with nt!IoCreateDriver.</p><p>With all these API calls properly labelled (hard work, yes), we get to this code that allocates some memory, and then get stuff moved into it. Finally a thread is created that starts execution at a function within this memory space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ZzAkPYrWrqSgCczv8caqsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*4fdl-mSV_GiMxUqyp0qrDg.png" /></figure><p>Dump this 0x5800 bytes from memory so we can take a look at what kinda monster it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6-Lpj0AK_k7cNoOtuTSYLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Y-NfeDxCGnkh4tNLxvAHvA.png" /></figure><p>There we go, this 3rd binary that we have to analyse is named “driver.sys”.</p><p>The new thread starts its execution in the DriverBootstrap of driver.sys. Within this function, it creates a copy of itself and calls IoCreateDriver to start the execution of DriverEntry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*tY7uk46vPNRAdbeHggMC7w.png" /></figure><p>Within DriverEntry, there is a call to CmRegisterCallbackEx that executes the function at 0xFFFFFA8005015970 every time a thread performs an operation to the registry (this is the definition from MSDN, but I don’t really understand it). What interests me here is that this function will get called when a condition is met, so we should see what happens in here.</p><p>I’m going to omit all the boring analysis steps — I just stepped through the function within windbg and try to link up what the function is doing. Until we reach this part where a decryption algorithm is found. We would obviously love to know what is this mysterious string that is decrypted. Let’s make windbg do the job for us by putting a breakpoint on where the salsa_decryption function is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ISoDC9LSaFypXJWg28A04w.png" /></figure><p>Nice! We found a string that looks like it’s a key to decrypt something…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*G-f36fbItzSpb5yfQORYsg.png" /></figure><p>The question is: what does it decrypt?</p><p>The answer is not that far off from where we found this password. In the same function, we see a registry key being created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*_pIiUEw7RvUwc1BAnRylTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*5__ur5lKK5UDUnsT_c2Dmw.png" /></figure><p>Let’s go find this regkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*g75l9s0otBofxpMIwVSM1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*4b9zhbe7lgRoJI-XJSBMqg.png" /></figure><p>Now let’s take many steps back and go back to the original crackinstaller binary again. This time, I found another function that writes a file to “C:\users\&lt;user&gt;\AppData\Local\Microsoft\Credentials\credHelper.dll”. This is where this file came from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*9MgCSmfrK5IxfCt7f05f1A.png" /></figure><p>OK, so now we shall analyze credHelper.dll. The clue to begin would probably be to find functions that read from/write to the regkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*g_EDsTO9smC7lepkaDUR1A.png" /></figure><p>Now let’s find where the data comes from. Slightly above this code block is a XOR decryption loop…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*RqX1509jfn2--4qZ6sVXag.png" /></figure><p>In another function within the vftable, a regkey “Password” is being read and used in a loop that kinda looks like RC4’s KSA, which makes sense if the XOR decryption loop is probably part of RC4 too. I wasn’t sure at this point, my guess is just based on intuition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*35s7L4565orpZpQtQFp6Dw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*E0kPEX14HHPahnXT75TQ6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*3ENDxdAIdSlJZW4Erj6OwQ.png" /></figure><p>Trying the decryption blindly…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*V6sXETP_rJaQaB5pkSnp3A.png" /></figure><p>And that’s it! Got the last part done based on intuition… If it had been any other decryption algorithm being used, I guess I would not have escaped from doing more COM-programming, which I saw other folks have coolly done :)</p><p>I ran out of energy writing just 7–9. Will have a part 3 for 10 and 11, stay tuned!</p><p>~~</p><p>Asuna<br><a href="https://twitter.com/AsunaAmawaka">https://twitter.com/AsunaAmawaka</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88baa92ffc9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insomniacs/journal-flareon7-part-2-88baa92ffc9b">Journal: FlareOn7 (Part 2)</a> was originally published in <a href="https://medium.com/insomniacs">insomniacs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>