间接指针覆盖-如何覆盖返回地址?

问题描述

因此,我读到如果无法通过溢出直接覆盖返回地址,则仍然可以通过指针间接覆盖返回地址。

我知道它可以通过使用溢出来覆盖局部变量来工作。然后,如果有一个指针被取消引用了该局部变量的值,那么显然可以覆盖返回地址吗?这是我努力理解的部分。

解决方法

这可能不是最理想的解决方法,但希望它使您对可能的想法有所了解:

void myFunc() {
  int* ptr = (whatever the code was pointing to);
  int numToBePutInPtr;
  char aString[10];

  // INSERT HERE some way of inputting into aString. To perform the attack
  // input 10 useless bytes,then the address of the code you want to get run,// then the address of the return address on the stack

  *ptr = numToBePutInPtr;
}

当最后一行开始运行时,它不是要运行的numToBePutInPtr的原始值,而是要运行的代码的地址。并且因为重写了*ptr来实际指向返回地址在堆栈上的位置,所以返回地址将替换为您要运行的代码的地址。

此攻击与更基本的溢出-覆盖-返回-地址攻击之间的主要区别在于,堆栈的更简单的防护措施不会捕获您溢出的局部变量(您在“跳过”)仅使用指针进行检查)。但是,仍然要严防其他检查。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...