ImageMagickにリモートコード実行が可能となる脆弱性
スポンサーリンク
サムネイル作成でお馴染みの ImageMagick にリモートコード実行が可能となる脆弱性が見つかったようです。
本脆弱性には ImageMagick という名前が付けられ(ロゴ画像あり)、以下のサイトで再現方法および対策が公開されています。
本記事では対策についてだけ簡単にまとめておきます。
Verify that all image files begin with the expected "magic bytes" corresponding to the image file types you support before sending them to ImageMagick for processing. (see FAQ for more info)
Use a policy file to disable the vulnerable ImageMagick coders. The global policy for ImageMagick is usually found in “/etc/ImageMagick”. The below policy.xml example will disable the coders EPHEMERAL, URL, MVG, and MSL.
つまり、ファイルの先頭のマジックバイトで実際に画像ファイルであるかを確認するか、設定ファイル(policy.xml) に次の設定を追加することでEPHEMERAL,URL,HTTPS,MVG,MSLというコーダを無効化すれば良いそう。
<policymap> <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" /> </policymap>
両方やるのが好ましいとは書いてありますが、前者の対策はプログラムの修正が必要になると思うので、GW中で時間がない企業戦士は取り急ぎ policy.xml での対策を実施するのがよさそうですね。
なお、PoC も公開されていますので、policy.xml で対応された場合はさくっと検証しておくことをおすすめします。
以下は手元で実施した対策前後での検証結果です。ご参考まで。
$ git clone https://github.com/ImageTragick/PoCs $ cd PoCs $ ./test.sh testing read UNSAFE testing delete UNSAFE tr: Illegal byte sequence testing http with nonce: SAFE testing rce1 UNSAFE testing rce2 SAFE testing MSL UNSAFE $ cat > policy.xml <<EOF <policymap> <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" /> </policymap> EOF $ ./test.sh testing read SAFE testing delete SAFE tr: Illegal byte sequence testing http with nonce: SAFE testing rce1 SAFE testing rce2 SAFE testing MSL SAFE