[英]Understanding how parameters are passed to functions in Assembly
我讀這個書面記錄就如何執行ret2libc
漏洞。 它聲明傳遞給函數的參數存儲在ebp+8
。
現在,如果我使用一個簡單的C程序
#include <stdlib.h>
int main() {
system("/bin/sh");
}
並編譯它: gcc -m32 -o test_sh test_sh.c
並用objdump -d -M intel test_sh
查看它的反匯編
0804840b <main>:
804840b: 8d 4c 24 04 lea ecx,[esp+0x4]
804840f: 83 e4 f0 and esp,0xfffffff0
8048412: ff 71 fc push DWORD PTR [ecx-0x4]
8048415: 55 push ebp
8048416: 89 e5 mov ebp,esp
8048418: 51 push ecx
8048419: 83 ec 04 sub esp,0x4
804841c: 83 ec 0c sub esp,0xc
804841f: 68 c4 84 04 08 push 0x80484c4
8048424: e8 b7 fe ff ff call 80482e0 <system@plt>
8048429: 83 c4 10 add esp,0x10
804842c: b8 00 00 00 00 mov eax,0x0
8048431: 8b 4d fc mov ecx,DWORD PTR [ebp-0x4]
8048434: c9 leave
8048435: 8d 61 fc lea esp,[ecx-0x4]
8048438: c3 ret
8048439: 66 90 xchg ax,ax
804843b: 66 90 xchg ax,ax
804843d: 66 90 xchg ax,ax
804843f: 90 nop
線
804841f: 68 c4 84 04 08 push 0x80484c4
將字符串“ / bin / sh”的地址壓入堆棧。 之后立即調用system@plt
函數。 那么從上面的輸出如何到達ebp+8
?
幫助將不勝感激!
您不是因為EBP + 8僅在創建新過程框架后在system @ plt中的序言之后才有意義。
push ebp
mov ebp, esp
此時,在system @ plt中,由EBP + 8指向的內存位置的內容將等於0x80484C4。
傳遞給函數的參數存儲在ebp + 8。
那是從被調用函數的角度來看,而不是從調用函數的角度來看。 調用函數在ebp+8
處具有自己的參數,並且main()
不使用其任何參數,因此,您在main()
中看不到ebp+8
任何使用。
您可以看到ebp+8
的用法如下:
嘗試編寫帶有參數的第二個函數,然后從main()
調用它,而不是調用system()
。 您仍然不會在main()
看到ebp+8
任何使用,但是您會在第二個函數中看到它的使用。
嘗試聲明main()
接受其char** argv
參數,然后嘗試將argv[0]
發送到printf()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.