#!/bin/bash ######################################################## # T-Pot post install script # # Ubuntu server 16.04.0, x64 # # # # v17.06 by mo, DTAG, 2017-03-22 # ######################################################## # Set TERM, DIALOGRC export TERM=xterm export DIALOGRC=/etc/dialogrc # Let's load dialog color theme cp /root/tpot/etc/dialogrc /etc/ # Some global vars myPROXYFILEPATH="/root/tpot/etc/proxy" myNTPCONFPATH="/root/tpot/etc/ntp" myPFXPATH="/root/tpot/keys/8021x.pfx" myPFXPWPATH="/root/tpot/keys/8021x.pw" myPFXHOSTIDPATH="/root/tpot/keys/8021x.id" myBACKTITLE="T-Pot Installer" mySITES="https://index.docker.io https://ubuntu.com https://github.com http://nsanamegenerator.com" # Let's create a function for colorful output fuECHO () { local myRED=1 local myWHT=7 tput setaf $myRED -T xterm echo "$1" "$2" tput setaf $myWHT -T xterm } fuRANDOMWORD () { local myWORDFILE=/usr/share/dict/names local myLINES=$(cat $myWORDFILE | wc -l) local myRANDOM=$((RANDOM % $myLINES)) local myNUM=$((myRANDOM * myRANDOM % $myLINES + 1)) echo -n $(sed -n "$myNUM p" $myWORDFILE | tr -d \' | tr A-Z a-z) } # Let's make sure there is a warning if running for a second time if [ -f install.log ]; then fuECHO "### Running more than once may complicate things. Erase install.log if you are really sure." exit 1; fi # Let's log for the beauty of it set -e exec 2> >(tee "install.err") exec > >(tee "install.log") # Let's setup the proxy for env if [ -f $myPROXYFILEPATH ]; then fuECHO "### Setting up the proxy." myPROXY=$(cat $myPROXYFILEPATH) tee -a /etc/environment < /dev/null; if [ $? -ne 0 ]; then dialog --backtitle $myBACKTITLE --title "[ Continue? ]" --yesno "\nInternet connection test failed. This might indicate some problems with your connection. You can continue, but the installation might fail." 10 50 if [ $? = 1 ]; then dialog --backtitle $myBACKTITLE --title "[ Abort ]" --msgbox "\nInstallation aborted. Exiting the installer." 7 50 exit else break; fi; fi; done; # Let's remove NGINX default website fuECHO "### Removing NGINX default website." rm /etc/nginx/sites-enabled/default rm /etc/nginx/sites-available/default rm /usr/share/nginx/html/index.html # Let's wait a few seconds to avoid interference with service messages fuECHO "### Waiting a few seconds to avoid interference with service messages." sleep 5 # Let's ask user for install flavor # Install types are TPOT, HP, INDUSTRIAL, ALL myFLAVOR=$(dialog --backtitle $myBACKTITLE --title "[ Choose your edition ]" --no-tags --menu \ "\nRequired: 4GB RAM, 64GB disk\nRecommended: 8GB RAM, 128GB SSD" 14 60 4 \ "TPOT" "Standard Honeypots, Suricata & ELK" \ "HP" "Honeypots only, w/o Suricata & ELK" \ "INDUSTRIAL" "Conpot, eMobility, Suricata & ELK" \ "EVERYTHING" "Everything" 3>&1 1>&2 2>&3 3>&-) # Let's ask user for a web user and password myOK="1" myUSER="tsec" while [ 1 != 2 ] do myUSER=$(dialog --backtitle $myBACKTITLE --title "[ Enter your web user name ]" --inputbox "\nUsername (tsec not allowed)" 9 50 3>&1 1>&2 2>&3 3>&-) dialog --backtitle $myBACKTITLE --title "[ Your username is ]" --yesno "\n"$myUSER 7 50 myOK=$? if [ "$myOK" = "0" ] && [ "$myUSER" != "tsec" ] && [ "$myUSER" != "" ]; then break fi done myPASS1="pass1" myPASS2="pass2" while [ "$myPASS1" != "$myPASS2" ] do while [ "$myPASS1" == "pass1" ] || [ "$myPASS1" == "" ] do myPASS1=$(dialog --insecure --backtitle $myBACKTITLE --title "[ Enter your web user password ]" --passwordbox "\nPassword" 9 50 3>&1 1>&2 2>&3 3>&-) done myPASS2=$(dialog --insecure --backtitle $myBACKTITLE --title "[ Repeat web user password ]" --passwordbox "\nPassword" 9 50 3>&1 1>&2 2>&3 3>&-) if [ "$myPASS1" != "$myPASS2" ]; then dialog --backtitle $myBACKTITLE --title "[ Passwords do not match. ]" --msgbox "\nPlease re-enter your password." 7 50 myPASS1="pass1" myPASS2="pass2" fi done htpasswd -b -c /etc/nginx/nginxpasswd $myUSER $myPASS1 fuECHO # Let's generate a SSL self-signed certificate without interaction (browsers will see it invalid anyway) fuECHO "### Generating a self-signed-certificate for NGINX." mkdir -p /etc/nginx/ssl openssl req -nodes -x509 -sha512 -newkey rsa:8192 -keyout "/etc/nginx/ssl/nginx.key" -out "/etc/nginx/ssl/nginx.crt" -days 3650 -subj '/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd' # Let's setup the ntp server if [ -f $myNTPCONFPATH ]; then fuECHO "### Setting up the ntp server." cp $myNTPCONFPATH /etc/ntp.conf fi # Let's setup 802.1x networking if [ -f $myPFXPATH ]; then fuECHO "### Setting up 802.1x networking." cp $myPFXPATH /etc/wpa_supplicant/ if [ -f $myPFXPWPATH ]; then fuECHO "### Setting up 802.1x password." myPFXPW=$(cat $myPFXPWPATH) fi myPFXHOSTID=$(cat $myPFXHOSTIDPATH) tee -a /etc/network/interfaces < # wpa-ap-scan 1 # wpa-proto RSN # wpa-pairwise CCMP # wpa-group CCMP # wpa-key-mgmt WPA-PSK # wpa-psk "" EOF # Let's modify the sources list sed -i '/cdrom/d' /etc/apt/sources.list # Let's make sure SSH roaming is turned off (CVE-2016-0777, CVE-2016-0778) fuECHO "### Let's make sure SSH roaming is turned off." tee -a /etc/ssh/ssh_config < /dev/tty2 # Check if containers and services are up */5 * * * * root check.sh # Example for alerta-cli IP update #*/5 * * * * root alerta --endpoint-url http://:/api delete --filters resource= && alerta --endpoint-url http://:/api send -e IP -r -E Production -s ok -S T-Pot -t \$(cat /data/elk/logstash/mylocal.ip) --status open # Check if updated images are available and download them 27 1 * * * root for i in \$(cat /data/images.conf); do docker pull dtagdevsec/\$i:1706; done # Restart docker service and containers 27 3 * * * root dcres.sh # Delete elastic indices older than 90 days (kibana index is omitted by default) 27 4 * * * root docker exec elk bash -c '/usr/local/bin/curator --host 127.0.0.1 delete indices --older-than 90 --time-unit days --timestring \%Y.\%m.\%d' # Update IP and erase check.lock if it exists 27 15 * * * root /etc/rc.local # Daily reboot 27 23 * * * root reboot # Check for updated packages every sunday, upgrade and reboot 27 16 * * 0 root apt-get autoclean -y && apt-get autoremove -y && apt-get update -y && apt-get upgrade -y && sleep 10 && reboot EOF # Let's create some files and folders fuECHO "### Creating some files and folders." mkdir -p /data/conpot/log \ /data/cowrie/log/tty/ /data/cowrie/downloads/ /data/cowrie/keys/ /data/cowrie/misc/ \ /data/dionaea/log /data/dionaea/bistreams /data/dionaea/binaries /data/dionaea/rtp /data/dionaea/roots/ftp /data/dionaea/roots/tftp /data/dionaea/roots/www /data/dionaea/roots/upnp \ /data/elasticpot/log \ /data/elk/data /data/elk/log /data/elk/logstash/conf \ /data/glastopf /data/honeytrap/log/ /data/honeytrap/attacks/ /data/honeytrap/downloads/ \ /data/emobility/log \ /data/ews/conf \ /data/suricata/log /home/tsec/.ssh/ # Let's take care of some files and permissions before copying chmod 500 /root/tpot/bin/* chmod 600 /root/tpot/data/* chmod 644 /root/tpot/etc/issue chmod 755 /root/tpot/etc/rc.local chmod 644 /root/tpot/data/systemd/* # Let's copy some files tar xvfz /root/tpot/data/elkbase.tgz -C / cp /root/tpot/data/elkbase.tgz /data/ cp -R /root/tpot/bin/* /usr/bin/ cp -R /root/tpot/data/* /data/ cp /root/tpot/data/systemd/* /etc/systemd/system/ cp /root/tpot/etc/issue /etc/ cp -R /root/tpot/etc/nginx/ssl /etc/nginx/ cp /root/tpot/etc/nginx/tpotweb.conf /etc/nginx/sites-available/ cp /root/tpot/etc/nginx/nginx.conf /etc/nginx/nginx.conf cp /root/tpot/keys/authorized_keys /home/tsec/.ssh/authorized_keys cp /root/tpot/usr/share/nginx/html/* /usr/share/nginx/html/ for i in $(cat /data/images.conf); do systemctl enable $i; done systemctl enable wetty # Let's enable T-Pot website fuECHO "### Enabling T-Pot website." ln -s /etc/nginx/sites-available/tpotweb.conf /etc/nginx/sites-enabled/tpotweb.conf # Let's take care of some files and permissions chmod 760 -R /data chown tpot:tpot -R /data chmod 600 /home/tsec/.ssh/authorized_keys chown tsec:tsec /home/tsec/.ssh /home/tsec/.ssh/authorized_keys # Let's replace "quiet splash" options, set a console font for more screen canvas and update grub sed -i 's#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"#GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0"#' /etc/default/grub sed -i 's#GRUB_CMDLINE_LINUX=""#GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"#' /etc/default/grub #sed -i 's#\#GRUB_GFXMODE=640x480#GRUB_GFXMODE=800x600x32#' /etc/default/grub #tee -a /etc/default/grub < /data/elk/logstash/mylocal.ip chown tpot:tpot /data/ews/conf/ews.ip # Final steps fuECHO "### Thanks for your patience. Now rebooting." mv /root/tpot/etc/rc.local /etc/rc.local && rm -rf /root/tpot/ && sleep 2 && reboot