Skip to content

Commit

Permalink
Merge pull request #544 from Pennyw0rth/krb5
Browse files Browse the repository at this point in the history
Add option generate-krb5-file for krb5 configuration
  • Loading branch information
mpgn authored Jan 18, 2025
2 parents ed89236 + dd27cc4 commit 9511ca2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
30 changes: 26 additions & 4 deletions nxc/protocols/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def print_host_info(self):
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"])
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})")

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

with open(self.args.generate_hosts_file, "a+") as host_file:
host_file.write(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}\n")
self.logger.debug(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}")
if self.args.generate_hosts_file:
with open(self.args.generate_hosts_file, "a+") as host_file:
host_file.write(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}\n")
self.logger.debug(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}")
elif self.args.generate_krb5_file and isdc:
with open(self.args.generate_krb5_file, "w+") as host_file:
data = f"""
[libdefaults]
dns_lookup_kdc = false
dns_lookup_realm = false
default_realm = { self.domain.upper() }
[realms]
{ self.domain.upper() } = {{
kdc = { self.hostname.lower() }.{ self.domain }
admin_server = { self.hostname.lower() }.{ self.domain }
default_domain = { self.domain }
}}
[domain_realm]
.{ self.domain } = { self.domain.upper() }
{ self.domain } = { self.domain.upper() }
"""
host_file.write(data)
self.logger.debug(data)

return self.host, self.hostname, self.targetDomain

Expand Down
1 change: 1 addition & 0 deletions nxc/protocols/smb/proto_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def proto_args(parser, parents):
smb_parser.add_argument("--smb-timeout", help="SMB connection timeout", type=int, default=2)
smb_parser.add_argument("--laps", dest="laps", metavar="LAPS", type=str, help="LAPS authentification", nargs="?", const="administrator")
smb_parser.add_argument("--generate-hosts-file", type=str, help="Generate a hosts file like from a range of IP")
smb_parser.add_argument("--generate-krb5-file", type=str, help="Generate a krb5 file like from a range of IP")
self_delegate_arg.make_required = [delegate_arg]

cred_gathering_group = smb_parser.add_argument_group("Credential Gathering", "Options for gathering credentials")
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
netexec -h
##### SMB
netexec smb TARGET_HOST --generate-hosts-file /tmp/hostsfile
netexec smb TARGET_HOST --generate-krb5-file /tmp/krb5conf
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # need an extra space after this command due to regex
netexec {DNS} smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --shares
Expand Down

0 comments on commit 9511ca2

Please sign in to comment.