RSS

You are viewing documentation for Falco version: v0.33.1

Falco v0.33.1 documentation is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.

Detect CVE-2020-8557 using Falco

CVE-2020-8557

kubelet管理器在计算pod的临时存储使用量时,不包括kubelet装载在pod中的/etc/hosts文件。如果pod将大量数据写入/etc/hosts文件,可能会填满节点的存储空间,并导致节点失败,这相当于DoS攻击。

严重程度

  • 中等的

受影响的 Kubernetes 版本

  • kubelet v1.18.0-1.18.5
  • kubelet v1.17.0-1.17.8
  • kubelet < v1.16.13

使用 Falco 检测 CVE-2020-8557

检测此漏洞的攻击目的至关重要。Falco是CNCF的开源项目,用于容器和Kuberenetes的运行时威胁检测。您可以使用Falco在主机和容器级别检测恶意活动。Falco在发现异常行为时会生成安全事件,这些异常行为由一组可定制的规则定义。

Falco的好处之一是利用其强大而灵活的规则语言。与此同时,Falco提供了一些现成的检测规则。让我们看看如何检测有人试图利用CVE 2020-8557。

该漏洞是因为kubelet管理器不包括kubelet装载在pod中的/etc/hosts文件。通常,当不可压缩的计算资源消耗(如内存和磁盘)达到退出阈值时,kubelet逐出管理器将开始逐出POD,以保持工作节点和节点上运行的其他POD的可用性。同时,/etc/hosts也是系统的一个重要文件,当您的机器启动时,它需要知道一些主机名到IP地址的映射,然后才能引用DNS。此映射保存在/etc/hosts文件中。在没有名称服务器的情况下,系统上的任何网络程序都会参考此文件来确定与主机名对应的IP地址。在Falco开箱即用规则中,有一个特殊的规则来检测/etc 文件夹下包括/etc/hosts 文件的任何修改。

- rule: Write below etc
  desc: an attempt to write to any file below /etc
  condition: write_etc_common
  output: "File below /etc opened for writing (user=%user.name command=%proc.cmdline parent=%proc.pname pcmdline=%proc.pcmdline file=%fd.name program=%proc.name gparent=%proc.aname[2] ggparent=%proc.aname[3] gggparent=%proc.aname[4] container_id=%container.id image=%container.image.repository)"
  priority: ERROR
  tags: [filesystem, mitre_persistence]

或者,您可以为 CVE 设置此特定规则:

- rule: Detect Write Below /etc/hosts
  desc: an attempt to write to /etc/hosts file (CVE-2020-8557)
  condition: open_write and container and fd.name=/etc/hosts
  output: "File /etc/hosts opened for writing (user=%user.name command=%proc.cmdline parent=%proc.pname pcmdline=%proc.pcmdline file=%fd.name program=%proc.name gparent=%proc.aname[2] ggparent=%proc.aname[3] gggparent=%proc.aname[4] container_id=%container.id image=%container.image.repository)"
  priority: ERROR
  tags: [filesystem, mitre_persistence]

当/etc/host文件发生文件写入活动时,将触发上面的 Falco 规则,他的输出将如下所示:

File /etc/hosts opened for writing (user=root command=bash parent=bash pcmdline=bash file=/etc/hosts program=bash gparent=<NA> ggparent=<NA> gggparent=<NA> container_id=384fc3447d54 image=kaizheh/nginx)

在工作节点上检查文件大小时,您会发现以下内容:

root@ip-172-20-48-137:/home/admin# find /var/lib/kubelet/pods/*/etc-hosts -size +1M
/var/lib/kubelet/pods/a8e75db1-b0cf-487a-ab5c-8041d33824f1/etc-hosts

工作节点上的文件大小/etc/hosts大于 1M。

缓解策略

因为该漏洞的目标是/etc/hosts文件。一个具体的缓解策略是将以下AppArmor配置文件应用于您正在运行的容器:

#include <tunables/global>
 
profile cve-2020-8557 flags=(attach_disconnected,mediate_deleted) {
  #include <abstractions/base>
 
  # accessing to network resources are subject to change per container
  network inet tcp,
  network inet udp,
  network inet icmp,
  deny network raw,
  deny network packet,
 
  file,
  Umount,
 
  # deny writes to /etc/hosts file
  deny /etc/hosts wl,
 
  # capabilities are subject to changes per container
  capability chown,
  capability dac_override,
  capability setuid,
  capability setgid,
}

前面的AppArmor配置文件允许来自容器的大多数活动,但拒绝写入/etc/hosts文件。

结论

在升级之前,应用缓解策略很重要。除了防止漏洞被利用之外,检测或监控 /etc/hosts 文件上的任何文件写入也很重要。查看 Falco 和 Sysdig Secure 了解更多信息以帮助缓解漏洞。

参考

https://github.com/kubernetes/kubernetes/issues/93032
https://kubernetes.io/docs/tasks/administer-cluster/out-of-resource/