Example #1
0
    def _handle_send_success(self, req, res, grep, original_url,
                             original_url_inst, start_time):
        '''
        Handle the case in "def _send" where the request was successful and
        we were able to get a valid HTTP response.
        
        :return: An HTTPResponse object.
        '''
        # Everything went well!
        rdata = req.get_data()
        if not rdata:
            msg = ('%s %s returned HTTP code "%s"' %
                   (req.get_method(),
                    urllib.unquote_plus(original_url),
                    res.code))
        else:
            printable_data = urllib.unquote_plus(rdata)
            if len(rdata) > 75:
                printable_data = '%s...' % printable_data[:75]
                printable_data = printable_data.replace('\n', ' ')
                printable_data = printable_data.replace('\r', ' ')
                
            msg = ('%s %s with data: "%s" returned HTTP code "%s"'
                   % (
                      req.get_method(),
                      original_url,
                      printable_data,
                      res.code)
                     )

        from_cache = hasattr(res, 'from_cache')
        flags = ' (id=%s,from_cache=%i,grep=%i)' % (res.id, from_cache,
                                                    grep)
        msg += flags
        om.out.debug(msg)

        http_resp = HTTPResponse.from_httplib_resp(res,
                                                   original_url=original_url_inst)
        http_resp.set_id(res.id)
        http_resp.set_wait_time(time.time() - start_time)

        # Clear the log of failed requests; this request is DONE!
        req_id = id(req)
        if req_id in self._error_count:
            del self._error_count[req_id]
        self._zero_global_error_count()

        if grep:
            self._grep(req, http_resp)

        return http_resp
Example #2
0
    def log_req_resp(request, response):
        '''
        Send the request and the response to the output manager.
        '''
        if not isinstance(response, HTTPResponse):
            url = request.url_object
            resp = HTTPResponse.from_httplib_resp(response,
                                                  original_url=url)
            resp.set_id(response.id)

        if not isinstance(request, HTTPRequest):
            msg = 'There is something odd going on in LogHandler,'\
                  ' request should be of type HTTPRequest got %s'\
                  ' instead.'
            raise TypeError(msg % type(request))

        om.out.log_http(request, resp)
Example #3
0
    def _log_req_resp(self, request, response):
        '''
        Send the request and the response to the output manager.
        '''
        if not isinstance(response, HTTPResponse):
            url = request.url_object
            resp = HTTPResponse.from_httplib_resp(response, original_url=url)
            resp.set_id(response.id)
        else:
            resp = response

        if not isinstance(request, HTTPRequest):
            msg = 'There is something odd going on in OutputManagerHandler,'\
                  ' request should be of type HTTPRequest got %s'\
                  ' instead.'
            raise TypeError(msg % type(request))

        om.out.log_http(request, resp)
Example #4
0
    def _handle_send_success(self, req, res, grep, original_url,
                             original_url_inst, start_time):
        '''
        Handle the case in "def _send" where the request was successful and
        we were able to get a valid HTTP response.
        
        :return: An HTTPResponse object.
        '''
        # Everything went well!
        rdata = req.get_data()
        if not rdata:
            msg = ('%s %s returned HTTP code "%s"' %
                   (req.get_method(), urllib.unquote_plus(original_url),
                    res.code))
        else:
            printable_data = urllib.unquote_plus(rdata)
            if len(rdata) > 75:
                printable_data = '%s...' % printable_data[:75]
                printable_data = printable_data.replace('\n', ' ')
                printable_data = printable_data.replace('\r', ' ')

            msg = ('%s %s with data: "%s" returned HTTP code "%s"' %
                   (req.get_method(), original_url, printable_data, res.code))

        from_cache = hasattr(res, 'from_cache')
        flags = ' (id=%s,from_cache=%i,grep=%i)' % (res.id, from_cache, grep)
        msg += flags
        om.out.debug(msg)

        http_resp = HTTPResponse.from_httplib_resp(
            res, original_url=original_url_inst)
        http_resp.set_id(res.id)
        http_resp.set_wait_time(time.time() - start_time)

        # Clear the log of failed requests; this request is DONE!
        req_id = id(req)
        if req_id in self._error_count:
            del self._error_count[req_id]
        self._zero_global_error_count()

        if grep:
            self._grep(req, http_resp)

        return http_resp
