Buffer Software Security overflows and other memory safety - - PowerPoint PPT Presentation

buffer
SMART_READER_LITE
LIVE PREVIEW

Buffer Software Security overflows and other memory safety - - PowerPoint PPT Presentation

This time We will begin By investigating our 1st section: Buffer Software Security overflows and other memory safety vulnerabilities History Memory layouts Buffer overflow fundamentals Analyzing security Security


slide-1
SLIDE 1

This time

  • History
  • Memory layouts
  • Buffer overflow fundamentals

Buffer

  • verflows

By investigating

and other memory safety vulnerabilities

We will begin

Software

Security

  • ur 1st section:
slide-2
SLIDE 2

Analyzing security

slide-3
SLIDE 3

“Security mindset”

  • One of the goals for this course is to develop a

“security mindset”

  • That is, the ability to view a potentially large,

complex system and be able to reason about:

  • What are some of the potential security threats?
  • What are the hidden assumptions? (and are the

explicit assumptions likely to be true?)

  • How can we mitigate the risks of the system?
  • Be creative! (attackers will be)
slide-4
SLIDE 4

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

Poll
 worker Voter Tabulator Encrypted
 disk Voting machine

slide-5
SLIDE 5

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

Poll
 worker Voter Tabulator Encrypted
 disk Voting machine

slide-6
SLIDE 6

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

Poll
 worker Voter Tabulator Encrypted
 disk

1

BDF Voting machine

slide-7
SLIDE 7

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

Poll
 worker Voter Tabulator Encrypted
 disk

1

BDF Voting machine

slide-8
SLIDE 8

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

Poll
 worker Voter Tabulator Encrypted
 disk

1

BDF

slide-9
SLIDE 9

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

Poll
 worker Voter Tabulator

2(a)

Token Encrypted
 disk

1

BDF

slide-10
SLIDE 10

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

2(b)

Poll
 worker Voter Tabulator

2(a)

Token Encrypted
 disk

1

BDF Token

slide-11
SLIDE 11

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

2(b) 2(c)

Poll
 worker Voter Tabulator

2(a)

Token Encrypted
 disk

1

BDF Token

slide-12
SLIDE 12

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

2(b) 2(c)

Poll
 worker Voter Tabulator

2(a)

Token Encrypted
 disk

1

BDF Token

slide-13
SLIDE 13

E-voting analysis

1.Pre-election phase

  • Poll worker loads a “ballot definition file” (defines

who’s running, colors on the screen, and many more things) on the voting machines with, e.g., USB

2.Voting phase

(a)Voter obtains a single-use token from poll workers

(on smartcard)

(b)Voter uses the token to interactively vote (c)Vote stored encrypted on disk (d)Voter token canceled

3.Post-election phase

  • Stored votes decrypted and transported to tabulator
  • Tabulator counts and announces vote
  • 1. Summarize the system as clearly


and concisely as possible

  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

2(b) 2(c) 3

Poll
 worker Voter Tabulator

2(a)

Token Encrypted
 disk

1

BDF Token

slide-14
SLIDE 14

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes
slide-15
SLIDE 15

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes

Is it ok if the attacker can do these, so long as you can catch him or her?

slide-16
SLIDE 16

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes
slide-17
SLIDE 17

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes
slide-18
SLIDE 18

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes
slide-19
SLIDE 19

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes
slide-20
SLIDE 20

E-voting analysis

  • 2. Identify the assets / goals of the system
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 disk BDF

  • Confidentiality (can’t steal data)
  • No one knows for whom any given voter

voted (except for the voter)

  • Integrity (can’t modify data)
  • Every voter’s vote counted once
  • No voter’s vote changed
  • Availability (system stays up)
  • Everyone has the ability to cast their vote
  • Usability (no undue burden on users)
  • Easy for the voter to vote (correct language,

good UI)

  • Easy for the tabulator to count votes
slide-21
SLIDE 21

E-voting analysis

  • 3. Identify the adversaries and threats
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 file store BDF

Someone with access to the disk or network: Read who voted for whom. Writing could change the outcome altogether Poll worker could
 set BDF to print
 “Mickey Mouse”
 but record as
 “Minnie Mouse” Voter could attempt to
 generate their own
 tokens & get ≥2 votes Someone with access to the machine: Because there is no end-to-end verification that a vote was counted, modifying the software could result in complete control

