OSCP – Detail Guide to Stack-based buffer Overflow – 6
In this blog, we will use our python script to again do execute the same task again. So this time we will call it fuzzing.
So start your vulnserver server in the windows machine and attach vulnserve in immunity debugger.
On the other side in kali machine create a script and test the program crash. I have already shared the script in the last blog you use that. Also, I am using another script to fuzz the program.
#!/usr/bin/python import sys, socket from time import sleep buffer = " A" * 1500 while True: try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(( '192.168.31.146', 9999)) s.send(( 'TRUN /.:/' + buffer)) s.close() sleep(l) buffer = buffer + "A"*100 except : print "Fuzzing crashed at %s bytes" %str(len(buffer)) sys.exit()
try to fire this script. on the other side
As you can see we got an access violation and paused. The value of ESP is overwritten with a bunch of A’s and also it overwrote the EIP as well so this is a good sign.
Now in Order to Execute our shellcode it is important to control the EIP. So we will create a pattern to come to know at what point we can control the EIP. We use Pattern Offset to find the exact location of the overwrite. Pattern Create allows us to generate a cyclical amount of bytes, based on the number of bytes we specify. We can then send those bytes to Vulnserver, instead of A’s, and try to find exactly where we overwrote the EIP. Pattern Offset will help us determine that soon. So let use this pattern in our script. We have a pattern creator script in Metasploit so we will use it in our kali box.
Now we use this random create pattern in our python script. here is the script below : –
Now we will use this script to get the exact overwritten point of EIP. So again start the vulnserver and attach in immunity debugger in window machine. press f9 to start the program.
On the other side execute this script
The Vulnserver crashed again and our “TRUN” message appearing on the EAX register. Now, look at the EIP. The value is 386F4337. If we executed correctly, this value is actually part of our code that we generated with Pattern Create.
Let’s try using Pattern Offset to find out. The command that should be typed is pattern_offset.rb -l 3000 -q 386F4337where “q” is our EIP value. Here are my results:
As you can see, an exact match was found at 2003 bytes. This is great news. We can now try to control the EIP, which will be critical later in our exploit.
That’s all about this blog. Next blog, we will use this offset value and create a new script to get more details and execute additional bad chars to get more interesting details about this attack.
Thanks for visiting this blog. Join Certcube Labs for IT security Training & Certifications