Hardening consulting

Supporting reconnection in RDP

Yes, another post on RDP ! I did some experiments with automatic reconnection, so this post talks about that project.


Automatic reconnection

Automatic reconnection allows a RDP client to automatically reconnect to the server without the need to re-authenticate. The typical example is when you close the lid of your laptop with an active RDP session, when you open it again, the client will reconnect automagically. This can also be the case with a network problem.


At the protocol level

Automatic reconnection is described in the specification:

  • Once the client has authenticated, the server will send a reconnection cookie and a session id in a Save Session Info PDU. The client is supposed to store these values and use then when reconnecting;
  • when it's time to reconnect, it's gonna use the session id and the cookie and will put them in the client info PDU. In fact it's not the cookie itself but a derived value that is computed using this formula:
toSend = hmac_md5(cookie, clientRandom);

The cookie itself is used like the key for a HMAC-MD5 computation. The hashed content is either 32 bytes of zeros when the transport is secured (TLS or NLA security). When the RDP security is used, it is the clientRandom that is exchanged during the negotiation.

  • When the server receives the packet it will do the same computation to check that the cookie is legitimate and will reconnect the client if so.

One would note that the specification states that the cookie is supposed be regenerated every hour by the server.

To conclusion

A very interesting feature which was quite easy to implement. I found a bug in FreeRDP which was not storing the clientRandom on the server-side. Since this patch, it is fixed.