<?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 Saurabh Tiwari on Medium]]></title>
        <description><![CDATA[Stories by Saurabh Tiwari on Medium]]></description>
        <link>https://medium.com/@meispi?source=rss-24aa576581a7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zFp7Jxcg2VKA6kf0p35prQ.png</url>
            <title>Stories by Saurabh Tiwari on Medium</title>
            <link>https://medium.com/@meispi?source=rss-24aa576581a7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 23:39:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meispi/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[S.H.E.L.L. CTF (Web Security) — Walk-Through]]></title>
            <link>https://meispi.medium.com/s-h-e-l-l-ctf-web-security-walk-through-ffceb407681b?source=rss-24aa576581a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffceb407681b</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[ctftime]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Saurabh Tiwari]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 07:37:54 GMT</pubDate>
            <atom:updated>2021-06-09T07:37:54.590Z</atom:updated>
            <content:encoded><![CDATA[<h3>S.H.E.L.L. CTF (Web Security) — Walk-Through</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*E69YI1LTxLB0oKJ7gAYqIg.png" /></figure><blockquote>Hello everyone! I am Saurabh Tiwari (aka meispi). I am currently a 2nd year undergrad in Mathematics and Computing and I do bug hunting in my free time (there is a pandemic going on so free time sometimes means all the time). During my weekend I try to solve some CTF challenges to improve my skills in this domain and have fun.</blockquote><p>So last weekend, I participated in <a href="https://ctftime.org/event/1362">S.H.E.L.L. CTF on ctftime.org</a>. This CTF challenge was not very complex as it was meant for beginners like me. The challenges ranged from easy to hard on various topics in the security domain like Cryptography, Reverse Engineering, Web Security, Forensics, and Miscellaneous. But my main focus was to solve all the challenges in the Web Security section. So this is the walk-through of how I solved them. Let’s get started!</p><h3>Challenge #1 — ANONYM</h3><h4>Description</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*ij6hp3_nTLe1lgup_NzYYw.png" /></figure><p>There is a URL that will refer us to the lab environment and we need to find a flag and submit it here. There is a hint: Anonymous are back and they really hate robots. If you have worked with developing a website or solved CTF challenges then you might be familiar with <a href="https://developers.google.com/search/docs/advanced/robots/intro">/robots.txt</a>, so I visited the endpoint to see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_Dc4K_X8COtv1TyjwQM0g.png" /></figure><p>It was referring to an endpoint /yfhdgvs.txt, so I went there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAOBXQ0PmofvkkavLBQ5vQ.png" /></figure><p>And got the first flag. SHELL{n0_ro80t5_4llow3d_50886509749a98ef14ec2bc45c57958e}</p><h3>Challenge #2 — Under Development</h3><h4>Description</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*YdiCAUkVN6kWAD5BqvQ27A.png" /></figure><p>Only a URL, with no hint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYTD1qskovXAuiewlu4Vug.png" /></figure><p>Nothing interesting to be found here, so I reviewed the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U-EwLtGMQY2feN57be8BZg.png" /></figure><p>Most of the times what we are looking for in source codes are basically… code that would help us (it might contain the flag in plain text or sometimes encoded or with basic encryption) or some comments that can provide any hints. Here I didn’t see any js files but it did have a comment.</p><p>&lt;!--TODO: Develop auth, buy some cookies from the supermarket--&gt;</p><p>When I looked at this comment, I thought it was just like the previous one just visit /auth or /buy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zb1UfBevbmXR3DJUHGP-Bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HL_Z4r5sORqNwJz87VV1Fw.png" /></figure><p>but NOPE!! Nothing to be found here.</p><p>The comment does mention cookies, maybe I’ve to look at the cookies sent with the requests.</p><p>So I fired up <a href="https://portswigger.net/burp/enterprise">Burp Suite</a> (a proxy tool to look at the requests sent from your browser and the response that was received).</p><p>When I visited the URL the request-response looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L4zrmfRz5u67RzP0avRTaQ.png" /></figure><p>Here I could see the response sets a cookie called privilege with the value dXNlcg%3D%3D, so I tried to decode this value. The %3D%3D is URL encoding for ==, so first, I&#39;ll URL decode it. Hopped on to the decoder tab in Burp Suite and URL decoded the value,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fiob4otJJz0ZhFxFhjmMWQ.png" /></figure><p>now I can try different algorithms to decode this but Base64 is the most common if you see = at the end, so I tried it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUhVx0xW7DNFf4xIOY-Dww.png" /></figure><p>Aha! user. Now I tried to change this cookie value to admin and see if something happens. But before I send the request with admin as the cookie I had to Base64 encode it and then URL encode the special characters if present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W4SVPGBUUdfrT9WvhBG0bQ.png" /></figure><p>change = to %3D , YWRtaW4= ⇒ YWRtaW4%3D and good to go!</p><p>I sent the request to the repeater tab and set the cookie:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XkVnW2UtNF_lfQlNKZrTTA.png" /></figure><p>And there it was, the 2nd flag!</p><p>flag ⇒ SHELL{0NLY_0R30_8e1a91a632ecaf2dd6026c943eb3ed1e}</p><h3>Challenge #3 — Collide</h3><h4>Description</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*7d6jn36esMRgnezl0ugByQ.png" /></figure><p>Another one with no description (or hint), just URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5p3EQSkfLU0D_rNlJFTPw.png" /></figure><p>Whoa!! some big words there. I have never developed a webpage in PHP so I had to google some things to figure out what the code meant.</p><p>SHA256 is a hashing function. Given a string it will compute a hash for that string and reversing this operation (getting back the string from the hash) is not possible. As the name indicates there are going to be 256 bits in the hash generated by SHA256 i.e. 2²⁵⁶ unique hashes are possible and after that, they will start <a href="https://crypto.stackexchange.com/questions/33929/can-two-files-strings-have-the-same-sha-256-value">colliding</a>, which means two different strings may have exact same hash. That’s what this challenge wanted. As I could see in the code given on the webpage, it receives 2 parameters from the URL shell ($_GET[&#39;shell&#39;]) and pwn ($_GET[&#39;pwn&#39;]), those two shouldn&#39;t be empty (if (isset($_GET[&#39;shell&#39;]) &amp;&amp; isset($_GET[&#39;pwn&#39;]))), they shouldn&#39;t be the same but their SHA256 hash should be (if ($_GET[&#39;shell&#39;] !== $_GET[&#39;pwn&#39;] &amp;&amp; hash(&quot;sha256&quot;, $_GET[&#39;shell&#39;]) === hash(&quot;sha256&quot;, $_GET[&#39;pwn&#39;]))) but it is very difficult to get 2 strings that are different but hashes are the same. But still, I tried different payloads and hoped if somehow it could break the logic.</p><p>shell=0&amp;pwn=0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ClLgWI1kOBKCU2PkY41Rsg.png" /></figure><p>nope, didn’t work.</p><p>shell=0&amp;pwn=1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5uJ7FfnhK0myAgOAzE7Gw.png" /></figure><p>neither did this.</p><p>So it was time to do some research or googling. After some googling, I came to know that the hash function expects a string, and giving it an array will break the logic and the function will return false (<a href="https://stackoverflow.com/questions/53080807/sha256-hash-collisions-between-two-strings/53081240">source</a>), this means both of them will be false and our 2nd condition will become true.</p><p>shell[]=0&amp;pwn[]=1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXSe7P1PKlPV90hUrifA8w.png" /></figure><p>And I got the 3rd flag!!</p><p>flag ⇒ SHELL{1nj3ct_&amp;_coll1d3_9d25f1cfdeb38a404b6e8584bec7a319}</p><h3>Challenge #4 — login</h3><h4>Description</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*INu5eexe1kwy5TPA9XAA6A.png" /></figure><p>I looked at the login portal,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9mnkdpOZI9G0AmsWnkIWQ.png" /></figure><p>mayyyybe the credentials are admin:admin, it never hurts to try</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F3lL9HfuK97nhsKrWXkAZw.png" /></figure><p>Now I saw that only the user din_djarin11 was allowed. So credential might be din_djarin11:admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hbf5dVvtNv5vWYNKPDCvgw.png" /></figure><p>Nope, invalid login.</p><p>Then I reviewed the source code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yv3E7_0OlcNOQ6u8EQVhGQ.png" /></figure><p>No comments but a js file, so I looked into that.</p><p>The js file contained the following code:</p><pre>function checkIt() {<br>  var user = document.getElementById(&quot;username&quot;).value; var pass = document.getElementById(&quot;password&quot;).value;<br>  if (user != &quot;din_djarin11&quot;) alert(&quot;Only for user: din_djarin11&quot;); else {<br>    var s = Hash(pass);<br>    if (s == &quot;9ef71a8cd681a813cfd377817e9a08e5&quot;) window.location = &quot;./&quot; + pass; <br>    else alert(&quot;Invalid login&quot;);<br>  }<br>}<br><br><br>var Hash = function (string) {<br><br>  function RotateLeft(lValue, iShiftBits) {<br>          return (lValue&lt;&lt;iShiftBits) | (lValue&gt;&gt;&gt;(32-iShiftBits));<br>  }<br><br>  function AddUnsigned(lX,lY) {<br>          var lX4,lY4,lX8,lY8,lResult;<br>          lX8 = (lX &amp; 0x80000000);<br>          lY8 = (lY &amp; 0x80000000);<br>          lX4 = (lX &amp; 0x40000000);<br>          lY4 = (lY &amp; 0x40000000);<br>          lResult = (lX &amp; 0x3FFFFFFF)+(lY &amp; 0x3FFFFFFF);<br>          if (lX4 &amp; lY4) {<br>                  return (lResult ^ 0x80000000 ^ lX8 ^ lY8);<br>          }<br>          if (lX4 | lY4) {<br>                  if (lResult &amp; 0x40000000) {<br>                          return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);<br>                  } else {<br>                          return (lResult ^ 0x40000000 ^ lX8 ^ lY8);<br>                  }<br>          } else {<br>                  return (lResult ^ lX8 ^ lY8);<br>          }<br>  }<br><br>  function F(x,y,z) { return (x &amp; y) | ((~x) &amp; z); }<br>  function G(x,y,z) { return (x &amp; z) | (y &amp; (~z)); }<br>  function H(x,y,z) { return (x ^ y ^ z); }<br>  function I(x,y,z) { return (y ^ (x | (~z))); }<br><br>  function FF(a,b,c,d,x,s,ac) {<br>          a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));<br>          return AddUnsigned(RotateLeft(a, s), b);<br>  };<br><br>  function GG(a,b,c,d,x,s,ac) {<br>          a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));<br>          return AddUnsigned(RotateLeft(a, s), b);<br>  };<br><br>  function HH(a,b,c,d,x,s,ac) {<br>          a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));<br>          return AddUnsigned(RotateLeft(a, s), b);<br>  };<br><br>  function II(a,b,c,d,x,s,ac) {<br>          a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));<br>          return AddUnsigned(RotateLeft(a, s), b);<br>  };<br><br>  function ConvertToWordArray(string) {<br>          var lWordCount;<br>          var lMessageLength = string.length;<br>          var lNumberOfWords_temp1=lMessageLength + 8;<br>          var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;<br>          var lNumberOfWords = (lNumberOfWords_temp2+1)*16;<br>          var lWordArray=Array(lNumberOfWords-1);<br>          var lBytePosition = 0;<br>          var lByteCount = 0;<br>          while ( lByteCount &lt; lMessageLength ) {<br>                  lWordCount = (lByteCount-(lByteCount % 4))/4;<br>                  lBytePosition = (lByteCount % 4)*8;<br>                  lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)&lt;&lt;lBytePosition));<br>                  lByteCount++;<br>          }<br>          lWordCount = (lByteCount-(lByteCount % 4))/4;<br>          lBytePosition = (lByteCount % 4)*8;<br>          lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80&lt;&lt;lBytePosition);<br>          lWordArray[lNumberOfWords-2] = lMessageLength&lt;&lt;3;<br>          lWordArray[lNumberOfWords-1] = lMessageLength&gt;&gt;&gt;29;<br>          return lWordArray;<br>  };<br><br>  function WordToHex(lValue) {<br>          var WordToHexValue=&quot;&quot;,WordToHexValue_temp=&quot;&quot;,lByte,lCount;<br>          for (lCount = 0;lCount&lt;=3;lCount++) {<br>                  lByte = (lValue&gt;&gt;&gt;(lCount*8)) &amp; 255;<br>                  WordToHexValue_temp = &quot;0&quot; + lByte.toString(16);<br>                  WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);<br>          }<br>          return WordToHexValue;<br>  };<br><br>  function Utf8Encode(string) {<br>          string = string.replace(/\r\n/g,&quot;\n&quot;);<br>          var utftext = &quot;&quot;;<br><br>          for (var n = 0; n &lt; string.length; n++) {<br><br>                  var c = string.charCodeAt(n);<br><br>                  if (c &lt; 128) {<br>                          utftext += String.fromCharCode(c);<br>                  }<br>                  else if((c &gt; 127) &amp;&amp; (c &lt; 2048)) {<br>                          utftext += String.fromCharCode((c &gt;&gt; 6) | 192);<br>                          utftext += String.fromCharCode((c &amp; 63) | 128);<br>                  }<br>                  else {<br>                          utftext += String.fromCharCode((c &gt;&gt; 12) | 224);<br>                          utftext += String.fromCharCode(((c &gt;&gt; 6) &amp; 63) | 128);<br>                          utftext += String.fromCharCode((c &amp; 63) | 128);<br>                  }<br><br>          }<br><br>          return utftext;<br>  };<br><br>  var x=Array();<br>  var k,AA,BB,CC,DD,a,b,c,d;<br>  var S11=7, S12=12, S13=17, S14=22;<br>  var S21=5, S22=9 , S23=14, S24=20;<br>  var S31=4, S32=11, S33=16, S34=23;<br>  var S41=6, S42=10, S43=15, S44=21;<br><br>  string = Utf8Encode(string);<br><br>  x = ConvertToWordArray(string);<br><br>  a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;<br><br>  for (k=0;k&lt;x.length;k+=16) {<br>          AA=a; BB=b; CC=c; DD=d;<br>          a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);<br>          d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);<br>          c=FF(c,d,a,b,x[k+2], S13,0x242070DB);<br>          b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);<br>          a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);<br>          d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);<br>          c=FF(c,d,a,b,x[k+6], S13,0xA8304613);<br>          b=FF(b,c,d,a,x[k+7], S14,0xFD469501);<br>          a=FF(a,b,c,d,x[k+8], S11,0x698098D8);<br>          d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);<br>          c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);<br>          b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);<br>          a=FF(a,b,c,d,x[k+12],S11,0x6B901122);<br>          d=FF(d,a,b,c,x[k+13],S12,0xFD987193);<br>          c=FF(c,d,a,b,x[k+14],S13,0xA679438E);<br>          b=FF(b,c,d,a,x[k+15],S14,0x49B40821);<br>          a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);<br>          d=GG(d,a,b,c,x[k+6], S22,0xC040B340);<br>          c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);<br>          b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);<br>          a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);<br>          d=GG(d,a,b,c,x[k+10],S22,0x2441453);<br>          c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);<br>          b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);<br>          a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);<br>          d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);<br>          c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);<br>          b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);<br>          a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);<br>          d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);<br>          c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);<br>          b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);<br>          a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);<br>          d=HH(d,a,b,c,x[k+8], S32,0x8771F681);<br>          c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);<br>          b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);<br>          a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);<br>          d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);<br>          c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);<br>          b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);<br>          a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);<br>          d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);<br>          c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);<br>          b=HH(b,c,d,a,x[k+6], S34,0x4881D05);<br>          a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);<br>          d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);<br>          c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);<br>          b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);<br>          a=II(a,b,c,d,x[k+0], S41,0xF4292244);<br>          d=II(d,a,b,c,x[k+7], S42,0x432AFF97);<br>          c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);<br>          b=II(b,c,d,a,x[k+5], S44,0xFC93A039);<br>          a=II(a,b,c,d,x[k+12],S41,0x655B59C3);<br>          d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);<br>          c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);<br>          b=II(b,c,d,a,x[k+1], S44,0x85845DD1);<br>          a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);<br>          d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);<br>          c=II(c,d,a,b,x[k+6], S43,0xA3014314);<br>          b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);<br>          a=II(a,b,c,d,x[k+4], S41,0xF7537E82);<br>          d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);<br>          c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);<br>          b=II(b,c,d,a,x[k+9], S44,0xEB86D391);<br>          a=AddUnsigned(a,AA);<br>          b=AddUnsigned(b,BB);<br>          c=AddUnsigned(c,CC);<br>          d=AddUnsigned(d,DD);<br>      }<br><br>    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);<br><br>    return temp.toLowerCase();<br>}</pre><p>When someone clicks on login, the code calls the checkIt() function, then it checks if the user is din_djarin11, if it is then it creates a hash for the password and the resulting hash should be equal to 9ef71a8cd681a813cfd377817e9a08e5.</p><p>The hashing function is quite huge and involves a lot of other functions and bit manipulation to generate the hash and I was too lazy to reverse engineer this whole code and generate back the string that would lead to the given hash and there was a possibility that it wasn’t even possible because of all the bit-wise shift operators that were being used in this code. So I tried some normal things like directory fuzzing (because if we found the correct password the directory name is the same as the password), but no luck. Maybe password brute forcing? I am too lazy to do that too (even though it would be fully automated). So I took a break and solved some of the easier challenges in other sections like Cryptography, Reverse Engineering, etc.</p><p>Then the next day I decided to understand the whole code and try to get back to the password that could produce this hash. While going through the code flow I decided to just google a hash (a = 0x67452301), and the first result that pops up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*Tjdb_KxzapLy1ZbfW_Zl9w.png" /></figure><p>The hashing algorithm is MD5 as the variables a,b,c and d used in this code are the same as discussed in this <a href="https://stackoverflow.com/questions/1727104/question-on-md5-state-variables">stack overflow question</a>. So I had to just reverse MD5 this hash and I&#39;ll get the password or why not just google it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*XIcOyD9A34aiNTL3anvNVQ.png" /></figure><p>reverseMD5(&quot;9ef71a8cd681a813cfd377817e9a08e5&quot;) = ir0nm4n</p><p>So I went to /ir0nm4n to see what&#39;s there</p><p>It downloaded a file, let’s look at the file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*Bj9PIfIxki1xBBx66adkOg.png" /></figure><p>And the 4th flag!!</p><p>flag = SHELL{th1s_i5_th3_wa7_845ad42f4480104b698c1e168d29b739}</p><h3>Challenge #5 — Fun with Tokens</h3><h4>Description</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*CNjZL7lffLldtuZ1_bQvTw.png" /></figure><p>I visited the URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glYfZd9qFEaqoKdtk8dVNw.png" /></figure><p>Nothing was happening when I clicked these 2 links.</p><p>So I visited /login as the description said something about the password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jB_8euSo2RseuF1JJwyAEA.png" /></figure><p>I tried admin:admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4DYN6ifRAXAdVzr1Iq_2gQ.png" /></figure><p>Nope, it redirects us back to the initial page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J2_JTuP0FNK6Yg9IzgceIw.png" /></figure><p>I reviewed the source code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iiz91WDZWA-iHgoRXnw1sw.png" /></figure><p>login is vulnerable was a comment, but no js files.</p><p>I reviewed the source code of the initial page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2GezCDALjvbs-dDHHbjctg.png" /></figure><p>There were three things to notice here:</p><ol><li>/adminNames endpoint</li><li>/admin endpoint</li><li>environment: while developing websites there is a file called .env which stores all the secrets and is meant to be private.</li></ol><p>So, I visited /adminNames.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*Pc_QUKXKywVblxxjxivjlQ.png" /></figure><p>A file!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*PT-Xb0JLyb6O2ArSCPpy9Q.png" /></figure><p>This file contained 2 names, one did look like a name (din_djarin11), the other one looked like some sort of hash (0xd4127c3c)</p><p>I thought these 2 could be the credentials on the login page, but that wasn’t the case.</p><p>So I visited the /admin endpoint as it was mentioned in the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNtH2XA2BC0OUifL3rjLwg.png" /></figure><p>Here it said that one had to send a token via headers for authorization, most probably the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization">Authorization</a> header.</p><p>But what token could it be?</p><p>Reading the Authorization header docs, it says that the most generic Authorization header could be of the form:</p><p>Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l</p><p>Where YWxhZGRpbjpvcGVuc2VzYW1l is Base64 encoding of aladdin:opensesame, as mentioned in the docs.</p><p>So maybe I had to send the credentials I got from the file in this form.</p><p>I tried different combinations like</p><p>0xd4127c3c:din_djarin11</p><p>din_djarin11:0xd4127c3c</p><p>Base64 encoded them and sent them as the header to the /admin endpoint but nothing worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rdoc4SsKKlmzU5vp4Uhi1Q.png" /></figure><p>The description said Did i fail in verifying passwords ? so maybe I don&#39;t need a password at all, but that didn&#39;t work either.</p><p>When nothing worked, I started looking for some interesting endpoints in the Burp Suite’s HTTP History tab and then I found this request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*eZflEgMUvrcDw-VFAiwLCQ.png" /></figure><p>A parameter called file, it was fetching a file called admins from the server and giving it to the user (the one that contained 2 names). Here comes the environment hint, I had to fetch .env file from the server and it might contain the flag I was looking for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mX_9XFn_WbVeXBKf2CKCfg.png" /></figure><p>Nope. So I tried path traversal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*huY12v-xelcO_Sb-sMS4sw.png" /></figure><p>Bingo!!</p><p>I got the file. I looked into that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*p9P2V7ec6k1IE3sI8xAeyQ.png" /></figure><p>It contained a secret, but not the flag.</p><p>So I kept on looking in the Burp Suite’s HTTP history tab to see if I find something else that could help me and then I found this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clDiSQVL80a2mGp5ybx1xg.png" /></figure><p>When I entered admin:admin on the login page, the response contained a JW token (“JWT token” is deprecated, 😉). So now the secret in our .env file makes sense, this JW token is signed using that secret key. But first, I Base64 decoded this token to see what&#39;s in there.</p><p>So I went to jwt.io</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ewcU3gUwysggW6I66ZOT5g.png" /></figure><p>But I entered the username as admin, what is this nqzva.</p><p>Ah! some sort of alphabetic rotation.</p><p>Let’s visit <a href="https://gchq.github.io/CyberChef">our friend</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qc8qehqzg-oTTUhEb_-QbA.png" /></figure><p>Yep, it was nothing but rotation by 13.</p><p>What is snyfr?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nsVaeEWs5k8WB6iYQ3Cl2A.png" /></figure><p>Ok, false.</p><p>So all I had to do was to make some changes in the JW token:</p><ul><li>Enter username (with ROT13) with one of the names provided in the first file</li><li>Change the admin value to true (ROT13)</li><li>verify using the secret given in the second file</li><li>send the request on /admin using the Authorization Bearer header</li></ul><p>But what about the password? remember the description hint (Did i fail in verifying passwords ?), so maybe I don&#39;t need a password at all.</p><p>So after doing all the above-mentioned things, I had this token (one can verify the token by just entering the secret in the verify signature box on jwt.io):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9sxtfbSJt9XrxV9TghT_g.png" /></figure><p>The final JW token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InF2YV9xd25ldmExMSIsInBhc3N3b3JkIjoiIiwiYWRtaW4iOiJnZWhyIiwiaWF0IjoxNjIyOTg1NTY1fQ.XoDGrcnaIORwggYUPdDjuCtxMbRoXT1pywj6arGJv5M</p><p>So I sent the request to /admin endpoint with this token:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*8vP4QtQu-d67aeTJ221PLQ.png" /></figure><p>Let’s look at the response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*3PzE-G2cDGUVyB7a2zKYdA.png" /></figure><p>Annnnnd I had my 5th and final flag, but it looked a bit different from other flags (it wasn’t starting from SHELL{)</p><p>Yet again ROT13:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0IM26211Dl2uDcW4nvWlg.png" /></figure><p>flag ⇒ SHELL{T0k3ns_d0_m4tt3r_4e91af4506f384d460f0f0c6e9e5fe4a}</p><p>Thank you for reading!</p><blockquote>You can reach out to me on <a href="https://twitter.com/meispi_">Twitter</a> or <a href="https://www.linkedin.com/in/saurabh-tiwari-546bb8136/">LinkedIn</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffceb407681b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bringing Out of Scope, In Scope]]></title>
            <link>https://meispi.medium.com/bringing-out-of-scope-in-scope-dc19ee17dd6?source=rss-24aa576581a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc19ee17dd6</guid>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[Saurabh Tiwari]]></dc:creator>
            <pubDate>Sun, 25 Apr 2021 09:19:33 GMT</pubDate>
            <atom:updated>2021-04-25T09:19:33.167Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>We are all aware of the CSRF on Login form being out of scope in almost all of the bug bounty programs. This post is about chaining this out of scope vulnerability with another vulnerability to show the impact.</blockquote><h3>CSRF on linking your social media account</h3><p>While hunting on this program, let’s call it redacted.com (for obvious reasons), I found a feature that was used to link your social media account (e.g. Gmail, Facebook etc.) with your account on redacted.com. It followed the normal OAuth flow i.e. clicking the connect your Gmail button, which leads to your Gmail and asks for your verification and then it verifies your Gmail account by sending the code with client id.</p><p>After verifying my Gmail account and linking it to redacted.com, I looked up in the burp history to see the requests that were made throughout this whole process and to my surprise the first request that was made (which is when you click connect your Gmail) didn’t have CSRF token to verify the session. Interesting!</p><p>But then I realised that the session was being checked when you click on verify on the Gmail page when you are redirected to it. So even if the connect your Gmail doesn’t have CSRF protection, the very next step has. So are we done? It’s not a vulnerability, then? Nope. Let’s try again.</p><p>So I disconnected my Gmail account and reconnected it to the same redacted.com account and this time it didn’t redirect me to any verification on Gmail page. This is a known behavior in OAuth flow. When you verify the same social media account with the same client the second time, it won’t lead you to the verification page and simply verify you as long as you are logged in to the account in the same browser. It doesn’t matter if the client account is different.</p><h3>What we have now?</h3><p>So, what can be done with the information we have right now? Let’s see:</p><ol><li>We have CSRF on connect your Gmail</li><li>The verification page doesn’t show up if the social media account has been linked before.</li></ol><h4>Attack Scenario</h4><p>If the attacker can somehow login to their social media account on the victim’s browser and trick the victim to click on the url that leads to the account linking (the url behind connect your Gmail), then the attacker can link their social media account with victim’s account. Now if the attacker logs in to the redacted.com page using login with google, they will be logged into the victim’s account.<br>But wait! How would the attacker login to his own social media account on victim’s browser? Social media like Gmail and Facebook don’t have CSRF on their login page. Social engineering? That won’t seem plausible in this pandemic.</p><p>So this attack scenario has failed, we can’t hack into someone else’s account using this scenario.</p><p>But our old friend that had been out of scope for too long comes into the game. CSRF on login on redacted.com.</p><h4>New Attack Scenario</h4><p>The attacker unlinks the Gmail account that the victim account has been linked to, then they’ll log the victim out of redacted.com, login using their own credentials (notice that there is no CSRF implemented here) and send a request to linking the social media account (belonging to victim) to the attacker’s account and then log out from victim’s browser. All of this can be done by hosting a page on a server and sending the url to this page to the victim.</p><p>Now when the attacker logs into their own account they can impersonate the victim.</p><p>This is how you can chain an out of scope vulnerability with another vulnerability to show an impact. There are other out of scope (in general) vulnerabilities like self XSS that can be chained with similar types of vulnerabilities to create an impact from nothing. But all of that depends on the functioning of the webpage and your creativity.</p><p>Thanks for reading!</p><p><a href="https://twitter.com/meispi_">Saurabh Tiwari (@meispi_) / Twitter</a></p><p><a href="https://github.com/meispi">meispi (Saurabh Tiwari) (github.com)</a></p><p><a href="https://www.linkedin.com/in/saurabh-tiwari-546bb8136/">Saurabh (meispi) Tiwari | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc19ee17dd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logistic Regression: The Entry To The ML World]]></title>
            <link>https://meispi.medium.com/logistic-regression-the-entry-to-the-ml-world-e2cb877ff817?source=rss-24aa576581a7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2cb877ff817</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Saurabh Tiwari]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 15:05:15 GMT</pubDate>
            <atom:updated>2021-04-20T15:05:15.994Z</atom:updated>
            <content:encoded><![CDATA[<p>Logistic Regression is a supervised learning technique to solve problems in which our target values are categorical in nature, i.e. having values that can be categorized in some classes. e.g. given some information about the customer predict if they should get a loan or not.</p><p>Now, due to this it is considered to be a classification technique. But I like to think it as a regression technique because all it is doing is adjusting the parameters in such a way that our S shaped figure approximates the dataset just like linear regression does to fit a line on the dataset. But we apply it to the problems that are categorical hence it is generally called a classification technique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*8Oz1LLUdRi966_wR.png" /></figure><h3>How ?</h3><p>So how is it happening? How is it forming that S shaped figure?</p><p>If you are familiar with Linear Regression in which we try to fit a line through the dataset, first we write our normal equation of line</p><p>Z = β.X + βo</p><p>Here, Z is our calculated value (in case of linear regression), β is our weights (if there are more attributes of X then that many βs) and βo is just for adjusting the graph in vertical direction.</p><p>To get the values of β and βo, in linear regression we take the difference of calculated value and expected value, square it, differentiate it w.r.t. β and equate it to 0 to get the value of β on which the error is minimum.</p><p>But in logistic regression first we create this linear function to a function that looks like an S shape. This function is called a sigmoid function.</p><p>Y’ = 1/(1+e^(-Z))</p><p>Notice that the value of Y’ will be between 0 and 1 irrespective of what Z is.</p><p>Here, Y’ is our calculated value and not Z. To get the values of β and βo, we go on and calculate the conditional probability of Y’ and do some messy mathematics to get the result. If you are interested to know the mathematics around it you can find it <a href="https://www.geeksforgeeks.org/understanding-logistic-regression/">here</a>.</p><p>Now, we’ve got our sigmoid function. We feed it the values of X and the calculated value will give us a result between 0 &amp; 1 and we can round it off to know in which class does a certain set of values belong.</p><h3>Code</h3><p>Doing all that mathematics on a code is a bit too much. But our friend python does it for us. Python has a built in library for logistic regression that you can use to feed the dataset and get results.</p><pre><strong>from</strong> <strong>sklearn.linear_model</strong> <strong>import</strong> LogisticRegression <br>classifier = LogisticRegression(random_state=0) <br>classifier.fit(train, result_tr)<br>pred = classifier.predict(test)</pre><p>There you go! Now you can solve most of the classification problems using logistic regression.</p><p>Thank you for reading.</p><p><a href="https://twitter.com/meispi_">Saurabh Tiwari (@meispi_) / Twitter</a></p><p><a href="https://www.linkedin.com/in/saurabh-tiwari-546bb8136/">Saurabh (meispi) Tiwari | LinkedIn</a></p><p><a href="https://github.com/meispi/">meispi (Saurabh Tiwari) (github.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2cb877ff817" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>