Aspx/asp.net Anti-injection program v1.0_ practical skills

Source: Internet
Author: User
Although ASP.net is a highly secure scripting language, it is often seen that asp.net sites are injected because of lax filtration. Because asp.net basically with Mmsql database erection If the permission is too large, it is easy to attack. Furthermore, I couldn't find a good asp.net script on the internet, so I wrote it myself. Shared here is designed to allow programmers to dispense with SQL injection.
I have written two versions, VB. NET and C # versions are convenient for use among different programs.
Describe:
1. XP + IIS5.1 + Access + MSSQL2000 test pass.
2. The MSSQL keyword is added because the ASPX database is used in conjunction with most of the MSSQL databases.
3. Put it in the database connection code, and similar to ASP usage.
Copy Code code as follows:

public void Jk1986_checksql ()
{
String jk1986_sql = "Exec Dream select Dream Drop dream alter dream exists Dream Union dream and Dream or Dream" dream mid Dream "ASC Dream Execute Dream XP_ Cmdshell Dreams, Dreams, Dreams, Dreams, declare, sp_OACreate Dream, Dreams, Dreams, Wscript.Shell Dreams, Dream xp_regwrite Dreams
string[] Jk_sql = Jk1986_sql. Split (' dream ');
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" (C # version) Webmaster network prompts you, do not submit illegal characters! ↓\\n\\nbloghttp://www.safe5.com [Url=file://\\n\\nby]\\n\\nby[/url]:jack '); </"+" script> ");
Response.Write ("Illegal operation!") The system does 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 ("Action page:" + page.request.servervariables["URL"] + "<br>");
Response.Write ("Submit mode: P O S T" + "<br>");
Response.Write ("Submit parameter:" + JK + "<br>");
Response.Write ("Submit data:" + Page.request.form[getsqlkey]. ToLower () + "<br>");
Response.End ();
}
}
}
-----------------------anti-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" (C # version) Webmaster safety net prompts you, do not submit illegal characters! ↓\\n\\nbloghttp://www.safe5.com [Url=file://\\n\\nby]\\n\\nby[/url]:jack '); </"+" script> ");
Response.Write ("Illegal operation!") The system does 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 ("Action page:" + page.request.servervariables["URL"] + "<br>");
Response.Write ("Submit mode: G E T" + "<br>");
Response.Write ("Submit parameter:" + JK + "<br>");
Response.Write ("Submit data:" + Page.request.querystring[getsqlkey]. ToLower () + "<br>");
Response.End ();
}
}
}
-----------------------prevent Cookies from being injected-----------------------
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" (C # version) Webmaster safety net prompts you, do not submit illegal characters! ↓\\n\\nbloghttp://www.safe5.com [Url=file://\\n\\nby]\\n\\nby[/url]:jack '); </"+" script> ");
Response.Write ("Illegal operation!") The system does 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 ("Action page:" + page.request.servervariables["URL"] + "<br>");
Response.Write ("Submission mode: 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.