SecSIGSecurity Special Interest Group of US MensaCuriosity. Perspective. Security.

Research Library · Idea

Stack smashing

Stack smashing is the corruption of a program's execution stack by writing past the end of an array declared as an automatic variable in a routine. The Jargon File definition quoted at the start of Aleph One's article says that code doing this can cause the return from the routine to jump to a random address.1 The term is also used for the deliberate exploitation of such a stack-based buffer overflow to run attacker-chosen code.

The best-known description is "Smashing the Stack for Fun and Profit" by Aleph One, which appeared as file 14 of Phrack issue 49, released on 8 November 1996.12 Its introduction reports a large increase in buffer overflow vulnerabilities being discovered and exploited in recent months, naming syslog, splitvt, sendmail 8.7.5, the Linux and FreeBSD mount programs, the Xt library and at as examples. The article sets out to explain what buffer overflows are and how their exploits work, assuming an Intel x86 CPU and the Linux operating system.1

The article explains the mechanics step by step. When a function is called, the saved instruction pointer, which it calls the return address, is placed on the stack. A function that copies a string into a local buffer with strcpy, without bounds checking, can overwrite that return address, and the article's demonstration overwrites it with 0x41414141, causing a segmentation violation when the function returns. In this way, the author writes, a buffer overflow lets an attacker change the return address and so change the flow of execution.1 To run arbitrary code, the article places the code to be executed, in most cases code that spawns a shell by calling execve, in the overflowing buffer and points the return address at it. Because the exact buffer address is hard to guess, it pads the front of the overflow buffer with NOP instructions so that an approximate address suffices.1

The technique predates the article. Spafford's analysis of the 1988 Internet worm describes a 536-byte string sent to the finger daemon that overran its input buffer and overwrote the stack's return address so that the injected instructions started a shell.3 Aleph One's article is a widely read tutorial account of the method and is not claimed here as its first description.

The root cause is a missing bounds check on a copy into a fixed-size buffer. Buffer overflows and memory-safety defects more generally are treated in their own entries.

Source · Smashing the Stack for Fun and Profit (opens in a new tab) · Phrack Magazine (author: Aleph One)

References

  1. Smashing the Stack for Fun and Profit (opens in a new tab) · Phrack Magazine, issue 49, file 14 (author: Aleph One); copy hosted on insecure.org · November 8, 1996 · Introduction, process memory, buffer overflow example, shell code and NOP padding. ↩ ↩ ↩ ↩ ↩
  2. Smashing the Stack for Fun and Profit (Phrack 49 article page) (opens in a new tab) · Phrack Magazine · November 8, 1996 · Issue release date 1996-11-08 as listed on the Phrack site. ↩
  3. The Internet Worm Program: An Analysis (opens in a new tab) · Purdue University Department of Computer Sciences, Technical Report CSD-TR-823 (author: Eugene H. Spafford) · November 29, 1988 · Description of the fingerd attack. ↩

Research articles

See what connects to it on the map of ideas →

See also