Home  >  Article  >  Operation and Maintenance  >  XSS attack principles and protection

XSS attack principles and protection

angryTom
angryTomforward
2019-11-30 14:27:073731browse

XSS attack principles and protection

简介

XSS(Cross Site Scripting, 跨站脚本攻击)又称是 CSS, 在 Web攻击中比较常见的方式, 通过此攻击可以控制用户终端做一系列的恶意操作, 如 可以盗取, 篡改, 添加用户的数据或诱导到钓鱼网站等

攻击原理

比较常见的方式是利用未做好过滤的参数传入一些脚本语言代码块通常是 JavaScript, PHP, Java, ASP, Flash, ActiveX等等, 直接传入到页面或直接存入数据库通过用户浏览器阅读此数据时可以修改当前页面的一些信息或窃取会话和 Cookie等, 这样完成一次 XSS攻击

例子

http://example.com/list?memo=<script>alert(“Javascript代码块”)</script>
http://example.com/list?memo=<strong οnclick=‘alert(“惊喜不断”)’>诱惑点击语句</strong>
http://example.com/list?memo=<img src=’./logo.jpg’ οnclick=‘location.href=“https://blog.csdn.net/qcl108”;’/>

以上例子只是大概描述了方式, 在实际攻击时代码不会如此简单

防御方法

防止 XSS安全漏洞主要依靠程序员较高的编程能力和安全意识

去掉任何对远程内容的引用 如 样式或 JavaScript等

Cookie内不要存重要信息为了避免 Cookie被盗, 最好 Cookie设置 HttpOnly属性防止 JavaScript脚本读取 Cookie信息

不要信任用户的输入, 必须对每一个参数值做好过滤或转译: (& 转译后 &), (4e23c0184842b6e6b1a902904a673e9c 转译后 >), (" 转译后 "), (\ 转译后 '), (/ 转译后 /), (;)等

本文来自 web服务器安全_网站安全防护教程 栏目。欢迎学习

The above is the detailed content of XSS attack principles and protection. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete