ansible生產環境使用場景(六):sudo漏洞修復

一、sudo漏洞說明

監測到sudo堆溢出漏洞(CVE-2021-3156),成功利用此漏洞,任何沒有特權的用戶都可以在易受***的主機上獲得root特權,需要將sudo版本更新至1.8.23-10及以上版本。

二、環境說明

主機名 操作系統版本 ip gcc版本 sudo版本 備註
ansible-tower Centos 7.6.1810 172.16.7.100 / / ansible管理服務器
157 Centos 7.6.1810 172.16.7.150 4.8.5 1.8.23 被管服務器
158 Centos 7.6.1810 172.16.7.158 / 1.8.23 被管服務器

三、漏洞修復方式

  • yum方式
  • 源碼方式

yum方式需先更新yum源,然後直接執行yum install sudo即可;源碼方式需下載對應的源文件然後編譯安裝,本文重點介紹源碼方式,使用ansible方式對雲上服務器進行批量升級。

四、安裝包下載

目前最新的穩定版本爲1.9.5,下載地址爲:https://www.sudo.ws/dist/sudo-1.9.5p2.tar.gz

五、yaml文件說明

---
- hosts: "{{ hostlist }}"
  gather_facts: no
  tasks:
  - name: gcc check
    shell:
      gcc -v
    register: gcc
    ignore_errors: true

  - name: install gcc
    yum:
      name=gcc
      state=present
    when: gcc.rc != 0

  - name: Unarchive sudo 
    unarchive:
      src: /tmp/sudo-1.9.5p2.tar.gz 
      dest: /root
      mode: 0755
      owner: root
      group: root

  - name: install sudo
    shell: |
      cd /root/sudo-1.9.5p2/
      ./configure --prefix=/usr --libexecdir=/usr/lib --with-secure-path --with-all-insults --with-env-editor --docdir=/usr/share/doc/sudo-1.9.5p2 --with-passprompt="[sudo] password for 
%p: "
      make && make install && ln -sfv libsudo_util.so.0.0.0 /usr/lib/sudo/libsudo_util.so.0

image-20210201170924497

  • "{{ hostlist }}":執行對象,在執行時通過參數'-e hostlist='傳入;
  • 'gcc check':檢查gcc是否安裝,如果未安裝則忽略報錯讓安裝進程繼續;
  • 'install gcc':安裝gcc,當gcc安裝的檢查結果不爲0即未安裝gcc時進行gcc的安裝;
  • 'Unarchive sudo':解壓安裝包並上傳到目標服務器/root目錄;
  • 'install sudo':進行sudo源碼安裝;

六、執行過程及驗證

[root@ansible-tower ansible]# ansible-playbook sudo.yaml -e hostlist=all
[root@ansible-tower ansible]# ansible -m shell -a "sudo --version|grep 'Sudoers audit plugin version'" all

image-20210201171722107

完成兩臺服務器sudo升級,版本爲1.9.5

本文所有腳本和安裝包文件已上傳github:ansible-production-practice-6

更多請點擊:ansible系列文章

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章