Here is the context:

The challenge asks us to count rhinoceros. Let’s connect via netcat to understand what it is about.
Here is what we get when we connect:

We have to count the number of rhinoceros ~c`°^) in the text and send the answer within seconds.
The fact is that it will ask us to do it several times so we have to make an infinite while loop to count each wave of rhinoceros.
Here is the code I wrote:
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
import pwn
import re
# connect to the server
r = pwn.remote('challenges.404ctf.fr', 31420)
iter = 0
while True:
print("Iteration: " + str(iter))
iter += 1
try:
# receive the response
response = r.recvuntil(b'>')
print(response.decode())
# count the number of ~c`°^) in the response
count = len(re.findall(r'~c`°\^\)', response.decode()))
print("Count: " + str(count))
# send the count
r.sendline(bytes(str(count), 'utf-8'))
except:
break
# receive the flag
response = r.recvuntil(b'}')
print(response.decode())
For each loop iteration, we receive until the character ‘>’ so we know we have the full response. Then we count the number of rhinoceros using regex. We send the count.
When we reach the end, the character ‘>’ will not be in the response. It will raise an error because it takes too much time. When it happens, we know it’s done so we break out of the loop.
We receive until the character ‘}’ (the end of the flag) and print the response.

We have the flag !
I hope this writeup was easy to understand. Have a good day 😀 !