• XSS学习笔记(五)-XSS防御


    如果只生产XSS的地方都与输入或输出相关联的。所以错过了主要矛盾。而且,我们将有一个解决问题的办法:您可以输入端砚格过滤,是可能的过滤输出时间,输出到用户的GET或POST中是否有敏感字符:

    输入过滤:
    过滤 ' " , <  >   <!--
    client: 开启 XSS filter 

    输出过滤(转义):
    转义: ' "   <  <!-- (转义为&#32; 等HTML硬编码)
    过滤: <script> href </script>模型 , window.location 模型 等

    浏览器防御:IE 8 以上的内核 开启 XSS filter ,chrome ctrl+ shift + N  开启隐身浏览 , firefox Noscript 插件

    事实上有非常多測试XSS攻击的工具:

    Paros proxy (http://www.parosproxy.org)
    Fiddler (http://www.fiddlertool.com/fiddler) (点击Toolbar上的"TextWizard" button)
    Burp proxy (http://www.portswigger.net/proxy/)
    TamperIE (http://www.bayden.com/dl/TamperIESetup.exe)

    以下贴一个 常见的php过滤XSS的函数:
    <?PHP
    /**
     * @blog http://www.phpddt.com
     * @param $string
     * @param $low 安全别级低
     */
    function clean_xss(&$string, $low = False)
    {
        if (! is_array ( $string ))
        {
            $string = trim ( $string );
            $string = strip_tags ( $string );
            $string = htmlspecialchars ( $string );
            if ($low)
            {
                return True;
            }
            $string = str_replace ( array ('"', "\", "'", "/", "..", "../", "./", "//" ), '', $string );
            $no = '/%0[0-8bcef]/';
            $string = preg_replace ( $no, '', $string );
            $no = '/%1[0-9a-f]/';
            $string = preg_replace ( $no, '', $string );
            $no = '/[x00-x08x0Bx0Cx0E-x1Fx7F]+/S';
            $string = preg_replace ( $no, '', $string );
            return True;
        }
        $keys = array_keys ( $string );
        foreach ( $keys as $key )
        {
            clean_xss ( $string [$key] );
        }
    }
    //just a test
    $str = 'phpddt.com<meta http-equiv="refresh" content="0;">';
    clean_xss($str); //假设你把目光出来。你知道xss强大的攻击
    echo $str;
    ?>
    

    由clean_xss()要过滤恶意内容!
  • 相关阅读:
    贝塞尔曲线应用(贝塞尔插值)
    贝塞尔曲线原理(简单阐述)
    STL头文件有哪些及简单介绍
    句柄与MFC对象关系和相互获取
    Reflect
    Set 和 Map 数据结构
    Symbol
    对象的新增方法
    对象的扩展
    数组的扩展
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4590990.html
Copyright © 2020-2023  润新知