ECS ¡153 ¡Discussion ¡Section
April ¡6, ¡2015
1
ECS 153 Discussion Section April 6, 2015 1 What Well Cover Goal : - - PowerPoint PPT Presentation
ECS 153 Discussion Section April 6, 2015 1 What Well Cover Goal : To discuss buffer overflows in detail Stack-based buffer overflows Smashing the stack: execution from the stack
1
2
3
text (instructions) data stack heap
4
return ¡address processor ¡status ¡word stack ¡grows stack ¡shrinks local ¡ variable ¡ values local ¡ variable values
5
6
main local variables return ¡address
state ¡info gets local variables parameter ¡to gets input ¡buffer main local variables address ¡of input ¡buffer
state ¡info gets local variables program ¡to invoke ¡shell program ¡to invoke ¡shell after message the ¡usual ¡stack the ¡stack ¡after ¡the ¡attack
7
8
– Need ¡to ¡get ¡alignment ¡right, ¡though
9
10
11
12
13
14
15
16
buffer ¡for ¡cleartext password ¡(80 ¡bytes) buffer ¡for hash ¡(13 ¡bytes) 0 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡79 ¡80 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ 92 store ¡hash ¡from /etc/passwd when given ¡login ¡name load ¡password ¡buffer ¡from ¡0 ¡on
17
18
19
to ¡validate ¡password
caller
20
21
22
/ e t c s e n d a m i l / . c f
23
24
malloc ¡space malloc ¡data return ¡address program goes ¡here stack
25
first malloc space malloc ¡data ¡1 malloc data ¡2 second malloc space
26
27
28
29
30
– Avoid ¡gets, ¡strcpy, ¡strcat, ¡sprintf – Use ¡fgets, ¡strncpy, ¡strncat, ¡instead; ¡no ¡standard ¡replacement ¡for ¡ sprintf (snprintf on ¡some ¡systems) – Don’t ¡forget ¡to ¡add ¡a ¡NUL ¡byte ¡at ¡the ¡end ¡of ¡arrays ¡if ¡you ¡use ¡these ¡ functions, ¡and ¡watch ¡those ¡n values!
– Checking ¡for ¡termination ¡character ¡is ¡not ¡enough
– Not ¡only ¡when ¡they ¡are ¡in ¡loops
31
32
33
34
main local variables return ¡address
state ¡info gets local variables parameter ¡to gets input ¡buffer main local variables address ¡of input ¡buffer
state ¡info gets local variables program ¡to invoke ¡shell program ¡to invoke ¡shell after message the ¡usual ¡stack the ¡stack ¡after ¡the ¡attack canary altered ¡canary
35
canary stack global ¡object table _exit ¡address buffer return ¡address altered ¡canary buffer (shell ¡code) altered ¡return ¡address Will ¡this ¡always ¡work?
36
37