L’Inondation
In this challenge, we can connect to a netcat server and we will be prompted with the message «Allez, vite, il y a une pile de photos assez importante à traiter,comptes-moi le nombre de rhinos par photo. »
. Which means we need to recover the amount of rhinos that is printed. A rhino is printed as ~c'°^)
.
I used the following function to get the text from the netcat server, send the number of rhinos found and return the text received:
1
2
3
4
5
6
7
8
9
def find_rhino():
text = io.recvuntil("> ").strip().decode("utf-8")
# count the number of rhinos by splitting the string into an array of rhinos and getting the length
rhinos = len(text.split("~c`°^)"))-1
io.sendline(str(rhinos))
returned_text = io.recvline().strip().decode("utf-8")
return returned_text
Then I used this while loop to use this function until I can’t find any more rhinos:
1
2
3
4
5
6
7
8
flag = find_rhino()
while "Très bien, la suite arrive" in flag:
try:
flag = find_rhino()
except Exception as e:
print(io.recvline().decode("utf-8"))
sleep(0.1)
At the end we get the full code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pwn import *
from time import sleep
HOST, PORT = "challenges.404ctf.fr", 31420
io = remote(HOST, PORT)
def find_rhino():
text = io.recvuntil("> ").strip().decode("utf-8")
rhinos = len(text.split("~c`°^)"))-1
io.sendline(str(rhinos))
returned_text = io.recvline().strip().decode("utf-8")
return returned_text
flag = find_rhino()
while "Très bien, la suite arrive" in flag:
try:
flag = find_rhino()
except Exception as e:
print(io.recvline().decode("utf-8"))
sleep(0.1)
By executing this code we get:
The flag is 404CTF{4h,_l3s_P0uvo1rs_d3_l'iNforM4tiqu3!}
.