#!/usr/bin/env bash

if [ $# -ne 2 ]; then
	echo "Syntax: $0 <ResourceTypePrefix> <grep pattern>"
	exit
fi

PREFIX=$1
GREP=$2

if [ ! -f msfcli_output.txt ]; then
	echo "[*] Getting msfcli information .."
	/pentest/exploits/framework/msfcli  > msfcli_output.txt
fi

categories=""
subcategories=""
for exploit in $(sed 's/^  *//g' msfcli_output.txt | sed 's/      */#/g'|grep $GREP|sed 's/ /@@@/g'); do
	#echo "exploit=$exploit"
	module=$(echo $exploit|cut -f1 -d#)
	category=$(echo $module|cut -f2 -d/|tr '[:lower:]' '[:upper:]') 
	categories="$categories, '$category'"
	subcategory=$(echo $module|cut -f3 -d/|tr '[:lower:]' '[:upper:]') 
	subcategories="$subcategories, '$subcategory'"
	descrip=$(echo $exploit|cut -f2 -d#|sed 's/@@@/ /g')
	echo "${PREFIX}_${category}_${subcategory}_____${descrip}_____. @@@FRAMEWORK_DIR@@@/scripts/setrubyenv.sh 1.8; @@@TOOL_METASPLOIT_DIR@@@/msfcli $module RHOST=@@@_RHOST@@@ RPORT=@@@_RPORT@@@ E"
done

echo "Categories:"
echo $categories
echo
echo "Subcategories:"
echo $subcategories

#LaunchExploit_LINUX_FTP_____ProFTPD 1.2 - 1.3.0 sreplace Buffer Overflow (Linux)_____ . @@@FRAMEWORK_DIR@@@/scripts/setrubyenv.sh 1.8; @@@TOOL_METASPLOIT_DIR@@@/msfcli 
#RHOST=@@@_RHOST@@@ RPORT=@@@_RPORT@@@ E
