# How to resolve RDP service exposure from the internet?

{% hint style="info" %}
This page is a practical hardening guide.

Goal: remove direct Internet exposure of **TCP/3389**.
{% endhint %}

## Protection of the RDP Service

RDP (Remote Desktop Protocol) is a Microsoft protocol for remote access.

It typically uses **TCP port 3389**.

It is a **high-value entry point** for attackers.

{% hint style="info" %}
An exposed RDP service becomes exploitable if:

* it is affected by a public vulnerability (example: BlueKeep)
* credentials are weak, reused, or leaked

That is usually enough for initial access and lateral movement.
{% endhint %}

Expose RDP only on internal networks.

Do not expose it directly to the Internet.

## Solutions

Most observed RDP services are used for two reasons:

* Remote administration
* Access to documents

Regarding remote administration, it is possible to consider the following options (in descending order of preference):

* Implementation of an RDP gateway, called RDG (Remote Desktop Gateway)
* Deployment of a VPN (Virtual Private Network)
* Hardening of the RDP service

Minimum baseline:

* Block inbound **TCP/3389** on the perimeter firewall.
* Allow RDP only **from** your RD Gateway or VPN IP range.

If the second reason applies, namely for the purpose of accessing internal documents, the adoption of Microsoft O365 and its SharePoint storage space should be prioritized.

## Implementation of an RDP Gateway

### Description

Remote Desktop Gateway (RDG) provides a safer way to reach internal RDP servers.

It acts as an intermediary. Only the gateway is exposed to clients.

It uses **HTTPS (TLS)** and typically exposes only **TCP/443**.

Place the gateway in an existing DMZ.

### Gateway installation

Connect to the Windows server that will host the gateway.

Open **Server Manager**.

#### Adding the gateway role

Once launched, it is necessary to access the "Add Roles and Features" functionality from the "Manage" tab of the Server Manager application:

<figure><img src="/files/00d6bff88e8c930496246ae242a8819c0d23b58d" alt=""><figcaption></figcaption></figure>

Then, you can proceed with the installation by clicking the "Next" button:

<figure><img src="/files/6ae3d1eeb8fce0c1d5ffecb6730fede1068d752a" alt=""><figcaption></figcaption></figure>

The installation type "Role-based or feature-based installation" must be selected before proceeding to the next section via the "Next" button:

<figure><img src="/files/217f6fb338d0b917aee801d64af194114cc474ec" alt=""><figcaption></figcaption></figure>

This step allows you to select the server on which the gateway will be installed. Once you have identified it, click on the "Next" button to continue:

<figure><img src="/files/1da33e670177d3dba39b17a22a31c1dba7d94d7e" alt=""><figcaption></figcaption></figure>

This tab allows you to select the roles to add to the server. You must select "Remote Desktop Services" before clicking "Next" to continue:

<figure><img src="/files/babf14870abb1a9af701fcc4a0a35f7979a1f5d0" alt=""><figcaption></figcaption></figure>

Certain features can be implemented on the server from this tab. You can leave the default features selected and go further:

<figure><img src="/files/04e76833ab81887adf5970b8f81654c8137e014f" alt=""><figcaption></figcaption></figure>

This is an informative tab about Remote Desktop Services; it can be skipped:

<figure><img src="/files/44e03621da1b19a650e8be0c44d54cf756f49916" alt=""><figcaption></figcaption></figure>

Select the **Remote Desktop Gateway** role service.

When prompted, accept the required features:

<figure><img src="/files/5af205f4609ed8dae34902a4ba790796f7c192aa" alt=""><figcaption></figcaption></figure>

Confirm the selection, then continue:

<figure><img src="/files/88988571732e0d5d83aee7168b04ae99d12d0609" alt=""><figcaption></figcaption></figure>

Certain tabs, related to the features selected previously, have been added automatically. Click "Next" to access them:

<figure><img src="/files/cc9663f559237fe5ca04fcb6f1cc90f240ffaafb" alt=""><figcaption></figcaption></figure>

This new tab contains information about the network policy and access service feature. Click "Next" to proceed to the next section:

![](/files/bd876411e9bdccf6a748bae52c3b4304115b6dd5)

This new tab contains information about the web server functionality. Click "Next" to proceed to the next section:

