ClickHouse¶à¸öÎó²îÔ­ÀíÆÊÎö

Ðû²¼Ê±¼ä 2022-03-21

Ò»¡¢Îó²î¸ÅÊö


ClickHouseÊǶíÂÞ˹yandex¹«Ë¾ÓÚ2016Ä꿪ԴµÄÔÆÊý¾Ý¿âÖÎÀíϵͳ£¬ClickHouseÆÕ±éÓ¦ÓÃÓÚÔÆƽ̨µÄ´óÊý¾ÝÆÊÎöÓ¦ÓÃÖУ¬ÆäÓû§°üÀ¨uber¡¢ebay¡¢µÂÒâÖ¾ÒøÐС¢°¢Àï°Í°Í¡¢ÌÚѶµÈ¡£


¿ËÈÕ£¬JFrogÇå¾²Ñо¿ÍŶÓÅû¶ÁËÔÚClickHouse DBMSÖз¢Ã÷µÄ7¸öÎó²î£¬ÓµÓÐClickHouse×îµÍȨÏ޵Ĺ¥»÷Õß¿ÉÒÔͨ¹ýÕâЩÎó²îʹClickHouse·þÎñÆ÷Í߽⡢×ß©ÄÚ´æÄÚÈÝ£¬ÉõÖÁµ¼ÖÂÔ¶³Ì´úÂëÖ´ÐУ¨RCE£©¡£

Îó²îÓ°ÏìÁËClickHouse 21.10.2.15°æ±¾Ö®Ç°µÄËùÓа汾¡£ÏêϸÎó²îÐÎòÈçϱíËùʾ£º


ͼƬ1.png


¶þ¡¢´¦Öóͷ£½¨Òé


2021Äê10ÔÂ18ÈÕÐû²¼µÄClickHouse 21.10.2.15°æ±¾ÐÞ¸´ÁËÉÏÊöµÄ7¸öÎó²î£¬Ç뾡¿ìÉý¼¶µ½ClickHouse 21.10.2.15¼°ÒÔºóµÄ°æ±¾¡£


ÏÂÔØÁ´½Ó£º

https://github.com/ClickHouse/ClickHouse/releases/


»º½â²½·¥£º

ÈôÊÇÎÞ·¨Éý¼¶£¬ÇëÔÚ·þÎñÆ÷ÖÐÌí¼Ó·À»ðǽսÂÔ£¬ÏÞÖÆÖ»ÔÊÐíÌض¨IPµÄ¿Í»§¶Ë»á¼ûWEB¶Ë¿Ú(8123)ºÍTCP·þÎñÆ÷¶Ë¿Ú(9000)¡£


Èý¡¢Îó²îÆÊÎö


ÕâЩÎó²î¶¼±£´æClickHouse Server´¦Öóͷ£Ñ¹ËõÊý¾ÝµÄÇëÇó´¦Öóͷ£Àú³ÌÖУ¬ClickHouse ServerÖ§³Ö¶ÔÓû§ÇëÇóµÄ¸½´øÊý¾Ý¾ÙÐÐѹËõ¡£Óû§¿ÉÒÔÔÚÌᳫWEBÇëÇóʱ£¬½«decompress±ê¼ÇÉèΪ1¼´¿É£¬¾ÙÀýÈçÏ£º

cat query.bin | curl -sS ¡ªdata-binary @-¡®http://serverIP:8123/?user=xxx&password=xxx&decompress=1' 

ÅÌÎʵĸ½´øÊý¾Ý(query.bin)¿ÉÒÔ°´ÏÂÃæµÄ½á¹¹¾ÙÐÐ×éÖ¯£º


ͼƬ2.png


ClickHouseÖ§³Ö¶àÖÖѹËõÃûÌ㬰üÀ¨LZ4¡¢Gorilla¡¢DeltaµÈ¶àÖÖѹËõËã·¨¡£ClickHouse Serverƾ֤ÇëÇóÖи½´øÊý¾ÝµÄѹËõËã·¨±êʶ£¬Å²Óòî±ðµÄ½âѹËã·¨À´¶ÔÊý¾Ý¾ÙÐнâѹ¡£


3.1 LZ4Ëã·¨ÏÈÈÝ


LZ4ѹËõËã·¨ÊÇLZË㷨ϵÁÐÖеÄÒ»ÖÖ£¬Ò²ÊÇÏÖÔÚ×ÛºÏЧÂÊ×î¿ìµÄѹËõËã·¨Ö®Ò»¡£

Ò»¸öLZ4ѹËõ¿éÓɶà¸öLZ4ÐòÁÐ×é³É£¬LZ4ÐòÁÐÓÉÒÔÏÂÊý¾Ý×é³É£¬ÈçÏÂͼËùʾ£º


ͼƬ3.png

