Skip to content

Commit e10756a

Browse files
committed
add krb5 conf file option for smb
1 parent a5ec90e commit e10756a

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

nxc/protocols/smb.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def print_host_info(self):
318318
smbv1 = colored(f"SMBv1:{self.smbv1}", host_info_colors[2], attrs=["bold"]) if self.smbv1 else colored(f"SMBv1:{self.smbv1}", host_info_colors[3], attrs=["bold"])
319319
self.logger.display(f"{self.server_os}{f' x{self.os_arch}' if self.os_arch else ''} (name:{self.hostname}) (domain:{self.targetDomain}) ({signing}) ({smbv1})")
320320

321-
if self.args.generate_hosts_file:
321+
if self.args.generate_hosts_file or self.args.generate_krb5_file:
322322
from impacket.dcerpc.v5 import nrpc, epm
323323
self.logger.debug("Performing authentication attempts...")
324324
isdc = False
@@ -328,9 +328,31 @@ def print_host_info(self):
328328
except DCERPCException:
329329
self.logger.debug("Error while connecting to host: DCERPCException, which means this is probably not a DC!")
330330

331-
with open(self.args.generate_hosts_file, "a+") as host_file:
332-
host_file.write(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}\n")
333-
self.logger.debug(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}")
331+
if self.args.generate_hosts_file:
332+
with open(self.args.generate_hosts_file, "a+") as host_file:
333+
host_file.write(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}\n")
334+
self.logger.debug(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}")
335+
elif self.args.generate_krb5_file and isdc:
336+
with open(self.args.generate_krb5_file, "w+") as host_file:
337+
data = f"""
338+
[libdefaults]
339+
dns_lookup_kdc = false
340+
dns_lookup_realm = false
341+
default_realm = { self.domain.upper() }
342+
343+
[realms]
344+
{ self.domain.upper() } = {{
345+
kdc = { self.hostname.lower() }.{ self.domain }
346+
admin_server = { self.hostname.lower() }.{ self.domain }
347+
default_domain = { self.domain }
348+
}}
349+
350+
[domain_realm]
351+
.{ self.domain } = { self.domain.upper() }
352+
{ self.domain } = { self.domain.upper() }
353+
"""
354+
host_file.write(data)
355+
self.logger.debug(data)
334356

335357
return self.host, self.hostname, self.targetDomain
336358

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def proto_args(parser, parents):
2121
smb_parser.add_argument("--smb-timeout", help="SMB connection timeout", type=int, default=2)
2222
smb_parser.add_argument("--laps", dest="laps", metavar="LAPS", type=str, help="LAPS authentification", nargs="?", const="administrator")
2323
smb_parser.add_argument("--generate-hosts-file", type=str, help="Generate a hosts file like from a range of IP")
24+
smb_parser.add_argument("--generate-krb5-file", type=str, help="Generate a krb5 file like from a range of IP")
2425
self_delegate_arg.make_required = [delegate_arg]
2526

2627
cred_gathering_group = smb_parser.add_argument_group("Credential Gathering", "Options for gathering credentials")

0 commit comments

Comments
 (0)