13
10

More than 5 years have passed since last update.

Amazon InspectorでEC2のセキュリティをチェックする

Last updated at Posted at 2016-05-17

AWSでセキュリティチェックができるAmazon Inspectorを、素のAmazon Linux(Amazon Linux AMI 2016.03.1)に実施してみましたので、まとめておきます。

手順

1.EC2へのタグ付け

検査対象にEC2インスタンスにタグをつけます。
Inspectorでは検査対象かどうかをタグで判断します。
ここでは Inspector:Trueにしました。

スクリーンショット 2016-05-17 13.19.46.png

2.Agentのインストール

$ curl -O https://d1wk0tztpsntt1.cloudfront.net/linux/latest/install
$ sudo bash install
$ sudo /etc/init.d/awsagent status
Configuration file path : /opt/aws/awsagent/etc/agent.cfg
Configuration status :
Agent version : 1.0.254.23
System release : Amazon Linux AMI release 2016.03 - 4.4.8-20.46.amzn1.x86_64
Daemon : true
Max queue size : 31457280
Log File :
Msgs log max size : 33554432
CodeModules : true
InstanceMetaData : true
PackageInfo : true
NetworkInterfaces : true
Groups : true
Users : true
Terminals : true
ConfigurationInfo : true
    GlobalFile:/etc/bash.bashrc
      : 

動いているみたいです。

3.SNS設定 (SNS通知する場合)

Topicを作成し、[Other topic actions] -> [Edit topic policy]を選択

スクリーンショット 2016-05-17 17.40.04.png

2つの項目ともに[Only these AWS users]を選択し、
arn:aws:iam::406045910587:root
を入力

スクリーンショット 2016-05-17 18.27.52.png

Subscriptionを作成

4.Inspector設定

Inspectorのコンソールにアクセスします。

スクリーンショット 2016-05-17 13.03.30.png

5.Role作成

最初にロールを作ります。
ウィザード通り作りました。

スクリーンショット 2016-05-17 13.05.40.png

6.ターゲットの指定

ターゲットに名前をつけて、インスタンスに適用したタグを選択します。

スクリーンショット 2016-05-17 13.08.51.png

7.テンプレートの指定

テンプレートを指定します。
テンプレートに名前をつけて、検査するルールパッケージを指定します。
とりあえず全部つけました。
所要時間は1時間が推奨らしいです。
ここで指定した時間中データ収集しているみたいで、早く終わることはなさそうな感じでした。
長ければ長いほどいいのか?というのはよく分からないです。
先ほど作ったSNS Topicも設定します。

Slice 1.png

検査できるパッケージは下記になります。

  • Common Vulnerabilities and Exposures

CVEで公開されている脆弱性の監査を行う。
該当のCVEは下記にリストアップされている。

  • CIS Operating System Security Configuration Benchmarks

CISという組織が発行しているセキュリティベンチマークを適用する。
OSごとに用意されているようで、現在は、
Amazon Linux versions 2014.09-2015.03
に対するベンチマークが適用されるらしい。

詳細なドキュメントは下記のフォームからダウンロードできた。
https://benchmarks.cisecurity.org/downloads/multiform/index.cfm

  • Security Best Practices

セキュリティ設定の確認。
チェックされるのはLinux-basedのOSのみ。

SSH設定とか、パーミッションの設定とかあります。

  • Runtime Behavior Analysis

こちらはbehaviorなんで、設定より動作の確認かな。
プロトコルとかポートの確認があります。
Linux Onlyのものと、Linux、Windows両方適用できるものがあります。

8.実行

作成できたら「実行」を押します。

スクリーンショット 2016-05-17 13.15.09.png

ステータスが「データを収集中」になります。

スクリーンショット 2016-05-17 13.15.43.png

実行中はEC2の負荷はほとんど上がらなかったです。
何もしていないインスタンスですが・・・

top - 04:37:20 up 50 min,  1 user,  load average: 0.00, 0.01, 0.01
Tasks:  73 total,   1 running,  72 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.3%st
Mem:   1019340k total,   209272k used,   810068k free,    10756k buffers
Swap:        0k total,        0k used,        0k free,   110608k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2290 root      20   0  602m  29m  12m S  0.3  2.9   0:04.16 awsagent

