Automatic Connection Script for Cisco Any Connect and Windows RDP Box

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s