Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crackmapexec: package refactoring #3490

Merged
merged 1 commit into from
Aug 18, 2022
Merged

crackmapexec: package refactoring #3490

merged 1 commit into from
Aug 18, 2022

Conversation

noraj
Copy link
Contributor

@noraj noraj commented Aug 18, 2022

crackmapexec: package refactoring

  • better pkgver
  • move from setuptools to PEP517
  • remove tons of useless dependencies
  • simplify packaging
  • remove useless patch
  • update upstream repository url

issued faced:

  1. ldapdomaindump module missing because AL version of impacket is outdated and not requiring it while it should
    • fixed by adding the dependency directly to cme
  2. pypsrp module missing

For 2.:

while running cme

Traceback (most recent call last):                                                                                                                                                                                                           
  File "/usr/bin/cme", line 8, in <module>                                                                                                                                                                                                   
    sys.exit(main())                                                                                                                                                                                                                         
  File "/usr/lib/python3.10/site-packages/cme/crackmapexec.py", line 116, in main                                                                                                                                                            
    args = gen_cli_args()                                                                                                                                                                                                                    
  File "/usr/lib/python3.10/site-packages/cme/cli.py", line 72, in gen_cli_args                                                                                                                                                              
    protocol_object = p_loader.load_protocol(protocols[protocol]['path'])                                                                                                                                                                    
  File "/usr/lib/python3.10/site-packages/cme/loaders/protocol_loader.py", line 12, in load_protocol                                                                                                                                         
    protocol = imp.load_source('protocol', protocol_path)                                                                                                                                                                                    
  File "/usr/lib/python3.10/imp.py", line 170, in load_source                                                                                                                                                                                
    module = _exec(spec, sys.modules[name])                                                                                                                                                                                                  
  File "<frozen importlib._bootstrap>", line 619, in _exec
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/cme/protocols/winrm.py", line 12, in <module>
    from pypsrp.client import Client
ModuleNotFoundError: No module named 'pypsrp'

while installing python-pypsrp

WARNING: The directory '/home/noraj/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
Collecting pypsrp==0.7.0
  Downloading pypsrp-0.7.0-py3-none-any.whl (85 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.7/85.7 kB 6.5 MB/s eta 0:00:00
Requirement already satisfied: cryptography in /usr/lib/python3.10/site-packages (from pypsrp==0.7.0) (37.0.4)
Requirement already satisfied: pyspnego<1.0.0 in /usr/lib/python3.10/site-packages (from pypsrp==0.7.0) (0.5.3)
Requirement already satisfied: requests<3.0.0,>=2.9.1 in /usr/lib/python3.10/site-packages (from pypsrp==0.7.0) (2.28.1)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3.10/site-packages (from requests<3.0.0,>=2.9.1->pypsrp==0.7.0) (3.3)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.10/site-packages (from requests<3.0.0,>=2.9.1->pypsrp==0.7.0) (1.26.11)
Requirement already satisfied: cffi>=1.12 in /usr/lib/python3.10/site-packages (from cryptography->pypsrp==0.7.0) (1.15.1)
Requirement already satisfied: pycparser in /usr/lib/python3.10/site-packages (from cffi>=1.12->cryptography->pypsrp==0.7.0) (2.21)
Installing collected packages: pypsrp
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
crackmapexec 5.3.0 requires xmltodict<0.13.0,>=0.12.0, but you have xmltodict 0.13.0 which is incompatible.
Successfully installed pypsrp-0.7.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

There is a conflict with xmltodict which result in pypsrp not being installed, but since python-pypsrp install pypsrp with pip in a .install post install script, the command failing doesn't result in the package not being install, hence we just have a dummy package:

$ pacman -Ql python-pypsrp
python-pypsrp /usr/
python-pypsrp /usr/share/
python-pypsrp /usr/share/doc/
python-pypsrp /usr/share/doc/python-pypsrp/
python-pypsrp /usr/share/doc/python-pypsrp/CHANGELOG.md
python-pypsrp /usr/share/doc/python-pypsrp/LICENSE
python-pypsrp /usr/share/doc/python-pypsrp/README.md

cme package sounds ok, but pypsrp must be fixed (tentative here #3491)

the current version of cme fails due to the same dependency issue

$ cme
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 581, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 909, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 800, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (xmltodict 0.13.0 (/usr/lib/python3.10/site-packages), Requirement.parse('xmltodict<0.13.0,>=0.12.0'), {'crackmapexec'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/cme", line 33, in <module>
    sys.exit(load_entry_point('crackmapexec==5.3.0', 'console_scripts', 'cme')())
  File "/usr/lib/python3.10/site-packages/cme/crackmapexec.py", line 116, in main
    args = gen_cli_args()
  File "/usr/lib/python3.10/site-packages/cme/cli.py", line 72, in gen_cli_args
    protocol_object = p_loader.load_protocol(protocols[protocol]['path'])
  File "/usr/lib/python3.10/site-packages/cme/loaders/protocol_loader.py", line 12, in load_protocol
    protocol = imp.load_source('protocol', protocol_path)
  File "/usr/lib/python3.10/imp.py", line 170, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 619, in _exec
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/cme/protocols/smb.py", line 36, in <module>
    from pywerview.cli.helpers import *
  File "/usr/lib/python3.10/site-packages/pywerview/cli/helpers.py", line 20, in <module>
    from pywerview.functions.net import NetRequester
  File "/usr/lib/python3.10/site-packages/pywerview/functions/net.py", line 30, in <module>
    from pywerview.requester import LDAPRPCRequester
  File "/usr/lib/python3.10/site-packages/pywerview/requester.py", line 40, in <module>
    import pywerview.formatters as fmt
  File "/usr/lib/python3.10/site-packages/pywerview/formatters.py", line 21, in <module>
    from impacket.examples.ntlmrelayx.attacks.ldapattack import MSDS_MANAGEDPASSWORD_BLOB
  File "/usr/lib/python3.10/site-packages/impacket/examples/ntlmrelayx/attacks/__init__.py", line 18, in <module>
    import pkg_resources
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3260, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3234, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3272, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 583, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 596, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 795, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'xmltodict<0.13.0,>=0.12.0' distribution was not found and is required by crackmapexec

@noptrix
Copy link
Contributor

noptrix commented Aug 18, 2022

@noraj thanks for this

@noptrix noptrix merged commit 575e810 into master Aug 18, 2022
@noptrix noptrix deleted the cme/PEP517 branch August 18, 2022 13:52
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