<?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 pugachev.io</title><link>https://pugachev.io/tags/malware/</link><description>Recent content in Malware on pugachev.io</description><generator>Hugo</generator><language>en-US</language><copyright>© Maxim Pugachev</copyright><lastBuildDate>Fri, 04 Dec 2026 13:46:18 +0100</lastBuildDate><atom:link href="https://pugachev.io/tags/malware/index.xml" rel="self" type="application/rss+xml"/><item><title>"Kernel Monarch" by Hack The Box</title><link>https://pugachev.io/2026/06/05/kernel-monarch-by-hack-the-box/</link><pubDate>Fri, 05 Jun 2026 13:36:46 +0100</pubDate><guid>https://pugachev.io/2026/06/05/kernel-monarch-by-hack-the-box/</guid><description>&lt;p&gt;This is a nice, compact, and straightforward way to brush up on basic Linux rootkits. The module includes full debugging information, so you won't have to spend much time working in IDA.&lt;/p&gt;&#10;&lt;p&gt;You get a loadable kernel module (LKM) with a modified flag: the file you have is not the one running on the host. The module hides itself from &lt;code&gt;lsmod&lt;/code&gt; in a simple way and hooks the &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;, and &lt;code&gt;syslog&lt;/code&gt; system calls, so neither &lt;code&gt;cat&lt;/code&gt; nor &lt;code&gt;dmesg&lt;/code&gt; shows the data you need.&lt;/p&gt;&#10;&lt;p&gt;The module hides its traces in a few files (&lt;code&gt;/proc/kallsyms&lt;/code&gt; and ftrace's function lists, for example), but the only interesting one is &lt;code&gt;/dev/kmsg&lt;/code&gt;, the kernel log buffer. So you need a way to read it unfiltered.&lt;/p&gt;&#10;&lt;p&gt;Luckily, the module only hooks the 64-bit &lt;code&gt;read&lt;/code&gt;, so other ways to read a file still work: &lt;code&gt;readv&lt;/code&gt;, &lt;code&gt;pread64&lt;/code&gt;, or even the 32-bit &lt;code&gt;read&lt;/code&gt;. GCC is installed on the host, so the task boils down to writing a small C program, compiling it, and using it to read the messages.&lt;/p&gt;&#10;&lt;p&gt;Have fun!&lt;/p&gt;&#10;&lt;p&gt;You can find the challenge &lt;a href="https://app.hackthebox.com/challenges/Kernel%20Monarch" target="_blank" rel="noopener"&gt;here&lt;/a&gt;.&lt;/p&gt;&#10;</description></item><item><title>"Iterative Virus" by Hack The Box</title><link>https://pugachev.io/2024/04/07/iterative-virus-by-hack-the-box/</link><pubDate>Sun, 07 Apr 2024 13:35:11 +0100</pubDate><guid>https://pugachev.io/2024/04/07/iterative-virus-by-hack-the-box/</guid><description>&lt;p&gt;A good pet project for a developer who wants to learn something new is writing a game. I've done this before, but it wasn't fun. The best project was writing a virus: tons of new knowledge, a broken OS when your creature &amp;quot;infected&amp;quot; something it shouldn't have (plus the infection algorithm didn't work correctly), and a fight with an antivirus that easily moved your file to quarantine. Oh, the good old days.&lt;/p&gt;&#10;&lt;p&gt;This challenge reminded me of those days: this is literally an old-school virus that infects files correctly! I don't mean this fancy &amp;quot;dropper with a downloader with a rootkit with...&amp;quot;, but rather something that finds a file, adds a new section, patches the entry point, and does all the things that viruses used to do. It even has something resembling polymorphic behavior! Pretty cool for a CTF challenge.&lt;/p&gt;&#10;&lt;p&gt;Let's start exploring it. First, this is a regular PE64 file:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-console" data-lang="shell"&gt;&lt;span class="line cmd"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; diec ./HELLO_WORLD_INFECTED_&lt;span class="se"&gt;\!\!\!&lt;/span&gt;.exe&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;PE64&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Linker: Microsoft Linker(14.28.30038)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Compiler: Microsoft Visual C/C&amp;#43;&amp;#43;(19.28.30038)[C]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Tool: Visual Studio(2019 version 16.9-16.10)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;p&gt;But, like a good old-fashioned infected file, it has a strange section that the entry point points to:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-console" data-lang="shell"&gt;&lt;span class="line cmd"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; objdump -wh ./HELLO_WORLD_INFECTED_&lt;span class="se"&gt;\!\!\!&lt;/span&gt;.exe &lt;span class="p"&gt;|&lt;/span&gt; grep ivir&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; 6 .ivir 00000d80 000000014001c000 000000014001c000 00018400 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line cmd"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; objdump -f ./HELLO_WORLD_INFECTED_&lt;span class="se"&gt;\!\!\!&lt;/span&gt;.exe &lt;span class="p"&gt;|&lt;/span&gt; grep start&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;start address 0x000000014001c000&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;p&gt;The code at the entry point also looks familiar: it first finds the address of the &lt;code&gt;GetProcAddress&lt;/code&gt; function using the &amp;quot;PEB technique&amp;quot;, and then resolves the addresses of additional functions that will be needed later. Here are the functions it tries to find, with their IDs:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;5: ExitProcess&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;6: CreateFileA&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;7: GetFileSize&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;8: CreateFileMappingA&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;9: MapViewOfFile&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;0x0C: FindFirstFileA&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;0x0D: FindNextFileA&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;0x0E: FindClose&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;0x0F: CloseHandle&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then the fun begins. The crackme checks whether the byte at offset 5 from the entry point (the one that follows the first &lt;code&gt;jmp&lt;/code&gt; instruction) is &lt;code&gt;5&lt;/code&gt;. If so, it calls a function that currently appears to be encrypted. Otherwise, it selects a 64-bit number based on this byte and stores it for decryption later. In the current binary, this byte is &lt;code&gt;1&lt;/code&gt;, so it looks like we need to do something to decrypt the extra code. So let's go with the flow and see what the crackme does next.&lt;/p&gt;&#10;&lt;p&gt;The next step is the actual infection phase. In short, it does the following:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Search for files matching the &lt;code&gt;*.exe&lt;/code&gt; wildcard, starting in the current directory.&lt;/li&gt;&#10;&lt;li&gt;Map the found file into memory using the &lt;code&gt;CreateFileMappingA&lt;/code&gt;/&lt;code&gt;MapViewOfFile&lt;/code&gt; functions.&lt;/li&gt;&#10;&lt;li&gt;If this file is not an EXE file (the first two bytes must be &lt;code&gt;MZ&lt;/code&gt;) or &lt;code&gt;_IMAGE_FILE_HEADER.Machine&lt;/code&gt; is not &lt;code&gt;0x8664&lt;/code&gt; (AMD64), close it and try to find another victim.&lt;/li&gt;&#10;&lt;li&gt;To avoid accidentally infecting your entire system, it only infects files with &lt;code&gt;0x53494854&lt;/code&gt; (&lt;code&gt;SIHT&lt;/code&gt;, or &lt;code&gt;THIS&lt;/code&gt; if you read the bytes in the file) in &lt;code&gt;_IMAGE_FILE_HEADER.TimeDateStamp&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;If there is enough space in the binary for a new &lt;code&gt;_IMAGE_SECTION_HEADER&lt;/code&gt;, it is added right after the last one. The new section has the following characteristics: &lt;code&gt;CNT_CODE | CNT_INITIALIZED_DATA | MEM_EXECUTE | MEM_READ&lt;/code&gt; and is named &lt;code&gt;.ivir&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;The actual virus code is then copied into the mapped memory, right after the last section (aligned to &lt;code&gt;FileAlignment&lt;/code&gt;, of course). By the way, when the crackme calls &lt;code&gt;MapViewOfFile&lt;/code&gt; in the second step, it already requests extra memory for the virus body.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;If everything goes well, the crackme moves to the encrypted part: it &amp;quot;decrypts&amp;quot; the copy in the new file one more time, using the key selected by the magic byte I described earlier. Given that the binary we have has a &lt;code&gt;1&lt;/code&gt; there, it uses &lt;code&gt;keys[1]&lt;/code&gt; and writes &lt;code&gt;2&lt;/code&gt; into the magic byte of the new file. In other words, every time it infects a file, it applies one more key and increments the byte. This means that if you run a newly infected file, it will use &lt;code&gt;keys[2]&lt;/code&gt;, and so on. When the magic byte is &lt;code&gt;5&lt;/code&gt;, the code is fully decrypted, and the virus calls it instead of infecting more files.&lt;/p&gt;&#10;&lt;p&gt;You could definitely play around with this and create specially crafted victim files to get the decrypted code back, but I cut corners and used the following IDC script:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x28C8AA0746A75909&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x6E2368B9C685770B&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x0EB7FD64E061C1A3D&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x0CB8FF2D53D7505A1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0x0F1EF554206DCE4D&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_screen_ea&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;get_screen_ea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x198&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_qword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nf"&gt;patch_qword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see, the decryption algorithm is just a multiplication. So, if you apply it 4 more times with the correct constants (the author has already done it once), you get the code back. Nice!&lt;/p&gt;&#10;&lt;p&gt;The decrypted code is simple: it shows you a message box with the flag if the name of the user running the binary matches the flag :) So you'll have to disassemble it anyway. Also, since this code runs inside an infected file, it also dynamically resolves the functions it needs, using the same idea as the main code.&lt;/p&gt;&#10;&lt;p&gt;One final note: the virus kindly stores the original entry point of the infected file in the qword following the magic byte. The only thing is that this is not the RVA itself, but the difference between the new and the original entry points. Feel free to write an antivirus.&lt;/p&gt;&#10;&lt;p&gt;The challenge can be found &lt;a href="https://app.hackthebox.com/challenges/Iterative%20Virus" target="_blank" rel="noopener"&gt;here&lt;/a&gt;.&lt;/p&gt;&#10;</description></item><item><title>"FFModule" by Hack The Box</title><link>https://pugachev.io/2024/03/25/ffmodule-by-hack-the-box/</link><pubDate>Mon, 25 Mar 2024 16:43:24 +0100</pubDate><guid>https://pugachev.io/2024/03/25/ffmodule-by-hack-the-box/</guid><description>&lt;p&gt;It's always fun to solve a challenge without even running the binary. Sometimes this is necessary because either you don't have the required hardware, OS, or library, or because the challenge has bugs and doesn't work. This crackme is an example of the latter: with my configuration at the time (Windows 11 + Firefox 124.0.1), it just crashed (that's after disabling Windows Defender, otherwise it gets killed even earlier). But in this case, a disassembler is enough.&lt;/p&gt;&#10;&lt;p&gt;This crackme is a classic example of how to inject malicious code into a process, and in particular, of how Firefox can be used as a target to steal data. Again, the problem is that this is a &amp;quot;classic&amp;quot; and an &amp;quot;example&amp;quot;, so even a mediocre antivirus will stop it.&lt;/p&gt;&#10;&lt;p&gt;But let's start from the very beginning: the code it injects is &amp;quot;hidden&amp;quot;, so at the first stage, the crackme &amp;quot;decrypts&amp;quot; it and then runs the injector. To see this code, just execute the following IDC script in IDA:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_screen_ea&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;get_screen_ea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x5A4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nf"&gt;patch_byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x72&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The injector doesn't look too fancy: it iterates through the list of running processes, and if a process's executable is &lt;code&gt;firefox.exe&lt;/code&gt;, it allocates memory in that process, copies the next stage into it, makes it executable, and starts a new thread there to run it.&lt;/p&gt;&#10;&lt;p&gt;The goal of the second stage is to install a trampoline in the &lt;code&gt;PR_Write&lt;/code&gt; function from &lt;a href="https://firefox-source-docs.mozilla.org/nspr/reference/pr_write.html" target="_blank" rel="noopener"&gt;Firefox's NSPR&lt;/a&gt;, which is used to write data to a file descriptor. To do this correctly, the following steps are needed:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;First, the shellcode (or what should I call it now?) finds the address of the &lt;code&gt;GetProcAddress&lt;/code&gt; function using the &amp;quot;PEB technique&amp;quot; described everywhere and by everyone, so I won't describe it here again.&lt;/li&gt;&#10;&lt;li&gt;It then finds the addresses of the &lt;code&gt;VirtualAlloc&lt;/code&gt; and &lt;code&gt;VirtualProtect&lt;/code&gt; functions and allocates executable memory to store the part of the original &lt;code&gt;PR_Write&lt;/code&gt; function that it will overwrite later.&lt;/li&gt;&#10;&lt;li&gt;The next step is to find the loaded Firefox library that contains the &lt;code&gt;PR_Write&lt;/code&gt; function: the shellcode compares the CRC32C hashes of the loaded library names with 3 values instead of using raw strings. At first, I could only identify &lt;code&gt;nss3.dll&lt;/code&gt; and guessed that another one should be &lt;code&gt;nspr4.dll&lt;/code&gt;, but the hash was different. It turns out that all 3 hashes are &lt;code&gt;nss3.dll&lt;/code&gt;, just spelled in different case: &lt;code&gt;nss3.dll&lt;/code&gt;, &lt;code&gt;NSS3.dll&lt;/code&gt; and &lt;code&gt;NSS3.DLL&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;It gets the address of the &lt;code&gt;PR_Write&lt;/code&gt; function and copies part of the function into the memory allocated in the second step. What's interesting is that the shellcode copies bytes until it finds the following byte sequence: &lt;code&gt;0x003300730073006E&lt;/code&gt;, which is the UTF-16 string &amp;quot;nss3&amp;quot;. Honestly, I don't know why it wouldn't use the exact size here, but it is what it is.&lt;/li&gt;&#10;&lt;li&gt;The last step is to set the memory protection bits and install the following trampoline:&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-nasm" data-lang="nasm"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;push&lt;/span&gt; &lt;span class="nb"&gt;r13&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;push&lt;/span&gt; &lt;span class="nb"&gt;r12&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;movabs&lt;/span&gt; &lt;span class="nb"&gt;r12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;PR_Write_hook&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;movabs&lt;/span&gt; &lt;span class="nb"&gt;r13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;unmodified_PR_Write&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;jmp&lt;/span&gt; &lt;span class="nb"&gt;r12&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;int3&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;p&gt;The third stage is the &lt;code&gt;PR_Write_hook&lt;/code&gt; itself, which fires every time the original function is called. First of all, it checks that the size of the data being sent is at least 5 bytes, and the first 4 bytes in the buffer are &lt;code&gt;POST&lt;/code&gt;. If so, then the following magic happens:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;It finds the address of the &lt;code&gt;GetProcAddress&lt;/code&gt; function using the same code that was used in the second stage.&lt;/li&gt;&#10;&lt;li&gt;Then, again using the same technique, the shellcode finds the necessary libraries and addresses of the following functions: &lt;code&gt;WSAStartup&lt;/code&gt;, &lt;code&gt;socket&lt;/code&gt;, &lt;code&gt;sendto&lt;/code&gt;, &lt;code&gt;closesocket&lt;/code&gt; and &lt;code&gt;WSACleanup&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;After the initial preparation (roughly speaking, because this preparation and the logic itself are mixed), the following code is executed:&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;sockaddr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mh"&gt;0x02&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x05&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x7f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x01&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0xa0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x20&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;decrypt_flag&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;WSAStartup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0x202&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;wsaData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;SOCKET&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AF_INET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SOCK_DGRAM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IPPROTO_UDP&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;sendto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SOCKADDR&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;sockaddr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sockaddr&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;closesocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;WSACleanup&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To avoid the hassle with &amp;quot;host&amp;quot; and &amp;quot;network&amp;quot; byte order, I used the following code to see the destination:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;sockaddr_in&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;sockaddr_in&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;INET_ADDRSTRLEN&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kt"&gt;uint16_t&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;inet_ntop&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AF_INET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;sin&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sin_addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;sizeof&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ntohs&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sin&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sin_port&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nf"&gt;printf&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;%s:%d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;which gave me &lt;code&gt;127.0.0.1:1337&lt;/code&gt;. So, the last question: what is this flag? I would probably cheat at this point and use Wireshark to see it, but as I said at the beginning, the crackme crashed my Firefox, so I had to decrypt it manually. Luckily, there was no rocket science, and the following IDC script will do the trick:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_screen_ea&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nf"&gt;get_screen_ea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mh"&gt;0x20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rotate_byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mh"&gt;0x13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nf"&gt;patch_byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="mh"&gt;0x42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Sometimes a good disassembler is the only tool you need.&lt;/p&gt;&#10;&lt;p&gt;The challenge can be found &lt;a href="https://app.hackthebox.com/challenges/FFModule" target="_blank" rel="noopener"&gt;here&lt;/a&gt;.&lt;/p&gt;&#10;</description></item></channel></rss>