Thursday, August 25, 2016

Exploring capabilities of Microsoft Azure, part 2: how to quickly establish a seamless reverse connection to a secure Windows environment using Azure "Point-to-Site" VPN client

This is part 2 as a follow-up to my previous article.

Introduction

This article describes a simple and time-effective way to quickly establish a reliable "temporary" connection to a secured Windows-based environment that has Internet connection with unrestricted port 443 (TCP) using an undocumented functionality of Microsoft Azure.

The presented functionality works at least on the following Windows editions:
- Windows 2008 R2 SP1
- Windows 7 SP1

Disclaimer

Of course, I have first contacted Microsoft Security Response Center to elaborate if they see any potential vulnerability in the observed behavior. At the state on 25.8.2016 when I publish this article their answer was negative so I feel confident to share this information with developers.

The technique described below is neither obvious nor standard. It perfectly works at the state on 25.8.2016, but Microsoft may close the identified reverse connection opportunity later if they eventually find it insecure.

Remember to get permission from your customer before you open any extra connection in any environment. Any potential misuse of this information is at your own risk and responsibility.

Typical use cases

a. You have a home PC. You want to connect to your running home PC from whatever location via RDP. You don’t want to pay for a dedicated static IP address at home location or conduct any time-consuming negotiations with a representative of your ISP.

b. You are a developer in the customer’s project. You are waiting for many days while the customer grants you a secure access to some QA or DEV environment while your colleague already has a connection. As usual, your colleague cannot share VPN connection credentials with you during working hours because only one person can be connected using them at the same time.

c. You are a solution architect. You found a component of an outsourced developer did not work in QA / DEV. A developer has to overview the problem blindly; of course, wasting your time over numerous Skype sessions/emails. This would be significantly more time effective to connect this person temporarily to QA / DEV machine for a quick live review, but a duration of bureaucratic routines to open extra connections crosses out this idea.

Prerequisites

1. Any Azure subscription.
· “Free Trial” subscription can be acquired on the official site by the URL https://azure.microsoft.com/en-us/free/.

2. Azure virtual machine (Azure VM), Windows-based. It can be of any size. For example, extra small (A0, 0.75 GB) is quite sufficient. Similar VM can be provisioned in ~10 minutes.
· The official guide can be found by the URL https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-hero-tutorial/

3. Established Azure VNET with configured Point-to-Site VPN; it takes ~30-45 min. to configure it from the scratch.
· The official complete configuration guide can be found by the URL https://azure.microsoft.com/en-us/documentation/articles/vpn-gateway-point-to-site-create/.

4. Self-signed Client Certificate (SSL) for that VPN.
· Refer to the “Section 2 - Generate and upload certificates” of the official guide.

5. Azure VPN client package; this is a downloaded executable of tiny size (~200 kb).
· Refer to the “Section 4 - Configure your VPN client” of the official guide.

Requirements for the target environment

The target environment you wish to connect to must have Internet connection and unrestricted access via port 443 (TCP, at least outbound, better both ways).

Requirements for a connecting person

The person you are connecting to the target environment should have Internet connection and any RDP client for Windows.

The idea behind the solution

There is an undocumented feature of Point-to-Site VPN client for Azure that allows connecting back to a machine that initiated this VPN connection in certain conditions. More details can be found in my previous article.

The solution

1. Connect to your target environment (Home PC, QA) under any available account using an RDP session
· For example, you can ask your colleague to connect to QA / DEV on your behalf (refer to the use cases above).

2. Install Client Certificate and Azure VPN client inside the established RDP session to the target environment.
- Both can be downloaded or made from Azure if needed.
- Note you do not need to install anything on the physical machine of the target environment. Use namely the established RDP session to the target environment to install them.

3. Initiate and open Point-to-Site VPN connection inside the RDP session to the target environment (~30 seconds.).
- You can find a private IP address issued by Azure VPN to the established client using "ipconfig".
- Alternatively, this IP is visible in the connection properties on Azure portal.
- Keep this Point-to-Site VPN connection open; in my tests, it fairly survived for many days.

4. Connect to your Azure VM over the internet using some local account of that VM, open an RDP session from its desktop to the RDP session on target environment by private IP from p.3, enter credentials, and keep this RDP window open inside your Azure VM.
- Note your local RDP session can be disconnected (replaced with the one that you have just established from Azure VM).

5. Ask the person to connect to your Azure VM under the same local account that you used to connect to Azure VM. See p.4. The person will open your RDP session and get access to the RDP windows inside.

As a result, the person can start effectively working in the target environment. You don’t have to share any extra credentials to that person except for some local account to connect to Azure VM.

That's all.

P.S. Please remember you cannot use reverse connection if you make it directly to a physical or virtual client machine. Attempts to connect will just close your "Point-to-Site" VPN session in this case.

Instead, you should connect back to the VPN session established from inside a local RDP connection to your physical or virtual machine. And you should not log-off your RDP session for the same reason; just close its window when completed (it keeps running in the background and can be reused later).

