<?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 Mohamed masmoudi on Medium]]></title>
        <description><![CDATA[Stories by Mohamed masmoudi on Medium]]></description>
        <link>https://medium.com/@mohamedmasmoudi745?source=rss-e886ac138d00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iC4S6CUH-iE4rYQnmpreAg.jpeg</url>
            <title>Stories by Mohamed masmoudi on Medium</title>
            <link>https://medium.com/@mohamedmasmoudi745?source=rss-e886ac138d00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 02:52:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohamedmasmoudi745/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[Buffer Overflow [Vulnserver]]]></title>
            <link>https://medium.com/@mohamedmasmoudi745/buffer-overflow-vulnserver-1fe3ac61d44d?source=rss-e886ac138d00------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fe3ac61d44d</guid>
            <category><![CDATA[buffer-overflow]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[red-team]]></category>
            <dc:creator><![CDATA[Mohamed masmoudi]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 20:53:04 GMT</pubDate>
            <atom:updated>2023-01-20T20:53:04.500Z</atom:updated>
            <content:encoded><![CDATA[<p>Buffers are memory storage regions that temporarily hold data while it is being transferred from one location to another. A buffer overflow (or buffer overrun) occurs when the volume of data exceeds the storage capacity of the memory buffer. As a result, The program attempting to write the data to the buffer overwrites adjacent memory locations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*TrVEiwQHt0u8uytLpxZb1A.png" /><figcaption>Buffer overflow example</figcaption></figure><h3>What is a Buffer Overflow Attack</h3><p>Attackers exploit buffer overflow issues by overwriting the memory of an application. This changes the execution path of the program, triggering a response that damages files or exposes private information. For example, an attacker may introduce extra code, sending new instructions to the application to gain access to IT systems.</p><p><strong>This is an example of a memory management</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Qn-RtzuLIpq4Ss5ILh4q6g.png" /></figure><p><strong>And this is an example of Stack hierarchy</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*roc8_BOu70X0RJYsMWSEwg.png" /></figure><p>ESP : extended stack pointer, EBP : extended base pointer, EIP : extended instruction pointer .</p><p>Imagine if send a bunch of characters into the buffer and we start overwriting EBP and EIP. This is Where a Buffer overflow attack comes into place Because if we access the EIP, we could insert malicious scripts to gain control of the computer.</p><h3>let’s start practicing</h3><p>In this Lab, we need some prerequisites.</p><ol><li>An attack machine.</li><li>A target machine with Windows defender switched off (Windows).</li><li>Download the exploitable server <a href="https://github.com/stephenbradshaw/vulnserver">https://github.com/stephenbradshaw/vulnserver</a></li><li>Download Immunity debugger in your Windows <a href="https://www.immunityinc.com/products/debugger/">https://www.immunityinc.com/products/debugger/</a></li></ol><p>First we should run the Vulnserver in the windows machine and connect the the server using “netcat”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6xILqHwSqRJ3bmACBh-a4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*Ho9gdKJRIwDMVOqe8EhmdA.png" /></figure><h3>Fuzzing Vulnserver using SPIKE</h3><p>spike is a fuzzing framework using for fuzzing network-based applications with scripting capability that allows you to create your own fuzzer</p><p>Download SPIKE : <a href="https://github.com/guilhermeferreira/spikepp/tree/master/SPIKE">https://github.com/guilhermeferreira/spikepp/tree/master/SPIKE</a></p><p>For this, we need to write a spiking script for TRUN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*kBLbk7s8Vors1aC3N1XZhg.png" /></figure><p>This script will:</p><ol><li>Read the banner that the server sends;</li><li>Simulate that the user sending the TRUN command;</li><li>Randomize the user input with the TRUN command.</li></ol><p>then we will use <strong>generic_send_tcp to start fuzzing our </strong>Vulnserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*gF9MZEAqWqt-bRAGnSxP-A.png" /></figure><p>after that we notice that our server crashed. So we have a buffer overflow in TRUN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*hg2tsjEHUeO2XXFgERXJOQ.png" /></figure><p>In the next step we will create our exploit to get a reverse shell of the windows machine.</p><p>the script will use socket to connect to the vulnserver and send 5000 ‘A’ characters</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*2p2sQX2TArhCmCV77te9jQ.png" /></figure><p>before we run it we should make sure that the server is running in the Immunity Debugger</p><pre>python2 exploit.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ff5Zs8IOsGsYT-j1vkx80A.png" /></figure><p>we notice that all the buffer is full of A and the EIP is overwritten by 41414141=’AAAA’</p><p>The next step is to find the exact bytes at which the TRUN crashed. the idea is ti send a known pattern and see when the EIP get overwritten. In this step you can create a pattern using Metasploit framework and use it in the script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*LRzkcloeOoNVG7VWUVE7eA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*dBJkMYCw55S6mlFWMCn11Q.png" /></figure><p>After sending this we check the value EIP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*iGKK-nr3ObTh9p89FHAs9g.png" /></figure><p>after that we can use Metasploit to find the index of this address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*6yhUhy8vY2WvUXRCI6DnWg.png" /></figure><h3>Finding bad characters</h3><p>Certain byte characters can cause issues in the development of exploits. By default, the null byte(x00) is always considered a bad character as it will stop the shellcode when executed.To find bad characters we will test all the bytes with this script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*xTEaHoJuJWPjv87lTl0-jQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uwaQW4xTUL5d_lgzHsrs_A.png" /></figure><p>As all the characters that we have sent are present, we can confirm that there is no bad character other than \x00 and \x0A. IF there was a bad character it would have been replaced with \xB0.</p><h3>Finding JMP ESP</h3><p>Now that we have control over the EIP register we need to point it to the ESP register.</p><p>In this step we need to find an address that contains the operation JMP ESP. So we will use mona.py to see modules that doesn’t have any protection mechanisms:</p><p>mona.py can be downloaded from here <a href="https://github.com/corelan/mona">https://github.com/corelan/mona</a></p><p>after installing mona you should replace it to this path C:/program files(x86)/immunity Inc/Immunity Debugger/PyCommands</p><p>and run this command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*0Sp-o3bHGyrNYs_0VbBuXQ.png" /></figure><p>in this code we have 9 modules but we will targeting essfunc.dll because it doesn’t have any protection.</p><p>And now, we need to find the a pointer to JMP ESP in essfunc.dll. We type !mona find -s “\xff\xe4” -m essfunc.dll (“\xff\xe4” is the Hex form of jmp esp)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_8JP-b4g4e70n2T1iQ_2A.png" /></figure><p>we double click in the first pointer to get the place of this instruction in assembly code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*RsLqVUmA1kOIkvhdm7gCaA.png" /></figure><p>Now everything is ready, let’s craft out script to get the reverse shell</p><p>we will use a tool called msfvenom for this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*5J1gF_PJXsm4-copQrIFhA.png" /></figure><p>LHOST= ip of the kali machine</p><p>LPORT= the port your kali is listening</p><p>EXITFUNC=thread is for making the shell stable <br>-f is for the file type, here it is C<br>-a is for architecture, here it is x86<br>-b is for bad character, which only the null byte is needed here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*-VNJVVgs0AAgNMTZORvjyg.png" /></figure><p>“\x90” = no operation</p><p>Remember to set a listener on port 4444 in your kali machine</p><pre>nc -lvp 4444 </pre><p>and run the script</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*4vKlWYC9QpcmHcrlkug7NA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fe3ac61d44d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>