首先關閉計算機,我運行的是一個在32位堆棧上運行Linux的Intel系統。我的教授在課堂上向我們提出了一個挑戰性的問題。利用堆棧緩衝區溢出
以下是代碼之前,我問的問題
// funWithFooAndBar.c
#include <stdio.h>
#include <stdlib.h>
void bar()
{
printf("Now inside bar()!\n");
}
void foo()
{
void *addr[1];
printf("Now inside foo()!\n");
// this is where I need to modify my code,
//I was given the hint that it will only be two lines of code
// So something like:
addr[1] = bar;
addr[5] = addr[4];
addr[4] = bar;;
}
int main (int argc, char *argv[])
{
foo();
printf("Back in main\n");
return 0;
}
我們的目標是通過寫超出數組的末端破壞堆棧,並通過,覆蓋返回地址,這樣的函數調用foo()在返回到main的路上返回到bar()。所以我的輸出應該是這樣的:
現在裏面foo()!
現在裏面吧()!
回到主
爲了做到這一點,我有溢出陣列,這樣的返回地址與bar.I'm的相當肯定,它會涉及到的地址的地址重寫函數bar()將等於& bar()
他提出的問題是我們可以添加兩行代碼(我在其中評論過)以使輸出如上所示。
謝謝!
編輯:我希望更多的解釋,而不是直接的答案,我知道我應該做的,而不是如何將其轉換爲C代碼。
編輯:作出了嘗試
我看不到任何企圖。 –
我希望更多的解釋,而不是直接的答案,我知道我應該做的,而不是如何將其轉換爲C代碼。 – Speerian
所以做一個嘗試..... –