这是关于该主题最为广泛知晓的文件:Smashing the Stack for Fun and Profit
然而,“堆栈溢出”与缓冲区溢出无关。 堆栈溢出通常只是糟糕代码中的错误情况,无法被利用用于除了崩溃(DoS)之外的任何事情。
编辑:您也询问了有关堆溢出的信息。 这是有关该主题的一个好文件:http://www.w00w00.org/files/articles/heaptut.txt
当你跳入一个子程序时,栈中包含数据和返回地址。如果你设法在栈上放置一个特定的地址作为返回地址,就可以强制CPU跳转到一个特定的内存位置,也就是你自己代码所在的位置。这就是缓冲区溢出攻击的原理。堆溢出攻击略有不同,更难利用。
栈溢出只是表明你已经用完了栈空间(通常在内核中更为有限)。
现代处理器在调用子程序时,几乎都会将返回地址推送到与本地数据(堆栈)相同的区域。对于不检查变量上限的例程(特别是strcpy函数),指令地址重定向(缓冲区溢出)可能会发生。
void make(char *me)
{
char sandwich[4]; // local data, this is in stack. the buffer for data is too small
strcpy(sandwich, me);
puts(sandwich);
// implicit "return;" the return instruction(RET on Intel) instructs the processor to implicitly pop an address from stack then resume execution on that address
}
void main()
{
// calling a subroutine (CALL on Intel) implicitly instructs the processor to push the next instruction's address(getchar line) on stack before jumping to make.
make("Love Not War");
getchar();
puts("This will not execute. The address to next instruction(getchar) gets overwritten with Not War");
}
"另外,第三方的恶意代码必须用目标处理器的汇编语言编写吗?" 是的
堆栈溢出可能会发生在正常运行程序时,例如递归例程(调用自身的函数)忽略了终止条件。堆栈区域将填充大量本地变量和返回地址。