-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcivilized.sh
123 lines (106 loc) · 3.29 KB
/
civilized.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
#title: civilized.sh
#description: Configuration Script
#author: R12W4N
#==============================================================================
[ "$DEBUG" == 'true' ] && set -x
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
BLUE=`tput setaf 4`
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
function trap_ctrlc ()
{
echo "Ctrl-C caught...performing clean up"
echo "Doing cleanup"
trap "kill 0" EXIT
exit 2
}
trap "trap_ctrlc" 2
function test(){
falconmodules=modules/
if [[ ! -d "$falconmodules" ]]; then
echo "${RED} $falconmodules Directory Not Exist ${RESET}"
wget -P ./modules/ https://raw.githubusercontent.com/BlackFalconBot/FalconPi/master/modules/adduser.sh
elif [ -d "$falconmodules" ]
then
echo "All Good"
fi
}
function setup()
{
read -p "${RED}Enter FalconPool Unit Name (user will be created in this host by this name): ${RESET}" FalconName
read -p "${RED}Enter FalconPool Unit Password : ${RESET}" Password
read -p "${RED}Enter Falcon Unique ID (Port number for Remote SSH Tunneling):${RESET} " FUID
if ! [[ "$FUID" =~ ^[0-9]+$ ]]
then
echo "Sorry integers only"
setup
fi
}
function adduser(){
#wget -P ./modules/ https://raw.githubusercontent.com/BlackFalconBot/FalconPi/master/modules/adduser.sh
echo "${GREEN}Adding User $FalconName ${RESET}"
/bin/bash ./modules/adduser.sh -a add $FalconName $Password
echo "${GREEN}Adding User $FalconName to Sudoers List ${RESET}"
usermod -aG sudo $FalconName
echo "${GREEN}Configuring SSH key based secure authentication ${RESET}"
echo "${GREEN}Generating SSH Keys ${RESET}"
ssh-keygen
echo "${GREEN}RSA Key Generated Successfully${RESET}"
read -p "${RED}Enter CnC User : ${RESET}" cncuser
read -p "${RED}Enter CnC Server IP : ${RESET}" cncip
read -p "${RED}Enter CnC Server Port : ${RESET}" cncport
ssh-copy-id -p $cncport $cncuser@$cncip
echo "${GREEN}DONE ${RESET}"
}
function installer(){
echo "${GREEN}Updating${RESET}"
apt update -y
apt --fix-broken install -y
if [[ ! -x /usr/bin/autossh ]] ; then
read -p "${GREEN}You will need autossh! Shall I invoke 'apt install autossh' for you${RESET} (Y/n)? "
if [ "$REPLY" != "n" ]; then
apt install autossh -y
fi
fi
}
function autossh(){
echo "${GREEN}Setting up rc-local.service ${RESET}"
cat > /etc/systemd/system/rc-local.service <<EOF
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
EOF
echo "${GREEN}Setting up rc.local${RESET}"
touch /etc/rc.local
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
read -p "${RED}Enter Monitoring Port : ${RESET}" mp
echo "${GREEN}Setting up autossh ${RESET}"
cat > /etc/rc.local << EOF
#!/bin/bash -e
autossh -M $mp -fN -o "PubkeyAuthentication=yes" -o "StrictHostKeyChecking=false" -o "PasswordAuthentication=no" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R $FUID:localhost:22 -i /root/.ssh/id_rsa $cncuser@$cncip -p $cncport &
exit 0
EOF
sudo systemctl start rc-local.service
sudo systemctl status --no-pager rc-local.service
echo "${GREEN}ssh $FalconName@$cncip -p $FUID ${RESET}"
}
test
setup
adduser
installer
autossh