Ê×Ò³ Ê«´Ê ×Öµä °å±¨ ¾ä×Ó ÃûÑÔ ÓÑ´ð ÀøÖ¾ ѧУ ÍøÕ¾µØͼ
µ±Ç°Î»ÖÃ: Ê×Ò³ > ½Ì³ÌƵµÀ > ÍøÕ¾¿ª·¢ > WebÇ°¶Ë >

WebÊ©ÓÃÖеݲȫ©¶´

2012-07-26 
WebÓ¦ÓÃÖеݲȫ©¶´??1¡¢¡¾×Ö·ûµ¼ÖµÄXSS¡¿??? Web³ÌÐòÊä³öÒ³Ãæʱ»áÖ¸¶¨£¨»òʹÓÃĬÈϵģ©Ò»¸ö×Ö·û¼¯£¬¸æËßä¯ÀÀ

WebÓ¦ÓÃÖеݲȫ©¶´

?

?

1¡¢¡¾×Ö·ûµ¼ÖµÄXSS¡¿

??? Web³ÌÐòÊä³öÒ³Ãæʱ»áÖ¸¶¨£¨»òʹÓÃĬÈϵģ©Ò»¸ö×Ö·û¼¯£¬¸æËßä¯ÀÀÆ÷ÈçºÎ´¦Àí·µ»ØµÄÊý¾Ý£¬³£¼û×Ö·û¼¯ÓÐutf-8£¬GBK£¬gb2312µÈµÈ¡£¾­Ö¤Ã÷£¬IE¡¢Chrome¡¢FFµÈÔÚ´¦Àí¿í×Ö·û¼¯£¨Èçgb2312£¬GBK£©Ê±´æÔÚÎÊÌ⣬¿Éµ¼ÖÂһЩ°²È«¹æÔò±»Bypassµô£¬Òý·¢XSS°²È«Â©¶´¡£

????? ä¯ÀÀÆ÷ÔÚ½âÎöÒ»¸öÐÂ×Ö·ûʱ£¬Ê×ÏȶÁÈ¡Ò»¸ö×Ö½Ú£¬Èç¹û¸Ã×Ö½Ú£¨Valid×Ö½Ú£¬V×Ö½Ú£¬ÎÒÔÝÇÒÕâÑù³Æºô£©ÊÇÖ¸¶¨×Ö·û¼¯ÀïµÄij¸ö×Ö·û£¨¸Ã×Ö·ûÖÁÉÙÓÐÓÉÁ½¸ö×Ö½Ú×é³É£©µÄµÚÒ»¸ö×Ö½Úʱ£¬ÔòÊÔͼÓøÃ×Ö½ÚºÍÆäºóÐø×Ö½Ú¹¹³ÉÒ»¸öºÏ·¨µÄ×Ö·û£¬Èç¹û×éºÏ³É¹¦ÔòÊä³ö¸Ã×Ö·û£¬²»³É¹¦Ôò¾¡Á¿ÏÔʾһ¸öºÏÀí×Ö·û¡£

?? ? ÔÚ¹¥»÷ʱ£¬¹¥»÷Õß¿É°ÑÒ»¸ö×Ö·û²ð·Ö³ÉÈô¸É¸ö×Ö½Ú£¬È»ºó°ÑÕâÒ»¸ö×Ö½ÚºÍÆäËü×Ö·ûÒ»Æð·¢Ë͵½·þÎñÆ÷¶Ë£¬Èç¹ûÕâ¸ö×Ö½Ú¿ÉÒÔºÍÆäËü×Ö·ûµÄ×Ö½Ú¹¹³ÉÒ»¸ö×Ö·û£¬ÕâÑù¸Ã×ֽھͳԵôÁ˺óÃæµÄ×Ö·û¡£´¦Àí²»É÷¾Í»áµ¼ÖÂXSSµÈ°²È«Â©¶´¡£

???? ÀýÈ磺

?????JavaScriptÖг£ÓÃË«ÒýºÅ¡°"¡±×öΪ×Ö·û´®µÄ·Ö½ç·û¡£Îª·ÀÖ¹XSS¡¢SQLIµÈ¹¥»÷ʱ£¬¶ÔÓÚ´Ó¿Í»§¶ËÊäÈëµ½·þÎñÆ÷¶ËµÄË«ÒýºÅ£¬ÎÒÃÇ»áÓ÷´Ð±¸ÜÀ´×ªÒå¡£¿¼Âǹ¥»÷£¬Èç¹û¿Í»§¶ËµÄÊäÈë´®ÖÐÔÚÒ»¸öV×Ö½Úºó½ô¸úÒ»¸öË«ÒýºÅ£¬µ½·þÎñÆ÷¶Ëʱ£¬ÎÒÃÇ»á¸øË«ÒýºÅÌí¼ÓÒ»¸ö·´Ð±¸Ü£»ÕâЩÄÚÈÝÏ´η¢Ë͸øä¯ÀÀÆ÷ʱ£¬ä¯ÀÀÆ÷»á°ÑV×ֽںͺóÃæµÄ·´Ð±¸Ü½âÎöΪһ¸ö×Ö·û£¬¼´V×Ö½Ú³ÔµôÁË·´Ð±¸Ü£¬ÎÒÃÇÒÔÇ°µÄ°²È«´¦ÀíʧЧ£»ÕâÑù³ÌÐò¾Í»á³öÏÖÎÊÌâ¡£

