我正在尝试执行一个非常简单的缓冲区溢出攻击。我对此几乎是新手。所以,如果这个问题很愚蠢,请原谅:-)
编码:
#include<stdio.h>
#include<stdlib.h>
int i, n;
void confused(int i)
{
printf("**Who called me? Why am I here?? *** %x\n ", i);
}
void shell_call(char *c)
{
printf(" ***Now calling \"%s\" shell command *** \n", c);
system(c);
}
void victim_func()
{
int a[4];
printf("Enter n: "); scanf("%d",&n);
printf("~~~~~~~~~~~~~ values and address of n locations ~~~~~~~~~~");
for (i = 0;i <n ;i++)
printf ("\n a[%d] = %x, address = %x", i, a[i], &a[i]);
printf("\nEnter %d HEX Values \n", n);
// Buffer Overflow vulnerability HERE!
for (i=0;i<n;i++) scanf("%x",&a[i]);
printf("Done reading junk numbers\n");
}
int main()
{
victim_func();
printf(“\n done”);
return 0;
}
当我使用 objdump 获取函数地址时,我有以下内容:
main(): 0x804854d
Address of main() where printf() is called: 0x8048563
victim_func(): 0x8048455
confused(): 0x8048414
现在,我想要的是从victim_func() 跳转到函数'confused()',方法是溢出那里的缓冲区,并将返回地址覆盖到confused() 的地址。我想从confused()返回到main中的printf()语句,然后正常退出。所以,我提供以下输入
Enter n: 7
Enter 7 HEX values:
1
2
3
4
5
8048414 (This is to jump to confused)
8048563 (this is to jump to printf() in main)
尽管该程序从该 printf 语句中打印出“Done”,但它正在跳回victim_func() 并打印出“Enter n:”
我究竟做错了什么?任何帮助将不胜感激!
PS:我不确定我的问题是否正确。如果需要更多信息,请告诉我。