Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions nxc/protocols/rdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ def __init__(self, args, db, host):
SUPP_PROTOCOLS.RDP,
]
self.protoflags = [
SUPP_PROTOCOLS.SSL,
SUPP_PROTOCOLS.RDP,
SUPP_PROTOCOLS.SSL,
SUPP_PROTOCOLS.SSL | SUPP_PROTOCOLS.HYBRID,
SUPP_PROTOCOLS.SSL | SUPP_PROTOCOLS.HYBRID_EX,
]
self.selected_proto = None
self.login_proto = None
width, height = args.res.upper().split("X")
height = int(height)
width = int(width)
Expand Down Expand Up @@ -112,8 +114,11 @@ def write(self, msg):

def print_host_info(self):
nla = colored(f"nla:{self.nla}", host_info_colors[3], attrs=["bold"]) if self.nla else colored(f"nla:{self.nla}", host_info_colors[2], attrs=["bold"])
if self.domain is None:
self.logger.display(f"Probably old, doesn't not support HYBRID or HYBRID_EX ({nla})")
if self.server_os is None:
if self.selected_proto == SUPP_PROTOCOLS.RDP:
self.logger.display(f"Standard RDP Security only, no server info available ({nla})")
else:
self.logger.display(f"Probably old, doesn't not support HYBRID or HYBRID_EX ({nla})")
else:
self.logger.display(f"{self.server_os} (name:{self.hostname}) (domain:{self.domain}) ({nla})")
try:
Expand All @@ -125,16 +130,19 @@ def _create_rdp_connection(self, credentials, supported_protocols=None):
iosettings = self.iosettings.clone_for_connection()
# Explicit protocols are used by discovery and screenshot fallbacks.
# Authenticated connections leave this unset so aardwolf selects the
# X224 flags appropriate for the credential type.
iosettings.supported_protocols = supported_protocols
return RDPConnection(
# X224 flags appropriate for the credential type, unless the server
# has no CredSSP and only takes the protocol create_conn_obj() found.
iosettings.supported_protocols = self.login_proto if supported_protocols is None else supported_protocols
conn = RDPConnection(
iosettings=iosettings,
target=copy.deepcopy(self.target),
credentials=copy.deepcopy(credentials),
)
conn.autologon_timeout = self.args.rdp_logon_timeout
return conn

def create_conn_obj(self):
self.target = RDPTarget(ip=self.host, domain="FAKE", port=self.port, timeout=self.args.rdp_timeout, unsafe_ssl=True) # old servers only offer ciphers OpenSSL rejects at its default security level
self.target = RDPTarget(ip=self.host, domain="FAKE", port=self.port, timeout=self.args.rdp_timeout, unsafe_ssl=True, autologon=False) # old servers only offer ciphers OpenSSL rejects at its default security level; no autologon with the dummy credentials
self.auth = NTLMCredential(secret="pass", username="user", domain="FAKE", stype=asyauthSecret.PASS)

self.runner.run(self.check_nla())
Expand Down Expand Up @@ -162,12 +170,23 @@ def create_conn_obj(self):
self.remoteName = sanitize_dns(info_domain.get("dnscomputername"), self.logger) if self.kerberos else self.host
self.server_os = self.guess_os(info_domain)
self.logger.extra["hostname"] = self.hostname
self.selected_proto = proto
break
else:
self.selected_proto = proto # accepted: without CredSSP the dummy credentials cannot fail here
break

if self.selected_proto is None:
self.logger.debug("Server rejected every protocol we offered")
elif self.selected_proto in (SUPP_PROTOCOLS.RDP, SUPP_PROTOCOLS.SSL):
self.login_proto = self.selected_proto

if self.args.domain:
self.domain = self.args.domain
if self.args.local_auth:
self.domain = self.hostname
if self.domain is None:
self.domain = self.hostname

if not self.kdcHost and self.domain:
result = self.resolver(self.domain)
Expand Down Expand Up @@ -223,7 +242,8 @@ async def check_nla(self):

async def connect_rdp(self):
"""Connect to the RDP server. Does NOT clean up on exit."""
_, err = await asyncio.wait_for(self.conn.connect(), timeout=self.args.rdp_timeout)
# Without CredSSP, connect() also waits up to autologon_timeout for the server to confirm the logon
_, err = await asyncio.wait_for(self.conn.connect(), timeout=self.args.rdp_timeout + (self.conn.autologon_timeout if self.login_proto is not None else 0))
if err is not None:
raise err
self.logger.debug(f"RDP negotiated protocol: {self.conn.x224_protocol}, authz_result: {self.conn.authz_result}")
Expand All @@ -249,6 +269,8 @@ async def login_and_confirm(self):

That PDU never comes when access is authorized but the logon is refused (restricted admin).
"""
if self.login_proto is not None and self.auth.stype != asyauthSecret.PASSWORD: # without CredSSP aardwolf sends the secret as the autologon password, so a hash, key or ccache only fails (+2 badPwdCount)
raise ValueError("no CredSSP on this server, only a password can log on")
await self.terminate_conn() # a session kept by an earlier success (--continue-on-success) would take a session slot this logon needs
self.conn = self._create_rdp_connection(self.auth)
await self.connect_rdp()
Expand Down
1 change: 1 addition & 0 deletions nxc/protocols/rdp/proto_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def proto_args(parser, parents):
rdp_parser.add_argument("-H", "--hash", metavar="HASH", dest="hash", nargs="+", default=[], help="NTLM hash(es) or file(s) containing NTLM hashes")
rdp_parser.add_argument("--port", type=int, default=3389, help="RDP port")
rdp_parser.add_argument("--rdp-timeout", type=int, default=5, help="RDP timeout on socket connection")
rdp_parser.add_argument("--rdp-logon-timeout", type=int, default=15, help="Time to wait for the logon confirmation of a server without NLA/CredSSP, raise it if a first logon is slow")
rdp_parser.add_argument("--nla-screenshot", action="store_true", help="Screenshot RDP login prompt if NLA is disabled")

dgroup = rdp_parser.add_mutually_exclusive_group()
Expand Down
42 changes: 21 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
"Topic :: Security"
]
dependencies = [
"aardwolf>=0.2.16",
"aardwolf>=0.2.17",
"argcomplete>=3.1.4",
"asyauth>=0.0.20",
"bloodhound-ce>=1.8.0",
Expand Down
30 changes: 15 additions & 15 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading