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
}
}
查看全文
相关阅读:
11月1号笔试题总结
10月30笔试题总结
web前端常用单词
9月13日·碎碎念
python 匿名函数
python 二分法查找
python 递归
python内置函数
python 列表生成式
python 生成器
原文地址:https://www.cnblogs.com/Spring/p/1209077.html
最新文章
idea启动tomcat报错:前言中不允许有内容
js正则0-100之间的正整数
51nod——1285 山峰和分段(暴力出奇迹)
51nod——2478 小b接水(预处理 思维)
51nod——2476 小b和序列(预处理 思维)
51nod——1640 天气晴朗的魔法 有边权限制的最大生成树
51nod——1548 欧姆诺姆和糖果
2019.5.18-5.19 ACM-ICPC 全国邀请赛(西安)赛后总结
2019.5.4总结
51nod——2502最多分成多少块
热门文章
51nod——2489 小b和灯泡(打表/平方数)
CSP-S 2020 考前总结
[模板] 多项式全家桶
[学习笔记] 分治FFT
NOIP2020集训做题记录
钱包生活面试
TCP协议中的三次握手和四次挥手(图解)
一些需要掌握的前端知识
11月4日亚细亚面试总结
11月2日组团招聘及爱用宝笔试总结
Copyright © 2011-2022 走看看