Token

slide-22
SLIDE 22

E-voting analysis

  • 4. Identify the vulnerabilities
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 file store BDF

  • Ballot definition files are not authenticated
  • How do we know they’re from the election board?
  • Can redefine “Candidate A” as “Candidate B”
  • Viruses
  • Smartcards are not authenticated
  • How do we know they’re not user-generated?
  • Possible to make your own and vote multiple times.
  • Specific software vulnerabilities
  • Every machine has the same encryption key!
  • Break one, and they all fall
  • Votes are shipped unencrypted!
  • Votes are stored in the order cast
  • If one can view the data unencrypted, this violates
  • ur confidentiality goal

Not a theoretical system: Diebold AccuVote-TS Used in 37 states at time of study
 Optional reading “Analysis of an Electronic Voting System”
 Kohno et al.

slide-23
SLIDE 23

E-voting analysis

  • 4. Identify the vulnerabilities
  • Mickey Mouse
  • Donald Duck
  • Minnie Mouse

1 2(a) 2(b) 2(c) 3

Poll
 worker Voter Tabulator Token Encrypted
 file store BDF

  • Ballot definition files are not authenticated
  • How do we know they’re from the election board?
  • Can redefine “Candidate A” as “Candidate B”
  • Viruses
  • Smartcards are not authenticated
  • How do we know they’re not user-generated?
  • Possible to make your own and vote multiple times.
  • Specific software vulnerabilities
  • Every machine has the same encryption key!
  • Break one, and they all fall
  • Votes are shipped unencrypted!
  • Votes are stored in the order cast
  • If one can view the data unencrypted, this violates
  • ur confidentiality goal
slide-24
SLIDE 24

Analyzing security

Takeaway points

  • Analyzing security requires a whole-systems view
  • Hardware, software, users, economics, ….
  • Security is only as strong as the weakest link
  • May have been difficult to break into the building
  • But if the data is sent unencrypted…
  • Securing a system can be difficult
  • Interdisciplinary (software, hardware, UI design)
  • Humans are in the loop
  • Security through obscurity does not work
  • Especially for high-value assets
  • It’s only a matter of time until someone finds out
slide-25
SLIDE 25

In order to achieve security, we must: Be able to eliminate bugs and design flaws
 and/or make them harder to exploit. Be able to think like attackers. Develop a foundation for deeply understanding
 the systems we use and build. Software Hardware Protocols Users Economics Law

The Goals of CMSC 414

slide-26
SLIDE 26

Software security

  • Security is a form of dependability
  • Does the code do “what it should”
  • To this end, we follow the software lifecycle
  • Distinguishing factor: an active, malicious attacker
  • Attack model
  • The developer is trusted
  • But the attacker can provide any inputs
  • Malformed strings
  • Malformed packets
  • etc.

What harm could an attacker possibly cause?

slide-27
SLIDE 27

screensaver --prompt=“Don’t unlock plz” Don't unlock plz press ctrl-c to logout Locked by dml

slide-28
SLIDE 28

screensaver --prompt=“Don’t unlock pretty plz” Don't unlock pretty
 plz press ctrl-c to logout Locked by dml

slide-29
SLIDE 29

screensaver --prompt=“Don’t unlock plz␠␠␠\
 ␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠” Don't unlock plz Locked by dml press ctrl-c to logout

slide-30
SLIDE 30

screensaver —prompt=“Under maintenance;\
 Do not interrupt␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠\
 ␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠␠” Under maintenance; Do not interrupt Locked by dml press ctrl-c to logout

slide-31
SLIDE 31

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document
slide-32
SLIDE 32

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document

Network communication

  • emails
  • various protocols
slide-33
SLIDE 33

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document

Network communication

  • emails
  • various protocols

Sensing the outside world

  • QR codes (to link w/ malware)
  • sound recordings
slide-34
SLIDE 34

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document

Network communication

  • emails
  • various protocols

Sensing the outside world

  • QR codes (to link w/ malware)
  • sound recordings

Third-party libraries

slide-35
SLIDE 35

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document

Network communication

  • emails
  • various protocols

Sensing the outside world

  • QR codes (to link w/ malware)
  • sound recordings

Third-party libraries Future code updates

