惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
L
LangChain Blog
C
Check Point Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
Vercel News
Vercel News
腾讯CDC
GbyAI
GbyAI
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件

博客园 - SCPlatform

windown 使用python 自动切换网络 CPU封装技术介绍 openssl unicode编译以及VC++2015环境下的问题 重新开启此博 MIFARE Classic S50技术详解 Mifare简介 如何获取JavaCard栈信息 JavaCard应用开发环境 如何获取JavaCard剩余空间 如何统合分析一张JavaCard BER-TLV数据结构 智能卡中的数据结构 加密解密算法 SCPlatform博客文章总目录 C#实现简体中文和繁体中文的转换 关于脚本注入的问题 开发Blog需注意的Blog基本特征和功能要素 java 学习步骤 CodeSmith 实体生成模板(C#版)
QueryString 整站过滤
SCPlatform · 2008-05-08 · via 博客园 - SCPlatform

51期间,网站中了木马,结果发现是QueryString没有过滤的问题,在网上查了一下找了一个比较好的办法。转一下。
                                              
                                            QueryString 整站过滤

对于QueryString的传值是每个程序员都要用到的。但是如何过滤QueryString的方法万千。下面我整理一个方法
大家继续优化讨论

第一步 web.config 加入键值

例如:
<add key="SafeRequest" value="id-int32,nid-int32,xid-int32,keyword-char" /> 

第二步 Global.asax 加入如下

void Application_BeginRequest(object source, EventArgs e)
    {
        String[] SafeRequest = System.Web.Configuration.WebConfigurationManager.AppSettings["SafeRequest"].ToString().Split(',');
        for (int i = 0; i < SafeRequest.Length; i++)
        {
            String RequestName = SafeRequest[i].Split('-')[0];
            String RequestType = SafeRequest[i].Split('-')[1];
            isValidRequest(RequestName, RequestType);
        }
       
    }
    public void isValidRequest(string parameterName, string parameterType)
    {
        string parameterValue = Request.QueryString[parameterName];
        if(parameterValue == null) return;

        if(parameterType.Equals("int32"))
        {
//future.mystring.IsNumeric是我自己做的一个类判断是不是数字。大家根据自己需要可以自行写一段(Bool)
            if(!future.mystring.IsNumeric(parameterValue)) Response.Redirect("index.aspx");
        }
        if (parameterType.Equals("char"))
        {
////future.mystring.IsNumeric是我自己做的一个类判断是不是字符,是否含有敏感字符。大家根据自己需要可以自行写一段(Bool)
            if (!future.mystring.MatchSqlString(parameterValue)) Response.Redirect("index.aspx");
        }

    }