Token¾ÞϸΪ1×Ö½Ú£¬¸ß4¸öbitsΪ²»¿ÉѹËõÊý¾Ý(literal£©µÄ³¤¶È(literallength)£¬¶øµÍ4¸öbitsΪ¿ÉÒÔѹËõÊý¾Ý(match)³¤¶È(match length)¡£ÈôÊÇliterallengthµÄֵΪ0£¬ÔòÌåÏÖºóÐøÊý¾ÝÀïûÓÐliteral¡£ÓÉÓÚliteral lengthÖ»ÓÐ4±ÈÌØÀ´ÌåÏÖ£¬ËüµÄ×î´óֵΪ15¡£µ±literalÊý¾ÝµÄ¾Þϸ´óÓÚ¼´ÊÇ15ʱ£¬ÐèÒªÔÚToken×ֶκóÌí¼Ó¸ñÍâµÄ×Ö½ÚÀ´ÌåÏÖliteralµÄ³¤¶È£¨Literal length+£©¡£


ÈôÊÇmatch lengthµÄֵΪ0£¬ÔòÌåÏÖºóÐøÊý¾ÝÀïûÓÐmatch¡£ÓÉÓÚmatchlengthÖ»ÓÐ4±ÈÌØÀ´ÌåÏÖ£¬ËüµÄ×î´óֵΪ15¡£µ±matchÊý¾ÝµÄ¾Þϸ´óÓÚ¼´ÊÇ15ʱ£¬ÐèÒªÔÚoffset×ֶκóÌí¼Ó¸ñÍâµÄ×Ö½ÚÀ´ÌåÏÖmatchµÄ³¤¶È£¨match length+£©¡£

LiteralsָûÓÐÖظ´¡¢Ê״ηºÆðµÄ×Ö½ÚÔ¼£¬¼´²»¿ÉѹËõµÄ²¿·Ö¡£

OffsetÖ¸µÄÊÇÏÖÔÚ×Ö·û´®ÀëËüµÄÆ¥ÅäÏîµÄ³¤¶È£¬¶øÆ¥Å䳤¶ÈÖ¸µÄÊÇÏÖÔÚ×Ö·û´®Óë×ÖµäÖÐÏàͬ×Ö·û´®µÄÆ¥Å䳤¶È¡£offsetÕ¼ÓÃ2¸ö×Ö½Ú£¬¼´×î´óֵΪ65535¡£

MatchÖ¸Öظ´Ï¿ÉÒÔѹËõµÄ²¿·Ö¡£


 3.2 CVE-2021-43304Ô­Àí

src/Compression/LZ4_decompress_faster.cppµÄdecompressImplº¯ÊýÔÚ¿½±´LZ4ÐòÁÐÊý¾ÝµÄliteralʱ£¬Ã»ÓÐÅжϸ´ÖƵÄÊý¾ÝÊÇ·ñÁè¼ÝÄ¿µÄ»º³åÇøµÄÏÞÖÆ¡£µ±ÐèÒª¸´ÖƵÄÊý¾ÝÁè¼ÝÄ¿µÄ»º´æµÄ¾Þϸʱ£¬»áµ¼Ö¶ÑÒç³ö¡£


ͼƬ4.png


ÈçÉÏͼ´úÂëËùʾ£¬ipÊÇÖ¸ÏòѹËõ»º³åÇøµÄÖ¸Õë¡£opÊÇÖ¸Ïò·ÖÅɵÄÄ¿µÄ»º³åÇøµÄÖ¸Õ룬¸ÃÄ¿µÄ»º³åÇøµÄ¾ÞϸΪ±¨Í·Öиø¶¨µÄ½âѹ¾Þϸ¡£copy_endÊÇÖ¸Ïò¸´ÖÆÇøÓò×îºóµÄÖ¸Õë¡£


copy_amountÊÇÄ£°åµÄ²ÎÊý£¬¿ÉÒÔÊÇ8¡¢16»ò32¡£¸´ÖÆÇøÓò±»·Ö¿é¸´ÖÆ£¬Ã¿¸ö¿éµÄ¾Þϸ¶¼Ó븴ÖÆÁ¿Ïàͬ¡£

¹¥»÷Õß¿ÉÒԽṹ¶ñÒâµÄLZ4ÐòÁÐÊý¾Ý£¬ÆäÖÐliteraµÄ³¤¶È(length±äÁ¿)´óÓÚdest_size£¬½«µ¼Ö¶ÑÒç³ö¡£


3.3 CVE-2021-43304Îó²î¸´ÏÖ

ÎÒÃÇ¿ÉÒԽṹÕâÑùµÄÇëÇóÊý¾Ý£¬ÆäÖÐѹËõË㷨ΪLZ4£¬literalµÄ³¤¶ÈΪ255*200£¬¶ødest_sizeΪ1¡£ÓÉÓÚliteralµÄ¾ÞϸԶ´óÓÚ½âѹºó»º³åÇøµÄ¾Þϸ£¬µ±clickhouse_server¾ÙÐи´ÖƲÙ×÷ʱ½«µ¼Ö¶ÑÒç³ö£¬´¥·¢³ÌÐòÍ߽⡣


ͼƬ5.png


3.4 CVE-2021-43305Îó²îÔ­Àí


Îó²î±£´æsrc/Compression/LZ4_decompress_faster.cppµÄdecompressImplº¯ÊýÖУ¬¸Ãº¯ÊýÖ±½Ó´ÓLZ4ѹËõÊý¾ÝÖжÁÈ¡16λÎÞ·ûºÅÆ«ÒÆÁ¿£¨offset¹¥»÷Õß¿ÉÒÔ¿ØÖÆ£©£¬offsetÓÃÓÚ¶¨Î»matchÊý¾ÝµÄλÖ㬵±offsetµÄÖµ´óÓÚdest_sizeµÄֵʱ£¬copyOverlap²Ù×÷½«µ¼Ö¶ÑÒç³ö¡£


ͼƬ6.png


3.5 CVE-2021-42388¼°CVE-2021-42387Îó²îÔ­Àí


Îó²î±£´æsrc/Compression/LZ4_decompress_faster.cppµÄdecompressImplº¯ÊýÖУ¬¸Ãº¯ÊýÖ±½Ó´ÓLZ4ѹËõÊý¾ÝÖжÁÈ¡16λÎÞ·ûºÅÆ«ÒÆÁ¿£¨offset¹¥»÷Õß¿ÉÒÔ¿ØÖÆ£©,¸ÃÆ«ÒÆÁ¿ÓÃÓÚÅÌËãwildCopy²Ù×÷µÄÔ´Êý¾ÝµØµã¡£µ±offsetµÄֵΪ´óÓÚcopy_amountʱ(Èçoffset = 0xffff£©£¬½«µ¼Ö³ÌÐò½«opµØµã֮ǰµÄÊý¾Ý¿½±´µ½opÖ¸ÏòµÄµØµãÖУ¬´Ó¶øµ¼ÖÂÔ½½ç¶Á¡£


ͼƬ7.png


CVE-2021-42387ÊÇCVE-2021-42388µÄÒ»¸öÀàËÆÎó²î£¬ÕâÀï¾Í²»ÔÙÏÈÈÝ¡£


3.6 CVE-2021-42389¡¢CVE-2021-42390¡¢CVE-2021-42391Îó²îÔ­Àí

ClickHouseÖ§³ÖµÄDoubleDelta±à½âÂëÆ÷¡¢Delta±à½âÂëÆ÷¡¢Gorilla±à½âÂëÆ÷Öж¼±£´æ±»Áã³ýµÄÎó²î¡£ËüÃÇ»ùÓÚ½«Ñ¹Ëõ»º³åÇøµÄµÚÒ»¸ö×Ö½ÚÉèÖÃΪÁã¡£½âѹ´úÂë¶ÁȡѹËõ»º³åÇøµÄµÚÒ»¸ö×Ö½Ú£¬²¢¶ÔÆäÖ´ÐÐÄ£ÔËËãÒÔ»ñµÃÊ£Óà×Ö½Ú£¬µ±source[0]Ϊ0ʱ£¬CPU¶Ô0¾ÙÐÐȡģʱ²Ù×÷½«±¬·¢³ý0Òì³£¡£


ͼƬ8.png


ËÄ¡¢¿¢ÊÂÓï


´óÊý¾Ýʱ´úÏ£¬´ó×ÚÊý¾ÝȺ¼¯¡¢ÅþÁ¬¼°ÍøÂç½çÏßµÄÑÓÉ춼ΪÊý¾Ý¿âµÄµÄÇå¾²Ìá³öÁ˸ü¸ßµÄÒªÇó¡£Êý¾Ý¿â×÷ΪÐÅÏ¢ÊÖÒÕϵͳµÄ½¹µãºÍ»ù´¡£¬³ÐÔØ×ÅÔ½À´Ô½¶àµÄÒªº¦ÓªÒµÏµÍ³£¬³ÉΪÆóÒµºÍ»ú¹¹×î¾ßÓÐÕ½ÂÔÐԵĽ¹µãÊý¾Ý×ʲú£¬Òò´ËÊý¾Ý¿â·½ÃæµÄÇå¾²ÖµµÃÎÒÃÇÒ»Á¬¹Ø×¢¡£


²Î¿¼Á´½Ó£º

[1]https://jfrog.com/blog/7-rce-and-dos-vulnerabilities-found-in-clickhouse-dbms/

[2]https://github.com/ClickHouse/ClickHouse

[3]https://thehackernews.com/2022/03/multiple-flaws-uncovered-in-clickhouse.html