Esempio n. 1
0
    def return_request_pair(self, request):
        """
        If the request is in scope, it saves the completed request,
        sets the start/end time, mangles the response, saves the
        mangled version, then writes the response back through the
        transport.
        """
        self.end_time = datetime.datetime.utcnow()
        if config.DEBUG_TO_FILE or config.DEBUG_VERBOSITY > 0:
            log_request(printable_data(request.response.full_response), id=self.connection_id, symbol='<m', verbosity_level=3)

        request.time_start = self.start_time
        request.time_end = self.end_time
        if context.in_scope(request):
            mangle_macros = copy.copy(self.intercepting_macros)

            if self.save_all:
                if self.stream_response and not mangle_macros:
                    request.async_deep_save()
                else:
                    yield request.async_deep_save()

            mangled = yield macros.mangle_response(request, mangle_macros)

            if mangled and self.save_all:
                yield request.async_deep_save()

            if request.response and (config.DEBUG_TO_FILE or config.DEBUG_VERBOSITY > 0):
                log_request(printable_data(request.response.full_response),
                            id=self.connection_id, symbol='<', verbosity_level=3)
        else:
            self.log("Response out of scope, passing along unmangled")
        self.data_defer.callback(request)
        defer.returnValue(None)
Esempio n. 2
0
    def return_request_pair(self, request):
        self.end_time = datetime.datetime.now()
        log_request(
            printable_data(request.response.full_response), id=self.connection_id, symbol="<m", verbosity_level=3
        )

        request.time_start = self.start_time
        request.time_end = self.end_time
        if context.in_scope(request):
            to_mangle = copy.copy(self.intercepting_macros).iteritems()
            if self.save_all:
                if self.stream_response and not to_mangle:
                    request.async_deep_save()
                else:
                    yield request.async_deep_save()

            # if we don't copy it, when we delete a macro from the console,
            # we get a crash. We do a shallow copy to keep the macro
            # instances the same.
            old_rsp = request.response
            for k, macro in to_mangle:
                if macro.intercept_responses:
                    if macro.async_rsp:
                        mangled_rsp = yield macro.async_mangle_response(request)
                    else:
                        mangled_rsp = macro.mangle_response(request)

                    if mangled_rsp is None:
                        request.response = None
                        self.data_defer.callback(request)
                        if self.save_all:
                            yield request.async_deep_save()
                        self.log("Response dropped, losing connection")
                        self.transport.loseConnection()
                        defer.returnValue(None)

                    request.response = mangled_rsp

            if request.response != old_rsp:
                request.response.unmangled = old_rsp
                if self.save_all:
                    yield request.async_deep_save()

            if request.response:
                log_request(
                    printable_data(request.response.full_response), id=self.connection_id, symbol="<", verbosity_level=3
                )
        else:
            self.log("Response out of scope, passing along unmangled")
        self.data_defer.callback(request)
        defer.returnValue(None)
Esempio n. 3
0
    def return_request_pair(self, request):
        """
        If the request is in scope, it saves the completed request,
        sets the start/end time, mangles the response, saves the
        mangled version, then calls back data_defer with the mangled
        request
        """
        from pappyproxy.pappy import session

        self.end_time = datetime.datetime.utcnow()
        if session.config.debug_to_file or session.config.debug_verbosity > 0 and request.response:
            log_request(printable_data(request.response.full_response),
                        id=self.connection_id,
                        symbol='<m',
                        verbosity_level=3)

        request.time_start = self.start_time
        request.time_end = self.end_time
        if context.in_scope(request):
            mangle_macros = copy.copy(self.intercepting_macros)

            if self.save_all:
                if self.stream_response and not mangle_macros:
                    request.async_deep_save()
                else:
                    yield request.async_deep_save()

            if request.response:
                mangled = yield macros.mangle_response(request, mangle_macros)

                if mangled and self.save_all:
                    yield request.async_deep_save()

                if request.response and (session.config.debug_to_file or
                                         session.config.debug_verbosity > 0):
                    log_request(printable_data(request.response.full_response),
                                id=self.connection_id,
                                symbol='<',
                                verbosity_level=3)
        else:
            self.log("Response out of scope, passing along unmangled")
        self.data_defer.callback(request)
        defer.returnValue(None)
Esempio n. 4
0
 def rawDataReceived(self, *args, **kwargs):
     data = args[0]
     self.log('Returning data back through stream')
     if not self._response_obj.complete:
         if data:
             if config.DEBUG_TO_FILE or config.DEBUG_VERBOSITY > 0:
                 s = printable_data(data)
                 dlines = s.split('\n')
                 for l in dlines:
                     self.log(l, symbol='<rd', verbosity_level=3)
         self._response_obj.add_data(data)
Esempio n. 5
0
 def rawDataReceived(self, *args, **kwargs):
     data = args[0]
     self.log('Returning data back through stream')
     if not self._response_obj.complete:
         if data:
             if config.DEBUG_TO_FILE or config.DEBUG_VERBOSITY > 0:
                 s = printable_data(data)
                 dlines = s.split('\n')
                 for l in dlines:
                     self.log(l, symbol='<rd', verbosity_level=3)
         self._response_obj.add_data(data)