<figure><img src="/files/0903779f11cba28b4ba0045f9c843fd0eafcb283" alt=""><figcaption></figcaption></figure>

A list representing all services related to the web server (IIS) is displayed. It is necessary to retain this default configuration before proceeding further:

<figure><img src="/files/edabeb9f9308608282022ed46549a7c427e3b74f" alt=""><figcaption></figcaption></figure>

A window summarising all the services and tools that will be installed is displayed to the user. Click on the "Install" button to confirm the installation (you can authorize the server to restart automatically by ticking the "Restart the destination server automatically" box):

<figure><img src="/files/e1d7238c7bcc9586a164ddb632ee0d9a4b62e62c" alt=""><figcaption></figcaption></figure>

The installation is complete:

![](/files/bfec377b6eb4f9a594daa8636fd8a17595acaf3d)

### Gateway configuration

Once installation is complete, you must then configure the remote desktop gateway by launching its management tool from the "Server Manager" application and the "Tools" tab, as shown in the following figure:

<figure><img src="/files/a4c7c14b4238f9a8e43abfbf4f26773050e44edf" alt=""><figcaption></figcaption></figure>

Once the tool has been launched, the window below is displayed to the user after selecting the server name on the left-hand interface. The newly installed remote desktop gateway must be configured. To do this, you can start by importing a certificate by clicking on the "View or modify certificate properties" feature:

<figure><img src="/files/616de410e8f9c2f7e23ebdf8efe269605d4bfaf5" alt=""><figcaption></figcaption></figure>

No certificate is installed on the gateway. There are two options:

1. Create a self-signed certificate
2. Or import a certificate corresponding to the server issued by a recognised certification authority.

The best choice is the **second option**. To do this, simply

* Select the option "Import a certificate into the RD Gateway Certificates (Local Computer)/Personal store",
* Then import it using the "Browse and Import Certificate" button:

<figure><img src="/files/68f10f1521ef27de8d0ee465cad16d9b86baa7b9" alt=""><figcaption></figcaption></figure>

If a self-signed certificate is to be created and used, simply select the "Create a self-signed certificate" option and click on the "Create and Import Certificate" button. The following window will appear:

<figure><img src="/files/8ae6a8e07247a4aba88d031a0bc707380568a72c" alt=""><figcaption></figcaption></figure>

The full name of the server must be entered in the first field, "Certificate name". This certificate must then be retrieved from the server and imported into all future machines using this gateway.

Once this step is complete, the window below will reappear. The imported certificate information will be updated, indicating that the import was successful.

Click "OK" to complete the gateway configuration:

<figure><img src="/files/464fda0dafb6de5dbcc4bd533d4f70ce29cb4d08" alt=""><figcaption></figcaption></figure>

Access rules must be added so that this gateway can be used correctly. To do this, click on the server drop-down menu on the left-hand side of the RD Gateway Manager application interface, then click on Policies and finally on Create New Authorization Policies, as shown in the figure below:

<figure><img src="/files/386a32460b5c179e181cfec59023285d42d07555" alt=""><figcaption></figcaption></figure>

The following window is displayed to the user. Two access rules must be created:

* An access rule for the gateway (called RD CAP) **and**
* An access rule for internal resources from the gateway (called RD RAP).

To do this, select "Create a RDP CAP and a RD RAP (recommended)" and then click "Next":

<figure><img src="/files/8dc4f9889b12d1c4a1e4429d4fee8ec3d5c14c08" alt=""><figcaption></figcaption></figure>

Name the CAP rule, then click "Next":

<figure><img src="/files/acb34e6c3ebd3c69f996fdf3da7041a1d6ffb091" alt=""><figcaption></figcaption></figure>

Select the user group(s) allowed to use the gateway (CAP), then click "Next":

<figure><img src="/files/c85e210ad88794c9978e8b7a8285bd1f30c434b8" alt=""><figcaption></figcaption></figure>

This step allows you to define the redirection properties of the CAP rule. Depending on certain business needs (and for ease of use), some redirections may be important and necessary, such as copy and paste ("Clipboard"):

* If certain redirections are not necessary, it is recommended to select the option "Disable device redirection for the following client device types" and then select them in order to strengthen the gateway configuration.
* If all redirections are necessary, select the "Enable device redirection for all client devices" option and then click "Next".

