byt3bl33d3r / CrackMapExec

A swiss army knife for pentesting networks
BSD 2-Clause "Simplified" License
8.37k stars 1.64k forks source link

Port to Python 3 #317

Closed sbrun closed 4 years ago

sbrun commented 5 years ago

Hello, Python 2.x will no longer be supported by their upstream developers in 2020. Thus Debian developers are actively removing Python 2 support in Debian Testing with the goal of getting rid of Python 2 in Debian 11 (bullseye). Kali is tracking Debian Testing and is thus affected by this. You should consider to switch crackmapexec to Python 3.

FWIW this is tracked in https://gitlab.com/kalilinux/packages/crackmapexec/issues/1 on the Kali side.

byt3bl33d3r commented 5 years ago

I am aware, efforts on this have been ongoing for a while I've been getting side tracked with some other projects of mine. Next month (October 2019) will be the official "Port CME to Python3" Month.

mpgn commented 4 years ago

I was ready to do it, but noticed that pywerview is not ported to python3 so I don't see how it is possible to port CME to python3 :'(

mpgn commented 4 years ago

Turns out I started to migrate the project to python3 https://github.com/mpgn/CrackMapExec/tree/python3

Of course, I migrate the pywerview to python3 too.

Here is a preview for tonight !

image

mpgn commented 4 years ago

I'm starting the fire https://github.com/byt3bl33d3r/CrackMapExec/pull/323 :)

byt3bl33d3r commented 4 years ago

Damn, this is crazy. Thanks for the help!

Reelix commented 4 years ago

Tried an install on 3.8 - Failed on https://github.com/dlitz/pycrypto - Which hasn't received a commit in the past 6 years and likely never will :p

mpgn commented 4 years ago

Very strange since CME doesn't use pycrypto anymore https://github.com/byt3bl33d3r/CrackMapExec/commit/333f1c4e06884e85b2776459963ef85d182aba8e ...

rhertzog commented 4 years ago

Hello, what's the current status for the Python 3 port ? It's getting harder for us (Kali) to keep crackmapexec with Python 2, Debian has already dropped the Python 2 version of impacket.

https://www.dlitz.net/software/pycrypto/ is available for Python 3 in Debian/Kali at least, even if it hasn't changed since a long time, its setup.py indicates Python 3 support. There are a couple of patches in the Debian package though: https://sources.debian.org/src/python-crypto/2.6.1-13/debian/patches/

Anyway I don't think that pycrypto should be a blocker.

mpgn commented 4 years ago

Hi @rhertzog CME is already ported to python3, we are waiting for the approval of @byt3bl33d3r to merge into the branch python3 of CME.

The project has also the dependency pywerview (python2 project) https://github.com/the-useless-one/pywerview/pull/34 where I'm also waiting for the PR (we don't even need to be on the master branch) - but this part is not a blocker since we can use my fork of their repo.

More info: https://github.com/byt3bl33d3r/CrackMapExec/pull/323

As for the pycrypto problem, I've tested CME python3 in Kali and I didn't encountered the problem described by Reelix.

rhertzog commented 4 years ago

@mpgn Do you consider both of your PR as ready? If yes, we can already package your forks in Kali until we have proper upstream releases.

mpgn commented 4 years ago

Hello @rhertzog

I've contact directly @byt3bl33d3r and he tells me that he has to deal with other issues first. He didn't forget us, he just has more important priorites :)

Do you consider both of your PR as ready? If yes, we can already package your forks in Kali until we have proper upstream releases.

Not an ideal solution because I'm afraid people will still open issue on this github while the issue maybe related to the python3 CME project. I've hoped the branch be merged even if some features (not related to python3) are missing (gevent over asyncio, only thirdparty with pip) but unfortunately no merge possible I guess.

I've tested to run my PR on latest Kali using this lines and CME is working fine on my side.

git clone --recursive https://github.com/mpgn/CrackMapExec && cd CrackMapExec
git submodule update --recursive
python3 setup.py install
cme
blshkv commented 4 years ago

Hi @mpgn , thanks a lot for taking the initiative. I'm having a minor issue with python3, clould you have a look at the following please:

