In the previous part of the Buffer overflow exploit we went through the basic overview of buffer overflow. In this tutorial we will create a server that is vulnerable to buffer overflow attack and create a simple client or attacker that connects to the server and sends a simple message.
Github - https://github.com/RihaMaheshwari/Buffer-Overflow-Exploit
Creating a Server
We need to create a server where we can perform the attack. We are using Windows 10 as a target for an attack. Below is the server code that is written in C programming language that is vulnerable to buffer overflow attack stored in C:/VulnerableServer. Copy and paste the code in Visual Studio 2017 and compile it.
The above program will open a port (i.e. 1200) and start listening. The buffer size is 100 and the use of strcpy () function is made. In the above code, a dll file is loaded. The reason for why we need to load the dll file is explained in Buffer Overflow - part 1. The dll file is stored in the same address as the Server (i.e. C:/VulnerableServer/Debug/dll.dll). You can also download the dll file by clicking here. Compile the code and run it in Visual Studio 2017. The given Figure is the output when the code is compiled and running.
Figure 1. Output of the Vulnerable server
Attaching Server with Immunity debugger
We will need to attach the server in an immunity debugger to see how the memory looks when running the server. When you run the server code in Visual Studio, it automatically generates an exe file that is stored in C:/VulnerableServer/Debug/VulnerableServer.exe. To attach the server in the immunity debugger, Open Immunity debugger and go to File → Open→ Select the VulnerableServer.exe file → Open as shown in figure.
Figure 2. Opening the executable file in debugger
An alert may be displayed, you need to allow access and click on the run button to get the port listening. The output of this is the same as shown in figure 1.
Verifying Port is Listening
To check whether it is actually listening to the port number we provided open command prompt and type the following command:
The output of the command will give the result as Listening as shown in the below diagram.
Figure 3. Verifying if the port 1200 is listening
Now we know the server is listening to the port number that we provided. Now the next step is to create a client/attacker which will send the data to the server through that port number.
Creating Attacker’s Script
Till now we just created a vulnerable Server that opens a port 1200 and listens to it. Now we need to create an attacker’s script that will connect to the port number 1200 and send a message. So we are going to use Kali Linux as an attacker’s machine. For this tutorial both the attacker and server are in the same network.
Before proceeding forward make sure you install python 2.7 in Kali Linux. Copy the following code written in Python and run it.
To run you need to open the terminal in the same folder where the above python script is saved. And type the following-
When you press enter, it will send message (i.e. Hello World) to the server. The following figure shows you the output on the server side when the message is sent. Whereas from the attacker’s side you will see the text as “The message has been sent”. If you don’t get this output, you may not be in the same network. Make sure in the script you change the ip address with the server’s ip.
Figure 4. Message sent from attacker to server
No comments:
Post a Comment