From 4aa4c95d22a865fe07430559dd95012352a680a1 Mon Sep 17 00:00:00 2001 From: Michael Dickinson <45626543+michael-dickinson-sainsburys@users.noreply.github.com> Date: Thu, 23 Dec 2021 12:49:37 +0000 Subject: [PATCH] New check 7167 Cloudfront distributions are protected by AWS Shield Advanced --- checks/check_extra7167 | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 checks/check_extra7167 diff --git a/checks/check_extra7167 b/checks/check_extra7167 new file mode 100644 index 0000000000..5bdcefed86 --- /dev/null +++ b/checks/check_extra7167 @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2019) by Toni de la Fuente +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +CHECK_ID_extra7167="7.167" +CHECK_TITLE_extra7167="[extra7167] Check if Cloudfront distributions are protected by AWS Shield" +CHECK_SCORED_extra7167="NOT_SCORED" +CHECK_CIS_LEVEL_extra7167="EXTRA" +CHECK_SEVERITY_check="Medium" +CHECK_ASFF_RESOURCE_TYPE_extra7167="AwsCloudFrontDistribution" +CHECK_ALTERNATE_extra7167="extra7167" +CHECK_SERVICENAME_extra7167="shield" +CHECK_RISK_extra7167='AWS Shield Advanced provides expanded DDoS attack protection for your resources' +CHECK_REMEDIATION_extra7167='Add as a protected resource in AWS Shield Advanced.' +CHECK_DOC_extra7167='https://docs.aws.amazon.com/waf/latest/developerguide/configure-new-protection.html' +CHECK_CAF_EPIC_extra7167='Infrastructure security' + +extra7167() { + if [[ "$($AWSCLI shield get-subscription-state --output text)" == "ACTIVE" ]]; then + LIST_OF_CLOUDFRONT_DISTRIBUTIONS=$($AWSCLI cloudfront list-distributions $PROFILE_OPT --query 'DistributionList.Items[*].[Id,ARN]' --output text) + if [[ $LIST_OF_CLOUDFRONT_DISTRIBUTIONS ]]; then + while read -r distribution; do + DISTRIBUTION_ID=$(echo $distribution | awk '{ print $1; }') + DISTRIBUTION_ARN=$(echo $distribution | awk '{ print $2; }') + if aws shield describe-protection --resource-arn $DISTRIBUTION_ARN >/dev/null 2>&1; then + textPass "$REGION: Cloudfront distribution $DISTRIBUTION_ID is protected by AWS Shield Advanced" "$REGION" "$DISTRIBUTION_ID" + else + textFail "$REGION: Cloudfront distribution $DISTRIBUTION_ID is not protected by AWS Shield Advanced" "$REGION" "$DISTRIBUTION_ID" + fi + done <<<"$LIST_OF_CLOUDFRONT_DISTRIBUTIONS" + else + textPass "$REGION: no Cloudfront distributions found" "$REGION" + fi + else + textInfo "No AWS Shield Advanced subscription found. Skipping check." + fi +}