1919from aardwolf .commons .target import RDPTarget
2020from aardwolf .keyboard .layoutmanager import KeyboardLayoutManager
2121from aardwolf .protocol .x224 .constants import SUPP_PROTOCOLS
22+ from aardwolf .network .x224 import X224Network
23+ from aardwolf .network .tpkt import TPKTPacketizer
2224from asyauth .common .credentials .ntlm import NTLMCredential
2325from asyauth .common .credentials .kerberos import KerberosCredential
2426from asyauth .common .constants import asyauthSecret
2527from asysocks .unicomm .common .target import UniTarget , UniProto
28+ from asysocks .unicomm .client import UniClient
2629
2730
2831class rdp (connection ):
@@ -33,12 +36,10 @@ def __init__(self, args, db, host):
3336 self .iosettings .video_out_format = VIDEO_FORMAT .RAW
3437 self .iosettings .clipboard_use_pyperclip = False
3538 self .protoflags_nla = [
36- SUPP_PROTOCOLS .SSL | SUPP_PROTOCOLS .RDP ,
3739 SUPP_PROTOCOLS .SSL ,
3840 SUPP_PROTOCOLS .RDP ,
3941 ]
4042 self .protoflags = [
41- SUPP_PROTOCOLS .SSL | SUPP_PROTOCOLS .RDP ,
4243 SUPP_PROTOCOLS .SSL ,
4344 SUPP_PROTOCOLS .RDP ,
4445 SUPP_PROTOCOLS .SSL | SUPP_PROTOCOLS .HYBRID ,
@@ -113,7 +114,7 @@ def create_conn_obj(self):
113114 self .target = RDPTarget (ip = self .host , domain = "FAKE" , port = self .port , timeout = self .args .rdp_timeout )
114115 self .auth = NTLMCredential (secret = "pass" , username = "user" , domain = "FAKE" , stype = asyauthSecret .PASS )
115116
116- self .check_nla ()
117+ asyncio . run ( self .check_nla () )
117118
118119 for proto in reversed (self .protoflags ):
119120 try :
@@ -165,22 +166,26 @@ def create_conn_obj(self):
165166
166167 return True
167168
168- def check_nla (self ):
169+ async def check_nla (self ):
169170 self .logger .debug (f"Checking NLA for { self .host } " )
170- for proto in self .protoflags_nla :
171- try :
172- self .iosettings .supported_protocols = proto
173- self .conn = RDPConnection (
174- iosettings = self .iosettings ,
175- target = self .target ,
176- credentials = self .auth ,
177- )
178- asyncio .run (self .connect_rdp ())
179- if proto .value == SUPP_PROTOCOLS .RDP or proto .value == SUPP_PROTOCOLS .SSL or proto .value == SUPP_PROTOCOLS .SSL | SUPP_PROTOCOLS .RDP :
180- self .nla = False
181- return
182- except Exception :
183- pass
171+ try :
172+ self .iosettings .supported_protocols = SUPP_PROTOCOLS .SSL
173+ self .conn = RDPConnection (
174+ iosettings = self .iosettings ,
175+ target = self .target ,
176+ credentials = None ,
177+ )
178+ packetizer = TPKTPacketizer ()
179+ client = UniClient (self .target , packetizer )
180+ self .conn ._connection = await asyncio .wait_for (client .connect (), timeout = self .args .rdp_timeout )
181+ self .conn ._x224net = X224Network (self .conn ._connection )
182+ _ , err = await asyncio .wait_for (self .conn ._x224net .client_negotiate (0 , SUPP_PROTOCOLS .SSL ), timeout = self .args .rdp_timeout )
183+ # If no error SSL supported if SSL_NOT_ALLOWED_BY_SERVER error, plain RDP supported
184+ if err is None or "SSL_NOT_ALLOWED_BY_SERVER" in str (err ):
185+ self .nla = False
186+ return
187+ except Exception :
188+ pass
184189
185190 async def connect_rdp (self ):
186191 _ , err = await asyncio .wait_for (self .conn .connect (), timeout = self .args .rdp_timeout )
0 commit comments