Skip to content

fix: improve headless RDP input and clipboard lifecycle - #47

Draft
Adamkadaban wants to merge 5 commits into
skelsec:mainfrom
Adamkadaban:rdp-reliability-final
Draft

fix: improve headless RDP input and clipboard lifecycle#47
Adamkadaban wants to merge 5 commits into
skelsec:mainfrom
Adamkadaban:rdp-reliability-final

Conversation

@Adamkadaban

Copy link
Copy Markdown

Fixes several issues that prevent reliable headless (non-interactive) RDP automation.

  1. Extended scancodes: Keys like Win (0xE05B) were sent as raw 16-bit keycodes. Windows requires keycode 0x5B with the KBDFLAGS.EXTENDED flag set separately. Without this, Win+R is silently ignored when we use send_key_scancode

  2. Synchronize Event serialization: TS_SYNC_EVENT.toggleFlags was serialized as 2 bytes. Both the MS spec and FreeRDP define it as 4 bytes (UINT32) after a 2-byte pad. Sending only 2 bytes caused Windows to immediately close the connection.

  3. Keyboard focus initialization: When mstsc or FreeRDP gives the RDP window focus, they send a 3-message sequence: Tab release, Synchronize (current Caps/Num/Scroll Lock state), Tab release. This tells the keyboard that it is ready and then shares the toggle key state. Without it, keystrokes after connecting may get silently dropped.

  4. Input send error propagation: send_key_scancode, send_mouse, send_focus_in, and handle_out_data now return transport errors instead of silently reporting success when the network write failed.

  5. Connection state isolation: Added RDPIOSettings.clone_for_connection() that produces fresh clipboard and dynamic channel state per connection. Prevents cross-connection state contamination when making multiple sequential connections.

  6. Clipboard lifecycle:
    Handlers are unregistered on channel stop. Exposed CLIPBOARD_FORMAT_LIST_RESPONSE acceptance as a queue event so callers can synchronize clipboard writes before triggering remote reads.

Sources

MS-RDPBCGR

FreeRDP

Testing

  • Tested e2e on Windows Server 2022, Windows 11, and Server 2025 AD with NTLM, Kerberos password, ccache, NT hash, and AES
  • Tested against Netexec E2E suite.

(Developed with assistance from Copilot, but all reviewed and tested by a human)

@Adamkadaban
Adamkadaban marked this pull request as draft July 27, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant