<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Malware on Monish Kumar&#39;s Blog</title>
        <link>https://itsmonish.pages.dev/tags/malware/</link>
        <description>Recent content in Malware on Monish Kumar&#39;s Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <lastBuildDate>Sat, 26 Apr 2025 17:51:33 +0530</lastBuildDate><atom:link href="https://itsmonish.pages.dev/tags/malware/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Malware - Discount Programming Devices</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-discount-programming-devices/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-discount-programming-devices/</guid>
        <description>&lt;h1 id=&#34;discount-programming-devices&#34;&gt;Discount Programming Devices
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: @sudo_Rem&lt;/p&gt;
&lt;p&gt;I used a tool on the internet to obfuscate my script!&lt;/p&gt;
&lt;p&gt;But I lost it, and I don&amp;rsquo;t know how to get it back.&lt;/p&gt;
&lt;p&gt;Maybe you can help?&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/discount-programming-devices/oops.py&#34; &gt;oops.py&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;In this challenge, we have a python script that has a lambda function declaration assigned to an underscore &lt;code&gt;_&lt;/code&gt;. It takes an argument &lt;code&gt;__&lt;/code&gt; and has the contents as:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;_ &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;lambda&lt;/span&gt; __ : __import__(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;zlib&amp;#39;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;decompress(__import__(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;base64&amp;#39;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;b64decode(__[::&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What&amp;rsquo;s going on here is simple. The argument &lt;code&gt;__&lt;/code&gt; is reversed, and passed to base64 decoder and then in turn passed to the decompress function from the &lt;code&gt;zlib&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;Following this declaration, is an exec function call that references the function pointer and passes on a very lengthy argument. Since the size of the argument was long, I figured it might take several passes to get to the end, so I put a script together &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/discount-programming-devices/process.py&#34; &gt;process.py&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/discount-programming-devices/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;processing&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;With the script, we can see that it took 50 passes and finally we have another python code at the end of it. It seems to be of the same logic, but putting the contents in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/discount-programming-devices/final.py&#34; &gt;final.py&lt;/a&gt; and executing it gave me the flag.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/discount-programming-devices/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;flag&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now it really seems straightforward. But did I actually do anything? I just did what the script would&amp;rsquo;ve done but in separate steps. So just to check, now that I know what the script is, I ran the &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/discount-programming-devices/oops.py&#34; &gt;oops.py&lt;/a&gt; directly. It gave the flag just like that.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/discount-programming-devices/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;oops&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;So I was wondering what was the point, but didn&amp;rsquo;t really think much of it. Then going through the CTF discord server, the challenge author admitted it was indeed a mistake.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Malware - Eco Friendly</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-eco-friendly/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-eco-friendly/</guid>
        <description>&lt;h1 id=&#34;eco-friendly&#34;&gt;Eco-Friendly
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: @JohnHammond&lt;/p&gt;
&lt;p&gt;This sample is good for the environment!&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/eco_friendly&#34; &gt;eco_friendly&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;For this challenge, we are given a powershell script, or I should say, one very long line of powershell. Opening the given file we can see an iex (Invoke-Expression) cmdlet that will execute whatever command follows it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/eco-friendly/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;first half&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;But the argument for the cmdlet seems to a string with random numbers in curly braces. If we scroll down for some time, we can find the end of the string with a option &lt;code&gt;-f&lt;/code&gt; which is used to format strings in powershell.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/eco-friendly/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;second half&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;What follows the &lt;code&gt;-f&lt;/code&gt; is lots of environment variables with an index number. Which means the script uses, fixed environment variables that is uniform across all Windows machine to construct the payload from the individual characters indexed from said environment variables. The random numbers in curly braces are just positional parameters. This type of technique is used to evade detection from anti-malware solutions which may scan for suspicious keywords.&lt;/p&gt;
&lt;p&gt;Now that we know this, we can just replace the &lt;code&gt;iex&lt;/code&gt; at the starting with a &lt;code&gt;Write-Host&lt;/code&gt; cmdlet to write whatever the string will be constructed to rather than executing it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/eco-friendly/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;payload&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Doing that, saving it to &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/payload.ps1&#34; &gt;payload.ps1&lt;/a&gt; and executing the script, reveals another level of obfuscation with the same technique. So putting that in file &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/stage1&#34; &gt;stage1&lt;/a&gt; and modifying the &lt;code&gt;iex&lt;/code&gt;  to &lt;code&gt;Write-Host&lt;/code&gt; in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/stage1_modified.ps1&#34; &gt;stage1_modified.ps1&lt;/a&gt; and executing again leads to another level of same obfuscation. Repeating the same with &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/stage2&#34; &gt;stage2&lt;/a&gt; and &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/stage2_modified.ps1&#34; &gt;stage2_modified.ps1&lt;/a&gt; leads to another level of obfuscation. Doing it again with &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/stage3&#34; &gt;stage3&lt;/a&gt; and &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/eco-friendly/stage3_modified.ps1&#34; &gt;stage3_modified.ps1&lt;/a&gt; finally gave away the flag as a comment.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/eco-friendly/4.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;flag&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I should have anticipated nested levels of obfuscation and written a script to get the process done, but still unsure of what it might hold, I did it manually. But got the flag at the end.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Malware - Palimpsest</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-palimpsest/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-palimpsest/</guid>
        <description>&lt;h1 id=&#34;palimpsest&#34;&gt;Palimpsest
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: Adam Rice (@adam.huntress)&lt;/p&gt;
&lt;p&gt;Our IT department was setting up a new workstation and started encountering some strange errors while installing software.&lt;/p&gt;
&lt;p&gt;The technician noticed a strange scheduled task and luckily backed it up and grabbed some log files before wiping the machine!&lt;/p&gt;
&lt;p&gt;Can you figure out what&amp;rsquo;s going on?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;We&amp;rsquo;ve included the exported scheduled task and log files below.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The archive password is &lt;code&gt;infected-palimpsest&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/Challenge.zip&#34; &gt;Challenge.zip&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;The attachment archive contains 3 event viewer logs (Application, Security and System) and a &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/Updater%20Service.xml&#34; &gt;Updater Service.xml&lt;/a&gt;. I first opened the XML file, which is the scheduled task that the challenge description tells about.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;xml file&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;While most of the contents of the XML file is pretty much what you&amp;rsquo;d find in most scheduled tasks, I was more interested in the actions of the task. As we can see, it is a powershell line, that collects the DNS TXT records from the site &lt;code&gt;5aa456e4dbed10b.pyrchdata.com&lt;/code&gt;, base64 decodes it, builds a string from it and executes it. So I queries the DNS TXT records myself to find out base64 data in it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;base64 txt&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Putting the contents in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/txt_records&#34; &gt;txt_records&lt;/a&gt; and decoding it, yields a powershell script with some obfuscation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage1&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;The first brackets reference the shell ID which I&amp;rsquo;m quite sure is constructing &lt;code&gt;iex&lt;/code&gt; cmdlet. Putting that in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/stage1_payload.ps1&#34; &gt;stage1_payload.ps1&lt;/a&gt; and modifying the &lt;code&gt;iex&lt;/code&gt; with &lt;code&gt;Write-Host&lt;/code&gt; should give us the next part of the payload.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/4.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage2&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Doing that does indeed reveals the next part of the payload. Now we still have an obfuscated script. The first line now tries to get a variable that matches the pattern &lt;code&gt;*mdr*&lt;/code&gt; and constructs something. I was pretty sure that is also &lt;code&gt;iex&lt;/code&gt; as well, but to be sure, I checked. Repeating the same trick we move on to the next stage of payload.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/5.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage3&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now this payload doesn&amp;rsquo;t have any base encoded strings, on the contrary &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/stage3_payload.ps1&#34; &gt;stage3_payload.ps1&lt;/a&gt; does something else. But I couldn&amp;rsquo;t fully read it because of the garbled format strings. I decided to clean it and substitute those strings to their result, I had &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/stage3_cleaned.ps1&#34; &gt;stage3_cleaned.ps1&lt;/a&gt; which was more readable.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/6.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage3 cleaned&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;We can now see clearly, that the payload gets the application event log with source as &lt;code&gt;mslnstaller&lt;/code&gt; (notice the typosquatting) and filters events with InstanceID within 40000 - 65000, extracts &amp;ldquo;data&amp;rdquo; from those logs and writes it to the a file named &lt;code&gt;flag.mp4&lt;/code&gt; in the AppData folder.&lt;/p&gt;
&lt;p&gt;Now we have use for those event log files, opening Application.evtx in windows event viewer and filtering events between 40000 - 65000 with source as &lt;code&gt;mslnstaller&lt;/code&gt; we have exactly 100 such logs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/7.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;event viewer logs&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Every record out of those 100 logs had a data node with some text and binary data. It is fair to assume that the binary data is what is being written to &lt;code&gt;flag.mp4&lt;/code&gt; all we have to do is extract it.&lt;/p&gt;
&lt;p&gt;Now I can write powershell scirpts to some level, I didn&amp;rsquo;t know how to extract fields from saved log files in it at the time of solving this challenge. So converted the .evtx files to .csv using &lt;a class=&#34;link&#34; href=&#34;https://github.com/josephatmwanzia/evtx2csv&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;this&lt;/a&gt; tool.&lt;/p&gt;
&lt;p&gt;Once I converted it, it was fairly easy for me to put a python script &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/extract_data.py&#34; &gt;extract_data.py&lt;/a&gt; together to extract the binary data and write to a file. The logic behind the script is simple. It opens the csv file and parses it using the &lt;code&gt;csv&lt;/code&gt; module and then checks each row for the condition required as in the powershell script. Then I used &lt;code&gt;unhexlify&lt;/code&gt; from &lt;code&gt;binascii&lt;/code&gt; module to convert the hex to actual binary data and wrote it to a file &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/palimpsest/from_evtx_data&#34; &gt;from_evtx_data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Even though the powershell script tells us it is an mp4, I was still a little suspicious it might be something else. But when I ran &lt;code&gt;file&lt;/code&gt; utility on it, it revealed that it is indeed a MP4 video file. Opening it got me:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/palimpsest/8.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;free real estate&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;So it says &amp;ldquo;It&amp;rsquo;s free real estate&amp;rdquo; and yeah the flag is there too. I tried using OCR to get the flag from the video, but it had a few mistakes which I had to correct it manually.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Malware - Ping Me</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-ping-me/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-ping-me/</guid>
        <description>&lt;h1 id=&#34;ping-me&#34;&gt;Ping Me
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: @JohnHammond&lt;/p&gt;
&lt;p&gt;We found this file in the autoruns of a host that seemed to have a lot of network activity&amp;hellip; can you figure out what it was doing?&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/ping-me/ping_me.vbs&#34; &gt;ping_me.vbs&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;For this challenge we are given a VBScript.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/ping-me/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;vbscript&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now I am not familiar with VBScript, but looking at the script we can observe an &amp;ldquo;Execute&amp;rdquo; at the start and a long expression. So it is logical to conclude that the expression evaluates to something and the &amp;ldquo;Execute&amp;rdquo; will execute whatever the expression evaluates to.&lt;/p&gt;
&lt;p&gt;In order to know what it really does, we just need to replace &amp;ldquo;Execute&amp;rdquo; with some print statement from VBScript. So I opened &lt;a class=&#34;link&#34; href=&#34;https://www.onlinegdb.com/online_vb_compiler&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;onlinegdb&lt;/a&gt; and it already had boilerplate code to output something (Hello world). I just modified it to evaluate the expression and output it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/ping-me/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;onlinegdb&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now we can see, that it indeed gets another script which should be VBScript as well. After adding some spaces and newline to it we have:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/ping-me/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;ping script&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;This script seems to have a list of IP address and runs a ping command on all of them. Well that explains the part of challenge description that says &amp;ldquo;a lot of network activity&amp;rdquo;, but what now?&lt;/p&gt;
&lt;p&gt;The IP address may seem random to an untrained eye. But I recognized them not to be random. You see the each octect in the IP address is a valid ASCII character and most of them are in alphabet and number character ranges.&lt;/p&gt;
&lt;p&gt;So I copied the list of IP address, put them in a &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/ping-me/solve.py&#34; &gt;solve.py&lt;/a&gt; to process them and convert them to a valid string. The script just splits the octets put them in a list and uses &lt;code&gt;chr&lt;/code&gt; function to convert the octets to valid characters.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ips &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;102.108.97.103&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;123.54.100.49&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;98.54.48.52&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;98.98.49.98&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;54.100.97.51&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;50.98.56.98&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;98.99.97.57&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;101.50.54.100&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;53.49.53.56&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;57.125.35.35&amp;#34;&lt;/span&gt;]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;chars &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; ip &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; ips:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    chars&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extend(ip&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;split(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;.&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;flag &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;join([chr(int(i)) &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; i &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; chars])
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;print(flag&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;strip(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;#&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This script gave away the flag.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/ping-me/4.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;flag&#34;
	
	
&gt;&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Malware - Revenge of the Discount Programming Devices</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-revenge-of-the-discount-programming-devices/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-revenge-of-the-discount-programming-devices/</guid>
        <description>&lt;h1 id=&#34;revenge-of-discount-programming-devices&#34;&gt;Revenge of Discount Programming Devices
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: @sudo_Rem&lt;/p&gt;
&lt;p&gt;One of our security analysts learned to avoid printing out flag when obfuscating code!&lt;/p&gt;
&lt;p&gt;Unfortunately, now they&amp;rsquo;ve lost that flag.&lt;/p&gt;
&lt;p&gt;Maybe you can help them get it back.&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/challenge&#34; &gt;challenge&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;In this challenge we are given a binary, an ELF binary to be specific. Running 	&lt;code&gt;strings&lt;/code&gt; utility on the binary among the entries we can find strong indicators (as shown below) that the binary has been compiled using &lt;a class=&#34;link&#34; href=&#34;https://pyinstaller.org/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;pyinstaller&lt;/a&gt;. This is a tool to convert python source code files to executable binaries.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;pyinstaller indicators&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;There is this tool called &lt;a class=&#34;link&#34; href=&#34;https://github.com/extremecoders-re/pyinstxtractor&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;pyinstxtractor&lt;/a&gt; that can extract the contents of a binary that is compiled by pyinstaller.  Using that tool I was able to dump all the contents of the binary into a folder. Since it is a statically linked binary there were quite a few things that got extracted. But we are focused on the &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/challenge.pyc&#34; &gt;challenge.pyc&lt;/a&gt;. This file contains the bytecode of the original file that was used to compile.&lt;/p&gt;
&lt;p&gt;We still need to convert the bytecode to actual source code before we can work on what it does. For that we can make use of another tool called &lt;a class=&#34;link&#34; href=&#34;https://github.com/zrax/pycdc&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;pycdc&lt;/a&gt;. Using the tool, I converted bytecode file &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/challenge.pyc&#34; &gt;challenge.pyc&lt;/a&gt; to &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/decompiled.py&#34; &gt;decompiled.py&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;decompiled&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now we have something to work on. On top of the code we can observe a lambda function that is assigned to a function pointer variable &lt;code&gt;_&lt;/code&gt; (underscore). It takes an argument which is &lt;code&gt;__&lt;/code&gt; (two underscores). The function reverses the data it gets, does a base64 decoding and uses the &lt;code&gt;zlib&lt;/code&gt; module to decompress the decoded contents. Then there is a &lt;code&gt;exec&lt;/code&gt; function that uses the function pointer &lt;code&gt;_&lt;/code&gt; and passes a very long string of data to it.&lt;/p&gt;
&lt;p&gt;Since the string was very long, I suspected multiple levels of same obfuscation. So I wrote a python script &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/solve_stage1.py&#34; &gt;solve_stage1.py&lt;/a&gt; to run the data till there is a exec function in the code.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;decoded 1&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/4.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;decoded 2&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;As we see, after 50 passes, we get a long list of numbers. But this list is commented out. At the end of the list there are 2 print statements out of which is one commented out. The first print statement simply joins the result of &lt;code&gt;chr&lt;/code&gt; function of each number in the list. The other prints out a string. I put this contents to &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/stage2.py&#34; &gt;stage2.py&lt;/a&gt; and reversed the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/5.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage 2&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/6.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage 2 end&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Since this provides us with another python script, I put that in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/stage3.py&#34; &gt;stage3.py&lt;/a&gt;, and cleaned the names of the variables. The variables were named with different number of underscores whose real names were declared at the start.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/7.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage 2 cleaned&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;After cleaning them, the functionality was revealed to be just an XOR operation between the two long byte sequence and print the output.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/8.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;stage 3&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now we are once again facing the same function as the first round of payload. So I made a copy of &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/solve_stage1.py&#34; &gt;solve_stage1.py&lt;/a&gt; as &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/solve_stage4.py&#34; &gt;solve_stage4.py&lt;/a&gt; and swapped the argument payload.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/revenge-of-the-discount-programming-devices/9.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;final&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;And executing &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/revenge-of-the-discount-programming-devices/solve_stage4.py&#34; &gt;solve_stage4.py&lt;/a&gt; gave away the flag.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Malware - Russian Roulette</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-russian-roulette/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-russian-roulette/</guid>
        <description>&lt;h1 id=&#34;russian-roulette&#34;&gt;Russian Roulette
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: @JohnHammond&lt;/p&gt;
&lt;p&gt;My PowerShell has been acting &lt;em&gt;really weird!!&lt;/em&gt; It takes a few seconds to start up, and sometimes it just crashes my computer!?!?! &lt;strong&gt;:(&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;WARNING: Please examine this challenge inside of a virtual machine for your own security. Upon invocation there is a real possibility that your VM may crash.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE: Archive password is &lt;code&gt;russian_roulette&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/russian_roulette.zip&#34; &gt;russian_roulette.zip&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;Extracting the archive outputs only a lnk file. &lt;a class=&#34;link&#34; href=&#34;https://fileinfo.com/extension/lnk&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;LNK&lt;/a&gt; files are basically shortcuts in windows. There are special files that open other files or execute commands. LNK files are a common threat vector as phishers can disguise anything as LNK file.&lt;/p&gt;
&lt;p&gt;For this challenge we have a &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/Windows%20PowerShell.lnk&#34; &gt;Windows PowerShell.lnk&lt;/a&gt;.  To see what it really opens we need a parser that can parse the LNK file contents. I found this tool called &lt;a class=&#34;link&#34; href=&#34;https://github.com/Matmaus/LnkParse3&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;LnkParse3&lt;/a&gt; that could do what I want.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;target&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;So the target of the shortcut is not a file but a powershell command. The &lt;code&gt;-e&lt;/code&gt; option allows encoded scripts or strings to execute. This is basically more powershell command but encoded in base64.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;decoded base64&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;On decoding the argument, we can observe that it uses the &lt;code&gt;iwr&lt;/code&gt; (&lt;code&gt;Invoke-WebRequest&lt;/code&gt;) cmdlet to download the contents pointed by the link and save it to a file &lt;code&gt;.cmd&lt;/code&gt; in the temp folder. Finally this &lt;code&gt;.cmd&lt;/code&gt; file is executed.&lt;/p&gt;
&lt;p&gt;Collecting the contents of the link downloaded a &lt;code&gt;powershell.zip&lt;/code&gt; but it was in fact a batch script. So I renamed it to &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/raw_payload.bat&#34; &gt;raw_payload.bat&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For some reason I don&amp;rsquo;t know, this batch file when opened with text editors showed garbled text, but when I used &lt;code&gt;cat&lt;/code&gt;  utility from the terminal it displayed the batch script. My theory was that it is because of the first two characters of the file where not recognizable. When I removed it and put the rest of the script in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/payload.bat&#34; &gt;payload.bat&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There were a lot of Russian comments (or I should say quotes) in the file. So I put together &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/cleanse.py&#34; &gt;cleanse.py&lt;/a&gt; to remove those commands and write the contents to &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/payload%20cleaned.bat&#34; &gt;payload cleaned.bat&lt;/a&gt;. Now I had more visibility over the code.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;start of deobfuscation&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I have seen this type of obfuscation before. So at the start of the script we can see a variable &lt;code&gt;ucbw&lt;/code&gt; to getting set as &lt;code&gt;set&lt;/code&gt;. Following it are lines that start with using the variable &lt;code&gt;ucbw&lt;/code&gt;. If we replace &lt;code&gt;ucbw&lt;/code&gt; as &lt;code&gt;set&lt;/code&gt; everywhere in the script, it is one step deobfuscating the script.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/4.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;space in&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;The variable &lt;code&gt;qmy&lt;/code&gt; is not empty actually. It has a white space. So replace &lt;code&gt;%qmy%&lt;/code&gt; with a single whitespace in the script and replacing &lt;code&gt;%jxaa%&lt;/code&gt; with &lt;code&gt;=&lt;/code&gt;, we get:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/5.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;deob cont&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Now we can keep on replacing variables with characters till we hit this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/6.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;different thing&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;The expression &lt;code&gt;set /a rtoy=9161456 %% 9161359&lt;/code&gt; mean set the variable &lt;code&gt;rtoy&lt;/code&gt; with the resultant value of arithmetic expression &lt;code&gt;9161456 %% 9161359&lt;/code&gt;. &lt;code&gt;%%&lt;/code&gt; is the modulus operation. So rtoy will be assigned 97, in this case. Next up we have &lt;code&gt;cmd /c exit=%rtoy%&lt;/code&gt;. &lt;code&gt;cmd \c&lt;/code&gt; executes the command passed to it. And that command here is exit with the exit code specified by variable &lt;code&gt;rtoy&lt;/code&gt;. Next up &lt;code&gt;set ztq=%=exitcodeAscii%&lt;/code&gt;.  &lt;code&gt;%=exitcodeAscii%&lt;/code&gt; is an undocumented dynamic variable in windows, that for some reason returns the exit code of the last program as an ascii character.&lt;/p&gt;
&lt;p&gt;Putting them together, the second line executes a cmd exit command with a exit code and the next command gets that exit code as ascii. In ascii 97 maps to the character &amp;lsquo;a&amp;rsquo;.  Now the variable &lt;code&gt;%ztq%&lt;/code&gt; can be used whenever you need a character &amp;lsquo;a&amp;rsquo;. So essentially for the next many commands are just construction of alphabets, numericals and symbols.&lt;/p&gt;
&lt;p&gt;De-obfuscating all that yielded &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/payload%20deobfuscated.bat&#34; &gt;payload deobfuscated.bat&lt;/a&gt;. In that you will find another encoded powershell payload.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/7.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;base64 payload&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I copied that payload and put it in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/powershell%20base64.txt&#34; &gt;powershell base64.txt&lt;/a&gt; to decode the contents.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/8.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;ps1 payload&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I put the contents obtained in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/powershell%20payload.ps1&#34; &gt;powershell payload.ps1&lt;/a&gt; and modified it to make it easy on the eyes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/9.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;cs payload&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Looking at the powershell script, we can see another sort of code in the variable &lt;code&gt;$s&lt;/code&gt;. Since I spent some time with C#, I recognized it right away. So the code creates an compiler object, compiles the function &lt;code&gt;Shot&lt;/code&gt; in the class &lt;code&gt;X&lt;/code&gt; , then with a 1 out of 6 chance executes the function &lt;code&gt;Shot&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The function &lt;code&gt;Shot&lt;/code&gt; contains some areas of interest. It imports two functions from the &lt;code&gt;ntdll.dll&lt;/code&gt;. And does AES decrytion on some data. But after some time of research on the internet, I found out that &lt;code&gt;NtRaiseHardError&lt;/code&gt; is an undocumented API from windows, that can be used to force BSOD (Blue Screen of Death) errors. Effectively this will restart you operating system. So even if function &lt;code&gt;Shot&lt;/code&gt; is executed it crashes the OS before it reaches the decryption code.&lt;/p&gt;
&lt;p&gt;So I put &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/russian-roulette/solve.cs&#34; &gt;solve.cs&lt;/a&gt; removing the DLL imports and put a writeline to output the decrypted content.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/10.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;flag&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;And that indeed was the flag. Also if you don&amp;rsquo;t want to dabble with C#, then you can just copy the decryption data on cyberchef and obtain the flag that way as well.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/russian-roulette/11.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;flag again&#34;
	
	
&gt;&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Malware - Strange Calc</title>
        <link>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-strange-calc/</link>
        <pubDate>Sat, 26 Apr 2025 17:51:33 +0530</pubDate>
        
        <guid>https://itsmonish.pages.dev/blog/huntress-ctf-2024/malware-strange-calc/</guid>
        <description>&lt;h1 id=&#34;strange-calc&#34;&gt;Strange Calc
&lt;/h1&gt;&lt;h2 id=&#34;challenge-statement&#34;&gt;Challenge Statement
&lt;/h2&gt;&lt;p&gt;Author: @JohnHammond&lt;/p&gt;
&lt;p&gt;I got this new calculator app from my friend! But it&amp;rsquo;s really weird, for some reason it needs admin permissions to run??&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE: Archive password is &lt;code&gt;strange_calc&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/strange-calc/calc.zip&#34; &gt;calc.zip&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;solution&#34;&gt;Solution
&lt;/h2&gt;&lt;p&gt;Extracting the archive, we have a &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/strange-calc/calc.exe&#34; &gt;calc.exe&lt;/a&gt; that appears to be a PE executable. Running &lt;code&gt;file&lt;/code&gt; command on the executable proves that it is indeed a PE executable but also reveals that it is a UPX packed executable.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/1.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;file output&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class=&#34;link&#34; href=&#34;https://upx.github.io/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;UPX&lt;/a&gt; is a &amp;ldquo;packer&amp;rdquo; program that compresses executables making them effectively smaller. But since compression increases the entropy of the executable, or in other words garbles the contents in the executable, packers are used to sneak malwares and evade a number of security tools.&lt;/p&gt;
&lt;p&gt;We can use the &lt;code&gt;upx&lt;/code&gt; command line tool to unpack a executable using the command &lt;code&gt;upx -d &amp;lt;executable&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I unpacked the binary to &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/strange-calc/calc_unpacked.exe&#34; &gt;calc_unpacked.exe&lt;/a&gt;, but this will turn out to be not necessary at all.&lt;/p&gt;
&lt;p&gt;I ran the strings utility on the executable trying to find some clues to deduce what kind of functionality the program has. While the unpacked version provided with function names used in the program they weren&amp;rsquo;t enough to make things clear. But then I saw a XML amidst the outputs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/2.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;xml output&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;It seemed to be a manifest of some kind, and has the name &amp;ldquo;AutoIT&amp;rdquo; in it. I actually had no idea what it was. I never even heard of it at that point. A quick internet search provided the needed details. &lt;a class=&#34;link&#34; href=&#34;https://www.autoitscript.com/site/autoit/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;AutoIT&lt;/a&gt; is a scripting language that can be used to automate windows UI and things.&lt;/p&gt;
&lt;p&gt;So that led to another question &amp;ldquo;What is a script doing in a executable?&amp;rdquo;. That was also quickly answered with a few more searches and I even found a tool called &lt;a class=&#34;link&#34; href=&#34;https://github.com/nazywam/AutoIt-Ripper&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;AutoIt-Ripper&lt;/a&gt; that can extract AutoIT scripts from executables.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/3.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;ripping script&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/4.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;found base64&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;rsquo;t understand what most of the code does, but the base64 string did catch my eye right away. So I decided to decode what it does.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/5.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;decode base64&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;rsquo;t know what this was either. But the &lt;code&gt;#@~^&lt;/code&gt; at the start and &lt;code&gt;^#~@&lt;/code&gt; at the end strongly suggested this is not random data. I found the start in &lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/List_of_file_signatures&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Wikipedia&amp;rsquo;s list of file signatures&lt;/a&gt; and it seems it is encoded VBScript. If it&amp;rsquo;s encoded there must be ways to decode it.&lt;/p&gt;
&lt;p&gt;After searching for a little I found several decoders for the job. Like &lt;a class=&#34;link&#34; href=&#34;https://master.ayra.ch/vbs/vbs.aspx&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;this&lt;/a&gt; one, a &lt;a class=&#34;link&#34; href=&#34;https://github.com/JohnHammond/vbe-decoder&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;vbe-decoder&lt;/a&gt; repo from the challenge author himself and even cyberchef had a recipe for it. I decided to go with cyberchef for the job.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/6.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;decode jse&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Decoding the script, I noticed that it is not VBScript, but JavaScript. I put on a JS beautifier to read the code better. I put the code in &lt;a class=&#34;link&#34; href=&#34;https://itsmonish.pages.dev/others/huntressctf-2024/strange-calc/decoded.js&#34; &gt;decoded.js&lt;/a&gt;. The function does some decoding stuff, but I was more interested in the part below the function.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/7.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;interesting stuff&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;I did know what was in variable &lt;code&gt;m&lt;/code&gt; though.  This is called &lt;a class=&#34;link&#34; href=&#34;https://en.wikipedia.org/wiki/Uuencoding&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;uuencoding&lt;/a&gt;. This is another binary to text encoding like base64 but was first devised to transfer data between unix machines. Hence the name u-u-encoding. So the script has function &lt;code&gt;a&lt;/code&gt; to decode the data, create a new user LocalAdministrator, use the decoded data as password, add the user to administrator group and then run calc.exe (again I guess).&lt;/p&gt;
&lt;p&gt;So it seems straightforward right? Decode the uuencoding and we should probably have the flag right? Well, yes but no. The encoded data in the javascript is not standard encoding. So only function &lt;code&gt;a&lt;/code&gt; can decode it. So I put the function in my browser&amp;rsquo;s javascript runtime and used &lt;code&gt;console.log&lt;/code&gt; to print the output.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/8.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;browser no output&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;No output? How? I know this was crazy thinking but I thought &amp;ldquo;Perhaps it will only work on a windows runtime&amp;rdquo;. The return value will be the password of the user LocalAdministrator. So if I execute calc.exe in a virtual machine and then extract password from the account, I could have the return value.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/9.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;no password&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;Guess what? The account was indeed created after I executed it, but it had no password. So I thought I went down the wrong rabbit hole and started performing dynamic analysis with &lt;a class=&#34;link&#34; href=&#34;https://github.com/mandiant/flare-fakenet-ng&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;flare-fakenet&lt;/a&gt;, ProcMon, x64dbg and quite others. But nothing seemed to make much sense.&lt;/p&gt;
&lt;p&gt;After sometime I decided to take good look at the function code. And then it caught my eye.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/10.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;find it?&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;The function returns only a substring of the decoded string. So what was in the entire string? I then added &lt;code&gt;console.log(c)&lt;/code&gt; before the return statement and ran the code again in my browser&amp;rsquo;s runtime.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://itsmonish.pages.dev/images/huntressctf-2024/strange-calc/11.png&#34;
	
	
	
	loading=&#34;lazy&#34;
	
		alt=&#34;flag&#34;
	
	
&gt;&lt;/p&gt;
&lt;p&gt;So yeah there was the flag. I was literally looking at it the whole time but it still managed to evade.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
