#!/bin/bash
# Findsploit by @xer0dayz
# https://sn1persecurity.com
#
# Finsploit is a simple bash script to quickly and easily search both local and online exploit databases.
#

clear

VER='2.0'
SEARCHSPLOIT_SCRIPT='/usr/bin/searchsploit'
NMAP_SCRIPTS='/usr/share/findsploit/nmap/nmap'
MSF_SEARCH_DIR='/usr/share/findsploit/msf_search'
BROWSER_CMD='firefox'
VAR1=$1;
VAR2=$2;
VAR3=$3;
VARS="$*"

OKRED='\033[91m'
COLOR2='\033[1m\033[92m'
OKRED='\033[1m'

OKBLUE='\033[94m'
OKRED='\033[91m'
OKGREEN='\033[92m'
OKORANGE='\033[93m'
RESET='\e[0m'
REGEX='^[0-9]+$'

function logo {
	echo -e "$OKRED   ___ _           _           _       _ _   "
	echo -e "$OKRED  / __(_)_ __   __| |___ _ __ | | ___ (_) |_ "
	echo -e "$OKRED / _\ | | '_ \ / _\` / __| '_ \| |/ _ \| | __|"
	echo -e "$OKRED/ /   | | | | | (_| \__ \ |_) | | (_) | | |_ "
	echo -e "$OKRED\/    |_|_| |_|\__,_|___/ .__/|_|\___/|_|\__|"
	echo -e "$OKRED                        |_|                  "
	echo ""
	echo -e "$OKRED + -- --=[ findsploit v$VER by @xer0dayz"
    echo -e "$OKRED + -- --=[ https://sn1persecurity.com$RESET"
	echo ""
}

function update {
	logo
	echo -e "$OKRED + -- --=[ Checking for updates... $RESET"
	if [[ $(curl -s https://api.github.com/repos/1N3/Findsploit/tags) == "" ]];
	then
    	echo -e "$OKRED + -- --=[ Error: no active internet connection $RESET"
    	echo ""
    	exit 1
  	fi
  	LATEST_VERSION=$(curl -s https://api.github.com/repos/1N3/Findsploit/tags | grep -Po '"name":.*?[^\\]",'| head -1 | cut -c11-13)
  	if [[ "$LATEST_VERSION" != "$VER" && "$LATEST_VERSION" != "" ]];
  	then
   		echo -e "$OKRED + -- --=[ Findsploit v$LATEST_VERSION is available to download. $RESET"
   		echo -e "$OKRED + -- --=[ Do you want to update Findsploit [Y/n]: $RESET"
    	read answer
  		if [[ "$answer" == "Y" || "$answer" == "y" ]] ;
  		then
  			cd  ~ || { echo -e "$OKRED + -- --=[ Update Failed $RESET" ; exit 1 ; }
			rm -r Findsploit  2> /dev/null
			git clone https://github.com/1N3/Findsploit || { echo -e "$OKRED + -- --=[ Couldn't download latest version $RESET" ; exit 1; }
			cd Findsploit ||  { echo -e "$OKRED + -- --=[ Update Failed $RESET" ; exit 1 ;}
			git checkout $LATEST_VERSION 2> /dev/null
			./install.sh
			cd ..
			rm -r Findsploit
  		else
     		exit 1
  		fi
	else
  		echo -e "$OKRED + -- --=[ Findsploit is already the latest version $RESET"
  		echo ""
	fi
}

if [ -z "$1" ];
then
	logo
	echo -e "$OKRED + -- --=[ Usage: findsploit windows xp remote, etc. $RESET"
	echo ""
	echo ""
	exit;
fi

if [[ "$1" == "--update" || "$1" == "-u" ]];
then
	update
	exit
else
	DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
	logo
	echo -e "$OKRED + -- --=[ SEARCHING: $COLOR2 $VARS $RESET"
	echo ""
	echo -e "$OKRED + -- --=[ NMAP SCRIPTS $RESET"
	echo ""
	egrep -i "$VAR1" $NMAP_SCRIPTS | egrep -i "$VAR2" --color=auto | egrep -i "$VAR3" --color=auto
	echo ""
	echo -e "$OKRED + -- --=[ METASPLOIT EXPLOIT S$RESET"
	echo ""
	egrep -i "$VAR1" $MSF_SEARCH_DIR/* | egrep -i "$VAR2" --color=auto | egrep -i "$VAR3" --color=auto
	echo ""
	echo -e "$OKRED + -- --=[ EXPLOITDB EXPLOITS $RESET"
	echo ""
	$SEARCHSPLOIT_SCRIPT $VARS
	echo ""
	echo 'https://www.exploit-db.com/search?q='$VAR1'+'$VAR2'+'$VAR3
	echo 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+exploit'
	echo 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+exploit+site:www.securityfocus.com'
	echo 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+site:0day.today'
	echo 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+site:www.security-database.com'
	echo 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+site:packetstormsecurity.com'
	echo 'https://exploits.shodan.io/?q='$VAR1'+'$VAR2'+'$VAR3
	echo 'https://vulners.com/search?query='$VAR1'+'$VAR2'+'$VAR3
	echo ""
	echo -e "$OKORANGE + -- --=[ Press any key to search online or Ctrl+C to exit...$RESET"
	read test
	$BROWSER_CMD 'https://sn1persecurity.com' 2> /dev/null &
	sleep 5
	$BROWSER_CMD 'https://www.exploit-db.com/search?q='$VAR1'+'$VAR2'+'$VAR3 2>/dev/null &> /dev/null
	$BROWSER_CMD 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+exploit' 2>/dev/null &> /dev/null
	$BROWSER_CMD 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+exploit+site:www.securityfocus.com' 2> /dev/null &> /dev/null
	$BROWSER_CMD 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+site:0day.today' 2> /dev/null &> /dev/null
	$BROWSER_CMD 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+site:www.security-database.com' 2> /dev/null
	$BROWSER_CMD 'https://www.google.ca/search?q='$VAR1'%20'$VAR2'%20'$VAR3'+site:packetstormsecurity.com' 2> /dev/null &> /dev/null
	$BROWSER_CMD 'https://exploits.shodan.io/?q='$VAR1'+'$VAR2'+'$VAR3 2> /dev/null &> /dev/null
	$BROWSER_CMD 'https://vulners.com/search?query='$VAR1'+'$VAR2'+'$VAR3 2> /dev/null &> /dev/null
fi
exit
