Skip to content

Commit 5c249d5

Browse files
authored
Merge pull request Pennyw0rth#239 from Pennyw0rth/marshall-version-setting
Add git commit to version command
2 parents da7c507 + 3e3b37f commit 5c249d5

5 files changed

Lines changed: 91 additions & 22 deletions

File tree

nxc/cli.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
from nxc.paths import NXC_PATH
1010
from nxc.loaders.protocolloader import ProtocolLoader
1111
from nxc.helpers.logger import highlight
12-
from nxc.logger import nxc_logger
12+
from nxc.logger import nxc_logger, setup_debug_logging
1313
import importlib.metadata
1414

1515

1616
def gen_cli_args():
17-
VERSION = importlib.metadata.version("netexec")
17+
setup_debug_logging()
18+
19+
try:
20+
VERSION, COMMIT = importlib.metadata.version("netexec").split("+")
21+
except ValueError:
22+
VERSION = importlib.metadata.version("netexec")
23+
COMMIT = ""
1824
CODENAME = "nxc4u"
25+
nxc_logger.debug(f"NXC VERSION: {VERSION} - {CODENAME} - {COMMIT}")
1926

2027
parser = argparse.ArgumentParser(description=rf"""
2128
. .
@@ -34,6 +41,7 @@ def gen_cli_args():
3441
3542
{highlight('Version', 'red')} : {highlight(VERSION)}
3643
{highlight('Codename', 'red')}: {highlight(CODENAME)}
44+
{highlight('Commit', 'red')} : {highlight(COMMIT)}
3745
""", formatter_class=RawTextHelpFormatter)
3846

3947
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():
95103
sys.exit(1)
96104

97105
if args.version:
98-
print(f"{VERSION} - {CODENAME}")
106+
print(f"{VERSION} - {CODENAME} - {COMMIT}")
99107
sys.exit(1)
100108

101109
return args

nxc/logger.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,31 @@
1111
from rich.logging import RichHandler
1212
import functools
1313
import inspect
14+
import argparse
1415

1516

17+
def parse_debug_args():
18+
debug_parser = argparse.ArgumentParser(add_help=False)
19+
debug_parser.add_argument("--debug", action="store_true")
20+
debug_parser.add_argument("--verbose", action="store_true")
21+
args, _ = debug_parser.parse_known_args()
22+
return args
23+
24+
def setup_debug_logging():
25+
debug_args = parse_debug_args()
26+
root_logger = logging.getLogger("root")
27+
28+
if debug_args.verbose:
29+
nxc_logger.logger.setLevel(logging.INFO)
30+
root_logger.setLevel(logging.INFO)
31+
elif debug_args.debug:
32+
nxc_logger.logger.setLevel(logging.DEBUG)
33+
root_logger.setLevel(logging.DEBUG)
34+
else:
35+
nxc_logger.logger.setLevel(logging.ERROR)
36+
root_logger.setLevel(logging.ERROR)
37+
38+
1639
def create_temp_logger(caller_frame, formatted_text, args, kwargs):
1740
"""Create a temporary logger for emitting a log where we need to override the calling file & line number, since these are obfuscated"""
1841
temp_logger = logging.getLogger("temp")
@@ -72,6 +95,7 @@ def __init__(self, extra=None):
7295
logging.getLogger("pypykatz").disabled = True
7396
logging.getLogger("minidump").disabled = True
7497
logging.getLogger("lsassy").disabled = True
98+
logging.getLogger("neo4j").setLevel(logging.ERROR)
7599

76100
def format(self, msg, *args, **kwargs): # noqa: A003
77101
"""Format msg for output

nxc/netexec.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from os.path import exists
2222
from os.path import join as path_join
2323
from sys import exit
24-
import logging
2524
from rich.progress import Progress
2625
import platform
2726

@@ -67,29 +66,17 @@ async def start_run(protocol_obj, args, db, targets):
6766

6867
def main():
6968
first_run_setup(nxc_logger)
70-
root_logger = logging.getLogger("root")
7169
args = gen_cli_args()
7270

73-
if args.verbose:
74-
nxc_logger.logger.setLevel(logging.INFO)
75-
root_logger.setLevel(logging.INFO)
76-
elif args.debug:
77-
nxc_logger.logger.setLevel(logging.DEBUG)
78-
root_logger.setLevel(logging.DEBUG)
79-
else:
80-
nxc_logger.logger.setLevel(logging.ERROR)
81-
root_logger.setLevel(logging.ERROR)
82-
logging.getLogger("neo4j").setLevel(logging.ERROR)
83-
8471
# if these are the same, it might double log to file (two FileHandlers will be added)
8572
# but this should never happen by accident
8673
if config_log:
8774
nxc_logger.add_file_log()
8875
if hasattr(args, "log") and args.log:
8976
nxc_logger.add_file_log(args.log)
9077

91-
nxc_logger.debug("PYTHON VERSION: " + sys.version)
92-
nxc_logger.debug("RUNNING ON: " + platform.system() + " Release: " + platform.release())
78+
nxc_logger.debug(f"PYTHON VERSION: {sys.version}")
79+
nxc_logger.debug(f"RUNNING ON: {platform.system()} Release: {platform.release()}")
9380
nxc_logger.debug(f"Passed args: {args}")
9481

9582
# FROM HERE ON A PROTOCOL IS REQUIRED

poetry.lock

Lines changed: 46 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ rich = "^13.3.5"
6363
python-libnmap = "^0.7.3"
6464
argcomplete = "^3.1.4"
6565
python-dateutil = ">=2.8.2"
66+
poetry-dynamic-versioning = "^1.2.0"
6667

6768
[tool.poetry.group.dev.dependencies]
6869
flake8 = "*"
@@ -71,8 +72,13 @@ pytest = "^7.2.2"
7172
ruff = "=0.0.292"
7273

7374
[build-system]
74-
requires = ["poetry-core>=1.2.0"]
75-
build-backend = "poetry.core.masonry.api"
75+
requires = ["poetry-core>=1.2.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
76+
build-backend = "poetry_dynamic_versioning.backend"
77+
78+
[tool.poetry-dynamic-versioning]
79+
enable = true
80+
pattern = "(?P<base>\\d+\\.\\d+\\.\\d+)"
81+
format = "{base}+{commit}"
7682

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

0 commit comments

Comments
 (0)