Example #1
0
def html_export(request_string):
    """
    :param request_string: The string of the request to export
    :return: A HTML that will perform the same HTTP request.
    """
    request_lines = request_string.split('\n\n')
    header = request_lines[0]
    body = '\n\n'.join(request_lines[1:])
    http_request = HTTPRequestParser(header, body)
    res = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Exported HTTP Request from w3af</title>
    </head>
    <body>\n"""
    res += '<form action="' + cgi.escape(http_request.get_uri().url_string,
                                         True)
    res += '" method="' + cgi.escape(http_request.get_method(), True) + '">\n'
    if http_request.get_data() and http_request.get_data() != '\n':
        post_data = http_request.get_dc()
        for param_name in post_data:
            for value in post_data[param_name]:
                res += '<label>' + cgi.escape(param_name) + '</label>\n'
                res += '<input type="text" name="' + \
                    cgi.escape(param_name.strip(), True)
                res += '" value="' + cgi.escape(value, True) + '">\n'
    res += '<input type="submit">\n'
    res += '</form>\n'
    res += """</body>\n</html>"""
    return res
Example #2
0
def html_export(request_string):
    """
    :param request_string: The string of the request to export
    :return: A HTML that will perform the same HTTP request.
    """
    request_lines = request_string.split('\n\n')
    header = request_lines[0]
    body = '\n\n'.join(request_lines[1:])
    http_request = HTTPRequestParser(header, body)
    res = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Exported HTTP Request from w3af</title>
    </head>
    <body>\n"""
    res += '<form action="' + cgi.escape(http_request.get_uri()
                                         .url_string, True)
    res += '" method="' + cgi.escape(http_request.get_method(), True) + '">\n'
    if http_request.get_data() and http_request.get_data() != '\n':
        post_data = http_request.get_dc()
        for param_name in post_data:
            for value in post_data[param_name]:
                res += '<label>' + cgi.escape(param_name) + '</label>\n'
                res += '<input type="text" name="' + \
                    cgi.escape(param_name.strip(), True)
                res += '" value="' + cgi.escape(value, True) + '">\n'
    res += '<input type="submit">\n'
    res += '</form>\n'
    res += """</body>\n</html>"""
    return res
    def test_POST_repeated(self):
        request_head = 'POST http://www.w3af.org/ HTTP/1.1\n' \
                       'Host: www.w3af.org\n' \
                       'Content-Length: 7\n' \
                       'Foo: spam\n' \
                       'Foo: eggs\n'

        post_data = 'a=1&a=2'
        fuzzable_request = HTTPRequestParser(request_head, post_data)
        exp_headers = Headers([('Host', 'www.w3af.org'),
                               ('Foo', 'spam, eggs')])
        self.assertEqual(fuzzable_request.get_headers(), exp_headers)
        self.assertEquals(fuzzable_request.get_data(), 'a=1&a=2')
        self.assertEquals(fuzzable_request.get_dc(), {'a': ['1', '2']})
    def test_POST_repeated(self):
        request_head = 'POST http://www.w3af.org/ HTTP/1.1\n' \
                       'Host: www.w3af.org\n' \
                       'Content-Length: 7\n' \
                       'Foo: spam\n' \
                       'Foo: eggs\n'

        post_data = 'a=1&a=2'
        fuzzable_request = HTTPRequestParser(request_head, post_data)
        exp_headers = Headers(
            [('Host', 'www.w3af.org'), ('Foo', 'spam, eggs')])
        self.assertEqual(fuzzable_request.get_headers(), exp_headers)
        self.assertEquals(fuzzable_request.get_data(), 'a=1&a=2')
        self.assertEquals(fuzzable_request.get_dc(), {'a': ['1', '2']})