Buffer Overrun Review Process Layout in Memory IA-32 - - PowerPoint PPT Presentation

buffer overrun review process layout in memory ia 32 nota
SMART_READER_LITE
LIVE PREVIEW

Buffer Overrun Review Process Layout in Memory IA-32 - - PowerPoint PPT Presentation

Buffer Overrun Review Process Layout in Memory IA-32 Nota=on Format : inst src dst registers prefixed with a %, constants with $


slide-1
SLIDE 1

Buffer ¡Overrun ¡Review ¡

slide-2
SLIDE 2

Process ¡Layout ¡in ¡Memory ¡

slide-3
SLIDE 3

IA-­‑32 ¡Nota=on ¡

  • Format ¡: ¡inst ¡src ¡dst ¡
  • registers ¡prefixed ¡with ¡a ¡‘%’, ¡constants ¡with ¡‘$’ ¡
  • (%ebx) ¡means ¡accessing ¡the ¡memory ¡address ¡stored ¡in ¡register ¡%ebx ¡
  • l ¡suffix ¡on ¡instruc=on ¡indicates ¡a ¡“long-­‑word” ¡(32-­‑bit) ¡instruc=on ¡

¡

Important ¡Registers ¡

  • %eax, ¡%ebx, ¡%ecx, ¡%edx, ¡%edi, ¡%esi ¡– ¡general ¡purpose ¡registers ¡(%eax ¡used ¡to ¡

store ¡return ¡value) ¡

  • %ebp ¡– ¡base ¡pointer. ¡Indicates ¡start ¡of ¡stack ¡frame ¡
  • %esp ¡– ¡stack ¡pointer. ¡Indicates ¡boVom ¡on ¡stack ¡
  • %eip ¡– ¡instruc=on ¡pointer. ¡Indicates ¡instruc=on ¡to ¡run ¡
slide-4
SLIDE 4

Common ¡Instruc=ons ¡

  • mov ¡a, ¡b ¡– ¡copy ¡value ¡of ¡a ¡into ¡b ¡
  • push ¡a ¡– ¡push ¡a ¡onto ¡the ¡stack ¡(decrement ¡stack, ¡copy ¡value ¡over) ¡
  • pop ¡a ¡– ¡pop ¡data ¡from ¡stack ¡into ¡a ¡(copy ¡value ¡over, ¡increment ¡stack) ¡
  • call ¡func ¡– ¡push ¡address ¡of ¡next ¡instruc=on ¡onto ¡stack ¡& ¡transfer ¡control ¡to ¡func ¡
  • ret ¡– ¡pop ¡return ¡address ¡off ¡stack ¡and ¡jump ¡to ¡it ¡
  • leave ¡– ¡syntac=c ¡sugar ¡for ¡mov ¡%ebp, ¡%esp ¡followed ¡by ¡pop ¡%ebp ¡(restores ¡prev ¡

stack ¡frame) ¡ ¡

slide-5
SLIDE 5

Func=on ¡Structure ¡

foo: ¡ ¡push ¡%ebp ¡ ¡mov ¡ ¡%esp, ¡%ebp ¡ ¡sub ¡$???, ¡ ¡%esp ¡ ¡… ¡ ¡… ¡ ¡… ¡ ¡leave ¡ ¡ret ¡ ¡ | ¡ | ¡ ¡ ¡Func=on ¡prologue ¡(creates ¡a ¡new ¡stack ¡frame) ¡ | ¡ ¡ | ¡ ¡ ¡Func=on ¡body ¡ ¡ | ¡ ¡ ¡Func=on ¡epilogue ¡(restore ¡old ¡stack ¡frame ¡& ¡ | ¡ ¡ ¡jump ¡to ¡return ¡address) ¡

slide-6
SLIDE 6

Calling ¡Conven=on ¡

foo: ¡ ¡… ¡ ¡… ¡ ¡… ¡ ¡ ¡push ¡$5 ¡ ¡push ¡$1 ¡ ¡call ¡bar ¡ ¡add ¡$8, ¡%esp ¡ ¡… ¡ ¡… ¡ ¡… ¡ Example ¡of ¡calling ¡bar(1,5) ¡ ¡ Arguments ¡pushed ¡on ¡stack ¡in ¡reverse ¡

  • rder ¡(last ¡argument ¡pushed ¡first) ¡

¡ Stack ¡restored ¡aber ¡func=on ¡call ¡end ¡ ¡ Extra: ¡Caller ¡also ¡some=mes ¡need ¡to ¡ save ¡registers, ¡but ¡don’t ¡worry ¡about ¡ this ¡too ¡much ¡

slide-7
SLIDE 7

Let’s ¡walk ¡through ¡an ¡example! ¡

  • Terminology: ¡

– SFP ¡: ¡saved ¡%ebp ¡on ¡the ¡stack ¡ – OFP ¡: ¡old ¡%ebp ¡from ¡the ¡previous ¡stack ¡frame ¡ – RIP ¡: ¡return ¡address ¡on ¡the ¡stack ¡

slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18
slide-19
SLIDE 19
slide-20
SLIDE 20
slide-21
SLIDE 21
slide-22
SLIDE 22
slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27
slide-28
SLIDE 28
slide-29
SLIDE 29
slide-30
SLIDE 30
slide-31
SLIDE 31

Buffer ¡Overflow ¡

  • C ¡is ¡not ¡memory ¡safe, ¡many ¡func=ons ¡can ¡write ¡past ¡buffers ¡ ¡

– Ex: ¡strcpy(), ¡gets(), ¡etc ¡

Return ¡Address ¡ Previous ¡Base ¡Pointer ¡ local ¡char[] ¡buffer ¡ Wri=ng ¡past ¡length ¡of ¡char[] ¡buffer ¡ will ¡begin ¡to ¡overwrite ¡things ¡on ¡the ¡stack ¡like ¡ previous ¡base ¡pointer ¡and ¡return ¡address ¡ ¡ Overwri=ng ¡return ¡address ¡can ¡allow ¡program ¡to ¡ Jump ¡to ¡wherever ¡aVacker ¡wants ¡