Пример #1
0
    def test_html_invalid_utf8_entity_encoded(self):
        """Test for invalid entity encoded chars"""
        samples = {
            'Valid ASCII': u"a",
            'Valid 2 Octet Sequence': u"&#xc3b1",
            'Invalid 2 Octet Sequence': u"&#xc328",
            'Invalid Sequence Identifier': u"&#xa0a1",
            'Valid 3 Octet Sequence': u"&#xe282a1",
            'Invalid 3 Octet Sequence (in 2nd Octet)': u"&#xe228a1",
            'Invalid 3 Octet Sequence (in 3rd Octet)': u"&#xe28228",
            'Valid 4 Octet Sequence': u"&#xf0908cbc",
            'Invalid 4 Octet Sequence (in 2nd Octet)': u"&#xf0288cbc",
            'Invalid 4 Octet Sequence (in 3rd Octet)': u"&#xf09028bc",
            'Invalid 4 Octet Sequence (in 4th Octet)': u"&#xf0288c28",
            'Valid 5 Octet Sequence (but not Unicode!)': u" &#xf8a1a1a1a1 ",
            'Valid 6 Octet Sequence (but not Unicode!)': u" &#xfca1a1a1a1a1 ",
            'Invalid unicode FFFE': u"&#xFFFE",
            'Invalid unicode FFFF': u"&#xFFFF",
        }

        for desc, sample in samples.iteritems():
            try:
                htmldecode(sample)
            except Exception as e:
                msg = 'Exception "%s" was raised when trying to htmldecode() a "%s".'
                self.assertTrue(False, msg % (e, desc))
Пример #2
0
    def test_html_invalid_utf8_entity_encoded(self):
        """Test for invalid entity encoded chars"""
        samples = {
            'Valid ASCII': u"a",
            'Valid 2 Octet Sequence': u"&#xc3b1",
            'Invalid 2 Octet Sequence': u"&#xc328",
            'Invalid Sequence Identifier': u"&#xa0a1",
            'Valid 3 Octet Sequence': u"&#xe282a1",
            'Invalid 3 Octet Sequence (in 2nd Octet)': u"&#xe228a1",
            'Invalid 3 Octet Sequence (in 3rd Octet)': u"&#xe28228",
            'Valid 4 Octet Sequence': u"&#xf0908cbc",
            'Invalid 4 Octet Sequence (in 2nd Octet)': u"&#xf0288cbc",
            'Invalid 4 Octet Sequence (in 3rd Octet)': u"&#xf09028bc",
            'Invalid 4 Octet Sequence (in 4th Octet)': u"&#xf0288c28",
            'Valid 5 Octet Sequence (but not Unicode!)': u" &#xf8a1a1a1a1 ",
            'Valid 6 Octet Sequence (but not Unicode!)': u" &#xfca1a1a1a1a1 ",
            'Invalid unicode FFFE': u"&#xFFFE",
            'Invalid unicode FFFF': u"&#xFFFF",
        }

        for desc, sample in samples.iteritems():
            try:
                htmldecode(sample)
            except Exception as e:
                msg = 'Exception "%s" was raised when trying to htmldecode() a "%s".'
                self.assertTrue(False, msg % (e, desc))
Пример #3
0
def html_unescape(t):
    """Decoder doing HTML unescaping.

    >>> encode_decode.htmldecode('<script>')
    u'<script>'
    >>>
    """
    return encode_decode.htmldecode(t)
Пример #4
0
def html_unescape(t):
    """Decoder doing HTML unescaping.

    >>> encode_decode.htmldecode('&lt;script&gt;')
    u'<script>'
    >>>
    """
    return encode_decode.htmldecode(t)
Пример #5
0
 def test_bug_trigger_case01(self):
     """
     u'í'.decode('utf-8')
     
     UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
                         position 9745: ordinal not in range(128)
     """
     html = u'Aquí encontrará'
     self.assertEqual(htmldecode(html), html)
Пример #6
0
 def test_bug_trigger_case01(self):
     """
     u'í'.decode('utf-8')
     
     UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in
                         position 9745: ordinal not in range(128)
     """
     html = u'Aquí encontrará'
     self.assertEqual(htmldecode(html), html)
