Skip to content

Fix impacket script path resolution order#93

Merged
mkultraWasHere merged 2 commits into
mainfrom
nops/script-path-fix
Jul 14, 2026
Merged

Fix impacket script path resolution order#93
mkultraWasHere merged 2 commits into
mainfrom
nops/script-path-fix

Conversation

@mkultraWasHere

@mkultraWasHere mkultraWasHere commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Root cause of persistent impacket ModuleNotFoundError across multiple agent sessions.

_ensure_impacket_installed() checked import impacket in-process, which could succeed via inherited PYTHONPATH or global site-packages, while sys.executable subprocesses (used by _build_script_command) run in an isolated uv venv where impacket isn't available.

Additionally, _get_impacket_script_path() checked PATH first, finding pip entry point wrappers at ~/.local/bin/ installed for Python 3.13. These wrappers fail when executed with sys.executable (runtime Python 3.12).

Fixed

  • _ensure_impacket_installed() now checks importability via sys.executable subprocess instead of in-process import — matches how scripts are actually executed
  • Script path resolution now checks site-packages/impacket/examples/ first — guaranteed to work with sys.executable since it's the same Python installation
  • PATH-based pip wrappers (~/.local/bin/) demoted to last resort

mkultraWasHere and others added 2 commits July 14, 2026 16:14
Root cause of persistent impacket errors: _get_impacket_script_path()
found pip entry point wrappers at ~/.local/bin/ (installed for Python
3.13) before checking site-packages. These wrappers pass
_is_python_script() but fail when run with sys.executable (runtime
Python 3.12) because they can't import from 3.13's site-packages.

Fix: check site-packages/impacket/examples/ FIRST — these scripts are
guaranteed to work with sys.executable since they live in the same
Python installation that _ensure_impacket_installed() targets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The in-process `import impacket` can succeed via inherited PYTHONPATH
or global site-packages while sys.executable subprocesses fail because
they run in an isolated uv venv. Now checks importability via
subprocess (matching how _build_script_command runs scripts) and also
reorders script path resolution to prefer site-packages over PATH
pip wrappers installed for a different Python version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes persistent ModuleNotFoundError issues when running Impacket example scripts by ensuring script discovery prefers the impacket/examples directory that matches the active sys.executable, rather than accidentally selecting PATH-installed wrappers from a different Python version.

Changes:

  • Updated _ensure_impacket_installed() to verify Impacket importability specifically via a sys.executable subprocess, and to install Impacket into that interpreter when needed.
  • Reordered _get_impacket_script_path() resolution to prefer site-packages/impacket/examples/, then the apt doc examples path, and only then PATH discovery.
  • Refreshed docstrings/log messages to reflect subprocess-based execution and the new resolution order.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mkultraWasHere mkultraWasHere merged commit d93c980 into main Jul 14, 2026
6 checks passed
@mkultraWasHere mkultraWasHere deleted the nops/script-path-fix branch July 14, 2026 20:41
mkultraWasHere added a commit that referenced this pull request Jul 15, 2026
… hack

- Remove target_ip from impacket_atexec and impacket_dcomexec — impacket
  0.13.x doesn't support -target-ip for these two scripts (wmiexec,
  psexec, smbexec do support it).
- Remove OpenSSL legacy provider hack from install script — impacket
  uses pycryptodomex for MD4, not OpenSSL. The MD4 errors are caused by
  the same Python version mismatch (pycryptodomex installed for 3.13,
  runtime is 3.12), which PR #93's auto-install fix addresses.
- Bump to 2.1.4.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mkultraWasHere added a commit that referenced this pull request Jul 15, 2026
* fix(network-ops): remove target_ip from atexec/dcomexec, enable MD4

- Remove target_ip parameter from impacket_atexec and impacket_dcomexec
  — installed impacket 0.13.x doesn't support -target-ip for these
  scripts, causing unrecognized argument errors. Use the IP directly
  as target instead.
- Enable OpenSSL legacy provider in install script for MD4 support —
  fixes "unsupported hash type MD4" errors in rbcd, dacledit, owneredit
  and any NTLM password auth path.
- Bump to 2.1.4.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(network-ops): remove target_ip from atexec/dcomexec, drop OpenSSL hack

- Remove target_ip from impacket_atexec and impacket_dcomexec — impacket
  0.13.x doesn't support -target-ip for these two scripts (wmiexec,
  psexec, smbexec do support it).
- Remove OpenSSL legacy provider hack from install script — impacket
  uses pycryptodomex for MD4, not OpenSSL. The MD4 errors are caused by
  the same Python version mismatch (pycryptodomex installed for 3.13,
  runtime is 3.12), which PR #93's auto-install fix addresses.
- Bump to 2.1.4.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants