![](/img/trans.png)
[英]How to find the vulnerability of a program to exploit using buffer overflow attack
[英]How to “cleanly” terminate the program after buffer overflow attack
我正在研究缓冲区溢出,并且试图跳到“ confused”功能,然后通过执行缓冲区溢出在main的末尾打印“完成”。
#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("\nEnter 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() {
printf("\n ~~~~~~~~~~~~~~~~~ Info Menu ~~~~~~~~~~~~");
printf("\n addrss of main %x", main);
printf("\n addrss of shell_cal %x", shell_call);
printf("\n addrss of confused %x", confused);
victim_func();
printf("\n done");
return 0;
}
我所做的是,我在n中放入7,在第16个十六进制值中我插入了混淆的地址,在第7个中插入了printf的地址。 混淆功能后,它成功打印出“完成”,但是程序返回到main的开头。 我认为该程序将在打印出“完成”后终止。
我只是想知道我做错了什么,还是应该这样做。
您始终可以在外壳程序代码中调用exit()来终止程序。 但是,您不能使用system()来完成此操作,因为system()将创建一个子进程,该子进程最终最终将返回其父进程。 您需要使用程序集直接调用exit()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.