Example #5
0
    def store_in_cache(request, response):
        # Create the http response object
        resp = HTTPResponse.from_httplib_resp(response,
                                              original_url=request.url_object)
        resp.set_id(response.id)
        resp.set_alias(gen_hash(request))

        hi = HistoryItem()
        hi.request = request
        hi.response = resp

        # Now save them
        try:
            hi.save()
        except sqlite3.Error, e:
            msg = 'A sqlite3 error was raised: "%s".' % e
            
            if 'disk' in str(e).lower():
                msg += ' Please check if your disk is full.'
                
            raise w3afMustStopException(msg)
Example #6
0
File: db.py Project: weisst/w3af
    def store_in_cache(request, response):
        # Create the http response object
        resp = HTTPResponse.from_httplib_resp(response,
                                              original_url=request.url_object)
        resp.set_id(response.id)
        resp.set_alias(gen_hash(request))

        hi = HistoryItem()
        hi.request = request
        hi.response = resp

        # Now save them
        try:
            hi.save()
        except sqlite3.Error, e:
            msg = 'A sqlite3 error was raised: "%s".' % e

            if 'disk' in str(e).lower():
                msg += ' Please check if your disk is full.'

            raise w3afMustStopException(msg)
Example #7
0
    def store_in_cache(request, response):
        # Create the http response object
        resp = HTTPResponse.from_httplib_resp(response, original_url=request.url_object)
        resp.set_id(response.id)
        resp.set_alias(gen_hash(request))

        hi = HistoryItem()
        hi.request = request
        hi.response = resp

        # Now save them
        try:
            hi.save()
        except Exception, ex:
            msg = (
                "Exception while inserting request/response to the"
                " database: %s\nThe request/response that generated"
                " the error is: %s %s %s" % (ex, resp.get_id(), request.get_uri(), resp.get_code())
            )
            om.out.error(msg)
            raise Exception(msg)
Example #8
0
    def store_in_cache(request, response):
        # Create the http response object
        resp = HTTPResponse.from_httplib_resp(response,
                                              original_url=request.url_object)
        resp.set_id(response.id)
        resp.set_alias(gen_hash(request))

        hi = HistoryItem()
        hi.request = request
        hi.response = resp

        # Now save them
        try:
            hi.save()
        except Exception, ex:
            msg = ('Exception while inserting request/response to the'
                   ' database: %s\nThe request/response that generated'
                   ' the error is: %s %s %s' %
                   (ex, resp.get_id(), request.get_uri(), resp.get_code()))
            om.out.error(msg)
            raise
Example #9
0
                    
                msg = ('%s %s with data: "%s" returned HTTP code "%s"'
                       % (
                          req.get_method(),
                          original_url,
                          printable_data,
                          res.code)
                         )

            from_cache = hasattr(res, 'from_cache')
            flags = ' (id=%s,from_cache=%i,grep=%i)' % (res.id, from_cache,
                                                        grep)
            msg += flags
            om.out.debug(msg)

            http_resp = HTTPResponse.from_httplib_resp(res,
                                                       original_url=original_url_inst)
            http_resp.set_id(res.id)
            http_resp.set_wait_time(time.time() - start_time)

            # Let the upper layers know that this response came from the
            # local cache.
            if isinstance(res, CachedResponse):
                http_resp.set_from_cache(True)

            # Clear the log of failed requests; this request is done!
            req_id = id(req)
            if req_id in self._error_count:
                del self._error_count[req_id]
            self._zero_global_error_count()

            if grep:
Example #10
0
                    
                msg = ('%s %s with data: "%s" returned HTTP code "%s"'
                       % (
                          req.get_method(),
                          original_url,
                          printable_data,
                          res.code)
                         )

            from_cache = hasattr(res, 'from_cache')
            flags = ' (id=%s,from_cache=%i,grep=%i)' % (res.id, from_cache,
                                                        grep)
            msg += flags
            om.out.debug(msg)

            http_resp = HTTPResponse.from_httplib_resp(res,
                                                       original_url=original_url_inst)
            http_resp.set_id(res.id)
            http_resp.set_wait_time(time.time() - start_time)

            # Let the upper layers know that this response came from the
            # local cache.
            if isinstance(res, CachedResponse):
                http_resp.set_from_cache(True)

            # Clear the log of failed requests; this request is done!
            req_id = id(req)
            if req_id in self._error_count:
                del self._error_count[req_id]
            self._zero_global_error_count()

            if grep: