Buffer Overflows
(…dissecting the exploit)
http://www.JasonDion.com
Attacker’s Methodology
Covering
Scanning Escalation Tracks
Performing Gaining Maintaining
and of and
Reconnaissance Access Access
Enumeration Privilege Placing
Backdoors
Pre-Attack Steps
Risk Level
http://www.JasonDion.com Buffer Overflows
What is a Buffer?
• A temporary storage
area the program uses
to store data
http://www.JasonDion.com Buffer Overflows
Buffer Usage
Phone: 555-1234
http://www.JasonDion.com Buffer Overflows
Buffer Usage
Example of an 8-bit Buffer (A)
A
0 1 2 3 4 5 6 7
Phone: 555-1234
http://www.JasonDion.com Buffer Overflows
Buffer Usage
Example of an 8-bit Buffer (A)
A 5 5 5 - 1 2 3 4
0 1 2 3 4 5 6 7
Phone: 555-1234
http://www.JasonDion.com Buffer Overflows
What is a Buffer Overflow?
• When a program puts
more data into a
buffer than the buffer
can hold
http://www.JasonDion.com Buffer Overflows
Buffer Usage
Example of an 8-bit Buffer (A)
A 5 5 5 - 1 2 3 4
0 1 2 3 4 5 6 7
B
0 1 2 3 4 5 6 7
Phone: 555-1234
http://www.JasonDion.com Buffer Overflows
Buffer Overflow
Example of an 8-bit Buffer (A)
A
0 1 2 3 4 5 6 7
B
0 1 2 3 4 5 6 7
Phone: 555-1234
210-555-1234
http://www.JasonDion.com Buffer Overflows
Buffer Overflow
Example of an 8-bit Buffer (A)
A 2 1 0 - 5 5 5 -
0 1 2 3 4 5 6 7
B 1 2 3 4
0 1 2 3 4 5 6 7
Phone: 555-1234
210-555-1234
http://www.JasonDion.com Buffer Overflows
How does the exploit work?
• Stack is a reserved area of
memory where the program
saves the return address
when a call instruction is
received
http://www.JasonDion.com Buffer Overflows
How does the exploit work?
• Stack is organized in FILO
structure
• First thing placed in the
stack is the last thing
removed
http://www.JasonDion.com Buffer Overflows
How does the exploit work?
• Attacker can place too
much information on the
stack or change the value
of the return pointer to carry
out the attack
http://www.JasonDion.com Buffer Overflows
How does the exploit work?
• Attacker’s code is placed in
the buffer
• Code could be used to run
commands or execute a
series of instructions
http://www.JasonDion.com Buffer Overflows
Attacker’s Methodology
Covering
Scanning Escalation Tracks
Performing Gaining Maintaining
and of and
Reconnaissance Access Access
Enumeration Privilege Placing
Backdoors
Pre-Attack Steps
Risk Level
http://www.JasonDion.com Buffer Overflows
Practice: Over the Wire
• http://overthewire.org/wargames/narnia/
• A live environment you can
connect to via SSH to attempt
various binary exploitation
challenges, including
Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
http://www.JasonDion.com Buffer Overflows
Recommended Reading
• The Shellcoder’s Handbook
• Hacking: The Art of Exploitation
• The Hacker Playbook 2
http://www.JasonDion.com Buffer Overflows
Buffer Overflows
(…dissecting the exploit)
http://www.JasonDion.com