diff --git a/liveCD/BeEFLive.sh b/liveCD/BeEFLive.sh index dfd189481..55ca75739 100644 --- a/liveCD/BeEFLive.sh +++ b/liveCD/BeEFLive.sh @@ -39,169 +39,264 @@ run_beef() { ruby beef -x } +# +# function to start msf and run in the background +# +run_msf() { + # start msf + /opt/metasploit-framework/msfconsole -r /opt/beef/test/thirdparty/msf/unit/BeEF.rc 2> /dev/null +} + +# +# functions to enable or disable msf integration +# +enable_msf() { + # enable msf integration in main config file + sed -i '1N;$!N;s/metasploit:\n\s\{1,\}enable:\sfalse/metasploit:\n enable: true/g;P;D' /opt/beef/config.yaml + # enable auto_msfrpcd + sed -i 's/auto_msfrpcd:\sfalse/auto_msfrpcd: true/g' /opt/beef/extensions/metasploit/config.yaml +} +disable_msf() { + # disable msf integration in main config file + sed -i '1N;$!N;s/metasploit:\n\s\{1,\}enable:\strue/metasploit:\n enable: false/g;P;D' /opt/beef/config.yaml + # disable auto_msfrpcd + sed -i 's/auto_msfrpcd:\strue/auto_msfrpcd: false/g' /opt/beef/extensions/metasploit/config.yaml +} + +# +# function to exit cleanly +# +# trap ctrl-c and call close_bash() +trap close_bash INT + +close_bash() { + echo "" + echo "Are you sure you want to exit the LiveCD? (y/N): " + read var + if [ $var = "y" ] ; then + disable_msf + exit + else + # beef would have quit + back_running="0" + show_menu + fi +} + # set default values bac="0" +# show user menu +show_menu + # # User Menu Loop # -while true; do - clear - echo "======================================" - echo " BeEF Live CD " - echo "======================================" - echo "" - echo "Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net" - echo "Browser Exploitation Framework (BeEF) - http://beefproject.com" - echo "See the file 'home/beef/doc/COPYING' for copying permission" - echo "" - - echo "Welcome to the BeEF Live CD" - echo "" - - - # - # Check for SSH Host Keys - if they do not exist SSH will be displayed as disabled - # (remastersys has a habit of deleting them during Live CD Creation) - # - f1="/etc/ssh/ssh_host_rsa_key" - if [ -f $f1 ] ; then - echo "[1] Disable SSH [Currently Enabled]" - else - echo "[1] Enable SSH [Currently Disabled]" - fi - - echo "[2] Update BeEF" - echo "[3] Update sqlMap (Bundled with LiveCD)" - echo "[4] Update metasploit-framework (Bundled with LiveCD)" +show_menu() { + while true; do + clear + echo "======================================" + echo " BeEF Live CD " + echo "======================================" echo "" - if [ "$bac" = "1" ] ; then - echo "[5] Disable BeEF in background mode [Currently Enabled]" - else - echo "[5] Enable BeEF in background mode [Currently Disabled]" - fi - - if [ "$sqlm" = "1" ] ; then - echo "[6] Disable sqlMap demo [Currently Enabled]" - else - echo "[6] Enable sqlMap demo [Currently Disabled]" - fi - - #echo "[7] Enable metasploit-framework integration [Currently Disabled]" + echo "Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net" + echo "Browser Exploitation Framework (BeEF) - http://beefproject.com" + echo "See the file 'home/beef/doc/COPYING' for copying permission" echo "" - echo "[q] Quit to terminal" - echo "" - echo "[b] Run BeEF" - echo "" - echo -n "BeEF Live ~# " - read var - - # - # Quit liveCD loop - # - if [ $var = "q" ] ; then - exit - fi - - # - # Create SSH Keys to enable SSH or Delete the Keys to disable - # - if [ $var = "1" ] ; then - if [ -f $f1 ] - then - sudo rm /etc/ssh/ssh_host_rsa_key - sudo rm /etc/ssh/ssh_host_dsa_key - else - sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' - sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' - echo "" - echo "Please provide a password for ssh user: beef" - sudo passwd beef - echo "ssh enabled" - fi - fi - - # - # Update BeEF from github repository - # - if [ $var = "2" ] ; then - cd /opt/beef - git stash - git pull - fi - - # - # Update sqlmap from github repository - # - if [ $var = "3" ] ; then - cd /opt/sqlmap - git stash - git pull - fi - - # - # Update msf from github repository - # - if [ $var = "4" ] ; then - cd /opt/metasploit-framework - git stash - git pull - fi - - # - # set BeEF to run in the background - # - if [ $var = "5" ] ; then - if [ "$bac" = "1" ] ; then - bac="0" - # check and disable sqlmap (requires beef run in the background) - sqlm="0" - else - bac="1" - fi - fi - - # - # enable the sqlmap demo - # - if [ $var = "6" ] ; then - if [ "$sqlm" = "1" ] ; then - sqlm="0" - else - sqlm="1" - # requires BeEF be run in the background - bac="1" - fi - fi - - # - # Run BeEF - # - if [ $var = "b" ] ; then - if [ "$bac" = "1" ] ; then - run_beef & - sleep 5 - echo "" - echo "BeEF is running in the background, returning to the menu or running something else now..." - sleep 5 - - # - # If the user has enabled it start sqlmap using beef as proxy - # - if [ $sqlm = "1" ] ; then - echo "" - echo "sqlMAP can now be run using the --proxy command set to the BeEF Proxy: http://127.0.0.1:6789 starting the wizard to demo with:" - echo "python /opt/sqlmap/sqlmap.py --proxy http://127.0.0.1:6789 --wizard" - sleep 5 - python /opt/sqlmap/sqlmap.py --proxy http://127.0.0.1:6789 --wizard - fi - else - cd /opt/beef/ - ruby beef -x - fi - fi -done + echo "Welcome to the BeEF Live CD" + echo "" + + + # + # Check for SSH Host Keys - if they do not exist SSH will be displayed as disabled + # (remastersys has a habit of deleting them during Live CD Creation) + # + f1="/etc/ssh/ssh_host_rsa_key" + if [ -f $f1 ] ; then + echo "[1] Disable SSH [Currently Enabled]" + else + echo "[1] Enable SSH [Currently Disabled]" + fi + + echo "[2] Update BeEF" + echo "[3] Update sqlMap (Bundled with LiveCD)" + echo "[4] Update metasploit-framework (Bundled with LiveCD)" + echo "" + if [ "$bac" = "1" ] ; then + echo "[5] Disable BeEF in background mode [Currently Enabled]" + else + echo "[5] Enable BeEF in background mode [Currently Disabled]" + fi + + if [ "$sqlm" = "1" ] ; then + echo "[6] Disable sqlMap demo [Currently Enabled]" + else + echo "[6] Enable sqlMap demo [Currently Disabled]" + fi + + if [ "$msf" = "1" ] ; then + echo "[7] Disable metasploit-framework integration [Currently Enabled]" + else + echo "[7] Enable metasploit-framework integration [Currently Disabled]" + fi + echo "" + echo "[q] Quit to terminal" + echo "" + if [ "$back_running" = "1" ] ; then + echo "[k] End BeEF process [BeEF running in background mode]" + else + echo "[b] Run BeEF" + fi + echo "" + echo -n "BeEF Live ~# " + read var + + # + # Quit liveCD loop + # + if [ $var = "q" ] ; then + close_bash + fi + + # + # Create SSH Keys to enable SSH or Delete the Keys to disable + # + if [ $var = "1" ] ; then + if [ -f $f1 ] + then + sudo rm /etc/ssh/ssh_host_rsa_key + sudo rm /etc/ssh/ssh_host_dsa_key + else + sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' + sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' + echo "" + echo "Please provide a password for ssh user: beef" + sudo passwd beef + echo "ssh enabled" + fi + fi + + # + # Update BeEF from github repository + # + if [ $var = "2" ] ; then + cd /opt/beef + git stash + git pull + msf="0" + fi + + # + # Update sqlmap from github repository + # + if [ $var = "3" ] ; then + cd /opt/sqlmap + git stash + git pull + fi + + # + # Update msf from github repository + # + if [ $var = "4" ] ; then + cd /opt/metasploit-framework + git stash + git pull + fi + + # + # set BeEF to run in the background + # + if [ $var = "5" ] ; then + if [ "$bac" = "1" ] ; then + bac="0" + # check and disable sqlmap (requires beef run in the background) + sqlm="0" + else + bac="1" + fi + fi + + # + # enable the sqlmap demo + # + if [ $var = "6" ] ; then + if [ "$sqlm" = "1" ] ; then + sqlm="0" + else + sqlm="1" + # requires BeEF be run in the background + bac="1" + fi + fi + + # + # enable the msf integration + # + if [ $var = "7" ] ; then + if [ "$msf" = "1" ] ; then + msf="0" + disable_msf + else + msf="1" + enable_msf + fi + fi + + # + # end background beef process + # + if [ $var = "k" ] ; then + pkill -x 'ruby' + back_running="0" + fi + + # + # Run BeEF + # + if [ $var = "b" ] ; then + + if [ "$msf" = "1" ] ; then + # + # First start msf if it is enabled + # + printf "Starting MSF (wait 45 seconds)..." + run_msf & + sleep 45 + fi + + if [ "$bac" = "1" ] ; then + # + # run beef in the background + # + run_beef & + sleep 5 + echo "" + echo "BeEF is running in the background, returning to the menu or running something else now..." + sleep 5 + back_running="1" + # + # If the user has enabled it start sqlmap using beef as proxy + # + if [ $sqlm = "1" ] ; then + echo "" + echo "sqlMAP can now be run using the --proxy command set to the BeEF Proxy: http://127.0.0.1:6789 starting the wizard to demo with:" + echo "python /opt/sqlmap/sqlmap.py --proxy http://127.0.0.1:6789 --wizard" + sleep 5 + python /opt/sqlmap/sqlmap.py --proxy http://127.0.0.1:6789 --wizard + fi + else + # + # run beef in the foreground + # + cd /opt/beef/ + ruby beef -x + fi + fi + + done +}