From d9c703c777fd6d1aff3ba7a254e399ed6b9b6a11 Mon Sep 17 00:00:00 2001 From: Joe Testa Date: Thu, 5 Dec 2024 09:41:26 -0500 Subject: [PATCH] When running against multiple hosts, now prints each target host regardless of output level. (#309) --- README.md | 1 + src/ssh_audit/outputbuffer.py | 22 +++++++++++----------- src/ssh_audit/ssh_audit.py | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0456e41..60e21aa 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,7 @@ For convenience, a web front-end on top of the command-line tool is available at ### v3.4.0-dev - Added warning to all key exchanges that do not include protections against quantum attacks due to the Harvest Now, Decrypt Later strategy (see https://en.wikipedia.org/wiki/Harvest_now,_decrypt_later). - Migrated from deprecated `getopt` module to `argparse`; partial credit [oam7575](https://github.com/oam7575). + - When running against multiple hosts, now prints each target host regardless of output level. ### v3.3.0 (2024-10-15) - Added Python 3.13 support. diff --git a/src/ssh_audit/outputbuffer.py b/src/ssh_audit/outputbuffer.py index 0058c8e..cb937e1 100644 --- a/src/ssh_audit/outputbuffer.py +++ b/src/ssh_audit/outputbuffer.py @@ -54,11 +54,11 @@ class OutputBuffer: self.__is_color_supported = ('colorama' in sys.modules) or (os.name == 'posix') self.line_ended = True - def _print(self, level: str, s: str = '', line_ended: bool = True) -> None: + def _print(self, level: str, s: str = '', line_ended: bool = True, always_print: bool = False) -> None: '''Saves output to buffer (if in buffered mode), or immediately prints to stdout otherwise.''' - # If we're logging only 'warn' or above, and this is an 'info', ignore message. - if self.get_level(level) < self.__level: + # If we're logging only 'warn' or above, and this is an 'info', ignore message, unless always_print is True (useful for printing informational lines regardless of the level setting). + if (always_print is False) and (self.get_level(level) < self.__level): return if self.use_colors and self.colors_supported and len(s) > 0 and level != 'info': @@ -145,22 +145,22 @@ class OutputBuffer: self._print('head', s, line_ended) return self - def fail(self, s: str, line_ended: bool = True, write_now: bool = False) -> 'OutputBuffer': - self._print('fail', s, line_ended) + def fail(self, s: str, line_ended: bool = True, write_now: bool = False, always_print: bool = False) -> 'OutputBuffer': + self._print('fail', s, line_ended, always_print=always_print) if write_now: self.write() return self - def warn(self, s: str, line_ended: bool = True) -> 'OutputBuffer': - self._print('warn', s, line_ended) + def warn(self, s: str, line_ended: bool = True, always_print: bool = False) -> 'OutputBuffer': + self._print('warn', s, line_ended, always_print=always_print) return self - def info(self, s: str, line_ended: bool = True) -> 'OutputBuffer': - self._print('info', s, line_ended) + def info(self, s: str, line_ended: bool = True, always_print: bool = False) -> 'OutputBuffer': + self._print('info', s, line_ended, always_print=always_print) return self - def good(self, s: str, line_ended: bool = True) -> 'OutputBuffer': - self._print('good', s, line_ended) + def good(self, s: str, line_ended: bool = True, always_print: bool = False) -> 'OutputBuffer': + self._print('good', s, line_ended, always_print=always_print) return self def sep(self) -> 'OutputBuffer': diff --git a/src/ssh_audit/ssh_audit.py b/src/ssh_audit/ssh_audit.py index 0837a91..421cc6a 100755 --- a/src/ssh_audit/ssh_audit.py +++ b/src/ssh_audit/ssh_audit.py @@ -532,9 +532,9 @@ def output(out: OutputBuffer, aconf: AuditConf, banner: Optional[Banner], header else: host = '%s:%d' % (aconf.host, aconf.port) - out.good('(gen) target: {}'. format(host)) + out.good('(gen) target: {}'. format(host), always_print=True) if client_audit: - out.good('(gen) client IP: {}'.format(client_host)) + out.good('(gen) client IP: {}'.format(client_host), always_print=True) if len(header) > 0: out.info('(gen) header: ' + '\n'.join(header)) if banner is not None: