NCSC 发布了 100.000 个最常用密码的列表,请参阅 100K passwords
我想知道我的任何用户是否使用过这些密码之一,因此受 bp_check 想法的启发,我写了一张支票。
我的做法正确吗?
我在使用 Unicode 时遇到了问题,但现在应该已经解决了。
最佳答案
这是我运行此类密码检查的代码:
-- script to check if any of the passwords on your SQL Server is amongst the 100.000 most used passwords that Troy Hunt and NCSC released
-- see https://www.ncsc.gov.uk/blog-post/passwords-passwords-everywhere
--drop table dbo.PwnedPasswordTop100k
create table dbo.PwnedPasswordTop100k ( pw nvarchar(500) collate Latin1_General_CS_AS not null)
go
bulk insert dbo.PwnedPasswordTop100k
FROM 'c:\temp\PwnedPasswordTop100k.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
, codepage=65001
)
go
SELECT sl.name , ppt.pw
from sys.sql_logins sl
cross join dbo.PwnedPasswordTop100k ppt
where PWDCOMPARE(ppt.pw, sl.password_hash) = 1
union all
SELECT s.name, 'password is NULL' FROM sys.sql_logins s -- password is null (from idea from BP_Check http://aka.ms/BPCheck;)
where password_hash is null
AND exists(SELECT * FROM fn_my_permissions(NULL, 'SERVER') where permission_name='CONTROL SERVER')
and name NOT IN ('MSCRMSqlClrLogin','##MS_SmoExtendedSigningCertificate##','##MS_PolicySigningCertificate##','##MS_SQLResourceSigningCertificate##','##MS_SQLReplicationSigningCertificate##','##MS_SQLAuthenticatorCertificate##','##MS_AgentSigningCertificate##','##MS_SQLEnableSystemAssemblyLoadingUser##')
union all
SELECT s.name, s.Name FROM sys.sql_logins s -- password the same as login (from idea from BP_Check http://aka.ms/BPCheck;)
where PWDCOMPARE(s.name, s.name) = 1
union all
select 'not SYSADM', 'You do not have CONTROL SERVER permissions, and cannot see any password_hashes'
where not exists(SELECT * FROM fn_my_permissions(NULL, 'SERVER') where permission_name='CONTROL SERVER')
--select top (10000) * from dbo.PwnedPasswordTop100k where pw like N'пїЅпїЅпїЅпїЅ'
begin try
drop table dbo.PwnedPasswordTop100k
end try
begin catch
end catch
必须将 PwnedPasswordTop100k.txt 文件复制到 SQL Server 上的 c:\temp,并且运行 SQL Server 的帐户必须有权访问该文件。或者,将路径更改为 SQL Server 可以看到的位置。
并非每个人都可以访问 SQL Server 可以看到的共享。
所以我还编写了一个包含所有密码的脚本:
Script with 100.000 passwords
这是一个 1500 kB 的 SELECT 语句。
相当大,但您可以在 SQL Server Management Studio 中运行它。
My SQL Server 可以每分钟检查大约 6 个用户,因此脚本速度不是很快。
关于sql - 检查 SQL Server 上的常用密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56024332/