Chinaunix首页 | 论坛 | 博客
  • 博客访问: 165474
  • 博文数量: 64
  • 博客积分: 3366
  • 博客等级: 中校
  • 技术积分: 765
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-10 10:32
文章分类

全部博文(64)

文章存档

2012年(5)

2011年(22)

2010年(37)

我的朋友

分类: 网络与安全

2010-05-15 14:47:02

百度空间的宠物插件对用户输入变量未经任何过滤便存储,并不经过滤输出,造成XSS

 
1.在中,用户可以输入留言管理,提交后,未过滤直接储存.
2.在中
 
将输出一段HTML:

'+F[2]+"说:"+BdUtil.insertWBR(F[0], 4)+'


其中BdUtil.insertWBR为
function(text, step) {
    var textarea = textAreaCache || getContainer();
    if (!textarea) {
        return text;
    }
    textarea.innerHTML = text.replace(/&/g, "&").replace(//g, ">");
    var string = textarea.value;
    var step = step || 5, reg = new RegExp("(\S{" + step + "})", "gi");
    var result = string.replace(/(<[^>]+>)/gi, "$1").replace(/(>|^)([^<]+)(<|$)/gi, function (a, b, c, d) {if (c.length < step) {return a;}return b + c.replace(reg, "$1") + d;}).replace(/&([^;]*)()([^;]*);/g, "&$1$3;");
    return result;
}
在首页中,textAreaCache 和 getContainer()均不存在,故!textarea为true,未经过滤直接return text.造成XSS.
测试代码:
宠物留言管理处输入:
 
 
 
二:creatbgmusic() Dom-Xss Bug
 
百度空间的Javascript Dom函数creatbgmusic()在输出变量bgmusic*没有进行过滤,导致可以通过initBlogTextForFCK()函数构造容易HTML代码,最终导致xss漏洞
 
在 代码:
 
function creatbgmusic(murl, musicnum, IsMusicHide, IsMusicLoop, IsMusicAutoPlay, unknow, functype) {
    //传入的murl赋值到bgmusic1和bgmusic2中
    //可以通过构造类似代码来闭合标签如 ">";document.body.appendChild(s);>#1
    var bgmusic1 = "" + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " ";
    if (musicnum <= 1) {
        bgmusic1 += " ";
    }
    bgmusic1 += "
";
    var bgmusic2 = "    if (musicnum <= 1) {
        bgmusic2 += "showcontrols="1" showpositioncontrols="0" ";
    }
    bgmusic2 += "> ";
    var bgmusic3 = "
u5BF9u4E0Du8D77uFF0Cu60A8u5C1Au672Au5B89u88C5windows media playeruFF0Cu65E0u6CD5u6B23u8D4Fu8BE5u7A7Au95F4u7684u80CCu666Fu97F3u4E50uFF0Cu8BF7u5148u4E0Bu8F7Du5E76u5B89u88C5

";
    var bgmus = detectWMP();
    if (functype == "FckMusicHelper") {
        if (bgmus.installed) {
            if (bgmus.type == "IE") {
                return bgmusic1;
            } else if (bgmus.type == "NS") {
                return bgmusic2;
            }
        } else {
            return bgmusic3;
        }
    } else {
        if (bgmus.installed) {
            //document.write 直接输出bgmusic变量 导致xss
            if (bgmus.type == "IE") {
                document.write(bgmusic1);
            } else if (bgmus.type == "NS") {
                document.write(bgmusic2);
            }
        } else {
            document.write(bgmusic3);
        }
        return "";
    }
}
 
在看百度空间里的initBlogTextForFCK()函数,调用了creatbgmusic() ,代码如下:
 
function initBlogTextForFCK(){
 //fck init music
 if(window.Node){Node.prototype.replaceNode=function(Node){this.parentNode.replaceChild(Node,this);}}
 var imgBox=document.getElementsByName('musicName');   //取得了文章中的所有name="musicName"的标签数组
 var isAutoPlay=true;
 for(var i=0,n=imgBox.length;i  var img=imgBox[i];
  if(img.getAttribute('rel')){     
   var musicSrc=img.getAttribute('rel');    //取得标签中rel的值,赋值给musicSrc
   var musicDiv = document.createElement("SPAN");
   var tmp=musicSrc.substr (musicSrc.indexOf('#')+1, 1);  //以"#"为界分割musicSrc字符串,提取自动播放的flag[tmp]
  
      ..........................
  
   //直接将部分musicSrc传入creatbgmusic函数.在creatbgmusic函数直接把传入的murl赋值到bgmusic1和bgmusic2中并document.write出来.
   var shtml=creatbgmusic(musicSrc.substr(0,musicSrc.indexOf('#')),1,true,false,tmpAutoPlay,tmpAutoPlay,'FckMusicHelper');
   shtml=shtml.replace('width=100%','width=200').replace('width="100%"','width=200 height=45');   img.replaceNode(musicDiv);
   musicDiv.innerHTML=shtml;
   i--;n--;
  }
 }
 
从上面的代码分析可以看出:在所有的参数传递中,我们没有看到过滤.百度空间的富文本编辑器的过滤模式是基于HTML语法的,不会过滤掉一个属性的值中的HTML标签.所以我们可以精心构造一个的恶意的标签,在JS进行DOM操作后引起XSS.
 
 
 
测试方法: 
NEW POC:
 

本文转自 ☆★ 包罗万象网 ★☆ - 转载请注明出处,侵权必究!
原文链接:

阅读(1150) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~