UP | HOME
../../

Buffer Overflow Exploits

Table of Contents

1 Abstract

A large number of exploits have been due to sloppy software development. Exceeding array bounds is referred to in security circles as "buffer overflow." These are by far the most common security problems in software. This lecture explains the stack-smashing technique, and presents a few techniques that help in avoiding the exploit.

  1. I often give 3 to 5 (55-minute) lectures on this topic.
  2. At least one on AlephOne.
  3. Lecture #1: Overview, Background, Ideas on: {Code Injection, Detection, Prevention}
  4. Lecture #2: Aleph One article, full exploration
  5. Lecture #3: Aleph One article, full exploration; past videos of mine
  6. Lecture #4: Experience the Exploit
  7. Lecture #5: Exploring recent CVEs on Buffer Overflow
  8. Coupled Topic: Software Development without Security Holes

2 Buffer Overflow Overview

  1. End result: a super-user owned shell process is born
  2. The enabling weaknesses
    1. data address space and executable code address space are not disjoint
    2. sloppy programming
  3. Intricately depends on: PL, Compiler, OS, CPU
  4. Arguably: The first security exploit (1988)
  5. Arguably: The most common exploit
  6. Arguably: The still prevalent exploit
  7. Alt names: buffer overrun, stack smashing, code injection
  8. Related exploits: heap overflow, format string exploit, …
  9. Famous Buffer Overflow Attacks: https://engineering.purdue.edu/ResearchGroups/SmashGuard/BoF.html

3 Background Knowledge

  1. Command line shells
    1. konsole + bash
    2. bash PS1 prompt
  2. Details (semantics and compiled code) of C
    1. String library methods: strcpy, strcat
    2. Array bounds
    3. Effective address calculation
    4. Stack frame
    5. ./C-intricacies.html
    6. ../LinuxSetup/StudyPrograms/
  3. OS Details
    1. System call: execv
    2. System call: exit
    3. setuserid suid root

4 Code Injection Idea

  1. The program is unmodified.
  2. The running process is modified.
  3. Modifying the return address (located on the stack)
  4. Insert (effectively) new machine code sequence into the process
  5. And return!

4.1 Choosing a binary

  1. Stack allocated local array
  2. Unchecked array index usage
  3. Copying a given argument into a local array
  4. Supplying a carefully constructed string argument
  5. The string has the executable machine code

4.2 Shell code

  1. Designing the shell-code to be injected
    1. ../LinuxSetup/StudyPrograms/testsc.c
  2. Constructing the shell-code from disassembly
  3. Fine tuning the shell code as a proper string

4.3 Modifying the return address

  1. Studying ./modret/modret.c
  2. Modify the return address to the beginning of the "string"
  3. modReturnAddress-acer602-20080507.html These are the results of trying out the code examples from the AlephOne article. These notes were recorded with Auditor LiveCD on my old Acer laptop with Pentium III (Coppermine) running Debian GNU/Linux 3.1, gcc version 3.3.5 (Debian 1:3.3.5-2).

5 The Exploit

  1. Putting it all together
  2. Padding the Shell Code with NOPs so that jump target address is less critical
  3. Inputting the shell code as an argument
  4. ./AlephOne/alephOne.html One of the best exaplanation of Stack Smashing.

6 Experiencing the Exploit in the Lab

  1. As of 2019, many "standard" code injections have been prevented.
  2. Virtual Machines
    1. VirtualBox
    2. VMware
  3. Linux Distro: (BackTrack) Audtor.ISO
    1. An Old OS/C-compiler/bash
    2. Uses IDE drives; so not bootable on modern PCs

6.1 Disable Stack top randomization

  1. Compile any program (e.g. from StudyPrograms).
  2. Invoke it several times, and print the address of a local variable of main Is it changing? That is Stack Top Randomization.

6.2 Disabling Stack Protection

  1. Compiler flags: no canaries gcc overflow.c -o overflow -fno-stack-protector
  2. ./bo.c compile: gcc -fno-stack-protector -z execstack -o bo bo.c

6.3 Disable ASLR

  1. ASLR Address Space Layout Randomization
  2. Disable ASLR: sudo echo 0 > /proc/sys/kernel/randomize_va_space Enabled: randomize_va_space should be 2
  3. ASLR is effective only if the binary was PIE (position independent code enabled). -fPIC -pie