slide-36
SLIDE 36

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document

Network communication

  • emails
  • various protocols

Sensing the outside world

  • QR codes (to link w/ malware)
  • sound recordings

Third-party libraries Goal: Correct operation despite malicious inputs Future code updates

slide-37
SLIDE 37

Most (interesting) software takes input

Target
 host (victim) Direct user interaction

  • command line interface (stdin)
  • user opens a document

Network communication

  • emails
  • various protocols

Sensing the outside world

  • QR codes (to link w/ malware)
  • sound recordings

Third-party libraries Goal: Correct operation despite malicious inputs Future code updates Others…

slide-38
SLIDE 38

We’re going to focus on C

http://www.tiobe.com

C is consistently in wide use

slide-39
SLIDE 39

We’re going to focus on C

  • Most kernels & OS utilities
  • fingerd
  • X windows server
  • Many high-performance servers
  • Microsoft IIS
  • Microsoft SQL server
  • Many embedded systems
  • Mars rover
  • But the techniques apply more broadly
  • Wiibrew:“Twilight Hack” exploits buffer overflow when saving the

name of Link’s horse, Epona

Many mission critical systems are written in C

slide-40
SLIDE 40

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 1999 2000 2001 2002 2003

  • Morris worm
  • Propagated across machines (too aggressively, thanks to a bug)
  • One way it propagated was a buffer overflow attack against a

vulnerable version of fingerd on VAXes

  • Sent a special string to the finger daemon, which caused it to

execute code that created a new worm copy

  • Didn’t check OS: caused Suns running BSD to crash
  • End result: $10-100M in damages, probation, community service
slide-41
SLIDE 41

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 1999 2000 2001 2002 2003

  • Morris worm
  • Propagated across machines (too aggressively, thanks to a bug)
  • One way it propagated was a buffer overflow attack against a

vulnerable version of fingerd on VAXes

  • Sent a special string to the finger daemon, which caused it to

execute code that created a new worm copy

  • Didn’t check OS: caused Suns running BSD to crash
  • End result: $10-100M in damages, probation, community service

(Robert Morris is now a professor at MIT)

slide-42
SLIDE 42

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 1999 2000 2001 2002 2003

  • CodeRed
  • Exploited an overflow in the MS-IIS server
  • 300,000 machines infected in 14 hours
slide-43
SLIDE 43

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 1999 2000 2001 2002 2003

  • CodeRed
  • Exploited an overflow in the MS-IIS server
  • 300,000 machines infected in 14 hours
slide-44
SLIDE 44

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 1999 2000 2001 2002 2003

  • SQL Slammer
  • Exploited an overflow in the MS-SQL server
  • 75,000 machines infected in 10 minutes
slide-45
SLIDE 45

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 2008 2009 2010 2011 2012

  • Conficker worm
  • Exploited an overflow in Windows RPC
  • ~10 million machines infected
slide-46
SLIDE 46

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 2008 2009 2010 2011 2012

  • Stuxnet
  • Exploited several overflows nobody had at the time known

about (“zero-day”)

  • Windows print spooler service
  • Windows LNK shortcut display
  • Windows task scheduler
  • Also exploited the same Windows RPC overflow as Conficker
  • Impact: legitimized cyber warfare (more on this later)
slide-47
SLIDE 47

We’re going to focus on C

A breeding ground for buffer overflow attacks 1988 2008 2009 2010 2011 2012

  • Flame
  • Same print spooler and LNK overflows as Stuxnet
  • Cyber-espionage virus
slide-48
SLIDE 48
slide-49
SLIDE 49
slide-50
SLIDE 50

GHOST: glibc vulnerability introduced in 2000,


  • nly just announced last year
slide-51
SLIDE 51

syslogd bug in Mac OS X & iOS

  • syslog: message logging infrastructure
  • Useful: one process issues the log messages,

syslogd handles storing/disseminating them

slide-52
SLIDE 52

syslogd bug in Mac OS X & iOS

  • syslog: message logging infrastructure
  • Useful: one process issues the log messages,

syslogd handles storing/disseminating them

slide-53
SLIDE 53
slide-54
SLIDE 54

Array of int’s

slide-55
SLIDE 55

Had this many int’s Array of int’s

slide-56
SLIDE 56

Want this many int’s Array of int’s

