蒸米大神談ROPwww.vuln.cn/6645
ROP的全稱為Return-oriented programming(返回導向編程),這是一種高級的內存攻擊技術可以用來繞過現代操作系統的各種通用防御(比如內存不可執行和代碼簽名等)。
0x01 linux_64與linux_86的區別
linux_64與linux_86的區別主要有兩點:首先是內存地址的范圍由32位變成了64位。但是可以使用的內存地址不能大於0x00007fffffffffff,否則會拋出異常。其次是函數參數的傳遞方式發生了改變,x86中參數都是保存在棧上,但在x64中的前六個參數依次保存在RDI, RSI, RDX, RCX, R8和 R9中,如果還有更多的參數的話才會保存在棧上。
0x02 尋找gadgets
linux安裝 ROPgadget
git clone https://github.com/JonathanSalwan/ROPgadget.git
cd ROPgadget
sudo python setup.py install
使用ROPgadget
~$ ROPgadget --binary level4 --only "pop|ret"
Gadgets information
============================================================
0x00000000004008ac : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004008ae : pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004008b0 : pop r14 ; pop r15 ; ret
0x00000000004008b2 : pop r15 ; ret
0x00000000004008ab : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004008af : pop rbp ; pop r14 ; pop r15 ; ret
0x0000000000400700 : pop rbp ; ret
0x00000000004008b3 : pop rdi ; ret
0x00000000004008b1 : pop rsi ; pop r15 ; ret
0x00000000004008ad : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret
0x0000000000400601 : ret
0x0000000000400682 : ret 0x2009