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

Issue with logrotation when scanning a large range #294

Open
nikaiw opened this issue May 7, 2024 · 0 comments
Open

Issue with logrotation when scanning a large range #294

nikaiw opened this issue May 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nikaiw
Copy link
Contributor

nikaiw commented May 7, 2024

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
@NeffIsBack NeffIsBack added the bug Something isn't working label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants