Hello and welcome back!
Today I come to you with a quick hack I wrote to allow myself to quickly connect to Cisco Any Connect VPN Endpoints. I wrote this with Linux in mind as I use a local VirtualBox VM locally that runs literally nothing but a VPN and an RDP client.
The reason? I don’t want my main computer touching anything with this specific VPN I am referring to and wanted a flexible way to RDP into a required server.
As a result, I came up with the below script based off the current version of Cisco Any Connect in combination with xFreeRDP:
VPN_COMMAND="/opt/cisco/anyconnect/bin/vpn"
VPN_ADDRESS="https://corporate_vpn.com"
VPN_CONNECT="$VPN_COMMAND -s connect $VPN_ADDRESS"
VPN_DISCONNECT="$VPN_COMMAND disconnect"
USERNAME="username"
DOMAIN="domain"
PASSWORD="password"
VDI_ADDRESS="VDI-IP"
SUDO_PASSWORD="sudo_password"
$VPN_DISCONNECT
#Remove Existing Configurations
rm -f ~/.anyconnect
printf "$SUDO_PASSWORD" | sudo -S "find rm -f /opt/cisco/anyconnect/profile/ -name '*.xml' -delete"
echo "Type Token:"
read token
printf "y\ny\n" | $VPN_CONNECT
#$VPN_CONNECT
#If Certificate Not Trusted
printf "y\ny\n2\n$USERNAME\n$PASSWORD\n$token\n" | $VPN_CONNECT
#If Certificate Trusted
#printf "2\n$USERNAME\n$PASSWORD\n$token\n" | $VPN_CONNECT
xfreerdp /u:$DOMAIN\\$USERNAME /p:$PASSWORD /v:$VDI_ADDRESS /f -wallpaper +clipboard