# 1. Global Protect Abuse 1/2

## Introduction&#x20;

The motivation for this blog comes after attending a Mandiant social gathering in London. The presenter, Rohan ([@Decode141](https://twitter.com/Decode141)), described how the VPN could be abused to join an attacker controlled machine on the target Network after initial access is achieved.&#x20;

In this blog I will explore how we can abuse Palo Alto's Global Protect to achieve just that. &#x20;

## Pre-Requisites

* Initial foothold is required
* [User Certificate ](https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA10g000000ClIICA0)
* VPN configuration details
* User Credentials

## Initial foothold

For the sake of simplicity we will assume that we compromised a user and we have a sliver session on the target machine. Anything demonstrated below can be achieved using a C2 of your choice since most functionality comes from Beacon Object Files and C# executables.

## User Credentials

Once we have a foothold on the target machine we could capture user credentials in a number of different ways. The easiest way is to just ask for them :) Let's see how that's done using sliver.&#x20;

Armory offers a wide range of [Beacon Object Files (bof)](https://hstechdocs.helpsystems.com/manuals/cobaltstrike/current/userguide/content/topics/beacon-object-files_main.htm) that are officially supported by sliver. Luckily for us [`c2tc-askcreds`](https://github.com/outflanknl/C2-Tool-Collection/tree/main/BOF/Askcreds) bof prompts the victim for their credentials.&#x20;

When the command is executed the following prompt will appear on their desktop:&#x20;

OneDrive.exe is specified from the bof. That could be anything but something that is relevant to the user would be ideal.&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FRgoyunj0kj3vXDh98xWq%2Fimage.png?alt=media&#x26;token=cd66ac32-1d59-46d4-ac08-95eedf747bd8" alt=""><figcaption><p>AskCreds prompt</p></figcaption></figure>

This is how it looks from the attacker's perspective:&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FlBuICzaaUFAWBM0tWzB3%2Fimage.png?alt=media&#x26;token=533a5a30-b755-405a-93a2-5bf9897020f4" alt=""><figcaption><p>Captured Credentials</p></figcaption></figure>

{% hint style="info" %}
Please note that this bof doesn't validate if the credentials are correct.&#x20;
{% endhint %}

## Global Protect Enumeration

### GUI

The easiest way to obtain information regarding the VPN is through the client app installed on the host machine.&#x20;

The portal login page can be identified by the settings button as shown below:

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FafUFPVbxZ6mxbOqRRsEE%2Fimage.png?alt=media&#x26;token=3557fb2d-3243-4ec6-999d-22e972c3407d" alt=""><figcaption><p>Portal Information</p></figcaption></figure>

Potential gateways to connect to are identified in the Connection Tab:

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FNRdhLinChtSNG8Oeif7u%2Fimage.png?alt=media&#x26;token=6560e9bc-b922-4d4c-b4b9-0f60211dd531" alt=""><figcaption><p>Gateways</p></figcaption></figure>

Information on the Host Profile on the respective tab. That will help us identify what sort of endpoint configuration / hardening we will need prior to a connection to the target network. If the endpoint doesn't meet the minimum requirements it might be isolated from the target network even though a successful connection was established.

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FOFJon3Vr74xZnIcsuRx0%2Fimage.png?alt=media&#x26;token=7bea5b93-07f1-4eb8-9429-2dfe13c6c15c" alt=""><figcaption></figcaption></figure>

### CLI

The `PanGPA.log` located at `C:\Users\<username>\AppData\Local\Palo Alto Networks\GlobalProtect` is very verbose and includes all the information needed to successfully create a remote connection.&#x20;

## User Certificate

In order to login into the paloalto portal we need a client certificate (this is not always the case). Let's find a few potential targets using shodan.&#x20;

The GlobalProtect Portal Login page ends with "/global-protect/login.esp" so using google dorks or shodan we can identify multiple instances.&#x20;

Let's take a look at the first example:

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FizX0UNajoflhgcJYi0hZ%2Fimage.png?alt=media&#x26;token=ac82556a-affd-4ef8-9464-29513bccf0b5" alt=""><figcaption><p>When a valid certificate is required</p></figcaption></figure>

A message appears at the end of the page informing us that a valid certificate is required.&#x20;

Another page found from shodan doesn't seem to have the same requirement.&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FA24esC5zpkAz93OZZ576%2Fimage.png?alt=media&#x26;token=26ba352b-99ec-4610-96c9-82351a3904e2" alt=""><figcaption><p>No certificate is required</p></figcaption></figure>

### Obtain the certificate from the victim

We can obtain the certificate from the host in a number of ways:&#x20;

* Using mmc through the GUI (low-priv user)&#x20;
* Using trustedsec's bofs (low-priv user)&#x20;
* Using mimikatz (requires elevated access)

#### Obtain Certificates through the GUI

We can quickly access user certificates by searching "Manage user certificates" on our host.

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FyvAnoDa2ZNYmR4G98Fhb%2Fimage.png?alt=media&#x26;token=02907d3f-31ad-43ab-ae2a-3cf5e277eb07" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2F0JXm0Cimb1iKUFR86zAU%2Fimage.png?alt=media&#x26;token=f0cb5a8b-0913-4bc9-b5b1-a9355ed6a633" alt=""><figcaption><p>Dave Daves User certificate</p></figcaption></figure>

In this case we need the "Dave Daves" certificate to be exported in order to gain access to the VPN portal.&#x20;

We can export the certificate by right clicking > All Tasks  > Export...

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FVgQhFpfH6hwt52Qa0KmH%2Fimage.png?alt=media&#x26;token=d065bd24-a489-445b-a894-1c42d35d3530" alt=""><figcaption><p>Export Certificate</p></figcaption></figure>

In some cases depending on the ADCS configuration we might face the issue of not being able to export the private key of the certificate.&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FH7h5CEEzY7GTDjrcAEfZ%2Fimage.png?alt=media&#x26;token=2feaa6be-d11f-47bb-b576-468975df8f6c" alt=""><figcaption><p>Export private key greyed out. </p></figcaption></figure>

At this point we could use a tool like [mimikatz to extract the private key](https://krestfield.github.io/docs/pki/exporting_a_nonexportable_certificate.html). That would require patching certain functions in memory and admin privileges. Also executing mimikatz on a mature environment would probably set off a few alarms.&#x20;

Alternatively we could request another certificate from the ADCS server with the export private key property being enabled.&#x20;

That can be done by requesting a new certificate.&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FXJmBBV94ui6E7ntwjaLU%2Fimage.png?alt=media&#x26;token=23b10243-d609-4da5-918d-75aa34947e2b" alt=""><figcaption><p>Requesting new certificate</p></figcaption></figure>

After clicking on Request Certificate with New Key the following window pops up:

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2F23MtZbUoT78FLbERKipy%2Fimage.png?alt=media&#x26;token=0d82cef5-77ca-488a-88e1-3ea9af475bbb" alt=""><figcaption><p>Request a key with private key being exportable</p></figcaption></figure>

1. Expand User Certificate details
2. Click On Properties
3. Navigate to the 'Private Key' Tab
4. Under Key Options, select Make private key exportable

We now have a second key that we are able to export.&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FUjuuiQhsWqEqtcT9SYlg%2Fimage.png?alt=media&#x26;token=46cda011-45aa-4332-a700-b20d85290e0e" alt=""><figcaption><p>"Export the private key" enabled</p></figcaption></figure>

In the following steps we will be asked to set up a password for the exported key and define the export directory. On an engagement instead of leaving the key lying around you can delete it once it's downloaded. &#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FVXllfKIXpoZd5cfhd9sQ%2Fimage.png?alt=media&#x26;token=304d54eb-15ed-44fd-9cd8-d33b9edfd8cf" alt=""><figcaption><p>Last step before exporting our key</p></figcaption></figure>

### Obtain the certificate through the beacon

We could use tools such as[ Hidden Desktop](https://github.com/sliverarmory/HiddenDesktop) to extract the keys as demonstrated before but it's not always possible. Thankfully the same result can be achieved using beacon object files without any GUI interaction.&#x20;

Two bofs will be used to request the certificate:

* [sa-adcs-enum](https://github.com/sliverarmory/CS-Situational-Awareness-BOF/tree/master/src/SA/adcs_enum) (I found this bof more reliable than using sa-adcs-enum-com. sa-adcs-enum-com would cause the sliver beacon to crash. I am not sure if that's the case with Cobalt Strike)

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2Flyi1GteA3WsiaOJXix7E%2Fimage.png?alt=media&#x26;token=3da2ec8f-e19a-4565-960a-ba74934dddca" alt=""><figcaption><p>sa-adcs-enum (most reliable in my experience)</p></figcaption></figure>

* [remote-adcs-request](https://github.com/sliverarmory/CS-Remote-OPs-BOF/tree/main/Remote/adcs_request)

sa-adcs-enum will help us identify all the information needed to create a valid adcs request using remote-adcs-request.&#x20;

**sa-adcs-enum**

This bof doesn't really require any arguments. We can just run this bof to enumerate the Certificate Authority and the template name required for the next step.

The first few lines will show all the information needed for the CA

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FwggeZQnZhSxPEUO5iG07%2Fimage.png?alt=media&#x26;token=3259a4d4-9034-4047-8921-38adfdd14574" alt=""><figcaption><p>Certificate Authority information</p></figcaption></figure>

From the above screenshot we can extract the name of the Certificate Authority `CLAIRE-ALEX-DC-CA` and the domain name is `CLAIRE.local`

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FcTSUg2BnQL9krSPDTLmf%2Fimage.png?alt=media&#x26;token=bb4e9fe8-ebd6-42c0-8619-f54862c93ba7" alt=""><figcaption><p>User Template</p></figcaption></figure>

The `User` template is the one required to authenticate to the VPN portal. Depending on the environment the template might have a different name .&#x20;

**remote-adcs-request**

All we need now is to run the following command so the pirvate key and certificate will be dumped.&#x20;

```
[server] sliver (LIGHT_JOURNEY) > remote-adcs-request 'Claire.local\CLAIRE-ALEX-DC-CA' User 
```

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FICD5I6fpM4wtYLWiAhW0%2Fimage.png?alt=media&#x26;token=ff8e3cfd-713d-459e-88ac-f8e712ea3b39" alt=""><figcaption><p>Generating the certificate</p></figcaption></figure>

We can then copy the contents of the certificate to a file and convert it to a .pfx file using the following command.&#x20;

```
openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx
```

## Additional considerations before connecting to the portal

It is common nowadays to come across MFA authentication after logging in. The fact that we have foothold on the target machine we can get the user to authenticate for us. Let's take the [number matching scenario](https://learn.microsoft.com/en-us/azure/active-directory/authentication/how-to-mfa-number-match#multifactor-authentication) demonstrated below:

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FacW3Q4GEgabnAe5x6jRW%2Fimage.png?alt=media&#x26;token=a907529a-66d3-4668-a844-820a81e8553c" alt=""><figcaption><p>Number matching MFA</p></figcaption></figure>

The user is expected to use the number appearing on his screen, usually in a browser, and type it into their authenticator application.&#x20;

In some cases authenticator will show more information such as the connection location. We might want to match the user's location to avoid adding to the victim's suspicion. &#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2F7e4xY6ru4cEFnFtwbohV%2Fimage.png?alt=media&#x26;token=3ffe39a7-79c7-4e39-b2c1-ce2080a57be6" alt=""><figcaption><p>Authenticator with additional context</p></figcaption></figure>

To overcome the MFA a small [c# script ](https://github.com/scriptchildie/maliciousCodeMatchingMFA/tree/main)was written. We can run from sliver or cobaltstrike to prompt the user with the number to match.&#x20;

### Attacker&#x20;

The user is essentially running the c# executable within the beacon's process. The executable takes 2 arguments, the user's email and the and number to type into their authenticator.&#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2FHeUpVTRM2UkUkvLtjnuz%2Fimage.png?alt=media&#x26;token=a62333a1-2d6f-4986-95e7-c2ad615e70a9" alt=""><figcaption><p>MFA phishing</p></figcaption></figure>

### Victim

The victim will see the pop up show up on his desktop. We then hope the user will authenticate for us. &#x20;

<figure><img src="https://1525675160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1BtmYYGIbNqDCOEq0YOj%2Fuploads%2Fn0LKSCm68zk6DUoYWJZu%2Fimage.png?alt=media&#x26;token=6a712c50-5fe5-4126-a058-0c4afb44e443" alt=""><figcaption><p>malicious MFA pop-up</p></figcaption></figure>

In the second part of this blog we will go through the process of connecting to the VPN and possible hardening techniques we can apply on the Firewall to stop attackers from connecting to the VPN from a non corporate laptop.&#x20;
