Skip to content

Commit 6971585

Browse files
authored
Merge branch 'main' into patch-1
2 parents d32080e + 051fa81 commit 6971585

36 files changed

Lines changed: 1343 additions & 919 deletions

.github/PULL_REQUEST_TEMPLATE/pull_request_template.md renamed to .github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
---
2-
name: Pull request
3-
about: Update code to fix a bug or add an enhancement/feature
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
8-
---
91
## Description
102

113
Please include a summary of the change and which issue is fixed, or what the enhancement does.

.github/workflows/build-binaries.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [ubuntu-latest, macOS-latest, windows-latest]
13-
python-version: ["3.11"]
13+
python-version: ["3.12"]
1414
#python-version: ["3.8", "3.9", "3.10", "3.11"] # for binary builds we only need one version
1515
steps:
1616
- uses: actions/checkout@v4
@@ -25,13 +25,13 @@ jobs:
2525
pyinstaller netexec.spec
2626
- name: Upload Windows Binary
2727
if: runner.os == 'windows'
28-
uses: actions/upload-artifact@v3
28+
uses: actions/upload-artifact@v4
2929
with:
3030
name: nxc.exe
3131
path: dist/nxc.exe
3232
- name: Upload Nix/OSx Binary
3333
if: runner.os != 'windows'
34-
uses: actions/upload-artifact@v3
34+
uses: actions/upload-artifact@v4
3535
with:
3636
name: nxc-${{ matrix.os }}
3737
path: dist/nxc

.github/workflows/build-zipapps.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [ubuntu-latest, macOS-latest, windows-latest]
13-
python-version: ["3.8", "3.9", "3.10", "3.11"]
13+
python-version: ["3.10", "3.11", "3.12"]
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: NetExec set up python on ${{ matrix.os }}
@@ -22,12 +22,12 @@ jobs:
2222
pip install shiv
2323
python build_collector.py
2424
- name: Upload nxc ZipApp
25-
uses: actions/upload-artifact@v3
25+
uses: actions/upload-artifact@v4
2626
with:
2727
name: nxc-zipapp-${{ matrix.os }}-${{ matrix.python-version }}
2828
path: bin/nxc
2929
- name: Upload nxcdb ZipApp
30-
uses: actions/upload-artifact@v3
30+
uses: actions/upload-artifact@v4
3131
with:
3232
name: nxcdb-zipapp-${{ matrix.os }}-${{ matrix.python-version }}
3333
path: bin/nxcdb

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Python
2020
uses: actions/setup-python@v5
2121
with:
22-
python-version: 3.11
22+
python-version: 3.12
2323
cache: poetry
2424
cache-dependency-path: poetry.lock
2525
- name: Install dependencies with dev group

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
max-parallel: 5
1515
matrix:
1616
os: [ubuntu-latest]
17-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
17+
python-version: ["3.10", "3.11", "3.12"]
1818
steps:
1919
- uses: actions/checkout@v4
2020
- name: Install poetry

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Supported Python versions](https://img.shields.io/badge/python-3.8+-blue.svg)
1+
![Supported Python versions](https://img.shields.io/badge/python-3.10+-blue.svg)
22
[![Twitter](https://img.shields.io/twitter/follow/al3xn3ff?label=al3x_n3ff&style=social)](https://twitter.com/intent/follow?screen_name=al3x_n3ff)
33
[![Twitter](https://img.shields.io/twitter/follow/_zblurx?label=_zblurx&style=social)](https://twitter.com/intent/follow?screen_name=_zblurx)
44
[![Twitter](https://img.shields.io/twitter/follow/MJHallenbeck?label=MJHallenbeck&style=social)](https://twitter.com/intent/follow?screen_name=MJHallenbeck)

nxc/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def proto_flow(self):
229229
else:
230230
self.logger.debug("Created connection object")
231231
self.enum_host_info()
232-
if self.print_host_info() and (self.login() or (self.username == "" and self.password == "")):
232+
self.print_host_info()
233+
if self.login() or (self.username == "" and self.password == ""):
233234
if hasattr(self.args, "module") and self.args.module:
234235
self.load_modules()
235236
self.logger.debug("Calling modules")

nxc/helpers/args.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from argparse import ArgumentDefaultsHelpFormatter, SUPPRESS, OPTIONAL, ZERO_OR_MORE
2+
from argparse import Action
23

34
class DisplayDefaultsNotNone(ArgumentDefaultsHelpFormatter):
45
def _get_help_string(self, action):
@@ -7,4 +8,18 @@ def _get_help_string(self, action):
78
defaulting_nargs = [OPTIONAL, ZERO_OR_MORE]
89
if (action.option_strings or action.nargs in defaulting_nargs) and action.default: # Only add default info if it's not None
910
help_string += " (default: %(default)s)" # NORUFF
10-
return help_string
11+
return help_string
12+
13+
14+
class DefaultTrackingAction(Action):
15+
def __init__(self, option_strings, dest, default=None, required=False, **kwargs):
16+
# Store the default value to check later
17+
self.default_value = default
18+
super().__init__(
19+
option_strings, dest, default=default, required=required, **kwargs
20+
)
21+
22+
def __call__(self, parser, namespace, values, option_string=None):
23+
# Set an attribute to track whether the value was explicitly set
24+
setattr(namespace, self.dest, values)
25+
setattr(namespace, f"{self.dest}_explicitly_set", True)

nxc/logger.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from logging.handlers import RotatingFileHandler
44
import os.path
55
import sys
6-
import re
76
from nxc.console import nxc_console
87
from nxc.paths import NXC_PATH
98
from termcolor import colored
@@ -43,7 +42,7 @@ def create_temp_logger(caller_frame, formatted_text, args, kwargs):
4342
temp_logger = logging.getLogger("temp")
4443
formatter = logging.Formatter("%(message)s", datefmt="[%X]")
4544
handler = SmartDebugRichHandler(formatter=formatter)
46-
handler.handle(LogRecord(temp_logger.name, logging.INFO, caller_frame.f_code.co_filename, caller_frame.f_lineno, formatted_text, args, kwargs, caller_frame=caller_frame))
45+
handler.handle(LogRecord(temp_logger.name, logging.INFO, caller_frame.f_code.co_filename, caller_frame.f_lineno, formatted_text, args, None, caller_frame=caller_frame))
4746

4847

4948
class SmartDebugRichHandler(RichHandler):
@@ -56,9 +55,6 @@ def __init__(self, formatter=None, *args, **kwargs):
5655

5756
def emit(self, record):
5857
"""Overrides the emit method of the RichHandler class so we can set the proper pathname and lineno"""
59-
# for some reason in RDP, the exc_text is None which leads to a KeyError in Python logging
60-
record.exc_text = record.getMessage() if record.exc_text is None else record.exc_text
61-
6258
if hasattr(record, "caller_frame"):
6359
frame_info = inspect.getframeinfo(record.caller_frame)
6460
record.pathname = frame_info.filename
@@ -93,6 +89,7 @@ def __init__(self, extra=None):
9389
rich_tracebacks=True,
9490
tracebacks_show_locals=False
9591
)],
92+
encoding="utf-8"
9693
)
9794
self.logger = logging.getLogger("nxc")
9895
self.extra = extra
@@ -176,7 +173,7 @@ def log_console_to_file(self, text, *args, **kwargs):
176173
self.logger.fail(f"Issue while trying to custom print handler: {e}")
177174

178175
def add_file_log(self, log_file=None):
179-
file_formatter = TermEscapeCodeFormatter("%(asctime)s | %(filename)s:%(lineno)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
176+
file_formatter = logging.Formatter("%(asctime)s | %(filename)s:%(lineno)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
180177
output_file = self.init_log_file() if log_file is None else log_file
181178
file_creation = False
182179

@@ -208,17 +205,5 @@ def init_log_file():
208205
)
209206

210207

211-
class TermEscapeCodeFormatter(logging.Formatter):
212-
"""A class to strip the escape codes for logging to files"""
213-
214-
def __init__(self, fmt=None, datefmt=None, style="%", validate=True):
215-
super().__init__(fmt, datefmt, style, validate)
216-
217-
def format(self, record): # noqa: A003
218-
escape_re = re.compile(r"\x1b\[[0-9;]*m")
219-
record.msg = re.sub(escape_re, "", str(record.msg))
220-
return super().format(record)
221-
222-
223208
# initialize the logger for all of nxc - this is imported everywhere
224209
nxc_logger = NXCAdapter()

nxc/modules/daclread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def search_target_principal_security_descriptor(self, context, connection):
373373
if self.target_DN is not None:
374374
_lookedup_principal = self.target_DN
375375
target = self.ldap_session.search(
376-
searchBase=self.baseDN,
376+
searchBase=_lookedup_principal,
377377
searchFilter=f"(distinguishedName={_lookedup_principal})",
378378
attributes=["nTSecurityDescriptor"],
379379
searchControls=controls,

0 commit comments

Comments
 (0)