Return-to-libc Attacks
Instructor: Fengwei Zhang
1
SUSTech CS 315 Computer Security
Return-to-libc Attacks Instructor: Fengwei Zhang 1 SUSTech CS 315 - - PowerPoint PPT Presentation
Return-to-libc Attacks Instructor: Fengwei Zhang 1 SUSTech CS 315 Computer Security Outline Non-executable Stack countermeasure How to defeat the countermeasure Tasks involved in the attack Function Prologue and Epilogue
Instructor: Fengwei Zhang
1
SUSTech CS 315 Computer Security
2
Running shellcode in C program
3
Calls shellcode
4
5
Jump to existing code: e.g. libc library. Function: system(cmd): cmd argument is a command which gets executed.
6
Buffer overflow problem
This code has potential buffer overflow problem in vul_func()
“Non executable stack” countermeasure is switched
address randomization is turned off. Root owned Set-UID program.
7
Task A : Find address of system().
address. Task B : Find address of the “/bin/sh” string.
Task C : Construct arguments for system()
address (argument for system())
8
system() and exit().
9
10
MYSHELL is passed to the vulnerable program as an environment variable, which is stored on the stack. Export an environment variable called “MYSHELL” with value “/bin/sh”. We can find its address.
11
Code to display address of environment variable
Export “MYSHELL” environment variable and execute the code.
12
is sensitive to the length of the program name.
to env77, we get a different address.
13
Frame for the system() function Need to know where exactly ebp is after we have “returned” to system(), so we can put the argument at ebp + 8.
Task C : Argument for system() Function Prologue
14
esp : Stack pointer ebp : Frame Pointer
15
Function Epilogue esp : Stack pointer ebp : Frame Pointer
16
1 2 1 2
Function prologue Function epilogue 8(%ebp) ⇒ %ebp + 8
17
Modified Return Address vul_func() epilogue system() prologue
Use of system()’s
argument
how the ebp and esp registers change with the function calls.
argument is used, vul_func() returns and system() prologue begins.
Change ebp and esp
Memory Map to Understand system() Argument
18
Return address is changed to system() address. ebp is replaced by esp after vul_func() epilogue Jump to system() system() prologue is executed ebp is set to current value of esp “/bin/sh” is stored in ebp+8 Check the memory map
19
ebp + 4 is treated as return address of system(). We can put exit() address so that on system() return exit() is called and the program doesn’t crash.
20
ebp + 4 ebp + 8 ebp + 12
code
21
bypassed
level details about function invocation
Oriented Programming (ROP)
22