32
Buffer Overflow 1 Software and Security

Software and Security

  • Upload
    morna

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

Software and Security. Why Software?. Why is software important to security? Virtually all of information security is implemented in software If your software is subject to attack, your security is broken Regardless of strength of crypto, access control, security protocols, etc. - PowerPoint PPT Presentation

Citation preview

Page 1: Software and Security

Buffer Overflow 1

Software and Security

Page 2: Software and Security

Buffer Overflow 2

Why Software? Why is software important to security? Virtually all of information security is

implemented in software If your software is subject to attack,

your security is brokeno Regardless of strength of crypto, access

control, security protocols, etc. Software is a poor foundation for

security

Page 3: Software and Security

Buffer Overflow 3

Bad Software Bad software is everywhere! NASA Mars Lander (cost $165 million)

o Crashed into Marso Error in converting English and metric units of

measure Denver airport

o Buggy baggage handling systemo Delayed airport opening by 11 monthso Cost of delay exceeded $1 million/day

MV-22 Ospreyo Advanced military aircrafto Lives have been lost due to faulty software

Page 4: Software and Security

Buffer Overflow 4

Software Issues

Attackers Actively look for

bugs and flaws Like bad software… …and try to make

it misbehave Attack systems

thru bad software

“Normal” users Find bugs and

flaws by accident Hate bad

software… …but must learn to

live with it Must make bad

software work

Page 5: Software and Security

Buffer Overflow 5

Complexity “Complexity is the enemy of security”, Paul

Kocher, Cryptography Research, Inc.

Netscape 17,000,000

Space shuttle 10,000,000

Linux 1,500,000

Windows XP 40,000,000

Boeing 777 7,000,000

system Lines of code (LOC)

A new car contains more LOC than was required to land the Apollo astronauts on the moon

Page 6: Software and Security

Buffer Overflow 6

Lines of Code and Bugs Conservative estimate: 5 bugs/1000 LOC Do the math

o Typical computer: 3,000 exe’s of 100K eacho Conservative estimate of 50 bugs/exeo About 150k bugs per computero 30,000 node network has 4.5 billion bugso Suppose that only 10% of bugs security-

critical and only 10% of those remotely exploitable

o Then “only” 4.5 million security-critical flaws!

Page 7: Software and Security

Buffer Overflow 7

Software Security Topics Program flaws (unintentional)

o Buffer overflowo Incomplete mediationo Race conditions

Malicious software (intentional)o Viruseso Wormso Other breeds of malware

Page 8: Software and Security

Buffer Overflow 8

Secure Software In software engineering, try to insure

that a program does what is intended Secure software engineering requires

that the software does what is intended…

…and nothing more Absolutely secure software is impossible

o Absolute security is almost never possible! How can we manage the risks?

Page 9: Software and Security

Buffer Overflow 9

Program Flaws Program flaws are unintentional

o But still create security risks The 3 most common types of flaws

o Buffer overflow (smashing the stack)o Incomplete mediationo Race conditions

Many other flaws can occur Here, we only consider buffer overflow

Page 10: Software and Security

Buffer Overflow 10

Buffer Overflow

Page 11: Software and Security

Buffer Overflow 11

Typical Attack Scenario

Users enter data into a Web form Web form is sent to server Server writes data to buffer, without

checking length of input data Data overflows from buffer Sometimes, overflow can enable an

attack Web form attack could be carried out by

anyone with an Internet connection

Page 12: Software and Security

Buffer Overflow 12

Buffer Overflow

Q: What happens when this is executed?

A: Depending on what resides in memory at location “buffer[20]”o Might overwrite user data or codeo Might overwrite system data or code

int main(){

int buffer[10];

buffer[20] = 37;}

Page 13: Software and Security

Buffer Overflow 13

Simple Buffer Overflow Consider boolean flag for authentication Buffer overflow could overwrite flag

allowing anyone to authenticate!

buffer

FTF O U R S C …

Boolean flag

In some cases, attacker need not be so lucky as to have overflow overwrite flag

Page 14: Software and Security

Buffer Overflow 14

Memory Organization

Text == code Data == static variables Heap == dynamic data Stack == “scratch

paper” o Dynamic local variableso Parameters to functionso Return address

stack

heap

data

text

high address

low address

SP

Page 15: Software and Security

Buffer Overflow 15

Simplified Stack Example

high

void func(int a, int b){

char buffer[10];

}

