Skip to content

Commit 485f720

Browse files
authored
Merge pull request #446 from Pennyw0rth/fix-windows
Fix windows and encoding stuff
2 parents 9e61764 + 8485417 commit 485f720

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

netexec.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ a = Analysis(
2525
'impacket.dcerpc.v5.lsad',
2626
'impacket.dcerpc.v5.gkdi',
2727
'impacket.dcerpc.v5.rprn',
28+
'impacket.dcerpc.v5.even',
2829
'impacket.dpapi_ng',
2930
'impacket.tds',
3031
'impacket.version',
@@ -48,6 +49,7 @@ a = Analysis(
4849
'pywerview.cli.helpers',
4950
'pylnk3',
5051
'pypykatz',
52+
'pyNfsClient',
5153
'masky',
5254
'msldap',
5355
'msldap.connection',

nxc/logger.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ def parse_debug_args():
2222
args, _ = debug_parser.parse_known_args()
2323
return args
2424

25+
2526
def setup_debug_logging():
2627
debug_args = parse_debug_args()
2728
root_logger = logging.getLogger("root")
28-
29+
2930
if debug_args.verbose:
3031
nxc_logger.logger.setLevel(logging.INFO)
3132
root_logger.setLevel(logging.INFO)
@@ -35,7 +36,7 @@ def setup_debug_logging():
3536
else:
3637
nxc_logger.logger.setLevel(logging.ERROR)
3738
root_logger.setLevel(logging.ERROR)
38-
39+
3940

4041
def create_temp_logger(caller_frame, formatted_text, args, kwargs):
4142
"""Create a temporary logger for emitting a log where we need to override the calling file & line number, since these are obfuscated"""
@@ -47,22 +48,24 @@ def create_temp_logger(caller_frame, formatted_text, args, kwargs):
4748

4849
class SmartDebugRichHandler(RichHandler):
4950
"""Custom logging handler for when we want to log normal messages to DEBUG and not double log"""
51+
5052
def __init__(self, formatter=None, *args, **kwargs):
5153
super().__init__(*args, **kwargs)
5254
if formatter is not None:
5355
self.setFormatter(formatter)
54-
56+
5557
def emit(self, record):
5658
"""Overrides the emit method of the RichHandler class so we can set the proper pathname and lineno"""
5759
# for some reason in RDP, the exc_text is None which leads to a KeyError in Python logging
5860
record.exc_text = record.getMessage() if record.exc_text is None else record.exc_text
59-
61+
6062
if hasattr(record, "caller_frame"):
6163
frame_info = inspect.getframeinfo(record.caller_frame)
6264
record.pathname = frame_info.filename
6365
record.lineno = frame_info.lineno
6466
super().emit(record)
6567

68+
6669
def no_debug(func):
6770
"""Stops logging non-debug messages when we are in debug mode
6871
It creates a temporary logger and logs the message to the console and file
@@ -72,7 +75,7 @@ def no_debug(func):
7275
def wrapper(self, msg, *args, **kwargs):
7376
if self.logger.getEffectiveLevel() >= logging.INFO:
7477
return func(self, msg, *args, **kwargs)
75-
else:
78+
else:
7679
formatted_text = Text.from_ansi(self.format(msg, *args, **kwargs)[0])
7780
caller_frame = inspect.currentframe().f_back
7881
create_temp_logger(caller_frame, formatted_text, args, kwargs)
@@ -94,7 +97,7 @@ def __init__(self, extra=None):
9497
self.logger = logging.getLogger("nxc")
9598
self.extra = extra
9699
self.output_file = None
97-
100+
98101
logging.getLogger("impacket").disabled = True
99102
logging.getLogger("pypykatz").disabled = True
100103
logging.getLogger("minidump").disabled = True
@@ -181,7 +184,7 @@ def add_file_log(self, log_file=None):
181184
open(output_file, "x") # noqa: SIM115
182185
file_creation = True
183186

184-
file_handler = RotatingFileHandler(output_file, maxBytes=100000)
187+
file_handler = RotatingFileHandler(output_file, maxBytes=100000, encoding="utf-8")
185188

186189
with file_handler._open() as f:
187190
if file_creation:
@@ -203,7 +206,7 @@ def init_log_file():
203206
datetime.now().strftime("%Y-%m-%d"),
204207
f"log_{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.log",
205208
)
206-
209+
207210

208211
class TermEscapeCodeFormatter(logging.Formatter):
209212
"""A class to strip the escape codes for logging to files"""

nxc/parsers/ldap_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def parse_result_attributes(ldap_response):
88
continue
99
attribute_map = {}
1010
for attribute in entry["attributes"]:
11-
val = [str(val) for val in attribute["vals"].components]
11+
val = [str(val).encode(val.encoding).decode("utf-8") for val in attribute["vals"].components]
1212
attribute_map[str(attribute["type"])] = val if len(val) > 1 else val[0]
1313
parsed_response.append(attribute_map)
1414
return parsed_response

0 commit comments

Comments
 (0)