<figure><img src="/files/dbf7a2d3ba23cbaac09f8b377c88351578b0b534" alt=""><figcaption></figcaption></figure>

This window is used to configure user session disconnection and expiry. It is recommended that you enable these options in order to strengthen the gateway configuration before continuing with the "Next" button:

<figure><img src="/files/c866727a8c848a698bf107f2f2b990fdef8ee08e" alt=""><figcaption></figcaption></figure>

A summary of the CAP rule configuration appears. You must now configure the RAP rule by clicking the "Next" button:

<figure><img src="/files/aef6e1e5d11d2345279c0bf29327ba933cfb59f2" alt=""><figcaption></figcaption></figure>

A summary of the CAP rule configuration appears.

Select the user group membership for the RAP rule, then click "Next":

<figure><img src="/files/ae19f6e6679fa2937d3ae8b870959cd738274870" alt=""><figcaption></figcaption></figure>

In the same way as the CAP rule, only the group(s) containing legitimate users who are authorised to use the gateway to access internal resources should be selected in the "User group membership (required)" box via the "Add Group..." button.

{% hint style="info" %}
Ideally, a specific user group should be created for this access within Active Directory to ensure their legitimacy.
{% endhint %}

You can then proceed by clicking on the "Next" button:

<figure><img src="/files/3a9113cc6a58d4d69e7824a5f796b30dbf4e5b61" alt=""><figcaption></figcaption></figure>

This window is used to specify all internal resources accessed from the gateway.

{% hint style="info" %}
It is recommended to create a domain group containing all legitimate servers that can be accessed from this gateway and to specify it using the "Select and Active Directory Domain Services network resource group" option.
{% endhint %}

<figure><img src="/files/d35136c23110619a772c06a7e6e03bd31891cf15" alt=""><figcaption></figcaption></figure>

The access ports used must be specified, either the default port 3389 for the RDP service or another port or ports if necessary:

<figure><img src="/files/7b9d66626c1028135f3017d500bcc45c5b24ac85" alt=""><figcaption></figcaption></figure>

In the same way as the CAP rule, a summary of the RAP rule configuration appears. You must confirm by clicking the "Next" button:

<figure><img src="/files/2588ddf9b81305073d062f0de53e2b4357bf8b82" alt=""><figcaption></figcaption></figure>

A window pops up, confirming the CAP and RAP rules:

<figure><img src="/files/970dd4f988fcc0508c4b2b2c3fb13cd9f7cd5489" alt=""><figcaption></figcaption></figure>

### Launching the gateway service

Finally, the gateway service may be stopped. You can check its status and activate it if it is not already running, as shown in the following figure.

From the Remote Desktop Services tab in the Server Manager application, the "Servers" tab and the "Services" section, the gateway service is identified by its name "Remote Desktop Gateway".

It can be launched if necessary by right-clicking on this service and then clicking on "Start Services":

<figure><img src="/files/2e60b10656d9facb9718224286d50126911bc028" alt=""><figcaption></figcaption></figure>

### Flow filtering

When internal servers must only be accessible from the gateway, it is necessary to configure their internal firewall.

To do this, simply access the Windows firewall configuration and list the incoming flows ("Inbound Rules" or "Incoming Traffic Rules"), as shown in the following figure.

Among these is the rule named "Remote Desktop - User Mode (TCP-In)", corresponding to incoming RDP traffic from the Windows system. You can analyse its properties by right-clicking and selecting "Properties":

<figure><img src="/files/6c7c546d1a793ae1d743016904f18f63248947b1" alt=""><figcaption></figcaption></figure>

You must then go to the "Scope" tab to configure filtering of incoming RDP traffic:

<figure><img src="/files/c547be73ead283153e15d4497c614beaf8e6ad80" alt=""><figcaption></figcaption></figure>

In the "Remote IP Address" section, you must specify all IP addresses from which incoming RDP traffic is permitted:

* If all of these flows must pass through the gateway, the gateway's IP address must be specified.
* If the gateway is installed on the server to which an RDP connection is made, the IP address "127.0.0.1" must be specified.

<figure><img src="/files/c384ff40b889eabd5e0cf7e54883c21bcbddd641" alt=""><figcaption></figcaption></figure>

### Starting an RDP connection

