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
}
}
查看全文
相关阅读:
寒江独钓(0):内核开发上机指导
异常:Hibernate数据库恢复错误
天书夜读:从汇编语言到Windows内核编程笔记(4)
企业WEBGIS网站解决方案
如何使用国际开源项目构建一个完整的GIS(地理信息)应用系统
将指定文件夹下的所有文件copy到目标文件夹下
一些jquery的小知识
压缩指定目录下指定文件(包括子目录下的文件)
解压一个rar文件
关于下载txt文本文挡的问题
原文地址:https://www.cnblogs.com/Spring/p/1209077.html
最新文章
IIS导出Excel的权限问题
FORM的ENCTYPE="multipart/formdata" 时request.getParameter()值为null问题的解决
vc++中的数据类型及其转换
数据格式转换【Delphi版】
简单工厂模式【java版】
类型强转【Delphi版】
Sql Server中char、varchar、nvarchar对比
Android开发计划
虚函数——多态的关键
静态成员方法与静态成员变量【Java版】
热门文章
Delphi数据类型
Sql Server创建表示例程序
单例模式【java版】
Windows内存管理(3)检查内存可用性,结构化异常处理 和 ASSERT
错误码、异常和断言
天书夜读:WinDbg配置和使用基础
UNICODE与ANSI的区别
Windows内存管理(1)
Windows内存管理(2)Lookaside
天书夜读:从汇编语言到Windows内核编程笔记(3)
Copyright © 2011-2022 走看看