7 Detection

  1. Checking the caller of execv
  2. Deep packet inspection
  3. Tools: Chaperon, Valgrind, CCured, CRED, Insure++, ProPolice and TinyCC, …

8 Prevention

  1. CPU/MMU: Separate address spaces for Data and Machine Instructions
    1. noexec-user-stack
    2. Never-eXecute (NX) bit http://en.wikipedia.org/wiki/NX_bit
    3. Intel: XD bit, eXecute Disable
    4. AMD: Enhanced Virus Protection
    5. ARM: XN for eXecute Never
  2. Stack top randomization
  3. ASLR Address space layout randomization
  4. Run-time Check for Input Taintedness
  5. Run-time Check for Array Bounds

8.1 Secure Programming Practices

  1. Techniques of Avoiding Buffer Overflow
  2. Safe String Libraries
  3. Static Analysis of Source Code
  4. Lectures on ../SecSoftware/

9 Labs

10 Reading List

  1. Readings are grouped into Required and Recommended.
  2. Required Readings are a must read. These are sources of exam questions.
  3. Recommended Readings bring more insight into the topic. But exam questions will not be derived from these.
  4. Some of our "readings" are actually web site visits.

10.1 Required Reading

  1. Aleph One, "Smashing The Stack For Fun And Profit," Phrack, Vol 7, Issue 49, File 14 of 16. 1996. A classic article. A local copy of the original Phrack article is ./AlephOne/phrack-article-p49-14.txt. An html-ized version of this paper with some corrections by me is ./AlephOne/alephOne.html.
  2. Prabhaker Mateti, Buffer Overflow Attacks. This article associated with this lecture. 2019.
  3. http://en.wikipedia.org, Buffer-overflow, Heap-overflow, Uncontrolled-format-string, Return-to-libc-attack, Return-oriented-programming. 2013. All Required Reading.
  4. Yves Younan, Wouter Joosen and Frank Piessens, "Runtime countermeasures for code injection attacks against C and C++ programs ", ACM Computing Surveys , 44(3), 2012. Recommended Reading.

10.2 Recommended Reading

  1. David A. Wheeler, "Secure Programming for Linux and Unix HOWTO," 2003, http://tldp.org/HOWTO/Secure-Programs-HOWTO/ Highly recommended reading.
  2. Matt Conover, and WSD, "w00w00 on Heap Overflows", January 1999, Originally at http://www.w00w00.org/ files/ articles/ heaptut.txt Web search for a copy. Highly recommended reading.
  3. skape, Understanding Windows Shellcode, http://nologin.org/ Downloads/ Papers/ win32-shellcode.pdf, 2003.
  4. Parvez Anwar, "Buffer Overflows in the Microsoft Windows Environment", 2009, https://www.ma.rhul.ac.uk/ static/ techrep/ 2009/ RHUL-MA-2009-06.pdf

10.3 Recommended Reading #2

  1. https://dl.packetstormsecurity.net/papers/attack/64bit-overflow.pdf 64 Bits Linux Stack Based Buffer Overflow 12pp
  2. https://bytesoverbombs.io/exploiting-a-64-bit-buffer-overflow-469e8b500f10 Nov 4, 2017;; {pm: Long winded. Uses Kali, python, metasploit pattern find tool, msfvenom, python payload generator; uses linux/x64/shell_reverse_tcp payload so the remote mc controls our host when exploit happens. Explains the real rsp register.}
  3. https://www.exploit-db.com/papers/24085/ Stack Smashing On A Modern Linux System, December 2012 {pm: "modern" = 2012}
  4. https://www.blackhat.com/presentations/bh-europe-09/Fritsch/Blackhat-Europe-2009-Fritsch-Buffer-Overflows-Linux-whitepaper.pdf 12pp April 16th, 2009
  5. Sebastian Krahmer, https://users.suse.com/~krahmer/no-nx.pdf 20pp {x86-64 buffer overflow exploits and the borrowed code chunks exploitation technique} Sep 2005

11 End


Copyright © 2019 www.wright.edu/~pmateti • 2019-09-15