LoginSignup
32

More than 3 years have passed since last update.

AWSにおけるsudo脆弱性情報(CVE-2019-14287)の対応状況をまとめてみた (2019/10/16)

Last updated at Posted at 2019-10-16

Linuxのsudoコマンドに、本来root権限を取れないはずのユーザーが、root権限を奪取できるようになる脆弱性が発見されて話題となっています。
私見ですが、ユーザの権限設計上の想定外が発見された状況ですから、早めにパッチを当てるべきと言えそうです。

ふと、AWS上では対応されているのかと思い、備忘録を兼ね、本脆弱性の対応状況を調べてみました。

ネットニュースの記事

下記の記事が大変にバズっており、話題となっています。

Linuxの「sudo」コマンドにroot権限奪取の脆弱性。ユーザーID処理のバグで制限無効化
Linuxのsudoコマンドに、本来root権限をとれないユーザーがそれを奪取できるようになる脆弱性が発見されました。この脆弱性を突けば、sudoを利用する際の権限設定ファイルsudoersを適切に設定していても、sudoを使えるユーザーなら完全なrootレベルでコマンドを実行できるようになるとのこと。すでに修正が施されたsudoコマンドがリリースされています。
https://japanese.engadget.com/2019/10/14/linux-sudo-root-id/

事象

sudoの脆弱性情報(Important: CVE-2019-14287)と新バージョン(1.8.28) (from サイオスセキュリティブログ)
https://security.sios.com/vulnerability/sudo-security-vulnerability-20191015.html

