ASJS通信盒子之百度空间相册

作者:ycosxhack
来源:余弦函数

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的值!如下代码:

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

百度空间首页的相册功能模块改版了,使用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 = "";
str += "
";
str += "
";
str += "
";
str += '
';
str += "
flashvars
' value='" + vs + "'>";
str += "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 += "";
G(obj).innerHTML=str;
}
很容易理解,我就不介绍每个参数的含义了。当我们使用CreateFlash()函数时,它创建了标签体,用来动态加载flash文件http://hi.baidu.com/ui/flash/album/main.swf。重点在flashvars!flashvars的值将被标签体中的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 //这个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 = "还没有照片?立即上传!";
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。也许会有好玩的。呃,也许高手能成功吧?

相关日志

发表评论