slide-57
SLIDE 57

Want this many int’s Takes bytes as 2nd arg Array of int’s

slide-58
SLIDE 58

Want this many int’s How many bytes should global.lockdown_session_fds be? Takes bytes as 2nd arg Array of int’s

slide-59
SLIDE 59

Want this many int’s How many bytes should global.lockdown_session_fds be? Takes bytes as 2nd arg Array of int’s

global.lockdown_session_count + 1 * sizeof(int)

slide-60
SLIDE 60

Want this many int’s How many bytes should global.lockdown_session_fds be? Takes bytes as 2nd arg Array of int’s

(global.lockdown_session_count + 1) * sizeof(int) global.lockdown_session_count + 1 * sizeof(int)

slide-61
SLIDE 61

syslogd bug in Mac OS X & iOS

  • syslog: message logging infrastructure
  • Useful: one process issues the log messages,

syslogd handles storing/disseminating them

Buffer
 too small

slide-62
SLIDE 62

syslogd bug in Mac OS X & iOS

  • syslog: message logging infrastructure
  • Useful: one process issues the log messages,

syslogd handles storing/disseminating them

Buffer
 too small Writes
 beyond 
 the buffer

slide-63
SLIDE 63

Buffer overflows are prevalent

4 8 12 16 1997 1999 2001 2003 2005 2007 2009 2011 2013 2015

Significant percent of all vulnerabilities

Data from the National Vulnerability Database

slide-64
SLIDE 64

Buffer overflows are prevalent

250 500 750 1000 1997 1999 2001 2003 2005 2007 2009 2011 2013 2015

Total number of buffer overflow vulnerabilities

Data from the National Vulnerability Database

slide-65
SLIDE 65

This class

Buffer overflows are impactful

MITRE's top-25 most dangerous software errors (from 2011)

slide-66
SLIDE 66

This class

E-voting

Buffer overflows are impactful

MITRE's top-25 most dangerous software errors (from 2011)

slide-67
SLIDE 67

This class

E-voting Later Later Later

Buffer overflows are impactful

MITRE's top-25 most dangerous software errors (from 2011)

slide-68
SLIDE 68

Our goals

  • Understand how these attacks work, and how to

defend against them

  • These require knowledge about:
  • The compiler
  • The OS
  • The architecture

Analyzing security requires a whole-systems view

slide-69
SLIDE 69

Memory layout

slide-70
SLIDE 70

Refresher

  • How is program data laid out in memory?
  • What does the stack look like?
  • What effect does calling (and returning from) a

function have on memory?

  • We are focusing on the Linux process model
  • Similar to other operating systems
slide-71
SLIDE 71

All programs are stored in memory

4G

slide-72
SLIDE 72

All programs are stored in memory

4G 0xffffffff 0x00000000

slide-73
SLIDE 73

All programs are stored in memory

4G 0xffffffff 0x00000000 The process’s view

  • f memory is that

it owns all of it

slide-74
SLIDE 74

All programs are stored in memory

4G 0xffffffff 0x00000000 The process’s view

  • f memory is that

it owns all of it In reality, these are virtual addresses; the OS/CPU map them to physical addresses

slide-75
SLIDE 75

The instructions themselves are in memory

Text

4G 0xffffffff 0x00000000

slide-76
SLIDE 76

The instructions themselves are in memory

Text

4G 0xffffffff 0x00000000

0x4bf mov %esp,%ebp 0x4be push %ebp 0x4c1 push %ecx 0x4c2 sub $0x224,%esp ... ...

slide-77
SLIDE 77

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

slide-78
SLIDE 78

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

Init’d data

static const int y=10;

slide-79
SLIDE 79

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

Uninit’d data

static int x;

Init’d data

static const int y=10;

slide-80
SLIDE 80

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

Uninit’d data

static int x;

Init’d data

static const int y=10;

Known at compile time

slide-81
SLIDE 81

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

cmdline & env Uninit’d data

static int x;

Init’d data

static const int y=10;

Known at compile time

slide-82
SLIDE 82

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

cmdline & env Uninit’d data

static int x;

Init’d data

static const int y=10;

Known at compile time Set when
 process starts

slide-83
SLIDE 83

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

cmdline & env Uninit’d data

static int x;

Init’d data

static const int y=10;

