Zeecka zeecka

Maintenance

BreizhCTF 2023 - Cryptography

BreizhCTF 2023 - Maintenance

Challenge details

EventChallengeCategoryPointsSolves
BreizhCTF 2023MaintenanceCryptography??????

maintenance

In order to make the BreizhCTF accessible to users running the i3 environment, a command-line interface was developed. Following several intrusions, we decided to put the interface into maintenance. Let’s hope this is enough…

Author: Zeecka

nc maintenance.ctf.bzh 30011

TL;DR

The service under maintenance allowed generating a user token encrypted with an ECB mode. Injecting into the user’s nickname then made it possible to generate the desired blocks to produce an administrator token.

Methodology

The application’s nominal scenario allows requesting an authentication token from a name and authenticating with the token:

Bonjour et bienvenue sur l'interface CLI du BreizhCTF !

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3): 1
La fonctionnalité d'enregistrement vous permet de récupérer un compte invité.
Renseigner votre nom: a
Vous pouvez à présent vous authentifier à l'aide de votre jeton 953b5025695b9ffa2f42ef3f4368763872683b5cb5bda8b61f6c0c139922f13259385586d4c74c42461c9821f30549e9.
Celui-ci est valide pour une durée de 3 minutes.

En cas d'erreur, transmettez ce code à votre administrateur: 757365726e616d653d613b726f6c653d696e766974653b74696d653d31363733383136303832.

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3): 2
Veuillez renseigner votre nom: a
Veuillez renseigner votre jeton d'authentification: 953b5025695b9ffa2f42ef3f4368763872683b5cb5bda8b61f6c0c139922f13259385586d4c74c42461c9821f30549e9
Vous être a présent connecté en tant qu'invité. Le serveur est actuellement en maintenance, seuls les administrateurs sont autorisés à se connecter.

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3): 

The first observation is the following: for a given username, it is possible to generate several tokens. Only the end of the token changes, and it appears to be invalidated after 3 minutes.

Inspecting the code to transmit to the administrator confirms the hypothesis that a block cipher is used together with a timestamp:

import binascii
print(binascii.unhexlify("757365726e616d653d613b726f6c653d696e766974653b74696d653d31363733383136303832"))
# b'username=a;role=invite;time=1673816082'

We therefore have a token with a guest role, containing our “username” and a timestamp. In order to verify the block cipher mode, we will use a name composed solely of the letter “a”, with a size equal to or greater than 2 blocks, so as to identify whether similar blocks appear.

Here, the block size is not known, so we can assume it is a standard size of 16 or 32 characters. We therefore enter a nickname of 64*“a”: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.

Note: this behavior can also be identified through an overflow search.

Bonjour et bienvenue sur l'interface CLI du BreizhCTF !

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3): 1
La fonctionnalité d'enregistrement vous permet de récupérer un compte invité.
Renseigner votre nom: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Vous pouvez à présent vous authentifier à l'aide de votre jeton a5ab67d0983fb22424077dc0f740f8ce485f149d0285de4d65c2484b6e8a4c4b485f149d0285de4d65c2484b6e8a4c4b485f149d0285de4d65c2484b6e8a4c4bea2dd7ec51fb011ee56f880daba3001bc99b4e3ad3310f38f71446845eea26311d016fdf40ae85b280f333642c28ab7a.
Celui-ci est valide pour une durée de 3 minutes.

En cas d'erreur, transmettez ce code à votre administrateur: 757365726e616d653d616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161613b726f6c653d696e766974653b74696d653d31363733383136363531.

We thus identify the repetition of the block “485f149d0285de4d65c2484b6e8a4c4b” that encodes our letter “aaaaa..”. The ECB mode is confirmed.

Here the token can be broken down as follows:

- a5ab67d0983fb22424077dc0f740f8ce  # username=aaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- ea2dd7ec51fb011ee56f880daba3001b  # aaaaaaaaa;role=i
- c99b4e3ad3310f38f71446845eea2631  # nvite;time=16738
- 1d016fdf40ae85b280f333642c28ab7a  # 16651  (+ padding)

The block size can be confirmed by adjusting the number of “a” in the username, for example:

- a5ab67d0983fb22424077dc0f740f8ce  # username=aaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- 485f149d0285de4d65c2484b6e8a4c4b  # aaaaaaaaaaaaaaaa
- 6400d13467c58e941b49e82d355e0e46  # ;role=invite;tim
- 0f61379f9547126363282643e16617a5  # e=1673817061  (+ padding)

This block cipher mode appears to be an ECB mode. We are now able to build any block and craft a token with an administrator role and a long lifetime.

To do so, we first need to add padding to our username to complete the first block (here 7 letters).

Next, we craft 2 blocks with an admin role and a time variable:

- ;role=admin;time
- =167381706100000  # padding avec des 0

we therefore have a username equal to: aaaaaaa;role=admin;time=167381706100000.

Bonjour et bienvenue sur l'interface CLI du BreizhCTF !

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3): 1
La fonctionnalité d'enregistrement vous permet de récupérer un compte invité.
Renseigner votre nom: aaaaaaa;role=admin;time=167381706100000
Vous pouvez à présent vous authentifier à l'aide de votre jeton a5ab67d0983fb22424077dc0f740f8ce35d6946370fab48bcb41109e57dd1deb23c4ed6cb17c7ca5269666e965322b656400d13467c58e941b49e82d355e0e468d157cee04febdd333427e0a1fe8fd22.
Celui-ci est valide pour une durée de 3 minutes.

En cas d'erreur, transmettez ce code à votre administrateur: 757365726e616d653d616161616161613b726f6c653d61646d696e3b74696d653d3136373338313730363130303030303b726f6c653d696e766974653b74696d653d31363733383932363831.

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3):

Here we therefore have the following token:

- a5ab67d0983fb22424077dc0f740f8ce  # username=aaaaaaa
- 35d6946370fab48bcb41109e57dd1deb  # ;role=admin;time
- 23c4ed6cb17c7ca5269666e965322b65  # =167381706100000
- 6400d13467c58e941b49e82d355e0e46  # ;role=invite;tim
- 8d157cee04febdd333427e0a1fe8fd22  # e=1673892681

We can therefore send back the token with only the first 3 blocks:

- a5ab67d0983fb22424077dc0f740f8ce  # username=aaaaaaa
- 35d6946370fab48bcb41109e57dd1deb  # ;role=admin;time
- 23c4ed6cb17c7ca5269666e965322b65  # =167381706100000

a5ab67d0983fb22424077dc0f740f8ce35d6946370fab48bcb41109e57dd1deb23c4ed6cb17c7ca5269666e965322b65

username=aaaaaaa;role=admin;time=167381706100000

Entrez votre choix (1,2,3): 2    
Veuillez renseigner votre nom: aaaaaaa
Veuillez renseigner votre jeton d'authentification: a5ab67d0983fb22424077dc0f740f8ce35d6946370fab48bcb41109e57dd1deb23c4ed6cb17c7ca5269666e965322b65
Vous être a présent connecté en tant qu'administrateur. BZHCTF{Oh_Noh_You_Pwned_Ze_BreizhCTF_!}

---------------------------------------
1. Demander un jeton d'authentification
2. S'authentifier
3. Quitter
---------------------------------------

Entrez votre choix (1,2,3):

We therefore have the flag: BZHCTF{Oh_Noh_You_Pwned_Ze_BreizhCTF_!}.

Flag

BZHCTF{Oh_Noh_You_Pwned_Ze_BreizhCTF_!}

Author: Zeecka