百度空间 | 百度首页 
               
 
查看文章
 
ASJS通信盒子之百度空间相册
2008-01-30 22:24

Flash与时下流行的Flex(Adobe给出的RIA解决方案,我才开始接触:-()使用的编程语言皆为ActionScript。而JavaScript主要被用于web客户端进行数据的逻辑控制。这两个脚本语言之间的通信模型我称之为ASJS通信盒子

研究这个,我的目的是给XSS增加点新鲜血液,其中会涉及到XML XSS(本文无)。这次的研究对象为百度空间相册,在空间首页中显示的相册功能模块。虽然有好几次的心跳,但还是没XSS成功~~~不过这次分析还是有收获的。比如:我开始写这篇文章了^^

http://www.xsscos.com/test.php?xss=hello-world这样格式的url不陌生吧?值为hello-world的xss以GET方式传输到服务端,在服务端以$xss = $_GET['xss']这样的格式来接收url中的xss值。本文不涉及服务端编程,所以就这样简要介绍。再来看看这样格式的url:http://www.xsscos.com/test.html?xss=hello-world。假设这时的test.html为静态HTML文件,我们用js来获取问号?之后的xss的值!如下代码:

<script language=javascript>
function getparastr() {
    var hrefstr,pos,parastr;
    hrefstr = window.location.href;
    pos = hrefstr.indexOf("?");
    parastr = hrefstr.substring(pos+1);
    return parastr;
}
var parastr = getparastr();
//此时parastr值为xss=hello-world
</script>

百度空间首页的相册功能模块改版了,使用flash了!许多参数传进传出的,研究好其通信机制,将会方便我们XSS,虽然会经常失败。百度空间使用CreateFlash("m_flaShow","roll", "/ui/flash/album/main.swf", _fw, _fw*0.67,arg);脚本来动态创建相册,其中CreateFlash函数为:

function CreateFlash(obj,idad, swfurl, wad, had, vs){
var str = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' ";
if(wad) str += "width='" + wad + "' ";
if(had) str += "height='" + had + "' ";
str += "id='" + idad + "' align='middle'>";
str += "<param name='allowScriptAccess' value='always'>";
str += "<param name='quality' value='high'>";
str += "<param name='movie' value='" + swfurl + "'>";
str += '<param name="wmode" value="transparent">';
str += "<param name='flashvars' value='" + vs + "'>";
str += "<embed src='" + swfurl + "' flashvars='" + vs + "' wmode="window" quality='high' "
if(wad) str += "width='" + wad + "' "
if(had) str += "height='" + had + "' ";
str += "name='" + idad + "' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'>";
str += "</object>";
G(obj).innerHTML=str;
}

很容易理解,我就不介绍每个参数的含义了。当我们使用CreateFlash()函数时,它创建了<object>标签体,用来动态加载flash文件http://hi.baidu.com/ui/flash/album/main.swf重点在flashvars!flashvars的值将被<object>标签体中的flash文件的as脚本获取,于是从js到as的通信步骤就完成了!那么flashvars的值是什么呢?从上面可以看出flashvars的值为arg,而arg在这之前声明如下:

var arg="xml=/coscmic/albumdata?type=27&subtype=0&style=3&mask=6&effect=3&edit=0&album=默认相册&t="+Math.random();
arg=arg.replace(/%/g,"%25").replace(/&/g,"%26");

其实我们是可以构造伪客户端的,其中style/mask/effect/album这四个参数都可以伪造,不过遗憾的是,服务端只允许style/mask/effect为长整形!而album参数的所有邪恶字符都会被过滤。所以我们就不用去考虑服务端注入或者XSS了,其实静下心来想想,XSS能发生在Flash文件中么?似乎不可能!为了更加透明地研究ASJS通信盒子,我下载了http://hi.baidu.com/ui/flash/album/main.swf文件,并对其进行了反编译,得到关键as源码如下(看注释):

//所有变量的声明都在此as代码底部
function getData(xml)
{
    myData.load(xml);
//myData为XML对象。加载xml文件,即上面js代码中的flashvars的值:http://hi.baidu.com/coscmic/albumdata?type=27&subtype=0&style=3&mask=6&effect=3&edit=0&album=默认相册&t=xxxxxx(我将路径补全)
    myData.onLoad = function (success)
    {
        if (success)
        {
            loading_mc._visible = false;
            if (this.firstChild.attributes.num != 0)
//如果图片数不为零时
            {
                photo_num = this.firstChild.childNodes.length;
//当前图片数
                effect_swf = this.firstChild.attributes.effect;
//当前相册播放样式
                mask_swf = this.firstChild.attributes.mask;
//当前相册背景边框
                style_swf = this.firstChild.attributes.style;
//当前相册动画特效
//看到没?这些值都来自前面的js文件,其中经历了XML这一个数据层
                var _loc4 = this.firstChild.childNodes;
                for (var _loc3 = 0; _loc3 < photo_num; ++_loc3)
                {
                    photo_s[_loc3] = _loc4[_loc3].attributes.s;
                    photo_u[_loc3] = _loc4[_loc3].attributes.u;
                } // end of for
                if (this.firstChild.attributes.edit == "1")
                {
                    isEdit = true;
                }
                else
                {
                    isEdit = false;
                } // end else if
                _root.onEnterFrame = function ()
                {
                    stage_width = Stage.width;
                    stage_height = Stage.height;
                    if (stage_width != 0 && stage_height != 0)
                    {
                        delete _root.onEnterFrame;
                        _root.gotoAndStop(3);
                    } // end if
                };
            }
            else if (this.firstChild.attributes.num == 0 && this.firstChild.attributes.edit == 0)
            {
                _root.onEnterFrame = function ()
                {
                    stage_width = Stage.width;
                    stage_height = Stage.height;
                    if (stage_width != 0 && stage_height != 0)
                    {
                        delete _root.onEnterFrame;
                        if (myData.firstChild.attributes.owner == 1)
                        {
                            update_url = myData.firstChild.attributes.url;
                            showEmptyInfo(1);
                        }
                        else
                        {
                            showEmptyInfo(0);
                        } // end if
                    } // end else if
                };
                photo_Empty = true;
            }
            else if (this.firstChild.attributes.num == 0 && this.firstChild.attributes.edit == 1)
            {
                photo_num = this.firstChild.childNodes.length;
                effect_swf = this.firstChild.attributes.effect;
                mask_swf = this.firstChild.attributes.mask;
                style_swf = this.firstChild.attributes.style;
                _loc4 = this.firstChild.childNodes;
                for (var _loc3 = 0; _loc3 < photo_num; ++_loc3)
                {
                    photo_s[_loc3] = _loc4[_loc3].attributes.s;
                    photo_u[_loc3] = this.firstChild.attributes.url;
//这个url就是我们的album值,即相册名称!
                } // end of for
                isEdit = true;
                _root.onEnterFrame = function ()
                {
                    stage_width = Stage.width;
                    stage_height = Stage.height;
                    if (stage_width != 0 && stage_height != 0)
                    {
                        delete _root.onEnterFrame;
                        _root.gotoAndStop(3);
                    } // end if
                };
                photo_Empty = true;
            } // end else if
        }
        else
        {
            empty_info_mc.info_text.html = true;
            empty_info_mc.info_text._width = Stage.width;
            empty_info_mc._y = (Stage.height - empty_info_mc._height) / 2;
            empty_info_mc.info_text.htmlText = "无法加载到图片数据,请稍候再试。";
            loading_mc._visible = false;
        } // end else if
    };
} // End of the function
function showEmptyInfo(type)
{
    empty_info_mc.info_text.html = true;
    empty_info_mc.info_text._width = Stage.width;
    empty_info_mc._y = (Stage.height - empty_info_mc._height) / 2;
    var _loc1 = new TextFormat();
    _loc1.underline = true;
    trace (type);
    if (type == 1)
    {
        empty_info_mc.info_text.htmlText = "<a href=\'" + update_url + "\' target=\'_blank\'>还没有照片?立即上传!</a>";
        empty_info_mc.info_text.setTextFormat(_loc1);
    }
    else
    {
        empty_info_mc.info_text.htmlText = "暂无照片,或需要权限查看!";
    } // end else if
} // End of the function
stop ();
System.useCodepage = true;
var stage_width = Stage.width;
var stage_height = Stage.height;
var photo_s = new Array();
var photo_u = new Array();
var effect_swf;
var mask_swf;
var style_swf;
var photo_num = 0;
var update_url;
var isEdit = false;
var photo_Empty = false;
var myData = new XML();
myData.ignoreWhite = true;
getData(xml);

到此,百度空间首页的相册功能模块分析完毕。本文开始提到的http://www.xsscos.com/test.html?xss=hello-world这个url,其实是js通信的一种手段,结合ASJS通信盒子,在某些情况下,XSS会更加灵活。本文仅介绍了从JS到AS的通信过程,技术并不新颖,但是在研究过程中保持邪恶的思维,你就会发现这样的研究很有趣,随后我将继续研究AS到JS的通信(其实我早就掌握了,只是这次要保持邪恶的思维再次研究一遍)。随着RIA技术的泛滥,XSS手段将越来越精彩。

最后气馁地说:大家别打百度空间相册功能模块的主意了,成功不了的!不过你可以到我的测试空间去看看http://hi.baidu.com/coscmic。也许会有好玩的。呃,也许高手能成功吧?


类别:As Hack | 添加到搜藏 | 浏览() | 评论 (7)
 
最近读者:
 
网友评论:
2
2008-01-30 22:38 | 回复
晕晕的...感觉自己什么都不知道...还是多多学习吧...
 
3
2008-01-30 23:38 | 回复
555……我是认识hello-world
 
4
2008-01-31 08:54 | 回复
技术是不新颖,弄个参数传来传去。不过这种架构还是很值得研究的。 核心思想和分层开发的是一样的。 不过你的研究出发点也。。。。。哈哈哈
 
5
2008-01-31 11:12 | 回复
呵呵,总得找个对象来分析分析。
 
6
2008-01-31 11:47 | 回复
百度很多值得研究,呵呵 BAIDU在慢慢强大,感觉
 
7
2008-01-31 11:59 | 回复
百度空间这些工程师,呵呵。很好。
 
8
2008-02-09 21:02 | 回复
天书。。。
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu