Skip to content

Commit 08b486d

Browse files
authored
Merge pull request Pennyw0rth#482 from Pennyw0rth/hosts_file
Add option to generate hosts file for smb proto to first blood more quickly on htb
2 parents cd75a4c + d9982b4 commit 08b486d

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

nxc/protocols/smb.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,22 @@ def print_host_info(self):
313313
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"])
314314
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})")
315315

316+
if self.args.generate_hosts_file:
317+
from impacket.dcerpc.v5 import nrpc, epm
318+
self.logger.debug("Performing authentication attempts...")
319+
isdc = False
320+
try:
321+
epm.hept_map(self.host, nrpc.MSRPC_UUID_NRPC, protocol="ncacn_ip_tcp")
322+
isdc = True
323+
except DCERPCException:
324+
self.logger.debug("Error while connecting to host: DCERPCException, which means this is probably not a DC!")
325+
326+
with open(self.args.generate_hosts_file, "a+") as host_file:
327+
host_file.write(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}\n")
328+
self.logger.debug(f"{self.host} {self.hostname} {self.hostname}.{self.targetDomain} {self.targetDomain if isdc else ''}")
329+
330+
return self.host, self.hostname, self.targetDomain
331+
316332
def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="", kdcHost="", useCache=False):
317333
self.logger.debug(f"KDC set to: {kdcHost}")
318334
lmhash = ""

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def proto_args(parser, parents):
1919
smb_parser.add_argument("--gen-relay-list", metavar="OUTPUT_FILE", help="outputs all hosts that don't require SMB signing to the specified file")
2020
smb_parser.add_argument("--smb-timeout", help="SMB connection timeout", type=int, default=2)
2121
smb_parser.add_argument("--laps", dest="laps", metavar="LAPS", type=str, help="LAPS authentification", nargs="?", const="administrator")
22+
smb_parser.add_argument("--generate-hosts-file", type=str, help="Generate a hosts file like from a range of IP")
2223
self_delegate_arg.make_required = [delegate_arg]
2324

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

tests/e2e_commands.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
##### Check Generic Help Options
22
netexec -h
33
##### SMB
4+
netexec smb TARGET_HOST --generate-hosts-file /tmp/hostsfile
45
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # need an extra space after this command due to regex
56
netexec {DNS} smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS
67
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --shares

0 commit comments

Comments
 (0)