zoukankan
html css js c++ java
.net 通用防注入代码
using
System;
namespace
web.comm
{
/**/
///
<summary>
///
ProcessRequest 的摘要说明。
///
</summary>
public
class
ProcessRequest
{
public
ProcessRequest()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
SQL注入式攻击代码分析
#region
SQL注入式攻击代码分析
/**/
///
<summary>
///
处理用户提交的请求
///
</summary>
public
static
void
StartProcessRequest()
{
//
System.Web.HttpContext.Current.Response.Write("<script>alert('dddd');</script>");
try
{
string
getkeys
=
""
;
//
string sqlErrorPage = System.Configuration.ConfigurationSettings.AppSettings["CustomErrorPage"].ToString();
if
(System.Web.HttpContext.Current.Request.QueryString
!=
null
)
{
for
(
int
i
=
0
;i
<
System.Web.HttpContext.Current.Request.QueryString.Count;i
++
)
{
getkeys
=
System.Web.HttpContext.Current.Request.QueryString.Keys[i];
if
(
!
ProcessSqlStr(System.Web.HttpContext.Current.Request.QueryString[getkeys],
0
))
{
//
System.Web.HttpContext.Current.Response.Redirect (sqlErrorPage+"?errmsg=sqlserver&sqlprocess=true");
System.Web.HttpContext.Current.Response.Write(
"
<script>alert('请勿非法提交!');history.back();</script>
"
);
System.Web.HttpContext.Current.Response.End();
}
}
}
if
(System.Web.HttpContext.Current.Request.Form
!=
null
)
{
for
(
int
i
=
0
;i
<
System.Web.HttpContext.Current.Request.Form.Count;i
++
)
{
getkeys
=
System.Web.HttpContext.Current.Request.Form.Keys[i];
if
(
!
ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys],
1
))
{
//
System.Web.HttpContext.Current.Response.Redirect (sqlErrorPage+"?errmsg=sqlserver&sqlprocess=true");
System.Web.HttpContext.Current.Response.Write(
"
<script>alert('请勿非法提交!');history.back();</script>
"
);
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
//
错误处理: 处理用户提交信息!
}
}
/**/
///
<summary>
///
分析用户请求是否正常
///
</summary>
///
<param name="Str">
传入用户提交数据
</param>
///
<returns>
返回是否含有SQL注入式攻击代码
</returns>
private
static
bool
ProcessSqlStr(
string
Str,
int
type)
{
string
SqlStr;
if
(type
==
1
)
SqlStr
=
"
exec |insert |select |delete |update |count |chr |mid |master |truncate |char |declare
"
;
else
SqlStr
=
"
'|and|exec|insert|select|delete|update|count|*|chr|mid|master|truncate|char|declare
"
;
bool
ReturnValue
=
true
;
try
{
if
(Str
!=
""
)
{
string
[] anySqlStr
=
SqlStr.Split(
'
|
'
);
foreach
(
string
ss
in
anySqlStr)
{
if
(Str.IndexOf(ss)
>=
0
)
{
ReturnValue
=
false
;
}
}
}
}
catch
{
ReturnValue
=
false
;
}
return
ReturnValue;
}
#endregion
}
}
查看全文
相关阅读:
关于CG Relighting系统设计的片言碎语
[F&Q:How To Learn Computer Graphic]如何学习计算机图形学
以后再也不写英文的文章了
[D80]天井
[应邀发布]Rapidmind Development Platform Download
vs2008 结构体托管
换实验室
3D
【入门】点击按钮添加输入框
【入门】PHP与数据库连接
原文地址:https://www.cnblogs.com/Spring/p/1209077.html
最新文章
使用C#创建ActiveX控件(译文)
asp.net中给listbox添加横向滚动条
asp.net中使用modal window的问题
解决modal窗口中cache造成的不能刷新问题
将asp.net usercontrol(用户控件页)转变为普通控件
SidebySide Execution
CSS 浮动
Crosssite scripting,XSS
ASP.NET application and page life cycle
Active Directory Basic Concept
热门文章
ASP.NET Compilation
offsetLeft,Left,clientLeft的区别
ASP.NET Web server controls
@ Page Directive
Windows Live ID Delegated Authentication
Understanding Digital Raw Capture
NVIDIA + mental image = Was ?
Practise Skin Sub Surface Scattering (SSS) Effect In RenderMan Production
[灰诗]侍神的红蝶
为HP 3704/3706重新分区
Copyright © 2011-2022 走看看