• 格式化文本(防止SQL注入)


     /// <summary>
            /// 格式化文本(防止SQL注入)
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Formatstr(string html)
            {
                System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex10 = new System.Text.RegularExpressions.Regex(@"select", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex11 = new System.Text.RegularExpressions.Regex(@"update", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex12 = new System.Text.RegularExpressions.Regex(@"delete", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                html = regex1.Replace(html, ""); //过滤<script></script>标记
                html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
                html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
                html = regex4.Replace(html, ""); //过滤iframe
                html = regex10.Replace(html, "s_elect");
                html = regex11.Replace(html, "u_pudate");
                html = regex12.Replace(html, "d_elete");
                html = html.Replace("'", "’");
                html = html.Replace(" ", " ");
                return html;
            }
    

      

  • 相关阅读:
    linux查询php.ini位置
    laravel打印完整SQL语句
    python识别图片中的文字
    python -使用pytesseract识别文字时遇到的问题
    python弹出选择文件的弹出窗获取文件方法
    python将字符串中多个空格换为一个空格
    python生成word文档
    linux下tar命令
    python使用xpath获取内容
    正则表达式匹配空行
  • 原文地址:https://www.cnblogs.com/password1/p/13226608.html
Copyright © 2020-2023  润新知