Ejemplo n.º 1
0
    def run_rserver_loop(self):
        ""
        try:
            res = select.select([self.rserver_socket.fileno()], [], [], 0.0)
        except (socket.error, ValueError):
            self.logger.log("*** Exception in select() on server socket.\n")
            thread.exit()
        if res[0]:
            try:
                socket_data = self.rserver_socket.recv(4096)
            except Exception as e:
                LOG.exception(e)
                socket_data = ""
                self.logger.log(
                    "*** Exception in remote server recv() happend.\n")

            if not socket_data:
                self.rserver_socket_closed = 1
                self.logger.log(
                    "*** Remote server closed connection. (Server buffer - %d bytes)\n"
                    % len(self.rserver_buffer))
        else:
            socket_data = ""

        if socket_data:
            self.logger_bin_rserver.log(socket_data)

        self.rserver_buffer = self.rserver_buffer + socket_data

        if not self.rserver_head_obj and not self.tunnel_mode:
            self.rserver_head_obj, rest = http_header.extract_server_header(
                self.rserver_buffer)

            # Code for ugly MS response without right delimiter.
            # Just '\015\012' at the end. Then it closes connection.
            if (self.rserver_socket_closed and self.rserver_buffer
                    and (not self.rserver_head_obj)):
                self.rserver_head_obj, rest = http_header.extract_server_header(
                    self.rserver_buffer + "\015\012")
                if self.rserver_head_obj:
                    self.logger.log(
                        "*** There is an bad MS Proxy response header with only one new line at the end in the buffer.\n"
                    )
            # End of code.

            if self.rserver_head_obj:
                self.logger.log("*** Got remote server response header.\n")
                self.rserver_buffer = rest
                self.logger.log("*** Remote server header:\n=====\n" +
                                self.rserver_head_obj.__repr__())
                self.guess_rserver_data_length()

        self.check_rserver_data_length()
Ejemplo n.º 2
0
    def www_connect_rserver(self):
        self.logger.log('*** Connecting to remote server...')
        self.first_run = 0

        # we don't have proxy then we have to connect server by ourselves
        rs, rsp = self.client_head_obj.get_http_server()

        self.logger.log('(%s:%d)...' % (rs, rsp))

        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((rs, rsp))
            self.rserver_socket = s
            self.rserver_socket_closed = 0
            self.current_rserver_net_location = '%s:%d' % (rs, rsp)
            self.logger.log('Done.\n')
        except:
            self.rserver_socket_closed = 1
            self.logger.log('Failed.\n')
            self.exit()
            thread.exit()
        if self.client_head_obj.get_http_method() == 'CONNECT':
            self.logger.log('*** Generating server HTTP response...')
            buffer = 'HTTP/1.1 200 Connection established\015\012\015\012'
            self.rserver_head_obj, rest = http_header.extract_server_header(buffer)
            self.rserver_buffer = rest
            self.guess_rserver_data_length()
            self.logger.log('Done.\n')
Ejemplo n.º 3
0
    def www_connect_rserver(self):
        self.logger.log('*** Connecting to remote server...')
        self.first_run = 0

        # we don't have proxy then we have to connect server by ourselves
        rs, rsp = self.client_head_obj.get_http_server()

        self.logger.log('(%s:%d)...' % (rs, rsp))

        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((rs, rsp))
            self.rserver_socket = s
            self.rserver_socket_closed = 0
            self.current_rserver_net_location = '%s:%d' % (rs, rsp)
            self.logger.log('Done.\n')
        except:
            self.rserver_socket_closed = 1
            self.logger.log('Failed.\n')
            self.exit()
            thread.exit()
        if self.client_head_obj.get_http_method() == 'CONNECT':
            self.logger.log('*** Generating server HTTP response...')
            buffer = 'HTTP/1.1 200 Connection established\015\012\015\012'
            self.rserver_head_obj, rest = http_header.extract_server_header(
                buffer)
            self.rserver_buffer = rest
            self.guess_rserver_data_length()
            self.logger.log('Done.\n')
Ejemplo n.º 4
0
    def run_rserver_loop(self):
        ""
        try:
            #select rserver的socket
            res = select.select([self.rserver_socket.fileno()], [], [], 0.0)
        except (socket.error, ValueError):
            self.logger.log('*** Exception in select() on server socket.\n')
            thread.exit()
        if res[0]:
            try:
                socket_data = self.rserver_socket.recv(8192)
            except:
                socket_data = ''
                self.logger.log('*** Exception in remote server recv() happend.\n')

            if not socket_data:
                self.rserver_socket_closed = 1
                self.logger.log('*** Remote server closed connection. (Server buffer - %d bytes)\n' % len(self.rserver_buffer))
        else:
            socket_data = ''

        if socket_data:
            self.logger_bin_rserver.log(socket_data)

        self.rserver_buffer = self.rserver_buffer + socket_data

        if not self.rserver_head_obj and not self.tunnel_mode:
            self.rserver_head_obj, rest = http_header.extract_server_header(self.rserver_buffer)

            # Code for ugly MS response without right delimiter.
            # Just '\015\012' at the end. Then it closes connection.
            if self.rserver_socket_closed and self.rserver_buffer and (not self.rserver_head_obj):
                self.rserver_head_obj, rest = http_header.extract_server_header(self.rserver_buffer + '\015\012')
                if self.rserver_head_obj:
                    self.logger.log("*** There is an bad MS Proxy response header with only one new line at the end in the buffer.\n")
            # End of code.

            if self.rserver_head_obj:
                self.logger.log("*** Got remote server response header.\n")
                self.rserver_buffer = rest
                self.logger.log('*** Remote server header:\n=====\n' + self.rserver_head_obj.__repr__())
                self.guess_rserver_data_length()

        self.check_rserver_data_length()