mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
52 lines
3.0 KiB
Bash
52 lines
3.0 KiB
Bash
#!/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_extra779="7.79"
|
|
CHECK_TITLE_extra779="[extra779] Ensure no security groups allow ingress from 0.0.0.0/0 or ::/0 to Elasticsearch/Kibana ports"
|
|
CHECK_SCORED_extra779="NOT_SCORED"
|
|
CHECK_TYPE_extra779="EXTRA"
|
|
CHECK_ALTERNATE_check779="extra779"
|
|
|
|
extra779(){
|
|
ES_API_PORT="9200"
|
|
ES_DATA_PORT="9300"
|
|
ES_KIBANA_PORT="5601"
|
|
# Test connectivity and authentication is performed by check extra787
|
|
for regx in $REGIONS; do
|
|
# crate a list of SG open to the world with port $ES_API_PORT or $ES_DATA_PORT or $ES_KIBANA_PORT
|
|
SG_LIST=$($AWSCLI ec2 describe-security-groups $PROFILE_OPT --region $regx --output text \
|
|
--query "SecurityGroups[?length(IpPermissions[?((FromPort==null && ToPort==null) || (FromPort<=\`$ES_API_PORT\` && ToPort>=\`$ES_API_PORT\`) || (FromPort<=\`$ES_DATA_PORT\` && ToPort>=\`$ES_DATA_PORT\`) || (FromPort<=\`$ES_KIBANA_PORT\` && ToPort>=\`$ES_KIBANA_PORT\`)) && (contains(IpRanges[].CidrIp, \`0.0.0.0/0\`) || contains(Ipv6Ranges[].CidrIpv6, \`::/0\`))]) > \`0\`].{GroupId:GroupId}")
|
|
# in case of open security groups goes through each one
|
|
if [[ $SG_LIST ]];then
|
|
for sg in $SG_LIST;do
|
|
# temp file store the list of instances IDs and public IP address if found
|
|
TEMP_EXTRA779_FILE=$(mktemp -t prowler-${ACCOUNT_NUM}-es-domain.EXTRA779.XXXXXXXXXX)
|
|
# finds instances with that open security group attached and get its public ip address (if it has one)
|
|
$AWSCLI $PROFILE_OPT --region $regx ec2 describe-instances --filters Name=instance.group-id,Values=$sg --query 'Reservations[*].Instances[*].[InstanceId,PublicIpAddress]' --output text > $TEMP_EXTRA779_FILE
|
|
# in case of exposed instances it does access checks
|
|
if [[ -s "$TEMP_EXTRA779_FILE" ]];then
|
|
while read instance eip ; do
|
|
if [[ "$eip" == "None" ]];then
|
|
textInfo "$regx: Found instance $instance with private IP on Security Group: $sg" "$regx"
|
|
else
|
|
textFail "$regx: Found instance $instance with public IP $eip on Security Group: $sg open to 0.0.0.0/0 on for Elasticsearch/Kibana ports - use extra787 to test AUTH" "$regx"
|
|
fi
|
|
done < <(cat $TEMP_EXTRA779_FILE)
|
|
fi
|
|
rm -rf $TEMP_EXTRA779_FILE
|
|
done
|
|
else
|
|
textPass "$regx: No Security Groups found open to 0.0.0.0/0 for Elasticsearch/Kibana ports" "$regx"
|
|
fi
|
|
done
|
|
}
|