/usr/bin/python3.6 /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/temp/tmpjti65h7a.py
  File "/usr/lib64/python3.6/site-packages/cme/data/invoke-vnc/vncexec.py", line 235
    print 'Ip addr required for reverse connection'
                                                  ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Ip addr required for reverse connection')?

  File "/usr/lib64/python3.6/site-packages/cme/data/invoke-vnc/gen_buffer.py", line 15
    print res
            ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(res)?

removing /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/temp/tmpjti65h7a.py
writing byte-compilation script '/var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/temp/tmpe5n5gbs4.py'
/usr/bin/python3.6 /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/temp/tmpe5n5gbs4.py
  File "/usr/lib64/python3.6/site-packages/cme/data/invoke-vnc/vncexec.py", line 235
    print 'Ip addr required for reverse connection'
                                                  ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Ip addr required for reverse connection')?

  File "/usr/lib64/python3.6/site-packages/cme/data/invoke-vnc/gen_buffer.py", line 15
    print res
            ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(res)?

removing /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/temp/tmpe5n5gbs4.py
running install_egg_info
Copying crackmapexec.egg-info to /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/image/_python3.6/usr/lib64/python3.6/site-packages/crackmapexec-5.0.0.dev0-py3.6.egg-info
running install_scripts
Installing cme script to /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/image/_python3.6/usr/lib/python-exec/python3.6
Installing cmedb script to /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/image/_python3.6/usr/lib/python-exec/python3.6
Installing crackmapexec script to /var/tmp/portage/net-analyzer/crackmapexec-3.1.5_p20200124/image/_python3.6/usr/lib/python-exec/python3.6
  File "/usr/lib64/python3.6/site-packages/cme/data/invoke-vnc/vncexec.py", line 235
    print 'Ip addr required for reverse connection'
                                                  ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Ip addr required for reverse connection')?

  File "/usr/lib64/python3.6/site-packages/cme/data/invoke-vnc/gen_buffer.py", line 15
    print res
            ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(res)?

 * python3_6: running distutils-r1_run_phase distutils-r1_python_install_all
blshkv commented 4 years ago

There is also one more issue with slinky.py module. It requires pylnk package, however it does not support python3. Update: there is a fork with python3 support: https://github.com/strayge/pylnk/commits/master

mpgn commented 4 years ago

Hello @blshkv I fix the problem in this commit https://github.com/byt3bl33d3r/CrackMapExec/pull/323/commits/6ad97132af7de3d8da23e47900cac39ceb1f71a0

blshkv commented 4 years ago

@mpgn thanks. Can you also fix a bunch of prints which I posted above? Update: all errors are related to the invoke-vnc external module.

mpgn commented 4 years ago

PR submitted to the Invoke-vnc project @blshkv :)

blshkv commented 4 years ago

@mpgn I have merged all patches, managed to install, start and tested some basic functionality. Great job!

mpgn commented 4 years ago

Closing this one since the python3 PR is merged 🖌️

blshkv commented 4 years ago

sorry, I can't find this commit and the merge pull request is still opened

mpgn commented 4 years ago

can you elaborate ?

blshkv commented 4 years ago

I have pulled the latest git version https://github.com/byt3bl33d3r/CrackMapExec.git master, e294a7292435eee7e1f517989b31fdf227522fdf commit and still see the same errors as reported. I can still apply the same patch from the pull request

mpgn commented 4 years ago

I see, I forgot about this one @blshkv but I already take care of the problem. Nevertheless, I cannot do much if no one wants to merge my PR . . .

https://github.com/klsecservices/Invoke-Vnc/pull/2

mpgn commented 4 years ago

We can use my fork in the meantime :)

blshkv commented 4 years ago

Please keep this bug open until someone will find a power to press that damn merge button :-)

byt3bl33d3r commented 4 years ago

@blshkv Just for my clarity, are you getting errors when packaging CME cause of the VNC script thing?

blshkv commented 4 years ago

@byt3bl33d3r hm... I just realized that you have merged https://github.com/byt3bl33d3r/CrackMapExec/pull/323 pull request yesterday. My apologies, this bug can be closed!

These are remaining external modules: https://github.com/klsecservices/Invoke-Vnc/pull/2 https://github.com/the-useless-one/pywerview/issues/36

mpgn commented 4 years ago

This should do the work :)