The Joy Robot
Home | Content | Services | About
Search Eng Light

Jonathan Pablo Toledo Guides, Connectivity 2020-03-06

Connect to a GlobalProtect VPN from Linux with OpenConnect

GlobalProtect is a service of the Palo Alto Networks company that consists of several products, including GlobalProtect Gateway, GlobalProtect Portal, and the GlobalProtect agent.

The latter fulfills three main functions:



  • Communicates with the GlobalProtect portal to obtain the policy for the user.
  • Establish and maintain a secure connection to Palo Alto Networks' closest (and fastest) GlobalProtect Gateway.
  • Finally, it generates a host information profile (HIP) of the client device, which includes factors such as patch level, disk encryption, antivirus version, and many other parameters.

1. Install OpenConnect (example for Debian/Ubuntu)

Terminal
$ sudo apt install openconnect

2. Get the HASH of the certificate and save it

Terminal
$ sudo openconnect --authenticate globalprotect.<tunombre.dominio>

3. Create the directory where the configuration files will be saved

In my case, I used the directory ~/Documents/software/vpnconnect, but you can save them wherever you prefer.



Terminal
$ mkdir -p ~/Documents/software/vpnconnect
$ cd ~/Documents/software/vpnconnect

4. Download the Hipreport Script

Terminal
$ wget https://raw.githubusercontent.com/dlenski/openconnect/034dba1b6e365e76aa1b05f6a0f6f0fcd206e38f/hipreport.sh

5. Give the hipreport script execution permissions

Terminal
$ chmod 755 hipreport.sh

6. Connect to the VPN

The password of the operating system superuser will be requested, and then that of the user of the VPN domain.



Terminal
$ sudo openconnect --csd-wrapper=./hipreport.sh --protocol=gp --user=<usuariodeldominio> --servercert <HASH> globalprotect.<tunombre.dominio>

7. Create a connection script to redirect traffic through the new network interface created by OpenConnect

First, we create the file:



Terminal
$ nano runvpn.sh

Next, we add the following content:



Language: Bash

 1 | #!/bin/bash
 2 | 
 3 | echo "**** GlobalProtect connection script ****"
 4 | 
 5 | user=<your domain username>
 6 | password=<your domain password>
 7 | 
 8 | echo $password | sudo openconnect --csd-wrapper=/<script path>/hipreport.sh --protocol=gp --user=$user --passwd-on-stdin --servercert <your hash> <your domain> &
 9 | 
10 | sleep 5
11 | 
12 | echo "**** Connection successfully established ****"
13 | 
14 | tun0IP="$(ifconfig tun0 | grep 'inet ' | cut -d 't' -f2 | cut -d ' ' -f2)"
15 | 
16 | echo "Your IP is: $tun0IP"
17 | 
18 | sudo route add default gw $tun0IP tun0
19 | 
20 | echo "**** Traffic has been routed through tun0 ****"

The Joy Robot