MySQL UDF that executes system commands

Source: Internet
Author: User

Hi.baidu.com/isno

Marco IvaldiA few years agoRaptor_udf2.c, Demonstrates how to use the mysql udf to intrude into the system, but this mysql udf also demonstrates a way to call system commands. However, this plug-in is currently not compatible with mysql 5.0 +, mainly because it does not conform to the new mysql udf specifications and does not return results.

MySQL User-Defined FunctionsYesRoland BoumanA new udf package for calling system commands, which has three functions:

  • sys_exec: Call system commands to execute external programs
  • sys_get: Return the value of the system environment variable.
  • sys_set: Set system environment variables

    This mysql udf package is compatible with mysql 5.0 + and supports both linux and windows. However, this package also has a problem. After executing the command, it returns the exit_code of the command, rather than the execution result of the command.

    Bernardo Damele A. G. added A sys_eval function to update the problem. If the Function Command is executed successfully, the execution result is returned, and if the error is returned, NULL is returned.

    Download the patch here: Mysqludfsys/">Here

    Lib_mysqludf_sySVersion 0.0.2 is downloaded hereHere.

    Instance used:

    $ Wget -- no-check-certificate https://svn.sqlmap.org/sqlmap/trunk/sqlmap/extra/mysqludfsys/ Lib_mysqludf_sys_0.0.3.tar.gz
    $ Tar xfz lib_mysqludf_sys_0.0.3.tar.gz
    $ Cd lib_mysqludf_sys_0.0.3
    $ Sudo./install. sh
    Compiling the MySQL UDF
    Gcc-Wall-I/usr/include/mysql-I.-shared lib_mysqludf_sys.c-o/usr/lib/lib_mysqludf_sys.so
    MySQL UDF compiled successfully

    Please provide your MySQL root password
    Enter password:
    MySQL UDF installed successfully
    $ Mysql-u root-p mysql
    Enter password:
    [...]
    Mysql> SELECT sys_eval (id );
    + -------------------------------------------------- +
    | Sys_eval (id) |
    + -------------------------------------------------- +
    | Uid = 118 (mysql) gid = 128 (mysql) groups = 128 (mysql) |
    + -------------------------------------------------- +
    1 row in set (0.02 sec)

    Mysql> SELECT sys_exec (touch/tmp/test_mysql );
    + ----------------------------------- +
    | Sys_exec (touch/tmp/test_mysql) |
    + ----------------------------------- +
    | 0 |
    + ----------------------------------- +
    1 row in set (0.02 sec)

    Mysql> exit
    Bye
    $ Ls-l/tmp/test_mysql
    -Rw ---- 1 mysql 0/tmp/test_mysql

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.