Known at compile time Set when
 process starts

Stack

int f() {
 int x; …

slide-84
SLIDE 84

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

cmdline & env Uninit’d data

static int x;

Init’d data

static const int y=10;

Known at compile time Set when
 process starts

Heap

malloc(sizeof(long));

Stack

int f() {
 int x; …

slide-85
SLIDE 85

Data’s location depends on how it’s created

Text

4G 0xffffffff 0x00000000

cmdline & env Uninit’d data

static int x;

Init’d data

static const int y=10;

Runtime Known at compile time Set when
 process starts

Heap

malloc(sizeof(long));

Stack

int f() {
 int x; …

slide-86
SLIDE 86

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

Heap

0xffffffff 0x00000000

Stack

slide-87
SLIDE 87

We are going to focus on runtime attacks

Stack and heap grow in opposite directions Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

slide-88
SLIDE 88

We are going to focus on runtime attacks

Stack and heap grow in opposite directions Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

slide-89
SLIDE 89

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

slide-90
SLIDE 90

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

slide-91
SLIDE 91

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

slide-92
SLIDE 92

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1

slide-93
SLIDE 93

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1

slide-94
SLIDE 94

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2

slide-95
SLIDE 95

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2

slide-96
SLIDE 96

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2 3

slide-97
SLIDE 97

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2 3

return

slide-98
SLIDE 98

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2 3

return

slide-99
SLIDE 99

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2 3

return

{

apportioned by the OS; managed in-process by malloc

slide-100
SLIDE 100

We are going to focus on runtime attacks

Stack and heap grow in opposite directions

push 1
 push 2
 push 3

Compiler provides instructions that
 adjusts the size of the stack at runtime

Heap

0xffffffff 0x00000000

Stack

Stack pointer

1 2 3

return

{

apportioned by the OS; managed in-process by malloc

Focusing on the stack for now

slide-101
SLIDE 101

Stack layout when calling functions

  • What do we do when we call a function?
  • What data need to be stored?
  • Where do they go?
  • How do we return from a function?
  • What data need to be restored?
  • Where do they come from?

Code examples (see ~/UMD/examples/ in the VM)

slide-102
SLIDE 102

Stack layout when calling functions

0xffffffff 0x00000000

caller’s data

void func(char *arg1, int arg2, int arg3) { char loc1[4] int loc2; int loc3; }

slide-103
SLIDE 103

Stack layout when calling functions

0xffffffff 0x00000000

caller’s data arg3 arg2 arg1

Arguments
 pushed in
 reverse order

  • f code

void func(char *arg1, int arg2, int arg3) { char loc1[4] int loc2; int loc3; }

slide-104
SLIDE 104

Stack layout when calling functions

0xffffffff 0x00000000

caller’s data arg3 arg2 arg1 loc1 loc2 …

Arguments
 pushed in
 reverse order

  • f code

Local variables
 pushed in the same order as they appear
 in the code

void func(char *arg1, int arg2, int arg3) { char loc1[4] int loc2; int loc3; }

slide-105
SLIDE 105

Stack layout when calling functions

0xffffffff 0x00000000

caller’s data arg3 arg2 arg1 ??? ??? loc1 loc2 …

Arguments
 pushed in
 reverse order

  • f code

Local variables
 pushed in the same order as they appear
 in the code

void func(char *arg1, int arg2, int arg3) { char loc1[4] int loc2; int loc3; }

slide-106
SLIDE 106

Stack layout when calling functions

0xffffffff 0x00000000

caller’s data arg3 arg2 arg1 ??? ??? loc1 loc2 …

Arguments
 pushed in
 reverse order

  • f code

Local variables
 pushed in the same order as they appear
 in the code

void func(char *arg1, int arg2, int arg3) { char loc1[4] int loc2; int loc3; }

Two values between the arguments
 and the local variables

slide-107
SLIDE 107

Stack layout when calling functions

0xffffffff 0x00000000

caller’s data arg3 arg2 arg1 ??? ??? loc1 loc2 …

Arguments
 pushed in
 reverse order

  • f code

Local variables
 pushed in the same order as they appear
 in the code

void func(char *arg1, int arg2, int arg3) { char loc1[4] int loc2; int loc3; }

Two values between the arguments
 and the local variables We will explore (and attack
 and defend) them next time.