Skip to content

Commit

Permalink
Merge pull request #239 from Pennyw0rth/marshall-version-setting
Browse files Browse the repository at this point in the history
Add git commit to version command
  • Loading branch information
NeffIsBack authored Apr 2, 2024
2 parents da7c507 + 3e3b37f commit 5c249d5
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 22 deletions.
14 changes: 11 additions & 3 deletions nxc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
. .
Expand All @@ -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)")
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions nxc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
17 changes: 2 additions & 15 deletions nxc/netexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -67,29 +66,17 @@ 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:
nxc_logger.add_file_log()
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
Expand Down
48 changes: 46 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand All @@ -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<base>\\d+\\.\\d+\\.\\d+)"
format = "{base}+{commit}"

[tool.ruff]
# Ruff doesn't enable pycodestyle warnings (`W`) or
Expand Down

0 comments on commit 5c249d5

Please sign in to comment.