<?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>BSides Athens Archives - George Gerontakis</title>
	<atom:link href="https://blog.gerontakis.eu/tag/bsides-athens-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gerontakis.eu/tag/bsides-athens-2/</link>
	<description>My personal Blog and more 😎</description>
	<lastBuildDate>Wed, 05 Jul 2023 13:15:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>BSides Athens 2023 &#8211; Web &#8211; Broken Production Challenge Solution</title>
		<link>https://blog.gerontakis.eu/2023/07/05/bsides-athens-2023-web-broken-production-challenge-solution/</link>
					<comments>https://blog.gerontakis.eu/2023/07/05/bsides-athens-2023-web-broken-production-challenge-solution/#respond</comments>
		
		<dc:creator><![CDATA[g.gerontakis]]></dc:creator>
		<pubDate>Wed, 05 Jul 2023 13:12:11 +0000</pubDate>
				<category><![CDATA[Arbitrary Code Execution]]></category>
		<category><![CDATA[CTF]]></category>
		<category><![CDATA[Local File Inclusion]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[arbitrary code execution]]></category>
		<category><![CDATA[BSides]]></category>
		<category><![CDATA[BSides Athens]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[Command Ececution]]></category>
		<category><![CDATA[LFI]]></category>
		<category><![CDATA[RCE]]></category>
		<guid isPermaLink="false">https://blog.gerontakis.eu/?p=103</guid>

					<description><![CDATA[<p>The description is pretty clear about what should we expect in this challenge (Web application Privilege escalation and Command Execution). A zip file is given with the following structure: First of all let&#8217;s examine the Dockerfile in order to get a better understanding of how this works: Nothing &#8220;too important&#8221; here, but we can see [&#8230;]</p>
<p>The post <a href="https://blog.gerontakis.eu/2023/07/05/bsides-athens-2023-web-broken-production-challenge-solution/">BSides Athens 2023 &#8211; Web &#8211; Broken Production Challenge Solution</a> appeared first on <a href="https://blog.gerontakis.eu">George Gerontakis</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="527" height="630" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-30.png" alt="" class="wp-image-104" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-30.png 527w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-30-251x300.png 251w" sizes="(max-width: 527px) 100vw, 527px" /></figure>



<span id="more-103"></span>



<p class="wp-block-paragraph">The description is pretty clear about what should we expect in this challenge (Web application Privilege escalation and Command Execution).</p>



<p class="wp-block-paragraph">A zip file is given with the following structure:</p>



<figure class="wp-block-image size-full"><img decoding="async" width="354" height="829" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-32.png" alt="" class="wp-image-106" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-32.png 354w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-32-128x300.png 128w" sizes="(max-width: 354px) 100vw, 354px" /></figure>



<p class="wp-block-paragraph">First of all let&#8217;s examine the Dockerfile in order to get a better understanding of how this works:</p>



<figure class="wp-block-image size-full"><img decoding="async" width="883" height="641" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-33.png" alt="" class="wp-image-108" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-33.png 883w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-33-300x218.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-33-768x558.png 768w" sizes="(max-width: 883px) 100vw, 883px" /></figure>



<p class="wp-block-paragraph">Nothing &#8220;too important&#8221; here, but we can see where and how the flag is stored. <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f60e.png" alt="😎" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The name of the file that contains the flag is randomly generated.</p>



<p class="wp-block-paragraph">Let&#8217;s start the instance and add the ip to hosts file as <strong>ctfchall1</strong></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="625" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-27-1024x625.png" alt="" class="wp-image-109" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-27-1024x625.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-27-300x183.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-27-768x469.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-27-1536x938.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-27.png 1801w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">An account can be created (user: gger / pass: gger):</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="652" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-28-1024x652.png" alt="" class="wp-image-111" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-28-1024x652.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-28-300x191.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-28-768x489.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-28-1536x978.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-28.png 1772w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">With the created account we login:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="433" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-29-1024x433.png" alt="" class="wp-image-112" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-29-1024x433.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-29-300x127.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-29-768x325.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-29-1536x649.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-29-2048x866.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">By examining the downloaded source code of the challenge, we can identify a part responsible for seting the authenticated user&#8217;s cookie after a succesfull login:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="829" height="889" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-35.png" alt="" class="wp-image-114" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-35.png 829w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-35-280x300.png 280w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-35-768x824.png 768w" sizes="auto, (max-width: 829px) 100vw, 829px" /></figure>



<p class="wp-block-paragraph">It is just a base64 ,json encoded username value, that we can easily create and set ourselves:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="960" height="181" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-36.png" alt="" class="wp-image-115" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-36.png 960w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-36-300x57.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-36-768x145.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-36-953x181.png 953w" sizes="auto, (max-width: 960px) 100vw, 960px" /></figure>



<p class="wp-block-paragraph">After that, with the help of the Burp Proxy <strong>Match and replace rules</strong> setting we can add a replace rule that replaces the PHPSESSID value with ours.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="521" height="277" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-30_1.png" alt="" class="wp-image-116" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-30_1.png 521w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-30_1-300x160.png 300w" sizes="auto, (max-width: 521px) 100vw, 521px" /></figure>



<p class="wp-block-paragraph">Now, when we refresh index of the web app, we are authenticated as <strong>Admin</strong>!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="243" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-31-1024x243.png" alt="" class="wp-image-117" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-31-1024x243.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-31-300x71.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-31-768x183.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-31-1536x365.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-31-2048x487.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Analyzing the php source code of the project we also find another vulnerability that could lead to Local File Inclusion (LFI):</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="636" height="347" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-37.png" alt="" class="wp-image-118" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-37.png 636w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-37-300x164.png 300w" sizes="auto, (max-width: 636px) 100vw, 636px" /></figure>



<p class="wp-block-paragraph">Abusing the user controlled <strong>util </strong>parameter can lead to local file inclusion, but because the line 7 replaces the chars &#8220;../&#8221; we need to double the chars we add to the Get request <strong>(&#8230;.// instead of ../ so when the are replaced only the needed ../ part will remain</strong>).</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="414" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-33-1024x414.png" alt="" class="wp-image-119" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-33-1024x414.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-33-300x121.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-33-768x310.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/2023-06-23_14-33.png 1388w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">There are several ways that an LFI can lead to Remote Command Execution. One of them is by polluting the access log file which will later be included and processed by php fpm.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="728" height="202" src="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-38.png" alt="" class="wp-image-121" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-38.png 728w, https://blog.gerontakis.eu/wp-content/uploads/2023/06/image-38-300x83.png 300w" sizes="auto, (max-width: 728px) 100vw, 728px" /></figure>



<p class="wp-block-paragraph">So we try to pollute the access log file found in <strong>/var/log/nginx/access.log</strong> </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="239" src="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-37-1024x239.png" alt="" class="wp-image-124" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-37-1024x239.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-37-300x70.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-37-768x179.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-37-1536x358.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-37.png 1561w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">If we request again the <strong>access.log</strong> file we can see that the php code we entered via the <strong>User-Agent</strong> header in order to pollute the log file, was executed successfully!</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="343" src="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-43-1024x343.png" alt="" class="wp-image-126" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-43-1024x343.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-43-300x100.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-43-768x257.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-43-1536x514.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-43.png 1557w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">We can also see the flag file with the random name <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f60e.png" alt="😎" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p class="wp-block-paragraph">Using the same vulnerability we can read the file:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="546" src="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50-1024x546.png" alt="" class="wp-image-127" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50-1024x546.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50-300x160.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50-768x409.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50-1536x818.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50.png 1556w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="505" src="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50_1-1024x505.png" alt="" class="wp-image-128" srcset="https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50_1-1024x505.png 1024w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50_1-300x148.png 300w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50_1-768x379.png 768w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50_1-1536x757.png 1536w, https://blog.gerontakis.eu/wp-content/uploads/2023/07/2023-06-23_14-50_1.png 1562w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>
<p>The post <a href="https://blog.gerontakis.eu/2023/07/05/bsides-athens-2023-web-broken-production-challenge-solution/">BSides Athens 2023 &#8211; Web &#8211; Broken Production Challenge Solution</a> appeared first on <a href="https://blog.gerontakis.eu">George Gerontakis</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gerontakis.eu/2023/07/05/bsides-athens-2023-web-broken-production-challenge-solution/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
