0

I need to make use of python's mitmproxy. I have installed it successfully. However when I run mitmproxy command on my terminal it gives me a stack trace like the below :

File "/usr/local/bin/mitmproxy", line 9, in load_entry_point('mitmproxy==0.13', 'console_scripts','mitmproxy'()

File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 558, in load_entry_pointreturn get_distribution(dist).load_entry_point(group, name)

File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 2682, in load_entry_point return ep.load()

File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 2355, in load return self.resolve()

File "/Library/Python/2.7/site-packages/pkg_resources/init.py", line 2361, in resolve module = import(self.module_name, fromlist=['name'], level=0)

File "/Library/Python/2.7/site-packages/libmproxy/main.py", line 7, in from . import version, cmdline

File "/Library/Python/2.7/site-packages/libmproxy/cmdline.py", line 5, in from netlib import http

File "/Library/Python/2.7/site-packages/netlib/http.py", line 7, in from . import odict, utils, tcp, http_status

File "/Library/Python/2.7/site-packages/netlib/tcp.py", line 26, in 'TLSv1.2': SSL.TLSv1_2_METHOD, AttributeError: 'module' object has no attribute 'TLSv1_2_METHOD'

I tried debugging the issue through some Googling and looks like I needed to upgrade my pyOpenSSL.

To know the current version of my PyOpen SSL I did the following on the Python prompt and got the ouptut as shown below to be 0.13:

>>> import OpenSSL
>>> print OpenSSL.__version__
0.13

So I tried upgrading the my pyOpenSSL using the below :

sudo pip install --upgrade pyOpenSSL

ans successfully did so, as when I ran the above again I received the following in the first line of the output :

Requirement already up-to-date: pyOpenSSL in /Library/Python/2.7/site-packages

Just to cross verify I went to the above path and found the PyOpenSSL dir as PyOpenSSL-0.15.1.dist-info. So am guessing PyOpenSSL was actually upgraded to the latest version.

However, when I ran the below on Python prompt again I received the version again as 0.13. Ideally I was expecting it to give the updated version now.

>>> import OpenSSL
>>> print OpenSSL.__version__
0.13

Some blogs suggested that if I have a virtualevn installed, it might interfere with the above. So I uninstalled virtualenv as well using

sudo pip uninstall virtualenv

I am still not able to get mitmproxy running. And when I run mitmproxy, I still get the same error as above.

Please let me know what am I missing and how to get mitmproxy running.

qre0ct
  • 5,680
  • 10
  • 50
  • 86

1 Answers1

0

So it happens yet again. :P I could figure out the problem with the above approach and the solution to it as well on my own - OF COURSE - with the help of some friends and blogs !

So appears that the problem was actually because of MANY out-dated dependencies : -

  • Outdated OpenSSL -

    current version displayed using OpenSSL version -a Awesome help found @ http://javigon.com/2014/04/09/update-openssl-in-osx/ to update OpenSSL and from a friend (https://anantshri.info/) who pointed out the issue itself initially.

  • Outdated pyOpenSSL - upgraded using the below which of course upgraded the same.

    sudo pip install --upgrade pyOpenSSL

  • Then why was the below still showing an outdated version ?

    import OpenSSL
    print OpenSSL.version
    0.13 because there were 2 different OpenSSLs in the system. One that was installed by pip and the other that was by default present in OSX. Again awesome help found @ https://github.com/pyca/pyopenssl/issues/128

some useful commands that helper were :

pip show pyOpenSSL - gives as output : Name: pyOpenSSL
Version: 0.15.1
Location: /Library/Python/2.7/site-packages

as part of the output - indicating that the OpenSSL installed using pip is actually 0.15.1

cross verify using :

ls /Library/Python/2.7/site-packages/ | grep OpenSSL - gives as output:
pyOpenSSL-0.15.1.dist-info

Now the path below also had another copy of OpenSSL :

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL
and cat version.py
in the above dir gave the below as part of output : version = '0.13.1'

indicating that the cause of the issue with the import statement showing the outdated python version.

And the above itself was the root cause for mitmproxy also not working

because mitmproxy was unable to use the latest version on OpenSSL.
So solved the problem by just replacing the OpenSSL in the above path (which was outdated) with the updated one from /Library/Python/2.7/site-packages/

where

cat ./OpenSSL/version.py gave as output (once again just to cross-verify)
version = '0.15.1'

And now the import statement reported the right version of OpenSSL.

Uninstalled mitmproxy using sudo pip uninstall mitmproxy - successfully uninstalled. Also uninstalled virtualenv. (not sure of the above 2 was required !)

Reinstalled mitmproxy as sudo pip install mitmproxy - Successfully done ! And ran mitmproxy now from the terminal wihtout a glitch ! :)

qre0ct
  • 5,680
  • 10
  • 50
  • 86