void main(){

func(1, 2);

}

::

buffer

ret

a

b

return address

low

SP

SP

SP

SP

Page 16: Software and Security

Buffer Overflow 16

Smashing the Stack

high

What happens if buffer overflows?

::

buffer

a

b

ret…

low

SP

SP

SP

SP

retoverflow

Program “returns” to wrong location

NOT!

???

A crash is likelyoverflow

Page 17: Software and Security

Buffer Overflow 17

Smashing the Stack

high

Trudy has a better idea… :

:

evil code

a

b

low

SP

SP

SP

SP

retret

Code injection Trudy can run

code of her choosing!

Page 18: Software and Security

Buffer Overflow 18

Smashing the Stack

Trudy may not knowo Address of evil codeo Location of ret on

stack Solutions

o Precede evil code with NOP “landing pad”

o Insert lots of new ret

evil code

::

::

ret

ret

:

NOP

NOP:

ret ret

Page 19: Software and Security

Buffer Overflow 19

Stack Smashing Summary

A buffer overflow must exist in the code Not all buffer overflows are exploitable

o Things must line up just right If exploitable, attacker can inject code Trial and error likely required

o Lots of help available onlineo Smashing the Stack for Fun and Profit, Aleph

One Also heap overflow, integer overflow, etc. Stack smashing is “attack of the decade”

Page 20: Software and Security

Buffer Overflow 20

Stack Smashing Example Program asks for a serial number that the

attacker does not know Attacker does not have source code Attacker does have the executable (exe)

Program quits on incorrect serial number

Page 21: Software and Security

Buffer Overflow 21

Example By trial and error, attacker discovers an

apparent buffer overflow

Note that 0x41 is “A” Looks like ret overwritten by 2 bytes!

Page 22: Software and Security

Buffer Overflow 22

Example Next, disassemble bo.exe to find

The goal is to exploit buffer overflow to jump to address 0x401034

Page 23: Software and Security

Buffer Overflow 23

Example Find that 0x401034 is “@^P4” in ASCII

Byte order is reversed? Why? X86 processors are “little-endian”

Page 24: Software and Security

Buffer Overflow 24

Example Reverse the byte order to “4^P@” and…

Success! We’ve bypassed serial number check by exploiting a buffer overflow

Overwrote the return address on the stack

Page 25: Software and Security

Buffer Overflow 25

Example

Attacker did not require access to the source code

Only tool used was a disassembler to determine address to jump to

Can find address by trial and erroro Necessary if attacker does not have

exeo For example, a remote attack

Page 26: Software and Security

Buffer Overflow 26

Example

Source code of the buffer overflow

Flaw easily found by attacker

Even without the source code!

Page 27: Software and Security

Buffer Overflow 27

Stack Smashing Prevention

1st choice: employ non-executable stacko “No execute” NX bit (if available) o Seems like the logical thing to do, but some real

code executes on the stack (Java does this) 2nd choice: use safe languages (Java, C#) 3rd choice: use safer C functions

o For unsafe functions, there are safer versionso For example, strncpy instead of strcpy

Page 28: Software and Security

Buffer Overflow 28

Stack Smashing Prevention

Canaryo Run-time stack checko Push canary onto stacko Canary value:

Constant 0x000aff0d Or value depends on ret

high

::

buffer

a

b

low

overflowret

canaryoverflow

Page 29: Software and Security

Buffer Overflow 29

Microsoft’s Canary Microsoft added buffer security check

feature to C++ with /GS compiler flag Uses canary (or “security cookie”) Q: What to do when canary dies? A: Check for user-supplied handler Handler may be subject to attack

o Claimed that attacker can specify handler code

o If so, “safe” buffer overflows become exploitable when /GS is used!

Page 30: Software and Security

Buffer Overflow 30

ASLR Address Space Layout

Randomization Randomize place where code is put

into memory Makes most buffer overflow attacks

probabilistic Vista does this (256 random

layouts)o Similar thing is done in Mac OS X

Page 31: Software and Security

Buffer Overflow 31

ASLR See work by Ulfar Erlingsson

o Slides can be found here

Page 32: Software and Security

Buffer Overflow 32

Buffer Overflow The “attack of the decade” for 90’s Will be the attack of the decade for 00’s Can be greatly reduced

o Use safe languages/safer functionso Educate developers, use tools, etc.

Buffer overflows will exist for a long timeo Legacy codeo Bad software development