Пример #7
0
    def _parse_xssed_vuln_page(self, xss_report_response):
        """
        Parse the HTTP response for a vulnerability page such as
        http://www.xssed.com/mirror/76754/ and create the vulnerability object
        to the KB.
        """
        body = xss_report_response.get_body()
        url_matches = self.XSSED_URL_RE.findall(body)

        for xss_url in url_matches:

            # Ugly but required because of how xssed.com writes stuff
            xss_url = xss_url.replace('<br>', '')
            xss_url = htmldecode(xss_url)
            xss_url = urllib2.unquote(xss_url)
            xss_url = URL(xss_url)

            if self.UNFIXED in xss_report_response.get_body():
                vuln_severity = severity.HIGH
                verb = 'contains'
            else:
                vuln_severity = severity.LOW
                verb = 'contained'

            desc_fmt = ('According to xssed.com the target domain %s a XSS'
                        ' vulnerability, see %s for more information')
            desc = desc_fmt % (verb, xss_report_response.get_url())
            v = Vuln('Potential XSS vulnerability', desc, vuln_severity,
                     xss_report_response.id, self.get_name())
            v.set_url(xss_url)

            #
            # Add the fuzzable request, this is useful if I have the
            # XSS plugin enabled because it will re-test this and
            # possibly confirm the vulnerability
            #
            fr = FuzzableRequest(xss_url)
            self.output_queue.put(fr)

            # Save the vuln to the KB and print to output
            self.kb_append(self, 'xss', v)
Пример #8
0
    def _parse_xssed_vuln_page(self, xss_report_response):
        """
        Parse the HTTP response for a vulnerability page such as
        http://www.xssed.com/mirror/76754/ and create the vulnerability object
        to the KB.
        """
        body = xss_report_response.get_body()
        url_matches = self.XSSED_URL_RE.findall(body)

        for xss_url in url_matches:

            # Ugly but required because of how xssed.com writes stuff
            xss_url = xss_url.replace('<br>', '')
            xss_url = htmldecode(xss_url)
            xss_url = urllib2.unquote(xss_url)
            xss_url = URL(xss_url)

            if self.UNFIXED in xss_report_response.get_body():
                vuln_severity = severity.HIGH
                verb = 'contains'
            else:
                vuln_severity = severity.LOW
                verb = 'contained'

            desc_fmt = ('According to xssed.com the target domain %s a XSS'
                        ' vulnerability, see %s for more information')
            desc = desc_fmt % (verb, xss_report_response.get_url())
            v = Vuln('Potential XSS vulnerability', desc,
                     vuln_severity, xss_report_response.id, self.get_name())
            v.set_url(xss_url)

            #
            # Add the fuzzable request, this is useful if I have the
            # XSS plugin enabled because it will re-test this and
            # possibly confirm the vulnerability
            #
            fr = FuzzableRequest(xss_url)
            self.output_queue.put(fr)

            # Save the vuln to the KB and print to output
            self.kb_append(self, 'xss', v)
Пример #9
0
 def test_tilde(self):
     self.assertEqual(htmldecode(u'hólá múndó'), u'hólá múndó')
Пример #10
0
 def test_bug_trigger_case02(self):
     html_utf8_raw = 'Aqu\xc3\xad encontrar\xc3\xa1'
     html_unicode = 'Aqu\xc3\xad encontrar\xc3\xa1'.decode('utf-8')
     self.assertEqual(htmldecode(html_utf8_raw), html_unicode)
Пример #11
0
 def test_bug_trigger_case04(self):
     html = u'\xed'
     self.assertEqual(htmldecode(html), html)
Пример #12
0
 def test_html_encoded(self):
     self.assertEqual(htmldecode(u'&aacute;'), u'á')
Пример #13
0
 def test_special_char(self):
     self.assertEqual(htmldecode(u'hola &#0443'), u'hola ƻ')
Пример #14
0
 def test_special_char(self):
     self.assertEqual(htmldecode(u'hola &#0443'), u'hola ƻ')
Пример #15
0
 def test_charref(self):
     self.assertEqual(htmldecode(u'hola mundo &#x41'), u'hola mundo A')
Пример #16
0
 def test_simple(self):
     self.assertEqual(htmldecode('hola mundo'), 'hola mundo')
Пример #17
0
 def test_tilde(self):
     self.assertEqual(htmldecode(u'hólá múndó'), u'hólá múndó')
Пример #18
0
 def test_simple(self):
     self.assertEqual(htmldecode('hola mundo'), 'hola mundo')
Пример #19
0
 def test_charref(self):
     self.assertEqual(htmldecode(u'hola mundo &#x41'), u'hola mundo A')
Пример #20
0
 def test_html_encoded(self):
     self.assertEqual(htmldecode(u'&aacute;'), u'á')
Пример #21
0
 def test_bug_trigger_case04(self):
     html = u'\xed'
     self.assertEqual(htmldecode(html), html)
Пример #22
0
 def test_bug_trigger_case02(self):
     html_utf8_raw = 'Aqu\xc3\xad encontrar\xc3\xa1'
     html_unicode = 'Aqu\xc3\xad encontrar\xc3\xa1'.decode('utf-8')
     self.assertEqual(htmldecode(html_utf8_raw), html_unicode)