Exploring capabilities of Microsoft Azure, part 1: undocumented reverse connection opportunity in Microsoft Azure "Point-to-Site" VPN

I had been recently evaluating network capabilities of Microsoft Azure and found an undocumented reverse connection option that looked interesting to me.

It looks like there is a useful feature in the configuration of "Point-to-Site" VPN client of Microsoft Azure. This feature allows me to connect back from any Windows Virtual Machine running in my Microsoft Azure subscription to local VPN clients via RDP session.
I described my findings below.
Disclaimer
I have contacted Microsoft Security Response Center to elaborate if they see any vulnerability in the observed behavior. At the state on 25.8.2016 when I publish this article their answer was negative so I feel confident to share this information with developers/admins.

A response to my question from a senior Azure Architect at Microsoft was also negative:
"...really, this is speculation/subjective/opinion and would probably be closed there as well...". 
OK, now I am confident this is not an unknown vulnerability, but rather an undocumented feature of Microsoft Azure.

Short description
In regular conditions, a "Point-to-Site" VPN connection drops in the case when you try to connect back to a physical or virtual client machine that initiated this VPN connection, but as I found, it survives if the initial VPN connection was open INSIDE an RDP SESSION established to that physical or virtual machine!
Let me explain it in more details. below.
Initial conditions
Assume you have a Virtual Network ("VNET") in your Azure subscription with configured "Point-to-Site" VPN.

You have a Virtual Machine running Windows ("Azure VM"); it has Remote Desktop client ("RDP").

You also have a physical or virtual local machine with installed "Point-to-Site" VPN client for Microsoft Azure. Let's name it "Local PC #1".

You establish a Remote Desktop session from "Local PC #1" to "Azure VM"; let's name this connection "RDP Azure VM". You initiate and open a "Point-to-Site" VPN connection from "Local PC #1" to your "VNET" as usually.

As a result, you can connect to your resources hosted in Azure subscription using private IP addresses of "VNET".

Attempt to connect back #1

If you try to connect back from "RDP Azure VM" to your "Local PC #1" using RDP client of "RDP Azure VM" and IP address issued to "Point-to-Site" VPN client of "Local PC #1" the connection fails *. It happens because your "Point-to-Site" VPN session immediately disconnects as it should be (no shared connection allowed).

* You can easily find this IP address in a number of ways, for example:
- On the VPN client machine using "ipconfig" and exploring the section "PPP adapter <name of your VNET>".
- On the portal.azure.com under All resources > (your VPN gateway) > Point-to-site configuration > Allocated IP addresses (for Resource model VNET).
- On the portal.azure.com under All resources > (your VNET) > VPN connections > (n) clients > IP addresses (for Classic model VNET).
- A simple Powershell script that just iterates a potential set of IP addresses of your VPN pool accessible from "Azure VM".

Changing to special conditions

Assume you have a second local machine, let's name it "Local PC #2", and you establish a Remote Desktop session from "Local PC #2" to "Local PC #1"; let's name this connection "Local RDP PC #1".

After that, you install "Point-to-Site" VPN client for Microsoft Azure inside the RDP connection "Local RDP PC #1".

You initiate and open a "Point-to-Site" VPN connection from "Local RDP to PC #1" to your "VNET" as usual.

As a result, you can connect from "Local RDP PC #1" to your resources hosted in Azure subscription using private IP addresses of "VNET".

Now please find and remember the IP address issued to "Point-to-Site" VPN client of "Local RDP PC #1". 
Let's name it "Local RDP IP of VPN Client".
- Refer to the previous chapter to find this IP address.
- Note this IP address issued to "Local RDP PC #1" is different from the one issued to "Local PC #1" because technically there are two different VPN clients who established connections. 

Attempt to connect back #2

If you try to connect back from "RDP Azure VM" to your "Local RDP PC #1" using RDP client of "RDP Azure VM" and IP address issued to Point-to-Site VPN client of "Local RDP PC #1" ("Local RDP IP of VPN Client", see above) the connection somehow succeeds while there is still no shared connection allowed. As a result, you can access any available resources of "Local PC #1" and other machines of LAN from "RDP Azure VM" using RDP connection established to "Local RDP PC #1".

In my tests, I have successfully connected back to VPN Client machines at least on the following Windows editions:
- Windows 7 SP1
- Windows 2008 R2 SP1
- Windows 8.1, Update: a reverse connection seems to work only on the early editions of Windows 8.

As you can see, there is an unexpected and undocumented difference in reverse connection behavior between "Attempt to connect back #1" and "Attempt to connect back #2".
Options to use this reverse connection from Azure RDP to local RDP
The identified "feature" seems to open a wide area for imagination.

Fairly, the first thing I tested was establishing a connection from my office to Home PC. It perfectly works!

Take a look at my next article to see more opportunities.