Пример #1
0
def main(method, querystring, headers, body):
    if method == "GET":
        response_line = 'HTTP/1.1 200 OK'
        response_headers = []
        response_body = get_body('index.html')
        return response_line, response_headers, response_body
    elif method == 'POST':
        parameters = parse_parameters(body)
        username, password = parameters['username'], parameters['password']
        db = SQLiteAPI()
        # todo hash password
        if db.add_user(username, password):
            template = 'successful_registration.html'
        else:
            template = 'unsuccessful_registration.html'

        response_line = 'HTTP/1.1 200 OK'
        response_headers = []
        response_body = get_body(template)
        return response_line, response_headers, response_body
    else:
        response_line = "HTTP/1.1 405 Method Not Allowed"
        response_headers = []
        response_body = get_body('405.html')
        return response_line, response_headers, response_body
Пример #2
0
    def __process(self, data):
        """
        Process data to fill properties of Burp object.
        """
        self.host = data.get('host', None)
        self.ip_address = data.get('ip_address', None)
        self.time = data.get('time', None)

        self.request.update({
            'method':
            data['request'].get('method'),
            'path':
            data['request'].get('path'),
            'version':
            data['request'].get('version'),
            'headers':
            parse_headers(data['request'].get('headers')),
            'body':
            data['request'].get('body', ""),
        })

        self.response.update({
            'version':
            data['response'].get('version'),
            'status':
            int(data['response'].get('status', 0)),
            'reason':
            data['response'].get('reason'),
            'headers':
            parse_headers(data['response'].get('headers')),
            'body':
            data['response'].get('body', ""),
        })

        self.url = urlparse(urljoin(self.host, self.request.get('path')))
        self.parameters = parse_parameters(self)

        # During parsing, we may parse an extra CRLF or two.  So to account
        # for that, we'll just grab the actual content-length from the
        # HTTP header and slice the request/response body appropriately.
        if self.get_response_header('Content-Length'):
            content_length = int(self.get_response_header('Content-Length'))
            if len(self) != content_length:
                #LOGGER.debug("Response content-length differs by %d" % (len(self) - content_length))
                self.response['body'] = self.response['body'][:content_length]

        if self.get_request_header('Content-Length'):
            content_length = int(self.get_request_header('Content-Length'))
            if len(self.get_request_body()) != content_length and 'amf' not in \
                self.get_request_header('Content-Type'):
                #LOGGER.debug("Request content-length differs by %d" % (len(self.get_request_body()) - content_length))
                self.request['body'] = self.request['body'][:content_length]
Пример #3
0
def get_transformer(transformer):
    if transformer is None:
        return None

    transformer_type = transformer.get('type', None)
    if transformer_type is None:
        return None

    if transformer_type not in TRANSFORMERS:
        return None

    settings = TRANSFORMERS[transformer_type]
    params = parse_parameters(transformer, settings)
    return settings['class'](**params)
Пример #4
0
def get_scaler(scaler_config, default_scaler):
    if scaler_config is None:
        scaler_type = default_scaler
        scaler_config = {}
    else:
        scaler_type = scaler_config.get('type', None)
    if scaler_type is None:
        scaler_type = default_scaler
        scaler_config = {}
    if scaler_type is None:
        return None

    if scaler_type not in SCALERS:
        raise ScalerException(
            "Scaler '{0}' isn\'t supported.".format(scaler_type))

    params = parse_parameters(scaler_config, SCALERS[scaler_type])
    return SCALERS[scaler_type]['class'](**params)