Skip to content

Commit 5f05c1d

Browse files
committed
only nego when cheking nla
1 parent b1e9d63 commit 5f05c1d

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

nxc/protocols/rdp.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
from nxc.config import host_info_colors, process_secret
1313
from nxc.paths import NXC_PATH
1414

15+
16+
from asysocks.unicomm.client import UniClient
17+
from aardwolf.network.tpkt import TPKTPacketizer
18+
from aardwolf.network.x224 import X224Network
19+
1520
from aardwolf.connection import RDPConnection
1621
from aardwolf.commons.queuedata.constants import VIDEO_FORMAT
1722
from aardwolf.commons.queuedata.keyboard import RDP_KEYBOARD_UNICODE
@@ -32,11 +37,6 @@ def __init__(self, args, db, host):
3237
self.iosettings = RDPIOSettings()
3338
self.iosettings.video_out_format = VIDEO_FORMAT.RAW
3439
self.iosettings.clipboard_use_pyperclip = False
35-
self.protoflags_nla = [
36-
SUPP_PROTOCOLS.SSL | SUPP_PROTOCOLS.RDP,
37-
SUPP_PROTOCOLS.SSL,
38-
SUPP_PROTOCOLS.RDP,
39-
]
4040
self.protoflags = [
4141
SUPP_PROTOCOLS.SSL | SUPP_PROTOCOLS.RDP,
4242
SUPP_PROTOCOLS.SSL,
@@ -113,7 +113,7 @@ def create_conn_obj(self):
113113
self.target = RDPTarget(ip=self.host, domain="FAKE", port=self.port, timeout=self.args.rdp_timeout)
114114
self.auth = NTLMCredential(secret="pass", username="user", domain="FAKE", stype=asyauthSecret.PASS)
115115

116-
self.check_nla()
116+
asyncio.run(self.check_nla())
117117

118118
for proto in reversed(self.protoflags):
119119
try:
@@ -165,22 +165,25 @@ def create_conn_obj(self):
165165

166166
return True
167167

168-
def check_nla(self):
168+
async def check_nla(self):
169169
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
170+
try:
171+
self.iosettings.supported_protocols = SUPP_PROTOCOLS.SSL | SUPP_PROTOCOLS.RDP
172+
self.conn = RDPConnection(
173+
iosettings=self.iosettings,
174+
target=self.target,
175+
credentials=None,
176+
)
177+
packetizer = TPKTPacketizer()
178+
client = UniClient(self.target, packetizer)
179+
self.conn._connection = await asyncio.wait_for(client.connect(), timeout=self.args.rdp_timeout)
180+
self.conn._x224net = X224Network(self.conn._connection)
181+
_, err = await asyncio.wait_for(self.conn._x224net.client_negotiate(0, SUPP_PROTOCOLS.SSL | SUPP_PROTOCOLS.RDP), timeout=self.args.rdp_timeout)
182+
if err is None or "HYBRID_REQUIRED_BY_SERVER" not in str(err):
183+
self.nla = False
184+
return
185+
except Exception:
186+
pass
184187

185188
async def connect_rdp(self):
186189
_, err = await asyncio.wait_for(self.conn.connect(), timeout=self.args.rdp_timeout)

0 commit comments

Comments
 (0)