Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenVPN: cycle through VPN configs #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions payloads/library/remote-access/openvpn/payload.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
#
# Title: OpenVPN
# Description: Create a connection to a VPN-connection to an OpenVPN-server. Optionally: Send traffic from the clients through said tunnel.
# Author: Hak5
# Version: 1.0
# Category: remote-access
# Target: Any
# Net Mode: BRIDGE, VPN
#
# Title: OpenVPN
# Description: Create a VPN connection to an OpenVPN server. Optionally, send
# traffic from the clients through said tunnel.
# Author: Hak5
# Version: 1.1
# Category: remote-access
# Target: Any
# Net Mode: BRIDGE, VPN

# Set to 1 to allow clients to use the VPN
FOR_CLIENTS=0
Expand All @@ -29,12 +30,7 @@ function start() {

DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

# Update factory default payload
cp ${DIR}/payload.sh /root/payloads/switch3/payload.sh

# Set NETMODE to BRIDGE and wait 3 seconds
# to ensure that things can settle

# Set NETMODE to BRIDGE and wait 3 seconds to ensure that things can settle
[[ "$FOR_CLIENTS" == "1" ]] && {
/usr/bin/NETMODE VPN
} || {
Expand All @@ -56,6 +52,37 @@ function start() {
setdns &

LED ATTACK

# Cycle between VPN configs when the button is pressed. The default
# "config.ovpn" will be loaded on startup, and pressing the button will
# cycle through all numbered VPN configs. To use this, add additional VPN
# configs named "config1.ovpn", "config2.ovpn", etc.
#
# If no numbered configs exist, the button functions as a way to reset the
# VPN connection.
next=1
while true; do
NO_LED=true BUTTON

# Stop openvpn and update the LED
LED SETUP
/etc/init.d/openvpn stop

# Determine which config to load next
if [ -f "${DIR}/config${next}.ovpn" ]; then
uci set openvpn.vpn.config="${DIR}/config${next}.ovpn"
uci commit
next=$(($next + 1))
elif [ -f "${DIR}/config1.ovpn" ]; then
uci set openvpn.vpn.config="${DIR}/config1.ovpn"
uci commit
next=1
fi

# Start openvpn and update the LED
/etc/init.d/openvpn start
LED ATTACK
done
}

# Start the payload
Expand Down