Advertisement
r00t-3xp10it

Apache2Domain.sh

Feb 26th, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.13 KB | None | 0 0
  1. #!/bin/sh
  2. # Apache2Domain.sh | Author: r00t-3xp10it
  3. # https://sourceforge.net/u/peterubuntu10/profile/
  4. # ---
  5. # Config apache2 domain name eg. http://malign0server.com
  6. # Domain name directorys will be build inside apache2 webroot
  7. # Example: /var/www/html/public_html/malign0server.com
  8. # apachedomain.log will be build in working directory
  9. # ---
  10. # works in apache/2.2.22 or apache/2.4 (tested)
  11. # works in linux ubuntu and kali 2.0 or old (tested)
  12. # screenshot: https://dl.dropboxusercontent.com/u/21426454/malign0server.png
  13. # ---
  14.  
  15.  
  16.  
  17.  
  18. # ---------------------
  19. # check if user is root
  20. # ---------------------
  21. if [ $(id -u) != "0" ]; then
  22. echo "[☠ ] we need to be root to run this script..."
  23. echo "[☠ ] execute [ sudo ./apachedomain.sh ] on terminal"
  24. exit
  25. else
  26. echo "root user" > /dev/null 2>&1
  27. fi
  28.  
  29.  
  30.  
  31.  
  32.  
  33. # ----------------------
  34. # variable declarations
  35. # ----------------------
  36. OS=`uname` # grab OS
  37. H0m3=`echo ~` # grab home path
  38. user=`who | cut -d' ' -f1 | sort | uniq` # grab username
  39. DiStR0=`awk '{print $1}' /etc/issue` # grab distribution -  Ubuntu or Kali
  40. InT3R=`netstat -r | grep "default" | awk {'print $8'}` # grab interface in use
  41. IP=`ifconfig $InT3R | egrep -w "inet" | cut -d ':' -f2 | cut -d 'B' -f1`
  42. IPATH=`pwd` # grab apachesetup.sh install path
  43.  
  44.  
  45.  
  46.  
  47. clear
  48. echo ""
  49. # simple banner
  50. echo "[☆ ] Author: r00t-3xp10it"
  51. echo "[☆ ] CONFIG OR DELETE APACHE2 WEBSERVER DOMAIN NAME"
  52. echo "[☆ ] DIRECTORYS WILL BE WRITEN INSIDE APACHE2 WEBROOT"
  53. echo "[☆ ] E.G. /var/www/html/public_html/domain_name.com"
  54. echo "[☆ ] APACHE2 (DOMAIN NAME) CAN BE ACCESSED IN:"
  55. echo "[☆ ] E.G. http://domain_name.com"
  56. echo "" && echo ""
  57.  
  58.  
  59.  
  60.  
  61.  
  62. # check if apache2 exists
  63. ch3=`which apache2`
  64. if [ "$?" -eq "0" ]; then
  65. echo "[✔ ] apache2 webserver..........[found]"
  66. sleep 2
  67. else
  68. echo ""
  69. echo "[☠ ] apache2 webserver -> not found   ]"
  70. echo "[☠ ] This script requires apache2     ]"
  71. echo ""
  72. sudo apt-get install apache2
  73. echo ""
  74. sleep 2
  75. fi
  76.  
  77.  
  78.  
  79.  
  80.  
  81. # -----------------------------------------------
  82. # grab apache2 webroot path or config domain name
  83. # http://192.168.1.208 OR http://malign0server
  84. # -----------------------------------------------
  85. # Input apache2 webroot path
  86. ApAcHe=$(zenity --title "☠ Enter APACHE2 WEBROOT PATH ☠" --text "example: /var/www/html" --entry --width 330) > /dev/null 2>&1
  87. QuE=$(zenity --list --title "APACHE2 DOMAIN NAME CONFIGURATION" --text "\nChose option:" --radiolist --column "Pick" --column "Option" TRUE "Build new domain name" FALSE "Delete old domain name" --width 350 --height 190) > /dev/null 2>&1
  88.  
  89.  
  90. if [ "$QuE" = "Build new domain name" ]; then
  91.   # check if running Apache/2.2 or Apache/2.4
  92.   apache2 -v | grep "Server version" | cut -d ':' -f2 | cut -d '(' -f1 >> version.log
  93.   sed -i "s/ //g" version.log
  94.   un=`cat version.log`
  95.   rm version.log > /dev/null 2>&1
  96.   D0MaIn=$(zenity --title="ENTER DOMAIN NAME TO USE" --text "example: malign0server.com" --entry --width 330) > /dev/null 2>&1
  97.  
  98.      if [ "$un" = "Apache/2.2.22" ]; then
  99.        # build malign0server.conf apache 2.2
  100.        echo "[✔ ] Building -> $D0MaIn.conf"
  101.        echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$D0MaIn.conf
  102.        echo "   ServerName $D0MaIn" >> /etc/apache2/sites-available/$D0MaIn.conf
  103.        echo "   DocumentRoot $ApAcHe/public_html/$D0MaIn" >> /etc/apache2/sites-available/$D0MaIn.conf
  104.        echo "</VirtualHost>" >> /etc/apache2/sites-available/$D0MaIn.conf
  105.        sleep 2
  106.      else
  107.        # build malign0server.conf apache 2.4
  108.        echo "[✔ ] Building -> $D0MaIn.conf"
  109.        echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$D0MaIn.conf
  110.        echo "   ServerName $D0MaIn" >> /etc/apache2/sites-available/$D0MaIn.conf
  111.        echo "   DocumentRoot $ApAcHe/public_html/$D0MaIn" >> /etc/apache2/sites-available/$D0MaIn.conf
  112.        echo "   <Directory $ApAcHe/public_html/$D0MaIn/>" >> /etc/apache2/sites-available/$D0MaIn.conf
  113.        echo "      Require all granted" >> /etc/apache2/sites-available/$D0MaIn.conf
  114.        echo "   </Directory>" >> /etc/apache2/sites-available/$D0MaIn.conf
  115.        echo "</VirtualHost>" >> /etc/apache2/sites-available/$D0MaIn.conf
  116.        sleep 2
  117.      fi
  118.  
  119.  
  120.   # build directorys needed by malign0server.conf
  121.   echo "[✔ ] Building -> Domain directorys"
  122.   mkdir -p $ApAcHe/public_html/$D0MaIn
  123.   echo "<html><H1>NEW DOMAIN WORKING ...</H1></html>" > $ApAcHe/public_html/$D0MaIn/index.html
  124.   sudo chmod -R g+rw $ApAcHe/public_html/$D0MaIn
  125.   sleep 2
  126.  
  127.  
  128.   # config hosts file (DNS record)
  129.   echo "[✔ ] Added -> DNS record to /etc/hosts"
  130.   echo "127.0.0.1 $D0MaIn" >> /etc/hosts
  131.   echo "" && echo ""
  132.   sleep 2
  133.  
  134.  
  135.   # enable new site
  136.   a2ensite $D0MaIn.conf
  137.   /etc/init.d/apache2 restart
  138.  
  139.  
  140.   # append recent configs to logfile
  141.   echo "#################################" >> apachedomain.log
  142.   echo "# apache domain - configuration #" >> apachedomain.log
  143.   echo "#################################" >> apachedomain.log
  144.   echo "# apache2 webroot path" >> apachedomain.log
  145.   echo "APACHE_WEBROOT=$ApAcHe" >> apachedomain.log
  146.   echo "DOMAIN_NAME=$D0MaIn" >> apachedomain.log
  147.   echo "URL_VECTOR=http://$D0MaIn" >> apachedomain.log
  148.   echo "/ETC/HOSTS_FILE=127.0.0.1 $D0MaIn" >> apachedomain.log
  149.   echo "DOMAIN_ROOT=$ApAcHe/public_html/$D0MaIn" >> apachedomain.log
  150.   echo "" >> apachedomain.log
  151.   echo "# files build:" >> apachedomain.log
  152.   echo "/etc/apache2/sites-available/$D0MaIn.conf" >> apachedomain.log
  153.   echo "/etc/apache2/sites-enabled/$D0MaIn.conf" >> apachedomain.log
  154.   echo "$ApAcHe/public_html/$D0MaIn" >> apachedomain.log
  155.   echo "/etc/hosts" >> apachedomain.log
  156.   echo "" >> apachedomain.log
  157.   echo "" >> apachedomain.log
  158.   echo ""
  159.   # display active configs to user
  160.   echo "[☆ ] APACHE_WEBROOT -> $ApAcHe"
  161.   echo "[☆ ] DOMAIN_NAME    -> $D0MaIn"
  162.   echo "[☆ ] URL_VECTOR     -> http://$D0MaIn"
  163.   echo "[☆ ] HOSTS_FILE     -> 127.0.0.1 $D0MaIn"
  164.   echo "[☆ ] DOMAIN_ROOT    -> $ApAcHe/public_html/$D0MaIn"
  165.   echo ""
  166.   echo "[✔ ] [ ☠ YOUR '$D0MaIn' DOMAIN ITS READY TO BE USED ☠ ]..."
  167.   sleep 2
  168.   echo "[☆ ] RUN THIS SCRIPT AGAIN IF YOU WISH TO DELETE RECENT CONFIGS"
  169.   echo "[☆ ] OR CONFIG A NEW DOMAIN NAME TO USE IN APACHE2 WEBSERVER"
  170.   echo "[☆ ] REMMENBER TO CHECK 'apachedomain.log' FOR FURTHER INFO."
  171.   sleep 2
  172.  
  173.  
  174. else
  175.  
  176.  
  177.   # use default configuration
  178.   D0MaIn=$(zenity --title="ENTER DOMAIN NAME TO DELETE" --text "example: malign0server.com" --entry --width 330) > /dev/null 2>&1
  179.   echo "[✔ ] apache2 -> default config in use!"
  180.   rm /etc/apache2/sites-available/$D0MaIn.conf > /dev/null 2>&1
  181.   rm /etc/apache2/sites-enabled/$D0MaIn.conf > /dev/null 2>&1
  182.   rm apachedomain.log > /dev/null 2>&1
  183.   rm -r $ApAcHe/public_html > /dev/null 2>&1
  184.   sed "s|127.0.0.1 $D0MaIn||" /etc/hosts > /etc/hosts.bak
  185.   mv /etc/hosts.bak /etc/hosts > /dev/null 2>&1
  186.   echo "" && echo ""
  187.   /etc/init.d/apache2 restart
  188.   sleep 2
  189.   echo ""
  190.   # display active configs to user
  191.   echo "[☆ ] APACHE_WEBROOT -> $ApAcHe"
  192.   echo "[☆ ] DOMAIN_NAME    -> localhost"
  193.   echo "[☆ ] URL_VECTOR     -> http://$IP"
  194.   echo "[✔ ] RUN THIS SCRIPT AGAIN IF YOU WISH TO CONFIG A NEW DOMAIN NAME"
  195.   echo ""
  196.   /etc/init.d/apache2 stop
  197.  
  198. fi
  199. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement