When dealing with SQL Server 2008 security audits, one critical question often arises: where exactly does the system store login passwords? While the LOGINPROPERTY function can retrieve password hashes, security professionals frequently need to examine the underlying storage mechanism.
SQL Server 2008 stores login credentials in two primary locations:
1. Master database system tables (primary storage)
2. Windows registry (for some configuration data)
The core authentication data resides in these system tables:
- sys.sql_logins (stores SQL-authenticated logins)
- sys.server_principals (contains principal metadata)
- sys.key_encryptions (stores encryption-related information)
SQL Server 2008 uses SHA-1 hashing (with salt) for password storage. The actual hash can be retrieved with:
SELECT name, password_hash
FROM sys.sql_logins
WHERE is_disabled = 0;
While you can't retrieve plaintext passwords, you can access the binary hash data. This PowerShell snippet extracts password hashes:
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = "Server=YourServer;Database=master;Integrated Security=True"
$command = New-Object System.Data.SqlClient.SqlCommand
$command.Connection = $connection
$command.CommandText = "SELECT name, password_hash FROM sys.sql_logins"
$connection.Open()
$reader = $command.ExecuteReader()
while ($reader.Read()) {
$name = $reader["name"]
$hash = [System.BitConverter]::ToString($reader["password_hash"])
Write-Output "Login: $name | Hash: $hash"
}
$connection.Close()
Some authentication-related data appears in the registry at:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.InstanceName\MSSQLServer
Important points for security audits:
- Passwords are never stored in plaintext
- The hash includes a per-login salt
- System tables are protected by SQL Server permissions
- Direct file access requires sysadmin privileges
For comprehensive security reviews, combine multiple data sources:
SELECT
l.name AS LoginName,
CONVERT(VARBINARY(256), l.password_hash) AS PasswordHash,
p.is_disabled,
p.create_date
FROM
sys.sql_logins l
JOIN
sys.server_principals p ON l.principal_id = p.principal_id
WHERE
p.type = 'S';
When auditing SQL Server 2008 security, a critical question arises: where are the actual password hashes stored? While LOGINPROPERTY('login_name', 'PasswordHash') retrieves the hash, it doesn't reveal the underlying storage mechanism.
SQL Server 2008 stores login credentials in system tables within the master database. The primary locations are:
SELECT name, password_hash
FROM sys.sql_logins
WHERE is_disabled = 0;
The actual data is persisted in the master.mdf file (primary data file) and its transaction log (mastlog.ldf). These are binary files that contain all system metadata, including password hashes.
Key points security auditors should know:
- Passwords are never stored in plain text
- Hashes use SHA-512 (SQL 2008 R2) or SHA-1 (original SQL 2008)
- System tables are encrypted when using TDE
For audit purposes, you can dump all login hashes using:
SELECT
name AS LoginName,
LOGINPROPERTY(name, 'PasswordHash') AS PasswordHash,
LOGINPROPERTY(name, 'IsLocked') AS IsLocked,
LOGINPROPERTY(name, 'IsExpired') AS IsExpired
FROM sys.server_principals
WHERE type_desc = 'SQL_LOGIN';
To enhance security:
- Enable Transparent Data Encryption (TDE) for the master database
- Regularly rotate SA and other privileged account passwords
- Implement Windows Authentication where possible
When examining SQL Server 2008 installations:
- The password hash format is 0x0100 + 4-byte salt + SHA-1 hash
- Hashes remain in transaction logs until log truncation
- Backup files (.bak) contain historical password hashes