The RDP connection from a legitimate machine and user to an internal server via the gateway must be configured.

After launching the "Remote Desktop Connection" application, you must configure the gateway in the "Advanced" tab, then "Settings", as shown in the following figure:

<figure><img src="/files/6333663c771eb6464c73aa936c5ff0b75e6f7cdc" alt=""><figcaption></figcaption></figure>

The following window will appear:

* Select the "Use these RD Gateway server settings" option
* Enter the **FQDN** of the previously configured RD Gateway
* Tick the "Use my RD Gateway credentials for the remote computer" box
* Confirm the configuration by clicking "OK"

<figure><img src="/files/b682d3b46528af500a149b75fe7e17cbdedef935" alt=""><figcaption></figcaption></figure>

Then, simply return to the general tab of the application, enter the name or IP address of the internal server to which the client wishes to connect and their username, before clicking on the "Connect" button as shown in the following figure:

<figure><img src="/files/322327155698955098c354a2b9f499f366e08530" alt=""><figcaption></figcaption></figure>

A window is displayed to the user so that they can verify the name or IP address of the RDP gateway and enter the password for the user account they entered previously:

<figure><img src="/files/40008ea6d325f66408574f77e7441504228cf2ef" alt=""><figcaption></figcaption></figure>

Next, either the connection is successful, or the gateway certificate is not recognised by the client machine (usually the case with a self-signed certificate or one signed by an internal certification authority), and this message is returned:

![](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwzUTKOoCOAuhqMwyJZbG%2Fuploads%2FSr92NPJRPx9JejH1f09f%2Fimage.png?alt=media\&token=f76f5b59-96ab-4dba-b5ce-ae5aee1c5039)

### RDP protocol hardening

In the event that it is necessary to expose the RDP protocol on the internet, here are several hardening measures to secure the protocol.

{% hint style="info" %}
It should be noted that these methods are not sufficient to guarantee the security of the services and should only be used temporarily.
{% endhint %}

Minimum temporary baseline:

* Enforce **MFA** for remote access (preferably via RD Gateway or VPN).
* Enable **Network Level Authentication (NLA)** on target servers.
* Restrict inbound RDP to a strict **IP allowlist** (ideally only the gateway).

#### Restrict user access

Create a dedicated Active Directory group for allowed RDP users.

Use the Group Policy Management Console ([GPMC](https://www.it-connect.fr/chapitres/la-console-gpmc-group-policy-management-console/)).

Typical approach:

* Add your AD group to the local **Remote Desktop Users** group via GPO.
* Alternatively, set the user right **Allow log on through Remote Desktop Services**.

Example (Restricted Groups / local group membership):

<figure><img src="/files/df17b58f7a941be91843adef3c1e2b3b4788b33d" alt=""><figcaption></figcaption></figure>

Add the allowed users or groups, then click OK:

<figure><img src="/files/9365299f0c8f8e85c8ae376cd6f40e7b3104c51a" alt=""><figcaption></figcaption></figure>

#### Deactivate guest account

The Windows Server 2012 R2 operating system has a guest account by default. It is necessary to disable it to prevent an attacker from attempting to elevate privileges on the server.

To do this, type the command `compmgmt.msc` in a command prompt to open Computer Management.

#### Temporarily lock an account in the event of a brute force attack

Attempts to log in to a user account should alert the system to prevent an attacker from launching brute force attacks until they identify a valid password.

Configure an **account lockout policy** (local or domain).

Domain (recommended): use the Group Policy Management Console.

* Computer Configuration > Windows Settings > Security Settings > Account Policies > Account Lockout Policy
* Set "Account lockout threshold" to **5** invalid logons
* Set lockout duration and reset counter to **15 minutes** (typical baseline)

{% hint style="info" %}
We recommend locking the account after 5 failed login attempts.
{% endhint %}

#### Use a strong password policy

To reduce the risk of a successful brute force or dictionary attack, the first thing to do is to use strong passwords with all types of characters: Upper case letters, lower case letters, numbers and special characters.

To configure this,

* Type the command `gpedit.msc` in a command prompt to open the Local Group Policy Editor
* Click Computer Configuration > Windows Settings > Security Settings > Account Policies > Password Policy.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stoik.io/cyber-best-practices/how-to-resolve-rdp-service-exposure-from-the-internet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
