diff --git a/checks/check_extra7166 b/checks/check_extra7166 new file mode 100644 index 0000000000..3496238832 --- /dev/null +++ b/checks/check_extra7166 @@ -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_extra7166="7.166" +CHECK_TITLE_extra7166="[extra7166] Check if Elastic IP addresses with associations are protected by AWS Shield Advanced" +CHECK_SCORED_extra7166="NOT_SCORED" +CHECK_CIS_LEVEL_extra7166="EXTRA" +CHECK_SEVERITY_check="Medium" +CHECK_ASFF_RESOURCE_TYPE_extra7166="AwsEc2Eip" +CHECK_ALTERNATE_extra7166="extra7166" +CHECK_SERVICENAME_extra7166="shield" +CHECK_RISK_extra7166='AWS Shield Advanced provides expanded DDoS attack protection for your resources' +CHECK_REMEDIATION_extra7166='Add as a protected resource in AWS Shield Advanced.' +CHECK_DOC_extra7166='https://docs.aws.amazon.com/waf/latest/developerguide/configure-new-protection.html' +CHECK_CAF_EPIC_extra7166='Infrastructure security' + +extra7166() { + 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_ELASTIC_IPS_WITH_ASSOCIATIONS=$($AWSCLI ec2 describe-addresses $PROFILE_OPT --region $regx --query 'Addresses[?AssociationId].AllocationId' --output text) + if [[ $LIST_OF_ELASTIC_IPS_WITH_ASSOCIATIONS ]]; then + for elastic_ip in $LIST_OF_ELASTIC_IPS_WITH_ASSOCIATIONS; do + EIP_ARN="arn:${PARTITION}:ec2:${regx}:${ACCOUNT_ID}:eip-allocation/${elastic_ip}" + if aws shield describe-protection --resource-arn $EIP_ARN >/dev/null 2>&1; then + textPass "$regx: EIP $elastic_ip is protected by AWS Shield Advanced" "$regx" "$elastic_ip" + else + textFail "$regx: EIP $elastic_ip is not protected by AWS Shield Advanced" "$regx" "$elastic_ip" + fi + done + else + textPass "$regx: no elastic IP addresses with assocations found" "$regx" + fi + done + else + textInfo "No AWS Shield Advanced subscription found. Skipping check." + fi +}