From 586d1f308c03a71b6c318bce2cf19f4da69349c6 Mon Sep 17 00:00:00 2001 From: Michael Dickinson <45626543+michael-dickinson-sainsburys@users.noreply.github.com> Date: Thu, 23 Dec 2021 15:21:51 +0000 Subject: [PATCH] New check 7171 Classic load balancers are protected by AWS Shield Advanced --- checks/check_extra7171 | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 checks/check_extra7171 diff --git a/checks/check_extra7171 b/checks/check_extra7171 new file mode 100644 index 0000000000..87db38b355 --- /dev/null +++ b/checks/check_extra7171 @@ -0,0 +1,50 @@ +#!/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_extra7171="7.171" +CHECK_TITLE_extra7171="[extra7171] Check if classic load balancers are protected by AWS Shield" +CHECK_SCORED_extra7171="NOT_SCORED" +CHECK_CIS_LEVEL_extra7171="EXTRA" +CHECK_SEVERITY_check="Medium" +CHECK_ASFF_RESOURCE_TYPE_extra7171="AwsElasticLoadBalancingLoadBalancer" +CHECK_ALTERNATE_extra7171="extra7171" +CHECK_SERVICENAME_extra7171="shield" +CHECK_RISK_extra7171='AWS Shield Advanced provides expanded DDoS attack protection for your resources' +CHECK_REMEDIATION_extra7171='Add as a protected resource in AWS Shield Advanced.' +CHECK_DOC_extra7171='https://docs.aws.amazon.com/waf/latest/developerguide/configure-new-protection.html' +CHECK_CAF_EPIC_extra7171='Infrastructure security' + +extra7171() { + if [[ "$($AWSCLI shield get-subscription-state --output text)" == "ACTIVE" ]]; then + CALLER_IDENTITY=$($AWSCLI sts get-caller-identity $PROFILE_OPT --query Arn) + PARTITION=$(echo $CALLER_IDENTITY | cut -d: -f2) + ACCOUNT_ID=$(echo $CALLER_IDENTITY | cut -d: -f5) + for regx in $REGIONS; do + LIST_OF_CLASSIC_LOAD_BALANCERS=$($AWSCLI elb describe-load-balancers $PROFILE_OPT --region $regx --query 'LoadBalancerDescriptions[?Scheme == `internet-facing`].[LoadBalancerName]' --output text |grep -v '^None$') + if [[ $LIST_OF_CLASSIC_LOAD_BALANCERS ]]; then + for elb in $LIST_OF_CLASSIC_LOAD_BALANCERS; do + ELB_ARN="arn:${PARTITION}:elasticloadbalancing:${regx}:${ACCOUNT_ID}:loadbalancer/${elb}" + if aws shield describe-protection --resource-arn $ELB_ARN >/dev/null 2>&1; then + textPass "$regx: ELB $elb is protected by AWS Shield Advanced" "$regx" "$elb" + else + textFail "$regx: ELB $elb is not protected by AWS Shield Advanced" "$regx" "$elb" + fi + done + else + textPass "$regx: no classic load balancers found" "$regx" + fi + done + else + textInfo "No AWS Shield Advanced subscription found. Skipping check." + fi +}