CMSC 414 Computer and Network Security Lecture 21 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

CMSC 414 Computer and Network Security Lecture 21

Description:

CMSC 414 Computer and Network Security Lecture 21 Jonathan Katz – PowerPoint PPT presentation

Number of Views:81
Avg rating:3.0/5.0
Slides: 19
Provided by: jkatz
Learn more at: http://www.cs.umd.edu
Category:

less

Transcript and Presenter's Notes

Title: CMSC 414 Computer and Network Security Lecture 21


1
CMSC 414Computer and Network SecurityLecture 21
  • Jonathan Katz

2
Examples using gdb
3
Even more devious
buf
EBP
EIP
overflow
Frame of the calling function
In the overflow, a pointer back into the buffer
appears in the location where the system expects
to find return address
Attacker puts actual assembly instructions into
his input string, e.g., binary code of
execve(/bin/sh)
4
NOP sled
  • If exact address of injected shellcode is
    unknown, use NOP sled to provide a margin of error

5
Severity of attack?
  • Theoretically, attacker can cause machine to
    execute arbitrary code with the permissions of
    the program itself

6
Heap overflows
  • The examples just described all involved
    overflowing the stack
  • Also possible to overflow buffers on the heap
  • More difficult to get arbitrary code to execute,
    but imagine the effects of overwriting
  • Passwords
  • Usernames
  • Filenames
  • Variables
  • Function pointers (possible to execute arbitrary
    code)

7
Defenses
8
Defenses (overview)
  • Prevent overflows from existing
  • Safe programming techniques/languages
  • Input validation
  • Static/dynamic analysis
  • Prevent overflows from being exploited
  • Intercept function calls (e.g., Libsafe)
  • Canaries (StackGuard)
  • Non-executable stack, data execution prevention
    (DEP)
  • Address space layout randomization/ASLR

Development/ compile time
compile time
O/S
9
Safe programming techniques
  • Use arrays instead of pointers
  • Make buffers (slightly) longer than necessary to
    avoid off-by-one errors

10
Safe programming techniques
  • We have seen that strcpy is unsafe
  • strcpy(buf, str) simply copies memory contents
    into buf starting from str until \0 is
    encountered, ignoring the size of buf
  • Avoid strcpy(), strcat(), gets(), etc.
  • Use strncpy(), strncat(), instead
  • Even these are not perfect (e.g., no null
    termination)
  • Still need to be careful when copying multiple
    inputs into a buffer

11
Safe programming languages
  • E.g., using Java prevents many of the problems
    that arise when using C
  • C variants have been developed that ensure that
    certain classes of overflows cannot occur
  • E.g., Cyclone

12
Input validation
  • (This is a general issue, not just in the context
    of buffer overflows)
  • Two approaches
  • Whitelisting
  • Allow input that matches up with approved
    whitelist
  • Blacklisting
  • Discard input that matches up with disallowed
    blacklist
  • The usual tradeoffs between usability/complexity
    and security

13
Length checking
  • Beware off-by-one errors
  • Even when using strncpy, the programmer must use
    the right value for the number of bytes to copy

strncpy(record,user,MAX_STRING_LEN-1)
strcat(record,) strncat(record,fnam
e,MAX_STRING_LEN-1)
14
Input validation
  • Blacklisting can often be easily circumvented
  • E.g., checking for a NOP sled
  • Replace NOP with a sequence of instructions whose
    net effect is to do nothing (inc eax, dec eax, )
  • Whitelisting can be more difficult to bypass
  • E.g., checking for printable ASCII
  • There are legal instructions that fall in this
    range!

15
ASCII printable instructions
  • (Partial list)
  • AND EAX
  • SUB EAX
  • PUSH EAX
  • POP EAX
  • PUSH ESP
  • POP ESP

16
What can be done?
  • AND EAX val1, AND EAX val2
  • If val1, val2 are ASCII-printable strings that
    are complements of each other, this zeros EAX
  • SUB EAX v1, SUB EAX v2, SUB EAX v3
  • If v1, v2, v3 ASCII-printable strings chosen
    appropriately, wrap around occurs and the net
    effect is an addition
  • PUSH EAX, POP ESP
  • Copies EAX into ESP

17
What can be done?
  • In principle, could build exploit using these
    instructions (very hard)
  • Alternative inject loader code that generates
    shellcode on the stack

18
EIP
loadercode
increasingaddresses
ESP
stack
Build shellcode on the stack. What happens when
the EIP and ESP meet?
Write a Comment
User Comments (0)
About PowerShow.com