Buffer Overflow - Theory Flashcards
How does a process creation works on Linux?
First, the kernel creates the virtual address space in which the program runs. Information is loaded from execution file to the newly allocated address space. And finally the kernel sets up the stack and heap and jumps at the entry point of the program.
What are the characteristics of the stack and the data allocated in it?
The data allocated in it corresponds to statically allocated local variables (including environments).
An important characteristic is that it grows towards the lower addresses (gross down).
What are the characteristics of the heap and the data allocated in it?
A contains the executable code, the uninitialized data, the initialized data (global variables) and the dynamically allocated data
An Important characteristic is that gross toward higher addresses (grows up)
What does the EIP register does
Contains the address of the next machining instruction to be executed
How does the call instruction works?
Based on the fact that the call instruction leads the stack pointer to another address, it needs to save the current EIP in order to be able to come back once the other function is over. It also needs to push the parameters to the stock.
What is the function prologue?
Since the CPU needs to remember where the caller frame is located on the stack (so that it can be restored once the call it function is over) function prologue pushes the current stock base address to the stack, moves the current top address to the base address (the new base of the stack is the old top of the stock), and moves the stack top pointer down giving room for the next instructions
What is the function epilogue?
They are the commands that resets the configurations from before the call function.
It includes leave and ret instructions, which corresponds to moving back the top stack pointer to the base pointer of the current called function frame, restore the saved base pointer (the pointer of the caller), pop the saved EIP and jump there.
What is the main idea of the stack smashing?
To use the memory writing characteristics and a buffer without size checking to override the instruction pointer of a called function
While using a stack smashing strategy what is the content to put in the instruction pointer of the called function, in other words, where do we jump?
We need to jump to a valid memory location that contains, or can be filled with, valid executable machine code
Some of the solutions are: environment variable, built-in existing functions, memory that we can control (the buffer itself, some other variable)
How do we guess the buffer location when using the buffer itself as the valid executable memory location in the stack smashing
We can use a debugger or read from a process in order to output the ESP value, but the results of the solutions differ from the real values, leading to a problem of precision
How do we deal with the problem of precision when using a debugger or a read from a process to output the ESP value in order to access the buffer itself content on a stack smashing strategy usage?
We can use the NOP sled. Which is a sequence of no operations at the beginning of the buffer which eventually leads us to the area of the executable code
What can we place as executable cold while using these stack smashing approach?
The main goal is to spawn a privileged shell. In order to do that we need to execute a system call, which is achieved by executing a software interrupt through the int instruction passing the 0x80 value.
How can we call the interrupt function successfully?
First, we need to write anywhere in the memory the “/bin/sh\0” content, then discover its address and create a buffer with it (address) as the first position and with a NULL value as the second position
Then we need to move the address of the string previously created, and placed in the first member of our buffer, in the register EBX, and using offsets pass the NULL value to the EDX register
How do we get the exact address of “/bin/sh\0”?
We execute a jump to a call instruction to which the next instruction is the creation of this content. This way the exact address is saved into the stack and we just pop it into our ESI register.
Why there is a problem leaving the 0x00 values in the assembly code?
Because they represent a “\0” which is a string term. String related operation will stop at the first “\0” found