AWSセキュリティ【Amazon Inspector】:EC2 インスタンスの脆弱性診断を自動で行うサービス

Amazon Inspectorは、ざっくりいうと「AWSのEC2 インスタンスの脆弱性診断を自動で行ってくれるサービス」です。

  • 脆弱性診断は、nヶ月に一度など定期的に行われるものもあれば、サイトリリース時や実施が検討された時などに1回だけ行われる場合もあります。
  • 脆弱性診断は、実際のサーバに攻撃者の視点でサイバー攻撃を仕掛けることによって、本物のサイバー被害を受ける前にセキュリティリスクを顕在化します。
  • 重要サーバがある大きな企業であれば、脆弱性診断を取り入れているところでしょう。

Amazon Inspectorのルールパッケージ

  1. ネットワークの到達可能性のセキュリティ評価項目のパッケージ
  2. ホスト評価のセキュリティ評価項目のパッケージ

Amazon Inspector の有効化手順

Systems Manager Run Command を使用して EC2 instances にAmazon Inspector エージェントをインストールできます。
これにより、AWS エージェントを複数のインスタンス(Linuxベースおよび Windowsベースの両方)にリモートでインストールできます。


Systems Manager Run Command を使用したエージェントのインストールは、現在 Debian オペレーティングシステムではサポートされていません。
インストールされており、Run Command を許可するIAMロールがあることを確認します。

有効化されました

有効化されました

Amazon Inspector ダッシュボード

Amazon Inspector ダッシュボード

Linux ベースの EC2 instance にエージェントをインストールするには

※ Amazon Inspector の有効化前に、対象AWSのEC2インスタンスにインストールしておきます。

[miko@ip-10-0-0-12 ~]$ sudo -s

[root@ip-10-0-0-12 miko]# wget https://inspector-agent.amazonaws.com/linux/latest/install

--2021-03-22 18:47:23--  https://inspector-agent.amazonaws.com/linux/latest/install
Resolving inspector-agent.amazonaws.com (inspector-agent.amazonaws.com)... 99.84.60.227, 2600:9000:2138:9e00:4:6195:f54f:9c81, 2600:9000:2138:da00:4:6195:f54f:9c81, ...
Connecting to inspector-agent.amazonaws.com (inspector-agent.amazonaws.com)|99.84.60.227|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 31083 (30K)
Saving to: ‘install’

100%[======================================>] 31,083      --.-K/s   in 0s

2021-03-22 18:47:23 (368 MB/s) - ‘install’ saved [31083/31083]

(オプション) Linux ベースのオペレーティングシステムの Amazon Inspector エージェントのインストールスクリプトの署名を確認します。?

[root@ip-10-0-0-12 miko]# sudo bash install

amzn.2.2
Distribution of the machine is Amazon Linux.
Distribution type of the machine is amzn.
Revision of the distro is 2.
Kernel version of the machine is 4.14.209-160.339.amzn2.x86_64.
ip-10-0-0-12.ap-northeast-1.compute.internal is an EC2 instance reporting region as ap-northeast-1.
Check for existing AwsAgent completed with error code:0
Existing version of agent installed is 0.0.0.0.
cannot find installed KM VERSION... assumed '0.0.0.0'
get_installed_km_version: EXISTING_KM_VERSION:0.0.0.0 exit status:0
Existing version of kernel module installed is 0.0.0.0.
PUBKEY_FILE: /tmp/awsagent.uMYww8xT/inspector.gpg
Validated AWS_AGENT_INVENTORY signature with: Primary key fingerprint: DDA0 D4C5 10AE 3C20 6F46  6DC0 2474 0960 5836 0418
HTTP/1.1 200 OK
x-amz-id-2: LSj+/NLpvk8XnB9Zm+RYJSUVqowcg4AABGRJp9O2aL5zcFUqudanY6ZzI3wbKTfY6x6gfV6tUDs=
x-amz-request-id: N4VA1YFW67GVBEMX
Date: Mon, 22 Mar 2021 09:49:01 GMT
Last-Modified: Wed, 03 Mar 2021 16:58:54 GMT
ETag: "505456c80a88af1b15288df1a11dc688"
Accept-Ranges: bytes
Content-Type:
Content-Length: 952
Server: AmazonS3

AGENT_MANIFEST_URL: https://s3.ap-northeast-1.amazonaws.com/aws-agent.ap-northeast-1/linux/releases/1.1.1677.0/AGENT_MANIFEST
AGENT_VERSION_URL:  https://s3.ap-northeast-1.amazonaws.com/aws-agent.ap-northeast-1/linux/releases/1.1.1677.0/VERSION
PUBKEY_FILE: /tmp/awsagent.uMYww8xT/inspector.gpg
Validated AGENT_MANIFEST signature with: Primary key fingerprint: DDA0 D4C5 10AE 3C20 6F46  6DC0 2474 0960 5836 0418
PUBKEY_FILE: /tmp/awsagent.uMYww8xT/inspector.gpg
Validated VERSION signature with: Primary key fingerprint: DDA0 D4C5 10AE 3C20 6F46  6DC0 2474 0960 5836 0418
AGENT_PACKAGE_URL: https://s3.ap-northeast-1.amazonaws.com/aws-agent.ap-northeast-1/linux/releases/1.1.1677.0/amzn-4.14.47-64.38.amzn2.x86_64-x86_64/AwsAgent-1.1.1677.0-102677.x86_64.rpm
EXPECTED_AGENT_PACKAGE_HASH: f25c505fdc25295637b584205e31a58baad683ff88f13cf88811cb715745f4dd
NEW_AGENT_VERSION:1.1.1677.0
AGENT_PACKAGE_NAME:AWSAgent.rpm
Validated agent package sha256 hash matches expected value.
package_install:package_path:     /tmp/awsagent.uMYww8xT/AWSAgent.rpm
package_install:new_version:      1.1.1677.0
package_install:existing_version: 0.0.0.0
package_type                    : agent
/bin/yum
Installing with yum...
yum install -y /tmp/awsagent.uMYww8xT/AWSAgent.rpm
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Examining /tmp/awsagent.uMYww8xT/AWSAgent.rpm: AwsAgent-1.1.1677.0-102677.x86_64
Marking /tmp/awsagent.uMYww8xT/AWSAgent.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package AwsAgent.x86_64 0:1.1.1677.0-102677 will be installed
--> Finished Dependency Resolution
amzn2-core/2/x86_64                                      | 3.7 kB     00:00
amzn2extra-docker/2/x86_64                               | 3.0 kB     00:00
amzn2extra-lamp-mariadb10.2-php7.2/2/x86_64              | 3.0 kB     00:00
amzn2extra-php7.2/2/x86_64                               | 3.0 kB     00:00
epel/x86_64/metalink                                     | 5.8 kB     00:00
epel/x86_64                                              | 4.7 kB     00:00
epel/x86_64/updateinfo                                   | 1.0 MB     00:00
epel/x86_64/primary_db                                   | 6.9 MB     00:00

Dependencies Resolved

================================================================================
 Package         Arch          Version                   Repository        Size
================================================================================
Installing:
 AwsAgent        x86_64        1.1.1677.0-102677         /AWSAgent         34 M

Transaction Summary
================================================================================
Install  1 Package

Total size: 34 M
Installed size: 34 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : AwsAgent-1.1.1677.0-102677.x86_64                            1/1
Redirecting to /bin/systemctl reload crond.service
  Verifying  : AwsAgent-1.1.1677.0-102677.x86_64                            1/1

Installed:
  AwsAgent.x86_64 0:1.1.1677.0-102677

Complete!
HTTP/1.1 200 OK
x-amz-id-2: o8TD4DHrazaNuzFSV5oU84JtodbF8fg5abLziGgfeq4BUaZznje2wxzmFKKKcjaCU9k0DAwiwO8=
x-amz-request-id: VCHRMSM0BYX3BSFN
Date: Mon, 22 Mar 2021 09:49:13 GMT
Last-Modified: Wed, 03 Mar 2021 16:58:54 GMT
ETag: "505456c80a88af1b15288df1a11dc688"
Accept-Ranges: bytes
Content-Type:
Content-Length: 952
Server: AmazonS3

Installation script completed successfully.

Notice:
By installing the Amazon Inspector Agent, you agree that your use is subject to the terms of your existing
AWS Customer Agreement or other agreement with Amazon Web Services, Inc. or its affiliates governing your
use of AWS services. You may not install and use the Amazon Inspector Agent unless you have an account in
good standing with AWS.
*  *  *
Current running agent reports to arsenal endpoint:
Current running agent reports version as: 1.1.1677.0
This install script was created to install agent version:1.1.1677.0
In most cases, these version numbers should be the same.

Amazon Inspector – 評価ターゲット 作成

Amazon Inspector ダッシュボードで、

評価ターゲット → 「作成」
 をクリック

「プレビュー」を選択して、含まれているインスタンスを表示して確認します。
確認したら、
「OK」→「保存」をクリック
評価ターゲット・作成成功  評価ターゲット・作成成功 !!
評価テンプレートを作成 評価テンプレートを作成!!

スキャン実行

評価テンプレート「NEW Assessment Target」のテンプレートにチェックを入れ、 「実行」 をクリック
評価テンプレート「NEW Assessment Target」のテンプレートにチェックを入れ、 「実行」 をクリック(分析完了になってから実行した)
※ 「Run Once」(1回実行)をクリックしたので、「実行」クリックはいらないのかも。最終的に、Report は2つできた??
スキャン実行中
スキャンが実行中となり、直前の実行が「開始準備中」になった。
スキャン中だが、「評価の実行」を見ると、
Download Report レポートをダウンロード可能
Download Report が表示されているものは完了してレポートをダウンロード可能となっている。

設定の翌日の朝、Amazon Inspector稼働状況をチェック!!

良くわかっていなかったが、「1回実行」で実施したので、時間はかかったと思うが、前日実行時にはレポートは出来上がっていたと思われる。

「評価の実行」→

「Download Report 」
をクリック

「Findings report」は脆弱結果だけ
「Full report」は同じく脆弱結果 +該当しなかった項目も全て出力される(大量に出力される)
レポートを Pdf で出力できる
レポートを
HTML / Pdf 形式 で
出力できる
「結果」に脆弱性がCVE番号で表示される 「結果」に脆弱性がCVE番号で
表示される
次項「セキュリティ対応の進め方」では、この一覧上の結果の内容に含まれるCVE番号をキーとして、
修正の仕方を検索して、1つずつ脆弱性を潰していく。

セキュリティ対応の進め方

脆弱性対策は、https://alas.aws.amazon.com/ (Amazon Linux Security Center) から対処方法をGET!!

Amazon Linux Security Center

どちらが選択されているか注意!!

右上の「AmazonLinux」
と「AmazonLinux2」で

一覧が変わるので、EC2によって、変えないと

いつまでもCVE番号を探すはめになる

Amazon Linux Security Center

Amazon Linux Security Center

ALAS番号のリンクで修正方法のページに飛んで、修正方法を確認して、これを実施して、脆弱性を1つ1つ潰していく。

AWSセキュリティ TIPSはこちら!

「セキュリティ機能全体像」はこちら!