fbpx
维基百科

栈缓冲区溢出

栈缓冲区溢出(stack buffer overflow或stack buffer overrun)是计算机程序把数据写入调用栈上的内存时超出了数据结构的边界。[1][2]栈缓冲区溢出是缓冲区溢出的一种。[1] 这会损坏相邻数据的值,引发程序崩溃或者修改了函数返回地址从而导致执行恶意的程序。这种攻击方式称为stack smashing。可被用于注入可执行代码、接管进程的执行。是最为古老的黑客攻击行为之一。[3][4][5]

例子

下例可用于覆盖函数返回地址。[3][6] 通过函数 strcpy() :

#include <string.h> void foo (char *bar) {  char c[12];  strcpy(c, bar); // no bounds checking } int main (int argc, char **argv) {  foo(argv[1]);  return 0; } 

当命令行参数少于12个字符时(例子B时)该程序是安全的。

foo()函数的不同输入下的调用栈:

 
A. - Before data is copied.
 
B. - "hello" is the first command line argument.
 
C. - "A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​A​\x08​\x35​\xC0​\x80" is the first command line argument.

例子C中, 命令行参数多于11个字符,导致foo()覆盖了本地调用栈的数据、存储的栈指针(EBP)以及最重要的返回地址。

攻击也可以修改内部变量值:

#include <string.h> #include <stdio.h> void foo (char *bar) {  float My_Float = 10.5; // Addr = 0x0023FF4C  char c[28]; // Addr = 0x0023FF30  // Will print 10.500000  printf("My Float value = %f\n", My_Float);  /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  Memory map:  @ : c allocated memory  # : My_Float allocated memory  *c *My_Float  0x0023FF30 0x0023FF4C  | |  @@@@@@@@@@@@@@@@@@@@@@@@@@@@#####  foo("my string is too long !!!!! XXXXX");  memcpy will put 0x1010C042 (little endian) in My_Float value.  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/  memcpy(c, bar, strlen(bar)); // no bounds checking...  // Will print 96.031372  printf("My Float value = %f\n", My_Float); } int main (int argc, char **argv) {  foo("my string is too long !!!!! \x10\x10\xc0\x42");  return 0; } 

平台相关

保护方式

常用三种方式来对抗栈缓冲区溢出攻击。

检查栈缓冲区溢出的发生

栈的警惕标志(stack canary),得名于煤矿里的金丝雀英语Animal sentinel#Historical examples,用于探测该灾难的发生。具体办法是在栈的返回地址的存储位置之前放置一个整形值,该值在装入程序时随机确定。栈缓冲区攻击时从低地址向高地址覆盖栈空间,因此会在覆盖返回地址之前就覆盖了警惕标志。返回返回前会检查该警惕标志是否被篡改。[2]

栈数据不可执行

采取了“写异或执行”策略(W^X英语W^X, "Write XOR Execute"),即内存要么可写,要么可执行,但二者不能兼得。这是最常用的方法,大部分桌面处理器都硬件支持不可执行标志(no-execute flag)。

随机化内存空间布局

著名例子

参见

参考文献

  1. ^ 1.0 1.1 Fithen, William L.; Seacord, Robert. VT-MB. Violation of Memory Bounds. US CERT. 2007-03-27 [2017-02-19]. (原始内容于2012-02-05). 
  2. ^ 2.0 2.1 Dowd, Mark; McDonald, John; Schuh, Justin. The Art Of Software Security Assessment. Addison Wesley. November 2006: 169–196. ISBN 0-321-44442-6. 
  3. ^ 3.0 3.1 Levy, Elias. Smashing The Stack for Fun and Profit. Phrack. 1996-11-08, 7 (49): 14 [2017-02-19]. (原始内容于2021-03-04). 
  4. ^ Pincus, J.; Baker, B. Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns (PDF). IEEE Security and Privacy Magazine. July–August 2004, 2 (4): 20–27 [2017-02-19]. doi:10.1109/MSP.2004.36. (原始内容 (PDF)于2016-03-04). 
  5. ^ Burebista. (PDF). [2017-02-19]. (原始内容 (PDF)存档于2007-09-28).  (dead link)
  6. ^ Bertrand, Louis. . MUSESS '02: McMaster University Software Engineering Symposium. 2002 [2017-02-19]. (原始内容存档于2007-09-30). 

