diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-07-03 02:48:35 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-07-03 02:48:35 +0200 |
commit | 4ef83d8c114a5359b0fc26c3c13753022943a4c5 (patch) | |
tree | 4ce7bb28e60d6dd78582c63c2ed2f44879ba39d5 /libpathod/pathoc.py | |
parent | 4407508e0ce971b03358877844d409e16b244562 (diff) | |
download | mitmproxy-4ef83d8c114a5359b0fc26c3c13753022943a4c5.tar.gz mitmproxy-4ef83d8c114a5359b0fc26c3c13753022943a4c5.tar.bz2 mitmproxy-4ef83d8c114a5359b0fc26c3c13753022943a4c5.zip |
pathoc: add socks connect
Diffstat (limited to 'libpathod/pathoc.py')
-rw-r--r-- | libpathod/pathoc.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 4a2ac5cd..39d3c3d6 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -11,7 +11,7 @@ import threading import OpenSSL.crypto -from netlib import tcp, http, http2, certutils, websockets +from netlib import tcp, http, http2, certutils, websockets, socks import language.http import language.websockets @@ -254,6 +254,39 @@ class Pathoc(tcp.TCPClient): ) http.read_headers(self.rfile) + def socks_connect(self, connect_to): + try: + client_greet = socks.ClientGreeting(socks.VERSION.SOCKS5, [socks.METHOD.NO_AUTHENTICATION_REQUIRED]) + client_greet.to_file(self.wfile) + self.wfile.flush() + + server_greet = socks.ServerGreeting.from_file(self.rfile) + server_greet.assert_socks5() + if server_greet.method != socks.METHOD.NO_AUTHENTICATION_REQUIRED: + raise socks.SocksError( + socks.METHOD.NO_ACCEPTABLE_METHODS, + "pathoc only supports SOCKS without authentication" + ) + + connect_request = socks.Message( + socks.VERSION.SOCKS5, + socks.CMD.CONNECT, + socks.ATYP.DOMAINNAME, + tcp.Address.wrap(connect_to) + ) + connect_request.to_file(self.wfile) + self.wfile.flush() + + connect_reply = socks.Message.from_file(self.rfile) + connect_reply.assert_socks5() + if connect_reply.msg != socks.REP.SUCCEEDED: + raise socks.SocksError( + connect_reply.msg, + "SOCKS server error" + ) + except (socks.SocksError, tcp.NetLibDisconnect) as e: + raise PathocError(str(e)) + def connect(self, connect_to=None, showssl=False, fp=sys.stdout): """ connect_to: A (host, port) tuple, which will be connected to with |