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

bof 321
OSCP Study materialbuffer overflow

Memory is the most crucial part of a system. We discussed memory and its working so now let’s see Memory in more details

bof 321
program memory

Generally, a process is laid out like it is defined in the figure .all above varios segments we have in program memory. So let’s get some idea about these segments

.text Segment: – The first segment is the actual program code in the .text segment where all the executable instructions are there

.data Segment:– Any data which has been inintilized to a value is stored

.bss Segment:– All uninitilized data store in .bss

Heap : – heap is used to generate dynamic memory whenever is required. In C we use malloc() function to use the dynamic memory. In c++ we use new and delete variable for the heap

We have a lot of unused memory

Stack: – The stack always points on top of the segment. we use the stack for storing arguments which are passed in the function as well as the local variables. The stack is also working as High to Low. Don’t worry at this time if you don’t understand about the stack as of now.

let’s discuss stack in more details coz its a very much important factor for BOF

Stack & It’s Working


The stack is a last in first out data structure. As we already know it is working as high to low . Stack grows down to the memory. The ESP should be pointing out top of the stack.

Stack support two operations: –

Push operation:– Push operation is used to pushing data into the stack. As soon as we push a value (2xA0203040) what one needs to do is update the stack pointer so now ESP will point the top of the stack after the adding the new value.

Push operation

POP Operation: – Once you are done with using the value you used pop operation free the memory from the stack and again we subtract value from ESP and again Put ESP as the top of the stack

PoP Operation

That’s all about this blog. We will discuss more stack and its operation in the next blog because it plays main role in the stack buffer overflow attack.

If you want to understand more deep information about stack and heap then visit this link

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

References : –

  1. https://aticleworld.com/memory-layout-of-c-program/
  2. http://www.firmcodes.com/memory-layout-c-program-2/
  3. https://www.youtube.com/watch?v=K0g-twyhmQ4
  4. https://www.youtube.com/watch?v=_8-ht2AKyH4

Leave a Reply

Your email address will not be published.