栈缓冲区溢出, stack, buffer, overflow或stack, buffer, overrun, 是计算机程序把数据写入调用栈上的内存时超出了数据结构的边界, 是缓冲区溢出的一种, 这会损坏相邻数据的值, 引发程序崩溃或者修改了函数返回地址从而导致执行恶意的程序, 这种攻击方式称为stack, smashing, 可被用于注入可执行代码, 接管进程的执行, 是最为古老的黑客攻击行为之一, 目录, 例子, 平台相关, 保护方式, 检查的发生, 栈数据不可执行, 随机化内存空间布局, 著名例子, 参见, . 栈缓冲区溢出 stack buffer overflow或stack buffer overrun 是计算机程序把数据写入调用栈上的内存时超出了数据结构的边界 1 2 栈缓冲区溢出是缓冲区溢出的一种 1 这会损坏相邻数据的值 引发程序崩溃或者修改了函数返回地址从而导致执行恶意的程序 这种攻击方式称为stack smashing 可被用于注入可执行代码 接管进程的执行 是最为古老的黑客攻击行为之一 3 4 5 目录 1 例子 2 平台相关 3 保护方式 3 1 检查栈缓冲区溢出的发生 3 2 栈数据不可执行 3 3 随机化内存空间布局 4 著名例子 5 参见 6 参考文献例子 编辑下例可用于覆盖函数返回地址 3 6 通过函数 a href Strcpy html title Strcpy strcpy a include lt string h gt void foo char bar char c 12 strcpy c bar no bounds checking int main int argc char argv foo argv 1 return 0 当命令行参数少于12个字符时 例子B时 该程序是安全的 foo 函数的不同输入下的调用栈 A Before data is copied B hello is the first command line argument C A A A A A A A A A A A A A A A A A A A A x08 x35 xC0 x80 is the first command line argument 例子C中 命令行参数多于11个字符 导致foo 覆盖了本地调用栈的数据 存储的栈指针 EBP 以及最重要的返回地址 攻击也可以修改内部变量值 include lt string h gt include lt stdio h gt void foo char bar float My Float 10 5 Addr 0x0023FF4C char c 28 Addr 0x0023FF30 Will print 10 500000 printf My Float value f n My Float Memory map c allocated memory My Float allocated memory c My Float 0x0023FF30 0x0023FF4C foo my string is too long XXXXX memcpy will put 0x1010C042 little endian in My Float value memcpy c bar strlen bar no bounds checking Will print 96 031372 printf My Float value f n My Float int main int argc char argv foo my string is too long x10 x10 xc0 x42 return 0 平台相关 编辑保护方式 编辑常用三种方式来对抗栈缓冲区溢出攻击 检查栈缓冲区溢出的发生 编辑 栈的警惕标志 stack canary 得名于煤矿里的金丝雀 英语 Animal sentinel Historical examples 用于探测该灾难的发生 具体办法是在栈的返回地址的存储位置之前放置一个整形值 该值在装入程序时随机确定 栈缓冲区攻击时从低地址向高地址覆盖栈空间 因此会在覆盖返回地址之前就覆盖了警惕标志 返回返回前会检查该警惕标志是否被篡改 2 栈数据不可执行 编辑 采取了 写异或执行 策略 W X 英语 W X Write XOR Execute 即内存要么可写 要么可执行 但二者不能兼得 这是最常用的方法 大部分桌面处理器都硬件支持不可执行标志 no execute flag 随机化内存空间布局 编辑著名例子 编辑莫里斯蠕虫针对Unix finger 英语 finger protocol 服务器 1 页面存档备份 存于互联网档案馆 Witty worm 英语 Witty worm 2 Slammer worm 英语 SQL Slammer 针对Microsoft SQL Server 3 页面存档备份 存于互联网档案馆 衝擊波蠕蟲 针对微软的DCOM 服务 Twilight hack 英语 Twilight hack 针对Wii参见 编辑参考文献 编辑 1 0 1 1 Fithen William L Seacord Robert VT MB Violation of Memory Bounds US CERT 2007 03 27 2017 02 19 原始内容存档于2012 02 05 2 0 2 1 Dowd Mark McDonald John Schuh Justin The Art Of Software Security Assessment Addison Wesley November 2006 169 196 ISBN 0 321 44442 6 3 0 3 1 Levy Elias Smashing The Stack for Fun and Profit Phrack 1996 11 08 7 49 14 2017 02 19 原始内容存档于2021 03 04 Pincus J Baker B Beyond Stack Smashing Recent Advances in Exploiting Buffer Overruns PDF IEEE Security and Privacy Magazine July August 2004 2 4 20 27 2017 02 19 doi 10 1109 MSP 2004 36 原始内容存档 PDF 于2016 03 04 Burebista Stack Overflows PDF 2017 02 19 原始内容 PDF 存档于2007 09 28 dead link Bertrand Louis OpenBSD Fix the Bugs Secure the System MUSESS 02 McMaster University Software Engineering Symposium 2002 2017 02 19 原始内容存档于2007 09 30 取自 https zh wikipedia org w index php title 栈缓冲区溢出 amp oldid 71490408, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。