NetExec
NetExec copied to clipboard
Issue with logrotation when scanning a large range
Describe the bug Logging error when scanning a large range, related to Rotation
To Reproduce scan a large range of hosts and reduce the maxBytes value from RotatingFileHandler(output_file, maxBytes=100) in logger.py (reducing maxBytes is not mandatory but help to trigger the issue faster)
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/__init__.py", line 1104, in emit
self.flush()
File "/usr/lib/python3.10/logging/__init__.py", line 1084, in flush
self.stream.flush()
OSError: [Errno 9] Bad file descriptor
Call stack:
File "/usr/lib/python3.10/threading.py", line 973, in _bootstrap
self._bootstrap_inner()
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 83, in _worker
work_item.run()
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/user/.local/pipx/venvs/netexec/lib/python3.10/site-packages/nxc/protocols/smb.py", line 164, in __init__
connection.__init__(self, args, db, host)
File "/home/user/.local/pipx/venvs/netexec/lib/python3.10/site-packages/nxc/connection.py", line 106, in __init__
self.logger.info(f"Socket info: host={self.host}, hostname={self.hostname}, kerberos={self.kerberos}, ipv6={self.is_ipv6}, link-local ipv6={self.is_link_local_ipv6}")
This might be because all the threads inherit the same fd for logging. However, when the log file is being rotated they keep trying to write to the old fd which was closed.
setting maxBytes to 0 to disable rotation of log indeed prevent the issue from happening.
when the issue occurs, this others related stacktrace can happen:
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/handlers.py", line 73, in emit
if self.shouldRollover(record):
File "/usr/lib/python3.10/logging/handlers.py", line 197, in shouldRollover
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
BrokenPipeError: [Errno 32] Broken pipe
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/handlers.py", line 73, in emit
if self.shouldRollover(record):
File "/usr/lib/python3.10/logging/handlers.py", line 197, in shouldRollover
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
OSError: [Errno 29] Illegal seek