[+] Wayc0de's Blog[+]

Tampilkan postingan dengan label MySQL. Tampilkan semua postingan
Tampilkan postingan dengan label MySQL. Tampilkan semua postingan

10/03/14

Playing with SQL Injection and Firewall Bypassing

Playing with SQL Injection and Firewall Bypassing

Disclaimer: This article is only for educational purposes, security researchers, and pentester. I would like to clarify that I am completely against cyber-crime.

ABSTRACT
Most cyber-attacks in the world that involve websites occurs due to lack of updates and configuration faults resulting in explorations of success.
One of the main threats is SQL Injection that left many worried about their systems, programmers, and SQL databases.
The biggest problem is not the DBMS itself but the lack of definition and verification of the input fields in web applications.

CONTEXT
Many web developers do not know how SQL queries can be handled and assume that an SQL query is a trusted command. This allows for SQL queries to circumvent access controls, thereby bypassing standard authentication and authorization checks. And sometimes SQL queries even may allow access to the command shell on the server operating system level.
Direct injection of SQL commands is a technique where an attacker creates or alters existing SQL commands to expose hidden data or to override valuable data, and even to execute dangerous system level commands on the server.

INTRODUCTION
Structured Query Language is the standard declarative language for relational databases. This allows for its simplicity and ease of use.
SQL was originally developed in the early 70s at IBM labs.
SQLMAP is a tool used for this type of vulnerability.
It is Open source, and often is used for Penetration Testing that enable intrusions on fragile DBMS written in Python. It provides functions to detect and exploit vulnerabilities of SQLI. Let's use the example sqlmap.py, widely used in operating systems and databases.

STEP BY STEP
Readers I will try to explain this in the simplest possible way.

You must have a vulnerable target, to find out if the target is vulnerable just input ' at the end of the URL being tested and press "Enter" if some error is returned the database is vulnerable.
You can use google to find it with some dork. Example: inurl: news.php id = 1?
There is a bank of google dorks data and several other possibilities that can be used to filter your search.

cd /pentest/database/sqlmap

We will now begin the game, to view the menu for sqlmap.py use the command ./sqlmap.py -h

Let's run sqlmap.py, the parameter [--dbs], to search the all databases in DBMS.


Or use the parameter --current-db to show the databases that are being used.

The parameter -D is for the target of database and --tables is tables list.


We will verify the existence of interesting information in the table (admin_users), time to list the columns. The parameter is –columns.

It is important to always indicate the target database (-D) data before listing the tables because if you do not do this (without the -D) it will list all tables in all databases.
-T = target table
-C = target columns, can be more than one column to be chosen. Example: username, password.
--dump = obtain, extract data.
Important to remember the parameter --proxy: enables use of proxy.  

Example:  /sqlmap.py --url "http://testphp.vulnweb.com/listproducts.php?cat=1" --dbs --proxy=http://183.223.10.108:80

Readers, I think that's the basics for beginners. sqlmap.py also has many interesting functions, I suggest researching about --prefix=PREFIX, --postfix=POSTFIX and takeover options.
More information about the program and videos of them in action on the official site.

--dump is to extract the data from the site but is not given any, this must be within the selected column, and you have to choosen what to extract from the column, where I extracted the logins and passwords are saved within the column.

Generally, the field of "passwords" DBMS are encrypted.
We then need to decrypt the passwords in order to access the target system.
We can find a way to log into the system. But wait, the passwords are encrypted in MD5, hahahaha put your hash on:http://www.md5decrypt.org and may be decrypted or otherwise


BEYOND THE BASICS
Readers, lucky for us, there are some awesome tamper scripts for sqlmap, which can be found in the latest development version from the Subversion repository.

svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap sqlmap-dev

In fact the function of the tamper scripts is to modify the request in a way that will escape detection rules WAF (Web Application Firewall). In some cases it may be necessary to combine some tamper scripts together in order to fool the WAF. For a complete list of scripts for tampering, you may find https://svn.sqlmap.org/sqlmap/trunk/sqlmap/tamper/

Many enterprises often overlook the current vulnerabilities and rely only on the firewall for protection. Unfortunately, most, if not all firewalls can be bypassed. So gentlemen, I want to demonstrate how to use some of the new features of sqlmap to bypass WAF’s/IDS.

Well, I'll demonstrate some important scripts that are charencode.py and charcodeencode.py to work with MySQL.

Hands-on: To begin using tamper scripts, you use the --tamper followed by the script name. In the example, we use the command:

