If you work with RDP (which stands for remote desktop protocol) usually to manage servers when you can’t do that task remotely, the envelope for this today is quite small however, some people have the old mindset of needing to be physically on the server to manage it.
If you have quite a few servers and you don’t disconnect correctly, you can end up with lots of disconnected sessions on all your servers, If you are not putting all these sessions through a gateway or a broker, you don’t have a clue where these sessions are because there’s no centralized log of where you’ve got lingering session.
If you do have a disconnected session on a server that doesn’t necessarily cause a problem until you change your password (the guidance on this is somewhat misinterpreted sometimes) when you do change your password (and this problem is not just limited to password changes) every disconnected session will still have the old password and it will cause you to have an account that continually locks out.
Password change policy
Obviously, your policies will be different depending on where you work, that being said, sometimes the policies can be very contradictory as they are not able to take into account complicated passwords, that will unlikely be reverse engineered (this is also known as cracking your password)
In this example consider for a moment, this is your password:
stLViK$+u&rlyecr#1pemAw#i3a
If you do have a password like that What’s funny is you will actually remember how to type that in with muscle memory once you touch enough times it will be quite easy, However, you change your password every month possibly every three months this is where the problem start….
Password will outdo any password policy that your company but the problem here occurs when the pass policy set by your company assumes people who do the bare minimum, so your extra secure password is also subject to the same policies because you probably have “One rule for everyone”
This will force you to do stupid things like set your password on the next change to exactly the same as before with one on the end as below:
stLViK$+u&rlyecr#1pemAw#i3a1
You still had a very secure password but now you’re applying unacceptable tactics to qualify to change password policy because you remember the last 15, now because you’ve added a “1” on the end you fall into the same trap everyone else does and probably the reason you have a password policy to start with.
If your password is very secure, you should really be exempting it from password changes as it will encourage wrong behaviors.
Course Trajectory : Back to RDP mission
My little outline on passwords is over let’s get back to the mission which is you need to find your disconnected RDP session so we have a couple of options here and they are :
A: Scan a list of small RDP servers for disconnected sessions
B: Scan a list of "all servers" from ADDS that match "server" and then scan that list
C: Scan a list of known RDP servers that are online and scan that list
Cavets/Notes
- If you scan the whole domain this will take sometime but will complete, however that will depend on how many servers you have
- If you scan the domain ensure the server listens on TCP:3389 as if it does not you will not have a disconnected RDP session
- If you scan the domain ensure the timeout is low so after 2 seconds it moves onto the next server
Script : RDP-ScanandDisconnect.ps1
This is option C where you need to have a servers.txt file in the same folder as the script (unless you ammend the script)