上記ブログで非常に分かりやすく解説されていますが、sudoersで「ALL」、つまり全てのユーザの権限を使ってコマンドを実行できるユーザは、sudoの-uオプションで「-1」もしくは「4294967295」を指定すると、root権限を取れてしまうというものです。
(sudoの-uオプションはユーザ名だけでなく、#UIDを指定しても良い)
上記だけ読めば、それ全てのユーザなんだから当たり前じゃないの?と思うところですが、例えばALL=(ALL,!root)と書いてあった場合、rootが取れないはずなのに、「-1」指定した場合にはrootが取れてしまうということで、想定外(つまり脆弱なポイント)となります。

また、私的には、以下のQiitaの解説が腹落ちしたので、紹介させていただきます。

sudoの脆弱性(CVE-2019-14287)についてまとめてみた
https://qiita.com/task4233/items/80a5ea1c0b4f8e45db2e

※抜粋

  1. sudoersのRunas仕様でALL句を使いつつrootでの実行を明示的に禁止している場合でもrootとして実行可能
  2. この脆弱性を利用した場合, 0(rootのuid)では無い値がログに残る
  3. 実行時にPAMセッションモジュールが実行されない

現実の影響

敢えてものすごく意識の低い書き方をすれば、sudoersに対する認識がroot権限でコマンド実行できるユーザを管理する機能として広まって、そのように利用されている事例が大多数でしょうから、逆に言えば上記のように「(ALL,!root)」と設定されているケースは稀で、現実ではこの脆弱性の影響を受けるケースは稀と言えるのではないかと想像したところです。
ただ、今後悪意を持ってこの脆弱性を突こうと考えたり、そもそもこの脆弱性を知らずして設定を入れてしまって被害を受けたりといったことは想像できますから、パッチを当てるに越したことはありません。

影響があるsudo

sudo < 1.8.28

AWSでの対応状況 2019/10/16

最新のAMIから新しくEC2を起動して調べてみます。

Amazon Linux 2

Amazon Linux 2 のセキュリティセンターでは既に更新が上がっています。
ALAS2-2019-1315
https://alas.aws.amazon.com/AL2/ALAS-2019-1315.html

New Packages:
(略)
x86_64:
sudo-1.8.23-4.amzn2.0.1.x86_64
sudo-devel-1.8.23-4.amzn2.0.1.x86_64
sudo-debuginfo-1.8.23-4.amzn2.0.1.x86_64

バージョンの数字は1.8.28未満ですが、Amazon Linux 2では上記にて対応されているようです。

2019/10/16時点で、AMIは「amzn2-ami-hvm-2.0.20190823.1-x86_64-gp2 (ami-0ff21806645c5e492)」が最新のようです。
一見、対応していないように見えますが、このAMIを使って新規にEC2を起動する場合、最新のアップデートが適用され、脆弱性は解消されています。
公式サイトのFAQにも、以下の記述があります。

Q: Amazon Linux 2 の更新はどこで入手できますか?
Amazon Linux 2 の更新は、各 AWS リージョンでホストされている設定済みリポジトリによって提供されます。(重要かつ必須の) セキュリティ更新は初回起動時に自動的に適用されます。また、インスタンス作成時の必須かつ重要なセキュリティパッチの自動インストールは、有効または無効にすることができます。
https://aws.amazon.com/jp/amazon-linux-2/faqs/

起動したばかりのEC2で実際に見てみると、以下のようになっており、最新パッチが適用されていました。

$ rpm -qa | grep sudo
sudo-1.8.23-4.amzn2.0.1.x86_64

$ sudo cat /var/log/yum.log 
Oct 16 02:08:22 Updated: libnghttp2-1.39.2-1.amzn2.x86_64
Oct 16 02:08:22 Updated: kernel-tools-4.14.146-119.123.amzn2.x86_64
Oct 16 02:08:22 Updated: sudo-1.8.23-4.amzn2.0.1.x86_64

これからAmazon Linux 2のEC2を起動する場合は、自動的に本脆弱性に対処できると言えそうです。
既に起動しているEC2では、yum updateで最新パッチを取りに行けるでしょう。

Amazon Linux

同様に最新パッチが公開されています。
ALAS-2019-1309
https://alas.aws.amazon.com/ALAS-2019-1309.html

New Packages:
(略)
x86_64:
sudo-devel-1.8.6p3-29.28.amzn1.x86_64
sudo-debuginfo-1.8.6p3-29.28.amzn1.x86_64
sudo-1.8.6p3-29.28.amzn1.x86_64

2019/10/16時点の最新と思われる「amzn-ami-hvm-2018.03.0.20190826-x86_64-gp2 (ami-0ab3e16f9c414dee7)」で起動します。
同じように確認すると、こちらも最新パッチが当たっているようです。

$ rpm -qa | grep sudo
sudo-1.8.6p3-29.28.amzn1.x86_64

$ sudo cat /var/log/yum.log 
Oct 16 02:38:09 Updated: libnghttp2-1.31.1-2.5.amzn1.x86_64
Oct 16 02:38:09 Updated: sudo-1.8.6p3-29.28.amzn1.x86_64
Oct 16 02:38:09 Updated: kernel-tools-4.14.146-93.123.amzn1.x86_64

これからAmazon LinuxのEC2を起動する場合は、自動的に本脆弱性に対処できると言えそうです。
既に起動しているEC2では、yum updateで最新パッチを取りに行けるでしょう。

Red Hat Enterprise Linux 8 / CentOS 8

2019/10/16時点で、まだ修正パッチがリリースされていません。(Errataが空欄です)
https://access.redhat.com/security/cve/cve-2019-14287

2019/10/16時点で最新と思われる「RHEL-8.0.0_HVM-20190618-x86_64-1-Hourly2-GP2 (ami-09f31cc5d5eecca1a)」で起動します。
実際に確かめてみますと、sudoのバージョンは1.8.28未満で、最新パッチではないようです。

$ rpm -qa | grep sudo
libsss_sudo-2.0.0-43.el8_0.3.x86_64
sudo-1.8.25p1-4.el8.x86_64

RHEL8では、本脆弱性に対応するパッチは来ていないようですので、対応を待つことになります。
10/20更新: 現時点でもパッチは来ておらず、Amazon LinuxやUbuntuと比較して4日以上多く待っている状況となっています。
10/25更新: RHEL7ではパッチがリリースされましたが、RHEL8は現時点でもパッチは来ておりません。

Ubuntu Server 18.04 LTS

最新パッチが公開されており、アップデートすることで対応できるようです。
USN-4154-1: Sudo vulnerability
https://usn.ubuntu.com/4154-1/

Update instructions
The problem can be corrected by updating your system to the following package versions:
(略)
Ubuntu 18.04 LTS
sudo - 1.8.21p2-3ubuntu1.1
sudo-ldap - 1.8.21p2-3ubuntu1.1

2019/10/16時点で最新と思われる「ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-20191002 (ami-0cd744adeca97abb1)」で起動します。
確認すると、sudoはどうやら最新ではないようです。

$ dpkg -l sudo
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-===========================================================
ii  sudo                        1.8.21p2-3ubuntu1  amd64              Provide limited super user privileges to specific users

そこで、apt-getでsudoを最新化します。

$ sudo apt-get update
Hit:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8570 kB]    
Get:5 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/universe Translation-en [4941 kB]             
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                    
Get:7 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]                          
Get:8 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]              
Get:9 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [753 kB]                  
Get:10 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [271 kB]           
Get:11 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [15.7 kB]           
Get:12 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [4956 B]       
Get:13 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1012 kB]             
Get:14 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [312 kB]         
Get:15 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [7884 B]            
Get:16 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [3944 B]      
Get:17 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [2512 B]                
Get:18 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-backports/main Translation-en [1644 B]
Get:19 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [4020 B]
Get:20 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1856 B]
Get:21 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [530 kB]
Get:22 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [178 kB]
Get:23 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [8872 B]
Get:24 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [3296 B]
Get:25 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [613 kB]
Get:26 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [204 kB]
Get:27 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [5260 B]                                            
Get:28 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [2464 B]                                            
Fetched 18.0 MB in 7s (2457 kB/s)                                                                                                      
Reading package lists... Done

