University ¡of ¡Washington ¡
Today ¡
¢ Memory ¡layout ¡ ¢ Buffer ¡overflow, ¡worms, ¡and ¡viruses ¡
1 ¡
Today Memory layout Buffer overflow, worms, and viruses - - PowerPoint PPT Presentation
University of Washington Today Memory layout Buffer overflow, worms, and viruses 1 University of Washington not drawn to scale IA32 Linux Memory
University ¡of ¡Washington ¡
¢ Memory ¡layout ¡ ¢ Buffer ¡overflow, ¡worms, ¡and ¡viruses ¡
1 ¡
University ¡of ¡Washington ¡
¢ Stack ¡
¢ Heap ¡
¢ Data ¡
¢ Text ¡
2 ¡
University ¡of ¡Washington ¡
3 ¡
University ¡of ¡Washington ¡
4 ¡
University ¡of ¡Washington ¡
¢ November, ¡1988 ¡
5 ¡
University ¡of ¡Washington ¡
¢ November, ¡1988 ¡
¢ The ¡Internet ¡Worm ¡was ¡based ¡on ¡stack ¡buffer ¡overflow ¡
§ many ¡Unix ¡func$ons ¡do ¡not ¡check ¡argument ¡sizes ¡ § allows ¡target ¡buffers ¡to ¡overflow ¡
6 ¡
University ¡of ¡Washington ¡
¢ ImplementaJon ¡of ¡Unix ¡funcJon ¡gets()
7 ¡
University ¡of ¡Washington ¡
¢ ImplementaJon ¡of ¡Unix ¡funcJon ¡gets()
¢ Similar ¡problems ¡with ¡other ¡Unix ¡funcJons ¡
8 ¡
University ¡of ¡Washington ¡
int main() { printf("Type a string:"); echo(); return 0; } /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf); } unix>./bufdemo Type a string:1234567 1234567 unix>./bufdemo Type a string:12345678 Segmentation Fault unix>./bufdemo Type a string:123456789ABC Segmentation Fault
9 ¡
University ¡of ¡Washington ¡
10 ¡
University ¡of ¡Washington ¡
echo: pushl %ebp # Save %ebp on stack movl %esp, %ebp pushl %ebx # Save %ebx leal -8(%ebp),%ebx # Compute buf as %ebp-8 subl $20, %esp # Allocate stack space movl %ebx, (%esp) # Push buf addr on stack call gets # Call gets . . . /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf); }
11 ¡
University ¡of ¡Washington ¡
12 ¡
University ¡of ¡Washington ¡
13 ¡
University ¡of ¡Washington ¡
14 ¡
. . . 804850a: 83 c4 14 add $0x14,%esp # deallocate space 804850d: 5b pop %ebx # restore %ebx 804850e: c9 leave # movl %ebp, %esp; popl %ebp 804850f: c3 ret # Return
University ¡of ¡Washington ¡
15 ¡
80485f2: call 80484f0 <echo> 80485f7: mov 0xfffffffc(%ebp),%ebx # Return Point
University ¡of ¡Washington ¡
16 ¡
¢ Input ¡string ¡contains ¡byte ¡representaJon ¡of ¡executable ¡code ¡ ¢ Stack ¡frame ¡must ¡be ¡big ¡enough ¡to ¡hold ¡exploit ¡code ¡ ¢ Overwrite ¡return ¡address ¡with ¡address ¡of ¡buffer ¡(need ¡to ¡know ¡B) ¡ ¢ When ¡bar() ¡executes ret, ¡will ¡jump ¡to ¡exploit ¡code ¡(instead ¡of ¡A) ¡
University ¡of ¡Washington ¡
¢ Buffer ¡overflow ¡bugs ¡allow ¡remote ¡machines ¡to ¡execute ¡
¢ Internet ¡worm ¡
§ finger droh@cs.cmu.edu
§ finger “exploit-code padding new-return-
§ exploit ¡code: ¡executed ¡a ¡root ¡shell ¡on ¡the ¡vic$m ¡machine ¡with ¡a ¡
17 ¡
University ¡of ¡Washington ¡
¢ History ¡
18 ¡
University ¡of ¡Washington ¡
¢ Starts ¡100 ¡threads ¡running ¡ ¢ Spread ¡self ¡
¢ A^ack ¡www.whitehouse.gov ¡
§ Denial ¡of ¡service ¡aJack ¡
¢ Deface ¡server’s ¡home ¡page ¡
¢ Later ¡versions ¡even ¡more ¡
¢ And ¡it ¡goes ¡on ¡sJll… ¡
19 ¡
University ¡of ¡Washington ¡
¢ Use ¡library ¡rouJnes ¡that ¡limit ¡string ¡lengths ¡
§ Use ¡fgets ¡to ¡read ¡the ¡string ¡ § Or ¡use ¡%ns ¡ ¡where ¡n ¡is ¡a ¡suitable ¡integer ¡
20 ¡
University ¡of ¡Washington ¡
¢ Randomized ¡stack ¡offsets ¡
¢ Nonexecutable ¡code ¡segments ¡
21 ¡
University ¡of ¡Washington ¡
¢ Worm: ¡A ¡program ¡that ¡
¢ Virus: ¡Code ¡that ¡
¢ Both ¡are ¡(usually) ¡designed ¡to ¡spread ¡among ¡computers ¡and ¡
22 ¡