#!/bin/bash12#Grab script was build by peterpt exclusively for fatrat 1.9.43#Grab script waits for a msfconsole script output and then copy that output to a final folder ,4#Grab script will close automatically the msfconsole window generated by fatrat5#closes the active msfconsole terminal automatically and autoclose itself .6#This script cannot work indenpendently from fatrat78#colours variables9cyan='\e[0;36m'10green='\e[0;34m'11okegreen='\033[92m'12lightgreen='\e[1;32m'13white='\e[1;37m'14red='\e[1;31m'15yellow='\e[0;33m'16BlueF='\e[1;34m' #Biru17RESET="\033[00m" #normal18orange='\e[38;5;166m'1920path=`pwd` #Set path variable21file=temp/msff #Filename to search in metasploit output folder22conf=config/grab.conf #Maximum time to wait for all process to be done23cvar="config/config.path"24output=$(sed -n 17p ${cvar})25#If timeout configuration file does not exist then abort script26if [ ! -f "$conf" ]; then27echo "Timeout configuration was not found"28echo "Aborting"29exit30else3132#timeout configuration file found , read the 4th line33tmo=`sed -n 4p $conf`34fi3536#Clean metasploit output folder (in case a previous file with same name was created)37rm -rf $HOME/.msf4/local/* >/dev/null 2>&13839# Look for the name of the file to be search in metasploit output in msff40# msff file will be created by fatrat4142if [ -f "$file" ]; then4344#msf file exists then read 1st line (filename to search)45var=`sed -n 1p $file`46else47#msf does not exist , abort48exit 149fi5051function outf(){52clear53echo -e $orange "---------------------------------------------------"54echo -e $orange "|$okegreen Grab Script 1.0 (fatrat 1.9.4 edition)$orange |"55echo -e $orange "---------------------------------------------------"56echo -e $okegreen "Second : $sleep - Timeout : $tmo"57echo ""58echo -e $okegreen "Waiting for msfconsole output to be generated in Xterm Window"59#set directory to search for file , and filename60out="$HOME/.msf4/local/$var"6162#sleep variable is equal to itself + 1 second63sleep=$((sleep+1))64if [ $sleep == "$tmo" ] ; then6566#in case timeout value achieved without any metasploit output file created67#then exits this script6869echo "Metasploit did not generated any output or your timeout is short"70pkill -f Microsploit > /dev/null 2>&171exit 172fi7374#File was created by metasploit , copy it to final destination , kill msfconsole window and auto-close this script75if [ -f $out ]; then76mv $HOME/.msf4/local/$var $output/$var7778#Look in active processes a process name "Microsploit" and kill it79pkill -f Microsploit > /dev/null 2>&180exit 181else8283#metasploit output file was not yet found , wait 1 second84sleep 18586# start again87outf88fi89}90echo -e $orange "---------------------------------------------------"91echo -e $orange "|$okegreen Grab Script 1.0 (fatrat 1.9.4 edition)$orange |"92echo -e $orange "---------------------------------------------------"93echo -e $okegreen " Dont close this window , it will autoclose itself"94echo ""95echo -e $okegreen "Waiting for msfconsole output to be generated in Xterm Window"96echo -e $orange "Max waiting time = $tmo seconds"97#if the current value from msff is empty then abort this script98#this will mean that msff file exists but does not have anything written99if [ -z "$var" ]; then100exit 1101fi102103#set sleep variable to 1 second104sleep="1"105106#Everything is ok until this point , start loop until timeout107outf108109110