Esempio n. 6
0
def _code_helper(line, func, copy=True):
    args = shlex.split(line)
    if not args:
        s = clipboard_contents()
        print 'Will decode:'
        print printable_data(s)
        s = func(s)
        if copy:
            try:
                copy_to_clipboard(s)
            except:
                print 'Result cannot be copied to the clipboard. Result not copied.'
        return s
    else:
        s = func(args[0].strip())
        if copy:
            try:
                copy_to_clipboard(s)
            except:
                print 'Result cannot be copied to the clipboard. Result not copied.'
        return s
Esempio n. 7
0
def _code_helper(line, func, copy=True):
    args = shlex.split(line)
    if not args:
        s = clipboard_contents()
        print 'Will decode:'
        print printable_data(s)
        s = func(s)
        if copy:
            try:
                copy_to_clipboard(s)
            except:
                print 'Result cannot be copied to the clipboard. Result not copied.'
        return s
    else:
        s = func(args[0].strip())
        if copy:
            try:
                copy_to_clipboard(s)
            except:
                print 'Result cannot be copied to the clipboard. Result not copied.'
        return s
Esempio n. 8
0
    def return_request_pair(self, request):
        """
        If the request is in scope, it saves the completed request,
        sets the start/end time, mangles the response, saves the
        mangled version, then writes the response back through the
        transport.
        """
        self.end_time = datetime.datetime.utcnow()
        if config.DEBUG_TO_FILE or config.DEBUG_VERBOSITY > 0:
            log_request(printable_data(request.response.full_response),
                        id=self.connection_id,
                        symbol='<m',
                        verbosity_level=3)

        request.time_start = self.start_time
        request.time_end = self.end_time
        if context.in_scope(request):
            mangle_macros = copy.copy(self.intercepting_macros)

            if self.save_all:
                if self.stream_response and not mangle_macros:
                    request.async_deep_save()
                else:
                    yield request.async_deep_save()

            mangled = yield macros.mangle_response(request, mangle_macros)

            if mangled and self.save_all:
                yield request.async_deep_save()

            if request.response and (config.DEBUG_TO_FILE
                                     or config.DEBUG_VERBOSITY > 0):
                log_request(printable_data(request.response.full_response),
                            id=self.connection_id,
                            symbol='<',
                            verbosity_level=3)
        else:
            self.log("Response out of scope, passing along unmangled")
        self.data_defer.callback(request)
        defer.returnValue(None)
Esempio n. 9
0
    def rawDataReceived(self, *args, **kwargs):
        from pappyproxy.pappy import session

        data = args[0]
        self.log('Returning data back through stream')
        if not self._response_obj.complete:
            if data:
                if session.config.debug_to_file or session.config.debug_verbosity > 0:
                    s = printable_data(data)
                    dlines = s.split('\n')
                    for l in dlines:
                        self.log(l, symbol='<rd', verbosity_level=3)
            self._response_obj.add_data(data)
Esempio n. 10
0
    def rawDataReceived(self, *args, **kwargs):
        from pappyproxy.pappy import session

        data = args[0]
        self.log('Returning data back through stream')
        if not self._response_obj.complete:
            if data:
                if session.config.debug_to_file or session.config.debug_verbosity > 0:
                    s = printable_data(data)
                    dlines = s.split('\n')
                    for l in dlines:
                        self.log(l, symbol='<rd', verbosity_level=3)
            self._response_obj.add_data(data)
Esempio n. 11
0
    def return_request_pair(self, request):
        """
        If the request is in scope, it saves the completed request,
        sets the start/end time, mangles the response, saves the
        mangled version, then calls back data_defer with the mangled
        request
        """
        from pappyproxy.pappy import session

        self.end_time = datetime.datetime.utcnow()
        if session.config.debug_to_file or session.config.debug_verbosity > 0 and request.response:
            log_request(printable_data(request.response.full_response), id=self.connection_id, symbol='<m', verbosity_level=3)

        request.time_start = self.start_time
        request.time_end = self.end_time
        if context.in_scope(request):
            mangle_macros = copy.copy(self.intercepting_macros)

            if self.save_all:
                if self.stream_response and not mangle_macros:
                    request.async_deep_save()
                else:
                    yield request.async_deep_save()

            if request.response:
                mangled = yield macros.mangle_response(request, mangle_macros)

                if mangled and self.save_all:
                    yield request.async_deep_save()

                if request.response and (session.config.debug_to_file or session.config.debug_verbosity > 0):
                    log_request(printable_data(request.response.full_response),
                                id=self.connection_id, symbol='<', verbosity_level=3)
        else:
            self.log("Response out of scope, passing along unmangled")
        self.data_defer.callback(request)
        defer.returnValue(None)
Esempio n. 12
0
    def rawDataReceived(self, *args, **kwargs):
        data = args[0]
        self.log("Returning data back through stream")
        if self.factory.stream_response:
            self.factory.return_transport.write(data)
        if not self._response_obj.complete:
            if data:
                s = printable_data(data)
                dlines = s.split("\n")
                for l in dlines:
                    self.log(l, symbol="<rd", verbosity_level=3)
            self._response_obj.add_data(data)

            if self._response_obj.complete:
                self.handle_response_end()