socks5/socks5.sh

87 lines
1.8 KiB
Bash
Raw Normal View History

2024-07-27 04:26:48 +05:00
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo -e "\033[31mThis script requires superuser rights.\033[0m"
exit 1
fi
if [ -z "$1" ]; then
echo "Please provide socks5 password as argument"
exit 1
fi
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' ERR
set -e
export DEBIAN_FRONTEND=noninteractive
DANTE_CONF="/etc/danted.conf"
DANTE_USER="usrsocks"
DANTE_PASSWORD=$1
INTERFACE=$(ip -o -4 route show to default | awk '{print $5}')
if [ -z "$INTERFACE" ]; then
echo "Failed to find active network interface"
exit 1
fi
echo "Active network interface found: $INTERFACE"
apt update
apt install -y dante-server
# Backup existing configuration file
if [ -f "${DANTE_CONF}" ]; then
cp "$DANTE_CONF" "${DANTE_CONF}.bak"
echo -e "\033[32mBackup existing configuration file\033[0m"
fi
NEW_CONFIG=$(cat <<-EOM
logoutput: syslog stdout /data/logs/danted.log
internal: $INTERFACE port = 1080
external: $INTERFACE
socksmethod: username
user.privileged: root
user.unprivileged: nobody
user.libwrap: nobody
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error connect disconnect
}
client block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error connect disconnect
}
socks block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}
EOM
)
# Write configuration file
echo "$NEW_CONFIG" > "$DANTE_CONF"
# Create user for auth
useradd -s /bin/false $DANTE_USER
echo "$DANTE_USER:$DANTE_PASSWORD" | chpasswd
systemctl restart danted
systemctl enable danted
trap - ERR
echo -e "\033[32mDante SOCKS5 proxy has been installed and configured with authentication\033[0m"