JSONãã¼ã¿ãã¯ãã¹ãã¡ã¤ã³ã¢ã¿ãã¯ããå®ãããã«while(1)ã使ããã¨ãããã¾ããã
ããã¯ãªã«
æ¢ã«ãåç¥ã®æ¹ãããã£ããããã©ãããç¥ãã¾ãããä»ãã£ãé¢é£æç®ã«è¡ãå½ãã£ã¦é©æããã®ã§å¿µã®ããã«ã¡ã¢ãæ¸ãã¦ããã¾ããç§ã¯ã¡ã¼ãªã³ã°ãªã¹ããªã©ã«å å ¥ãã¦ãã¾ããã®ã§è«è°ãæ¸ãã§ãããã©ãããç¥ããªãã®ã§ãããããã¦ã§ãä¸ã«è§£èª¬è¨äºãããããã§ãããéã«ç§ã«æ¯éã¨ãæãã¦ãã ããã
JSONãã¼ã¿ã®å é ã«
JSONãã¼ã¿ã®å é ã«while(1)ãç½®ãã¦ãããã¨ã§ç¡éã«ã¼ããçºçããã¦ããã¦ãååçæ»æã®ãã¼ã¸ã®æªæããscriptã®å®è¡ã失æãããã¨ããã¢ã¤ãã¢ã«ã¯æ¬ ç¹ãããã¨ãããã¨ããå ç¨ã¨ããæç®ããç¥ãã¾ãããããã¯while(true)ã«ã¤ãã¦ãåæ§ã§ããJavaScriptã¯æè»ã§å¼·åãªè¨èªã§ãããããã©ã¦ã¶ãJavaScriptã¨ã³ã¸ã³ãã¾ããã«å®è£ ãã¦ããã®ã§ããã°ãã¢ã¿ãã¯ã®ãã£ã³ã¹ãä¸ãã¦ãããã¨ã«ãªãã¾ãããããããã¯ãã©ã¦ã¶ã®èå¼±æ§ã¨ã¯æãããã¾ãããããããJavaScriptããã®ãããªè¨è¨ãªã®ã§ããããæ»æè ã¯ãããã¿ã«ä½æããããã¼ã¸ã«ãã£ã¦èªã¿è¾¼ã¾ããå¤é¨scriptï¼è¦ããã«ã¿ã¼ã²ããã¨ãªãJSONãã¼ã¿ãã¯ãã£ã¦ããJSãã¡ã¤ã«ï¼ã®å é ã«ããwhile(1)ãç¡å¹ã«ãã¦ããããwhile(0)ã§ãããã®ããã«ãã¦ãã¾ããã¨ãå¯è½ã§ããåæ§ã«while(true)ã¯while(false)ã¨å¤è²ãã¦ãã¾ãã¾ããç¡éã«ã¼ãã«ãªãã¾ããããããã¦ãã¼ã¿ãçã¾ãããã¨ã«ãªãã¾ããNumberãBooleanã®æå³ãã³ã³ã¹ãã©ã¯ã¿çµç±ã§æ¸ãæããã®ã ããã§ããJavaScriptHijackingã¨ããååã§æåãªå è¡äºä¾ã®Arrayã®æã¨ææ³ãã»ã¼åãã§ããã
ç¾æç¹ã§ç¹å®ãã©ã¦ã¶ã«é©ç¨å¯è½ãªexploitãçºè¦ããã¦ããã¨ããããã§ã¯ããã¾ãããããããªãããã®ãããªèç¶æ§ãJavaScriptã®è¨èªä»æ§ã¨ãã®å®è£ ã«ãã£ã¦ã¯ããããã¨ãããã¨ãªã®ã§ãã
ç°¡åãªè§£æ±ºç
while(1)ã«æ¿ãã¦ãfor(;;)ã使ãã¾ãã ã¾ã¨ããªJavaScriptã¨ã³ã¸ã³ã¯forã®ä¸æ¸ãã許ãã¾ãããJavaScriptã®è¨èªã®è¨è¨ã«ã¯ãã®ãããªçºæ³ã¯ãªãããã§ããå¾ã£ã¦æå³ããç¡éã«ã¼ããç ´å£ã§ãã¾ãããå ç¨ç§ãèªãã æç®ã®èè ã®ç ç©¶è ã«ããã°å ¨ã¦ã®ãã©ã¦ã¶ã§æ¤æ»æ¸ã¿ã ããã§ãã
ãã£ã¨å¼·åãªè§£æ±ºæ³
HTTPã®GETãåãã¦ã®JSONãã¼ã¿ãé ä¿¡ãã¹ãã§ã¯ããã¾ããããµã¼ãã§ã¯POSTã®ã¿ãåãä»ããã¹ãã§ãããã©ã¦ã¶å´ã®XHRã§ãPOSTãã¦ããã°ããã®ã§ãããã®æãç¡éã«ã¼ãã«ããé²è¡ã¯æå³ã¯ãªãã®ã§åã£ã¦ãã¾ã£ã¦ãè¯ãã§ãããã
追è¨ï¼3/30ï¼
Kanatokoããã徳丸ããã«æ å ±ã½ã¼ã¹ãæãã¦ããã ãã¾ããã大å¤ãããã¨ããããã¾ãããBilly Hoffman (è), Bryan Sullivan (è), GIJOE (ç£ä¿®, 翻訳), 渡é äºä» (翻訳) ã®ããAjaxã»ãã¥ãªã㣠(åè¡æ¬ï¼ã½ããã«ãã¼ï¼) ãã ããã§ããhoshikuzu ã¯ã¨ããä¼ç¤¾ã®åå¼å çµç±ã§è©²å½é¨åãå«ããããããªè³æã®PDFãé ããã®ã§ããããã£ããä¸è¨ã®æ¬ãè¦ã¦ã¿ããã¨æãã¾ãããã ãã徳丸ããã«ããã°èå¿ã®ã»ãã¥ãªãã£å¯¾çé¨åã«ã¤ãã¦ã¯å¼±ãæ¸ç±ãªã®ã ããã§ããè³¼å ¥ãã©ããã¾ããããâ¦çµè²»ã§è½ã¡ãªããã§ããããJSON-Hijackã«ã¤ãã¦ã¯setterãgetterã使ããªãææ³ãæ¸ãã¦ããã¨ããã®ã§ããã ãã§ãè¦ããæ°ããã¾ããâ¦
追è¨(3/31)
Billy Hoffmanæ°ã«ããããé ååã®ãJSONãã¼ã¿ã®HIJACKINGã«é¢ããPoCã以ä¸ã«ãä¸è¨èæ¸ããã®å¼ç¨ã§ããï¼æ°å¤ã³ã³ã¹ãã©ã¯ã¿ã«é¢ããPoCã¯ç¾åãã¦ããªããã¨æãã¾ã)
â¦ã¨ããã§ãã®æ¬ãé»åããã¯ã¨ãã¦ãããä¸ã«ããã®ã§ããæ¨©å©é¢ä¿ã«ã¤ãã¦ã¯èª¿ã¹ããã¾ããã§ããããã¿ã¾ããã宣ä¼ã«ãªãããè¯ãã¨ãã¦ãã ãããï¼ä¸æ¹ãæ¬æ¥è¨ã®ä¸ã®æ¹ã§ãªãã°ããªãã¦ããã¾ããã»ã»ï¼
Here we have a literal array defined. Internally, the JavaScript interpreter calls the array constructor function Array() to create an array object from the supplied array literal. Next, the JavaScript interpreter checks to see if an operation is performed on this array. For example, [1, 2, 3].join(",") is perfectly valid JavaScript code. However, in this block of JavaScript no operations are performed on this array. Because the array object was never assigned to a variable, it is unreferenced, and the object will eventually be cleared by the JavaScript interpreter's garbage collection routines. Thus, by pointing a SCRIPT tag at an Ajax endpoint on a Web server that returns JSON, we can force the JavaScript interpreter to execute the array constructor function Array().
We know from the "Hijacking Ajax Frameworks" section earlier in the chapter that JavaScript code can clobber other functions, including internal functions. It turns out we can clobber the Array() function as well! An attacker can replace the array constructor with their own malicious version, which can capture all the contents of the array and send them to a third party and capture the method. Consider the following piece of code.function Array() {
var foo = this;
var bar = function() {
var ret = "Captured array items are: [";
for(var x in foo) {
ret += foo[x] + ", ";
}
ret += "]";
//notify an attacker. Here we just display it
alert(ret);
};
setTimeout(bar, 100);
}In our malicious array function, we set the variable foo equal to the current object (the array that is being created).We also create an anonymous function bar(), which will iterate all the properties of the variable foo (all the items stored in the array). All the data collected is simply displayed to the user, but it is trivial for an attacker to send this data to a third party using an Image object. The last thing the evil array constructor does is use the setTimeout() function to call our bar() function after 100 milliseconds. This ensures that by the time the bar() function is called, the elements in our array literal have been properly loaded into the array so that our bar() function can steal the contents.
hoshikuzu註::ãã®éãå¤§å¹ ã«çç¥ãã¦ãã¾ãã
Second, for(;;); consists of nothing but a JavaScript keyword and some symbols. There is no way an attacker can clobber or override the for keyword. Some people suggest using while(1);. This is not an ideal solution because 1 is a numeric literal, and it could be possible that some JavaScript interpreters would invoke the number constructor function Number () when a numeric literal is encountered. An attacker could conceivably use this=0; inside a malicious number constructor and literally redefine the value of 1, making the while conditional evaluate to false, which in turn causes the JavaScript interpreter to fall through to the JSON literal.
The same possibility could apply to using while (true); as an infinite loop and boolean literals. The authors currently know of no JavaScript interpreters that do this, but it certainly is possible that one might do so in the future. As a security-conscious developer, you must think not only about how to secure your application now, but how you can secure your application in such a way that minimizes the chance it will become insecure in the future due to technological changes.
追è¨ãã®ï¼(3/31)
ãã®æ¬ã®æ¥æ¬èªçã§ã¯Arrayã³ã³ã¹ãã©ã¯ã¿ã®æ¹é ã«ãã£ã¦JSONãã¤ã¸ã£ãã¯ãåºããã®ã¯Firefoxã®ï¼ç³»åã ã¨ããã話ããªã®ã§ããããããããIEã§ã¯ã©ããï¼ã¨ããè«è°ããããä¸ã«åºã¦ããããã§ããFirefox2ã§ãã£ã¦getterãsetterã使ããªãã¨ãPoCãæç«ããã®ãªãï¼æåã®JSONãã¤ã¸ã£ãã¯ã®ææ³ã¯getterãsetteré¢é£ã使ã£ã¦ããã®ã§ãã©ã¦ã¶ç¬èªã®æ¡å¼µã«ä¾åãã¦ãã¾ãããããã®å¶ç´ãã¨ããã°ï¼ã¨ããåæã§ãIEã§ã工夫次第ã§ã¯ï¼ã¨ããçºæ³ã®ããã§ãããã®è«è°ã«ã¤ãã¦ãããªãç§ã§ã¯ããã¾ããâ¦å¼ç¨ãããã¨ã ãã§ããã¦ããã¾ããå¾å¦ã®ããã«ã
ã©ããããããªã¼æ°ã®PoCã§ã¯functionæã使ã£ã¦ããã®ã«å¯¾ãã¦ããã®è«è°ã§ã¯æ¿ããã«functionãªãã©ã«ã使ãã¨è¯ãã®ã§ã¯ï¼ã¨ããææ¡ã®ããã§ãããã©ãããªãã©ã ã颿°åããã°ããã®ã«ã¨ããã妿³ãå¹ãåºã¦ãã¾ãã¾ãããç¶ãã³ã¡ã³ãæ¬ã®è«è°ã§ã¯IEã®ä»ãFirefox3.02ãããã§ãéç¨ããå¯è½æ§ã調ã¹ã¦ããããã§ããâ¦ããã«èªã¿é²ãã¦ã¿ãã¨çµå±Hijackãæç«ããªããããã¨èªè§£ããç§ã§ãã
Calling the Array constructor in IEI had a conversation a while ago on email with Billy Hoffman about how in IE the Array constructor wasnât called when using [] to create arrays. The question is, was he right? Technically yes but actually no ;)
You see Arrays in JScript are actually objects and not arrays, so trying to overwrite the Array constructor will have no effect. However using the Object constructor does. I found this while hacking away in JSON to create my Twitter POC.
The is a strange quirk which although it technically is the same code it results in different behaviour. Take the following example:-
function Object() {
alert(arguments[0]);
}
([1,2,3]);That doesnât work butâ¦look at this example:-
var Object = function() {
alert(arguments[0]);
}
([1,2,3]);It works! Yay! Strange but true. Donât ask how I found this but it was either by fuzzing, playing around in Hackvertor or pure luck ;)
ã¨ããã§
It works! Yay!Strange but true.ãèªãã ã¨ãã«ç§ã®é ã®ä¸ã®ç¿»è¨³ã«ã¼ãã³ããã«ãã³ã®ãããå¼ã³åºãã¦ãã¾ããã䏿è°ã ãæ¬å½ã ãæ¬å½ã ã䏿è°ã ãããã§ããã®ã ï¼ãã¨å«ãã§ãã¾ããããããã