Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[winrm] better output #114

Merged
merged 8 commits into from
Dec 10, 2023
21 changes: 16 additions & 5 deletions nxc/protocols/winrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ def __init__(self, args, db, host):
self.lmhash = ""
self.nthash = ""
self.ssl = False
self.auth_type = None

connection.__init__(self, args, db, host)

def proto_logger(self):
# Reason why default is SMB/445, because default is enumerate over SMB.
# For more details, please check the function "print_host_info"
logging.getLogger("pypsrp").disabled = True
logging.getLogger("pypsrp.wsman").disabled = True
self.logger = NXCAdapter(
extra={
"protocol": "WINRM",
"protocol": "SMB",
"host": self.host,
"port": "5985",
"port": "445",
"hostname": self.hostname,
}
)
Expand Down Expand Up @@ -180,9 +183,16 @@ def laps_search(self, username, password, ntlm_hash, domain):
return True

def print_host_info(self):
self.logger.extra["protocol"] = "WINRM-SSL" if self.ssl else "WINRM"
self.logger.extra["port"] = self.port
self.logger.display(f"{self.server_os} (name:{self.hostname}) (domain:{self.domain})")
if self.args.no_smb:
self.logger.extra["protocol"] = "WINRM-SSL" if self.ssl else "WINRM"
self.logger.extra["port"] = self.port
self.logger.display(f"{self.server_os} (name:{self.hostname}) (domain:{self.domain})")
else:
self.logger.display(f"{self.server_os} (name:{self.hostname}) (domain:{self.domain})")
self.logger.extra["protocol"] = "WINRM-SSL" if self.ssl else "WINRM"
self.logger.extra["port"] = self.port

self.logger.info(f"Connection information: {self.endpoint} (auth type:{self.auth_type}) (domain:{self.domain if self.args.domain else ''})")

if self.args.laps:
return self.laps_search(self.args.username, self.args.password, self.args.hash, self.domain)
Expand Down Expand Up @@ -211,6 +221,7 @@ def create_conn_obj(self):
self.logger.debug(f"Requesting URL: {endpoints[protocol]['url']}")
res = requests.post(endpoints[protocol]["url"], verify=False, timeout=self.args.http_timeout)
self.logger.debug(f"Received response code: {res.status_code}")
self.auth_type = res.headers["WWW-Authenticate"] if "WWW-Authenticate" in res.headers else "NOAUTH"
self.endpoint = endpoints[protocol]["url"]
self.ssl = endpoints[protocol]["ssl"]
return True
Expand Down