??? Çë¿´ÏÂÃæµÄÀý×Ó£º

ʾÀýÒ»£º

PHPÒ³Ã棺

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>×Ö·ûµ¼ÖµÄXSS</title></head><body><script language="javascript">function callback(o){//do nothing}callback({"userInput":"normal"});//Õý³£ÊäÈëcallback({"userInput":"<?php echo substr('ÎÒ',0,1);?>"});alert(0);//"});//¹¥»÷ÐÔÊäÈëcallback({"userInput":"<?php echo substr('ÎÒ',0,2);?>"});alert(1);//"});//¹¥»÷ÐÔÊäÈëcallback({'userInput':'<?php echo chr(0xC1);?>\'});alert(2);//'});//¹¥»÷ÐÔÊäÈë</script></body></html>?

?

PHPÒ³ÃæÊä³ö£º

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>×Ö·ûµ¼ÖµÄXSS</title></head><body><script language="javascript">function callback(o){//do nothing}callback({"userInput":"normal"});//Õý³£ÊäÈëcallback({"userInput":"Î"});alert(0);//"});//¹¥»÷ÐÔÊäÈëcallback({"userInput":"ÎÒ"});alert(1);//"});//¹¥»÷ÐÔÊäÈëcallback({'userInput':'Á\'});alert(2);//'});//¹¥»÷ÐÔÊäÈë</script></body></html>?

?˵Ã÷£º

1.userInput¶ÔÓ¦µÄֵΪÓû§ÊäÈëµÄÖµ£»

2.ΪÁ˽âÊÍÎÒÃÇÓÃPHPÀ´½Ø¶ÏÊä³ö×Ö·ûÖеÄ×Ö½Ú£»

3.´Ó³ÌÐòÊä³ö¿ÉÒÔ¿´³ö¡°ÎÒ¡±µÄµÚÒ»¸ö×ֽںͱíʾ·´Ð±¸ÜµÄ×Ö½Ú±»ä¯ÀÀÆ÷ʶ±ðΪ¡°Ò\¡±×Ö£¬´Ó¶øV×Ö½Ú³ÔµôÁË·´Ð±¸Ü

4.metaÖÐÖ¸¶¨µÄ charset=utf-8Ϊʱ£¬²»»á³öÏÖÉÏÊöÎÊÌ⣻µ«ÊÇÓû§Ç¿ÖÆÔÚÒ³ÃæÉϰѱàÂëת»»Îªgb2312ʱÓÖ»á³öÏÖ¸ÃÎÊÌâ¡£

?

ʾÀý¶þ£ºÈçºÎÊäÈë°ë¸ö×Ö·û£¿

PHPÒ³Ãæhttp://localhost/test2.php£º

?

<script language="javascript">var callback = "<?=($_GET["callback"])?>";</script>

?

ÔÚä¯ÀÀÆ÷ÖÐÊäÈëÈçÏÂURL£º

?

http://localhost/test2.php?callback=%E6";alert%28/XSS/%29;//"

»Ø³µ£¬Ò³ÃæÊä³öÈçÏÂHTML£¬²¢µ¯³öalert¿ò¡° /XSS/ ¡±£¬ËµÃ÷´æÔÚXSS©¶´¡£

?

<script language="javascript">var callback = "æ";alert(/XSS/);//"";</script>

˵Ã÷£º

(1) PHPÖлá¶ÔËùÓÐË«ÒýºÅÌí¼Ó·´Ð±¸ÜÀ´×ªÒ壬¸ù¾ÝÊäÈëURLµÄ×îºóÒ»¸öË«ÒýºÅµÄÊä³ö½á¹û¿É¿´³ö¡£

(2) ±¾À´¶Ôcallback=%E6" ÖеÄË«ÒýºÅÒ²Ìí¼ÓÓÐÒ»¸ö·´Ð±¸Ü£¬ µ«ÊÇ%E6(¡°ÎÒ¡±×ÖµÚÒ»¸ö×Ö½ÚµÄURL±àÂë)ºÍ%5CÄܹ¹³ÉÒ»¸ö×Ö·û¡°æ\¡±£¬ËùÒÔÊä³öʱ£¬%E6¾Í³ÔµôÁ˺óÃæµÄË«ÒýºÅ¡£´Ó¶øµ¼ÖÂXSS©¶´


?

ÈȵãÅÅÐÐ