BlackArch / blackarch

An ArchLinux based distribution for penetration testers and security researchers.
https://www.blackarch.org
Other
2.82k stars 570 forks source link

CME: SyntaxError: multiple exception types must be parenthesized #3509

Closed CarlosSanchizCarrillo closed 2 years ago

CarlosSanchizCarrillo commented 2 years ago

Bug description

When executing CME I have an error related to python syntax

Steps to reproduce

❯ /usr/bin/crackmapexec
Traceback (most recent call last):
  File "/usr/bin/crackmapexec", 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/rdp.py", line 7, in <module>
    from aardwolf.commons.url import RDPConnectionURL
  File "/usr/lib/python3.10/site-packages/aardwolf/commons/url.py", line 6, in <module>
    from aardwolf.commons.authbuilder import AuthenticatorBuilder
  File "/usr/lib/python3.10/site-packages/aardwolf/commons/authbuilder.py", line 9, in <module>
    from aardwolf.authentication.ntlm.native import NTLMAUTHHandler, NTLMHandlerSettings
  File "/usr/lib/python3.10/site-packages/aardwolf/authentication/ntlm/native.py", line 17, in <module>
    from aardwolf.authentication.ntlm.creds_calc import *
  File "/usr/lib/python3.10/site-packages/aardwolf/authentication/ntlm/creds_calc.py", line 3, in <module>
    from unicrypto.symmetric import DES
  File "/usr/lib/python3.10/site-packages/unicrypto/__init__.py", line 45, in <module>
    importlib.util.find_spec(pref_to_module[prefname])
  File "/usr/lib/python3.10/importlib/util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
  File "/usr/lib/python3.10/site-packages/Crypto/Random/__init__.py", line 28, in <module>
    from Crypto.Random import OSRNG
  File "/usr/lib/python3.10/site-packages/Crypto/Random/OSRNG/__init__.py", line 32, in <module>
    from Crypto.Random.OSRNG.posix import new
  File "/usr/lib/python3.10/site-packages/Crypto/Random/OSRNG/posix.py", line 66
    except IOError, e:
           ^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized
CarlosSanchizCarrillo commented 2 years ago

CME is the latest version available on the repos

noraj commented 2 years ago

With the latest version from the repo, I have a different error:

$ /usr/bin/crackmapexec                                                                                                                                                                                                                    
Traceback (most recent call last):
  File "/usr/bin/crackmapexec", 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/rdp.py", line 7, in <module>
    from aardwolf.commons.url import RDPConnectionURL
  File "/usr/lib/python3.10/site-packages/aardwolf/commons/url.py", line 6, in <module>
    from aardwolf.commons.authbuilder import AuthenticatorBuilder
  File "/usr/lib/python3.10/site-packages/aardwolf/commons/authbuilder.py", line 10, in <module>
    from aardwolf.authentication.kerberos.native import RDPKerberos
  File "/usr/lib/python3.10/site-packages/aardwolf/authentication/kerberos/native.py", line 21, in <module>
    from minikerberos.network.aioclientsockssocket import AIOKerberosClientSocksSocket
ModuleNotFoundError: No module named 'minikerberos.network.aioclientsockssocket

BA is using minikerberos 0.3.1 and the latest on pypi is 0.3.1 too.

But the issue is CME is requiring an old version

https://github.com/Porchetta-Industries/CrackMapExec/blob/master/requirements.txt#L38

Same as for #3406, we should move CME pkgbuild to a venv template as there are too many dependencies and too much of them are using old versions or the sub-depencencies are outdated and sub-depencencies authors are not quick to update them.

The issue is happening because many sub-dependencies of CME (from skelsec) are requiring minikerberos 0.2.x instead of 0.3.x but network/aioclientsockssocket.py was removed in the 0.2.20 -> 0.3.0 upgrade. In the meantime I'll try to ping the author to ask him to update minikerberos:

CarlosSanchizCarrillo commented 2 years ago

After adding () to posix.io file on line 66 I got the same error

Traceback (most recent call last): File "/usr/bin/crackmapexec", line 8, in 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 "", line 619, in _exec File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/usr/lib/python3.10/site-packages/cme/protocols/rdp.py", line 7, in from aardwolf.commons.url import RDPConnectionURL File "/usr/lib/python3.10/site-packages/aardwolf/commons/url.py", line 6, in from aardwolf.commons.authbuilder import AuthenticatorBuilder File "/usr/lib/python3.10/site-packages/aardwolf/commons/authbuilder.py", line 10, in from aardwolf.authentication.kerberos.native import RDPKerberos File "/usr/lib/python3.10/site-packages/aardwolf/authentication/kerberos/native.py", line 21, in from minikerberos.network.aioclientsockssocket import AIOKerberosClientSocksSocket ModuleNotFoundError: No module named 'minikerberos.network.aioclientsockssocket'

But I have also installed the minikerberos pkg..

noraj commented 2 years ago

@mpng about locking minikerberos https://github.com/Porchetta-Industries/CrackMapExec/commit/43f49348fad47c3f69c74ceb623cea9bb8e08ae6, is there a way to update to 0.3.1 by patching how rdp is handled?

At BlackArch we had some issues with cme dependencies, because as AL is rolling release we can have only 1 version for each package which is the last version, but cme often locks older versions because of breacking changes that don't have a solution yet. creating version locked PKGBUILD in BA would be way to much work. So I'll guess I'll have to create a custom PKGBUILD with a virtual environment and poetry install inside it. RIP the dependencies duplication but maintaining CME working with system dependency on AL/BA is too much efforts. AL team has to do something similar for metasploit because it has too much dependencies.

Anyway I think I'll do that or do you think that not cutting edge dependency version is an exception or is something that happens often?

If I'm doing the virtual env. I'll have to adapt PKGBUILD-python-standalone and python-standalone.install with poetry because you don't update cme on pypi anymore right?

noraj commented 2 years ago

For people searching for this issue:

$ pacman -Syu
...
error: failed to commit transaction (conflicting files)                                                                                                                                                                                      
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/__init__.py exists in filesystem                                                                                                                                                     
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/_utils.py exists in filesystem                                                                                                                                                       
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/client.py exists in filesystem                                                                                                                                                       
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/complex_objects.py exists in filesystem                                                                                                                                              
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/encryption.py exists in filesystem                                                                                                                                                   
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/exceptions.py exists in filesystem                                                                                                                                                   
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/host.py exists in filesystem                                                                                                                                                         
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/messages.py exists in filesystem                                                                                                                                                     
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/negotiate.py exists in filesystem                                                                                                                                                    
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/powershell.py exists in filesystem                                                                                                                                                   
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/pwsh_scripts/__init__.py exists in filesystem                                                                                                                                        
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/pwsh_scripts/copy.ps1 exists in filesystem                                                                                                                                           
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/pwsh_scripts/fetch.ps1 exists in filesystem                                                                                                                                          
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/serializer.py exists in filesystem                                                                                                                                                   
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/shell.py exists in filesystem                                                                                                                                                        
python-pypsrp: /usr/lib/python3.10/site-packages/pypsrp/wsman.py exists in filesystem                                                                                                                                                        
Errors occurred, no packages were upgraded.

Solution: sudo pacman -Syu --overwrite='/usr/lib/python3.10/site-packages/pypsrp/*'