Windows PrintDemonÌáȨÎó²îÆÊÎö
Ðû²¼Ê±¼ä 2020-05-211.Îó²î¸ÅÊö
΢ÈíÔÚ5ÔÂ12ÈÕµÄÇå¾²¸üÐÂÖйûÕæÁËÒ»¸öWindowsÍâµØÌáÈ¡Îó²î£¨CVE-2020-1048£©£¬¸ÃÎó²îµÄÐÎòΪ£º
¡°Windows Print Spooler·þÎñ²»ÊÊÍâµØÔÊÐíí§ÒâµÄÎļþϵͳдÈ룬±£´æÌØȨÌáÉýÎó²î¡£¹¥»÷ÕßʹÓôËÎó²îÄܹ»ÓÃϵͳÌØȨÔËÐÐí§Òâ´úÂ룬´Ó¶øʵÏÖ£º³ÌÐòµÄ×°Öá¢Éó²é¡¢¸ü¸Ä»òÊý¾Ýɾ³ý£¬ÒÔ¼°½¨Éè¾ßÓÐÍêÕûȨÏÞµÄÕÊ»§¡£ÒªÊ¹ÓôËÎó²î£¬¹¥»÷Õß±ØÐèµÇ¼µ½ÊÜÓ°ÏìµÄϵͳ²¢ÔËÐÐÌض¨¾ç±¾»òÓ¦ÓóÌÐò¡±¡£
¸ÃÎó²îÓÉÇå¾²Ñо¿Ö°Ô±Alex IonescuºÍYarden Shafir·¢Ã÷£¬²¢±»ÃüÃûΪPrintDemon¡£Print SpoolerÊÇϵͳ×Ô´øµÄ´òÓ¡ºǫ́´¦Öóͷ£·þÎñ£¬ÖÎÀíËùÓÐÍâµØºÍÍøÂç´òÓ¡ÐÐÁУ¬¿ØÖÆ×ÅËùÓдòÓ¡ÊÂÇé¡£Print SpoolerÔÚWindowsϵͳÖÐÒѱ£´æ¶àÄ꣬´Ó΢ÈíÐû²¼µÄ²¹¶¡Ò³Ãæ¿ÉÖª¸ÃÎó²îÓ°ÏìWindows7ÖÁWindows10 1909µÄÏÕЩËùÓа汾¡£
2.Îó²îÑéÖ¤
ÓÅ·¢¹ú¼ÊÍøÕ¾¹ÙÍøADLabÇå¾²Ñо¿Ô±¶Ô¸ÃÎó²î¾ÙÐÐÁËÆÊÎöºÍÑéÖ¤£¬ÊµÏÖÁËÔÚµÍȨÏ޵ıê×¼Óû§ÏÂдÈëϵͳĿ¼£¬²âÊÔ²Ù×÷ϵͳΪWindows 10 x64ÆóÒµ°æ2016£¨ºã¾Ã·þÎñ°æ£©£¬²âÊÔ°ì·¨ÈçÏ£º
£¨1£©ÔÚ²âÊÔϵͳÖн¨ÉèÒ»¸ö±ê×¼Óû§test£¬²¢Ê¹Óøñê×¼Óû§µÇ¼ϵͳ¡£Éó²éÆäËùÊôÓû§×飬ȷÈÏÆä²»ÊÇÖÎÀíÔ±Óû§×é¡£
£¨2£©ÔÚtestÕË»§Ï£¬ÊµÑéÔÚϵͳĿ¼Ï½¨ÉèÎļþ¼Ð»òÕßдÈëÎļþ£¬¾ùʧ°Ü¡£
£¨3£©È»ºóÖ´ÐÐÈçÏÂPowerShellÏÂÁÒÔÆÚÔÚϵͳĿ¼Ï½¨ÉèÎļþmyport.txt¡£
£¨4£©ÖØÆô²âÊÔϵͳ²¢µÇ¼testÓû§£¬¿ÉÒÔ¿´µ½ÔÚϵͳĿ¼ÏÂÒÑÌìÉúÁËmyport.txtÎļþ£¬Éó²éÄÚÈÝȷʵ°üÀ¨Á˲âÊÔ×Ö·û´®¡£¸ÃЧ¹ûÅú×¢£ºµÍȨÏÞµÄ testÓû§Í»ÆÆÁËÎÞ·¨ÐÞ¸Äϵͳ×ÊÔ´µÄÇå¾²ÏÞÖÆ¡£
3.Îó²îÔÀí
¸ÃÎó²îÉæ¼°µ½Windows´òÓ¡»úµÄÊÂÇé»úÖÆ£¬Îª¸üºÃµÄÃ÷È·Îó²î³ÉÒò£¬Ê×ÏȼòÆÓÏÈÈÝ´òÓ¡»ú»ù´¡ÖªÊ¶£¬È»ºóÔÙÆÊÎöÎó²î³ÉÒò¡£
´òÓ¡»úÊÂÇé»úÖÆ
WindowsϵͳµÄ´òÓ¡»úÓÐÁ½¸ö½¹µã×é¼þ£º´òÓ¡»úÇý¶¯ºÍ´òÓ¡»ú¶Ë¿Ú¡£
¡ö ´òÓ¡»úÇý¶¯
ÔÚÌí¼ÓÒ»¸ö´òÓ¡»úʱ£¬ÐèҪװÖôòÓ¡»úÇý¶¯¡£ÔÚMSDNÎĵµÐÎòÖУ¬ÔçÆÚϵͳҪÇóÖ»Óо߱¸SeLoadDriverPrivilegeȨÏÞµÄÓû§²Å»ª×°ÖôòÓ¡Çý¶¯£¬µ«ÎªÁ˱ãÓÚ±ê×¼Óû§×°ÖÃÇý¶¯£¬´ÓWindows Vista×îÏÈ£¬Ö»Òª´òÓ¡»úÇý¶¯ÊÇÒѾ±£´æµÄ¿ÉÁ¢×ÝÈ»ÓõÄÇý¶¯£¬¾Í²»ÐèÒªÈκÎÌØȨ¼´¿É×°Öá£ÀýÈ磬ͨ¹ýÒ»ÌõPowerShellÏÂÁî¼´¿É×°Öá°Generic / Text-Only¡±Çý¶¯¡£
¡ö ´òÓ¡»ú¶Ë¿Ú
ÔÚÌí¼ÓÒ»¸ö´òÓ¡»úʱ£¬ÐèÒªÉèÖôòÓ¡»úµÄ¶Ë¿Ú¡£WindowsÖ§³Ö¶àÖÖÀàÐ͵ĴòÓ¡»ú¶Ë¿Ú£ºLPT1¶Ë¿Ú¡¢USB¶Ë¿Ú¡¢ÍøÂç¶Ë¿ÚºÍÎļþµÈ¡£ÈôÊÇÉèÖö˿ÚΪÎļþ£¬ÔòÒâζ×Å´òÓ¡»ú½«Êý¾Ý´òÓ¡µ½Ö¸¶¨Îļþ¡£ÀýÈ磬ͨ¹ýÒ»ÌõPowerShellÏÂÁî¼´¿ÉÌí¼ÓÒ»¸öÊä³öµ½Ö¸¶¨ÎļþµÄ´òÓ¡¶Ë¿Ú£º
Add-PrinterPort -Name "C:\windows\Temp\myport.txt"
ÏÖʵÉÏ£¬¸Ã²Ù×÷ÊÇÔÚ×¢²á±íÖÐÔöÌíÒ»¸öREG_SZÀàÐ͵ÄÖµ¡£
×¼±¸ºÃÇý¶¯ºÍ¶Ë¿Úºó£¬Í¨¹ýÒ»ÌõPowerShellÏÂÁî¼´¿É½¨ÉèÒ»¸ö´òÓ¡»ú¡£
´òÓ¡»ú½¨ÉèÍê±Ïºó£¬Í¨¹ýÒ»ÌõPowerShellÏÂÁî¼´¿É´òÓ¡Êý¾Ýµ½Ö¸¶¨¶Ë¿Ú£º
"PrintTest!" | Out-Printer -Name "PrintTest"
ÓÉÓÚPrintTest´òÓ¡»úµÄ¶Ë¿ÚÊÇÎļþc:\windows\Temp\myport.txt£¬Òò´Ë´òÓ¡ÏÂÁîÖ´Ðкó£¬Êý¾Ý¡°Print Test!¡±½«»á±»Ð´È루¼´´òÓ¡£©µ½¸ÃÎļþ¡£
Õë¶Ô¶Ë¿ÚÊÇÎļþµÄ´òÓ¡Àú³Ì£¬spooler´òÓ¡·þÎñ³ÌÐòÒÔimpersonating·½·¨À´Ä£ÄâÄ¿½ñÓû§µÄÌØȨ¾ÙÐÐÎļþдÈë¡£Òò´Ë£¬ÈôÊǶ˿ÚÎļþÔÚÊܱ£»¤µÄϵͳĿ¼£¨ÀýÈçC:\Windows\system32£©£¬ Ôò·ÇÖÎÀíԱϵÄPowerShell´òÓ¡×÷Òµ¾Í»áʧ°Ü¡£
ÍÑ»ú´òÓ¡µÄ»úÖÆ
ÔÚWindowsϵͳÉÏ£¬ÈôÊÇϵͳÉèÖÃÆôÓÃÁ˼ÙÍÑ»ú·þÎñ£¬ÔòËùÓеĴòӡʹÃü¶¼²»ÊÇÁ¬Ã¦Ö´ÐС£Ïà·´£¬ÏµÍ³Ê¹ÓÃPrint SpoolerÀ´ÖÎÀíÍÑ»ú´òӡʹÃü¡£ÏêϸÀ´Ëµ£¬µ±Óû§Å²ÓôòÓ¡²Ù×÷ºó£¬ÏµÍ³½«´òÓ¡×÷Òµ´æ´¢ÔÚÌض¨µÄ¼ÙÍÑ»úÎļþ¼ÐÖС£
ĬÈÏÇéÐÎÏ£¬WindowsÌìÉúµÄÍÑ»ú´òӡʹÃüÎļþΪ.SPLÎļþ£¬±ðµÄWindows»¹»á½¨Éèºó׺ÃûΪ.SHDµÄshadowÎļþ²¢Í¬SPLÎļþ×ö¹ØÁª¡£½¨ÉèshadowÎļþµÄÓÃ;ÊÇ£ºÔÚ´òÓ¡³ÌÐò·ºÆðÎÊÌâ»òÕß´òӡʹÃü±»¹ÒÆðºó£¬PrintSpoolerÒÀÈ»¿ÉÒÔͨ¹ýSHDÎļþ»Ö¸´´òӡʹÃü¡£
ÔÚWindowsϵͳÖØÆô»òPrint Spooler·þÎñÖØÆôÖ®ºó£¬.SHDºÍ.SPLÎļþ»á±»ÖØжÁÈ¡ÒÔ»Ö¸´´òӡʹÃü¡£
´òÓ¡ÌáȨµÄÔÀí
ÍÑ»ú´òÓ¡»úÖÆʹµÃWindowsϵͳÔÚÖØÆôºó»á»Ö¸´¿ÉÄܱ£´æµÄδִÐдòӡʹÃü¡£¿ÉÊÇ£¬ÖØÆôºóµÄPrinter Spooler·þÎñ³ÌÐòÖ±½ÓʹÓÃÁËSystemȨÏÞÀ´»Ö¸´Î´Ö´ÐеĴòÓ¡×÷Òµ¡£¹ØÓÚ´òÓ¡»ú¶Ë¿ÚΪÎļþµÄ´òӡʹÃü£¬´òÓ¡ÎļþµÄдÈëÒ²¾ÍÔÚSystemȨÏÞϱ»Ö´ÐС£Òò´Ë£¬ÏµÍ³ÖØÆôʹµÃÍÑ»ú´òӡʹÃü¾ß±¸ÁËSystemȨÏÞµÄí§ÒâÎļþдÈëÄÜÁ¦¡£
´òÓ¡»úµÄÉèÖóýPowerShell¾ç±¾Í⣬ͨ¹ýϵͳ¿ØÖÆÃæ°åÒ²ÄÜÉèÖá£ÏêϸÀ´Ëµ£¬Í¨¹ý¡°×°±¸ºÍ´òÓ¡»ú¡±ÄÜÌí¼Ó´òÓ¡»ú²¢ÉèÖö˿ڡ£
µ«ÈôÊÇÉèÖôòÓ¡¶Ë¿ÚÃûΪ¡°C:\Windows\system32\myport.txt¡±£¬Ôò»áʧ°Ü¡£
ΪºÎÉèÖÃͬÑùÎļþÃûµÄ´òÓ¡»ú¶Ë¿Ú£¬Í¨¹ý¿ØÖÆÃæ°å»áʧ°Ü£¬¶øͨ¹ýPowerShell ÏÂÁîÔò¿ÉÒÔÀÖ³ÉÄØ£¿Í¨Ì«¹ýÎöÕâÁ½ÖÖ·½·¨¶Ôspooler³ÌÐòÖ´ÐÐÁ÷³ÌµÄÓ°Ï죬·¢Ã÷spooler³ÌÐò¶Ôͨ¹ýPowerShellÏÂÁîÐÐÌí¼Ó´òÓ¡»ú¶Ë¿Ú·½·¨È±·¦Ç徲УÑé¡£
ÏêϸÀ´½²£¬Õë¶ÔPowerShellÏÂÁîÌí¼Ó´òÓ¡»ú¶Ë¿Ú£¬spooler³ÌÐòÖ±½ÓÉèÖÃÁËÏìÓ¦µÄ´òÓ¡»ú¶Ë¿Ú×¢²á±íÏÕë¶Ô¿ØÖÆÃæ°åÌí¼Ó´òÓ¡»ú¶Ë¿Ú£¬spooler³ÌÐò»áÊ×ÏÈʵÑ齨Éè¸Ã¶Ë¿ÚÎļþ£¬½¨Éèʧ°Üºó¾Í²»»áÔÙÉèÖÃÏìÓ¦µÄ×¢²á±íÏî¡£
½øÒ»²½ÆÊÎöÏà¹ØAPI·¢Ã÷£¬WindowsϵͳÌṩÁËÁ½ÖÖÌí¼Ó´òÓ¡»ú¶Ë¿ÚµÄAPI£¬»®·ÖÊÇAddPortº¯ÊýºÍXcvDataº¯Êý¡£ÆäÖÐMSDN¶ÔAddPortµÄÐÎò£º
¡°AddPortº¯Êýä¯ÀÀÍøÂçÒÔ²éÕÒÏÖÓж˿ڣ¬²¢µ¯³ö¶Ô»°¿ò¹©Óû§Ñ¡Ôñ¡£AddPortº¯ÊýÓ¦¸Ãͨ¹ýŲÓÃEnumPortsÀ´ÑéÖ¤Óû§ÊäÈëµÄ¶Ë¿ÚÃû³Æ£¬ÒÔÈ·±£²»±£´æÖظ´µÄÃû³Æ¡£AddPortº¯ÊýµÄŲÓ÷½±ØÐè¾ßÓлá¼û¶Ë¿ÚËùÅþÁ¬µÄ·þÎñÆ÷µÄSERVER_ACCESS_ADMINISTERȨÏÞ¡£ÒªÌí¼Ó¶Ë¿Ú¶ø²»ÏÔʾ¶Ô»°¿ò£¬¿ÉŲÓÃXcvDataº¯Êý¶ø²»ÊÇAddPort ¡±¡£
ͨ¹ý¿ØÖÆÃæ°åÌí¼Ó´òÓ¡»úÔڵײãÊÇŲÓÃÁËAddPortº¯Êý£¬¸Ãº¯Êý»á´¥·¢spooler³ÌÐò¶Ô¶Ë¿ÚµÄÕýµ±ÐÔУÑ顣ͨ¹ýPowerShellÏÂÁîÌí¼Ó´òÓ¡»úÔڵײãÔòÊÇÖ±½ÓŲÓÃXcvDataº¯Êý£¬¸Ãº¯Êý²»»á´¥·¢spooler³ÌÐò¶ÔÓû§Ìí¼ÓµÄ¶Ë¿Ú¾ÙÐÐÇ徲УÑé¡£Òò´Ë£¬²âÊÔ³ÌÐòAddPort.exeͨ¹ý¸Ãº¯ÊýÔÚ±ê×¼Óû§È¨ÏÞÏÂÒ²ÄÜÉèÖôòÓ¡»ú¶Ë¿ÚΪÊܱ£»¤Ä¿Â¼ÖеÄÎļþ¡£
Îó²î²¹¶¡µÄÆÊÎö
ÆÊÎöÎó²îÐÞ¸´ºóµÄ°æ±¾·¢Ã÷£¬Î¢ÈíÔÚÒªº¦º¯ÊýLcmCreatePortEntry£¨×îÖÕ½¨Éè´òÓ¡»ú¶Ë¿ÚµÄº¯Êý£©ÖÐÌí¼ÓÁËÏìÓ¦µÄ¶Ë¿ÚÕýµ±ÐÔ¼ì²é´úÂë¡£ÏÂͼÊÇÒªº¦º¯ÊýLcmCreatePortEntryÔÚÐÞ¸´Ç°ºÍÐÞ¸´ºóµÄCall Graph±ÈÕÕ£¬¿ÉÒÔ¿´³ö£º²¹¶¡µÄ½¹µãÊÇͨ¹ýº¯ÊýPortIsValid¶Ô¶Ë¿Ú¾ÙÐÐÕýµ±ÐÔ¼ì²é¡£
ƾ֤ÉÏÎĵÄÆÊÎö¿ÉÖª£¬±ê×¼Óû§ÊÇÎÞ·¨ÔÚϵͳĿ¼Öн¨ÉèÎļþµÄ£¬°Ñ¶Ë¿ÚÉèÖÃΪϵͳĿ¼ÏµÄÎļþ»áµ¼ÖÂPortIsValid¼ì²â²»µ½Ä¿µÄÎļþ£¬´Ó¶øÅжÏÒªÉèÖõĶ˿ÚÊDz»·¨µÄ¡£Òò´Ë£¬ÔÚ²¹¶¡ÐÞ¸´ºó£¬±ê×¼Óû§Ìí¼Ó´òÓ¡¶Ë¿ÚΪϵͳĿ¼ÏÂÎļþµÄ´òÓ¡»ú¾Í»áʼÖÕʧ°Ü£¬´Ó¶ø×èÖ¹ÁËϵͳÖØÆôʱ»Ö¸´¶ñÒâµÄ´òÓ¡·þÎñ¡£
4.ÐÞ¸´½¨Òé
ÓÉÓÚ¸ÃÎó²îÄÜÓ°ÏìÖÚ¶àµÄWindowsϵͳ°æ±¾£¬²¢ÇÒ¿ÉÒÔÔÚ±ê×¼Óû§ÏÂÌᳫÎó²î¹¥»÷£¬½¨ÒéÊÜÓ°ÏìµÄÓû§ÊµÊ±¾ÙÐÐϵͳ¸üлò×°ÖÃÎó²î²¹¶¡¡£
±ðµÄ£¬Î¢ÈíµÄÇå¾²¸üÐÂÖ»ÊǶԴòÓ¡¶Ë¿ÚAPI¾ÙÐÐÁ˸üÑÏ¿áµÄУÑé¡£¿ÉÊÇ£¬ÈôÊǶñÒâÎļþ¶Ë¿ÚÔÚÎó²îÐÞ¸´Ç°ÒѾ½¨É裬ÔòÎó²î¹¥»÷ÏÖʵÒѾÉúЧ£¬´Ëʱ¾ÙÐÐϵͳ¸üÐÂÈÔÈ»ÊDz»Çå¾²µÄ¡£½¨ÒéÓû§ÏÈʹÓÃPowerShellÏÂÁîGet-PrinterPortÀ´¼ì²éϵͳÖÐÊÇ·ñ±£´æ¿ÉÒɵĴòÓ¡»ú¶Ë¿Ú£¬ÔÚɾ³ý¿ÉÒɶ˿ںóÔÙʵÑéϵͳ¸üС£
²Î¿¼Á´½Ó£º
[1]https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2020-1048
[2]https://docs.microsoft.com/en-us/windows/win32/printdocs/addport
[3]https://docs.microsoft.com/en-us/previous-versions/ff564255(v%3dvs.85)
[4]https://windows-internals.com/printdemon-cve-2020-1048/