Skip to content

Instantly share code, notes, and snippets.

@royharoush
Created December 22, 2015 01:25
Show Gist options
  • Save royharoush/4be797b7a89c164d9d4d to your computer and use it in GitHub Desktop.
Save royharoush/4be797b7a89c164d9d4d to your computer and use it in GitHub Desktop.
##### Install metasploit ~ http://docs.kali.org/general-use/starting-metasploit-framework-in-kali
echo -e "\n ${GREEN}[+]${RESET} Installing ${GREEN}metasploit${RESET} ~ exploit framework"
apt-get -y -qq install metasploit-framework 2>/dev/null || echo -e ' '${RED}'[!] Issue with apt-get'${RESET} 1>&2
mkdir -p ~/.msf4/modules/{auxiliary,exploits,payloads,post}/
#--- ASCII art
export GOCOW=1 # Always a cow logo ;) Others: THISISHALLOWEEN (Halloween), APRILFOOLSPONIES (My Little Pony)
file=~/.bashrc; [ -e "${file}" ] && cp -n $file{,.bkup}
([[ -e "${file}" && "$(tail -c 1 ${file})" != "" ]]) && echo >> "${file}"
grep -q '^GOCOW' "${file}" 2>/dev/null || echo 'GOCOW=1' >> "${file}"
#--- Fix any port issues
file=$(find /etc/postgresql/*/main/ -maxdepth 1 -type f -name postgresql.conf -print -quit); [ -e "${file}" ] && cp -n $file{,.bkup}
sed -i 's/port = .* #/port = 5432 /' "${file}"
#--- Start services
systemctl stop postgresql
systemctl start postgresql #systemctl restart postgresql
msfdb init
sleep 5s
#--- Setup alias
file=~/.bash_aliases; [ -e "${file}" ] && cp -n $file{,.bkup} #/etc/bash.bash_aliasesa
grep -q '^## metasploit' "${file}" 2>/dev/null || echo -e '## metasploit\nalias msfc="systemctl start postgresql; msfdb start; msfconsole -q \"$@\""\nalias msfconsole="systemctl start postgresql; msfdb start; msfconsole \"$@\""\n' >> "${file}"
#--- Apply new alias
if [[ "${SHELL}" == "/bin/zsh" ]]; then source ~/.zshrc else source "${file}"; fi
#--- Autorun Metasploit commands each startup
mkdir -p ~/.msf4/modules/
file=~/.msf4/msf_autorunscript.rc; [ -e "${file}" ] && cp -n $file{,.bkup}
[ -e "${file}" ] || cat <<EOF > "${file}"
#run post/windows/escalate/getsystem
#run migrate -f -k
#run migrate -n "explorer.exe" -k # Can trigger AV alerts by touching explorer.exe...g
#run post/windows/manage/smart_migrate
#run post/windows/gather/smart_hashdump
EOF
file=~/.msf4/msfconsole.rc; [ -e "${file}" ] && cp -n $file{,.bkup}
#load sounds verbose=true
#load auto_add_route
#load alias
#alias dir/ls del/rm auto handler https://github.com/rapid7/metasploit-framework/tree/master/plugins // https://github.com/rapid7/metasploit-framework/issues/5107
[ -e "${file}" ] || cat <<EOF > "${file}"
setg TimestampOutput true
setg VERBOSE true
load sounds
#use exploit/multi/handler
#set AutoRunScript 'multi_console_command -rc "~/.msf4/msf_autorunscript.rc"'
setg ExitOnSession false
setg EnableStageEncoding true
#set PAYLOAD windows/meterpreter/reverse_https
#set LHOST 0.0.0.0
setg LPORT 443
EOF
#--- First time run
echo -e 'sleep 10\ndb_status\n#db_rebuild_cache\n#sleep 310\nexit' > /tmp/msf.rc && msfconsole -r /tmp/msf.rc
echo -e "\n ${GREEN}[+]${RESET} ${GREEN}Starting Metasploit for the first time${RESET} ~ this ${BOLD}will take a ~350 seconds${RESET}"
msfconsole -q -x 'version;db_status;sleep 310;exit' #db_rebuild_cache;
#--- Check
systemctl postgresql status
--- Add to start up
systemctl enable postgresql
--- Wipe database and start fresh - or just 'reinit'
systemctl stop metasploit
sudo -u postgres dropdb msf3
sudo -u postgres createdb -O msf3 msf3
systemctl restart metasploit
msfconsole -q -x 'db_rebuild_cache;sleep 300;exit'
##### Install metasploit ~ http://docs.kali.org/general-use/starting-metasploit-framework-in-kali
echo -e "\n ${GREEN}[+]${RESET} Installing ${GREEN}metasploit${RESET} ~ exploit framework"
apt-get -y -qq install metasploit-framework 2>/dev/null || echo -e ' '${RED}'[!] Issue with apt-get'${RESET} 1>&2
mkdir -p ~/.msf4/modules/{auxiliary,exploits,payloads,post}/
#--- ASCII art
export GOCOW=1 # Always a cow logo ;) Others: THISISHALLOWEEN (Halloween), APRILFOOLSPONIES (My Little Pony)
file=~/.bashrc; [ -e "${file}" ] && cp -n $file{,.bkup}
([[ -e "${file}" && "$(tail -c 1 ${file})" != "" ]]) && echo >> "${file}"
grep -q '^GOCOW' "${file}" 2>/dev/null || echo 'GOCOW=1' >> "${file}"
#--- Fix any port issues
file=$(find /etc/postgresql/*/main/ -maxdepth 1 -type f -name postgresql.conf -print -quit); [ -e "${file}" ] && cp -n $file{,.bkup}
sed -i 's/port = .* #/port = 5432 /' "${file}"
#--- Start services
systemctl stop postgresql
systemctl start postgresql #systemctl restart postgresql
msfdb init
sleep 5s
#--- Setup alias
file=~/.bash_aliases; [ -e "${file}" ] && cp -n $file{,.bkup} #/etc/bash.bash_aliasesa
grep -q '^## metasploit' "${file}" 2>/dev/null || echo -e '## metasploit\nalias msfc="systemctl start postgresql; msfdb start; msfconsole -q \"$@\""\nalias msfconsole="systemctl start postgresql; msfdb start; msfconsole \"$@\""\n' >> "${file}"
#--- Apply new alias
if [[ "${SHELL}" == "/bin/zsh" ]]; then source ~/.zshrc else source "${file}"; fi
#--- Autorun Metasploit commands each startup
mkdir -p ~/.msf4/modules/
file=~/.msf4/msf_autorunscript.rc; [ -e "${file}" ] && cp -n $file{,.bkup}
[ -e "${file}" ] || cat <<EOF > "${file}"
#run post/windows/escalate/getsystem
#run migrate -f -k
#run migrate -n "explorer.exe" -k # Can trigger AV alerts by touching explorer.exe...g
#run post/windows/manage/smart_migrate
#run post/windows/gather/smart_hashdump
EOF
file=~/.msf4/msfconsole.rc; [ -e "${file}" ] && cp -n $file{,.bkup}
#load sounds verbose=true
#load auto_add_route
#load alias
#alias dir/ls del/rm auto handler https://github.com/rapid7/metasploit-framework/tree/master/plugins // https://github.com/rapid7/metasploit-framework/issues/5107
[ -e "${file}" ] || cat <<EOF > "${file}"
setg TimestampOutput true
setg VERBOSE true
load sounds
#use exploit/multi/handler
#set AutoRunScript 'multi_console_command -rc "~/.msf4/msf_autorunscript.rc"'
setg ExitOnSession false
setg EnableStageEncoding true
#set PAYLOAD windows/meterpreter/reverse_https
#set LHOST 0.0.0.0
setg LPORT 443
EOF
#--- First time run
echo -e 'sleep 10\ndb_status\n#db_rebuild_cache\n#sleep 310\nexit' > /tmp/msf.rc && msfconsole -r /tmp/msf.rc
echo -e "\n ${GREEN}[+]${RESET} ${GREEN}Starting Metasploit for the first time${RESET} ~ this ${BOLD}will take a ~350 seconds${RESET}"
msfconsole -q -x 'version;db_status;sleep 310;exit' #db_rebuild_cache;
#--- Check
systemctl postgresql status
--- Add to start up
systemctl enable postgresql
--- Wipe database and start fresh - or just 'reinit'
systemctl stop metasploit
sudo -u postgres dropdb msf3
sudo -u postgres createdb -O msf3 msf3
systemctl restart metasploit
msfconsole -q -x 'db_rebuild_cache;sleep 300;exit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment