
An example detection and remediation policy.
#+Title: CVE-2016-2118 清单与修复 #+SETUPFILE: ~/src/org-html-themes/setup/theme-readtheorg.setup
[[file:./media/badlock.png]]
此策略通过检查系统上是否安装了已知存在漏洞的软件包版本,来检测易受 [[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-2118][CVE-2016-2118]](通常称为 [[http://badlock.org][Badlock]])攻击的主机。修复策略将 =samba= 保持为 =latest= 可用版本。
注意: 该策略目前仅覆盖 CentOS 5 和 6。请考虑为更多平台提供支持。
此策略通过传统(但写得糟糕)的 [[file:Makefile][Makefile]] 进行安装。要安装,只需克隆此仓库,然后运行 make install MASTERFILES=</path/to/policy_root>。
例如: #+BEGIN_SRC sh :results raw :wrap EXAMPLE make install MASTERFILES=/tmp/example-a10042 #+END_SRC
#+RESULTS: #+BEGIN_EXAMPLE mkdir -p /tmp/example-a10042/services/cfengine-CVE-2016-2118/cfengine-CVE-2016-2118 rsync -avz --exclude /home/nickanderson/vagrant/tmp/eia/CVE/masterfiles/services/cfengine-CVE-2016-2118/* /tmp/example-a10042/services/cfengine-CVE-2016-2118/ sending incremental file list Makefile README.org main.cf data/ data/centos_5.json data/centos_6.json media/ media/badlock.png
sent 19,776 bytes received 165 bytes 39,882.00 bytes/sec total size is 29,079 speedup is 1.46 find /tmp/example-a10042/services/cfengine-CVE-2016-2118/ -type f | xargs chmod 600 find /tmp/example-a10042/services/cfengine-CVE-2016-2118/ -type d | xargs chmod 700 #+END_EXAMPLE
将策略安装到你的策略集后,你需要将其添加到 inputs 中,以便它被解析。
如果你运行的是 CFEngine =3.7.3=、=3.8.1= 或更高版本,可以使用 [[https://docs.cfengine.com/docs/master/reference-language-concepts-augments.html][augments 文件]] 将其添加到 inputs 中。
例如: #+BEGIN_SRC json { "inputs": [ "services/cfengine-CVE-2016-2118/main.cf" ] } #+END_SRC
** =inventory_CVE_2016_2118= 此 bundle 检查已安装的 samba 版本是否与 =data/$(sys.flavor).json= 中定义的已知易受攻击版本匹配,例如:=data/centos_6.json=。当然还有其他方法,比如使用包管理器本身来查找易受攻击的版本。
这是一个自动运行 bundle,因此如果你正在使用 [[https://github.com/cfengine/masterfiles/][Masterfiles Policy Framework]](CFEngine 默认附带的策略),你可以简单地定义 =services_autorun= 类。
#+BEGIN_SRC json { "inputs": [ "services/cfengine-CVE-2016-2118/main.cf" ], "classes": { "services_autorun": [ "any" ] } } #+END_SRC
注意: 当策略运行并检测到易受攻击的主机时,它会输出一条报告并定义类 =CVE_2016_2118=。
例如:
#+BEGIN_EXAMPLE R: Detected Vulnerability: CVE-2016-2118 #+END_EXAMPLE
CFEngine Enterprise 用户将在 Mission Portal 中看到库存报告界面新增了一个 =Vulnerable CVE(s)= 属性。
例如:
[[file:./media/vulnerable_cves_inventory_attribute.png]]
[[file:./media/inventory_report_vulnerable_cves.png]]
[[file:./media/inventory_report_vulnerable_cves_chart.png]]
[[file:./media/define_alert.png]]
[[file:./media/alert_status_vulnerable_hosts.png]]
** =remediate_CVE_2016_2118= =remediate_CVE_2016_2118= 也是一个自动运行 bundle,但仅在定义了 =remediate_CVE_2016_2118= 类时才会运行。
有多种方式可以灵活地表示哪些主机以及哪些时间段允许自动修复。
如果你运行的是 =3.7.3=、=3.8.1= 或更高版本,可以通过将其添加到 [[https://docs.cfengine.com/docs/master/reference-language-concepts-augments.html][augments 文件]] 来为整个基础设施启用它。
#+BEGIN_SRC json { "inputs": [ "services/cfengine-CVE-2016-2118/main.cf" ], "classes": { "services_autorun": [ "any" ], "remediate_CVE_2016_2118": [ "any" ] } } #+END_SRC
该策略会在一个以系统类型命名的 JSON 数据文件中查找已知易受攻击的软件包列表,该文件类型由 =$(sys.flavor)= 标识,例如 [[file:data/centos_6.json][=centos_6=]]。