Hacking MySQL Online Databases with Sqlmap
In this tutorial, In that tutorial, I showed you the basics of running a MySQL server on BackTrack. In addition, if you are not familiar with databases and DataBase Management Systems (DBMS). Since MySQL is SO important in so many web applications, I will be doing more MySQL tutorials in the future. The more you know about MySQL, the better you can hack MySQL!
Generally, MySQL is teamed up with PHP and an Apache web server (often referred to as LAMPP or XAMPP) to build dynamic, database driven web sites. Such development packages as Drupal, Joomla, Wordpress, Ruby on Rails and others all use MySQL as their default database. Millions of websites have MySQL backends and very often they are "homegrown" websites, without much attention on security.
In this tutorial, we will looking to extract information about an online MySQL database before we actually extract information from the database. Once again, I'll repeat, the more we know, the more successful we will be in hacking and the less chance you will be detected.
Here, we will be using one of the best database hacking tools available, sqlmap. Sqlmap can be used for databases other than MySQL, such Microsoft's SQL Server and Oracle, but here we will focus its capabilities on those ubiquitous web sites that are built with PHP, Apache and MySQL.
Step 1Start Sqlmap
First, fire up BackTrack and go to BackTrack, then Information Gathering, then Database Analysis, then MySQL Analysis and finally, sqlmap as shown in the screenshot below.Step 2Find a Vulnerable Web Site
In order to get "inside" the web site and ultimately, the database, we are looking for web sites that end in "php?id=" where XXX represents some number. Those who are familiar with google hacks/dorks can do a search on google by entering:- inurl:index.php?id=
- inurl:gallery.php?id=
- inurl:post.php?id=
- inurl:article?id=
For our purposes here and to keep you out of the long reach of the law, we will be hacking a website designed for this purpose, www.webscanhost.org. We can practice on this web site and refine your skills without worrying about breaking any laws and having to make bail money for you.
Step 3Open Sqlmap
When you click on sqlmap, you will be greeted by a screen like that below. Sqlmap is a powerful tool, written as a Python script (we will be doing Python tutorial soon) that has a multitude of options. We will just be scratching the surface of its capabilities in this tutorial.Step 4Determine the DBMS Behind the Web Site
Before we begin hacking a web site, we need to gather information. We need to know WHAT we are hacking. As I have said many times before, most exploits are very specific to the OS, the application, services, ports, etc. Let's begin by finding out what the DBMS is behind this web site.The start sqlmap on this task, we type:
- ./sqlmap.py -u "the entire URL of the vulnerable web page"
- ./sqlmap.py -u "http://www.webscantest.com/datastore/ search_get_by_id.php?id=4"
Step 5Find the Databases
Now that we know what the database management system (DBMS) is MySQL 5.0, we need to know what databases it contains. sqlmap can help us do that. We take the command we used above and append to it --dbs, like this:- ./sqlmap.py -u "http://www.webscantest.com/datastore/
Step 6Get More Info from the Database
So, now we know what the DBMS is (MySQL 5.0) and the name of a database of interest (scanme). The next step is to try to determine the tables and columns in that database. In this way, we will have some idea what data is in the database, where it is and what type of data (numeric or string). All of this information is critical and necessary to extracting the data. To do this, we need to make some small revisions to our sqlmap command. Everything else we have used above remains the same, but now we tell sqlmap we want to see the tables and columns from the scanme database. We can append our command with --columns -D and the name of the database, scanme such as this:- ./sqlmap.py -u "http://www.webscantest.com/datastore/
As we can see below, sqlmap successfully was able to enumerate three tables; (1) accounts, (2) inventory, and (3) orders, complete with column names and datatypes. Not Bad!
Keep coming back, my amateur hackers, for more adventures in Hackerland!
Comments
Post a Comment