Summary of charencode.py
Quite simply, this script is useful for ignoring very weak web application firewalls (WAF) …
Another interesting function url-decode the request before processing it through their set of rules (:
The web server will anyway go to url-decoded back version, concluding, it should work against any DBMS.

Example to use:
We will demonstrate the use of charunicodeencode.py for additional security. The vast number of organizations have deployed WAF. Guys, this is a tricky part to exploit such an environment. Well, standard SQL injection attack vectors will not work neither will the scripts.
That is the reason we use tamper scripts, this facility known as “tamper scripts" in aid of a quiet way to bypass web application firewalls.

Guys, I have demonstrated just a few of the many tamper scripts. We highly recommend testing them out as each one can be used in different situations.

Notes: That's not a tool for "script kiddies" it is of utmost importance to make use of such a powerful tool responsibly and maturely.
Caution if used in the wrong way, sqlmap generates many queries and can affect the performance of the database target, moreover strange entries and changes to the database schema are possible if the tool is not controlled and used extensively.

PARTLY ANONYMOUS
I will demonstrate to you how to use sqlmap with The Onion Router for the protection of IP, DNS, etc... In your Linux, in the terminal type:
$ sudo apt-get install tor tor-geoip

After enter the sqlmap folder and type:
./sqlmap.py -u "http://www.targetvuln.com/index.php?cata_id=1" -b -a –tor --check-tor--user-agent="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

The argument --tor invokes the Tor to be used and the --check-tor checks if Tor is being used properly, if not, you will receive an error message in red at the terminal. The User Agent is the googlebot, all your requests on the site will look like the Google bot doing a little visit.

TOR at SQLMap, we can set your TOR proxy for hiding the source from where the traffic or request is generated.

–tor-port–tor-type :  the parameter can help you out to set the TOR proxy manually.
check-tor : the parameter will check if the tor setup is appropriate and functional.

CONCLUSION:
It is known that many targets have been explored through SQL Injection a few years ago when this threat was discovered, the injection form was "the nail". The pentester had to enter the codes manually, taking longer to complete the attack.
Then came the development of programs that automated attack. Nowadays perhaps the best known of these programs is sqlmap.py. SQLMAP is a program of open source testing framework written in Python. It has full support for database systems: MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase, SAP MaxDB and also supports 6 types of SQL Injection techniques.

SOLUTION:
1.    Correct the SQL server regularly.
2.    Limit the use of dynamic queries.
3.    Escape input data from users.
4.    Stores the credentials of the database in a separate file.
5.    Use the principle of least privilege.
6.    Turn off the magic quotes.
7.    Disable shell access.
8.    Disable any feature of the bank that you do not need
9.    Test your code
10. Search in google advanced techniques to correct this vulnerability.


Read More...

18/10/11

Import Sql Dump File to Mysql Database

First lets look at what is mySQL database?

MySQL is a relational database management system (RDBMS) which has more than 11 million installations. The program runs as a server providing multi-user access to a number of databases. MySQL is owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now a subsidiary of Sun Microsystems, which holds the copyright to most of the codebase. The project's source code is available under terms of the GNU General Public License, as well as under a variety of proprietary agreements.


Why use import or export of sql dump file (scenario)?

I have two MySQL databases located on a server somewhere. I connect via secure shell. I don't know all of the details about the configuration of this particular server but it obviously has MySQL installed/configured properly and you can assume that any other 'very likely' items would also be resident. I need to completley copy one database into the other (one is currently quite large, the second is empty).

And the easiest way to do this is use sql export to dump file and sql import of dump file to mySQL database. How to create mySQL dump file (export database to sql file)?

The easiest way to export is use next syntax in command prompt (cmd):
mysqldump -u USER -p PASSWORD DATABASE > filename.sql

For example we have database with next parameters:

database username baseu01
database password h4z56s3
database name database01
sql export file name export.sql

Appropriate command line for export is:
mysqldump -u baseu01 -p h4z56s3 database01 > filename.sql

After executing export command you will have file "export.sql" in your folder.

Example how sql export dump file looks like:

-- phpMyAdmin SQL Dump
-- version 2.9.0.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 26, 2007 at 07:14 AM
-- Server version: 4.1.21
-- PHP Version: 4.4.2
--
-- Database: `optimumd_search`
--

-- --------------------------------------------------------

--
-- Table structure for table `PLD`
--

CREATE TABLE `PLD` (
`ID` int(11) NOT NULL auto_increment,
`TITLE` varchar(255) NOT NULL default '',
`CACHE_TITLE` text,
`TITLE_URL` varchar(255) default NULL,
`CACHE_URL` text,
`DESCRIPTION` longtext,
`PARENT_ID` int(11) NOT NULL default '0',
`STATUS` int(11) NOT NULL default '1',
`DATE_ADDED` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
...

INSERT INTO `PLD` VALUES (1, 'Arts', 'Arts', 'Arts', 'index.php?c=1', '', 0, 2, '2007-, '');
INSERT INTO `PLD` VALUES (2, 'Business', 'Business', 'Business', 'index.php?c=2'01', 264,);
INSERT INTO `PLD` VALUES (3, 'Computers and Internet', 'Computers aernet', 'Compd_I ...);
INSERT INTO `PLD` VALUES (4, 'Games', 'Games', 'Games', 'index.php1', 88, 0, 0, '', '');
INSERT INTO `PLD` VALUES (5, 'Health', 'Health', 'Health', 'index.php?c=5'', 170, 0,, '');
INSERT INTO `PLD` VALUES (6, 'Home', 'Home', 'Home', 'index.php?c=6', '', 0, 0, '', '');
INSERT INTO `PLD` VALUES (7, 'Kids and Teens', 'Kids and Teens', 'Kids_and_Tee2-22 12:46 ...);
INSERT INTO `PLD` VALUES (8, 'News', 'News', 'News', 'index.php?c=8, 53, 0, 0, '', '');
INSERT INTO `PLD` VALUES (9, 'Recreation', 'Recreation', 'Recreati007-02-25 151', 118, ...);

...

So what to do with sql dump file? Simple... Use it as an archive if some disaster happends and you loose your database or windows server crashes - you can allways import sql dump file back in mySQL database.

How to import sql dump file to mySQL database?

The scenario: server crashes and you got mysql dump file stored on your hard drive. First you install mySQL database - then create database, database user and database password and then use next command line:

mysql -u username -p password database_name < filename.sql If we use the same example as we used for export command line for export is: mysql -u baseu01 -p h4z56s3 database01 < export.sql Advanced options for exporting or importing a database How to Export A MySQL Database Structures Only If you no longer need the data inside the database’s tables (unlikely), simply add –no-data switch to export only the tables’ structures. For example, the syntax is: mysqldump -u username -ppassword –no-data database_name > dump.sql

How to Backup Only Data of a MySQL Database

If you only want the data to be backed up, use –no-create-info option. With this setting, the dump will not re-create the database, tables, fields, and other structures when importing. Use this only if you pretty sure that you have a duplicate databases with same structure, where you only need to refresh the data.

Syntax:
mysqldump -u username -ppassword –no-create-info database_name > dump.sql
How to Dump Several MySQL Databases into Text File


–databases option allows you to specify more than 1 database.

Example syntax:
mysqldump -u username -ppassword –databases db_name1 [db_name2 ...] > dump.sql

How to Dump All Databases in MySQL Server


To dump all databases, use the –all-databases option, and no databases’ name need to be specified anymore.

mysqldump -u username -ppassword –all-databases > dump.sql
How to Online Backup InnoDB Tables


Backup the database inevitable cause MySQL server unavailable to applications because when exporting, all tables acquired a global read lock using FLUSH TABLES WITH READ LOCK at the beginning of the dump until finish. So although READ statements can proceed, all INSERT, UPDATE and DELETE statements will have to queue due to locked tables, as if MySQL is down or stalled. If you’re using InnoDB, –single-transaction is the way to minimize this locking time duration to almost non-existent as if performing an online backup. It works by reading the binary log coordinates as soon as the lock has been acquired, and lock is then immediately released.

Syntax:
mysqldump -u username -ppassword –all-databases –single-transaction > dump.sql
mysql database import-export usage and linking to us

This tutorial can be used with windows server 2003, windows server 2000, windows XP and windows XP proffessional or even unix wervers - as long as mySQL database is installed on your computer.

If you find this tutorial to be usefull please add link to it import-sql-dump-file-to-mysql-database so other people will also find this tutorial page.
Read More...

27/09/11

Underground Radar: Possible Compromise of MySQL.com and its Subdomains

We recently found an interesting post in a Russian underground forum in the course of our research. People exchange information about their illegal activities in these kinds of forums. We found a user in the forum with the handle ‘sourcec0de’ and ICQ number ’291149′ who is currently offering root access to some of the cluster servers of mysql.com and its subdomains.

Click for larger view

The screenshot above shows that the seller appears to have a shell console window with root access to these servers. The price for each access starts at $3,000 USD, with the exchange of money/access being provided by the well known garant/escrow system, whereby a trusted third party verifies both sides of the transaction.

In our previous underground research, we have also seen the user ‘sourcec0de’ selling stolen PayPal accounts and discussing the management of botnet command and control servers.

We contacted MySQL.com about this issue last week. We are making this public to stress the fact that hackers do not only profit from selling stolen data or by inserting bad links into spammed or phishing messages, websites and other possible infection vectors . In this case, whether sourcec0de’s claim is true or not, it shows how cybercriminals are so brazen as to sell admin access to specific systems, which could be negatively impacted by their break-ins.


nb : trendmicro Read More...