【发布时间】:2011-11-12 17:46:00
【问题描述】:
我正在尝试执行一个非常简单的缓冲区溢出攻击。我对此几乎是新手。所以,如果这个问题很愚蠢,请原谅:-)
代码:
#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:我不确定我的问题是否正确。如果需要更多信息,请告诉我。
【问题讨论】:
-
其实这是学校的作业!
-
如果这真的是家庭作业,请标记它。
-
@VJo 我认为这是一项很棒的教育任务——我很想亲自尝试一下:它需要对代码的汇编程序实现有深入的理解和直接的实验。白帽子也需要掌握这些想法。
-
LOL 哪所学校教如何滥用缓冲区溢出?确实,您需要深入了解二进制代码。上面的尝试是苍白的尝试,不会奏效
-
@VJo:实际上,我看过的所有计算机安全课程都包含这样的内容。了解这些攻击是如何工作的很重要,如果没有别的,那么了解为什么在编程时应该小心。
标签: c buffer-overflow objdump