Beispiel #1
0
    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,
                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, exceptions.TcpDisconnect) as e:
            raise PathocError(str(e))
Beispiel #2
0
 def test_with_authentication(self):
     p = self.pathoc()
     with p.connect():
         socks.ClientGreeting(
             socks.VERSION.SOCKS5,
             [socks.METHOD.USERNAME_PASSWORD]
         ).to_file(p.wfile)
         p.wfile.flush()
         f = p.request("get:/p/200")  # the request doesn't matter, error response from handshake will be read anyway.
     assert f.status_code == 502
     assert b"SOCKS5 mode failure" in f.content
     assert b"mitmproxy only supports SOCKS without authentication" in f.content
Beispiel #3
0
    def test_no_connect(self):
        """
        mitmproxy doesn't support UDP or BIND SOCKS CMDs
        """
        p = self.pathoc()
        with p.connect():
            socks.ClientGreeting(
                socks.VERSION.SOCKS5,
                [socks.METHOD.NO_AUTHENTICATION_REQUIRED]).to_file(p.wfile)
            socks.Message(socks.VERSION.SOCKS5, socks.CMD.BIND,
                          socks.ATYP.DOMAINNAME,
                          ("example.com", 8080)).to_file(p.wfile)

            p.wfile.flush()
            p.rfile.read(2)  # read server greeting
            f = p.request(
                "get:/p/200"
            )  # the request doesn't matter, error response from handshake will be read anyway.
        assert f.status_code == 502
        assert b"SOCKS5 mode failure" in f.content