Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save theqwan-chengwei/d298459244a1f006ec67072d177e37ff to your computer and use it in GitHub Desktop.
Save theqwan-chengwei/d298459244a1f006ec67072d177e37ff to your computer and use it in GitHub Desktop.
ImageTragick (CVE-2016–3714). use ansible update policy file to disable the vulnerable ImageMagick coders.
---
- name: check ImageMagick folder exists
stat:
path: /etc/ImageMagick
register: check_imagemagick_folder_exists
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: apt-get update imagemagick 8:6.7.7.10-6ubuntu3.1
apt: pkg={{ item }} state=latest
when: (check_imagemagick_folder_exists.stat.exists == true)
with_items:
- imagemagick
- imagemagick-common
- libmagickcore5
- libmagickcore5-extra
- libmagickwand5
- name: comment policymap
lineinfile:
dest: /etc/ImageMagick/policy.xml
backrefs: yes
regexp: "^{{ item }}"
line: "<!-- {{ item }} -->"
when: (check_imagemagick_folder_exists.stat.exists == true)
with_items:
- ' <policy domain="coder" rights="none" pattern="EPHEMERAL" />'
- ' <policy domain="coder" rights="none" pattern="URL" />'
- ' <policy domain="coder" rights="none" pattern="HTTPS" />'
- ' <policy domain="coder" rights="none" pattern="MVG" />'
- ' <policy domain="coder" rights="none" pattern="MSL" />'
- ' <policy domain="coder" rights="none" pattern="TEXT" />'
- ' <policy domain="coder" rights="none" pattern="SHOW" />'
- ' <policy domain="coder" rights="none" pattern="WIN" />'
- ' <policy domain="coder" rights="none" pattern="PLT" />'
- ' <policy domain="path" rights="none" pattern="@\*" />'
- '</policymap>'
- name: add policymap
lineinfile: >
dest=/etc/ImageMagick/policy.xml
insertafter=EOF
line={{ item }}
when: (check_imagemagick_folder_exists.stat.exists == true)
with_items:
- ' <policy domain="coder" rights="none" pattern="EPHEMERAL" />'
- ' <policy domain="coder" rights="none" pattern="URL" />'
- ' <policy domain="coder" rights="none" pattern="HTTPS" />'
- ' <policy domain="coder" rights="none" pattern="MVG" />'
- ' <policy domain="coder" rights="none" pattern="MSL" />'
- ' <policy domain="coder" rights="none" pattern="TEXT" />'
- ' <policy domain="coder" rights="none" pattern="SHOW" />'
- ' <policy domain="coder" rights="none" pattern="WIN" />'
- ' <policy domain="coder" rights="none" pattern="PLT" />'
- ' <policy domain="path" rights="none" pattern="@*" />'
- '</policymap>'
@theqwan-chengwei
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment