{ "info": { "author": "Nadeem Douba", "author_email": "ndouba@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "A small and sweet man-in-the-middle proxy capable of doing HTTP and HTTP over SSL.\r\n\r\n\r\nIntroduction\r\n============\r\n\r\npymiproxy is a small, lightweight, man-in-the-middle proxy capable of performing HTTP and HTTPS (or SSL) inspection. The\r\nproxy provides a built-in certificate authority that is capable of generating certificates for SSL-based destinations.\r\nPymiproxy is also extensible and provides two methods for extending the proxy: method overloading, and a pluggable\r\ninterface. It is ideal for situations where you're in dire need of a cool proxy to tamper with out- and/or in-bound HTTP\r\ndata.\r\n\r\nInstallation Requirements\r\n=========================\r\n\r\nThe following modules are required:\r\n\r\n- pyOpenSSL\r\n\r\n\r\nInstallation\r\n============\r\n\r\nJust run the following command at the command prompt:\r\n\r\n $ sudo python setup.py install\r\n\r\n\r\nUsage\r\n=====\r\n\r\nThe module offers a few examples in the code. In brief, pymiproxy can be run right-away by issuing the following command\r\nat the the command-prompt:\r\n\r\n $ python -m miproxy.proxy\r\n\r\nThis will invoke pymiproxy with the *DebugInterceptor* plugin which simply outputs the first 100 bytes of each request\r\nand response. The proxy runs on port 8080 and listens on all addresses. Go ahead and give it a try.\r\n\r\n===================================\r\nExtending or Implementing pymiproxy\r\n===================================\r\n\r\nThere are two ways of extending the proxy:\r\n\r\n\r\n- Develop and register an Interceptor plugin; or\r\n- Overload the mitm_request, and mitm_response methods in the ProxyHandler class.\r\n\r\n\r\nThe decision on which method you choose to use is entirely dependant on whether or not you wish to push the data being\r\nintercepted through a set of interceptors or not.\r\n\r\n-------------------\r\nInterceptor Plugins\r\n-------------------\r\n\r\nThere are currently two types of interceptor plugins:\r\n\r\n- RequestInterceptorPlugins: executed prior to sending the request to the remote server; and\r\n- ResponseInterceptorPlugins: executed prior to sending the response back to the client.\r\n\r\nThe following flow is taken by pymiproxy in this mode:\r\n\r\n1. Client request received\r\n2. Client request parsed\r\n3. Client request processed/transformed by Request Interceptor plugins\r\n4. Updated request sent to remote server\r\n5. Response received by remote server\r\n6. Response processed/transformed by Response Interceptor plugins\r\n7. Updated response sent to client\r\n\r\nYou can register as many plugins as you wish. However, keep in mind that plugins are executed in the order that they are\r\nregistered in. Take care in how you register your plugins if the result of one plugin is dependent on the result of\r\nanother.\r\n\r\nThe following is a simple code example of how to run the proxy with plugins:\r\n\r\n from miproxy.proxy import RequestInterceptorPlugin, ResponseInterceptorPlugin, AsyncMitmProxy\r\n\r\n class DebugInterceptor(RequestInterceptorPlugin, ResponseInterceptorPlugin):\r\n\r\n def do_request(self, data):\r\n print '>> %s' % repr(data[:100])\r\n return data\r\n\r\n def do_response(self, data):\r\n print '<< %s' % repr(data[:100])\r\n return data\r\n\r\n\r\n if __name__ == '__main__':\r\n proxy = None\r\n if not argv[1:]:\r\n proxy = AsyncMitmProxy()\r\n else:\r\n proxy = AsyncMitmProxy(ca_file=argv[1])\r\n proxy.register_interceptor(DebugInterceptor)\r\n try:\r\n proxy.serve_forever()\r\n except KeyboardInterrupt:\r\n proxy.server_close()\r\n\r\n\r\n------------------\r\nMethod Overloading\r\n------------------\r\n\r\nThe alternate approach to extending the proxy functionality is to subclass the ProxyHandler class and overload the\r\nmitm_request and mitm_response methods. The following is a quick example:\r\n\r\n from miproxy.proxy import AsyncMitmProxy\r\n\r\n class MitmProxyHandler(ProxyHandler):\r\n\r\n def mitm_request(self, data):\r\n print '>> %s' % repr(data[:100])\r\n return data\r\n\r\n def mitm_response(self, data):\r\n print '<< %s' % repr(data[:100])\r\n return data\r\n\r\n\r\n if __name__ == '__main__':\r\n proxy = None\r\n if not argv[1:]:\r\n proxy = AsyncMitmProxy(RequestHandlerClass=MitmProxyHandler)\r\n else:\r\n proxy = AsyncMitmProxy(RequestHandlerClass=MitmProxyHandler, ca_file=argv[1])\r\n try:\r\n proxy.serve_forever()\r\n except KeyboardInterrupt:\r\n proxy.server_close()\r\n\r\nNote: In both cases, the methods that process the data need to return the data back to the proxy handler. Otherwise,\r\nyou'll get an exception.\r\n\r\nKudos\r\n=====\r\n\r\nThanks to the great documentation at python.org, GnuCitizen's PDP for the ideas, the pyOpenSSL group for making a great OpenSSL API.", "description_content_type": null, "docs_url": null, "download_url": "http://pypi.canariproject.com/pymiproxy/pymiproxy-1.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/allfro/pymiproxy/", "keywords": "", "license": "GPL", "maintainer": "", "maintainer_email": "", "name": "pymiproxy", "package_url": "https://pypi.org/project/pymiproxy/", "platform": "", "project_url": "https://pypi.org/project/pymiproxy/", "project_urls": { "Download": "http://pypi.canariproject.com/pymiproxy/pymiproxy-1.0.tar.gz", "Homepage": "https://github.com/allfro/pymiproxy/" }, "release_url": "https://pypi.org/project/pymiproxy/1.0/", "requires_dist": null, "requires_python": null, "summary": "Micro Interceptor Proxy - a simple MITM HTTP/S proxy", "version": "1.0" }, "last_serial": 2087822, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "0691153e788d0b6ad44e74354d946358", "sha256": "64104db1b0652b6114a633709c5550e1c1da6db9218bb2b76894d3cb60380275" }, "downloads": -1, "filename": "pymiproxy-1.0.tar.gz", "has_sig": false, "md5_digest": "0691153e788d0b6ad44e74354d946358", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5715, "upload_time": "2016-04-28T00:55:54", "url": "https://files.pythonhosted.org/packages/66/9f/e35aa0b97ba4bd8cbe76259680be0fc3bc39cfab0469e48c6a5294e87d99/pymiproxy-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0691153e788d0b6ad44e74354d946358", "sha256": "64104db1b0652b6114a633709c5550e1c1da6db9218bb2b76894d3cb60380275" }, "downloads": -1, "filename": "pymiproxy-1.0.tar.gz", "has_sig": false, "md5_digest": "0691153e788d0b6ad44e74354d946358", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5715, "upload_time": "2016-04-28T00:55:54", "url": "https://files.pythonhosted.org/packages/66/9f/e35aa0b97ba4bd8cbe76259680be0fc3bc39cfab0469e48c6a5294e87d99/pymiproxy-1.0.tar.gz" } ] }