SlideShare a Scribd company logo
1 of 65
Software Exploits How the Black Hats do what they do—Stack Overflows (or how a 1337 h4x0r can pwn your system) Kevin C. Smallwood March 2006
What will we cover? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is a buffer overflow? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The problem on the stack ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Shellcode ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simple example program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Typical execve() program stack Low Memory High Memory 4-byte null Bottom of Stack 0xBFFFFFFC: Full pathname of executable—null-terminated env strings—null-terminated TERM=vt100, etc. argv strings—null-terminated argv[0], argv[1], etc. zero-filled padding 0 to 8064 bytes Starting address can easily be calculated: /bin/ls    8-bytes 112-bytes of ELF interpreter information env pointers argv pointers runtime data (from _start, etc.) envp argv argc Top of Stack Parameters to  main()
How are functions called? ,[object Object],[object Object]
Function Call ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],parameters to greeting() greeting(char *temp1, char *temp2) Return Address High Memory temp2 Low Memory temp1 Return Address (eip)
Function Prolog ,[object Object],[object Object],[object Object],char  name[400] ; temp2 Low Memory Return Address (eip) ,[object Object],ebp High Memory esp name[400] temp1
Function Epilog ,[object Object],[object Object],High Memory temp2 Low Memory Return Address (eip) ,[object Object],ebp esp name[400] temp1
Even simpler code example: ,[object Object],[object Object],[object Object],[object Object]
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y 
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y  i
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y  i d
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y  i d e
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y  i d e n
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y  i d e n t
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer m y  i d e n t null
What happens to the stack? ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer 6D 79 20 69 64 65 6E 74 00
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h 
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t 
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a c
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a c k
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a c k 8E
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a c k 8E FF
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a c k 8E FF FF
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer s m a s h  t h a t  s t a c k 8E FF FF BF
What happens to the stack? Black Hat Style ,[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer 73 6D 60 73 68 20 74 68 60 74 20 73 74 60 63 6B 8E FF FF BF
What is significant about the return address? ,[object Object],[object Object],[object Object],[object Object],[object Object],stuff more stuff Return Address Saved Frame Pointer 73 6D 60 73 68 20 74 68 60 74 20 73 74 60 63 6B 8E FF FF BF
More about shellcode ,[object Object],[object Object],[object Object],[object Object]
Classic shell-spawning shellcode ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classic shell-spawning shellcode ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classic shell-spawning shellcode ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
genv program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Put the exploit together ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What does the program stack look like? ,[object Object],stuff more stuff Return Address Saved Frame Pointer 8E FD FF BF 8E FD FF BF 8E FD FF BF 8E FD FF BF 8E FD FF BF
Is this a problem in OSS? ,[object Object],[object Object],[object Object],[object Object]
Methods of stopping stack buffer overflows ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Be a better software engineer! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What did we cover? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
For more information ,[object Object],[object Object],[object Object],[object Object],[object Object]
Questions? Feedback?
Part 2: Overflows in the Heap ,[object Object]
Heap overflows ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Heap overflow program #1 Adjacent variable corruption ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Heap overflow program #1 Adjacent variable corruption ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Heap overflow exploit Adjacent variable corruption ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Heap overflow exploit  Adjacent variable corruption ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Playing 44CON CTF for fun and profit
Playing 44CON CTF for fun and profitPlaying 44CON CTF for fun and profit
Playing 44CON CTF for fun and profit44CON
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...akaptur
 
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrainsit-people
 
Exploring slides
Exploring slidesExploring slides
Exploring slidesakaptur
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Python profiling
Python profilingPython profiling
Python profilingdreampuf
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterakaptur
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XSbyterock
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
PFDS 8.4.1
PFDS 8.4.1PFDS 8.4.1
PFDS 8.4.1rf0444
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...akaptur
 
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2DataStax
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegeninovex GmbH
 

What's hot (20)

Playing 44CON CTF for fun and profit
Playing 44CON CTF for fun and profitPlaying 44CON CTF for fun and profit
Playing 44CON CTF for fun and profit
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Python profiling
Python profilingPython profiling
Python profiling
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Faster Python, FOSDEM
Faster Python, FOSDEMFaster Python, FOSDEM
Faster Python, FOSDEM
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Files
FilesFiles
Files
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
PFDS 8.4.1
PFDS 8.4.1PFDS 8.4.1
PFDS 8.4.1
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
Cassandra Community Webinar | Introduction to Apache Cassandra 1.2
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
 
CLinkedList
CLinkedListCLinkedList
CLinkedList
 
Vcs26
Vcs26Vcs26
Vcs26
 

Viewers also liked

Buffer overflow(bao cao)
Buffer overflow(bao cao)Buffer overflow(bao cao)
Buffer overflow(bao cao)phanleson
 
Design and implementation_of_shellcodes
Design and implementation_of_shellcodesDesign and implementation_of_shellcodes
Design and implementation_of_shellcodesAmr Ali
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W mattersAlexandre Moneger
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionGeorg Wicherski
 
Anatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAnatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAbhineet Ayan
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassemblingHarsh Daftary
 
Java Shellcode Execution
Java Shellcode ExecutionJava Shellcode Execution
Java Shellcode ExecutionRyan Wincey
 
Shellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycShellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycZ Chen
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR mattersAlexandre Moneger
 
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentExploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentAjin Abraham
 
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEFMichele Orru
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writingsbha0909
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Positive Hack Days
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013midnite_runr
 
Hacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortHacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortVincent Ohprecio
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptJulia Yu-Chin Cheng
 
Exploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterExploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterAjin Abraham
 

Viewers also liked (20)

Buffer overflow(bao cao)
Buffer overflow(bao cao)Buffer overflow(bao cao)
Buffer overflow(bao cao)
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
 
PUROLLC-SAMPLE SLIDE
PUROLLC-SAMPLE SLIDEPUROLLC-SAMPLE SLIDE
PUROLLC-SAMPLE SLIDE
 
Business management of hiv aids case study of a south african contract cleani...
Business management of hiv aids case study of a south african contract cleani...Business management of hiv aids case study of a south african contract cleani...
Business management of hiv aids case study of a south african contract cleani...
 
Design and implementation_of_shellcodes
Design and implementation_of_shellcodesDesign and implementation_of_shellcodes
Design and implementation_of_shellcodes
 
07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters07 - Bypassing ASLR, or why X^W matters
07 - Bypassing ASLR, or why X^W matters
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode Detection
 
Anatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineeringAnatomy of A Shell Code, Reverse engineering
Anatomy of A Shell Code, Reverse engineering
 
Linux Shellcode disassembling
Linux Shellcode disassemblingLinux Shellcode disassembling
Linux Shellcode disassembling
 
Java Shellcode Execution
Java Shellcode ExecutionJava Shellcode Execution
Java Shellcode Execution
 
Shellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneycShellcode and heapspray detection in phoneyc
Shellcode and heapspray detection in phoneyc
 
05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters05 - Bypassing DEP, or why ASLR matters
05 - Bypassing DEP, or why ASLR matters
 
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit DevelopmentExploit Research and Development Megaprimer: Unicode Based Exploit Development
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
 
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writing
 
Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.Anton Dorfman. Shellcode Mastering.
Anton Dorfman. Shellcode Mastering.
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
 
Hacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades shortHacking school computers for fun profit and better grades short
Hacking school computers for fun profit and better grades short
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and Concept
 
Exploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 EgghunterExploit Research and Development Megaprimer: Win32 Egghunter
Exploit Research and Development Megaprimer: Win32 Egghunter
 

Similar to Software Exploits

StackOverflow
StackOverflowStackOverflow
StackOverflowSusam Pal
 
Defcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEDefcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEFelipe Prado
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer OverflowsSumit Kumar
 
Format String Vulnerability
Format String VulnerabilityFormat String Vulnerability
Format String VulnerabilityJian-Yu Li
 
CS50 Lecture3
CS50 Lecture3CS50 Lecture3
CS50 Lecture3昀 李
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploitshughpearse
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory OverflowsAnkur Tyagi
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 
Need help with this paperThis assignment consists of writing resea.pdf
Need help with this paperThis assignment consists of writing resea.pdfNeed help with this paperThis assignment consists of writing resea.pdf
Need help with this paperThis assignment consists of writing resea.pdfsktambifortune
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performancesjulien pauli
 
Offensive cyber security: Smashing the stack with Python
Offensive cyber security: Smashing the stack with PythonOffensive cyber security: Smashing the stack with Python
Offensive cyber security: Smashing the stack with PythonMalachi Jones
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughterQuinn Wilton
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Charles Nutter
 
Compiler design.pdf
Compiler design.pdfCompiler design.pdf
Compiler design.pdfNitesh Dubey
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineMatt Provost
 

Similar to Software Exploits (20)

StackOverflow
StackOverflowStackOverflow
StackOverflow
 
Defcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEDefcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHE
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer Overflows
 
Format String Vulnerability
Format String VulnerabilityFormat String Vulnerability
Format String Vulnerability
 
ROP
ROPROP
ROP
 
CS50 Lecture3
CS50 Lecture3CS50 Lecture3
CS50 Lecture3
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
Need help with this paperThis assignment consists of writing resea.pdf
Need help with this paperThis assignment consists of writing resea.pdfNeed help with this paperThis assignment consists of writing resea.pdf
Need help with this paperThis assignment consists of writing resea.pdf
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
 
Offensive cyber security: Smashing the stack with Python
Offensive cyber security: Smashing the stack with PythonOffensive cyber security: Smashing the stack with Python
Offensive cyber security: Smashing the stack with Python
 
Exploitation Crash Course
Exploitation Crash CourseExploitation Crash Course
Exploitation Crash Course
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
test
testtest
test
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Compiler design.pdf
Compiler design.pdfCompiler design.pdf
Compiler design.pdf
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 

Software Exploits

  • 1. Software Exploits How the Black Hats do what they do—Stack Overflows (or how a 1337 h4x0r can pwn your system) Kevin C. Smallwood March 2006
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Typical execve() program stack Low Memory High Memory 4-byte null Bottom of Stack 0xBFFFFFFC: Full pathname of executable—null-terminated env strings—null-terminated TERM=vt100, etc. argv strings—null-terminated argv[0], argv[1], etc. zero-filled padding 0 to 8064 bytes Starting address can easily be calculated: /bin/ls  8-bytes 112-bytes of ELF interpreter information env pointers argv pointers runtime data (from _start, etc.) envp argv argc Top of Stack Parameters to main()
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.

Editor's Notes

  1. Leet Speak: How an “elite” “hacker” can “own” your system.
  2. Most of us have heard about buffer overflows. We know they are poor programming practices, and we may have heard that they allow the “Black Hats” access to our systems or programs in some way. But how do the Black Hats really exploit a small programming error? Why is a gets(), strcpy(), sprintf(), etc. such a problem? Bottom-line is that the Black Hats use buffer overflows on the stack to overwrite the return address to jump to their supplied code or crash the system. The key is that the Black Hat must control the input of the source buffer in order to overflow the destination buffer. If there is no outside of the program input for the source buffer, and the programmer knows that the source buffer is not larger than the destination buffer, a strcpy() is not a bad thing. You just need to know what to look for!
  3. Knowing the contents of the stack and how functions are called is very important in the understanding of how to exploit a buffer overflow. Details of the stack will be covered in up-coming slides. Sometimes a Black Hat will just cause the exploited software to crash. This can cause a Denial of Service (DoS). If a service (local or remote) is important enough, denial to that service could result in lost revenue or reputation.
  4. Shellcode got its name from the typical functionality of providing a privileged shell on a system. A remote exploit may just provide an entry point for the Black Hat to launch further attacks in order to gain full access to the system. Since the Black Hat can overwrite the return address of a function on the stack, that return address could be changed to the address of a program function that rewards the exploiter by applying credits to an account, zeroing-out a balance, increasing the quantity ordered (but not the total price), etc. A return address could be changed to execute a C-Library call like “execve()” to provide a shell or other privilege. This is one way around non-executable stack protection since the stack is just used to build proper arguments and then return into the library to do the dirty work.
  5. The important items in this example program are in red . The main thing to note is that we are passing argv[2] from outside the program to a function where we do a strcpy() into a set-length buffer of size 400. It is pretty easy to supply more than 400 characters from the command line. Those extra characters will overflow the name[] buffer and over-write items on the stack including the return address.
  6. This diagram is very important to know well. The stack grows from high memory to low memory. The starting address of the environment strings can easily be calculated if you know the full pathname of the command. The area on the stack for environment strings can be used to hold shellcode. The zero-filled padding space on the stack was something introduced in 2.5 for hyper-threading. The runtime data is information first loaded when a program is loaded to execute, but before the main() procedure is called. NOTE: This assumes that Red Hat’s exec-shield is not on.
  7. Assembly code is using AT&T format: CMD <source> <destination>
  8. Here we are saving the caller’s frame pointer along with making room for the local variables--in this case 400 bytes for the “name” character array.
  9. The “leave” instruction restores/pops the save frame pointer to point back at the calling routine. The “ret” instruction pops the return address on the stack into the EIP register where execution will continue at that new address.
  10. Let’s use a real simple code example to demonstrate the exploit.
  11. Assume that the source string (i.e., “my ident”) is being provided from outside the program via the command line, a file, an environment variable, a pipe-line or even a network connection. The point is that the source string comes from outside the program and is under the control of the attacker.
  12. The final result of “normal” and expected (by the software engineer) behavior.
  13. Replacing the ASCII characters with numeric (hex) values.
  14. Again, assume that the source string in the strcpy() is being provided from outside the program by the attacker.
  15. The final result of our strcpy(). We have over-written the saved frame pointer and the return address. Note that with some skill, just over-writing the save frame pointer, we can influence the behavior of the executing program. However, it is much faster and more to the point to over-write the return address to execute our supplied “shell code.”
  16. Here we see what is on the stack in numeric form.
  17. Here is the crux of exploiting a stack (or heap) buffer overflow: executing supplied code not originally in the program.
  18. In some cases, the appearance of a NULL is not critical, but in most cases, shell code should not contain any zero bytes. Our main target for this exploit is to find setuid programs so that we can gain more privileges than we currently have.
  19. Various “tricks” used to avoid NULL bytes (for example, using “xor reg, reg” to zero-out that register).
  20. Notice no NULL bytes.
  21. Here is a simple program to tell us where the value of the environment variable is located on the stack.
  22. Smashing the stack of a setuid root program and executing shell-spawning shell code results in an interactive root shell! Yes!
  23. Five copies of the address copied onto the stack over-writing the return address!
  24. Examples of problems from the Common Vulnerabilities and Exposures list and BugTraq.
  25. Dangerous string handling functions: gets(), strcpy(), strcat(), sprintf(), vsprintf(), sscanf(), vscanf(), fscanf() Many of the insecure string handling functions have more secure functions that use a value to limit the number of characters processed. These include: fgets(), strncpy(), strncat(), snprintf(), vsnprintf() While these are more secure due to one of the parameters limiting the number of characters processed, be careful to fall victim to the off-by-one problem if the function automatically appends a NULL—the destination buffer size is now SIZE-1. Additionally, when concatenating strings in a buffer, the size of that buffer may only be the remaining space in the buffer and not the full size of the original buffer; this is a common programming mistake.
  26. This is only the beginning!
  27. The 24 bytes between the variables was found by experimentation.