aiohttpĿ¼´©Ô½Â©¶´£¨CVE-2024-23334£©·ÖÎö
Ðû²¼Ê±¼ä 2024-04-01Ò»¡¢Â©¶´¸ÅÊö
aiohtp Êǹ¹½¨ÓÚ Python l/0 ¿ò¼Ü AsyncI0 Ö®ÉϵĿªÔ´¿â£¬ÓÃÓÚ´¦ÖÃÎÞÐè»ùÓÚ´«Í³Ïß³ÌÍøÂçµÄ´óÁ¿²¢·¢HTTPÇëÇó¡£aiohttpÖ§³ÖHTTP¿Í»§¶Ë¡¢HTTP·þÎñ¶Ë¡¢WebSocket¿Í»§¶Ë¡¢WebSocket·þÎñ¶Ë¡¢·þÎñ¶ËÖмä¼þµÈ¡£aiohttp±»¹ã·ºÊ¹Óã¬ÔÚÍøÂçÖÐÓдóÁ¿»ùÓڸÿò¼Ü¿ª·¢µÄÔÚÏßϵͳ¡£
¶¶È¦Îª¶Ä¶øÉúADLabÑо¿Ô±ÔÚ©¶´Ç鱨¸ú×ÙÖз¢ÏÖÁËaiohttpĿ¼±éÀú©¶´£¨CVE-2024-23334£©£¬²¢¶ÔÆä½øÐÐÁËÉîÈë·ÖÎöºÍÑéÖ¤¡£
¶þ¡¢Ó°Ïì°æ±¾
ÊÜÓ°Ïì°æ±¾£º<3.9.2£¬ÇëÏà¹ØÓû§¾¡¿ìÉý¼¶µ½3.9.2¼°ÒÔÉÏ°æ±¾¡£
Èý¡¢Â©¶´·ÖÎö
¸Ã©¶´µÄÒªº¦ÐÅÏ¢ÈçÏÂ[1]£º
aiohttp is an asynchronous HTTP client/server framework for asyncio and Python. When using aiohttp as a web server and configuring static routes, it is necessary to specify the root path for static files. Additionally, the option 'follow_symlinks' can be used to determine whether to follow symbolic links outside the static root directory. When 'follow_symlinks' is set to True, there is no validation to check if reading a file is within the root directory. This can lead to directory traversal vulnerabilities, resulting in unauthorized access to arbitrary files on the system, even when symlinks are not present. Disabling follow_symlinks and using a reverse proxy are encouraged mitigations. Version 3.9.2 fixes this issue.
ƾ¾ÝÒªº¦ÐÅÏ¢£¬¶¨Î»µ½¿ª·¢ÎĵµµÄ˵Ã÷[2]£º
ƾ¾ÝÎĵµÃèÊö£¬follow_symlinksÊÇÒ»¸öÉè¼ÆÉÏÓÃÓÚ·ÇÉú²ú»·¾³µÄ¹¦Ð§£¬¶øÇÒÒÑÔÚÎĵµÖÐÃ÷È·ÌáʾÆôÓøù¦Ð§ÊÇÒ»¸öÄþ¾²·çÏÕ¡£
±àдÈçϵÄʾÀý´úÂ룬²âÊÔfollow_symlinksµÄ¹¦Ð§£º
ÔÚstaticĿ¼Ï´´½¨·ûºÅÁ´½Ód£¬Ö¸ÏòÆäËüĿ¼d:\test£¨¸ÃĿ¼Ï´æÔÚ²âÊÔÎļþ123.txt£©¡£
ÒÔfollow_symlink=fasleµÄģʽÆô¶¯²âÊÔwebserver£¬·ÃÎÊstatic/d/123.txtµÄ½á¹ûÈçÏÂËùʾ£¨ÌáʾÕÒ²»µ½Îļþ£©£º
ÒÔfollow_symlink=trueµÄģʽÆô¶¯²âÊÔwebserver£¬·ÃÎÊstatic/d/123.txtµÄ½á¹ûÈçÏÂËùʾ£¨ÀֳɶÁÈ¡ÎļþÄÚÈÝ£©£º
ÏÔÈ»£¬Æ¾¾ÝÎĵµµÄÃèÊö£¬Èç¹ûfollow_symlink=trueÇÒ´æÔÚ·ûºÅÁ´½Ó£¬½á¹û¾ÍÊÇ·¨Ê½µÄÕý³£Ô¤ÆÚ¹¦Ð§¡£ÄÇô£¬¸Ã¹¦Ð§ÊÇÈçºÎ±»È϶¨³É©¶´£¿
©¶´µÄÒªº¦ÐÅÏ¢[1]ÖÐÓÐÒ»¾äÖØÒªÃèÊö£ºÂ©¶´²»ÒÀÀµÓÚ·ûºÅÁ´½ÓµÄ´æÔÚÐÔ¡£µ«ÊÇ£¬ÔÚÇëÇ󷾶ÖÐʹÓò»´æÔڵķûºÅÁ´½Ó£¬µ×²ãÓÖÈçºÎÄÜ·ÃÎʵ½Ä¿±êÎļþ¡£
¾¹ý·ÖÎö£¬·¢Ïֵײ㴦ÖÃÇëÇóµÄÒªº¦º¯ÊýÈçÏ£º
Ê×ÏÈ£¬»ñÈ¡ÇëÇóÎļþÃû£¨filename£©¡£ÒÔ GET /static/d/123.txtΪÀý£¬filename¾ÍÊÇd/123.txt¡£
È»ºó£¬°Ñfilenameת»»ÎªPath¹¤¾ß£¬²¢¼ì²â¸Ã¹¤¾ßÊÇ·ñ´æÔÚanchorÊôÐÔ¡£Èç¹û´æÔÚ£¬Ôò¾Ü¾ø·ÃÎÊ¡£ÔÚwindowsƽ̨ÉÏ£¬anchor¹¤¾ß¾ÍÊÇÅÌ·û£¨ºÃ±Èd:\£©¡£Òò´Ë£¬´Ë´¦´æÔÚÄþ¾²¼ì²â£¬¼´²»ÔÊÐí¿çÅÌ·û·ÃÎÊ¡£ºÃ±ÈGET /static/d:\test\123.txt£¬»á±»ÊÓ×÷·Ç·¨ÇëÇó¶ø¾Ü¾ø£º
ÔÙÈ»ºó£¬°ÑstaticĿ¼µÄPath¹¤¾ßºÍfilenameµÄPath¹¤¾ß×öÆ´½Ó£¬ÐγÉÐÂÎļþ·¾¶filepath¡£×îºó£¬¶ÁÈ¡filepathµÄÊý¾Ý£¬²¢·µ»Ø¸ø¿Í»§¶Ë¡£
ÏÔÈ»£¬Èç¹ûfilename°üÂÞ²»´æÔڵķûºÅÁ´½Ó£¬µ«ÄÜ·ÃÎʵ½Ä¿±êÎļþ£¬ÄÇ˵Ã÷¹¤¾ßÆ´½Ó·¢ÉúÁË·ÇÔ¤ÆڵĽá¹û¡£ÓÉÓÚPath¹¤¾ßÊdz߶ȵÄpythonÀֱ࣬½Óµ¥¶À½øÐвâÊÔ¡£
£¨1£©É趨directory=c:\test , filename = d:\test\123.txt£¬Æ´½Ó´úÂëºÍ½á¹ûÈçÏÂ:
Æ´½Ó½á¹ûÖ¸ÏòÄ¿±êÎļþd:\test\123.txt£¬µ«ÊÇfname°üÂÞanchor£¬ÎÞ·¨Í¨¹ýÇ°ÃæµÄfilename.anchor¼ì²é¡£
£¨2£©É趨directory=c:\test , filename = ..\d:\test\123.txt£¬Æ´½Ó´úÂëºÍÔËÐнá¹ûÈçÏ£º
Æ´½Ó½á¹û¶ÁÈ¡µ½Ä¿±êÎļþ£¬ÇÒfname²»°üÂÞanchor£¬ÄÜͨ¹ýfilename.anchor¼ì²é¡£
£¨3£©É趨directory=c:\test , filename = ..\..\d:\test\123.txt£¬Æ´½Ó´úÂëºÍÔËÐнá¹ûÈçÏ£º
Æ´½Ó½á¹ûÒ²¶ÁÈ¡µ½ÁËÄ¿±êÎļþ£¬ÇÒfname²»°üÂÞanchor£¬ÄÜfilename.anchor¼ì²é¡£
Òò´Ë£¬Ö»ÒªÔÚfilename֮ǰ¼ÓÉÏ..\¾ÍÄÜÖ±½ÓÒýÈëÅÌ·û£¬Î¥±³Ôʼ¹¦Ð§Éè¼ÆÖÐÐèÒª·ûºÅÁ´½Ó´æÔÚµÄÏÞÖÆ£¬´Ó¶øÐγÉÁË¿ÉÒÔ¶ÁÈ¡´ÅÅÌÉÏÈÎÒâÎļþµÄÄþ¾²Â©¶´¡£
ËÄ¡¢²¹¶¡·ÖÎö
²¹¶¡Òªº¦´úÂëÈçÏ£º
²¹¶¡µÄºËÐÄ»úÖÆÊÇ£ºÂ·¾¶Æ´½Ó³Éunresolved_pathºó£¬Ê×Ïȵ÷ÓÃnormpath´¦ÖÃunresolved_pathÀ´ÐγÉnormalized_path£¬È»ºóÅж¨normalized_pathÊÇ·ñλÓÚ¾²Ì¬Ä¿Â¼_directory֮ϡ£
µ¥¶À²âÊÔ²¹¶¡»úÖƵĴúÂëºÍ½á¹ûÈçÏ£º
ÏÔÈ»£¬ÓÉÓÚÆ´½ÓºóµÄ·¾¶²»ÊÇstaticĿ¼µÄ×ÓĿ¼£¬ËùÒÔ´¥·¢ÁËÒì³££¬µ¼ÖºóÐø´úÂë²»ÔÙ¶ÁÈ¡Æ´½Óºó·¾¶ÏµÄÎļþ£¬´Ó¶øµ¼ÖÂÁ˸鶴²»ÔÙ´æÔÚ¡£
²¹¶¡²»Ó°ÏìaiohttpµÄ·ûºÅÁ¬½ÓÖ§³Ö£¬ÒòΪ·ûºÅÁ´½ÓÎļþ±ØÐë´æÔÚÓÚstaticĿ¼֮Ï¡£Ê¹Ó÷ûºÅÁ´½ÓÎļþÀ´´¦ÖÃstatic×ÊÔ´×Ô¼º¾ÍÊÇÒ»¸öDZÔÚµÄÄþ¾²·çÏÕ£¬¿ª·¢ÕßÈÔÐèÒªÒýÆð×ã¹»µÄÖØÊÓ£¬½÷É÷ʹÓøù¦Ð§¡£