Exterinterface.call xss

http://lcamtuf.blogspot.com/2011/03/other-reason-to-beware-of.html

March06,2011

TheotherreasontobewareExternalInterface.call()

AdobeFlashhasafunctioncalledExternalInterface.call(...),whichimplementsaJavaScriptbridgetothehostingpage.Ittakestwoparameters:thefirstoneisthenameoftheJavaScriptfunctiontocall.Thesecondoneisastringtopasstothisfunction.

Itisunderstoodthatthefirstparametershouldnotbeattacker-controlled(ofcourse,mistakeshappen:-).Itisalsounderstoodthatthereisnoinherentharminputtinguserinputinthesecondparameter,ifthecallbackfunctionitselfisnotbehavingstupidly;infact,Adobedocumentationgivesanexamplethatfollowsthisverypattern:

...

ExternalInterface.call("sendToJavaScript",input.text);

...

Suchacallwouldbetranslatedtoaneval(...)statementinjectedontheembeddingpage.Thisstatementlooksroughlythefollowingway:

try{

__flash__toXML(sendToJavaScript,"valueofinput.text"));

}catch(e){

"<undefined/>";

}

Whenwritingthesupportingcodebehindthiscall,theauthorsrememberedtousebackslashescapingwhenoutputtingthesecondparameter:hello"worldbecomeshello\"world.Unfortunately,theyoverlookedtheneedtoescapeanystraybackslashcharacters,too.

So,trytofigureoutwhathappensifthevalueofinput.textissettothefollowingstring:

Helloworld!\"+alert(1));}catch(e){}//

IreportedthisproblemtoAdobeinMarch2010.InMarch2011,afterfollowingup,Ireceivedthefollowingresponse:

"Wehavenotmadeanychangetothisbehaviorforbackwardscompatibilityreasons."

Caveatemptor:-)

解决时发现这个xss是攻击者利用了Adobe的一个已知漏洞,我们简称之为ExternalInterface.call注入,此漏洞于2010.03已经被report给Adobe了,但是被Adobe拒绝修复,官方回复是:"Wehavenotmadeanychangetothisbehaviorforbackwardscompatibilityreasons."详细可以参考:http://lcamtuf.blogspot.com/2011/03/other-reason-to-beware-of.html简单来说,Adobeflash里提供了一个调用外部js的方法ExternalInterface.call(...),此方法有两个参数,第一个参数是要调用的js函数名,第二个参数是传递给这个函数的参数。这个call方法使用了eval实现函数的调用,最后生成的代码有一段是:try{__flash__toXML(js_function,"params"));}catch(e){"";}很明显,参数params里面不能有“"”,以防止try块里面的函数调用被破坏,Adobe的开发人员也注意到了这一点,所以他们会转义掉“"”。例如,params如果是xxx"yy,那么会转成xxx\"yy。但是,他们忘了转义“\”,所以如果params是xxx\"yy,那么最后得到的是xxx\\"yy。注入漏洞就此产生。攻击者可以构造这样的params来进行xss攻击:1:\",alert(1)));}catch(e){}//2:\"))}catch(e){alert(2)}//经由Adobeeval生成的js代码则大致如下:try{__flash__toXML(js_function("\\",alert(1)));}catch(e){}//"));}catch(e){"";}try{__flash__toXML(js_function("\\"))}catch(e){alert(2)}//"));}catch(e){"";}可以看到,如果你在flashas代码里使用了flash.external.ExternalInterface.call(),并且直接使用用户输入作为第二个参数的话,那么你就存在上面论述的xss风险。我们建议的修复方案是,对第二个参数做限制,使用前对用户输入进行过滤,一般来说,过滤掉\、/这样的特殊字符即可,具体可由实际需要而定。也可以不允许使用用户输入作为第二个参数。seanzhu,本内容来自腾讯内部分享,请勿外传!

xss

相关推荐