如何检查 Docker 镜像是否存在漏洞_docker1,还在等机会

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注网络安全)
img

正文

为了帮助大家避免这种情况的发生,我给大家介绍几个检查 Docker 镜像是否存在漏洞的方法:

方法一:使用 Docker 镜像扫描工具

这是最简单的方法之一。你只需要安装一个 Docker 镜像扫描工具,然后运行它来扫描你的 Docker 镜像。 这些工具可以帮助你匹配已知的安全漏洞,从而判断镜像是否存在漏洞。

给大家讲一个好玩的,缓解下大家的学习疲劳吧!

使用 Docker 镜像扫描工具可以帮你发现你的 Docker 镜像中隐藏的惊天秘密!比如说,你可能会发现你的镜像里面竟然藏着一只小猫咪,或者一份已经过期的披萨!

但是,别担心,使用 Docker 镜像扫描工具可以帮你找到这些问题,并解决它们。下面,我们就来看看如何使用 Docker 镜像扫描工具吧!

首先,你需要安装 Docker 镜像扫描工具。这个过程非常简单,就像下单外卖一样方便。只需要在终端里输入以下命令:

sudo apt-get install docker-bunny-scanner

然后,你就可以开始使用 Docker 镜像扫描工具了!比如说,你可以输入以下命令来扫描你的 Docker 镜像:

docker-bunny-scanner scan -i {你的镜像名称}0

等待一段时间后,你就可以得到一个详细的报告,告诉你镜像里面都有什么秘密。有时候,你可能会发现镜像里面的秘密非常奇怪,比如说一份过期的披萨或者一只小猫咪。但是,别担心,这些问题都可以通过更新你的镜像或者删除它们来解决。

好啦!到这里我们回到正题,在这里具体来跟大家讲讲如何使用 Docker 镜像扫描工具来判断镜像是否存在漏洞。

1. 如何使用 Docker 镜像扫描工具来判断镜像是否存在漏洞

根据上文大家了解了Docker 镜像扫描工具可以帮助我们检测 Docker 镜像中是否存在问题和漏洞的。所以,以下就是使用 Docker 镜像扫描工具的步骤:

安装 Docker 镜像扫描工具
  1. 目前市面上有很多种 Docker 镜像扫描工具可供选择,如 Anchore、Clair、Trivy 等。

a. 以 Trivy 为例,使用以下命令进行安装:

1. $ wget <https://github.com/aquasecurity/trivy/releases/download/v0.19.2/trivy_0.19.2_Linux-64bit.tar.gz>
$ tar zxvf trivy_0.19.2_Linux-64bit.tar.gz
$ sudo mv trivy /usr/local/bin/

下载要扫描的 Docker 镜像

$ docker pull {镜像名}:{标签}

运行 Docker 镜像扫描工具

$ trivy {镜像名}:{标签}

  1. 查看扫描结果

扫描结果会显示镜像中存在的漏洞信息。根据结果可以针对性地对镜像进行修复。

以上就是使用 Docker 镜像扫描工具来判断镜像是否存在漏洞的详细步骤。

举个例子,我们可以使用以下命令来扫描一个名为 ubuntu 的镜像:

$ trivy ubuntu:latest

扫描结果会显示该镜像中存在的漏洞信息。

最后,我想和大家分享一个生活案例。有一天,我在扫描我的 Docker 镜像时,发现里面居然有一份已经过期的牛奶!我很震惊,因为我从来没有在我的 Docker 镜像里面存过牛奶。于是,我开始调查这个问题,最终发现是我的同事偷偷地在我的 Docker 镜像里面存放了牛奶。不过,我很快就解决了这个问题,把牛奶删除了。哈哈哈,这个笑话真冷!

总之,使用 Docker 镜像扫描工具可以帮你发现你的 Docker 镜像中的问题,并解决它们。希望这篇文章能够帮助你更好地使用 Docker 镜像扫描工具!

方法二:手动检查 Docker 镜像

你知道吗?有些人花了一整天的时间来准备自己的 Docker 镜像,只为了在运行时发现它存在漏洞。这真的很令人沮丧,就像在购物时发现自己账户的余额不足一样。所以,我们需要了解如何手动检查 Docker 镜像以确保它们没有安全问题。

首先,我们需要一个有漏洞的 Docker 镜像。

我曾经有个朋友,他经常把自己的垃圾放在公共地方。一天,他发现他的垃圾里有人留下了一个有漏洞的 Docker 镜像。他决定接受这个挑战,看看能否找出其中的漏洞并修复它。

接下来,我们需要一个工具来扫描 Docker 镜像中的漏洞。我曾经听说过一个叫做“大黄蜂”的工具,它可以扫描 Docker 镜像并发现其中的漏洞。但是,我朋友对此并不满意。他认为这个工具太过简单,而且很容易被攻击者绕过。

于是,他决定采用一种更加复杂的方法。他花了一整天的时间来手动检查 Docker 镜像中的每一个组件,以确保它们没有漏洞。他甚至开始梦想着成为一名黑客。

然而,他很快就发现了一个问题:这个方法太过耗时。他花了整整一个星期才完成了这个任务,而且他的垃圾桶已经满了。

于是,他决定寻找一种更加高效的方法。他开始阅读有关 Docker 镜像和漏洞扫描的文献,并学习了一些新的技能。最终,他发现了一个叫做“Clair”的工具,它可以自动扫描 Docker 镜像中的漏洞,并生成报告。

这个工具真的很神奇!它只需要几分钟的时间就可以扫描一个 Docker 镜像,并告诉你其中存在的漏洞。而且,它还可以帮助你修复这些漏洞。

现在,我朋友已经成为了一名 Docker 镜像的专家。他不再把自己的垃圾扔在公共地方,而是将它们放在一个安全的地方,并确保其中不存在任何漏洞。

所以,如果你也想成为一名 Docker 镜像的专家,那么就一定要学会手动检查 Docker 镜像以确保它们没有安全问题。同时,你也可以使用一些自动化工具来提高效率。记住,安全永远是第一位的!

1. 如何使用 手动检查 Docker 镜像来判断镜像是否存在漏洞

首先需要安装一个叫做 Docker Bench 的工具,该工具可以检查 Docker 镜像中是否存在安全漏洞。可以通过以下命令在 Linux 系统上安装 Docker Bench:

sudo docker run -it --net host --pid host --userns host --cap-add audit_control \
    -e DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST \
    -v /var/lib:/var/lib \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /usr/lib/systemd:/usr/lib/systemd \
    -v /etc:/etc --label docker_bench_security \
    docker/docker-bench-security

安装完成后,可以使用以下命令对镜像进行检查:

sudo docker run -it --net host --pid host --userns host --cap-add audit_control \
    -e DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST \
    -v /var/lib:/var/lib \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /usr/lib/systemd:/usr/lib/systemd \
    -v /etc:/etc --label docker_bench_security \
    docker/docker-bench-security

检查完成后,Docker Bench 会输出一个报告,报告中会包含镜像中存在的漏洞及其严重程度等信息。

以下是使用 Docker Bench 对一个叫做 nginx 的 Docker 镜像进行检查的示例:

sudo docker run -it --net host --pid host --userns host --cap-add audit_control \
    -e DOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST \
    -v /var/lib:/var/lib \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /usr/lib/systemd:/usr/lib/systemd \
    -v /etc:/etc --label docker_bench_security \
    docker/docker-bench-security

# 输出信息
[INFO] 1 - Host Configuration
[INFO] 1.1 - Ensure a separate partition for containers has been created (Scored)
[INFO] 1.2 - Ensure the container host has been Hardened (Not Scored)
[INFO] 1.3 - Ensure auditing is configured for the Docker daemon (Scored)
[INFO] 1.4 - Ensure auditing is configured for Docker files and directories - /var/lib/docker (Scored)
[INFO] 1.5 - Ensure auditing is configured for Docker files and directories - /etc/docker (Scored)
[INFO] 1.6 - Ensure auditing is configured for Docker files and directories - docker.service (Scored)
[INFO] 1.7 - Ensure auditing is configured for Docker files and directories - docker.socket (Scored)
[INFO] 1.8 - Ensure the Docker socket file ownership is set to root:docker (Scored)
[INFO] 1.9 - Ensure the Docker socket file permissions are set to 660 or more restrictive (Scored)
[INFO] 2 - Docker daemon configuration
[INFO] 2.1 - Ensure network traffic is restricted between containers on the default bridge (Scored)
[INFO] 2.2 - Ensure the logging level is set to 'info' (Scored)
[INFO] 2.3 - Ensure Docker is allowed to make changes to iptables (Scored)
[INFO] 2.4 - Ensure insecure registries are not used (Scored)
[INFO] 2.5 - Ensure aufs storage driver is not used (Scored)
[INFO] 2.6 - Ensure TLS authentication for Docker daemon is configured (Scored)
[INFO] 2.7 - Ensure the default ulimit is configured appropriately (Scored)
[INFO] 2.8 - Enable user namespace support (Scored)
[INFO] 2.9 - Ensure the default seccomp profile is not Disabled (Scored)
[INFO] 3 - Docker daemon configuration files
[INFO] 3.1 - Ensure that docker.service file ownership is set to root:root (Scored)
[INFO] 3.2 - Ensure that docker.service file permissions are set to 644 or more restrictive (Scored)
[INFO] 3.3 - Ensure that docker.socket file ownership is set to root:root (Scored)
[INFO] 3.4 - Ensure that docker.socket file permissions are set to 644 or more restrictive (Scored)
[INFO] 3.5 - Ensure that /etc/docker directory ownership is set to root:root (Scored)
[INFO] 3.6 - Ensure that /etc/docker directory permissions are set to 755 or more restrictive (Scored)
[INFO] 3.7 - Ensure that registry certificates are rotated (Scored)
[INFO] 4 - Container Images and Build File
[INFO] 4.1 - Ensure a user for the container has been created (Scored)
[INFO] 4.2 - Ensure that containers use trusted base images (Not Scored)
[INFO] 4.3 - Ensure unnecessary packages are not installed in the container (Scored)
[INFO] 4.4 - Ensure images are scanned and rebuilt to include security patches (Not Scored)
[INFO] 5 - Container Runtime
[INFO] 5.1 - Ensure AppArmor Profile is Enabled (Scored)
[INFO] 5.2 - Ensure SELinux security options are set, if applicable (Scored)
[INFO] 5.3 - Ensure Linux Kernel Capabilities are restricted within containers (Scored)
[INFO] 5.4 - Ensure privileged containers are not used (Scored)
[INFO] 5.5 - Ensure sensitive host system directories are not mounted on containers (Scored)
[INFO] 5.6 - Ensure sshd is not run within containers (Scored)
[INFO] 5.7 - Ensure privileged ports are not mapped within containers (Scored)
[INFO] 5.8 - Ensure only needed ports are open on the container (Not Scored)
[INFO] 5.9 - Ensure the host's process namespace is not shared (Scored)
[INFO] 5.10 - Ensure the host's IPC namespace is not shared (Scored)
[INFO] 5.11 - Ensure the host's PID namespace is not shared (Scored)
[INFO] 5.12 - Ensure the host's network namespace is not shared (Scored)
[INFO] 5.13 - Ensure memory usage for container is limited (Scored)
[INFO] 5.14 - Ensure CPU priority is set appropriately on the container (Not Scored)
[INFO] 5.15 - Ensure the container's root filesystem is mounted as read only (Scored)
[INFO] 6 - Docker Swarm Configuration
[INFO] 6.1 - Ensure Swarm is not running in auto-pilot mode (Scored)
[INFO] 6.2 - Ensure TLS authentication for Docker Swarm is configured (Scored)
[INFO] 6.3 - Ensure that Docker Swarm admin port is not bind to a specific IP address (Scored)
[INFO] 6.4 - Ensure that Docker Swarm management plane is separated from worker plane (Scored)
[INFO] 6.5 - Ensure that Docker Swarm services are bind to appropriate network interfaces (Scored)
[INFO] 6.6 - Ensure that Docker Swarm service secrets are encrypted in transit (Scored)
[INFO] 6.7 - Ensure that Docker Swarm service configs are encrypted in transit (Scored)
[INFO] 6.8 - Ensure that Docker Swarm node certificates are rotated (Scored)
[INFO] 7 - Kubernetes
[INFO] 7.1 - Ensure that the --anonymous-auth argument is not set to true (Scored)
[INFO] 7.2 - Ensure that the --basic-auth-file argument is not set (Scored)
[INFO] 7.3 - Ensure that the --insecure-bind-address argument is not set (Scored)
[INFO] 7.4 - Ensure that the --insecure-port argument is set to 0 (Scored)
[INFO] 7.5 - Ensure that the --secure-port argument is not set to 0 (Scored)
[INFO] 7.6 - Ensure that the --tls-cert-file and --tls-private-key-file arguments are set (Scored)
[INFO] 7.7 - Ensure that the --tls-cert-file and --tls-private-key-file arguments are set to a valid path (Scored)
[INFO] 7.8 - Ensure that the --tls-cert-file and --tls-private-key-file arguments permissions are set to 644 or more restrictive (Scored)
[INFO] 7.9 - Ensure that the --tls-cipher-suites argument is set to a secure cipher suite (Scored)
[INFO] 7.10 - Ensure that the --tls-min-version argument is set to 1.2 (Scored)
[INFO] 7.11 - Ensure that the admission control plugin EventRateLimit is set (Scored)
[INFO] 7.12 - Ensure that the admission control plugin AlwaysAdmit is not set (Scored)
[INFO] 7.13 - Ensure that the admission control plugin AlwaysPullImages is set (Scored)
[INFO] 7.14 - Ensure that the admission control plugin SecurityContextDeny is set (Scored)
[INFO] 7.15 - Ensure that the --profiling argument is set to false (Scored)
[INFO] 7.16 - Ensure that the --repair-malformed-updates argument is set to false (Scored)
[INFO] 7.17 - Ensure that the --insecure-allow-any-token argument is not set to false (Scored)
[INFO] 7.18 - Ensure that the --kubelet-certificate-authority argument is set (Scored)


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注网络安全)**
![img](https://img-blog.csdnimg.cn/img_convert/032b8c7d5e1ea85076bc23edf3d2581a.png)

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

elet-certificate-authority argument is set (Scored)


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注网络安全)**
[外链图片转存中...(img-tCUfOrzO-1713372622309)]

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 21
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值