Python 2 is deprecated and you should no longer use it. However, many older tools (especially hacking and pentesting tools) are written in Python 2 and have not yet been or will never be updated to Python 3. So, until new tools have replaced the old ones in the year 9001, we need a way to run the old tools on an otherwise current Linux distribution.
There's an official guide by Offensive Security. Follow it to install pyenv
: https://www.kali.org/docs/general-use/using-eol-python-versions/
I was able to set up pyenv
with the official guidance mentioned above. However, I was still not able to get exploit 42315.py
to work because I somehow couldn't install the impacket
dependency. Fortunately, after some Google-fu I found the following commands in the thread of a related Github issue:
$ pip2 install --upgrade setuptools
$ pip2 install --upgrade pip
Make sure to set your environment to Python 2.7.18 before running these commands (see official guidance above). Also make sure to first install pip2
:
$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo python2 get-pip.py
Now, you should be able to successfully install the Python 2 version of impacket
:
$ pip2 install impacket
...
Collecting impacket
...
Successfully installed Jinja2-2.11.3 MarkupSafe-1.1.1 Werkzeug-1.0.1 chardet-4.0.0 click-7.1.2 cryptography-3.3.2 dnspython-1.16.0 enum34-1.1.10 flask-1.1.4 future-0.18.2 impacket-0.9.23 ipaddress-1.0.23 itsdangerous-1.1.0 ldap3-2.9.1 ldapdomaindump-0.9.3 pyOpenSSL-20.0.1 pyasn1-0.4.8 pycryptodomex-3.10.1 six-1.16.0
Some modules such as pycrypto
require development dependencies. You can install them with:
$ sudo apt install python2-dev
By the way, to make 42315.py work, you additionally need mysmb.py
:
wget https://raw.githubusercontent.com/worawit/MS17-010/master/mysmb.py