ASP. NET script intrusion overview {reference msdn}

Source: Internet
Author: User
Reference: http://msdn.microsoft.com/zh-cn/library/w1sw53ds (vs.80). aspx ASP. NET Script intrusion Overview

From the browser's perspective, a webpage is just a long string. The browser will process this string in order. In this process, some characters are displayed, and other characters are interpreted according to special rules (such<B>And<SCRIPT>). If a malicious user can insert some special characters into a page, the browser will not know that these characters should not be in this position and will process them as part of the page.

The following describes how a simple script can work. If the applicationProgramTo allow users to post comments to the latest video for other users to read, the steps to use the script can be:

    1. The application displays a form in which users can enter comments. Malicious users write<SCRIPT>Block comments.

    2. Sends a form. Malicious user comments are stored in the database.

    3. Another user accesses the site. When constructing a page, the application reads comments from the database and places them in the page. Malicious user<SCRIPT>The block is written to the page as if it was a text comment.

    4. When the browser of the second user displays this page, it will encounter <SCRIPT>Block and execute it.

Malicious users can also use scripts in other ways. Most scripts require the application to accept malicious input and insert it into the page (or echo it). the browser will execute it on this page. The potential damage caused by such exploitation depends on the script being executed. It can be insignificant, for example, annoying messages popped up in a browser. However, it may also steal cookies, steal user input (such as passwords), and even run the local machine on the user's computer.Code(If the requirements for Internet security are not strict), resulting in serious damage.

For more information about how to prevent script exploitation, see how to prevent script intrusion by applying HTML code to strings in Web applications.

SQL statement Exploitation

There is a variant used by the script that can cause execution of malicious SQL statements. If the application prompts the user to enter information and Concatenates the user input into a string that represents an SQL statement, this situation occurs. For example, an application may prompt you to enter the customer name to execute a statement similar to the following:

Copy code
 
"Select * from MERs where customername =" & txtcustomername. Value

However, malicious users who are familiar with the database may use text boxes to input embedded SQL statements containing the customer's name to generate statements similar to the following:

Copy code
Select * from MERs where customername = 'a 'delete from MERs where customername>''

When this query is executed, the database is compromised.

Prevent script Exploitation

The main way to prevent scripts from being used is to never trust information from users. Assume that any data sent from a browser to your application contains malicious scripts.

Similarly, every time you write a string to a page, you should assume that the string may contain malicious scripts (unless you have created a string programmatically ). For example, when reading strings from a database, you should assume that they may contain malicious scripts. Developers with high security awareness do not even trust their own databases on the grounds that they believe that malicious users may be able to tamper with the database.

ASP. NET provides several methods to prevent script exploitation:

    • ASP. NET performs request verification on query strings, form variables, and cookie values. By default, if the current request contains HTML-encoded elements or some HTML characters (for example), The ASP. NET page framework will cause an error.

    • If you want to display strings in the application but do not trust these strings, you can apply HTML encoding to these strings when writing back strings in the response. For example, after encoding, Mark<B>Will become& Lt; B & gt;. If the string you want to display comes from a database that you are not sure to trust its content, you may do so.

    • If you want your application to accept an HTML (for example, some format settings from the user), encode the HTML on the client before submitting it to the server.

    • To prevent the use of SQL statements, you must create SQL queries by concatenating strings. Instead, use parameterized queries and assign user input to parameter objects. For more information, see parameters in the data adapter command.

    • Always perform form input verification and string format setting/type verification on a set of expected values. For example, if a specific form variable is an integer, use the system. int32.tryparse method to verify whether the value is indeed an integer, and use the range check to help ensure that the value is within an acceptable range.

See Task

How to: prevent script intrusion in Web applications by applying HTML encoding to strings
Concept

Web Application Security Threats
Basic security practices for Web applications (Visual Studio)

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.