cs642 computer security
play

CS642: Computer Security Drew Davidson - PowerPoint PPT Presentation

X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Week ACL-based permissions (UNIX style)


  1. X86 ¡Review ¡ Process ¡Layout, ¡ISA, ¡etc. ¡ CS642: ¡ Computer ¡Security ¡ Drew ¡Davidson ¡ davidson@cs.wisc.edu ¡

  2. From ¡Last ¡Week ¡ • ACL-­‑based ¡permissions ¡(UNIX ¡style) ¡ – Read, ¡Write, ¡eXecute ¡can ¡be ¡restricted ¡on ¡users ¡ and ¡groups ¡ – Processes ¡(usually) ¡run ¡with ¡the ¡permissions ¡of ¡ the ¡invoking ¡user ¡ • Example: ¡ ¡ write ¡ passwd ¡ /etc/shadow ¡ RUID: ¡ EUID: ¡ rist ¡ root ¡

  3. Processes ¡are ¡the ¡front ¡line ¡of ¡system ¡ security ¡ • Control ¡a ¡process ¡and ¡you ¡get ¡the ¡privileges ¡of ¡ its ¡UID ¡ • So ¡how ¡do ¡you ¡control ¡a ¡process? ¡ – Send ¡specially ¡formed ¡input ¡to ¡process ¡ write ¡ input ¡ passwd ¡ /etc/shadow ¡ RUID: ¡ EUID: ¡ rist ¡ root ¡

  4. Roadmap ¡ • Today ¡ – Enough ¡x86 ¡to ¡understand ¡(some) ¡process ¡ vulnerabiliUes ¡ • Next ¡Time ¡ – Live ¡demo ¡of ¡an ¡aVack ¡ – How ¡such ¡aVacks ¡occur ¡

  5. Why ¡do ¡we ¡need ¡to ¡look ¡at ¡assembly? ¡ “WYSINWYX: ¡What ¡you ¡see ¡is ¡not ¡what ¡you ¡eXecute” ¡ [Balakrishnan ¡and ¡Reps ¡TOPLAS ¡2010] ¡ VulnerabiliUes ¡exploited ¡in ¡this ¡form ¡ pushl %ebp We ¡understand ¡code ¡in ¡this ¡form ¡ movl %esp, %ebp subl $16, %esp int foo(){ movl $0, -4(%ebp) int a = 0; Compiler ¡ movl -4(%ebp), %eax return a + 7; addl $7, %eax } leave ret

  6. x86: ¡Popular ¡but ¡crazy ¡ • CISC ¡(complex ¡instrucUon ¡set ¡compuUng) ¡ – Over ¡100 ¡disUnct ¡opcodes ¡in ¡the ¡set ¡ • Register ¡poor ¡ – Only ¡8 ¡registers ¡of ¡32-­‑bits, ¡only ¡6 ¡are ¡general-­‑ purpose ¡ • Variable-­‑length ¡instrucUons ¡ • Built ¡of ¡many ¡backwards-­‑compaUble ¡revisions ¡ – Many ¡security ¡problems ¡preventable… ¡in ¡ hindsight ¡

  7. A ¡LiVle ¡History ¡ Intel ¡aVempts ¡to ¡trademark ¡ the ¡number ¡486, ¡gets ¡denied ¡ 2003 ¡ 1978 ¡ 1982 ¡ 1985 ¡ 1989 ¡ 1993 ¡ 1995 ¡ … ¡ “5” ¡ ¡ ? y -­‑ e c n e i c S

  8. Process ¡memory ¡layout ¡ unused ¡ .text ¡ .data ¡ .bss ¡ heap ¡ stack ¡ Env ¡ Low ¡memory ¡ ¡ High ¡memory ¡ ¡ Grows ¡downward ¡ Grows ¡upward ¡ addresses ¡ addresses ¡ .text ¡ heap ¡ – Machine ¡code ¡of ¡ – Dynamic ¡variables ¡ executable ¡ stack ¡ .data ¡ – Local ¡variables ¡ – Global ¡iniUalized ¡variables ¡ – FuncUon ¡call ¡data ¡ .bss ¡ Env ¡ – Below ¡Stack ¡SecUon ¡ – Environment ¡variables ¡ ¡ ¡ ¡global ¡uniniUalized ¡ – Program ¡arguments ¡ variables ¡

  9. Registers ¡ 32 ¡bits ¡ EAX ¡ AX ¡ AH ¡ AL ¡ EBX ¡ BX ¡ BH ¡ BL ¡ ECX ¡ CX ¡ CH ¡ CL ¡ EDX ¡ DX ¡ DH ¡ DL ¡ ESI ¡ EDI ¡ ESP ¡ (stack ¡pointer) ¡ EBP ¡ (base ¡pointer) ¡

  10. InstrucUon ¡Syntax ¡ • InstrucUon ¡ends ¡with ¡ Examples: ¡ data ¡length ¡ • opcode, ¡src, ¡dst ¡ subl ¡$16, ¡%ebx ¡ • Constants ¡preceded ¡ by ¡$ ¡ movl ¡(%eax), ¡%ebx ¡ • Registers ¡preceded ¡by ¡ % ¡ • IndirecUon ¡uses ¡( ¡) ¡ ¡

  11. Register ¡InstrucUons: ¡sub ¡ registers ¡ • Subtract ¡from ¡a ¡ %eax ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebx ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ 7 ¡ 9 ¡ 7 ¡ register ¡value ¡ memory ¡ subl ¡%eax, ¡%ebx ¡

  12. The ¡Stack ¡ • Local ¡storage ¡ – Good ¡place ¡to ¡keep ¡data ¡that ¡doesn’t ¡fit ¡into ¡ registers ¡ • Grows ¡from ¡high ¡addresses ¡towards ¡low ¡ addreses ¡

  13. Frame ¡InstrucUons: ¡push ¡ registers ¡ • Put ¡a ¡value ¡on ¡the ¡ %eax ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ 7 ¡ M ¡ N ¡ stack ¡ memory ¡ – Pull ¡from ¡register ¡ pushl ¡%eax ¡ Frame ¡ – Value ¡goes ¡to ¡%esp ¡ – Subtract ¡from ¡%esp ¡ • Example: ¡ registers ¡ %eax ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ 7 ¡ M ¡ N-­‑4 ¡ ¡ pushl ¡%eax ¡ memory ¡ 7 ¡ Frame ¡

  14. Frame ¡InstrucUons: ¡pop ¡ registers ¡ • Take ¡a ¡value ¡from ¡the ¡ %eax ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ 9 ¡ M ¡ N ¡ stack ¡ memory ¡ – Pull ¡from ¡stack ¡ popl ¡%eax ¡ 7 ¡ Frame ¡ pointer ¡ – Value ¡goes ¡from ¡%esp ¡ – Add ¡to ¡%esp ¡ registers ¡ %eax ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ 7 ¡ M ¡ N+4 ¡ memory ¡ Frame ¡

  15. Control ¡flow ¡instrucUons: ¡jmp ¡ • %eip ¡points ¡to ¡the ¡ registers ¡ %eip ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ currently ¡execuUng ¡ K ¡ M ¡ N ¡ instrucUon ¡(in ¡the ¡ memory ¡ text ¡secUon) ¡ jmp ¡-­‑20 ¡ Frame ¡ • Has ¡uncondiUonal ¡ and ¡condiUonal ¡ forms ¡ registers ¡ • Uses ¡relaUve ¡ %eip ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ K-­‑20 ¡ M ¡ N ¡ addressing ¡ memory ¡ Frame ¡

  16. Control ¡flow ¡instrucUons: ¡call ¡ registers ¡ %eip ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %ebp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ %esp ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ K ¡ M ¡ N ¡ • Saves ¡the ¡current ¡ instrucUon ¡pointer ¡ memory ¡ to ¡the ¡stack ¡ A: ¡call ¡FOO ¡ Frame ¡ • Jumps ¡to ¡the ¡ argument ¡value ¡ registers ¡ %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 (foo) ¡ ebp ¡ eip+2 ¡ data ¡ ebp ¡ ebp ¡ main: ¡ foo: ¡ ¡ ¡ ¡… ¡ ¡ ¡ ¡pushl ¡ ¡ ¡%ebp ¡ eip ¡ eip ¡ eip ¡ ¡ ¡ ¡subl ¡ ¡ ¡ ¡$8, ¡%esp ¡ ¡ ¡ ¡movl ¡ ¡ ¡ ¡%esp, ¡%ebp ¡ eip ¡ eip ¡ ¡ ¡ ¡movl ¡ ¡ ¡ ¡$2, ¡4(%esp) ¡ ¡ ¡ ¡subl ¡ ¡ ¡ ¡$16, ¡%esp ¡ eip ¡ eip ¡ ¡ ¡ ¡movl ¡ ¡ ¡ ¡$l, ¡(%esp) ¡ ¡ ¡ ¡movl ¡ ¡ ¡ ¡$3, ¡-­‑4(%ebp) ¡ eip ¡ eip ¡ ¡ ¡ ¡call ¡ ¡ ¡ ¡foo ¡ ¡ ¡ ¡movl ¡ ¡ ¡ ¡8(%ebp), ¡%eax ¡ eip ¡ eip ¡ ¡ ¡ ¡addl ¡ ¡ ¡ ¡$8, ¡%esp ¡ ¡ ¡ ¡addl ¡ ¡ ¡ ¡$9, ¡%eax ¡ eip ¡ ¡ ¡ ¡… ¡ ¡ ¡ ¡leave ¡ eip ¡ ¡ ¡ ¡ ¡ret ¡ ¡ ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend