Spring
每天,都要积极的生活!
.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
}
}
posted on 2008-05-28 11:56
Eric Zhang
阅读(151)
评论(0)
编辑
收藏
所属分类:
Asp & .NET
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
.NET初学者架构设计指南
你必须知道的.NET
使用Visual Studio2005入门.Net2.0系列视频教程
.NET设计模式系列文章
cn域名数量已经超越.net 短期内难威胁.com
.NET Reflector被Red Gate收购
.NET类库源代码
.NET知识体系
.NET多好
.NET 设计规范
相关链接:
历史上的今天:
2005-05-28
[ASP]GetRows的用法详解!
所属分类的其他文章:
型网站的架构设计问题----大型高并发高负载网站的系统架构
MySpace的六次重构
cs0016: 未能写入输出文件“c:\windows\microsoft.net\***.dll”错误处理
.net 通用防注入代码
iis中asp存取Access时报"Microsoft JET Database Engine (0x80004005)未指定错误"的解决方法
启用IIS的Gzip压缩功能
P3P 和 跨域 (cross-domain) cookie 访问(读取和设置)
VS.net调试程序速度变慢的问题
"HTTP 错误 401.1 - 未经授权:访问由于凭据无效被拒绝" 的解决办法
在Web应用程序中执行计划任务(多线程)
最新IT新闻:
11个处于悬崖边缘的 Web 公司
扎克博格:Facebook要先赚吆喝后赚钱
金融风暴改写富豪榜排名 巴菲特资产超盖茨
红杉资本发出严重警告:黄金时代已成历史
2008年10月11日科技博客精选
导航
博客园
首页
新随笔
联系
订阅
管理
公告
欢迎回来!:-)
<
2008年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
统计
随笔 - 172
文章 - 1
评论 - 42
引用 - 6
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(4)
给我留言
查看留言
我参加的小组
创业交流
我参与的团队
天津.NET俱乐部(0/792)
ASP.NET AJAX (Atlas)学习(0/1352)
随笔分类
Asp & .NET(68)
(rss)
C#(8)
(rss)
DataBases(42)
(rss)
Duwamish(5)
(rss)
Java (6)
(rss)
Linux(1)
(rss)
My Attitude(1)
(rss)
My Life(12)
(rss)
Others(26)
(rss)
PHP(1)
(rss)
Project Management(4)
(rss)
Server(4)
(rss)
积分与排名
积分 - 71919
排名 - 600
阅读排行榜
1. sql server日期时间函数(4434)
2. iframe自适应高度(4059)
3. "HTTP 错误 401.1 - 未经授权:访问由于凭据无效被拒绝" 的解决办法 (3982)
4. ASCⅡCharacters (ASCⅡ码对照表) (3944)
5. SQL-SERVER触发器 (2629)