2024-02-22 18:09:52 +00:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
myANSIBLE_PORT=64295
|
2024-02-23 15:41:52 +00:00
|
|
|
|
myANSIBLE_TPOT_PLAYBOOK="installer/install/deploy.yml"
|
|
|
|
|
myADJECTIVE=$(shuf -n1 installer/install/a.txt)
|
|
|
|
|
myNOUN=$(shuf -n1 installer/install/n.txt)
|
2024-02-22 18:09:52 +00:00
|
|
|
|
myENV_FILE="$HOME/tpotce/.env"
|
|
|
|
|
|
2024-02-23 15:41:52 +00:00
|
|
|
|
myDEPLOY=$(cat << "EOF"
|
|
|
|
|
|
|
|
|
|
____ [ T-Pot ] ____ _
|
|
|
|
|
/ ___| ___ _ __ ___ ___ _ __ | _ \ ___ _ __ | | ___ _ _
|
|
|
|
|
\___ \ / _ \ _ \/ __|/ _ \| __| | | | |/ _ \ _ \| |/ _ \| | | |
|
|
|
|
|
___) | __/ | | \__ \ (_) | | | |_| | __/ |_) | | (_) | |_| |
|
|
|
|
|
|____/ \___|_| |_|___/\___/|_| |____/ \___| .__/|_|\___/ \__, |
|
|
|
|
|
|_| |___/
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
)
|
2024-02-22 18:09:52 +00:00
|
|
|
|
|
|
|
|
|
# Check if the script is running in a HIVE installation
|
|
|
|
|
if ! grep -q 'TPOT_TYPE=HIVE' "$HOME/tpotce/.env";
|
|
|
|
|
then
|
|
|
|
|
echo "# This script is only supported on HIVE installations."
|
2024-02-27 19:11:16 +00:00
|
|
|
|
echo
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check if running on a supported distribution
|
|
|
|
|
mySUPPORTED_DISTRIBUTIONS=("AlmaLinux" "Debian GNU/Linux" "Fedora Linux" "openSUSE Tumbleweed" "Raspbian GNU/Linux" "Rocky Linux" "Ubuntu")
|
|
|
|
|
myCURRENT_DISTRIBUTION=$(awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '"')
|
|
|
|
|
|
|
|
|
|
if [[ ! " ${mySUPPORTED_DISTRIBUTIONS[@]} " =~ " ${myCURRENT_DISTRIBUTION} " ]];
|
|
|
|
|
then
|
|
|
|
|
echo "# Only the following distributions are supported: AlmaLinux, Fedora, Debian, openSUSE Tumbleweed, Rocky Linux and Ubuntu."
|
|
|
|
|
echo
|
2024-02-22 18:09:52 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-02-23 15:41:52 +00:00
|
|
|
|
echo "${myDEPLOY}"
|
|
|
|
|
echo
|
2024-02-27 19:11:16 +00:00
|
|
|
|
echo "# This script will prepare a T-Pot SENSOR installation to transmit logs into this HIVE."
|
2024-02-23 15:41:52 +00:00
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
# Ask if a T-Pot SENSOR was installed
|
|
|
|
|
read -p "# Was a T-Pot SENSOR installed? (y/n): " mySENSOR_INSTALLED
|
2024-02-22 18:09:52 +00:00
|
|
|
|
if [[ ${mySENSOR_INSTALLED} != "y" ]];
|
|
|
|
|
then
|
2024-02-23 15:41:52 +00:00
|
|
|
|
echo "# A T-Pot SENSOR must be installed to continue."
|
2024-02-22 18:09:52 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-02-23 19:30:12 +00:00
|
|
|
|
# Ask for the remote user
|
|
|
|
|
read -p "# Enter the remote username T-Pot SENSOR was installed with: " mySSHUSER
|
|
|
|
|
if [[ ${mySSHUSER} == "" ]];
|
2024-02-22 18:09:52 +00:00
|
|
|
|
then
|
2024-02-23 19:30:12 +00:00
|
|
|
|
echo "# You need to enter a user. Aborting."
|
2024-02-22 18:09:52 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Validate IP/domain name loop
|
|
|
|
|
while true; do
|
2024-02-23 15:41:52 +00:00
|
|
|
|
read -p "# Enter the IP/domain name of the SENSOR: " mySENSOR_IP
|
2024-02-22 18:09:52 +00:00
|
|
|
|
if [[ ${mySENSOR_IP} =~ ^([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*\.[a-zA-Z]{2,})|(([0-9]{1,3}\.){3}[0-9]{1,3})$ ]];
|
|
|
|
|
then
|
|
|
|
|
break
|
|
|
|
|
else
|
|
|
|
|
echo "# Invalid IP/domain. Please enter a valid IP or domain name."
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2024-02-23 19:30:12 +00:00
|
|
|
|
# Check if ssh key has been deployed
|
|
|
|
|
read -p "# Has a SSH key been deployed to the SENSOR? (y/n): " mySSHKEY_DEPLOYED
|
|
|
|
|
if [[ ${mySSHKEY_DEPLOYED} != "y" ]];
|
|
|
|
|
then
|
|
|
|
|
echo "# Generate a SSH key using 'ssh-keygen' and deploy it to the SENSOR (Example: ssh-copy-id -p 64295 ${mySSHUSER}@${mySENSOR_IP})."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-02-22 18:09:52 +00:00
|
|
|
|
# Validate IP/domain name of HIVE
|
|
|
|
|
while true; do
|
|
|
|
|
read -p "# Enter the IP/domain name of this HIVE: " myTPOT_HIVE_IP
|
|
|
|
|
if [[ ${myTPOT_HIVE_IP} =~ ^([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*\.[a-zA-Z]{2,})|(([0-9]{1,3}\.){3}[0-9]{1,3})$ ]];
|
|
|
|
|
then
|
|
|
|
|
break
|
|
|
|
|
else
|
|
|
|
|
echo "# Invalid IP/domain. Please enter a valid IP or domain name."
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2024-02-23 15:41:52 +00:00
|
|
|
|
# Create a random SENSOR user name that is easily readable
|
|
|
|
|
myLS_WEB_USER="sensor-${myADJECTIVE}-${myNOUN}"
|
2024-02-22 18:09:52 +00:00
|
|
|
|
|
|
|
|
|
# Create a random password
|
|
|
|
|
myLS_WEB_PW=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1)
|
|
|
|
|
|
|
|
|
|
# Create myLS_WEB_USER_ENC
|
|
|
|
|
myLS_WEB_USER_ENC=$(htpasswd -b -n "${myLS_WEB_USER}" "${myLS_WEB_PW}")
|
|
|
|
|
myLS_WEB_USER_ENC_B64=$(echo -n "${myLS_WEB_USER_ENC}" | base64 -w0)
|
|
|
|
|
|
2024-02-23 15:41:52 +00:00
|
|
|
|
# Create myTPOT_HIVE_USER, since this is for Logstash on the SENSOR, it needs to directly base64 encoded
|
2024-02-22 18:09:52 +00:00
|
|
|
|
myTPOT_HIVE_USER=$(echo -n "${myLS_WEB_USER}:${myLS_WEB_PW}" | base64 -w0)
|
|
|
|
|
|
|
|
|
|
# Print credentials
|
2024-02-23 15:41:52 +00:00
|
|
|
|
echo "# The following SENSOR credentials have been created:"
|
|
|
|
|
echo "# New SENSOR username: ${myLS_WEB_USER}"
|
|
|
|
|
echo "# New SENSOR passowrd: ${myLS_WEB_PW}"
|
2024-02-22 18:09:52 +00:00
|
|
|
|
echo "# New htpasswd encoded credentials: ${myLS_WEB_USER_ENC}"
|
|
|
|
|
echo "# New htpasswd credentials base64 encoded: ${myLS_WEB_USER_ENC_B64}"
|
2024-02-23 15:41:52 +00:00
|
|
|
|
echo "# New SENSOR credentials base64 encoded: ${myTPOT_HIVE_USER}"
|
2024-03-22 19:47:39 +00:00
|
|
|
|
echo
|
2024-03-24 15:21:51 +00:00
|
|
|
|
echo "# Ansible will ask for the ‘BECOME password‘ which is typically the password you ’sudo’ with on the SENSOR."
|
2024-03-22 19:47:39 +00:00
|
|
|
|
echo "# The password will allow Ansible to run a reboot via sudo on the SENSOR."
|
|
|
|
|
echo
|
2024-02-22 18:09:52 +00:00
|
|
|
|
|
|
|
|
|
# Read LS_WEB_USER from file
|
|
|
|
|
myENV_LS_WEB_USER=$(grep "^LS_WEB_USER=" "${myENV_FILE}" | sed 's/^LS_WEB_USER=//g' | tr -d "\"'")
|
|
|
|
|
|
2024-02-23 19:30:12 +00:00
|
|
|
|
# Add the new SENSOR user
|
|
|
|
|
if [ "${myENV_LS_WEB_USER}" == "" ];
|
|
|
|
|
then
|
|
|
|
|
myENV_LS_WEB_USER="${myLS_WEB_USER_ENC_B64}"
|
|
|
|
|
else
|
|
|
|
|
myENV_LS_WEB_USER="${myENV_LS_WEB_USER} ${myLS_WEB_USER_ENC_B64}"
|
|
|
|
|
fi
|
2024-02-22 18:09:52 +00:00
|
|
|
|
|
2024-02-23 15:41:52 +00:00
|
|
|
|
# Need to export for Ansible
|
2024-02-22 18:09:52 +00:00
|
|
|
|
export myTPOT_HIVE_USER
|
|
|
|
|
export myTPOT_HIVE_IP
|
|
|
|
|
|
2024-03-22 19:47:39 +00:00
|
|
|
|
ANSIBLE_LOG_PATH=${HOME}/tpotce/data/deploy_sensor.log ansible-playbook ${myANSIBLE_TPOT_PLAYBOOK} -i ${mySENSOR_IP}, -c ssh -u ${mySSHUSER} --ask-become-pass -e "ansible_port=${myANSIBLE_PORT}"
|
2024-02-23 19:30:12 +00:00
|
|
|
|
|
|
|
|
|
if [ "$?" == 0 ];
|
|
|
|
|
then
|
|
|
|
|
# Update the T-Pot .env config and lswebpasswd (avoid the need to restart T-Pot) on the host
|
|
|
|
|
echo "# Updating SENSOR users on this HIVE and in the T-Pot .env config:"
|
|
|
|
|
sed -i "/^LS_WEB_USER=/c\LS_WEB_USER=$myENV_LS_WEB_USER" "${myENV_FILE}"
|
|
|
|
|
: > "${HOME}"/tpotce/data/nginx/conf/lswebpasswd
|
|
|
|
|
for i in $myENV_LS_WEB_USER;
|
|
|
|
|
do
|
|
|
|
|
if [[ -n $i ]];
|
|
|
|
|
then
|
|
|
|
|
# Need to control newlines as they kept coming up for some reason
|
|
|
|
|
echo -n "$i" | base64 -d -w0
|
|
|
|
|
echo
|
|
|
|
|
echo -n "$i" | base64 -d -w0 | tr -d '\n' >> ${HOME}/tpotce/data/nginx/conf/lswebpasswd
|
|
|
|
|
echo >> ${HOME}/tpotce/data/nginx/conf/lswebpasswd
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
2024-02-23 15:41:52 +00:00
|
|
|
|
|
|
|
|
|
unset myTPOT_HIVE_USER
|
|
|
|
|
unset myTPOT_HIVE_IP
|