Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro_Exp_post.pdf

lukesun629
November 21, 2012
9.2k

 Intro_Exp_post.pdf

lukesun629

November 21, 2012
Tweet

Transcript

  1. Basic Goals • Exploit basic buffer overflow by yourself –

    Understand basic memory vulnerabilities – Basic use of gdb – Basic use of shellcode
  2. ELF Format • Executable and Linkable Format • 3 main

    types of object files – relocatable file: gcc –c test.c => test.o(test.a) – executable file: gcc –o test test.c => test – shared object file: test.so • Parallel views – Linking View – Execution View
  3. About Stack • Region of memory managed with stack discipline

    • Grows toward lower addresses • Register %esp indicates lowest stack address – address of top element • Stack Operations – pushl -> %esp+4 – popl -> %esp-4 byte byte … byte byte %esp Stack Top Stack Bottom
  4. Memory Layout(Linux X86) • Stack • Shared Libraries • Heap

    • Data(Global/Static) • Text For Kernal Stack shared libraries Heap Data Text Unused 0xC0000000 0x40000000 0x00000000 0x08048000 0xFFFFFFFF %esp
  5. Stack Frame arguments return address stack frame pointer [exception handlers]

    local variables callee saved registers For Kernal Stack shared libraries Heap Data Text Unused 0xC0000000 0x40000000 0x00000000 0x08048000 0xFFFFFFFF %ebp previous stack frame pointer %esp
  6. GDB • Starting GDB – gdb program + run [arglist]

    – gdb –args program [arglist] + run – attach pid • Stopping GDB – quit – Ctrl-d
  7. GDB • Breakpoints and Watchpoints – break function – break

    *addr – info break – clear function – delete/enable/disable [n] – watch expr – info watch
  8. GDB • Display – print [/f] expr • x hex

    • d signed decimal • u unsigned decimal • o octal • t binary • a address • c character • f floating point – info reg [rn]
  9. GDB • Display – x [/Nuf] expr • N count

    of units to display • u unit size – b bytes – h halfwords (two bytes) – w words (four bytes) – g giant words (eight bytes) • f printing format – s null-terminated string – i machine instructions – disassem [addr]
  10. GDB • demo – view arguments and environment variables –

    view stack structure – insert breakpoints and control execution
  11. Buffer Overflow Exploit char **argv int argc evil code address

    evil code evil code Contruct evil buffer: buf = evil_code + evil_code_address
  12. Buffer Overflow Exploit evil code evil code evil code address

    Useless buf Useless buf Contruct evil buffer: buf = evil_code + evil_code_address
  13. Shellcode • What is shellcode – A small piece of

    code used as the payload in the exploitation of a software vulnerability – Typically it starts a command shell from which the attacker can control the compromised machine • What we use here – We use execve system call to obtain a high- permission level shell
  14. Shellcode 0 //sh /bin 0 string syscall calling convention %eax=0xb

    %ebx=filename %ecx=argv %edx=envp %esi %edi %ebp %esp "/bin//sh" CLTD converts signed long word EAX to double word EDX:EAX int execve(const char *filename, char *const argv[], char *const envp[]);
  15. Exploit • Construct Attacking Buffer – buf = NOP+SHELLCODE+RET_ADDRESS •

    How to find return address – debuging – pattern_tool.py from metasploit • “Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3 Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7A c8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1A e2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2A”
  16. Practice 1 • ssh –p2222 111.111.111.111 • password: bl******* •

    capture the level05.flag • ./level05 $(python –c ‘print “\x90”* 50 + “\x31….\x80”+”\x90”*n+”\xff\xff\xff\xbf”*m’)
  17. More Vulnerabilities • Heap Overflow • Integer Overflow • Format

    String • Heap Spray We Need Your Presentations!
  18. Platform Defenses and More Exploitations • DEP/W^X – Return-to-libc/Return Oriented

    Programing (ROP) • ASLR – jmp esp/ret2ret/… Call For Presentations!
  19. How to learn • CTFs • Wargames – io smash

    the stack – exploit-excercises.com • Presentations • Open Courses