Advertisement
Guest User

brtw2003

a guest
Feb 10th, 2010
1,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 27.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##
  4. ##  MADE CHANGES BELOW !!
  5. ##  Author: brtw2003/bl0wf1sh '10
  6. ##  Complete documentation: http://dradisframework.org
  7. ##
  8.  
  9. DRADIS_PORT="3004"
  10. DRADIS_IP="localhost"
  11. BASE_DIR="CHANGE_ME"
  12.                 #where your dradis 2.5.0 should be installed
  13. BANNER="banner.png"
  14.                 #add your own custom logo to the front login page - must be a png and not too large!
  15. DRADIS_ENV="mycompany"
  16.                 #this will be used for your default dradis environment, including database instance
  17. SVN_USE="no"
  18.                 #if you say yes, dradis svn release will be downloaded and used
  19.                 #use it only if you are quite familar with dradis!
  20. TEMPLATE="generic"
  21.                         # import a default templates - based on the dradis export package feature
  22.                         # -templates must be placed into directory: _TEMPLATES
  23.                         # -use the export package feature within dradis to create the dradis-export.zip file
  24.                         # -file name must be like: {template}_xxxxxxx.tmpl.zip
  25.                         # -example: pentest_template_V1.1.tmpl.zip
  26.                         # Currently 3 templates can be specified
  27.                         # mobile (default for MC assessment)
  28.                         # wlan (default for WLAN pentest)
  29.                         # generic (default for the usual pentest)
  30.                         #
  31. TMPL_GENERIC="generic_pentest_1.0.tmpl"
  32. TMPL_MCD="mobile_computing_1.0.tmpl"
  33. TMPL_WLAN="wlan_1.0.tmpl"
  34.                         #templates must be placed in the BASE_DIR/_TEMPLATES folder
  35.                        
  36. ############ END OF MANUAL CHANGES ########
  37. ######################################
  38.  
  39.  
  40.  
  41. RELEASE="1.1"
  42. UPDATE="10/02/2010 (brtw2003)"
  43. DRADIS_DB="${DRADIS_ENV}.sqlite3"
  44. DRADIS_RELEASE="2.5.0"
  45. TERMINAL="/usr/bin/xterm -bg white -fg black"
  46.  
  47. ####
  48. ### functions
  49. ####
  50.  
  51.  
  52. #setup new dradis (installation + initialization)
  53. dradis_new () {
  54.  
  55. if [ ${BASE_DIR} == "CHANGE_ME" ]; then
  56.     printf "\n\n###ERROR### SORRY, you didn't change the BASE_DIR paramater !\n"
  57.     printf "###ERROR## Okay, fix it - edit BASE_DIR paramater in this script!\n\n"
  58.     printf "###INFO## will start nano for you to edit file!\n\n"
  59.     sleep 5
  60.     nano startDradis
  61.     printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n"
  62.     exit 0
  63. fi
  64.  
  65. if [ ${SVN_USE} == "yes" ]; then
  66.   printf "\n###INFO## You choose the svn release, will prepare ...inlcuding svn download of latest version\n"
  67.   printf "###INFO## base dir we will use: ${BASE_DIR}\n\n"
  68.   printf "\n...okay, let's go...\n"
  69.  
  70.   if [ ! -d ${BASE_DIR} ]; then
  71.     mkdir -p ${BASE_DIR}
  72.   fi
  73.  
  74.   if [ ! -d ${BASE_DIR}/server ]; then
  75.     cd ${BASE_DIR} && `which svn` co https://dradis.svn.sourceforge.net/svnroot/dradis/server/trunk server && \
  76.     `which svn` co https://dradis.svn.sourceforge.net/svnroot/dradis/server/trunk client
  77.   else
  78.     cd ${BASE_DIR}/server && printf "\nDradis Server Release (svn update, just a second..): \t" && `which svn` update
  79.     cd ${BASE_DIR}/client && printf "\nDradis Client Release (svn update, just a second..): \t" && `which svn` update
  80.   fi
  81.  
  82.     if [ ! -d ${BASE_DIR}/_TEMPLATES ]; then
  83.         mkdir ${BASE_DIR}/_DB-BACKUP ${BASE_DIR}/_LOGS ${BASE_DIR}/_TEMPLATES
  84.         cp -p `pwd`/_TEMPLATES/* ${BASE_DIR}/_TEMPLATES/
  85.     fi
  86. fi
  87.  
  88.  
  89. if [[ $EUID -ne 0 ]]; then
  90.     printf "\n###ERROR## SORRY, script needs to be run as root!\n"
  91.     exit 0
  92. fi
  93.  
  94. if [ ! -f  "${BASE_DIR}/.installed" ]; then
  95.     read -p "Installation folder: $BASE_DIR - is this correct? (y/n) : " -e optFolder
  96.     if [ $optFolder == "n" ]; then
  97.         printf "\n\n###ERROR## Okay, fix it - edit BASE_DIR paramater in this script!\n\n\n"
  98.         printf "###INFO## will start nano for your to edit file!\n\n"
  99.         sleep 5
  100.         nano startDradis
  101.         printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n" 
  102.         exit 0
  103.     fi
  104.  
  105.     printf "\n###INFO## Using latest dradis release (2.5.0)\n"
  106.     printf "###INFO## Will unpack original dradis source 2.5.0..\n"
  107.     printf "###INFO## Dradis will be installed to: ${BASE_DIR}\n"
  108.     printf "###INFO## Custom stuff can be found in: ${BASE_DIR}/_TEMPLATES\n"
  109.    
  110.     if [ ! -f ./_TEMPLATES/dradis-v2.5.0.tar.gz ]; then
  111.         printf "\n###ERROR## Sorry, installer source not found!\n\n"
  112.         exit 0
  113.     else
  114.         mkdir -p ${BASE_DIR}
  115.         cp `pwd`/startDradis ${BASE_DIR}/
  116.         cp `pwd`/_TEMPLATES/dradis-v2.5.0.tar.gz ${BASE_DIR}/ && \
  117.         mkdir -p ${BASE_DIR}/_TEMPLATES ${BASE_DIR}/_LOGS ${BASE_DIR}/_DB-BACKUP && \
  118.         cp `pwd`/_TEMPLATES/* ${BASE_DIR}/_TEMPLATES/ && \
  119.         cd ${BASE_DIR} && tar xf dradis-v2.5.0.tar.gz && rm dradis-v2.5.0.tar.gz && \
  120.         mv dradis-2.5/* . && rm -rf dradis-2.5
  121.     fi
  122.  
  123.     if [ -f "$BASE_DIR/_TEMPLATES/${BANNER}" ]; then
  124.         printf "\n###INFO## Found custom banner, will copy it to the right folder...\n"
  125.         cp $BASE_DIR/_TEMPLATES/${BANNER} $BASE_DIR/server/public/images/banner.png
  126.     fi
  127.  
  128.     # remove production env variable in environment.rb
  129.     sed -i "s/^ENV/#ENV/g" ${BASE_DIR}/server/config/environment.rb && \
  130.     sed -i "s/^RAILS_ENV/#RAILS_ENV/g" ${BASE_DIR}/server/config/environment.rb
  131.        
  132.     touch  ${BASE_DIR}/.installed
  133.  
  134.     read -p "Initial dradis shared login password? : " -e optPWD
  135.  
  136.     if [ -n "$optPWD" ]; then
  137.         DRADIS_PWD="${optPWD}" 
  138.     else
  139.         DRADIS_PWD="topSecure" 
  140.     fi
  141.  
  142.     #create now custom ssl certificate
  143.     dradis_ssl
  144.    
  145.     if [ -n "${DRADIS_ENV}" ]; then
  146.     cd ${BASE_DIR}/server/config
  147.    
  148.     if [ ! -f environments/${DRADIS_ENV}.rb ]; then
  149.         DRADIS_DB="${DRADIS_ENV}.sqlite3"
  150.         cp environments/production.rb environments/${DRADIS_ENV}.rb
  151.        
  152.         if [ -z "$(cat database.yml |grep '${DRADIS_ENV}:')" ]; then
  153.             printf "\n\n${DRADIS_ENV}:\n  adapter: sqlite3\n  database: db/${DRADIS_DB}\n  timeout: 5000\n\n" >>database.yml
  154.         fi
  155.     fi
  156.     else
  157.         DRADIS_DB=production.sqlite3
  158.     fi
  159.  
  160.     if [ ! -f "$BASE_DIR/server/db/migrate/007_create_custom_environment.rb" ]; then
  161.         cp $BASE_DIR/_TEMPLATES/007_create_custom_environment.rb $BASE_DIR/server/db/migrate/
  162.     fi
  163.  
  164.     #initialize dradis environment
  165.     cd ${BASE_DIR}/server
  166.     export RAILS_ENV=$DRADIS_ENV; rake dradis:reset >/dev/null
  167.  
  168.     sleep 3
  169.     db_date=$(date '+%F %H:%M:%S')
  170.     sqlite3 -line ${BASE_DIR}/server/db/${DRADIS_DB} "update configurations set value='${DRADIS_PWD}' where name='password'"
  171.  
  172.     #let's call the import template function
  173.     dradis_import
  174.    
  175.     printf "\n\n###INFO## Okay, done..\n"
  176.     printf "###INFO## We have do run verify.sh - to check prerequisites!\n"
  177.     printf "###INFO## Dradis 2.5 needs some new gem packages, which are not installed in BT4 finale!\n\n"
  178.     cd ${BASE_DIR}
  179.     sh verify.sh
  180.     printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n"
  181.     exit 0
  182. else
  183.     printf "\n###INFO## ..dradis release 2.5.0 is already installed!!\n"
  184.    
  185.     if [ ! -f "$BASE_DIR/.verifycalled" ]; then
  186.         printf "###WARNING## You still have not executed verify.sh !!\n\n"
  187.         read -p "Should we really proceed? (y/n)" -e optVerify
  188.     fi
  189.    
  190.     if [ $optVerify == "n" ]; then
  191.         printf "\n###INFO## GOOD CHOICE, will run now verify.sh !!\n\n"
  192.         cd ${BASE_DIR}
  193.         sh verify.sh
  194.         printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n"
  195.         exit 0
  196.     fi
  197.    
  198.     clear
  199.     printf "\n\n###INFO## ..use a different menu option! Dradis $DRADIS_RELEASE installation looks good!\n\n"
  200.     cd ${BASE_DIR}
  201.     exit 0
  202. fi
  203. }
  204.  
  205.  
  206.  
  207. #general import functions for our custom templates
  208. dradis_import () {
  209. ###import project templates
  210.  
  211. if [ ${TEMPLATE} == "generic" ]; then
  212.     printf "\n###INFO## You choose to import the 'Generic Pentest Template Package'...give me a second\n\n"
  213.         if [ -f "${BASE_DIR}/_TEMPLATES/${TMPL_GENERIC}" ]; then
  214.             cd ${BASE_DIR}/server
  215.             FILE="[$BASE_DIR/_TEMPLATES/$TMPL_GENERIC]"
  216.             rake 'upload:project:template'$FILE'' >/dev/null
  217.         else
  218.             printf "\n###ERROR## Sorry, template file doesn't exist: $TMPL_GENERIC \n"
  219.         fi
  220. fi
  221.  
  222. if [ ${TEMPLATE} == "mobile" ]; then
  223.     printf "\n###INFO## You choose to import the 'Generic Mobile Template Package'...give me a second\n\n"
  224.         if [ -f "${BASE_DIR}/_TEMPLATES/${TMPL_MCD}" ]; then
  225.             cd ${BASE_DIR}/server
  226.             FILE="[$BASE_DIR/_TEMPLATES/$TMPL_MCD]"
  227.             rake 'upload:project:template'$FILE'' >/dev/null
  228.         else
  229.             printf "\n###ERROR## Sorry, template file doesn't exist: $TMPL_MCD \n"
  230.         fi
  231. fi
  232.  
  233. if [ ${TEMPLATE} == "wlan" ]; then
  234.     printf "\n###INFO## You choose to import the 'Generic Wireless LAN Template Package'...give me a second\n\n"
  235.         if [ -f "${BASE_DIR}/_TEMPLATES/${TMPL_WLAN}" ]; then
  236.             cd ${BASE_DIR}/server
  237.             FILE="[$BASE_DIR/_TEMPLATES/$TMPL_WLAN]"
  238.             rake 'upload:project:template'$FILE'' >/dev/null
  239.         else
  240.             printf "\n###ERROR## Sorry, template file doesn't exist: $TMPL_WLAN \n"
  241.         fi
  242. fi
  243.  
  244. }
  245.  
  246.  
  247.  
  248. #call firefox
  249. dradis_browser () {
  250.  
  251. if [ -f "$(which firefox)" ]; then
  252.     $(which firefox) -no-remote https://${DRADIS_IP}:${DRADIS_PORT}/login&
  253.     printf "\n\n\n*****************************************************************************\n"
  254.     printf "\nPlease, use default Dradis shared PWD:\t\t$DRADIS_PWD"
  255.     printf "\nDradis server Log File can be found here: $BASE_DIR/_LOGS/$DRADIS_ENV.log\n"
  256.     if [ "$ENCRYPT" == "YES" ]; then
  257.         printf "\nDon't forget your encrypted GPG password for your backup:  $GPG_PWD\n"
  258.     fi
  259.     printf "*****************************************************************************\n\n"
  260. else
  261.     printf "\n\n\n*****************************************************************************\n"
  262.     printf "\nPlease, use default Dradis shared PWD:\t\t$DRADIS_PWD"
  263.     printf "\n\n..Didn't find Firefox...\n"
  264.     printf "\nSTART NOW YOUR WEB BROWSER and login to: https://$DRADIS_IP:$DRADIS_PORT/login"
  265.     printf "\nDradis server Log File can be found here: ${BASE_DIR}/_LOGS/$DRADIS_ENV.log\n"
  266.     if [ "$ENCRYPT" == "YES" ]; then
  267.         printf "\nDon't forget your encrypted GPG password for your backup:  $GPG_PWD\n"
  268.     fi
  269.     printf "*****************************************************************************\n\n"
  270. fi
  271. }
  272.  
  273.  
  274.  
  275. #use dradis with backup feature
  276. dradis_backup () {
  277.  
  278. if [ ${BASE_DIR} == "CHANGE_ME" ]; then
  279.     printf "\n\n###ERROR### SORRY, you didn't change the BASE_DIR paramater !\n"
  280.     printf "###ERROR## Okay, fix it - edit BASE_DIR paramater in this script!\n\n"
  281.     printf "###INFO## will start nano for your to edit file!\n\n"
  282.     sleep 5
  283.     nano startDradis
  284.     printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n"
  285.     exit 0
  286. fi
  287.  
  288. if [ ! -f "$BASE_DIR/.verifycalled" ]; then
  289.     printf "###WARNING## You still have not executed verify.sh !!\n\n"
  290.     read -p "Should we really proceed? (y/n)" -e optVerify
  291. fi
  292.  
  293. if [ "$optVerify" == "n" ]; then
  294.     printf "\n###INFO## GOOD CHOICE, run now verify.sh !!\n\n"
  295.     cd ${BASE_DIR}
  296.     sh verify.sh
  297.     printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n"
  298.     exit 0
  299. fi
  300.  
  301. ##look for required env settings...
  302. if [ ! "$(pidof -s xinit)" ]; then
  303.     printf "\n###ERROR## SORRY, X11 is not running and we do use xterm to start dradis!\n"
  304.     printf "###ERROR## also to start firefox for you..\n"
  305.     exit 0
  306. elif [ "${DRADIS_IP}" == "localhost" ]; then
  307.     if [ ! $(ifconfig -a | awk '/^[lL][a-zA-Z0-9,_:.]/{n=$1}($1=="UP"){u[n]=n}END{for(n in u){print u[n]}}') ]; then
  308.         printf "\n\t###ERROR## SORRY, seems your dont have a loopback device?\n"
  309.         printf "we do need it, because dradis server is usually running on localhost!\n"
  310.         printf "Fix your networking first!\n"
  311.         exit 0
  312.     fi
  313. fi
  314.  
  315. if [ ! -n "$(env |grep "^DISPLAY" |cut -d"=" -f2)" ]; then
  316.     printf "\n###ERROR## SORRY, can't find a proper DISPLAY variable!Are you running X??\n"
  317.     printf "\n###ERROR### ..let's see if we can fix it...\n"
  318.    
  319.     #look if we can setup display var ....for the real lazy onces :-)
  320.     user_id=$(ps -ef |grep xinit |grep -v grep |cut -d" " -f1)
  321.     if [ -d "/home/${user_id}" ]; then
  322.         if [ -f "/home/${user_id}/.Xauthority" ]; then
  323.             export XAUTHORITY=/home/${user_id}/.Xauthority
  324.             export DISPLAY=:0.0
  325.         fi
  326.     fi
  327.    
  328.     if [ ! -n "$(env |grep "^DISPLAY" |cut -d"=" -f2)" ]; then
  329.         printf "\n###INFO### PROBLEM fixed :-)\n"
  330.     else
  331.         printf "\n###ERROR### Can't do magic, please fix DISPLAY and xauthority issue!\n"
  332.         exit 0
  333.     fi
  334. fi
  335.  
  336. # remove production env variable in environment.rb - done during install, but safer to do it again !
  337. sed -i "s/^ENV/#ENV/g" ${BASE_DIR}/server/config/environment.rb && \
  338. sed -i "s/^RAILS_ENV/#RAILS_ENV/g" ${BASE_DIR}/server/config/environment.rb
  339.  
  340. printf "\n\n###INFO## Okay, let's do the backup...\n"
  341. BACKUP="YES"
  342.  
  343. read -p "Should we encrypt the backup data? (y/n): " -e optEncrypt
  344.  
  345. if [ $optEncrypt == "y" ]; then
  346.    read -p "GPG password to encrypt file (REMEMBER IT!!!): " -e optGPG
  347.    ENCRYPT="YES"
  348.    
  349.     if [ -n "$optGPG" ]; then
  350.         GPG_PWD="$optGPG"
  351.     else
  352.         printf "\n\n###ERROR### SORRY, string can not be empty!! Try it again\n"
  353.         read -p "GPG password to encrypt file (REMEMBER IT!!!): " -e optGPG
  354.         GPG_PWD="$optGPG"
  355.     fi
  356. fi
  357.  
  358. read -p "Initial dradis shared login password? : " -e optPWD
  359.  
  360. if [ -n "$optPWD" ]; then
  361.     DRADIS_PWD="${optPWD}" 
  362. else
  363.     DRADIS_PWD="topSecure" 
  364. fi
  365.  
  366. printf "\n\n###INFO## looking for running dradis instance..\n"
  367. pgrep -f 'ruby ./script/server' >/dev/null
  368. if [[ $? -eq 0 ]]; then
  369.     printf "\n\n###WARNING## dradis server active..I KILL IT NOW!\n\n"
  370.     kill -9 `pgrep -f 'ruby ./script/server'` >/dev/null
  371. fi
  372.  
  373. if [ -n "${DRADIS_ENV}" ]; then
  374.     cd ${BASE_DIR}/server/config
  375.    
  376.     if [ ! -f environments/${DRADIS_ENV}.rb ]; then
  377.         DRADIS_DB="${DRADIS_ENV}.sqlite3"
  378.         cp environments/production.rb environments/${DRADIS_ENV}.rb
  379.        
  380.         if [ -z "$(cat database.yml |grep '${DRADIS_ENV}:')" ]; then
  381.             printf "\n\n${DRADIS_ENV}:\n  adapter: sqlite3\n  database: db/${DRADIS_DB}\n  timeout: 5000\n\n" >>database.yml
  382.         fi
  383.     fi
  384. else
  385.     DRADIS_DB=production.sqlite3
  386. fi
  387.  
  388. if [ ! -f "$BASE_DIR/server/db/$DRADIS_DB" ]; then
  389.     printf "\n###INFO### your production database doesn't exist, therefore nothing to backup!\n"
  390.     printf "###INFO### will initalize now your new environment...\n"
  391.  
  392.     if [ ! -f "$BASE_DIR/server/db/migrate/007_create_custom_environment.rb" ]; then
  393.         cp $BASE_DIR/_TEMPLATES/007_create_custom_environment.rb $BASE_DIR/server/db/migrate/
  394.     fi
  395.    
  396.     cd ${BASE_DIR}/server
  397.     export RAILS_ENV=${DRADIS_ENV};rake db:migrate >/dev/null
  398. else
  399.     # do a backup of old dradis sqlite database
  400.     printf "\n###INFO## backup previous Dradis Framework database & settings....\n"
  401.     cd ${BASE_DIR}/server/db
  402.     cp ${DRADIS_DB} ${BASE_DIR}/_DB-BACKUP/${DRADIS_DB}.`date +%F` && \
  403.     gzip ${BASE_DIR}/_DB-BACKUP/${DRADIS_DB}.`date +%F`
  404.    
  405.     printf "###INFO## Backup is located in: \t${BASE_DIR}/_DB-BACKUP\n"
  406.     printf "###INFO## backup previous project....\n"
  407.     cd ${BASE_DIR}/server
  408.     export RAILS_ENV=${DRADIS_ENV};rake dradis:backup >/dev/null
  409.     sleep 4
  410.     printf "###INFO## clear old environment..\n"
  411.     cd ${BASE_DIR}/server
  412.     export RAILS_ENV=${DRADIS_ENV};rake dradis:reset >/dev/null
  413.     mv ${BASE_DIR}/server/backups/dradis_*.zip ${BASE_DIR}/_DB-BACKUP/
  414. fi
  415.  
  416. if [ "${ENCRYPT}" == "YES" ]; then
  417.     if [ -f "$(which gpg)" ]; then
  418.         if [ -f "${BASE_DIR}/_DB-BACKUP/${DRADIS_DB}.`date +%F`.gz" ]; then
  419.             printf "\n\n###INFO## encrypting db backup file...\n"
  420.             $(which gpg) -q --passphrase "$GPG_PWD" --yes --batch --no-tty -c ${BASE_DIR}/_DB-BACKUP/${DRADIS_DB}.`date +%F`.gz >/dev/null  
  421.             sleep 3
  422.             rm -f ${BASE_DIR}/_DB-BACKUP/${DRADIS_DB}.`date +%F`.gz
  423.         else
  424.             printf "\n\n###ERROR## sorry, there is no backup file to encrypt!\n"   
  425.         fi
  426.     else
  427.         printf "\n\n###ERROR## sorry, gpg not found, will not encrypt your database backup file!\n"
  428.         printf "###INFO## install it, under debian run: apt-get install gpg\n"
  429.     fi
  430. fi
  431.  
  432. db_date=$(date '+%F %H:%M:%S')
  433. sqlite3 -line ${BASE_DIR}/server/db/${DRADIS_DB} "update configurations set value='${DRADIS_PWD}' where name='password'"
  434.  
  435. #let's call the import template function
  436. dradis_import
  437.  
  438. ##finally we start the server and client if needed
  439. cd ${BASE_DIR}/server
  440. ${TERMINAL} -T "DRADIS SERVER" -geometry 70x25+0+0 -e ruby ./script/server -e ${DRADIS_ENV} -p ${DRADIS_PORT} -b ${DRADIS_IP}&
  441.  
  442. if [ "${CLIENT}" == "YES" ]; then
  443.     sleep 3
  444.     cd ${BASE_DIR}/client
  445.     ${TERMINAL} -T "DRADIS CLIENT" -geometry 70x25+0+350 -e ruby dradis.rb -g&
  446. fi
  447.  
  448. #create a sym link in our log dir to the server log...
  449. if [ ! -f "$BASE_DIR/_LOGS/$DRADIS_ENV.log" ]; then
  450.     cd $BASE_DIR/_LOGS/
  451.     ln -s $BASE_DIR/server/log/${DRADIS_ENV}.log
  452. fi
  453.  
  454. sleep 4
  455. #finally start firefox
  456. dradis_browser
  457.  
  458. exit 0
  459. }
  460.  
  461.  
  462.  
  463. #quick dradis initialization without backup
  464. dradis_quick () {
  465.  
  466. if [ ${BASE_DIR} == "CHANGE_ME" ]; then
  467.     printf "\n\n###ERROR### SORRY, you didn't change the BASE_DIR paramater !\n"
  468.     printf "###ERROR## Okay, fix it - edit BASE_DIR paramater in this script!\n\n"
  469.     printf "###INFO## will start nano for your to edit file!\n\n"
  470.     sleep 5
  471.     nano startDradis
  472.     printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n" 
  473.     exit 0
  474. fi
  475.  
  476. if [ ! -f "$BASE_DIR/.verifycalled" ]; then
  477.     printf "###WARNING## You still have not executed verify.sh !!\n\n"
  478.     read -p "Should we really proceed? (y/n)" -e optVerify
  479. fi
  480.  
  481. if [ "$optVerify" == "n" ]; then
  482.     printf "\n###INFO## GOOD CHOICE, run now verify.sh !!\n\n"
  483.     cd ${BASE_DIR}
  484.     sh verify.sh
  485.     printf "\n###INFO## CHANGE directory NOW TO: $BASE_DIR & run startDradis again !!\n\n"
  486.     exit 0
  487. fi
  488.  
  489. ##look for required env settings...
  490. if [ ! "$(pidof -s xinit)" ]; then
  491.     printf "\n###ERROR## SORRY, X11 is not running and we do use xterm to start dradis!\n"
  492.     printf "###ERROR## also to start firefox for you..\n"
  493.     exit 0
  494. elif [ "${DRADIS_IP}" == "localhost" ]; then
  495.     if [ ! $(ifconfig -a | awk '/^[lL][a-zA-Z0-9,_:.]/{n=$1}($1=="UP"){u[n]=n}END{for(n in u){print u[n]}}') ]; then
  496.         printf "\n\t###ERROR## SORRY, seems your dont have a loopback device?\n"
  497.         printf "we do need it, because dradis server is usually running on localhost!\n"
  498.         printf "Fix your networking first!\n"
  499.         exit 0
  500.     fi
  501. fi
  502.  
  503. if [ ! -n "$(env |grep "^DISPLAY" |cut -d"=" -f2)" ]; then
  504.     printf "\n###ERROR## SORRY, can't find a proper DISPLAY variable!Are you running X??\n"
  505.     printf "\n###ERROR### ..let's see if we can fix it...\n"
  506.    
  507.     #look if we can setup display var ....for the real lazy onces :-)
  508.     user_id=$(ps -ef |grep xinit |grep -v grep |cut -d" " -f1)
  509.     if [ -d "/home/${user_id}" ]; then
  510.         if [ -f "/home/${user_id}/.Xauthority" ]; then
  511.             export XAUTHORITY=/home/${user_id}/.Xauthority
  512.             export DISPLAY=:0.0
  513.         fi
  514.     fi
  515.    
  516.     if [ ! -n "$(env |grep "^DISPLAY" |cut -d"=" -f2)" ]; then
  517.         printf "\n###INFO### PROBLEM fixed :-)\n"
  518.     else
  519.         printf "\n###ERROR### Can't do magic, please fix DISPLAY and xauthority issue!\n"
  520.         exit 0
  521.     fi
  522. fi
  523.  
  524. if [ -f "$BASE_DIR/_TEMPLATES/${BANNER}" ]; then
  525.     printf "\n###INFO## Found custom banner, will copy it to the right folder...\n"
  526.     cp $BASE_DIR/_TEMPLATES/${BANNER} $BASE_DIR/server/public/images/banner.png
  527. fi
  528.  
  529. # remove production env variable in environment.rb - done during install, but safer to do it again !
  530. sed -i "s/^ENV/#ENV/g" ${BASE_DIR}/server/config/environment.rb && \
  531. sed -i "s/^RAILS_ENV/#RAILS_ENV/g" ${BASE_DIR}/server/config/environment.rb
  532.  
  533. read -p "Initial dradis shared login password? : " -e optPWD
  534.  
  535. if [ -n "$optPWD" ]; then
  536.     DRADIS_PWD="${optPWD}" 
  537. else
  538.     DRADIS_PWD="topSecure" 
  539. fi
  540.  
  541. pgrep -f 'ruby ./script/server' >/dev/null
  542. if [[ $? -eq 0 ]]; then
  543.     printf "\n\n###WARNING## dradis server active..I KILL IT NOW!\n\n"
  544.     kill -9 `pgrep -f 'ruby ./script/server'` >/dev/null
  545. fi
  546.    
  547.  
  548. if [ -n "${DRADIS_ENV}" ]; then
  549.     cd ${BASE_DIR}/server/config
  550.    
  551.     if [ ! -f environments/${DRADIS_ENV}.rb ]; then
  552.         DRADIS_DB="${DRADIS_ENV}.sqlite3"
  553.         cp environments/production.rb environments/${DRADIS_ENV}.rb
  554.        
  555.         if [ -z "$(cat database.yml |grep '${DRADIS_ENV}:')" ]; then
  556.             printf "\n\n${DRADIS_ENV}:\n  adapter: sqlite3\n  database: db/${DRADIS_DB}\n  timeout: 5000\n\n" >>database.yml
  557.         fi
  558.     fi
  559. else
  560.     DRADIS_DB=production.sqlite3
  561. fi
  562.  
  563. if [ ! -f "$BASE_DIR/server/db/migrate/007_create_custom_environment.rb" ]; then
  564.     cp $BASE_DIR/_TEMPLATES/007_create_custom_environment.rb $BASE_DIR/server/db/migrate/
  565. fi
  566.  
  567. printf "###INFO## clear previous environment..\n"
  568. cd ${BASE_DIR}/server
  569. export RAILS_ENV=${DRADIS_ENV};rake dradis:reset >/dev/null
  570.  
  571.  
  572. db_date=$(date '+%F %H:%M:%S')
  573. sqlite3 -line ${BASE_DIR}/server/db/${DRADIS_DB} "update configurations set value='${DRADIS_PWD}' where name='password'"
  574.  
  575.  
  576. read -p "Would you like to import a predefined template? (y/n)" -e askTMPL
  577. if [ $askTMPL == "y" ]; then
  578.  
  579.     read -p "Choose template (generic, mobile or wlan): " -e askTYPE
  580.     if [ $askTYPE == "generic" ]; then
  581.         TEMPLATE="generic"
  582.     elif [ $askTYPE == "mobile" ]; then
  583.         TEMPLATE="mobile"
  584.     elif [ $askTYPE == "wlan" ]; then
  585.         TEMPLATE="wlan"
  586.     fi
  587.    
  588.     #let's call the import template function
  589.     printf "\n###INFO## ...will import your requested template...\n"
  590.     dradis_import
  591. fi
  592.  
  593.  
  594. ##finally we start the server and client if needed
  595. cd ${BASE_DIR}/server
  596. ${TERMINAL} -T "DRADIS SERVER" -geometry 70x25+0+0 -e ruby ./script/server -e ${DRADIS_ENV} -p ${DRADIS_PORT} -b ${DRADIS_IP}&
  597.  
  598. #create a sym link in our log dir to the server log...
  599. if [ ! -f "$BASE_DIR/_LOGS/$DRADIS_ENV.log" ]; then
  600.     cd $BASE_DIR/_LOGS/
  601.     ln -s $BASE_DIR/server/log/${DRADIS_ENV}.log
  602. fi
  603.  
  604. sleep 4
  605. #finally start firefox
  606. dradis_browser
  607.  
  608. exit 0
  609. }
  610.  
  611.  
  612.  
  613. dradis_ssl () {
  614.  
  615. read -p "Create a new SSL Certificate (y/n)? : " -e optSSL
  616.  
  617. if [ $optSSL == "y" ]; then
  618.     ## 1.step creating proper self-signed certs
  619.     if [ -f "${BASE_DIR}/server/config/ssl/server.crt" ]; then
  620.         cd ${BASE_DIR}/server/config/ssl
  621.         printf "\n###INFO### creating new ssl key...\n"
  622.         $(openssl genrsa -des3 -out server.key 1024)
  623.         printf "\n###INFO### create now server request, based on our new key...\n"
  624.         printf "\n###INFO### add all your custom infos...\n"
  625.         $(openssl req -new -key server.key.insecure -out server.csr)
  626.         printf "\n###INFO### create a self-signed certificate..don't wanna sponsor verisign & co..\n"
  627.         $(openssl x509 -req -days 365 -in server.csr -signkey server.key.insecure -out server.crt >/dev/null)
  628.         printf "\n\n###INFO### ..seems we are done :-)\n"
  629.     else
  630.         printf "\n\n###ERROR## SORRY, don't see any existing ssl certificate in ${BASE_DIR}/server/config/ssl/\n\n"
  631.     fi
  632. fi
  633.  
  634. clear
  635. }
  636.  
  637.  
  638.  
  639. dradis_word () {
  640.  
  641. clear
  642. XML_PARSER="$BASE_DIR/_TEMPLATES/dradis_xml_parser.pl"
  643. XML_FILE="$BASE_DIR/_TEMPLATES/word_custom_template.xml"
  644.  
  645.  
  646. if [ ! -f "$XML_FILE" ]; then
  647.     printf "\n\n###ERROR## Sorry, there is no default template: $XML_FILE!\n"
  648.     printf "###ERROR## We need an initial dradis XML template - so I will stop now!\n\n\n"
  649.     exit 0
  650. fi
  651.  
  652. #we do need some specific perl modules..
  653. perl -e 'use XML::Simple;' 2>/dev/null
  654. if [ `echo $?` != "0" ]; then
  655.         printf "\n###ERROR## Please, install missing Perl module:\n\n"
  656.         read -p "Install XML::Simple Perl module? (y/n)" -e optPerl
  657.         if [ $optPerl == "y" ]; then
  658.             perl -MCPAN -e 'install XML::Simple'
  659.         fi
  660.         sleep 2
  661.         clear
  662. fi
  663.  
  664. #dump current dradis XML meta tags
  665. $XML_PARSER -f $XML_FILE
  666.  
  667. read -p "Should we place your 'word_custom_template.xml' to the right dradis location? (y/n)" -e optXML
  668.  
  669. if [ $optXML == "y" ]; then
  670.     #finally copy template to the right place
  671.     cd $BASE_DIR/_TEMPLATES
  672.     if [ -f "$XML_FILE" ]; then
  673.         if [ -d $BASE_DIR/server/vendor/plugins/word_export ]; then
  674.             printf "\n\n###INFO## Copy your template to: $BASE_DIR/server/vendor/plugins/word_export/template.xml\n\n"
  675.             cp $XML_FILE $BASE_DIR/server/vendor/plugins/word_export/template.xml
  676.             sleep 2
  677.         else
  678.             printf "\n\n###ERROR## Sorry, missing word_export plugin - will not copy it!\n";
  679.             sleep 4
  680.         fi
  681.     fi
  682. fi
  683. clear
  684.  
  685. }
  686.  
  687.  
  688.  
  689. dradis_start () {
  690.    
  691.     printf "\n###INFO## Starting dradis $DRADIS_RELEASE....\n"
  692.     cd $BASE_DIR/server
  693.    
  694.     if [ ! "$(pidof -s xinit)" ]; then
  695.     printf "\n###ERROR## SORRY, X11 is not running and we do use xterm to start dradis!\n"
  696.     printf "###ERROR## also to start firefox for you..\n"
  697.     exit 0
  698.     elif [ "${DRADIS_IP}" == "localhost" ]; then
  699.         if [ ! $(ifconfig -a | awk '/^[lL][a-zA-Z0-9,_:.]/{n=$1}($1=="UP"){u[n]=n}END{for(n in u){print u[n]}}') ]; then
  700.             printf "\n\t###ERROR## SORRY, seems your dont have a loopback device?\n"
  701.             printf "we do need it, because dradis server is usually running on localhost!\n"
  702.             printf "Fix your networking first!\n"
  703.             exit 0
  704.         fi
  705. fi
  706.  
  707. if [ ! -n "$(env |grep "^DISPLAY" |cut -d"=" -f2)" ]; then
  708.     printf "\n###ERROR## SORRY, can't find a proper DISPLAY variable!Are you running X??\n"
  709.     printf "\n###ERROR### ..let's see if we can fix it...\n"
  710.    
  711.     #look if we can setup display var ....for the real lazy onces :-)
  712.     user_id=$(ps -ef |grep xinit |grep -v grep |cut -d" " -f1)
  713.     if [ -d "/home/${user_id}" ]; then
  714.         if [ -f "/home/${user_id}/.Xauthority" ]; then
  715.             export XAUTHORITY=/home/${user_id}/.Xauthority
  716.             export DISPLAY=:0.0
  717.         fi
  718.     fi
  719.    
  720.     if [ ! -n "$(env |grep "^DISPLAY" |cut -d"=" -f2)" ]; then
  721.         printf "\n###INFO### PROBLEM fixed :-)\n"
  722.     else
  723.         printf "\n###ERROR### Can't do magic, please fix DISPLAY and xauthority issue!\n"
  724.         exit 0
  725.     fi
  726. fi
  727.  
  728. ##finally we start the server and client if needed
  729. cd ${BASE_DIR}/server
  730. ${TERMINAL} -T "DRADIS SERVER" -geometry 70x25+0+0 -e ruby ./script/server -e ${DRADIS_ENV} -p ${DRADIS_PORT} -b ${DRADIS_IP}&
  731.  
  732. #create a sym link in our log dir to the server log...
  733. if [ ! -f "$BASE_DIR/_LOGS/$DRADIS_ENV.log" ]; then
  734.     cd $BASE_DIR/_LOGS/
  735.     ln -s $BASE_DIR/server/log/${DRADIS_ENV}.log
  736. fi
  737.  
  738. sleep 4
  739.  
  740. #call firefox
  741. dradis_browser
  742.  
  743. exit 0
  744. }
  745.  
  746.  
  747.  
  748. dradis_pwd () {
  749.     clear
  750.     GETIT=`sqlite3 -line -noheader $BASE_DIR/server/db/$DRADIS_DB "select * from configurations where name='password'" |grep value  |cut -d"=" -f2`
  751.     printf "\n\nYour current shared Password:\t$GETIT\n\n"
  752.     sleep 3
  753.     clear
  754. }
  755.  
  756.  
  757.  
  758.  
  759. ####
  760. ## begin menu & loop forever...
  761. ####
  762. clear
  763. echo
  764. echo -e '\E[37;44m'"\t\033[1mProfessional Pentest documentation matters!\033[0m"
  765. echo -e '\E[37;44m'"\t\t\033[1mVersion: $RELEASE, Last update: $UPDATE\033[0m"
  766.  
  767. if [ $BASE_DIR != "CHANGE_ME" ]; then
  768.     if ([ ! -f  $BASE_DIR/.installed ] || [ ! -d $BASE_DIR/server ]); then
  769.         printf "\n\n!!! Seems you didn't install properly dradis 2.5, please start with option 1 !!!\n"
  770.         printf "  Install it now and than you'll see all other options you can choose ;-)\n\n"
  771.  
  772.     while :
  773.     do
  774. cat << !
  775.  
  776. ----------------------  DRADIS FRAMEWORK MENU  --------------------------
  777. |                    powered by Advanced Services           |
  778. |                                   |
  779. | 1. Start new dradis $DRADIS_RELEASE custom installation               |
  780. | 2. Quit                               |
  781. |                                   |
  782. -------------------------------------------------------------------------
  783. !
  784. echo
  785. echo
  786. echo -n " Select an option from the menu: "
  787. read choice
  788. case $choice in
  789.  
  790. 1) dradis_new ;;
  791. 2) exit ;;
  792. *) echo ""$choice" is not valid! "; sleep 2 ;;
  793.  
  794.         esac
  795.         done
  796.     else
  797.         while :
  798.         do
  799. cat << !
  800.  
  801. -----------------  MOTOROLA - DRADIS FRAMEWORK MENU  --------------------
  802. |                    powered by Advanced Services           |
  803. |                                   |
  804. |                                   |
  805. | 1. Only start Dradis $DRADIS_RELEASE server                   |
  806. |                                   |
  807. | 2. Quick dradis $DRADIS_RELEASE initalization (no Backup)         |
  808. |    (wipe exisiting data - quick usage for engagements)        |
  809. |                                   |
  810. | 3. Use existing dradis environment (with Backup)          |
  811. |                                   |
  812. | 4. Create a custom dradis SSL certificate             |
  813. |                                   |
  814. | 5. Dump custom Word template (properties & usage)         |
  815. |                                   |
  816. | 6. New dradis $DRADIS_RELEASE custom installation             |
  817. |    (overwrites existing installation - change BASE_DIR variable!) |
  818. |                                   |
  819. | 7. Show me the current shared password                |
  820. |                                   |
  821. | 8. Quit                               |
  822. |                                   |
  823. -------------------------------------------------------------------------
  824. !
  825. echo
  826. echo
  827. echo -n " Select an option from the menu: "
  828. read choice
  829. case $choice in
  830.  
  831. 1) dradis_start ;;
  832. 2) dradis_quick ;;
  833. 3) dradis_backup ;;
  834. 4) dradis_ssl ;;
  835. 5) dradis_word ;;
  836. 6) dradis_new ;;
  837. 7) dradis_pwd ;;
  838. 8) exit ;;
  839. *) echo ""$choice" is not valid! "; sleep 2 ;;
  840.  
  841.         esac
  842.         done
  843.     fi
  844.     else
  845.     printf "\n\n###ERROR## Sorry, you have to adjust BASE_DIR variable! Will call nano for you\n"
  846.     sleep 4
  847.     nano startDradis
  848.     printf "\n\n###INFO## Restart 'startDradis' script again!\n"   
  849.     exit 0
  850. fi
  851.  
  852. #EOF
  853.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement