sa1*_*125 31 c pointers buffer-overflow stack-trace fortify-source
我有一个家庭作业,要求我使用缓冲区溢出调用函数而不显式调用它.代码基本上是这样的:
#include <stdio.h>
#include <stdlib.h>
void g()
{
    printf("now inside g()!\n");
}
void f()
{   
    printf("now inside f()!\n");
    // can only modify this section
    // cant call g(), maybe use g (pointer to function)
}
int main (int argc, char *argv[])
{
    f();
    return 0;
}
虽然我不知道该怎么办.我想改变程序计数器的返回地址,以便它直接进入g()的地址,但我不知道如何访问它.无论如何,提示将是伟大的.
cod*_*ict 13
基本思想是改变函数的返回地址,以便在函数返回时继续在新的黑客地址执行.正如Nils在其中一个答案中所做的那样,你可以声明一块内存(通常是数组)并以这样的方式溢出它,使得返回地址也被覆盖.
我建议你不要盲目地接受这里给出的任何程序,而不要真正了解它们是如何工作的.这篇文章写得很好,你会发现它非常有用:
Nil*_*nck 11
这是编译器相关的,因此不能给出单个答案.
以下代码将为gcc 4.4.1执行您想要的操作.禁用优化编译(重要!)
#include <stdio.h>
#include <stdlib.h>
void g()
{
    printf("now inside g()!\n");
}
void f()
{   
  int i;
  void * buffer[1];
  printf("now inside f()!\n");
  // can only modify this section
  // cant call g(), maybe use g (pointer to function)
  // place the address of g all over the stack:
  for (i=0; i<10; i++)
     buffer[i] = (void*) g;
  // and goodbye..
}
int main (int argc, char *argv[])
{
    f();
    return 0;
}
输出:
nils@doofnase:~$ gcc overflow.c
nils@doofnase:~$ ./a.out
now inside f()!
now inside g()!
now inside g()!
now inside g()!
now inside g()!
now inside g()!
now inside g()!
Segmentation fault
| 归档时间: | 
 | 
| 查看次数: | 8843 次 | 
| 最近记录: |