$ sudo apt-get install sudo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  sudo
1 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
Need to get 428 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 sudo amd64 1.8.21p2-3ubuntu1.1 [428 kB]
Fetched 428 kB in 0s (38.7 MB/s)
(Reading database ... 56531 files and directories currently installed.)
Preparing to unpack .../sudo_1.8.21p2-3ubuntu1.1_amd64.deb ...
Unpacking sudo (1.8.21p2-3ubuntu1.1) over (1.8.21p2-3ubuntu1) ...
Setting up sudo (1.8.21p2-3ubuntu1.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

$ dpkg -l sudo
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version             Architecture        Description
+++-============================-===================-===================-=============================================================
ii  sudo                         1.8.21p2-3ubuntu1.1 amd64               Provide limited super user privileges to specific users

上記のように手動でアップデートすることで、脆弱性に対応できました。
既に起動しているEC2でも、同様に最新パッチを取りに行けばOKですね。

Ubuntu Server 16.04 LTS

最新パッチが公開されており、アップデートすることで対応できるようです。
USN-4154-1: Sudo vulnerability
https://usn.ubuntu.com/4154-1/

Update instructions
The problem can be corrected by updating your system to the following package versions:
(略)
Ubuntu 16.04 LTS
sudo - 1.8.16-0ubuntu1.8
sudo-ldap - 1.8.16-0ubuntu1.8

2019/10/16時点で最新と思われる「ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20190913 (ami-0f9af249e7fa6f61b)」で起動します。
確認すると、sudoはどうやら最新ではないようです。

$ dpkg -l sudo
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version             Architecture        Description
+++-============================-===================-===================-=============================================================
ii  sudo                         1.8.16-0ubuntu1.7   amd64               Provide limited super user privileges to specific users

そこで、apt-getでsudoを最新化します。

$ sudo apt-get update
Hit:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]    
Get:4 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [7,532 kB]
Get:5 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/universe Translation-en [4,354 kB]                         
Get:6 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [144 kB]                                    
Get:7 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial/multiverse Translation-en [106 kB] 
Get:8 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1,046 kB]   
Get:9 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [406 kB] 
Get:10 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [767 kB]
Get:11 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [321 kB]
Get:12 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.8 kB]
Get:13 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [8,468 B]
Get:14 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7,280 B]
Get:15 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [4,456 B]
Get:16 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8,064 B]
Get:17 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [4,328 B]
Get:18 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]       
Get:19 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [761 kB]
Get:20 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [295 kB]
Get:21 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [461 kB]
Get:22 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [189 kB]
Get:23 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [5,724 B]
Get:24 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [2,708 B]                                           
Fetched 16.8 MB in 6s (2,561 kB/s)                                                                                                     
Reading package lists... Done

$ sudo apt-get install sudo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  sudo
1 upgraded, 0 newly installed, 0 to remove and 24 not upgraded.
Need to get 390 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 sudo amd64 1.8.16-0ubuntu1.8 [390 kB]
Fetched 390 kB in 0s (36.0 MB/s)
(Reading database ... 51385 files and directories currently installed.)
Preparing to unpack .../sudo_1.8.16-0ubuntu1.8_amd64.deb ...
Unpacking sudo (1.8.16-0ubuntu1.8) over (1.8.16-0ubuntu1.7) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up sudo (1.8.16-0ubuntu1.8) ...

$ dpkg -l sudo
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                         Version             Architecture        Description
+++-============================-===================-===================-=============================================================
ii  sudo                         1.8.16-0ubuntu1.8   amd64               Provide limited super user privileges to specific users 

上記のように手動でアップデートすることで、脆弱性に対応できました。
既に起動しているEC2でも、同様に最新パッチを取りに行けばOKですね。

まとめ

平たく言えば、これから新規にAmazon Linux 2 / Amazon Linux を構築する場合以外は全て手動で要アップデートのようです。

このように比較して初めて知ることですが、Amazon Linuxはセキュリティ対応の面で優秀だと分かりました。
まず、脆弱性への対応速度が早いです。
また、Amazon Linuxでは、公開されているAMIが一見古くても、初回起動時に最新パッチが当たるようになっています。

その他のLinuxでは、上記の通り、対応速度に差があり、また、アップデートは手動での対応となりました。

クラウドロックインだという話はありますが、やはりAWSではAmazon Linuxを使うと何かと安心できる場面が多そうだと感じました。

そして余談ではありますが、このような比較検証がすぐできてしまうというのも、AWSの良い点だと思えるところです。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32