(O+P)ut

アウトプット



(O+P)ut

エンジニアのアウトプット

【AWS/SecurityHub】awsコマンドで脆弱性情報を確認する

スポンサーリンク

やりたいこと

awscliを利用してSecurityHubで検知されている「CRITICAL」や「HIGH」の脆弱性を一覧化したい。

環境情報
$ aws --version
aws-cli/2.15.23 Python/3.11.6 ...

やり方

以下のようにSeverityLabelでフィルターをつけることで該当の脆弱性情報がJSON形式で出力される。

$ aws securityhub get-findings --filters '{"SeverityLabel":[{"Value": "CRITICAL","Comparison":"EQUALS"}]}'

表示に必要な情報をqueryで絞ることで以下のように欲しい情報のみを出力させることもできる。

$ aws securityhub get-findings --filters '{"SeverityLabel":[{"Value": "HIGH","Comparison":"EQUALS"}]}' --query 'Findings[].{SeverityLabel:Severity.Label,Compliance:Compliance,ProductName:ProductName,Title:Title,Description:Description}' --profile stg
[
    {
        "SeverityLabel": "HIGH",
        "Compliance": {
            "Status": "FAILED",
            "RelatedRequirements": [
                "CIS AWS Foundations Benchmark v3.0.0/5.4"
            ]
        },
        "ProductName": "Security Hub",
        "Title": "VPC default security groups should not allow inbound or outbound traffic",
        "Description": "This AWS control checks that the default security group of a VPC does not allow inbound or outbound traffic."
    },

以下、補足です。

補足

GUIでも確認ができますが、機械的に情報を一覧化しようとするとawscliが便利です。例えばタイトルだけを抜き出したい場合は、以下のようなワンライナーを利用することでサクッと確認ができます。

$ aws securityhub get-findings --filters '{"SeverityLabel":[{"Value": "HIGH","Comparison":"EQUALS"}]}' --query 'Findings[].{SeverityLabel:Severity.Label,Compliance:Compliance,ProductName:ProductName,Title:Title,Description:Description}' --output json | grep Title | cut -d"\"" -f4 | sort | uniq
Amazon Inspector EC2 scanning should be enabled
Amazon Inspector ECR scanning should be enabled
CloudFront distributions should have a default root object configured
ECR private repositories should have image scanning configured
GuardDuty should be enabled

以上、ご参考になれば幸いです。