ãæ¡å¼µåã§ã¯ãªããå 容ã«ãã£ã¦ãã¡ã¤ã«ãéããã¨ãã®æ¡å¼µå㯠Content-Type ã§ã¯ãªããã¨ã«æ³¨æ
å°ãåã« JSONP ã XSS ãå¼ãèµ·ãããããããªãã¨ããç¹ã«é¢ããèå³æ·±ãè¨äºã奥ãããæ¸ããã¦ãã¾ããã
JSONP ã«ããã Padding é¨å(ã ãã§ãªãJSONé¨åãã4/5追è¨)ã«æ»æè
ã HTML ã¨è§£éå¯è½ãªã¹ã¯ãªããã注å
¥ãããã¨ã«ãããJSONP ãªãã¼ã¿ãç´æ¥ IE ã§éããå ´åã« HTML ã¨è§£éãã XSS ãçºçãããã¨ããç¹ã«ã¤ãã¦æ¸ããã¦ãã¾ãã
ããã§ãIE ã JSONP ã HTML ã¨è§£éããçç±ã¯ä»¥ä¸ã®2ç¹ã
- IEã®ããç¥ãããæ©è½ãæ¡å¼µåã§ã¯ãªããå 容ã«ãã£ã¦ãã¡ã¤ã«ãéããã¨ãã«ãããå 容ã HTML ã£ã½ãå ´åã«ã¯ãContent-Type: text/javascript ãç¡è¦ãã HTML ã¨ãã¦è§£éãããã
- ä¸è¿°ã®è¨å®ããç¡å¹ãã«è¨å®ãã¦ããå ´åã§ããURL path ã®æ¡å¼µåã¨æããé¨åã以ã£ã¦ãã¡ã¤ã«ã¿ã¤ãã決å®ããå¯è½æ§ããããã¨ã
åè ã«ã¤ãã¦ã¯èª¬æããã¾ã§ããªããããç¥ããã話ã§ããã¨æãã¾ããå¾è ã«ã¤ãã¦ã¯ãIE ã§ã¯ã¬ã¹ãã³ã¹ãããã® Content-Type: ãã¬ã¸ã¹ã㪠HKCR\MIME\Database\Content Type å ã«è¦ã¤ãããªãå ´åã¯ãPATH_INFO (ããããã㨠QUERY_STRING ã)ã«å«ã¾ããæ¡å¼µåã¨æããé¨åãå©ç¨ãã¦ãã¡ã¤ã«ã¿ã¤ãã決å®ãã¾ããä¾ãã°ã次ã®ãã㪠CGI <http://example.com/cgi-bin/dynscript.js> ããã£ãã¨ãã¾ããå¤æ° s ã®å 容ã¯ãæ»æè ãããç¨åº¦*1è¨å®ã§ãããã®ã¨ãã¾ãã
#!/bin/sh echo "Content-Type: text/javascript" echo "" echo "var s = \"<html><script>alert(document.location);</script></html>\";" echo "alert( s );"
ãã® CGI ã«å¯¾ã㦠IE 㧠http://example.com/cgi-bin/dynscript.js ã«ã¢ã¯ã»ã¹ããå ´åã¯ãJScript ãã¡ã¤ã«ãéããã©ããã®ãã¤ã¢ãã°ã表示ãããã¦ã¼ã¶ã®ç¢ºèªãå¾
ã£ã¦å®è¡ããã¾ããã¨ãããåãCGIã«å¯¾ãç¡ç¨ãª PATH_INFO ãä»ä¸ãhttp://example.com/cgi-bin/dynscript.js/test.html ã¨ãã¦ã¢ã¯ã»ã¹ããå ´åã«ã¯ããã¡ã¤ã«ã¯ HTML ã¨è§£éãããããã«ãç¡æ¡ä»¶ã«å¤æ° s å
ã®ã¹ã¯ãªãã" alert(document.location) "ãå®è¡ããã¦ãã¾ãã¾ãã
ã¨ããããã§ãtext/javascript ã®ãããªãIE ãç´ ç´ã«è§£éã§ããªã(åè¿°ããã¬ã¸ã¹ããªã«ã¨ã³ããªãåå¨ããªã) Content-Type: ãåãåºãWebã¢ããªã±ã¼ã·ã§ã³ã¯æ³¨æãå¿
è¦ã¨ãããã¨ã«ãåãã¦æ°ãã¤ããã®ã§ããã
ã¡ãªã¿ã«ããã®åé¡ã¸ã®å¯¾å¿ã¨ãã¦ã奥ããã®è¨äºã§ã¯
1. padding ã«ä½¿ç¨ã§ããæåãå¶éãã
2. json ã³ã³ãã³ãå ã® < ãã¨ã¹ã±ã¼ããã
3. ã¬ã¹ãã³ã¹ããã㧠charset ãæå®ãã
ã¨ãããã¨ãæãã¦ãã¾ããããã¯ã³ã¡ã³ãæ¬ã«ãæ¸ããã¦ããã¨ãã
HTML ã¨ãã¦è§£éããã¦ãåé¡ãªãããã«ããã¢ããã¼ãã®ã»ããæ±ç¨ç
ã¨ããèãã«ãããã®ã ããã§ãã
éã«ãHTMLã¨ãã¦è§£éãããªãã¨ããã¢ããã¼ãã¨ãã¦
- Content-Type: text/plain ã®ãããªç¡å®³ãªã¬ã¹ãã³ã¹ããããè¿ã
- ãæ¡å¼µåã§ã¯ãªãâ¦ãã«ããèªåå¤å®ãåé¿ãããããå é ã«ã¹ãã¼ã¹ã512ãã¤ãç¨åº¦ä»å ãã
ã¨ããæ段ãããã¾ãã
#!/bin/sh echo "Content-Type: text/plain" echo "" printf "%512s" " " echo "" echo "var s = \"<html><script>alert(document.location);</script></html>\";" echo "alert( s );"
ãã¡ããã奥ããã«ãããHTMLã¨è§£éããã¦ãå®å ¨ã«åä½ãããã¢ããã¼ãã¨ããHTMLã¨è§£éãããªãããã«ããã¢ããã¼ããã®ä¸¡æ¹ãçµã¿åããããã¨ãã§ããã¨æãã¾ãã