Webshell and UDF
Method 1: Webshell
If we have write permission, we can use UNION attack and INTO OUTFILE
to create a PHP webshell on the target system:
Here we choose the images
directory since it is usually owned by the www-data
user, not root.
Once the webshell is created successfully, we can spawn a netcat reverse shell. Start a listener on our local machine:
Spawn a netcat reverse shell using the webshell:
Method 2: UDF
There is a plugin lib_mysqludf_sys
which contains the following dangerous functions:
sys_eval()
: executes any command and returns the resultsys_exec()
: executes any command and returns the return codesys_get()
: gets an environment variablesys_set()
: creates or modifies an environment variable
MySQL does not have this lib by default. In order to use these functions, we have to import lib_mysqludf_sys
first. Generate a binary version of this lib using sqlmap cloak.py
:
Grab its content as hex:
Connect to MySQL. In the MySQL shell, copy and paste the hex data and unhex()
it:
Here we use DUMPFILE
instead OUTFILE
since DUMPFILE
outputs a unmodified binary file while OUTFILE
adds newlines and escapes some special characters.
Exports the sys_eval()
function from lib_mysqludf_sys.so
:
At this stage we can execute any command using the sys_eval()
function:
Last updated