|
我写了两个版本,VB.NET和C#版本方便不同程序间使用.
描述:
1. XP + IIS5.1 + Access + MSSQL2000 下测试通过。
2. 由于考虑到ASPX大多数和MSSQL数据库配合使用,在此增加了MSSQL关键字。
3. 放到数据库连接代码处即可,和ASP用法类似。
复制代码 代码如下:
public void JK1986_CheckSql()
{
string jk1986_sql = "exec select drop alter exists union and or xor order mid asc execute xp_cmdshell insert update delete join declare char sp_oacreate wscript.shell xp_regwrite ' ; -- %";
string[] jk_sql = jk1986_sql.Split(' ');
foreach (string jk in jk_sql)
{
// -----------------------防 Post 注入-----------------------
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#版本 )站长网提示您,请勿提交非法字符!↓//n//nBloghttp://www.safe5.com [url=file:////n//nBy]//n//nBy[/url]:Jack');</" + "script>");
Response.Write("非法操作!系统做了如下记录 ↓" + "<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("操 作 I P :" + getip + "<br>");
Response.Write("操 作 时 间:" + DateTime.Now.ToString() + "<br>");
Response.Write("操 作 页 面:" + Page.Request.ServerVariables["URL"] + "<br>");
Response.Write("提 交 方 式:P O S T " + "<br>");
Response.Write("提 交 参 数:" + jk + "<br>");
Response.Write("提 交 数 据:" + Page.Request.Form[getsqlkey].ToLower() + "<br>");
Response.End();
}
}
}
// -----------------------防 GET 注入-----------------------
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#版本 )站长安全网提示您,请勿提交非法字符!↓//n//nBloghttp://www.safe5.com [url=file:////n//nBy]//n//nBy[/url]:Jack');</" + "script>");
Response.Write("非法操作!系统做了如下记录 ↓" + "<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("操 作 I P :" + getip + "<br>");
Response.Write("操 作 时 间:" + DateTime.Now.ToString() + "<br>");
Response.Write("操 作 页 面:" + Page.Request.ServerVariables["URL"] + "<br>");
Response.Write("提 交 方 式:G E T " + "<br>");
Response.Write("提 交 参 数:" + jk + "<br>");
Response.Write("提 交 数 据:" + Page.Request.QueryString[getsqlkey].ToLower() + "<br>");
Response.End();
}
}
}
// -----------------------防 Cookies 注入-----------------------
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#版本 )站长安全网提示您,请勿提交非法字符!↓//n//nBloghttp://www.safe5.com [url=file:////n//nBy]//n//nBy[/url]:Jack');</" + "script>");
Response.Write("非法操作!系统做了如下记录 ↓" + "<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("操 作 I P :" + getip + "<br>");
Response.Write("操 作 时 间:" + DateTime.Now.ToString() + "<br>");
Response.Write("操 作 页 面:" + Page.Request.ServerVariables["URL"] + "<br>");
Response.Write("提 交 方 式: Cookies " + "<br>");
Response.Write("提 交 参 数:" + jk + "<br>");
Response.Write("提 交 数 据:" + Page.Request.Cookies[getsqlkey].Value.ToLower() + "<br>");
Response.End();
}
}
}
}
}
AspNet技术:Aspx/Asp.net 防注入程序 V1.0,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。