2015-12-08 14:47:39 +00:00
#!/bin/bash
2017-05-01 19:03:27 +00:00
# T-Pot post install script
2015-12-08 14:47:39 +00:00
2017-03-22 18:27:43 +00:00
# Set TERM, DIALOGRC
2017-03-22 18:42:24 +00:00
export TERM = linux
2017-03-22 18:27:43 +00:00
export DIALOGRC = /etc/dialogrc
# Let's load dialog color theme
cp /root/tpot/etc/dialogrc /etc/
2015-12-08 14:47:39 +00:00
# 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"
2017-04-20 23:11:10 +00:00
myBACKTITLE = "T-Pot-Installer"
2017-04-24 14:57:58 +00:00
mySITES = "https://index.docker.io https://github.com http://nsanamegenerator.com https://pypi.python.org https://ubuntu.com"
2017-04-20 23:11:10 +00:00
myPROGRESSBOXCONF = " --backtitle " $myBACKTITLE " --progressbox 24 80"
2015-12-08 14:47:39 +00:00
2016-08-22 15:24:48 +00:00
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)
}
2017-04-20 23:11:10 +00:00
# Let's wait a few seconds to avoid interference with service messages
2017-05-01 19:03:27 +00:00
sleep 3
tput civis
2017-04-20 23:11:10 +00:00
dialog --no-ok --no-cancel --backtitle " $myBACKTITLE " --title "[ Wait to avoid interference with service messages ]" --pause "" 6 80 7
2017-03-22 18:27:43 +00:00
# Let's setup the proxy for env
if [ -f $myPROXYFILEPATH ] ;
2017-04-20 23:11:10 +00:00
then
dialog --title "[ Setting up the proxy ]" $myPROGRESSBOXCONF <<EOF
EOF
2017-03-22 18:27:43 +00:00
myPROXY = $( cat $myPROXYFILEPATH )
2017-04-20 23:11:10 +00:00
tee -a /etc/environment 2>& 1>/dev/null <<EOF
2017-03-22 18:27:43 +00:00
export http_proxy = $myPROXY
export https_proxy = $myPROXY
export HTTP_PROXY = $myPROXY
export HTTPS_PROXY = $myPROXY
export no_proxy = localhost,127.0.0.1,.sock
EOF
source /etc/environment
# Let's setup the proxy for apt
2017-04-20 23:11:10 +00:00
tee /etc/apt/apt.conf 2>& 1>/dev/null <<EOF
2017-03-22 18:27:43 +00:00
Acquire::http::Proxy " $myPROXY " ;
Acquire::https::Proxy " $myPROXY " ;
EOF
2017-04-20 23:11:10 +00:00
# Let's add proxy settings to docker defaults
myPROXY = $( cat $myPROXYFILEPATH )
tee -a /etc/default/docker 2>& 1>/dev/null <<EOF
http_proxy = $myPROXY
https_proxy = $myPROXY
HTTP_PROXY = $myPROXY
HTTPS_PROXY = $myPROXY
no_proxy = localhost,127.0.0.1,.sock
EOF
# Let's restart docker for proxy changes to take effect
systemctl stop docker 2>& 1 | dialog --title "[ Stop docker service ]" $myPROGRESSBOXCONF
systemctl start docker 2>& 1 | dialog --title "[ Start docker service ]" $myPROGRESSBOXCONF
2017-03-22 18:27:43 +00:00
fi
2017-04-22 18:05:12 +00:00
# Let's test the internet connection
mySITESCOUNT = $( echo $mySITES | wc -w)
j = 0
2017-03-22 18:27:43 +00:00
for i in $mySITES ;
do
2017-04-24 14:06:23 +00:00
dialog --title "[ Testing the internet connection ]" --backtitle " $myBACKTITLE " \
--gauge " \n Now checking: $i \n " 8 80 $( expr 100 \* $j / $mySITESCOUNT ) <<EOF
2017-04-20 23:11:10 +00:00
EOF
curl --connect-timeout 5 -IsS $i 2>& 1>/dev/null
2017-03-22 18:27:43 +00:00
if [ $? -ne 0 ] ;
then
2017-04-16 21:44:19 +00:00
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
2017-03-22 18:27:43 +00:00
if [ $? = 1 ] ;
then
2017-04-16 21:44:19 +00:00
dialog --backtitle " $myBACKTITLE " --title "[ Abort ]" --msgbox "\nInstallation aborted. Exiting the installer." 7 50
2017-03-22 18:27:43 +00:00
exit
else
break;
fi ;
fi ;
2017-04-24 14:06:23 +00:00
let j += 1
dialog --title "[ Testing the internet connection ]" --backtitle " $myBACKTITLE " \
--gauge " \n Now checking: $i \n " 8 80 $( expr 100 \* $j / $mySITESCOUNT ) <<EOF
EOF
2017-03-22 18:27:43 +00:00
done ;
2016-10-27 11:11:51 +00:00
# Let's remove NGINX default website
2017-04-20 23:11:10 +00:00
#fuECHO "### Removing NGINX default website."
rm -rf /etc/nginx/sites-enabled/default 2>& 1 | dialog --title "[ Removing NGINX default website. ]" $myPROGRESSBOXCONF ;
rm -rf /etc/nginx/sites-available/default 2>& 1 | dialog --title "[ Removing NGINX default website. ]" $myPROGRESSBOXCONF ;
rm -rf /usr/share/nginx/html/index.html 2>& 1 | dialog --title "[ Removing NGINX default website. ]" $myPROGRESSBOXCONF ;
2016-10-23 11:38:44 +00:00
2017-03-22 18:27:43 +00:00
# Let's ask user for install flavor
2016-10-25 16:35:39 +00:00
# Install types are TPOT, HP, INDUSTRIAL, ALL
2017-05-01 19:03:27 +00:00
tput cnorm
2017-04-16 21:44:19 +00:00
myFLAVOR = $( dialog --no-cancel --backtitle " $myBACKTITLE " --title "[ Choose your edition ]" --no-tags --menu \
2017-03-22 18:27:43 +00:00
"\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>& -)
2016-10-25 16:35:39 +00:00
2017-04-24 14:06:23 +00:00
# Let's ask for a secure tsec password
myUSER = "tsec"
myPASS1 = "pass1"
myPASS2 = "pass2"
mySECURE = "0"
while [ " $myPASS1 " != " $myPASS2 " ] && [ " $mySECURE " = = "0" ]
do
while [ " $myPASS1 " = = "pass1" ] || [ " $myPASS1 " = = "" ]
do
myPASS1 = $( dialog --insecure --backtitle " $myBACKTITLE " \
--title "[ Enter password for console user (tsec) ]" \
--passwordbox "\nPassword" 9 60 3>& 1 1>& 2 2>& 3 3>& -)
done
myPASS2 = $( dialog --insecure --backtitle " $myBACKTITLE " \
--title "[ Repeat password for console user (tsec) ]" \
--passwordbox "\nPassword" 9 60 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 60
myPASS1 = "pass1"
myPASS2 = "pass2"
fi
mySECURE = $( printf "%s" " $myPASS1 " | cracklib-check | grep -c "OK" )
if [ " $mySECURE " = = "0" ] && [ " $myPASS1 " = = " $myPASS2 " ] ;
then
dialog --backtitle " $myBACKTITLE " --title "[ Password is not secure ]" --defaultno --yesno "\nKeep insecure password?" 7 50
myOK = $?
if [ " $myOK " = = "1" ] ;
then
myPASS1 = "pass1"
myPASS2 = "pass2"
fi
fi
done
printf "%s" " $myUSER : $myPASS1 " | chpasswd
# Let's ask for a web username with secure password
2017-03-22 18:27:43 +00:00
myOK = "1"
2016-08-22 15:24:48 +00:00
myUSER = "tsec"
2017-04-24 14:06:23 +00:00
myPASS1 = "pass1"
myPASS2 = "pass2"
mySECURE = "0"
2016-08-22 15:24:48 +00:00
while [ 1 != 2 ]
do
2017-04-16 21:44:19 +00:00
myUSER = $( dialog --backtitle " $myBACKTITLE " --title "[ Enter your web user name ]" --inputbox "\nUsername (tsec not allowed)" 9 50 3>& 1 1>& 2 2>& 3 3>& -)
myUSER = $( echo $myUSER | tr -cd "[:alnum:]_.-" )
dialog --backtitle " $myBACKTITLE " --title "[ Your username is ]" --yesno " \n $myUSER " 7 50
2017-03-22 18:27:43 +00:00
myOK = $?
if [ " $myOK " = "0" ] && [ " $myUSER " != "tsec" ] && [ " $myUSER " != "" ] ;
2016-08-22 15:24:48 +00:00
then
break
fi
done
2017-04-24 14:06:23 +00:00
while [ " $myPASS1 " != " $myPASS2 " ] && [ " $mySECURE " = = "0" ]
2016-08-22 15:24:48 +00:00
do
2016-10-23 12:54:57 +00:00
while [ " $myPASS1 " = = "pass1" ] || [ " $myPASS1 " = = "" ]
do
2017-04-24 14:06:23 +00:00
myPASS1 = $( dialog --insecure --backtitle " $myBACKTITLE " \
--title "[ Enter password for your web user ]" \
--passwordbox "\nPassword" 9 60 3>& 1 1>& 2 2>& 3 3>& -)
2016-10-23 12:54:57 +00:00
done
2017-04-24 14:06:23 +00:00
myPASS2 = $( dialog --insecure --backtitle " $myBACKTITLE " \
--title "[ Repeat password for your web user ]" \
--passwordbox "\nPassword" 9 60 3>& 1 1>& 2 2>& 3 3>& -)
2016-10-23 12:54:57 +00:00
if [ " $myPASS1 " != " $myPASS2 " ] ;
then
2017-04-24 14:06:23 +00:00
dialog --backtitle " $myBACKTITLE " --title "[ Passwords do not match. ]" \
--msgbox "\nPlease re-enter your password." 7 60
2016-10-23 12:54:57 +00:00
myPASS1 = "pass1"
myPASS2 = "pass2"
fi
2017-04-24 14:06:23 +00:00
mySECURE = $( printf "%s" " $myPASS1 " | cracklib-check | grep -c "OK" )
if [ " $mySECURE " = = "0" ] && [ " $myPASS1 " = = " $myPASS2 " ] ;
then
dialog --backtitle " $myBACKTITLE " --title "[ Password is not secure ]" --defaultno --yesno "\nKeep insecure password?" 7 50
myOK = $?
if [ " $myOK " = = "1" ] ;
then
myPASS1 = "pass1"
myPASS2 = "pass2"
fi
fi
2016-08-22 15:24:48 +00:00
done
2017-04-20 23:11:10 +00:00
htpasswd -b -c /etc/nginx/nginxpasswd " $myUSER " " $myPASS1 " 2>& 1 | dialog --title "[ Setting up user and password ]" $myPROGRESSBOXCONF ;
2016-08-22 15:24:48 +00:00
2017-03-22 18:27:43 +00:00
# Let's generate a SSL self-signed certificate without interaction (browsers will see it invalid anyway)
2017-05-01 19:03:27 +00:00
tput civis
2017-04-20 23:11:10 +00:00
mkdir -p /etc/nginx/ssl 2>& 1 | dialog --title "[ Generating a self-signed-certificate for NGINX ]" $myPROGRESSBOXCONF ;
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' 2>& 1 | dialog --title "[ Generating a self-signed-certificate for NGINX ]" $myPROGRESSBOXCONF ;
2015-12-08 14:47:39 +00:00
# Let's setup the ntp server
if [ -f $myNTPCONFPATH ] ;
then
2017-04-20 23:11:10 +00:00
dialog --title "[ Setting up the ntp server ]" $myPROGRESSBOXCONF <<EOF
EOF
cp $myNTPCONFPATH /etc/ntp.conf 2>& 1 | dialog --title "[ Setting up the ntp server ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
fi
# Let's setup 802.1x networking
if [ -f $myPFXPATH ] ;
then
2017-04-20 23:11:10 +00:00
dialog --title "[ Setting 802.1x networking ]" $myPROGRESSBOXCONF <<EOF
EOF
cp $myPFXPATH /etc/wpa_supplicant/ 2>& 1 | dialog --title "[ Setting 802.1x networking ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
if [ -f $myPFXPWPATH ] ;
then
2017-04-20 23:11:10 +00:00
dialog --title "[ Setting up 802.1x password ]" $myPROGRESSBOXCONF <<EOF
EOF
2015-12-08 14:47:39 +00:00
myPFXPW = $( cat $myPFXPWPATH )
fi
myPFXHOSTID = $( cat $myPFXHOSTIDPATH )
2017-04-20 23:11:10 +00:00
tee -a /etc/network/interfaces 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
wpa-driver wired
wpa-conf /etc/wpa_supplicant/wired8021x.conf
### Example wireless config for 802.1x
### This configuration was tested with the IntelNUC series
### If problems occur you can try and change wpa-driver to "iwlwifi"
### Do not forget to enter a ssid in /etc/wpa_supplicant/wireless8021x.conf
2016-12-06 12:18:00 +00:00
### The Intel NUC uses wlpXsY notation instead of wlanX
2015-12-08 14:47:39 +00:00
#
2016-12-06 12:18:00 +00:00
#auto wlp2s0
#iface wlp2s0 inet dhcp
2015-12-08 14:47:39 +00:00
# wpa-driver wext
# wpa-conf /etc/wpa_supplicant/wireless8021x.conf
EOF
2017-04-20 23:11:10 +00:00
tee /etc/wpa_supplicant/wired8021x.conf 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
ctrl_interface = /var/run/wpa_supplicant
ctrl_interface_group = root
eapol_version = 1
ap_scan = 1
network = {
key_mgmt = IEEE8021X
eap = TLS
identity = " host/ $myPFXHOSTID "
private_key = "/etc/wpa_supplicant/8021x.pfx"
private_key_passwd = " $myPFXPW "
}
EOF
2017-04-20 23:11:10 +00:00
tee /etc/wpa_supplicant/wireless8021x.conf 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
ctrl_interface = /var/run/wpa_supplicant
ctrl_interface_group = root
eapol_version = 1
ap_scan = 1
network = {
ssid = "<your_ssid_here_without_brackets>"
key_mgmt = WPA-EAP
pairwise = CCMP
group = CCMP
eap = TLS
identity = " host/ $myPFXHOSTID "
private_key = "/etc/wpa_supplicant/8021x.pfx"
private_key_passwd = " $myPFXPW "
}
EOF
fi
# Let's provide a wireless example config ...
fuECHO "### Providing a wireless example config."
2017-04-20 23:11:10 +00:00
tee -a /etc/network/interfaces 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
### Example wireless config without 802.1x
### This configuration was tested with the IntelNUC series
### If problems occur you can try and change wpa-driver to "iwlwifi"
#
#auto wlan0
#iface wlan0 inet dhcp
# wpa-driver wext
# wpa-ssid <your_ssid_here_without_brackets>
# wpa-ap-scan 1
# wpa-proto RSN
# wpa-pairwise CCMP
# wpa-group CCMP
# wpa-key-mgmt WPA-PSK
# wpa-psk "<your_password_here_without_brackets>"
EOF
# Let's modify the sources list
sed -i '/cdrom/d' /etc/apt/sources.list
2016-01-29 16:56:26 +00:00
# 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."
2017-04-20 23:11:10 +00:00
tee -a /etc/ssh/ssh_config 2>& 1>/dev/null <<EOF
2016-01-29 16:56:26 +00:00
UseRoaming no
EOF
2016-08-01 13:25:58 +00:00
# Let's pull some updates
2017-04-20 23:11:10 +00:00
apt-get update -y 2>& 1 | dialog --title "[ Pulling updates ]" $myPROGRESSBOXCONF
apt-get upgrade -y 2>& 1 | dialog --title "[ Pulling updates ]" $myPROGRESSBOXCONF
2016-08-01 13:25:58 +00:00
# Let's clean up apt
2017-04-20 23:11:10 +00:00
apt-get autoclean -y 2>& 1 | dialog --title "[ Pulling updates ]" $myPROGRESSBOXCONF
apt-get autoremove -y 2>& 1 | dialog --title "[ Pulling updates ]" $myPROGRESSBOXCONF
2016-08-01 13:25:58 +00:00
2017-03-22 18:27:43 +00:00
# Installing alerta-cli, wetty, ctop, elasticdump
2017-04-20 23:11:10 +00:00
pip install --upgrade pip 2>& 1 | dialog --title "[ Installing pip ]" $myPROGRESSBOXCONF
pip install alerta 2>& 1 | dialog --title "[ Installing alerta ]" $myPROGRESSBOXCONF
ln -s /usr/bin/nodejs /usr/bin/node 2>& 1 | dialog --title "[ Installing wetty ]" $myPROGRESSBOXCONF
npm install https://github.com/t3chn0m4g3/wetty -g 2>& 1 | dialog --title "[ Installing wetty ]" $myPROGRESSBOXCONF
npm install https://github.com/t3chn0m4g3/elasticsearch-dump -g 2>& 1 | dialog --title "[ Installing elasticsearch-dump ]" $myPROGRESSBOXCONF
wget https://github.com/bcicen/ctop/releases/download/v0.4.1/ctop-0.4.1-linux-amd64 -O ctop 2>& 1 | dialog --title "[ Installing ctop ]" $myPROGRESSBOXCONF
mv ctop /usr/bin/ 2>& 1 | dialog --title "[ Installing ctop ]" $myPROGRESSBOXCONF
chmod +x /usr/bin/ctop 2>& 1 | dialog --title "[ Installing ctop ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
# Let's add a new user
2017-04-20 23:11:10 +00:00
addgroup --gid 2000 tpot 2>& 1 | dialog --title "[ Adding new user ]" $myPROGRESSBOXCONF
adduser --system --no-create-home --uid 2000 --disabled-password --disabled-login --gid 2000 tpot 2>& 1 | dialog --title "[ Adding new user ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
# Let's set the hostname
2016-12-06 08:55:41 +00:00
myHOST = $( curl -s -f www.nsanamegenerator.com | html2text | tr A-Z a-z | awk '{print $1}' )
2017-04-20 23:11:10 +00:00
if [ " $myHOST " = "" ] ;
then
dialog --no-ok --no-cancel --backtitle " $myBACKTITLE " --title "[ Failed to fetch name from remote, using local cache ]" --pause "" 6 80 2
myHOST = $( fuRANDOMWORD)
fi
hostnamectl set-hostname $myHOST 2>& 1 | dialog --title "[ Setting new hostname ]" $myPROGRESSBOXCONF
sed -i 's#127.0.1.1.*#127.0.1.1\t' " $myHOST " '#g' /etc/hosts 2>& 1 | dialog --title "[ Setting new hostname ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
# Let's patch sshd_config
2017-04-20 23:11:10 +00:00
sed -i 's#Port 22#Port 64295#' /etc/ssh/sshd_config 2>& 1 | dialog --title "[ SSH listen on tcp/64295 ]" $myPROGRESSBOXCONF
sed -i 's#\#PasswordAuthentication yes#PasswordAuthentication no#' /etc/ssh/sshd_config 2>& 1 | dialog --title "[ SSH password authentication only from RFC1918 networks ]" $myPROGRESSBOXCONF
tee -a /etc/ssh/sshd_config 2>& 1>/dev/null <<EOF
2017-04-26 18:01:15 +00:00
2016-08-01 13:25:58 +00:00
Match address 127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
PasswordAuthentication yes
EOF
2015-12-08 14:47:39 +00:00
# Let's make sure only myFLAVOR images will be downloaded and started
2016-03-07 12:13:52 +00:00
case $myFLAVOR in
HP)
echo "### Preparing HONEYPOT flavor installation."
2017-04-30 23:34:30 +00:00
cp /root/tpot/etc/tpot/compose/hp.yml /root/tpot/etc/tpot/tpot.yml 2>& 1>/dev/null
2016-03-07 12:13:52 +00:00
; ;
INDUSTRIAL)
echo "### Preparing INDUSTRIAL flavor installation."
2017-04-30 23:34:30 +00:00
cp /root/tpot/etc/tpot/compose/industrial.yml /root/tpot/etc/tpot/tpot.yml 2>& 1>/dev/null
2016-03-07 12:13:52 +00:00
; ;
TPOT)
echo "### Preparing TPOT flavor installation."
2017-04-30 23:34:30 +00:00
cp /root/tpot/etc/tpot/compose/tpot.yml /root/tpot/etc/tpot/tpot.yml 2>& 1>/dev/null
2016-03-07 12:13:52 +00:00
; ;
2017-04-24 15:21:45 +00:00
EVERYTHING)
2016-03-07 12:13:52 +00:00
echo "### Preparing EVERYTHING flavor installation."
2017-04-30 23:34:30 +00:00
cp /root/tpot/etc/tpot/compose/all.yml /root/tpot/etc/tpot/tpot.yml 2>& 1>/dev/null
2016-03-07 12:13:52 +00:00
; ;
esac
2016-02-12 21:47:19 +00:00
2015-12-08 14:47:39 +00:00
# Let's load docker images
2017-04-30 23:34:30 +00:00
myIMAGESCOUNT = $( cat /root/tpot/etc/tpot/tpot.yml | grep container_name | cut -d: -f2 | wc -l)
2017-04-22 18:05:12 +00:00
j = 0
2017-05-01 19:03:27 +00:00
for name in $( cat /root/tpot/etc/tpot/tpot.yml | grep image | cut -d'"' -f2)
2016-08-01 13:25:58 +00:00
do
2017-04-24 14:06:23 +00:00
dialog --title "[ Downloading docker images, please be patient ]" --backtitle " $myBACKTITLE " \
2017-05-01 19:03:27 +00:00
--gauge " \n Now downloading: $name \n " 8 80 $( expr 100 \* $j / $myIMAGESCOUNT ) <<EOF
2017-04-22 18:05:12 +00:00
EOF
2017-05-01 19:03:27 +00:00
docker pull $name 2>& 1>/dev/null
2017-04-22 18:05:12 +00:00
let j += 1
2017-04-24 14:06:23 +00:00
dialog --title "[ Downloading docker images, please be patient ]" --backtitle " $myBACKTITLE " \
2017-05-01 19:03:27 +00:00
--gauge " \n Now downloading: $name \n " 8 80 $( expr 100 \* $j / $myIMAGESCOUNT ) <<EOF
2017-04-24 14:06:23 +00:00
EOF
2016-08-01 13:25:58 +00:00
done
2015-12-08 14:47:39 +00:00
# Let's add the daily update check with a weekly clean interval
2017-04-20 23:11:10 +00:00
dialog --title "[ Modifying update checks ]" $myPROGRESSBOXCONF <<EOF
EOF
tee /etc/apt/apt.conf.d/10periodic 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
APT::Periodic::Update-Package-Lists "1" ;
APT::Periodic::Download-Upgradeable-Packages "0" ;
APT::Periodic::AutocleanInterval "7" ;
EOF
# Let's make sure to reboot the system after a kernel panic
2017-04-20 23:11:10 +00:00
dialog --title "[ Reboot after kernel panic ]" $myPROGRESSBOXCONF <<EOF
EOF
tee -a /etc/sysctl.conf 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
# Reboot after kernel panic, check via /proc/sys/kernel/panic[_on_oops]
2017-02-26 11:29:38 +00:00
# Set required map count for ELK
2015-12-08 14:47:39 +00:00
kernel.panic = 1
kernel.panic_on_oops = 1
2017-02-26 11:29:38 +00:00
vm.max_map_count = 262144
2015-12-08 14:47:39 +00:00
EOF
# Let's add some cronjobs
2017-04-20 23:11:10 +00:00
dialog --title "[ Adding cronjobs ]" $myPROGRESSBOXCONF <<EOF
EOF
tee -a /etc/crontab 2>& 1>/dev/null <<EOF
2015-12-08 14:47:39 +00:00
# Check if updated images are available and download them
2017-05-01 19:03:27 +00:00
27 1 * * * root /usr/bin/docker-compose -f /etc/tpot/tpot.yml pull
2015-12-08 14:47:39 +00:00
2016-03-02 15:21:17 +00:00
# Delete elastic indices older than 90 days (kibana index is omitted by default)
2017-05-01 19:03:27 +00:00
#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'
2016-10-23 10:34:08 +00:00
# Daily reboot
2017-05-01 19:03:27 +00:00
27 3 * * * root reboot
2015-12-08 14:47:39 +00:00
# Check for updated packages every sunday, upgrade and reboot
2017-05-01 19:03:27 +00:00
27 16 * * 0 root apt-get autoclean -y && apt-get autoremove -y && apt-get update -y && apt-get upgrade -y && sleep 10 && reboot
2015-12-08 14:47:39 +00:00
EOF
# Let's create some files and folders
2016-02-19 16:52:45 +00:00
mkdir -p /data/conpot/log \
2015-12-14 13:53:20 +00:00
/data/cowrie/log/tty/ /data/cowrie/downloads/ /data/cowrie/keys/ /data/cowrie/misc/ \
2016-06-01 15:46:06 +00:00
/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 \
2016-02-19 16:52:45 +00:00
/data/elasticpot/log \
2017-05-03 20:55:18 +00:00
/data/elk/data /data/elk/log \
2016-06-18 22:20:02 +00:00
/data/glastopf /data/honeytrap/log/ /data/honeytrap/attacks/ /data/honeytrap/downloads/ \
2016-02-19 16:52:45 +00:00
/data/emobility/log \
2017-03-12 23:31:34 +00:00
/data/ews/conf \
2017-04-19 12:22:51 +00:00
/data/suricata/log /home/tsec/.ssh/ \
2017-04-30 23:34:30 +00:00
/etc/tpot/elk /etc/tpot/compose /etc/tpot/systemd \
2017-04-20 23:11:10 +00:00
/usr/share/tpot/bin 2>& 1 | dialog --title "[ Creating some files and folders ]" $myPROGRESSBOXCONF
2016-02-08 11:21:03 +00:00
# Let's take care of some files and permissions before copying
2017-04-20 23:11:10 +00:00
chmod 500 /root/tpot/bin/* 2>& 1 | dialog --title "[ Setting permissions ]" $myPROGRESSBOXCONF
2017-04-30 23:34:30 +00:00
chmod 600 -R /root/tpot/etc/tpot 2>& 1 | dialog --title "[ Setting permissions ]" $myPROGRESSBOXCONF
2017-04-20 23:11:10 +00:00
chmod 644 /root/tpot/etc/issue 2>& 1 | dialog --title "[ Setting permissions ]" $myPROGRESSBOXCONF
chmod 755 /root/tpot/etc/rc.local 2>& 1 | dialog --title "[ Setting permissions ]" $myPROGRESSBOXCONF
2017-04-30 23:34:30 +00:00
chmod 644 /root/tpot/etc/tpot/systemd/* 2>& 1 | dialog --title "[ Setting permissions ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
# Let's copy some files
2017-04-30 23:34:30 +00:00
tar xvfz /root/tpot/etc/tpot/elkbase.tgz -C / 2>& 1 | dialog --title "[ Extracting elkbase.tgz ]" $myPROGRESSBOXCONF
2017-04-20 23:11:10 +00:00
cp -R /root/tpot/bin/* /usr/share/tpot/bin/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
2017-04-30 23:34:30 +00:00
cp -R /root/tpot/etc/tpot/* /etc/tpot/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
cp /root/tpot/etc/tpot/systemd/* /etc/systemd/system/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
2017-04-20 23:11:10 +00:00
cp /root/tpot/etc/issue /etc/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
cp -R /root/tpot/etc/nginx/ssl /etc/nginx/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
cp /root/tpot/etc/nginx/tpotweb.conf /etc/nginx/sites-available/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
cp /root/tpot/etc/nginx/nginx.conf /etc/nginx/nginx.conf 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
cp /root/tpot/keys/authorized_keys /home/tsec/.ssh/authorized_keys 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
cp /root/tpot/usr/share/nginx/html/* /usr/share/nginx/html/ 2>& 1 | dialog --title "[ Copy configs ]" $myPROGRESSBOXCONF
2017-04-30 23:34:30 +00:00
systemctl enable tpot 2>& 1 | dialog --title "[ Enabling service for tpot ]" $myPROGRESSBOXCONF
2017-04-20 23:11:10 +00:00
systemctl enable wetty 2>& 1 | dialog --title "[ Enabling service for wetty ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
2016-08-08 00:21:02 +00:00
# Let's enable T-Pot website
2017-04-20 23:11:10 +00:00
ln -s /etc/nginx/sites-available/tpotweb.conf /etc/nginx/sites-enabled/tpotweb.conf 2>& 1 | dialog --title "[ Enabling T-Pot website ]" $myPROGRESSBOXCONF
2016-08-01 13:25:58 +00:00
2015-12-08 14:47:39 +00:00
# Let's take care of some files and permissions
2017-04-20 23:11:10 +00:00
chmod 760 -R /data 2>& 1 | dialog --title "[ Set permissions and ownerships ]" $myPROGRESSBOXCONF
chown tpot:tpot -R /data 2>& 1 | dialog --title "[ Set permissions and ownerships ]" $myPROGRESSBOXCONF
chmod 600 /home/tsec/.ssh/authorized_keys 2>& 1 | dialog --title "[ Set permissions and ownerships ]" $myPROGRESSBOXCONF
chown tsec:tsec /home/tsec/.ssh /home/tsec/.ssh/authorized_keys 2>& 1 | dialog --title "[ Set permissions and ownerships ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
# Let's replace "quiet splash" options, set a console font for more screen canvas and update grub
2017-04-20 23:11:10 +00:00
sed -i 's#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"#GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0"#' /etc/default/grub 2>& 1>/dev/null
sed -i 's#GRUB_CMDLINE_LINUX=""#GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"#' /etc/default/grub 2>& 1>/dev/null
2016-10-28 13:08:55 +00:00
#sed -i 's#\#GRUB_GFXMODE=640x480#GRUB_GFXMODE=800x600x32#' /etc/default/grub
#tee -a /etc/default/grub <<EOF
#GRUB_GFXPAYLOAD=800x600x32
#GRUB_GFXPAYLOAD_LINUX=800x600x32
#EOF
2017-04-20 23:11:10 +00:00
update-grub 2>& 1 | dialog --title "[ Update grub ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
cp /usr/share/consolefonts/Uni2-Terminus12x6.psf.gz /etc/console-setup/
gunzip /etc/console-setup/Uni2-Terminus12x6.psf.gz
sed -i 's#FONTFACE=".*#FONTFACE="Terminus"#' /etc/default/console-setup
sed -i 's#FONTSIZE=".*#FONTSIZE="12x6"#' /etc/default/console-setup
2017-04-20 23:11:10 +00:00
update-initramfs -u 2>& 1 | dialog --title "[ Update initramfs ]" $myPROGRESSBOXCONF
2015-12-08 14:47:39 +00:00
2017-04-19 12:22:51 +00:00
# Let's enable a color prompt and add /usr/share/tpot/bin to path
2016-08-12 20:21:02 +00:00
myROOTPROMPT = 'PS1="\[\033[38;5;8m\][\[$(tput sgr0)\]\[\033[38;5;1m\]\u\[$(tput sgr0)\]\[\033[38;5;6m\]@\[$(tput sgr0)\]\[\033[38;5;4m\]\h\[$(tput sgr0)\]\[\033[38;5;6m\]:\[$(tput sgr0)\]\[\033[38;5;5m\]\w\[$(tput sgr0)\]\[\033[38;5;8m\]]\[$(tput sgr0)\]\[\033[38;5;1m\]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"'
myUSERPROMPT = 'PS1="\[\033[38;5;8m\][\[$(tput sgr0)\]\[\033[38;5;2m\]\u\[$(tput sgr0)\]\[\033[38;5;6m\]@\[$(tput sgr0)\]\[\033[38;5;4m\]\h\[$(tput sgr0)\]\[\033[38;5;6m\]:\[$(tput sgr0)\]\[\033[38;5;5m\]\w\[$(tput sgr0)\]\[\033[38;5;8m\]]\[$(tput sgr0)\]\[\033[38;5;2m\]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"'
2017-04-20 23:11:10 +00:00
tee -a /root/.bashrc 2>& 1>/dev/null <<EOF
2016-08-12 20:21:02 +00:00
$myROOTPROMPT
2017-04-19 12:22:51 +00:00
PATH = " $PATH :/usr/share/tpot/bin "
2016-08-12 20:21:02 +00:00
EOF
2017-04-20 23:11:10 +00:00
tee -a /home/tsec/.bashrc 2>& 1>/dev/null <<EOF
2016-08-12 20:21:02 +00:00
$myUSERPROMPT
2017-04-19 12:22:51 +00:00
PATH = " $PATH :/usr/share/tpot/bin "
2016-08-12 20:21:02 +00:00
EOF
2016-02-03 14:10:19 +00:00
2016-02-08 12:37:02 +00:00
# Let's create ews.ip before reboot and prevent race condition for first start
2017-04-20 23:11:10 +00:00
source /etc/environment 2>& 1>/dev/null
2016-02-08 12:37:02 +00:00
myLOCALIP = $( hostname -I | awk '{ print $1 }' )
2017-04-19 12:22:51 +00:00
myEXTIP = $( /usr/share/tpot/bin/myip.sh)
2017-04-20 23:11:10 +00:00
sed -i " s#IP:.*#IP: $myLOCALIP ( $myEXTIP ) [0m# " /etc/issue 2>& 1>/dev/null
sed -i " s#SSH:.*#SSH: ssh -l tsec -p 64295 $myLOCALIP [0m#" /etc/issue 2>& 1>/dev/null
sed -i " s#WEB:.*#WEB: https:// $myLOCALIP :64297 [0m# " /etc/issue 2>& 1>/dev/null
tee /data/ews/conf/ews.ip 2>& 1>/dev/null <<EOF
2016-02-08 12:37:02 +00:00
[ MAIN]
ip = $myEXTIP
EOF
2017-04-20 23:11:10 +00:00
tee /etc/tpot/elk/environment 2>& 1>/dev/null <<EOF
2017-04-19 12:22:51 +00:00
MY_EXTIP = $myEXTIP
MY_HOSTNAME = $HOSTNAME
EOF
2017-04-20 23:11:10 +00:00
chown tpot:tpot /data/ews/conf/ews.ip 2>& 1>/dev/null
2016-02-08 12:37:02 +00:00
2015-12-08 14:47:39 +00:00
# Final steps
2017-04-20 23:11:10 +00:00
mv /root/tpot/etc/rc.local /etc/rc.local 2>& 1>/dev/null && \
rm -rf /root/tpot/ 2>& 1>/dev/null && \
dialog --no-ok --no-cancel --backtitle " $myBACKTITLE " --title "[ Thanks for your patience. Now rebooting. ]" --pause "" 6 80 2 && \
reboot