1時間後、ステータスが分析完了になって、終了です。

スクリーンショット 2016-05-17 14.29.37.png

実行結果

1. Medium : Instance xxxxxxxxxxxxx is configured to allow users to log in with root credentials over SSH. This increases the likelihood of a successful brute-force attack.

  • ルールパッケージ
    • Security Best Practices-1.0
  • 説明
    • This rule helps determine whether the SSH daemon is configured to permit logging in to your EC2 instance as root.
  • 推奨事項
    • It is recommended that you configure your EC2 instance to prevent root logins over SSH. Instead, log in as a non-root user and use sudo to escalate privileges when necessary. To disable SSH root logins, set PermitRootLogin to "no" in /etc/ssh/sshd_config and restart sshd.

PermitRootLogin を "no"にしろってことみたいです。
やっといてよって気が・・・

2. Low : Instance i-xxxxxxxxxxxxx used insecure protocol(s) 80/tcp (http) to connect to a remote host. These protocols pass traffic in the clear, increasing the risk of a successful traffic interception attack.

  • ルールパッケージ
    • Runtime Behavior Analysis-1.0
  • 説明
    • This rule detects client use of insecure protocols.
  • 推奨事項
    • It is recommended that you replace these insecure protocols with encrypted versions.

リモートに接続するときにHTTP使ってるってことかな?
どうしろって言ってるのかよく分からない・・・

3. Informational : Instance i-xxxxxxxxxxx was listening on TCP port(s) 111, 55131, 57093, but no connections to these port(s) were seen during the assessment run.

  • ルールパッケージ
    • Runtime Behavior Analysis-1.0
  • 説明
    • This rule detects listening TCP ports that may not be required by the assessment target.
  • 推奨事項
    • To reduce the attack surface area of your deployments, we recommend that you disable network services that you do not use. Where network services are required, we recommend that you employ network control mechanisms such as VPC ACLs, EC2 security groups, and firewalls to limit exposure of that service.

Linstenしているポートですね。
インスタンス上で確認すると、こんな感じでした。

$ netstat -nl --inet | grep tcp
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:55131               0.0.0.0:*                   LISTEN

57093ってなんなんでしょう?

4. Informational : No potential security issues found

  • ルールパッケージ
    • Common Vulnerabilities and Exposures-1.1
  • 結果
    • No potential security issues found
  • 説明
    • Amazon Inspector did not find any potential security issues during this assessment.
  • 推奨事項
    • No remediation needed.

CVE関連の問題はないってことかと。

5. Informational : Unsupported Operating System or Version

  • ルールパッケージ
    • CIS Operating System Security Configuration Benchmarks-1.0
  • 説明
    • Operating system Amazon Linux AMI release 2016.03, found on the instance i-06f394abd8f926bed, is not supported by this Rules Package. The supported operating systems are: Amazon Linux AMI release 2015.03
  • 推奨事項
    • Not available

Amazon Linux AMI 2016.03.1には対応していないってことですね。

SNSではこんな感じのJSONで通知されます。

{"template":"arn:aws:inspector:ap-northeast-1:xxxxxxxxxxx:target/xxxxxxxx/template/xxxxxxxxx","newstate":"COMPLETED","time":"2016-05-17T10:06:05.929Z","event":"ASSESSMENT_RUN_STATE_CHANGED","target":"arn:aws:inspector:ap-northeast-1:xxxxxxxxxxx:target/xxxxxxx"}

終わったことが分かるっていうくらいですね。

感想

インストールも設定もかなり簡単で、あっさりできました。
簡単にセキュリティ監査ができるというのはかなり使えるんではないかと思います。
タグで対象を指定するというのも一括で行うことを考えると、やりやすいと思います。
折角なので、CISのベンチマークがAmazon Linuxの最新に対応して欲しいですね。

参考

https://aws.amazon.com/jp/inspector/
http://aws.typepad.com/aws_japan/2015/10/amazon-inspector-automated-security-assessment-service.html
https://docs.aws.amazon.com/inspector/latest/userguide/inspector_introduction.html
http://dev.classmethod.jp/cloud/aws/inspector-send-mail-using-sns/
https://docs.aws.amazon.com/ja_jp/inspector/latest/userguide/inspector_assessments.html

13
10
0

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
13
10