Subscribe to Windows IT Pro
September 29, 2008 12:00 AM

Find Weak Database Passwords

T-SQL stored procedure checks passwords' complexity
SQL Server Pro
InstantDoc ID #99987
Rating: (2)
Downloads
99987.zip

The usp_Check_Passwords stored procedure is a simple T-SQL password-cracking tool that you can use to check the complexity of the passwords used for SQL Server database logins. This stored procedure requires access to the passwd column of the syslogins system table in the master database. It is unlikely that a hacker will gain access to the syslogins table, but nonetheless it’s a useful tool for finding weak passwords.

The stored procedure takes one parameter: the pathname of a text file containing passwords. It uses the BULK INSERT statement executed dynamically to load the password file into SQL Server. Password files can be obtained from a number of places on the web. Alternatively, you can write your own password file. Simply put each password on a separate line and save the password list as a text file. Figure 4 shows an example of a simple password file named Pswfile.txt. To use this file with usp_Check_Passwords, you’d use the code

USE master GOEXEC usp_check_passwords   'C:\temp\pswfile.txt'

Note that you’d need to customize the password file’s path.

The stored procedure uses the undocumented PWDCompare system function to compare each passed-in password against the passwd column in the syslogins table. The procedure will also detect blank passwords and trivial logins (i.e., logins that have the same password as their login name).

I wrote and checked usp_Check_Passwords on SQL Server 2005 Developer Edition SP1. You can download the code for this stored procedure by clicking the 99987.zip hotlink at the top of this page.

—Eli Leiba, senior application DBA, Israel Electric

Related Content:

ARTICLE TOOLS

Comments
  • TIM
    4 years ago
    Oct 02, 2008

    Oh, yeah, I added the following at the end of the select statement to exclude the Certificate logins:
    and syslogins.name NOT LIKE '##MS_%##'

  • TIM
    4 years ago
    Oct 02, 2008

    Thanks for the code. This works good for trivial passwords, but after I created a login with a blank password using Management Studio (on SQL 2000 & 2005 instances), it doesn't show up on the report when I run this.
    After creating a login with blank password using Enterprise Manager on a SQL 2000 instance, that login shows up as NULL password on the report.
    Examining the syslogins table, Management Studio apparently doesn't store the password as 'NULL', even though when logging on with that account, a blank password works.
    Can you modify the code for this?
    Thanks.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.