首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ansible和apt,如何为可远程攻击的安全漏洞CVE-2014-6271更新bash?

使用Ansible和apt,如何为可远程攻击的安全漏洞CVE-2014-6271更新bash?
EN

Stack Overflow用户
提问于 2014-09-24 19:01:40
回答 1查看 7.3K关注 0票数 3

给定bash的远程代码执行漏洞于2014年9月24日宣布,如何使用Ansible更新基于apt的系统?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-24 19:01:40

这里是我最喜欢的解决方案,在一个相当均匀的环境中。这样做的好处是,与其他人使用的version=latest模式不同,将来更新不会花费太多时间。

代码语言:javascript
复制
- name: update apt cache if not done today
  apt: update_cache=yes cache_valid_time=86400

# http://seclists.org/oss-sec/2014/q3/650
- name: ensure secure ansible, ubuntu 1204 edition
  apt: pkg=bash=4.2-2ubuntu2.5 state=present
  when: ansible_distribution=='Ubuntu' and ansible_distribution_version=='12.04'

- name: ensure secure ansible, ubuntu 1404 edition
  apt: pkg=bash=4.3-7ubuntu1.3 state=present
  when: ansible_distribution=='Ubuntu' and ansible_distribution_version=='14.04'

# based on the following gist and comments below. there have been several exploits, this covers them well.
# https://gist.github.com/kacy/2b9408af04c71fab686e
- name: ensure bash is not vulnerable to 201409 problem
  shell: "foo='() { echo not patched; }' bash -c foo"
  register: command_result
  ignore_errors: yes
  failed_when: "'command not found' not in command_result.stderr"

说明:如果每天更新很多次的话,更新apt缓存是很昂贵的。可以调整缓存时间。代码实际上是测试以确保漏洞是固定的-测试是好的。这将突出显示任何未被编码的发行版/版本所涵盖的主机。

用户@jarv 发布了一个很好的解决方案也是如此。而不是总是更新apt,它只在问题没有得到解决的情况下才这样做。这是最快的解决方案(至少在这个答案中)。jarv也有在链接回购中添加了分发测试。,对于异构环境很有用。

代码语言:javascript
复制
- name: Check if we are vulnerable
  shell: executable=/bin/bash env x='() { :;}; echo vulnerable'  bash -c "echo this is a test"
  register: test_vuln

- name: Apply bash security update if we are vulnerable
  apt: name=bash state=latest update_cache=true
  when: "'vulnerable' in test_vuln.stdout"

- name: Check again and fail if we are still vulnerable
  shell: executable=/bin/bash env x='() { :;}; echo vulnerable'  bash -c "echo this is a test"
  when: "'vulnerable' in test_vuln.stdout"
  register: test_vuln
  failed_when: "'vulnerable' in test_vuln.stdout"

还有其他的方法。Ansible的创建者Michael DeHaan和官方@ansible账户在推特上发布了几个解决方案:

这是一条单线

代码语言:javascript
复制
ansible all -m apt -a 'update_cache=yes name=bash state=latest'

这里有一个更新和检查的解决方案

代码语言:javascript
复制
- name: update apt
  command: apt-get update

- name: update bash
  command: apt-get --only-upgrade install bash

- name: check bash fix
  command: env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
  register: command_result
  failed_when: "'error' not in command_result.stderr"
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26024468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档