Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit be29274

Browse files
author
Chocobozzz
committed
SECURITY: Avoid simple sql injection when login in openvpn
1 parent 76a7939 commit be29274

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

installation/scripts/connect.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/bin/bash
22
. /etc/openvpn/scripts/config.sh
3+
. /etc/openvpn/scripts/functions.sh
4+
5+
common_name=$(echap "$common_name")
6+
trusted_ip=$(echap "$trusted_ip")
7+
trusted_port=$(echap "$trusted_port")
8+
ifconfig_pool_remote_ip=$(echap "$ifconfig_pool_remote_ip")
9+
remote_port_1=$(echap "$remote_port_1")
10+
bytes_received=$(echap "$bytes_received")
11+
bytes_sent=$(echap "$bytes_sent")
12+
313

414
# We insert data in the log table
515
mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "INSERT INTO log (log_id, user_id, log_trusted_ip, log_trusted_port, log_remote_ip, log_remote_port, log_start_time, log_end_time, log_received, log_send) VALUES(NULL, '$common_name','$trusted_ip', '$trusted_port','$ifconfig_pool_remote_ip', '$remote_port_1', now(),'0000-00-00 00:00:00', '$bytes_received', '$bytes_sent')"

installation/scripts/disconnect.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22
. /etc/openvpn/scripts/config.sh
3+
. /etc/openvpn/scripts/functions.sh
4+
5+
common_name=$(echap "$common_name")
6+
bytes_received=$(echap "$bytes_received")
7+
bytes_sent=$(echap "$bytes_sent")
8+
trusted_ip=$(echap "$trusted_ip")
9+
trusted_port=$(echap "$trusted_port")
310

411
# We specify the user is offline
512
mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -e "UPDATE user SET user_online=0 WHERE user_id='$common_name'"

installation/scripts/functions.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
function echap() {
4+
# echap ' and \
5+
echo "$1" | sed s/\\\\/\\\\\\\\/g | sed s/\'/\\\\\'/g
6+
}

installation/scripts/login.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22
. /etc/openvpn/scripts/config.sh
3+
. /etc/openvpn/scripts/functions.sh
4+
5+
username=$(echap "$username")
6+
password=$(echap "$password")
37

48
# Authentication
59
user_pass=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "SELECT user_pass FROM user WHERE user_id = '$username' AND user_enable=1 AND (TO_DAYS(now()) >= TO_DAYS(user_start_date) OR user_start_date='0000-00-00') AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date='0000-00-00')")

update.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ cd "$www"
3939

4040
bower --allow-root install
4141
chown -R "$user:$group" "$www"
42+
43+
rm "/etc/openvpn/scripts/"{connect.sh,disconnect.sh,login.sh,functions.sh}
44+
cp "$base_path/installation/scripts/"{connect.sh,disconnect.sh,login.sh,functions.sh} "/etc/openvpn/scripts"
45+
chmod +x "/etc/openvpn/scripts/"{connect.sh,disconnect.sh,login.sh,functions.sh}
46+
47+
echo "OpenVPN-admin upgraded."

0 commit comments

Comments
 (0)