Microsoft's Windows Terminal Services (built into Windows 2000 Server and Windows Server 2003) and Windows XP's Remote Desktop, provide an easy, convenient way for administrators to implement thin computing within an organization or for users to connect to their XP desktops from a remote computer and run applications or access files.
Microsoft RDP (Remote Desktop Protocol) is vulnerable to man in the middle vulnerability. This is an update of Erik Forsberg's advisory released in April 2003.
* Terminal Server software: Microsoft Windows Terminal Services using RDP v5.2
* Terminal Server Client software: Microsoft Remote Desktop for Windows XP v5.1.2600.2180
A Windows 2000 terminal server can be installed in one of two modes: administrative or application server. In administrative mode, only users with administrative accounts can access the terminal server, this is why these sessions are so interesting.
By default, the data that travels between the terminal server and the terminal services client is protected by encryption. The RDP protocol uses the RC4 symmetric encryption algorithm which provides three levels of security:
- High: encrypts both the data sent from client to server and the data sent from server to client using a 128- bit key.
- Medium: encrypts both the data sent from client to server and the data sent from server to client using a 56- bit key if the client is a Windows 2000 or above client, or a 40-bit key if the client is an earlier version.
- Low: encrypts only the data sent from client to server, using either a 56-bit or 40-bit key, depending on the client version. In administration mode, RC4 encryption keys are generated after an initial key exchange in which RSA asymmetric encryption is used.
In April 2003 Erik Forsberg released a security advisory to the Internet community explaining how MITM attacks can be performed:
"... During extensive investigation of the Remote Desktop Protocol (RDP), the protocol used to connect to Windows Terminal Services, we have found that although the information sent over the network is encrypted, there is no verification of the identity of the server when setting up the encryption keys for the session. This means RDP is vulnerable to Man In The Middle attacks (from here on referred to as MITM attacks). The attack works as follows:
1) The client connects to the server, however by some method (DNS spoofing, arp poisoning, etc.) we've fooled it to connect to the MITM instead. The MITM sends the request further to the server.
2) The server sends it's public key and a random salt, in clear text, again through the MITM. The MITM sends the packet further to the client, but exchanges the public key to another one for which it knows the private part.
3) The client sends a random salt, encrypted with the server public key, to the MITM.
4) The MITM decrypts the clients random salt with it's private key, encrypts it with the real servers public key and sends it to the server.
5) The MITM now know both the server and the client salt, which is enough information to construct the session keys used for further packets sent between the client and the server. All information sent between the parts can now be read in cleartext.
The vulnerability occurs because the clients by no means try to verify the public key of the server, sent in step 2 above. In other protocols, such as the Secure Shell protocol, most client implementations solve this for example by letting the user answer a question whether a specific server key fingerprint is valid. ..."
Microsoft confirmed the above problem and fixed the new versions of Remote Desktop Clients. Recent clients (mstsc.exe), including the one of version XPSP2 5.1.2600.2180, now check the Terminal Server identity verifying its public key. They solved the problem ? No, man-in-the-middle attacks are still possible and can be really invisible for users.
During the initial key-exchange phase, the terminal server sends to the client a server certificate created at the start up of Terminal Server services. This certificate is stored in the registry of the server under the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ TermService\Parameters\Certificate
The public key modulus (n) is the same as the one present in the RSA2 key stored in the LSA Secret "L$HYDRAENCKEY" of the server; the signature is the information used by the client to verify the server identity. From a man-in-the-middle attacker's point of view, the public key signature must be modified on the fly to trick the client into verifying the new MITM public key that will be replaced into the network packet directed to the client. But what is used to produce this signature? Well, a digital signature is noting more nothing less than a hash of something (in this case a server public key) encrypted using a private key and an asymmetric encryption algorithm. This is exactly what is done by the terminal server. At the client-side, this signature is decrypted using a public key and the result is compared with a new hash of the received server public key calculated by the client; if the two hashes match the identity of the server is approved.
Microsoft use another RSA private key to sign the Terminal Server public key and this private key is public ! It could sound strange but this is only the truth, the private key used for the signature creation is hard-coded into mstlsapi.dll and it is dynamically created, used and de-allocated into a subroutine of the "TLSInit" API. Every Windows user has this file ... is this a new kind of public-private key (PPK) ?!?
The Microsoft Windows Terminal Server PPK follows:
public exponent: e
public modulus: n
secret prime factor: p
secret prime factor: q
d mod (p-1): dmp1
d mod (q-1): dmq1
q^-1 mod p: iqmp
The knowledge of the PPK key lets the attacker calculate a valid signature for the MITM public key generated on the fly during the MITM attack; the client will verify the MITM signature correctly and it will accept the session without informing the users that the server key is changed from the usual one. The signature is calculated encrypting, with the private part of the PPK key, the MD5 hash of the server public key for a total of 108 bytes hashed
By default, in administrative mode, only users with administrative accounts can access the terminal server. An attacker which can perform a successful MITM attack on the RDP sessions could easily obtain administrative credentials and compromise the server. Be warned that the attack could be completely invisible because the Remote Desktop client software does not inform the user about changed server keys.
The attack described above has been successfully implemented into the software Cain & Abel available at http://www.oxid.it. From version 2.7 the program can now perform man-in-the-middle attacks against RDP protocol sessions decrypting all the information that travels from client to server in both directions. The program try also to recognize the keyboard activity at the client-side providing some kind of password interception.