# T1612: Build Image on Host

Adversaries may build a container image directly on a host to bypass defenses that monitor for the retrieval of malicious images from a public registry. A remote build request may be sent to the Docket API that includes a Dockerfile that pulls a vanilla base image, such as alpine, from a public or local registry and then builds a custom image upon it.

An adversary may take advantage of that build API to build a custom image on the host that includes malware downloaded from their C2 server, and then they may utilize Deploy Container using that custom image. If the base image is pulled from a public registry, defenses will likely not detect the image as malicious since it's a vanilla image. If the base image already resides in a local registry, the pull may be considered even less suspicious since the image is already in the environment.

Now if adversaries can locate a remote docker API this can actually aid in the process of building a docker on the host where their malicious activities and payloads can run without the intervention of EDR or AV.

In this small example I'll demonstrate that docker images can be set remotely

<figure><img src="https://315180959-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MRh03Vwd4nuiUi3Oje7%2Fuploads%2FpwuBcjzamwSnHJCITf0Q%2Fimage.png?alt=media&#x26;token=351901d9-2026-4284-94af-1f3a8d5efb26" alt=""><figcaption></figcaption></figure>

But if there are images already installed execution can be achieved

<figure><img src="https://315180959-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MRh03Vwd4nuiUi3Oje7%2Fuploads%2FYb8HyzzSDy0oesH5xFIR%2Fimage.png?alt=media&#x26;token=226f3b4b-2d43-47a4-bb15-c8f26f4356d9" alt=""><figcaption></figcaption></figure>

Interacting with the API to enumerate the containers available

<figure><img src="https://315180959-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MRh03Vwd4nuiUi3Oje7%2Fuploads%2F5uh5fTd7ikfpvzvzBbis%2Fimage.png?alt=media&#x26;token=551e7e4d-439a-4e80-9c64-8f169de9a004" alt=""><figcaption></figcaption></figure>

And finally executing commands inside the container and then proceed with steps from their such as Escape to Host or use a Privilege Escalation technique to continue

<figure><img src="https://315180959-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MRh03Vwd4nuiUi3Oje7%2Fuploads%2FDbff4PEXt84XSy5v2s6c%2Fimage.png?alt=media&#x26;token=ddb825a9-7e95-4e65-8772-f12e7e934f58" alt=""><figcaption></figcaption></figure>


---

# 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://dmcxblue.gitbook.io/red-team-notes-2-0/red-team-techniques/privilege-escalation/t1612-build-image-on-host.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.
