我正在读下面这篇关于缓冲区溢出的论文:http://www1.telhai.ac.il/sources/private/academic/cs/557/2659/Materials/Smashing.pdf
根据本文中的示例,攻击者在溢出的缓冲区中注入代码,并修改返回地址以指向缓冲区的地址。既然注入的代码和局部变量都位于堆栈上,那么攻击者在用代码溢出缓冲区之前,难道不应该确保她/他已经为局部变量留出了足够的空间吗?在广义上,当代码和局部变量都在堆栈上时,我对如何维护堆栈感到困惑....are有可能局部变量覆盖注入的代码?
发布于 2012-08-08 00:38:02
一种解决方案是不使用任何局部变量。对于很小的代码来说,这不一定是一个很大的约束,因为这些代码无论如何都是通过调用其他东西来完成工作的。(相对地说,这不是一个很大的约束,这超出了我的能力范围,但因为这不是最容易编写的代码,所以在那个上下文中它不是一个很大的约束)。
不过,这甚至不是必须的。堆栈将如下所示:
Function A Arg 2
Function A Arg 1
Function A Arg 0
Return Address into caller
Function A Local 1
Function A Local 0
Function B Arg 1
Function B Arg 0
Return Address into place in Function A's executable code.
Function B Local 2
Function B Local 1
Function B Local 0
Function C Arg 0
Return Address into place in Function B's executable code.
Function C Local 3
Function C Local 2
Function C Local 1
Function C Local 0
...缓冲区溢出使它看起来像这样:
Function A Arg 2
Function A Arg 1
Function A Arg 0
Return Address into caller
Function A Local 1
NastyCode bytes 0-3
NastyCode bytes 4-7
NastyCode bytes 8-B
NastyCode bytes C-E
NastyCode bytes F-10
NastyCode bytes 10-13
NastyCode bytes 14-17
NastyCode bytes 18-1B
NastyCode bytes 1F-20
...
NastyCode arg 0 (etc.)
Return Address (of NastyCode [may not even be valid, may return to original caller, or may jump into something it'll set up]).
NastyCode Local 2
NastyCode Local 1
NastyCode Local 0
Return Address (should be of Function F, into a point in Function E but it's changed to point to byte 0 of NastyCode)
Function F Local 2
Function F Local 1
Function F Local 0因此,写入堆栈的可执行代码可以远离该代码的本地变量。
https://stackoverflow.com/questions/11850028
复制相似问题