-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-services.sh
More file actions
executable file
·205 lines (173 loc) · 5.81 KB
/
Copy pathinstall-services.sh
File metadata and controls
executable file
·205 lines (173 loc) · 5.81 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
BIRed='\033[1;91m'
BIGreen='\033[1;92m'
BIYellow='\033[1;93m'
BICyan='\033[1;96m'
BIWhite='\033[1;97m'
NC='\e[0m'
clear
echo -e "${BICyan}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BICyan}║${NC} ${BIWhite}INSTALL & CONFIGURE VPN SERVICES${NC} ${BICyan}║${NC}"
echo -e "${BICyan}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
# Install Fail2Ban
echo -e "${BIGreen}[1/4]${NC} ${BIWhite}Configuring Fail2Ban...${NC}"
apt-get install -y fail2ban >/dev/null 2>&1
cat > /etc/fail2ban/jail.local << EOF
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5
[sshd]
enabled = true
port = ssh
logpath = /var/log/auth.log
maxretry = 5
EOF
systemctl enable fail2ban >/dev/null 2>&1
systemctl restart fail2ban >/dev/null 2>&1
echo -e "${BIGreen}✓${NC} Fail2Ban configured for SSH protection"
# Install & Configure OpenVPN
echo ""
echo -e "${BIGreen}[2/4]${NC} ${BIWhite}Configuring OpenVPN...${NC}"
apt-get install -y openvpn >/dev/null 2>&1
if [ ! -d "/etc/openvpn/server" ]; then
mkdir -p /etc/openvpn/server
fi
# Generate simple certificates
cd /etc/openvpn/server
if [ ! -f "ca.crt" ]; then
openssl genrsa -out ca.key 2048 >/dev/null 2>&1
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -subj "/C=US/ST=State/L=City/O=Org/CN=VPN-CA" >/dev/null 2>&1
openssl genrsa -out server.key 2048 >/dev/null 2>&1
openssl req -new -key server.key -out server.csr -subj "/C=US/ST=State/L=City/O=Org/CN=VPN-Server" >/dev/null 2>&1
openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt >/dev/null 2>&1
openssl dhparam -out dh.pem 2048 >/dev/null 2>&1
openvpn --genkey secret ta.key >/dev/null 2>&1
fi
cat > /etc/openvpn/server.conf << EOF
port 1194
proto tcp
dev tun
ca /etc/openvpn/server/ca.crt
cert /etc/openvpn/server/server.crt
key /etc/openvpn/server/server.key
dh /etc/openvpn/server/dh.pem
tls-auth /etc/openvpn/server/ta.key 0
cipher AES-256-CBC
auth SHA256
persist-key
persist-tun
status /var/log/openvpn.log
verb 3
keepalive 10 120
max-clients 100
user nobody
group nogroup
EOF
systemctl enable openvpn@server >/dev/null 2>&1
systemctl restart openvpn@server >/dev/null 2>&1
echo -e "${BIGreen}✓${NC} OpenVPN configured on port 1194"
# Install BadVPN
echo ""
echo -e "${BIGreen}[3/4]${NC} ${BIWhite}Configuring BadVPN...${NC}"
if [ ! -f "/usr/local/bin/badvpn-udpgw" ]; then
echo -e "${BIYellow}Installing BadVPN from source...${NC}"
apt-get install -y build-essential libssl-dev >/dev/null 2>&1
cd /tmp
if [ ! -d "badvpn" ]; then
git clone https://github.com/ambrop72/badvpn.git >/dev/null 2>&1
fi
cd badvpn
mkdir -p build && cd build
cmake .. >/dev/null 2>&1
make >/dev/null 2>&1
cp udpgw/badvpn-udpgw /usr/local/bin/
chmod +x /usr/local/bin/badvpn-udpgw
cd /
fi
cat > /etc/systemd/system/badvpn.service << EOF
[Unit]
Description=BadVPN UDP Gateway
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/badvpn-udpgw --listen-addr 127.0.0.1:7200 --max-clients 1000 --max-connections-for-client 10
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable badvpn >/dev/null 2>&1
systemctl restart badvpn >/dev/null 2>&1
echo -e "${BIGreen}✓${NC} BadVPN configured for ports 7100 and 7900"
# Configure WebSocket Services
echo ""
echo -e "${BIGreen}[4/4]${NC} ${BIWhite}Configuring WebSocket Services...${NC}"
domain=$(cat /etc/xray/domain 2>/dev/null || echo "localhost")
# Create drops utility if not exists
if [ ! -f "/usr/local/bin/drops" ]; then
cat > /usr/local/bin/drops << 'EOF'
#!/bin/bash
while true; do
nc -l -p $2 -e "echo -e \"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n\"; nc $1 $3"
done
EOF
chmod +x /usr/local/bin/drops
fi
cat > /etc/systemd/system/WebSocket.SSH-WS.service << EOF
[Unit]
Description=SSH WebSocket Service
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/drops 127.0.0.1 80 22
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
cat > /etc/systemd/system/WebSocket.Dropbear.service << EOF
[Unit]
Description=Dropbear WebSocket Service
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/drops 127.0.0.1 80 109
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
cat > /etc/systemd/system/WebSocket.Stunnel.service << EOF
[Unit]
Description=Stunnel WebSocket Service
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/drops 127.0.0.1 80 443
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
echo -e "${BIGreen}✓${NC} WebSocket services configured"
echo ""
echo -e "${BICyan}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BICyan}║${NC} ${BIWhite}CONFIGURATION COMPLETE${NC} ${BICyan}║${NC}"
echo -e "${BICyan}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BIGreen}Services Configured:${NC}"
echo -e " ✓ Fail2Ban (SSH protection)"
echo -e " ✓ OpenVPN (port 1194)"
echo -e " ✓ BadVPN (ports 7100-7900)"
echo -e " ✓ WebSocket Services"
echo ""
echo -e "${BIYellow}Run 'restart-all' to restart all services${NC}"
echo ""