![](/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.