mirror of
https://github.com/prowler-cloud/prowler.git
synced 2025-12-19 05:17:47 +00:00
39 lines
2.1 KiB
Bash
39 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Prowler - the handy cloud security tool (c) by Toni de la Fuente
|
|
#
|
|
# This Prowler check is licensed under a
|
|
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
|
#
|
|
# You should have received a copy of the license along with this
|
|
# work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
|
|
|
CHECK_ID_check312="3.12"
|
|
CHECK_TITLE_check312="[check312] Ensure a log metric filter and alarm exist for changes to network gateways (Scored)"
|
|
CHECK_SCORED_check312="SCORED"
|
|
CHECK_ALTERNATE_check312="check312"
|
|
|
|
check312(){
|
|
# "Ensure a log metric filter and alarm exist for changes to network gateways (Scored)"
|
|
CLOUDWATCH_GROUP=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region $REGION --query 'trailList[*].CloudWatchLogsLogGroupArn' --output text | tr ' ' '
|
|
' | awk -F: '{ print $7 }')
|
|
if [[ $CLOUDWATCH_GROUP ]];then
|
|
for group in $CLOUDWATCH_GROUP; do
|
|
CLOUDWATCH_LOGGROUP_REGION=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region $REGION --query 'trailList[*].CloudWatchLogsLogGroupArn' --output text | awk -F: '{ print $4 }')
|
|
METRICFILTER_SET=$($AWSCLI logs describe-metric-filters --log-group-name $group $PROFILE_OPT --region $CLOUDWATCH_LOGGROUP_REGION --query 'metricFilters' | grep -E 'CreateCustomerGateway.*DeleteCustomerGateway.*AttachInternetGateway.*CreateInternetGateway.*DeleteInternetGateway.*DetachInternetGateway')
|
|
if [[ $METRICFILTER_SET ]];then
|
|
HAS_ALARM_ASSOCIATED=$($AWSCLI cloudwatch describe-alarms $PROFILE_OPT --region $CLOUDWATCH_LOGGROUP_REGION --query 'MetricAlarms[].MetricName' --output text | awk 'BEGIN {IGNORECASE=1}; /InternetGateway/ || /CustomerGateway/;')
|
|
if [[ $HAS_ALARM_ASSOCIATED ]];then
|
|
textPass "CloudWatch group $group found with metric filters and alarms for changes to network gateways"
|
|
else
|
|
textFail "CloudWatch group $group found with metric filters but no alarms associated"
|
|
fi
|
|
else
|
|
textFail "CloudWatch group $group found but no metric filters or alarms associated"
|
|
fi
|
|
done
|
|
else
|
|
textFail "No CloudWatch group found for CloudTrail events"
|
|
fi
|
|
}
|