Lecture 4 - Software Threats and Vulnerabilities: CS Department City University of Hong Kong
Lecture 4 - Software Threats and Vulnerabilities: CS Department City University of Hong Kong
Vulnerabilities
CS Department
City University of Hong Kong
Buffer-overflow and
Memory Safety
• Examples.
– Buffer overflow attacks
– Integer overflow attacks
– Format string vulnerabilities
– Race condition vulnerabilities
An Information Security Short Course
15
(Summer 2020)
Example 1: buffer overflows
• Extremely common bug in C/C++ programs.
– First major exploit: 1988 Internet Worm. fingerd. (a simple background
process on server)
# of vulnerable 600
software product
500 »20% of all vuln.
400 2005-2007: » 10%
300
200
char buf[128]
SP
An Information Security Short Course
23
(Summer 2020)
What are buffer overflows?
• One of the most common OS bugs is a buffer overflow
– The developer fails to include code that checks whether an input
string fits into its buffer array
– An input to the running process exceeds the length of the buffer
– The input string overwrites a portion of the memory of the process
– Causes the application to behave improperly and unexpectedly
argument: str
return address
stack frame pointer
*str Problem:
no length checking in strcpy()
char buf[128]
Program P: execve(“/bin/sh”)
return address
When func() exits, the user gets shell !
Note: attack code P runs in stack.
char buf[128]
low
An Information Security Short Course
42
(Summer 2020)
Shellcode of execve
How to develop shellcode that runs as execve(“/bin/sh”)?
low
An Information Security Short Course
51
(Summer 2020)
An Information Security Short Course
52
(Summer 2020)
More on Stack Smashing
• Some complications:
– Shellcode should not contain the ‘\0’ character.
– Overflow should not crash program before func()
exists.
Object T
NOP shell
• After overflow of buf : slide code
data
buf[256] vtable
ptr
An Information Security Short Course 56
(Summer 2020) object T
General Control Hijacking:
Corrupting Function Pointers in Heap
shellcode
shellcode
shellcode
More Control
Hijacking Attacks