diff --git a/README.md b/README.md index bcb3a2b..b3cfa9b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # lsassy -[![PyPI version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=py&type=6&v=v3.1.7&x2=0)](https://pypi.org/project/lsassy) +[![PyPI version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=py&type=6&v=v3.1.8&x2=0)](https://pypi.org/project/lsassy) [![PyPI Statistics](https://img.shields.io/pypi/dm/lsassy.svg)](https://pypistats.org/packages/lsassy) [![Tests](https://github.com/hackndo/lsassy/workflows/Tests/badge.svg)](https://github.com/hackndo/lsassy/actions?workflow=Tests) [![Twitter](https://img.shields.io/twitter/follow/hackanddo?label=HackAndDo&style=social)](https://twitter.com/intent/follow?screen_name=hackanddo) diff --git a/lsassy/__init__.py b/lsassy/__init__.py index 47ed839..b7edc10 100644 --- a/lsassy/__init__.py +++ b/lsassy/__init__.py @@ -1 +1 @@ -__version__ = '3.1.7' +__version__ = '3.1.8' diff --git a/lsassy/console.py b/lsassy/console.py index 4e95ba4..7cb0695 100644 --- a/lsassy/console.py +++ b/lsassy/console.py @@ -4,7 +4,7 @@ from lsassy import __version__ from lsassy.core import ThreadPool from lsassy.dumper import Dumper -from lsassy.logger import lsassy_logger +from lsassy.logger import lsassy_logger, LsassyLogger import logging @@ -84,6 +84,9 @@ def main(): args = parser.parse_args() + # Handle no_color parameter with logger + lsassy_logger.set_no_color(no_color=args.no_color) + if args.v == 1: lsassy_logger.setLevel(logging.INFO) elif args.v >= 2: diff --git a/lsassy/logger.py b/lsassy/logger.py index 0d3cc5a..8d81943 100644 --- a/lsassy/logger.py +++ b/lsassy/logger.py @@ -3,16 +3,16 @@ class LsassyLogger(logging.LoggerAdapter): - def __init__(self): - super().__init__(self) + def __init__(self, no_color=False): + super().__init__(self, extra=None) self.logger = logging.getLogger("lsassy") self.logger.propagate = False - self.no_color = None + self.no_color = no_color - formatter = LsassyFormatter() - handler = logging.StreamHandler(sys.stdout) - handler.setFormatter(formatter) - self.logger.addHandler(handler) + formatter = LsassyFormatter(no_color=no_color) + self.handler = logging.StreamHandler(sys.stdout) + self.handler.setFormatter(formatter) + self.logger.addHandler(self.handler) def lsassy_highlight(self, msg): """ @@ -24,6 +24,12 @@ def lsassy_highlight(self, msg): return msg return "\033[1;33m{}\033[0m".format(msg) + def set_no_color(self, no_color=False): + self.logger.removeHandler(self.handler) + self.handler = logging.StreamHandler(sys.stdout) + self.handler.setFormatter(LsassyFormatter(no_color=no_color)) + self.logger.addHandler(self.handler) + class LsassyFormatter(logging.Formatter): """ @@ -31,8 +37,9 @@ class LsassyFormatter(logging.Formatter): """ def __init__(self, no_color=False): self.formatter = logging.Formatter.__init__(self, '%(bullet)s %(threadName)s %(message)s', None) - self._no_color = no_color - if not self._no_color: + self.no_color = no_color + self.BLUE, self.WHITE, self.YELLOW, self.RED, self.GREEN, self.NC = '', '', '', '', '', '' + if not self.no_color: self.BLUE = '\033[1;34m' self.WHITE = '\033[1;37m' self.YELLOW = '\033[1;33m' @@ -40,19 +47,6 @@ def __init__(self, no_color=False): self.GREEN = '\033[1;32m' self.NC = '\033[0m' - @property - def no_color(self): - try: - return self._no_color - except AttributeError: - return False - - @no_color.setter - def no_color(self, no_color): - if no_color: - self.BLUE, self.WHITE, self.YELLOW, self.RED, self.GREEN, self.NC = '', '', '', '', '', '' - self._no_color = no_color - def format(self, record): """ Custom bullet formatting with colors diff --git a/lsassy/output/table_output.py b/lsassy/output/table_output.py index 6e79345..a9ba6b0 100644 --- a/lsassy/output/table_output.py +++ b/lsassy/output/table_output.py @@ -40,5 +40,8 @@ def get_output(self): cred["sha1"] if cred["sha1"] is not None else "", "{} - {}".format(cred["ticket"]["domain"], cred["ticket"]["endtime"].strftime("%Y-%m-%d %H:%M")) if cred["ticket"] is not None else "", "{}".format(cred["masterkey"]) if cred["masterkey"] is not None else "") - return table + console = Console() + with console.capture() as capture: + console.print(table) + return capture.get() diff --git a/lsassy/writer.py b/lsassy/writer.py index dd98bbe..fbe94b1 100644 --- a/lsassy/writer.py +++ b/lsassy/writer.py @@ -45,9 +45,7 @@ def write(self, file_format, out_format="pretty", output_file=None, quiet=False, output = self.get_output(out_format, users_only, tickets, masterkeys) if file_format is None: - file_format = out_format file_content = output - else: file_content = self.get_output(file_format, users_only, tickets, masterkeys) diff --git a/pyproject.toml b/pyproject.toml index 7c8d23a..c0bb6ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "lsassy" -version = "3.1.7" +version = "3.1.8" description = "Tool to remotely extract credentials" readme = "README.md" homepage = "https://github.com/hackndo/lsassy" diff --git a/setup.py b/setup.py index 91f9ba2..d8c0210 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="lsassy", - version="3.1.7", + version="3.1.8", author="Pixis", author_email="hackndo@gmail.com", description="Python library to extract credentials from lsass remotely", diff --git a/tests/test_lsassy.py b/tests/test_lsassy.py index 47f4bd1..dc5fb7d 100644 --- a/tests/test_lsassy.py +++ b/tests/test_lsassy.py @@ -2,4 +2,4 @@ def test_version(): - assert __version__ == '3.1.7' + assert __version__ == '3.1.8'