15
Buffer Overflows Lesson 14

Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Embed Size (px)

Citation preview

Page 1: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Buffer Overflows

Lesson 14

Page 2: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Example of poor programming/errors

• Buffer Overflows• result of poor programming practice

• use of functions such as gets and strcpy– these don’t check input for boundaries

• may allow individual to gain root or admin access

• Easy to do in any programming language…what is the real problem?

Page 3: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

What is a buffer overflow?

• “A buffer overflow attack is when an attacker tries to store too much information in an undersized receptacle.”

• “A common implementation is when a user of the program gives the program more data than the developers of the program allocated to store it.”

Page 4: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Exploits

• Buffer Overflows• fingerd, statd, talkd, …• result of poor programming practice

• Shell Escapes• special character in input string causes escape to

shell

Page 5: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Buffer Overflow Example

#include <stdio.h>#include <string.h>

void func(char *p){ char stack_temp[20]; strcpy(stack_temp, p); printf(stack_temp);}

int main(int argc, char* argv[]){ func(“I AM MORE THAN TWENTY CHARACTERS LONG!”); return 0;}

Page 6: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Buffer Overflows

Program

Execute A

Return

Subroutine A

Read Variable

Data

Process Stack

Return Addr

Page 7: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Buffer Overflows

Program

Execute A

Return

Subroutine A

Read Variable

Data

Process Stack

Return AddrNew Addr

Another Routine

Page 8: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Buffer Overflows

Program

Execute A

Return

Subroutine A

Read Variable

Data

Process Stack

Return AddrNew Addr

Machine Code

Page 9: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Types of buffer overflow attacks

• Denial of service – buffer overflow will cause the system to “crash”• Since important information needed by the OS to

continue running can be located on the stack, by overflowing with enough data you can wipe out this important information.

• Execution of code that the attacker chooses to run.• Overwrite just the right amount of information to

overflow the stack and rewrite the return address pointer.

• Do this right and you can point to your own code.

Page 10: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Buffer Overflows (cont)

• “A key point to remember is that the attacker’s code will run at whatever privileges the software that is exploited is running at.”

• “In most cases, an attacker tries to exploit programs that are running as a privileged account such as root or domain administrator.”

Page 11: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Protection against buffer overflow attacks

• Close the port or service• Best way to protect yourself is to remove SW that is

subject to an overflow.• If this SW is installed by default, close ports and

remove service.

• Rule of thumb: “Know what is installed on your systems and have the least amount of services running and ports open that are required for the system to operate in a specific environment.”

Page 12: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Protection

• Apply the vendor’s patch or install the latest version of the software.• Usually shortly after a buffer overflow

vulnerability is discovered the vendor will develop and release a patch.

• This fixes the problem as opposed to just minimizing exposure.

Page 13: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Protection

• Filter specific traffic at the firewall.• Block the traffic of the vulnerable software at

the firewall.• This will restrict the ability of external attackers

to exploit the vulnerability.• Does not prevent an insider from exploiting the

vulnerability, just limits the exposure.

Page 14: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Prevention

• Test key applications.• Take a proactive approach and attempt to find

buffer overflow exploits yourself.• Not practical for all applications but for key ones it

is.

Page 15: Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and

Prevention

• Run Software at the Least Privilege Required• Often system administrators will install and

configure applications as root. • Quick an easy to ensure they have access to what

they need.• Also easy way to guarantee system is vulnerable if

buffer overflow exploit is discovered in one of the applications since it will execute code as root.