Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


May 1997

How Safe Are Your SQL Server Passwords


RSS
Subscribe to Windows IT Pro | See More Security Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Password encryption in SQL Server 6.5 is not as secure as you think. Anyone with a little knowledge and SQL Server systems administrator (SA) privileges can capture passwords or disable encryption checks, essentially making the password clear text. You can't do much to prevent these problems, but you can be aware of them and understand their significance. If you know about some holes in SQL Server's password encryption, at least you'll know where you're exposed. With a little knowledge, you can work around the holes and use SQL Server's quirks to your benefit.

A History of SQL Server Passwords
Before SQL Server 6.0, SQL Server passwords were extremely vulnerable. Earlier versions of SQL Server stored clear text passwords in the password column of the syslogins system table, which has one row of values for each valid SQL Server logon. Anyone with the proper permissions could read the password column and then log on as that user. Most people weren't concerned about the passwords' security because people assumed--incorrectly--that users needed SA privileges to read the password. However, using any text editor, even Notepad, any user could read passwords directly from a database backup.

SQL Server 6.0 greatly improved security by encrypting passwords. SQL Server still stores passwords in syslogins, but it encrypts the string so even the SA can't read it. Therefore, you might think that because curious users can no longer pilfer passwords from a dump, passwords are secure and database administrators (DBAs) live happily ever after. Unfortunately, the story doesn't end quite so nicely. SAs can capture the encrypted form of a password in several ways without user knowledge.

Security Hole 1:
SAs Can Capture Passwords in a Private Table

Two built-in system procedures (SPs), sp_addlogin and sp_password, manage SQL Server passwords. The procedure sp_addlogin (shown in Listing 1) creates new users and passwords, and sp_password changes existing users' passwords. Microsoft and third-party applications that manage user accounts call these procedures under the covers even if you don't explicitly call them. For example, SQL Enterprise Manager (SEM) calls sp_addlogin whenever you add a new login. (You can easily verify this action by watching Transact-SQL--T-SQL--activity with SQLTrace.) Calling sp_addlogin moves passwords into the procedure and stores them in @passwd in clear text. Stealing passwords is simple in this model: You add an insert statement to sp_addlogin that captures the clear text version of the password in a history table:

Insert into PasswordHistory VALUES (@loginame, @passwd)

Now you can compile a complete list of passwords as SQL Server adds new logins to the system. The procedure sp_password has the same hole as sp_addlogin, so you can keep track of password changes by adding the same insert statement to sp_password.

Security Hole 2:
SAs Can Disable Password Encryption for Each Logon

In Listing 1, the password and status columns in the Values clause in the insert statement expose two more SQL Server secrets. SQL Server encrypts passwords with pwdencrypt, an undocumented system function that accepts a string variable and returns an encrypted version of the string. The system then stores the encrypted version in syslogins. SQL Server can validate a user's encrypted password at logon because instead of unencrypting the value in syslogins, SQL Server uses pwdcompare, another undocumented function call, to compare the clear text and encrypted versions. The logon proceeds if pwdcompare determines that the clear text and encrypted version match.

Here's where the status column comes in. The comment for status says, "0*08 bit means pw encrypt new alogorithm" (that's algorithm to you and me). That comment got me thinking, so just for fun, I removed the 0x08 bit from a few status columns in syslogins using ^, SQL Server's bitwise exclusive OR operator. (If you're not familiar with bitwise operators, pretend I'm subtracting 8 from the status value.) Sure enough, this action disabled password encryption. The passwords were clear text in the eyes of the database. I could now log on to the server using one of the supposedly encrypted passwords from syslogins; in fact, the server no longer accepted the encrypted string as a valid password. So, rogue SAs can defeat password encryption in SQL Server 6.5 by capturing passwords in a private table or temporarily disabling password encryption altogether for each logon.

On a positive note, however, you can use the secret password management functions to enhance a custom security model. I've seen many applications where developers have extended SQL Server's base security by adding a customized user table that contains a password column. You can call pwdencrypt and pwdcompare from T-SQL like any other server function and use them to create user-level password checks. The procedure pwdencrypt("un-encrypted") returns the encrypted string; pwdcompare("unencrypted string", "encrypted string") returns TRUE (1) if the strings match and FALSE (0) if they don't match. (Caution: The pwdencrypt and pwdcompare functions are undocumented. Microsoft does not support them, and they can change from release to release.)

   Previous  [1]  2  Next 


Top Viewed ArticlesView all articles
No Jobs, No Excitement at Apple's Last Macworld Keynote

Apple CEO Steve Jobs made the right move in skipping out on his company's last appearance at Macworld: In a Tuesday keynote address at the conference, Apple had no interesting new products to sell, opting instead to spend mind-numbing amounts of time on ...

Home Tech? Work Tech? Increasingly, It's Just Tech

Paul discusses how the consumer market is influencing business technology in ways that are unprecedented. ...

Where is Microsoft NetMeeting in Windows XP?

...


Security Whitepapers The Impact of Messaging and Web Threats

Why SaaS is the Right Solution for Log Management

Protecting (You and) Your Data with Exchange Server 2007

Related Events Security Summit

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Check out our list of Free Email Newsletters!

Security eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

Related Security Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing