From ffcb6a0b69a355755aed3ef05088f064ba4b3628 Mon Sep 17 00:00:00 2001 From: Toni de la Fuente Date: Fri, 2 Oct 2020 19:10:00 +0200 Subject: [PATCH] Added extra7102 ElasticIP Shodan integration --- checks/check_extra7102 | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 checks/check_extra7102 diff --git a/checks/check_extra7102 b/checks/check_extra7102 new file mode 100644 index 00000000..b8dfd99e --- /dev/null +++ b/checks/check_extra7102 @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2018) 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_extra7102="7.102" +CHECK_TITLE_extra7102="[extra7102] Check if any of the Elastic or Public IP are in Shodan (requires Shodan API KEY)" +CHECK_SCORED_extra7102="NOT_SCORED" +CHECK_TYPE_extra7102="EXTRA" +CHECK_SEVERITY_extra7102="Low" +CHECK_ASFF_RESOURCE_TYPE_extra7102="AwsEc2Eip" +CHECK_ALTERNATE_check7102="extra7102" + +# Watch out, always use Shodan API key, if you use `curl https://www.shodan.io/host/{ip}` massively +# your IP will be banned by Shodan + +# This is the right way to do so +# curl -ks https://api.shodan.io/shodan/host/{ip}?key={YOUR_API_KEY} + +# Each finding will be saved in prowler/output folder for further review. + +SHODAN_API_KEY="" + +extra7102(){ + if [[ ! $SHODAN_API_KEY ]]; then + textInfo "[extra7102] Requires a Shodan API key to work. Edit checks/check_extra7102 first" + else + for regx in $REGIONS; do + LIST_OF_EIP=$($AWSCLI $PROFILE_OPT --region $regx ec2 describe-addresses --query 'Addresses[*].PublicIp' --output text) + if [[ $LIST_OF_EIP ]]; then + for ip in $LIST_OF_EIP;do + SHODAN_QUERY=$(curl -ks https://api.shodan.io/shodan/host/$ip?key=$SHODAN_API_KEY) + if [[ $SHODAN_QUERY == *"No information available for that IP"* ]]; then + textPass "$regx: IP $ip is not listed in Shodan" "$regx" + else + echo $SHODAN_QUERY > $OUTPUT_DIR/shodan-output-$ip.json + IP_SHODAN_INFO=$(cat $OUTPUT_DIR/shodan-output-$ip.json | jq -r '. | { ports: .ports, org: .org, country: .country_name }| @text' | tr -d \"\{\}\}\]\[ | tr , '\ ' ) + textFail "$regx: IP $ip is listed in Shodan with data $IP_SHODAN_INFO. More info https://www.shodan.io/host/$ip and $OUTPUT_DIR/shodan-output-$ip.json" "$regx" + fi + done + else + textInfo "$regx: No Public or Elastic IPs found" "$regx" + fi + done + fi +}