/// <summary> 
    /// 过滤不安全的字符串
    /// </summary> 
    /// <param name="Str"></param> 
    /// <returns></returns> 
    public static string FilteSQLStr( string Str)
    {

Str = Str.Replace( " ' " , "" );
        Str = Str.Replace( " /" " , "" );
        Str = Str.Replace( " & " , " &amp " );
        Str = Str.Replace( " < " , " &lt " );
        Str = Str.Replace( " > " , " &gt " );

Str = Str.Replace( " delete " , "" );
        Str = Str.Replace( " update " , "" );
        Str = Str.Replace( " insert " , "" );

return Str; 
    }

2.

#region 过滤 Sql 语句字符串中的注入脚本 
        /// <summary> 
        /// 过滤 Sql 语句字符串中的注入脚本
        /// </summary> 
        /// <param name="source"> 传入的字符串 </param> 
        /// <returns> 过 滤后的字符串 </returns> 
        public static string SqlFilter( string source)
        {
            // 单引号替换成两个单引号 
            source = source.Replace( " ' " , " '' " );

// 半角封号替换为全角封号,防止多语句执行 
            source = source.Replace( " ; " , " ; " );

// 半角括号替换为全角括号 
            source = source.Replace( " ( " , " ( " );
            source = source.Replace( " ) " , " ) " );

/////////////// 要用正则表达式替换,防止字母大小写得情况 ////////////////// //

// 去除执行存储过程的命令关键字 
            source = source.Replace( " Exec " , "" );
            source = source.Replace( " Execute " , "" );

// 去除系统存储过程或扩展存储过程关键字 
            source = source.Replace( " xp_ " , " x p_ " );
            source = source.Replace( " sp_ " , " s p_ " );

// 防止16进制注入 
            source = source.Replace( " 0x " , " 0 x " );

return source;
        }
        #endregion

3.

/// 过滤SQL字符。
        /// </summary> 
        /// <param name="str"> 要过滤SQL字符的字符串。 </param> 
        /// <returns> 已过滤掉SQL字符的字符串。 </returns> 
        public static string ReplaceSQLChar( string str)
        {
            if (str == String.Empty)
                return String.Empty; str = str.Replace( " ' " , " ‘ " );
            str = str.Replace( " ; " , " ; " );
            str = str.Replace( " , " , " , " );
            str = str.Replace( " ? " , " ? " );
            str = str.Replace( " < " , " < " );
            str = str.Replace( " > " , " > " );
            str = str.Replace( " ( " , " ( " );
            str = str.Replace( " ) " , " ) " );
            str = str.Replace( " @ " , " @ " );
            str = str.Replace( " = " , " = " );
            str = str.Replace( " + " , " + " );
            str = str.Replace( " * " , " * " );
            str = str.Replace( " & " , " & " );
            str = str.Replace( " # " , " # " );
            str = str.Replace( " % " , " % " );
            str = str.Replace( " $ " , " ¥ " );

return str;
        } 
4.

/// <summary> 
/// 过滤标记
/// </summary> 
/// <param name="NoHTML"> 包括HTML,脚本,数据库关键字,特殊字符的源码 </param> 
/// <returns> 已经去除标记后的文字 </returns> 
public string NoHtml( string Htmlstring)
{
    if (Htmlstring == null )
    {
        return "" ;
    }
    else 
    {
        // 删除脚本 
         Htmlstring = Regex.Replace(Htmlstring, @" <script[^>]*?>.*?</script> " , "" , RegexOptions.IgnoreCase);
        // 删除HTML 
        Htmlstring = Regex.Replace(Htmlstring, @" <(.[^>]*)> " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" ([/r/n])[/s]+ " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" --> " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" <!--.* " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(quot|#34); " , " /" " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(amp|#38); " , " & " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(lt|#60); " , " < " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(gt|#62); " , " > " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(nbsp|#160); " , " " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(iexcl|#161); " , " /xa1 " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(cent|#162); " , " /xa2 " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(pound|#163); " , " /xa3 " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &(copy|#169); " , " /xa9 " , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, @" &#(/d+); " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " xp_cmdshell " , "" , RegexOptions.IgnoreCase);

// 删除与数据库相关的词 
         Htmlstring = Regex.Replace(Htmlstring, " select " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " insert " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " delete from " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " count'' " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " drop table " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " truncate " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " asc " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " mid " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " char " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " xp_cmdshell " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " exec master " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " net localgroup administrators " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " and " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " net user " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " or " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " net " , "" , RegexOptions.IgnoreCase);
        // Htmlstring = Regex.Replace(Htmlstring, "*", "", RegexOptions.IgnoreCase); 
        Htmlstring = Regex.Replace(Htmlstring, " - " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " delete " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " drop " , "" , RegexOptions.IgnoreCase);
        Htmlstring = Regex.Replace(Htmlstring, " script " , "" , RegexOptions.IgnoreCase);

// 特殊的字符 
         Htmlstring = Htmlstring.Replace( " < " , "" );
        Htmlstring = Htmlstring.Replace( " > " , "" );
        Htmlstring = Htmlstring.Replace( " * " , "" );
        Htmlstring = Htmlstring.Replace( " - " , "" );
        Htmlstring = Htmlstring.Replace( " ? " , "" );
        Htmlstring = Htmlstring.Replace( " ' " , " '' " );
        Htmlstring = Htmlstring.Replace( " , " , "" );
        Htmlstring = Htmlstring.Replace( " / " , "" );
        Htmlstring = Htmlstring.Replace( " ; " , "" );
        Htmlstring = Htmlstring.Replace( " */ " , "" );
        Htmlstring = Htmlstring.Replace( " /r/n " , "" );
        Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

return Htmlstring;
   }
}

5.

; i < pattern.Length; i ++ )
{
str = str.Replace(pattern[i].ToString(), "" );
}
return str;
}

过滤sql特殊字符方法集合的更多相关文章

  1. C# 过滤sql特殊字符方法集合

    1./// <summary>    /// 过滤不安全的字符串    /// </summary>    /// <param name="Str" ...

  2. mssql sql语句过滤百分号的方法分享

    转自:http://www.maomao365.com/?p=6743 摘要: 下文讲述sql脚本中过滤百分号的方法: 实验环境:sql server 2008 R2  百分号:在sql脚本编写中“百 ...

  3. C# 过滤sql特殊字符串方法

    1. /// <summary>    /// 过滤不安全的字符串    /// </summary>    /// <param name="Str" ...

  4. jQuery过滤选择器:not()方法使用介绍

    在jQuery的早期版本中,:not()筛选器只支持简单的选择器,说明我们传入到:not这个filter中的selector可以任意复杂,比如:not(div a) and :not(div,a) & ...

  5. SQL特殊字符转义

    原文链接: SQL特殊字符转义 应 该说,您即使没有处理 HTML 或 JavaScript 的特殊字符,也不会带来灾难性的后果,但是如果不在动态构造 SQL 语句时对变量中特殊字符进行处理,将可能导 ...

  6. TP5:使用了INPUT函数来接收参数了,还需再过滤SQL注入吗

    TP5:使用了INPUT函数来接收参数了,还需再过滤SQL注入吗,默认的INPUT函数都做了哪些动作啊 有了PDO参数绑定 基本上不需要考虑sql注入的问题(除非自己拼接SQL),需要考虑的是XSS方 ...

  7. jQuery过滤选择器:not()方法介绍

    jQuery(':not(selector)') 在jQuery的早期版本中,:not()筛选器只支持简单的选择器,说明我们传入到:not这个filter中的selector可以任意复杂,比如:not ...

  8. .net 过滤 sql防注入类,省地以后每次都要重新弄!

    /// <summary>    /// 过滤不安全的字符串    /// </summary>    /// <param name="Str"&g ...

  9. 5.用通配符进行过滤 ---SQL

    一.LIKE操作符 通配符(wildcard) 用来匹配值的一部分的特殊字符.搜索模式(search pattern)由字面值.通配符或两者组合构成的搜索条件.通配符本身实际上是SQL的WHERE子句 ...

随机推荐

  1. VS2017创建一个 ASP.NET Core2.0 应用,并搭建 MVC 框架

    https://testerhome.com/topics/11747 1.使用最新版本的VS2017,并安装.NET Core2.0中相关开发工具   2.打开VS2017,点击文件-新建-项目,选 ...

  2. leetcode997

    class Solution: def findJudge(self, N: int, trust: 'List[List[int]]') -> int: if N==1 and len(tru ...

  3. PHP轻量级框架 Slim 使用(一)

    安装参照文档:https://wizardforcel.gitbooks.io/slim3-doc/content/1.html 项目目录 其中主要业务操作在app目录中完成,可根据需求划分 我这里分 ...

  4. element——message-box

    `${action}`可以捕获用户选择cancel还是confirm,然后进行相应操作 官方文档:http://element-cn.eleme.io/#/zh-CN/component/messag ...

  5. Git 上传文件到 码云 gitee

    1:git bash 执行如下 git config –global user.name “eason” git config –global user.email “your email@qq.co ...

  6. JavaScript的 onclick 事件是如何调用jquery 方法的

    看见个不错的问答,关于JavaScript的 onclick 事件是如何调用jquery 方法的,特此标注,链接如下:http://segmentfault.com/q/101000000033350 ...

  7. Mysql 死锁分析学习

    https://blog.csdn.net/aesop_wubo/article/details/8286215   * CREATE TABLE `user_item` ( * `id` BIGIN ...

  8. dpkg卸载

    from:https://jingyan.baidu.com/article/f54ae2fc2724a71e92b849c4.html 选择 dpkg -l来查看软件的状态. 选择 dpkg -P来 ...

  9. nginx+php 开启https

    nginx 配置如下,配置好重启nginx,不是nginx -s reload,如果还不能访问肯定就是防火墙问题,关闭防火墙再试试. 我遇到的问题是:我服务器是ecs,域名解析到阿里云复杂均衡的,结果 ...

  10. 解决linux下访问https站点问题

    pfx转jks:(注:因jks要求密码长度不能小于6位,所以申请pfx证书时,密码长度最好不小于6位) keytool -importkeystore -v -srckeystore ***.pfx ...