zoukankan      html  css  js  c++  java
  • SQL注入攻击

    1.错误代码:

     string id = Request.Params["id"];
       string sql = "insert into [UserTable]([UserID]) values ('"+id+"')";
       executeSql(sql)

    2. 当运行http://localhost:14288/Default.aspx?id=wert')  delete from [UserTable] --

        UserTable数据被清空了

    3.做简单替换

       string id = Request.Params["id"];
       id = id.Replace("'", "''");
       string sql = "insert into [UserTable]([UserID]) values ('"+id+"')";

       executeSql(sql);

       这样会有以下这种垃圾数据还是可以进入数据库

       werxlt')  delete from [UserTable] --

    4.使用下面方法,但是像原来有空格的数据就会被清掉,比如a- b就成了a-b

    public string CheckStr(string html)

     {
                System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                html = regex1.Replace(html, ""); //过滤<script></script>标记
                html = regex2.Replace(html, ""); //过滤href=java script: (<A>) 属性
                html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
                html = regex4.Replace(html, ""); //过滤iframe
                html = regex5.Replace(html, ""); //过滤frameset
                html = regex6.Replace(html, ""); //过滤frameset
                html = regex7.Replace(html, ""); //过滤frameset
                html = regex8.Replace(html, ""); //过滤frameset
                html = regex9.Replace(html, "");
                html = html.Replace(" ", "");
                html = html.Replace("</strong>", "");
                html = html.Replace("<strong>", "");
                return html;
     }

    当运行http://localhost:14288/Default.aspx?id=wert')  delete from [UserTable] --

    显示'deletefrom' 附近有语法错误。

  • 相关阅读:
    windows如何查看删除记录
    nodejs 服务器 崩溃 2种解决办法
    WINDOWS常用端口列表
    windows端口
    普通交换机不需要任何设置,也不能设置
    二层网管交换机应用——访问控制功能管理内网电脑上网行为
    使用 Easy Sysprep v4(ES4) 封装 Windows 7教程
    A电脑的gho还原到B电脑上的驱动解决方案
    servlet 容器与servlet
    依赖注入与控制反转
  • 原文地址:https://www.cnblogs.com/kenny999/p/2868092.html
Copyright © 2011-2022 走看看