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ÇÒ±£´æ·ûºÅÁ´½Ó£¬Ð§¹û¾ÍÊdzÌÐòµÄÕý³£Ô¤ÆÚ¹¦Ð§¡£ÄÇô£¬¸Ã¹¦Ð§ÊÇÔõÑù±»È϶¨³ÉÎó²î£¿
Îó²îµÄÒªº¦ÐÅÏ¢[1]ÖÐÓÐÒ»¾äÖ÷ÒªÐÎò£ºÎó²î²»ÒÀÀµÓÚ·ûºÅÁ´½ÓµÄ±£´æÐÔ¡£¿ÉÊÇ£¬ÔÚÇëÇ󷾶ÖÐʹÓò»±£´æµÄ·ûºÅÁ´½Ó£¬µ×²ãÓÖÔõÑùÄÜ»á¼ûµ½Ä¿µÄÎļþ¡£
¾Ì«¹ýÎö£¬·¢Ã÷µ×²ã´¦Öóͷ£ÇëÇóµÄÒªº¦º¯ÊýÈçÏ£º
Ê×ÏÈ£¬»ñÈ¡ÇëÇóÎļþÃû£¨filename£©¡£ÒÔ GET /static/d/123.txtΪÀý£¬filename¾ÍÊÇd/123.txt¡£
È»ºó£¬°Ñfilenameת»»ÎªPath¹¤¾ß£¬²¢¼ì²â¸Ã¹¤¾ßÊÇ·ñ±£´æanchorÊôÐÔ¡£ÈôÊDZ£´æ£¬Ôò¾Ü¾ø»á¼û¡£ÔÚ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ÔÚµÄÇ徲Σº¦£¬¿ª·¢ÕßÈÔÐèÒªÒýÆð×ã¹»µÄÖØÊÓ£¬ÉóÉ÷ʹÓøù¦Ð§¡£