LoginSignup
3
2

More than 1 year has passed since last update.

Trivyで、AWSのサービス自体を手軽にスキャンする

Last updated at Posted at 2023-03-22

前提条件

各種サービスが閲覧できるIAMユーザーで、AWS管理コンソールにログインしている。(この記事はAdministratorAccessで実施)

この記事について

Dockerイメージの脆弱性スキャナーとして有名な「Trivy」が、AWSのサービス自体をスキャンできるようになりました。
https://trivy.dev/

気軽に試してみたい方のために、AWS CloudShellで実行する手順をまとめました。
下記のコマンドを実行して下さい。

$ curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.38.1
$ trivy aws

「v0.38.1」の所はバージョンになるので、こちらのリンクで最新のバージョンをご確認下さい。
https://github.com/aquasecurity/trivy/releases

「trivy aws」だと、全体のスキャンを実行します。

[cloudshell-user@ip-10-2-46-188 ~]$ trivy aws
2023-03-03T08:42:07.890Z        INFO    Need to update the built-in policies
2023-03-03T08:42:07.890Z        INFO    Downloading the built-in policies...
39.14 KiB / 39.14 KiB [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% ? p/s 0s
[1/32] Scanning accessanalyzer...
[2/32] Scanning api-gateway...
[3/32] Scanning athena...

中略

Scan Overview for AWS Account xxxxxxxxxxxx
┌────────────────┬──────────────────────────────────────────────────┬──────────────┐
│                │                Misconfigurations                 │              │
│                ├──────────┬──────────────┬────────┬─────┬─────────┤              │
│ Service        │ Critical │     High     │ Medium │ Low │ Unknown │ Last Scanned │
├────────────────┼──────────┼──────────────┼────────┼─────┼─────────┼──────────────┤
│ accessanalyzer │        0 │            0 │      0 │   0 │       0 │ just now     │
│ api-gateway    │        0 │            0 │      0 │   0 │       0 │ just now     │
│ athena         │        0 │            0 │      0 │   0 │       0 │ just now     │
│ cloudfront     │        0 │            6 │      3 │   0 │       0 │ just now     │
│ cloudtrail     │        0 │            1 │      0 │   1 │       0 │ just now     │
│ cloudwatch     │        0 │            0 │      0 │  46 │       0 │ just now     │
│ codebuild      │        0 │            0 │      0 │   0 │       0 │ just now     │
│ documentdb     │        0 │            3 │      3 │   7 │       0 │ just now     │
│ dynamodb       │        0 │            0 │      0 │   0 │       0 │ just now     │
│ ec2            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ ecr            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ ecs            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ efs            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ eks            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ elasticache    │        0 │            4 │      5 │   0 │       0 │ just now     │
│ elasticsearch  │        0 │            0 │      0 │   0 │       0 │ just now     │
│ elb            │        1 │            2 │      0 │   0 │       0 │ just now     │
│ emr            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ iam            │        0 │            0 │      1 │   0 │       0 │ just now     │
│ kinesis        │        0 │            0 │      0 │   0 │       0 │ just now     │
│ kms            │        0 │            0 │      2 │   0 │       0 │ just now     │
│ lambda         │        0 │            0 │      0 │   1 │       0 │ just now     │
│ mq             │        0 │            0 │      0 │   0 │       0 │ just now     │
│ msk            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ neptune        │        0 │            6 │      3 │   0 │       0 │ just now     │
│ rds            │        0 │            7 │      4 │   4 │       0 │ just now     │
│ redshift       │        0 │            0 │      0 │   0 │       0 │ just now     │
│ s3             │        0 │            0 │     56 │  25 │       0 │ just now     │
│ sns            │        0 │            7 │      0 │   0 │       0 │ just now     │
│ sqs            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ ssm            │        0 │            0 │      0 │   0 │       0 │ just now     │
│ workspaces     │        0 │            0 │      0 │   0 │       0 │ just now     │
└────────────────┴──────────┴──────────────┴────────┴─────┴─────────┴──────────────┘

「trivy aws --service サービス名」で、リソース(ARN)単位での問題を確認できます。

[cloudshell-user@ip-10-2-46-188 ~]$ trivy aws --service elb

Resource Summary for Service 'elb' (AWS Account xxxxxxxxxxxx)
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────────────────────────────────────┐
│                                                                                                                             │            Misconfigurations             │
│                                                                                                                             ├──────────┬──────┬────────┬─────┬─────────┤
│ Resource                                                                                                                    │ Critical │ High │ Medium │ Low │ Unknown │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────┼──────┼────────┼─────┼─────────┤
│ arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:listener/app/hogehoge-dev-alb-api/c11111111111111c/3333333333333333 │        1 │    0 │      0 │   0 │       0 │
│ arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:loadbalancer/app/hogehoge-dev-alb-api/c22222222222222c              │        0 │    2 │      0 │   0 │       0 │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────┴──────┴────────┴─────┴─────────┘

「trivy aws --service サービス名 --arn ARN名」で、サービス名とARNから、具体的な問題点を確認できます。

[cloudshell-user@ip-10-2-46-188 ~]$ trivy aws --service elb --arn arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:listener/app/hogehoge-dev-alb-api/c11111111111111c/3333333333333333

Results for 'arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:listener/app/hogehoge-dev-alb-api/c11111111111111c/3333333333333333' (AWS Account xxxxxxxxxxxx)


arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:listener/app/hogehoge-dev-alb-api/c11111111111111c/3333333333333333 (cloud)

Tests: 1 (SUCCESSES: 0, FAILURES: 1, EXCEPTIONS: 0)
Failures: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 1)

CRITICAL: Listener for application load balancer does not use HTTPS.
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Plain HTTP is unencrypted and human-readable. This means that if a malicious actor was to eavesdrop on your connection, they would be able to see all of your data flowing back and forth.

You should use HTTPS, which is HTTP over an encrypted (TLS) connection, meaning eavesdroppers cannot read your traffic.

See https://avd.aquasec.com/misconfig/avd-aws-0054
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────



This scan report was loaded from cached results. If you'd like to run a fresh scan, use --update-cache.

問題点と共に、
https://avd.aquasec.com/misconfig/avd-aws-0054
のように、リンクが表示されます。

このURL、完全ではないものの、以下のような推奨対応策を確認できます。
眺めてみると面白いと思います。

  • 管理コンソール
  • CloudFormation
  • Terraform

参考元

3
2
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
3
2