mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-11 07:15:15 +00:00
118 lines
7.1 KiB
Bash
118 lines
7.1 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(){
|
|
# if TEST_AUTHENTICATION has a value Prowler will try to access each ElasticSearch server to port:
|
|
# 9200 API, 9300 Communcation and 5601 Kibana to figure out if authentication is enabled.
|
|
# That is from the host where Prowler is running and will try to read indices or get kibana status
|
|
TEST_ES_AUTHENTICATION=
|
|
ES_API_PORT="9200"
|
|
ES_DATA_PORT="9300"
|
|
ES_KIBANA_PORT="5601"
|
|
|
|
httpStatus(){
|
|
case $1 in
|
|
000) SERVER_RESPONSE="000 Not responding" ;;
|
|
200) SERVER_RESPONSE="200 Successful" ;;
|
|
400) SERVER_RESPONSE="400 Error: Bad Request" ;;
|
|
401) SERVER_RESPONSE="401 Error: Unauthorized" ;;
|
|
403) SERVER_RESPONSE="403 Error: Forbidden" ;;
|
|
404) SERVER_RESPONSE="404 Error: Not Found" ;;
|
|
407) SERVER_RESPONSE="407 Error: Proxy Authentication Required" ;;
|
|
408) SERVER_RESPONSE="408 Error: Request Timeout" ;;
|
|
500) SERVER_RESPONSE="500 Error: Internal Server Error" ;;
|
|
502) SERVER_RESPONSE="502 Error: Bad Gateway" ;;
|
|
503) SERVER_RESPONSE="503 Error: Service Unavailable" ;;
|
|
504) SERVER_RESPONSE="504 Error: Gateway Timeout" ;;
|
|
505) SERVER_RESPONSE="505 Error: HTTP Version Not Supported" ;;
|
|
*) SERVER_RESPONSE="HTTP: status not defined." ;;
|
|
esac
|
|
}
|
|
|
|
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 [[ $TEST_ES_AUTHENTICATION ]];then
|
|
if [[ "$eip" != "None" ]];then
|
|
# check for Elasticsearch on port $ES_API_PORT, rest API HTTP.
|
|
CHECH_HTTP_ES_API=$(curl -m 2 -s -w "%{http_code}" -o /dev/null -X GET "http://$eip:$ES_API_PORT/_cat/indices")
|
|
httpStatus $CHECH_HTTP_ES_API
|
|
if [[ $CHECH_HTTP_ES_API -eq "200" ]];then
|
|
textFail "$regx: Found instance $instance with public IP $eip on Security Group: $sg with Elasticsearch port $ES_API_PORT response $SERVER_RESPONSE" "$regx"
|
|
else
|
|
textInfo "$regx: Found instance $instance with public IP $eip on Security Group: $sg with Elasticsearch port $ES_API_PORT response $SERVER_RESPONSE" "$regx"
|
|
fi
|
|
|
|
# check for port $ES_DATA_PORT TCP, this is the communication port, not:
|
|
# test_tcp_connectivity is in include/os_detector
|
|
# syntax is 'test_tcp_connectivity $HOST $PORT $TIMEOUT' (in seconds)
|
|
CHECH_HTTP_ES_DATA=$(test_tcp_connectivity $eip $ES_DATA_PORT 2)
|
|
# Using HTTP error codes here as well to reuse httpStatus function
|
|
# codes for better handling, so 200 is open and 000 is not responding
|
|
httpStatus $CHECH_HTTP_ES_DATA
|
|
if [[ $CHECH_HTTP_ES_DATA -eq "200" ]];then
|
|
textFail "$regx: Found instance $instance with public IP $eip on Security Group: $sg with Elasticsearch port $ES_DATA_PORT response $SERVER_RESPONSE" "$regx"
|
|
else
|
|
textInfo "$regx: Found instance $instance with public IP $eip on Security Group: $sg with Elasticsearch port $ES_DATA_PORT response $SERVER_RESPONSE" "$regx"
|
|
fi
|
|
|
|
# check for Kibana on port $ES_KIBANA_PORT
|
|
CHECH_HTTP_ES_KIBANA=$(curl -m 2 -s -w "%{http_code}" -o /dev/null -X GET "http://$eip:$ES_KIBANA_PORT/api/status")
|
|
httpStatus $CHECH_HTTP_ES_KIBANA
|
|
if [[ $CHECH_AUTH_5601 -eq "200" ]];then
|
|
textFail "$regx: Found instance $instance with public IP $eip on Security Group: $sg with Kibana on port $ES_KIBANA_PORT response $SERVER_RESPONSE" "$regx"
|
|
else
|
|
textInfo "$regx: Found instance $instance with public IP $eip on Security Group: $sg with Kibana on port $ES_KIBANA_PORT response $SERVER_RESPONSE" "$regx"
|
|
fi
|
|
fi
|
|
else
|
|
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 $ES_API_PORT/$ES_DATA_PORT/$ES_KIBANA_PORT" "$regx"
|
|
fi
|
|
fi
|
|
if [[ "$eip" == "None" ]];then
|
|
textInfo "$regx: Found instance $instance with private IP on Security Group: $sg" "$regx"
|
|
fi
|
|
# done < <(cat $TEMP_EXTRA779_FILE | grep -v None$)
|
|
done < <(cat $TEMP_EXTRA779_FILE)
|
|
# while read instance eip ; do
|
|
# textInfo "$regx: Found instance $instance with private IP on Security Group: $sg" "$regx"
|
|
# done < <(cat $TEMP_EXTRA779_FILE | grep None$)
|
|
fi
|
|
rm -rf $TEMP_EXTRA779_FILE
|
|
#textFail "$regx: Found Security Group: $sg open to 0.0.0.0/0 on for Elasticsearch ports" "$regx"
|
|
done
|
|
else
|
|
textPass "$regx: No Security Groups found open to 0.0.0.0/0 for Elasticsearch/Kibana ports" "$regx"
|
|
fi
|
|
done
|
|
}
|