1616from pyrdp .enum import MCSChannelName , ParserMode , PlayerPDUType , ScanCode , SegmentationPDUType
1717from pyrdp .layer import ClipboardLayer , DeviceRedirectionLayer , LayerChainItem , RawLayer , \
1818 VirtualChannelLayer
19+ from pyrdp .layer .rdp .virtual_channel .dynamic_channel import DynamicChannelLayer
20+ from pyrdp .layer .segmentation import SegmentationObserver
1921from pyrdp .logging import RC4LoggingObserver
2022from pyrdp .logging .StatCounter import StatCounter
2123from pyrdp .logging .adapters import SessionLogger
2527from pyrdp .mitm .AttackerMITM import AttackerMITM
2628from pyrdp .mitm .ClipboardMITM import ActiveClipboardStealer , PassiveClipboardStealer
2729from pyrdp .mitm .DeviceRedirectionMITM import DeviceRedirectionMITM
30+ from pyrdp .mitm .DynamicChannelMITM import DynamicChannelMITM
2831from pyrdp .mitm .FastPathMITM import FastPathMITM
2932from pyrdp .mitm .FileCrawlerMITM import FileCrawlerMITM
3033from pyrdp .mitm .MCSMITM import MCSMITM
3841from pyrdp .mitm .config import MITMConfig
3942from pyrdp .mitm .layerset import RDPLayerSet
4043from pyrdp .mitm .state import RDPMITMState
44+ from pyrdp .parser .rdp .virtual_channel .dynamic_channel import DynamicChannelParser
4145from pyrdp .recording import FileLayer , RecordingFastPathObserver , RecordingSlowPathObserver , \
4246 Recorder
4347from pyrdp .security import NTLMSSPState
@@ -274,6 +278,8 @@ def buildChannel(self, client: MCSServerChannel, server: MCSClientChannel):
274278 self .buildClipboardChannel (client , server )
275279 elif self .state .channelMap [channelID ] == MCSChannelName .DEVICE_REDIRECTION :
276280 self .buildDeviceChannel (client , server )
281+ elif self .state .channelMap [channelID ] == MCSChannelName .DYNAMIC_CHANNEL :
282+ self .buildDynamicChannel (client , server )
277283 else :
278284 self .buildVirtualChannel (client , server )
279285
@@ -366,7 +372,10 @@ def buildDeviceChannel(self, client: MCSServerChannel, server: MCSClientChannel)
366372 LayerChainItem .chain (client , clientSecurity , clientVirtualChannel , clientLayer )
367373 LayerChainItem .chain (server , serverSecurity , serverVirtualChannel , serverLayer )
368374
369- deviceRedirection = DeviceRedirectionMITM (clientLayer , serverLayer , self .getLog (MCSChannelName .DEVICE_REDIRECTION ), self .statCounter , self .state , self .tcp )
375+ deviceRedirection = DeviceRedirectionMITM (clientLayer , serverLayer ,
376+ self .getLog (MCSChannelName .DEVICE_REDIRECTION ),
377+ self .statCounter , self .state , self .tcp )
378+
370379 self .channelMITMs [client .channelID ] = deviceRedirection
371380
372381 if self .config .enableCrawler :
@@ -375,6 +384,30 @@ def buildDeviceChannel(self, client: MCSServerChannel, server: MCSClientChannel)
375384 if self .attacker :
376385 self .attacker .setDeviceRedirectionComponent (deviceRedirection )
377386
387+ def buildDynamicChannel (self , client : MCSServerChannel , server : MCSClientChannel ):
388+ """
389+ Build the MITM component for the dynamic channel.
390+ Ref: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpedyc/0147004d-1542-43ab-9337-93338f218587
391+ :param client: MCS channel for the client side
392+ :param server: MCS channel for the server side
393+ """
394+
395+ clientSecurity = self .state .createSecurityLayer (ParserMode .SERVER , True )
396+ clientVirtualChannel = VirtualChannelLayer (activateShowProtocolFlag = False )
397+ clientLayer = DynamicChannelLayer (DynamicChannelParser (isClient = True ))
398+ serverSecurity = self .state .createSecurityLayer (ParserMode .CLIENT , True )
399+ serverVirtualChannel = VirtualChannelLayer (activateShowProtocolFlag = False )
400+ serverLayer = DynamicChannelLayer (DynamicChannelParser (isClient = False ))
401+
402+ clientLayer .addObserver (LayerLogger (self .getClientLog (MCSChannelName .DYNAMIC_CHANNEL )))
403+ serverLayer .addObserver (LayerLogger (self .getServerLog (MCSChannelName .DYNAMIC_CHANNEL )))
404+
405+ LayerChainItem .chain (client , clientSecurity , clientVirtualChannel , clientLayer )
406+ LayerChainItem .chain (server , serverSecurity , serverVirtualChannel , serverLayer )
407+
408+ dynamicChannelMITM = DynamicChannelMITM (clientLayer , serverLayer , self .getLog (MCSChannelName .DYNAMIC_CHANNEL ), self .statCounter , self .state )
409+ self .channelMITMs [client .channelID ] = dynamicChannelMITM
410+
378411 def buildVirtualChannel (self , client : MCSServerChannel , server : MCSClientChannel ):
379412 """
380413 Build a generic MITM component for any virtual channel.
0 commit comments