Aspx/Asp.net anti-injection program V1.0

Source: Internet
Author: User

Although ASP. NET is a highly secure scripting language, but it is often seen in ASP.. NET website injection due to lax filtering. because ASP. NET is basically used with MMSQL database setup. If the permission is too large, it is easy to be attacked. in addition, no good ASP can be found on the network. NET injection prevention script, so I wrote it myself. this sharing aims to free programmers from the troubles of SQL injection.
I have written two versions, VB. NET and C #, to facilitate the use of different programs.
Description:
1. XP + IIS5.1 + Access + MSSQL2000 passed the test.
2. The MSSQL keyword is added here because most of the ASPX and MSSQL databases are used in combination.
3. Place it in the database connection code, which is similar to ASP usage. Copy codeThe Code is as follows: public void JK1986_CheckSql ()
{
String jk1986_ SQL = "exec statements select statements drop statements alter statements exists except union statements and statements or both xor two order statements mid sequence asc statements execute statements before xp_statement shell statements insert statements update statements delete statements join statements declare invalid char should sp_oacreate should wscript. shell response xp_regwrite comment 'response; response -- Response % ";
String [] jk_ SQL = jk1986_ SQL .Split ('hangzhou ');
Foreach (string jk in jk_ SQL)
{
// ----------------------- Anti-Post injection -----------------------
If (Page. Request. Form! = Null)
{
For (int k = 0; k <Page. Request. Form. Count; k ++)
{
String getsqlkey = Page. Request. Form. Keys [k];
String getip;
If (Page. Request. Form [getsqlkey]. ToLower (). Contains (jk) = true)
{
Response. Write ("<script Language = JavaScript> alert ('asp. NET (C #) Webmaster prompt you, do not submit invalid characters! Region \ n \ nBloghttp: // www.safe5.com [url = file: // \ n \ nBy] \ n \ nBy [/url]: Jack '); </"+" script> ");
Response. Write ("invalid operation! The system makes the following record "+" <br> ");
If (Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]! = Null)
{
Getip = this. Page. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"];
}
Else
{
Getip = Page. Request. ServerVariables ["REMOTE_ADDR"];
}
Response. Write ("operation I P:" + getip + "<br> ");
Response. Write ("operation time:" + DateTime. Now. ToString () + "<br> ");
Response. Write ("Operation Page:" + Page. Request. ServerVariables ["URL"] + "<br> ");
Response. Write ("delivery method: p o s t" + "<br> ");
Response. Write ("Submit parameter:" + jk + "<br> ");
Response. Write ("submit data:" + Page. Request. Form [getsqlkey]. ToLower () + "<br> ");
Response. End ();
}
}
}
// ----------------------- Prevent GET injection -----------------------
If (Page. Request. QueryString! = Null)
{
For (int k = 0; k <Page. Request. QueryString. Count; k ++)
{
String getsqlkey = Page. Request. QueryString. Keys [k];
String getip;
If (Page. Request. QueryString [getsqlkey]. ToLower (). Contains (jk) = true)
{
Response. Write ("<script Language = JavaScript> alert ('asp. NET (C #) webmasters security NET prompts you, please do not submit illegal characters! Region \ n \ nBloghttp: // www.safe5.com [url = file: // \ n \ nBy] \ n \ nBy [/url]: Jack '); </"+" script> ");
Response. Write ("invalid operation! The system makes the following record "+" <br> ");
If (Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]! = Null)
{
Getip = this. Page. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"];
}
Else
{
Getip = Page. Request. ServerVariables ["REMOTE_ADDR"];
}
Response. Write ("operation I P:" + getip + "<br> ");
Response. Write ("operation time:" + DateTime. Now. ToString () + "<br> ");
Response. Write ("Operation Page:" + Page. Request. ServerVariables ["URL"] + "<br> ");
Response. Write ("delivery method: g e t" + "<br> ");
Response. Write ("Submit parameter:" + jk + "<br> ");
Response. Write ("submit data:" + Page. Request. QueryString [getsqlkey]. ToLower () + "<br> ");
Response. End ();
}
}
}
// ----------------------- Prevent cookie injection -----------------------
If (Page. Request. Cookies! = Null)
{
For (int k = 0; k <Page. Request. Cookies. Count; k ++)
{
String getsqlkey = Page. Request. Cookies. Keys [k];
String getip;
If (Page. Request. Cookies [getsqlkey]. Value. ToLower (). Contains (jk) = true)
{
Response. Write ("<script Language = JavaScript> alert ('asp. NET (C #) webmasters security NET prompts you, please do not submit illegal characters! Region \ n \ nBloghttp: // www.safe5.com [url = file: // \ n \ nBy] \ n \ nBy [/url]: Jack '); </"+" script> ");
Response. Write ("invalid operation! The system makes the following record "+" <br> ");
If (Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]! = Null)
{
Getip = this. Page. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"];
}
Else
{
Getip = Page. Request. ServerVariables ["REMOTE_ADDR"];
}
Response. Write ("operation I P:" + getip + "<br> ");
Response. Write ("operation time:" + DateTime. Now. ToString () + "<br> ");
Response. Write ("Operation Page:" + Page. Request. ServerVariables ["URL"] + "<br> ");
Response. Write ("submission method: Cookies" + "<br> ");
Response. Write ("Submit parameter:" + jk + "<br> ");
Response. Write ("submit data:" + Page. Request. Cookies [getsqlkey]. Value. ToLower () + "<br> ");
Response. End ();
}
}
}
}
}

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.