Popular asp.net ValidateRequest filter rule

Source: Internet
Author: User

 

 

The source code of the. net4.0 check is extracted as follows:

 

 

 

/// Here, the pseudo Portal

 

/// </Summary>

 

/// <Param name = "s"> </param>

 

/// <Returns> </returns>

 

Private static bool IsDangerousString (string s)

 

{

 

// Remove \ 0 first

 

S = RemoveNullCharacters (s );

 

Int macount = 0;

 

Return IsDangerousString (s, out macount );

 

}

 

 

 

/// <Summary>

 

/// Remove character Truncation

 

/// </Summary>

 

/// <Param name = "s"> </param>

 

/// <Returns> </returns>

 

Private static string RemoveNullCharacters (string s)

 

{

 

If (s = null)

 

{

 

Return null;

 

}

 

If (s. IndexOf ('\ 0')>-1)

 

{

 

Return s. Replace ("\ 0", string. Empty );

 

}

 

Return s;

 

}

 

 

 

 

 

Static char [] startingChars = new char [] {'<','&'};

 

 

 

Private static bool IsAtoZ (char c)

 

{

 

Return (c> = 'A') & (c <= 'Z') | (c> = 'A ') & (c <= 'Z ')));

 

}

 

 

 

/// <Summary>

 

/// 1. No <and & certainly

 

/// 2. <followed by a letter or! /? None

 

/// 3. & # No

 

/// </Summary>

 

/// <Param name = "s"> </param>

 

/// <Param name = "matchIndex"> </param>

 

/// <Returns> </returns>

 

Internal static bool IsDangerousString (string s, out int matchIndex)

 

{

 

MatchIndex = 0;

 

Int startIndex = 0;

 

While (true)

 

{

 

Int num2 = s. IndexOfAny (startingChars, startIndex );

 

If (num2 <0)

 

{

 

Return false;

 

}

 

If (num2 = (s. Length-1 ))

 

{

 

Return false;

 

}

 

MatchIndex = num2;

 

Char ch = s [num2];

 

If (ch! = '&')

 

{

 

If (ch = '<') & (IsAtoZ (s [num2 + 1]) | (s [num2 + 1] = '! ') | (S [num2 + 1] ='/') | (s [num2 + 1] = '? '))))

 

{

 

Return true;

 

}

 

}

 

Else if (s [num2 + 1] = '#')

 

{

 

Return true;

 

}

 

StartIndex = num2 + 1;

 

}

 

}

 

 

 

Summary

 

1. Do not appear <and & must be safe

 

2. It is safe to only show <or & single characters

 

3. <a-Z,/,! appears ,/,! ,? Is insecure

 

4. & appears later # It is insecure

 

5. None of the above are safe.

 

 

 

In combination with the filtering rules and ie features, we can find some bypass methods, such as in ie6

 

 

 

<~ /XSS/*-*/STYLE = xss: e/**/xpression (alert ('xsss')>

 

 

 

Reference

 

Http://www.procheckup.com/vulnerability_manager/documents/document_1258758664/bypassing-dot-NET-ValidateRequest.pdf

From: hi.baidu.com/cnqing

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.