# RDP MitM Exercise

### 1. Introduction

The Man-in-the-Middle (MitM) attack is a cyberattack where the attacker secretly relays and possibly alters the communications between two parties who believe that they are directly communicating with each other. This theory is discussing MitM for the rdp protocol

### 2. Goal

* performing an rdp mitm proxy
* play with username/password authentication
* enable/disable NLA (Network Layer Authentication on the target RDP server)

### 3. Security Questions

As you can see, the RDP connection is protected against this kind of RDP main-in-the-middle attack by activating NLA (Network Level Authentication). Please do your research and respond to the following questions

* Explain NLA?
* Explain CredSSP?
* Explain why NLA should protect against MitM?
* Would 2FA fix the problem of this kind of MitM attack?
* What is the difference between the two nmap outputs in the steps above (enabled/disabled NLA)?

### 4. Exercise

#### 4.1 Pyrdp Mitm Docker

1. Disable NLA for RDP on Client

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FVi6iUEeThmPuivEhtP8m%2Frdp01.png?alt=media&#x26;token=90c21ce2-acd2-4031-aa21-e1082a83ec26" alt=""></div>

2\. Perform nmap scan to check if NLA is active on port 3389

> nmap -P0 -p 3389 --script rdp-enum-encryption 192.168.71.150 192.168.71.159

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2Fsg3RKVwFnXKVpxRHRANJ%2Fnmap01.png?alt=media\&token=6ddd81a5-68db-4001-8f6e-b12ea80c4e98)

3\. Setup Pyrdp Docker

> docker pull gosecure/pyrdp:latest\
> docker run --rm -i -p 3389:3389 gosecure/pyrdp pyrdp-mitm.py `x.x.x.x` (IP Adress of RDP Server)

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FeaSmFVvDgT7qxDM4NX3s%2Fdocker_rdp01.png?alt=media&#x26;token=56043489-f704-4165-a2db-e3177f13c101" alt=""></div>

In my case the setup didn't work. I can see that the docker service is listening on localhost with port 3389, but for some reasons the forwarding to the destination server failed!

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FVejlIpkWEzMEY5KLRCEe%2Fnetstat01.png?alt=media\&token=e31dddf6-38d0-4993-9ffd-8e6df07873e8)

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FWDsWcbzIkRiuI68ESsMq%2Fnetstat02.png?alt=media\&token=19a6e2d0-82f6-4625-8ebd-0dd91c53f2d3)

4\. Enable NLA for RDP Client

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2F7doMTSuNpJywL6jket5g%2Frdp03.png?alt=media&#x26;token=f7c74018-3549-451b-8159-ca007210a11c" alt=""></div>

5\. Perform nmap scan to check NLA again

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2F33FJySNxDVSnejagrZxh%2Fnmap02.png?alt=media\&token=1f4b5ba7-2968-45bc-bae0-9a051bdcd412)

I'll stop here and use another tool to simulate an RDP mitm attack

#### 4.2 Seth Mitm tool

Setup: 1 Kali Linux Box (Attacker), 1Win2k8 Server (Victim), 1 Win10 Box (Target)

https://github.com/SySS-Research/Seth

Attacker IP: 192.168.71.164 Victim IP: 192.168.71.166\
Target IP: 192.168.71.150

> ./seth.sh eth1 192.168.71.{164,166,150}

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FdoLHib7OAaMXVCF2BxdI%2Fseth01.png?alt=media\&token=da4863c3-16f5-4512-ab8a-f7a1614cf636)

Initialize RDP Connection from Server to Win10 Box

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2Fmg2JNTysKayLHGxVGpZ4%2Frdp_cert_error01.png?alt=media&#x26;token=569a6ee7-f777-480e-8211-870d8b1f9b0d" alt=""></div>

Victim needs to **ignore the certificate warnings** and proceed with yes!

Attacker catched credentials!

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FNPpRKCVZDkfqZaykuKlV%2Fattacker01.png?alt=media\&token=af8af129-528f-47bd-9c5d-a276d7bda1d8)

**If NLA for RDP is enabled this attack won't work!**

### 5. Answers

Network Level Authentication, or NLA as its commonly known, is a service/technology that is used in conjunction with Remote Desktop services and was rolled out with version 6.0 of RDP with initial support in MS Windows Vista.

NLA uses the Credential Security Support Provider (CredSSP) protocol to perform strong server authentication over SSL/TLS or Kerberos to protect against MITM attacks. Additionally, the NLA protects the remote client by completing user authentication before a full RDP connection is established.

2FA can be used for a better security, but won't fully prevent this kind of attack. The attacker will still be able to catch the second factor when the victim types it.

First output shows that downgrade to other type of weaker authentication is possible. With NLA activated only strong server authentication is allowed.

### 6. Further Readings

[https://www.alternativesec.xyz/pentesting/2017/01/02/NLA-How-to/](https://www.alternativesec.xyz/pentesting/2017/01/02/NLA-How-to/)\
[https://www.gosecurity.ch/rdp-man-in-the-middle-angriff/](https://www.gosecurity.ch/rdp-man-in-the-middle-angriff/)
