diff --git a/nxc/cli.py b/nxc/cli.py index 04f6ddc4c..e16062530 100755 --- a/nxc/cli.py +++ b/nxc/cli.py @@ -9,13 +9,20 @@ from nxc.paths import NXC_PATH from nxc.loaders.protocolloader import ProtocolLoader from nxc.helpers.logger import highlight -from nxc.logger import nxc_logger +from nxc.logger import nxc_logger, setup_debug_logging import importlib.metadata def gen_cli_args(): - VERSION = importlib.metadata.version("netexec") + setup_debug_logging() + + try: + VERSION, COMMIT = importlib.metadata.version("netexec").split("+") + except ValueError: + VERSION = importlib.metadata.version("netexec") + COMMIT = "" CODENAME = "nxc4u" + nxc_logger.debug(f"NXC VERSION: {VERSION} - {CODENAME} - {COMMIT}") parser = argparse.ArgumentParser(description=rf""" . . @@ -34,6 +41,7 @@ def gen_cli_args(): {highlight('Version', 'red')} : {highlight(VERSION)} {highlight('Codename', 'red')}: {highlight(CODENAME)} + {highlight('Commit', 'red')} : {highlight(COMMIT)} """, formatter_class=RawTextHelpFormatter) parser.add_argument("-t", type=int, dest="threads", default=256, help="set how many concurrent threads to use (default: 256)") @@ -95,7 +103,7 @@ def gen_cli_args(): sys.exit(1) if args.version: - print(f"{VERSION} - {CODENAME}") + print(f"{VERSION} - {CODENAME} - {COMMIT}") sys.exit(1) return args diff --git a/nxc/logger.py b/nxc/logger.py index 51862a697..ce8598a37 100755 --- a/nxc/logger.py +++ b/nxc/logger.py @@ -11,8 +11,31 @@ from rich.logging import RichHandler import functools import inspect +import argparse +def parse_debug_args(): + debug_parser = argparse.ArgumentParser(add_help=False) + debug_parser.add_argument("--debug", action="store_true") + debug_parser.add_argument("--verbose", action="store_true") + args, _ = debug_parser.parse_known_args() + return args + +def setup_debug_logging(): + debug_args = parse_debug_args() + root_logger = logging.getLogger("root") + + if debug_args.verbose: + nxc_logger.logger.setLevel(logging.INFO) + root_logger.setLevel(logging.INFO) + elif debug_args.debug: + nxc_logger.logger.setLevel(logging.DEBUG) + root_logger.setLevel(logging.DEBUG) + else: + nxc_logger.logger.setLevel(logging.ERROR) + root_logger.setLevel(logging.ERROR) + + def create_temp_logger(caller_frame, formatted_text, args, kwargs): """Create a temporary logger for emitting a log where we need to override the calling file & line number, since these are obfuscated""" temp_logger = logging.getLogger("temp") @@ -72,6 +95,7 @@ def __init__(self, extra=None): logging.getLogger("pypykatz").disabled = True logging.getLogger("minidump").disabled = True logging.getLogger("lsassy").disabled = True + logging.getLogger("neo4j").setLevel(logging.ERROR) def format(self, msg, *args, **kwargs): # noqa: A003 """Format msg for output diff --git a/nxc/netexec.py b/nxc/netexec.py index 9b15d1cd0..4ff49e6aa 100755 --- a/nxc/netexec.py +++ b/nxc/netexec.py @@ -21,7 +21,6 @@ from os.path import exists from os.path import join as path_join from sys import exit -import logging from rich.progress import Progress import platform @@ -67,20 +66,8 @@ async def start_run(protocol_obj, args, db, targets): def main(): first_run_setup(nxc_logger) - root_logger = logging.getLogger("root") args = gen_cli_args() - if args.verbose: - nxc_logger.logger.setLevel(logging.INFO) - root_logger.setLevel(logging.INFO) - elif args.debug: - nxc_logger.logger.setLevel(logging.DEBUG) - root_logger.setLevel(logging.DEBUG) - else: - nxc_logger.logger.setLevel(logging.ERROR) - root_logger.setLevel(logging.ERROR) - logging.getLogger("neo4j").setLevel(logging.ERROR) - # if these are the same, it might double log to file (two FileHandlers will be added) # but this should never happen by accident if config_log: @@ -88,8 +75,8 @@ def main(): if hasattr(args, "log") and args.log: nxc_logger.add_file_log(args.log) - nxc_logger.debug("PYTHON VERSION: " + sys.version) - nxc_logger.debug("RUNNING ON: " + platform.system() + " Release: " + platform.release()) + nxc_logger.debug(f"PYTHON VERSION: {sys.version}") + nxc_logger.debug(f"RUNNING ON: {platform.system()} Release: {platform.release()}") nxc_logger.debug(f"Passed args: {args}") # FROM HERE ON A PROTOCOL IS REQUIRED diff --git a/poetry.lock b/poetry.lock index 217e53777..a1955562f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aardwolf" @@ -659,6 +659,20 @@ files = [ {file = "dsinternals-1.2.4.tar.gz", hash = "sha256:030f935a70583845f68d6cfc5a22be6ce3300907788ba74faba50d6df859e91d"}, ] +[[package]] +name = "dunamai" +version = "1.19.2" +description = "Dynamic version generation" +optional = false +python-versions = ">=3.5" +files = [ + {file = "dunamai-1.19.2-py3-none-any.whl", hash = "sha256:bc126b17571a44d68ed826cec596e0f61dc01edca8b21486f70014936a5d44f2"}, + {file = "dunamai-1.19.2.tar.gz", hash = "sha256:3be4049890763e19b8df1d52960dbea60b3e263eb0c96144a677ae0633734d2e"}, +] + +[package.dependencies] +packaging = ">=20.9" + [[package]] name = "exceptiongroup" version = "1.2.0" @@ -1495,6 +1509,25 @@ files = [ dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] +[[package]] +name = "poetry-dynamic-versioning" +version = "1.2.0" +description = "Plugin for Poetry to enable dynamic versioning based on VCS tags" +optional = false +python-versions = ">=3.7,<4.0" +files = [ + {file = "poetry_dynamic_versioning-1.2.0-py3-none-any.whl", hash = "sha256:8dbef9728d866eb3d1a4edbb29c7ac8abdf96e3ca659473e950e2c016f3785ec"}, + {file = "poetry_dynamic_versioning-1.2.0.tar.gz", hash = "sha256:1a7bbdba2530499e73dfc6ac0af19de29020ab4aaa3e507573877114e6b71ed6"}, +] + +[package.dependencies] +dunamai = ">=1.18.0,<2.0.0" +jinja2 = ">=2.11.1,<4" +tomlkit = ">=0.4" + +[package.extras] +plugin = ["poetry (>=1.2.0,<2.0.0)"] + [[package]] name = "prompt-toolkit" version = "3.0.43" @@ -2176,6 +2209,17 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "tomlkit" +version = "0.12.4" +description = "Style preserving TOML library" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomlkit-0.12.4-py3-none-any.whl", hash = "sha256:5cd82d48a3dd89dee1f9d64420aa20ae65cfbd00668d6f094d7578a78efbb77b"}, + {file = "tomlkit-0.12.4.tar.gz", hash = "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3"}, +] + [[package]] name = "tqdm" version = "4.66.1" @@ -2307,4 +2351,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.0" -content-hash = "436554c6ea6b8f350b7f30c67cd7cfaff74248995f714804b81cf79f26d79bce" +content-hash = "10aa4808e56fd71b438e074ae1a328290ec06b6e3e674b6cdc7e8bcf7eb9646e" diff --git a/pyproject.toml b/pyproject.toml index 697e775b9..30b01aecb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,6 +63,7 @@ rich = "^13.3.5" python-libnmap = "^0.7.3" argcomplete = "^3.1.4" python-dateutil = ">=2.8.2" +poetry-dynamic-versioning = "^1.2.0" [tool.poetry.group.dev.dependencies] flake8 = "*" @@ -71,8 +72,13 @@ pytest = "^7.2.2" ruff = "=0.0.292" [build-system] -requires = ["poetry-core>=1.2.0"] -build-backend = "poetry.core.masonry.api" +requires = ["poetry-core>=1.2.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"] +build-backend = "poetry_dynamic_versioning.backend" + +[tool.poetry-dynamic-versioning] +enable = true +pattern = "(?P\\d+\\.\\d+\\.\\d+)" +format = "{base}+{commit}" [tool.ruff] # Ruff doesn't enable pycodestyle warnings (`W`) or