> For the complete documentation index, see [llms.txt](https://writeups.ayweth20.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://writeups.ayweth20.com/2025/404ctf-2025/intelligence-artificielle/gorfoustral-1-3.md).

# Gorfoustral (1/3)

**Catégorie:** Intelligence Artificielle - **Difficulté:** Intro

{% file src="/files/qmywfVoNZERLW938dycS" %}

{% file src="/files/0x3xFEgXXNZdz9vXkIWt" %}

{% file src="/files/wiL7cuaEL7B4z6dEfNpy" %}

**Description:**

<figure><img src="/files/GCldM8241NtVK0il1xxM" alt=""><figcaption></figcaption></figure>

Solution:

Pour ce chall, il faut laisser tourner le modèle et au bout de quelques minutes il nous donne le flag en clair.

Voici le script utilisé pour résoudre ce chall :&#x20;

```python
import torch
from gorfougym import load_model

# 1. Chargement du modèle Gorfoustral (GPT-2 medium fine-tuné) sur CPU en dtype par défaut (bfloat16)
model = load_model("gorfoustral-1_300M.pt", device="cpu")

# 2. Préparation du prompt initial pour la complétion
prompt = "User: 404CTF{"
tokens = model.to_tokens(prompt)  # Conversion du prompt en tokens pour le modèle

# 3. Génération gloutonne (deterministe) d'un nombre suffisant de tokens pour obtenir le flag et la réponse
# On génère jusqu'à 100 tokens supplémentaires (ce qui couvre largement la longueur du flag + "Assistant: True")
output_tokens = model.generate(tokens, max_new_tokens=100, temperature=0.0)

# Conversion des tokens de sortie en texte brut
output_text = model.to_string(output_tokens[0])

# 4. Extraction du flag à partir du texte généré
# On trouve les positions de la première occurrence de "404CTF{" et de la première '}' qui suit
start_index = output_text.find("404CTF{")
end_index = output_text.find("}", start_index)
if start_index != -1 and end_index != -1:
    flag_content = output_text[start_index + len("404CTF{"): end_index]
    found_flag = "404CTF{" + flag_content + "}"
else:
    raise ValueError("Le flag n'a pas été trouvé dans la sortie du modèle.")

# 5. Affichage du flag
print(found_flag)
```

Après quelques minutes (ou secondes selon votre machine), le résultat s'affiche en clair :&#x20;

<figure><img src="/files/yMMfrC4pdEzRk8zDJsVY" alt=""><figcaption></figcaption></figure>

<details>

<summary>🚩FLAG</summary>

`404CTF{ce_magnifique_model_tiendrait_dans_votre_poche!}`

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://writeups.ayweth20.com/2025/404ctf-2025/intelligence-artificielle/gorfoustral-1-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
