whoAMI-scanner を AWS CloudShell で実行して利用している AMI が信頼できる AMI なのか確認してみた

whoAMI-scanner を AWS CloudShell で実行して利用している AMI が信頼できる AMI なのか確認してみた

Clock Icon2025.02.21

Datadog の Security Lab は whoAMI: A cloud image name confusion attack | Datadog Security Labs を公開しています。その記事の中で AWS アカウント内で利用している AMI が信頼できるイメージなのかを確認できるツールである whoAMI-scanner も紹介しています。

本ブログでは、whoAMI-scanner を AWS CloudShell 上で実行して、AWS アカウント内の AMI が信頼できるイメージなのか確認してみました。

AWS CloudShell で whoAMI-scanner を実行する

whoAMI-scanner のインストールにはいくつかのオプションがあり、今回はバイナリリリースを利用する方法で試してみます。README.md に他のインストール方法も含めて記載されています。

バイナリリリースは下記で公開されています。

AWS CloudShell において次のコマンドによりツールを実行できる準備をします。

$ mkdir whoAMI-scanner
$ cd whoAMI-scanner
$ wget https://github.com/DataDog/whoAMI-scanner/releases/download/v1.0.0/whoAMI-scanner_1.0.0_linux_amd64.tar.gz
$ tar -xzf whoAMI-scanner_1.0.0_linux_amd64.tar.gz

次のコマンドで whoAMI-scanner を実行します。

$ ./whoAMI-scanner

実行結果例です。今回の環境では意図的に Public, unverified, & unknown が存在するようにしています。

$ ./whoAMI-scanner
[ 👀 whoAMI-scanner v1.0.0 👀 ] AWS Caller Identity: arn:aws:sts::111122223333:assumed-role/access-role/user
[*] Verbose mode disabled. Only unknown and unverified AMIs will be displayed.
[*] Starting AMI analysis...
[1/5][ap-northeast-1] ami-0573d60aa30d52acd is from an unverified account.
[5/5][ap-northeast-1] ami-000exampleexample is from an unverified account.

Summary Key:
+-------------------------------+-----------------------------------------------------------+
| Term                          | Definition                                                |
+-------------------------------+-----------------------------------------------------------+
| Self hosted                   | AMIs from this account                                    |
| Allowed AMIs                  | AMIs from an allowed account per the AWS Allowed AMIs API |
| Trusted AMIs                  | AMIs from an trusted account per user input to this tool  |
| Verified AMIs                 | AMIs from Verified Accounts (Verified by Amazon)          |
| Shared with me (Private)      | AMIs shared privately with this account but NOT from a    |
|                               | verified, trusted or allowed account. If you trust this   |
|                               | account, add it to your Allowed AMIs API or specify it as |
|                               | trusted in the whoAMI-scanner command line.               |
| Public, unverified, but known | AMIs from unverified accounts, but we found the account   |
|                               | ID in fwdcloudsec's known_aws_accounts mapping:           |
|                               |   https://github.com/fwdcloudsec/known_aws_accounts.      |
|                               | These are likely safe to use but worth investigating.     |
| Public, unverified, & unknown | AMIs from unverified accounts. Be cautious with these     |
|                               | unless they are from accounts you control. If not from    |
|                               | your accounts, look to replace these with AMIs from       |
|                               | verified accounts                                         |
+-------------------------------+-----------------------------------------------------------+

Summary:
 AWS's "Allowed AMI" config status by region
                 Enabled/Audit-mode/Disabled: 0/0/17
                             Total Instances: 5
                                  Total AMIs: 5
                            Self hosted AMIs: 1
                                Allowed AMIs: 0
                                Trusted AMIs: 0
                               Verified AMIs: 1
               Shared with me (Private) AMIs: 1
               Public, unverified, but known: 0
          Public, unverified, & unknown AMIs: 2

Instances created with privately shared AMIs:
 ami-0292eab5277c13112 | ap-northeast-1 | i-00746a9604073840f | Account: 444455556666 | Vendor Name: Unknown | Instance Name: shared-ami | AMI Name: shared-ami

Instances created with AMIs from public unverified accounts:
 ami-0573d60aa30d52acd | ap-northeast-1 | i-0ce1bf41d42184925 | Account: 111122223333 | Vendor Name: Unknown | Instance Name: deleted-self-ami | AMI Name: deleted-self-ami
 ami-000exampleexample | ap-northeast-1 | i-0c5a981499329c3d9 | Account: 777788889999 | Vendor Name: Unknown | Instance Name: public-ami | AMI Name: public-ami

[!] No regions have AWS's "Allowed AMIs" feature enabled or in audit mode.
        Enabling Allowed AMIs protects you against the whoAMI attack.
        Visit https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-allowed-amis.html for more information.

AWS CloudShell 上では下記画像のように色付きで出力されます。

run-whoami-scanner-in-aws-cloudshell-1

今回の環境では 5 つの EC2 インスタンスを用意しており、利用する AMI のパターンを変えています。

run-whoami-scanner-in-aws-cloudshell-2

Verified AMIs としてカウントされているのは、 です。Amazon が提供している Amazon Linux 2023 の AMI を利用しています。

Self hosted としてカウントされているのは、 です。アカウント内で作成した AMI を利用しています。

Shared with me (Private) としてカウントされているのは、 です。アカウントを明示的に指定して共有したプライベート AMI を利用しています。

Public, unverified, & unknown としてカウントされているのは、 です。 は今回のブログのために用意した独自のパブリック AMI です。 は同じアカウントで作成した AMI を利用していますが、インスタンス作成後に削除した状態となります。インスタンス作成後に AMI が削除されている場合は unkwon 扱いとなる場合があるようです。

なお、出力結果の最後の内容は Allowed AMIs 機能を利用することで表示されなくなります。

[!] No regions have AWS's "Allowed AMIs" feature enabled or in audit mode.
        Enabling Allowed AMIs protects you against the whoAMI attack.
        Visit https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-allowed-amis.html for more information.

Allowed AMIs 機能については次のブログで紹介されており、参考になります。

https://dev.classmethod.jp/articles/202412-allowed-amis/

利用が終わった後は次のコマンドでツールを削除しました。

$ cd
$ rm -rf whoAMI-scanner

さいごに

whoAMI attacks について調べている際に、whoAMI-scanner が公開されていることを知ったため試してみました。AWS アカウント内で利用さている AMI が信頼できるかどうかを確認するのに便利なツールでした。また、Allowed AMI 機能の重要さを知るよい機会となりました。

このブログがどなたかのご参考になれば幸いです。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.