it编程 > 数据库 > MsSqlserver

SQL Server安全配置全面检查与优化方案

18人参与 2025-10-20 MsSqlserver

一、说明

1.1 覆盖操作系统和数据库版本

1.2 查询最小权限要求

例如创建的shijw用户,授权如下:

alter server role [diskadmin] add member [shijw];
alter server role [processadmin] add member [shijw];
alter server role [securityadmin] add member [shijw];
alter server role [setupadmin] add member [shijw];

二、sql语句

2.1 数据库用户密码复杂度认证

select name, is_policy_checked from sys.sql_logins;

sql返回结果:

2.2 数据库用户密码有效期策略

select name, is_policy_checked from sys.sql_logins;

sql返回结果:

2.3 连接会话限制

select convert(numeric(18,2), convert(numeric(18,2), c.value_in_use) / convert(numeric(18,2), maximum) * 100) as user_count
from sys.configurations c
where c.name = 'user connections';

sql返回结果:

2.4 连接数据库进程数限制

select convert(decimal(18,0), (sum(s.current_workers_count) * 1.0 / i.max_workers_count) * 100) as cpu线程使用率
from sys.dm_os_sys_info i, sys.dm_os_schedulers s
group by i.max_workers_count;

sql返回结果:

2.5 物理备份

select bs.database_name, 
       backuptype = case
           when bs.type = 'd' and bs.is_copy_only = 0 then 'full database'
           when bs.type = 'd' and bs.is_copy_only = 1 then 'full copy-only database'
           when bs.type = 'i' then 'differential database backup'
           when bs.type = 'l' then 'transaction log'
           when bs.type = 'f' then 'file or filegroup'
           when bs.type = 'g' then 'differential file'
           when bs.type = 'p' then 'partial'
           when bs.type = 'q' then 'differential partial' end + ' backup',
       case bf.device_type 
           when 2 then 'disk'
           when 5 then 'tape'
           when 7 then 'virtual device'
           when 9 then 'azure storage'
           when 105 then 'a permanent backup device'
           else 'other device' end as devicetype,
       bs.backup_start_date, 
       backupfinishdate = bs.backup_finish_date,
       [backupstatus] = case bs.backup_start_date when null then '备份失败' else '成功' end,
       latestbackuplocation = bf.physical_device_name
from msdb.dbo.backupset bs
left join msdb.dbo.backupmediafamily bf on bs.[media_set_id] = bf.[media_set_id]
where bs.backup_start_date > dateadd(month, - 2, sysdatetime())
order by bs.database_name asc, bs.backup_start_date desc;

sql返回结果:

2.6 网络传输加密

select distinct (encrypt_option) from sys.dm_exec_connections;

sql返回结果:

2.7 数据库存储加密

select d.name as 'database name',
       case
           when e.encryption_state = 3 then 'encrypted'
           when e.encryption_state = 2 then 'in progress'
           else 'not encrypted'
       end as state
from sys.dm_database_encryption_keys e
right join sys.databases d on d.database_id = e.database_id
left join sys.certificates c on e.encryptor_thumbprint = c.thumbprint;

sql返回结果:

2.8 透明加密

select name, is_encrypted from sys.databases;

sql返回结果:

2.9 连接超时机制

select comment, value from sys.sysconfigures where comment like 'remote%';

sql返回结果:

2.10 数据库版本补丁

select @@version;
select serverproperty('productversion');

2.11 弱口令

select name, create_date, is_disabled from sys.sql_logins where pwdcompare('', password_hash) = 1;
select name, create_date, is_disabled from sys.sql_logins where pwdcompare(name, password_hash) = 1;

2.12 c2审计

select value from sys.sysconfigures where comment = 'c2 audit mode';

sql返回结果:

2.13 sql审核

select status from sys.dm_server_audit_status where status = 1;

sql返回结果:

2.14 sql注入

select value from sys.sysconfigures where comment = 'enable or disable command shell';

sql返回结果:

三、总结

这些sql脚本主要用于检查sql server数据库的安全配置,确保数据库在操作系统、权限控制、备份、加密以及其他关键领域符合最佳实践。根据执行结果,系统管理员可以针对发现的问题采取相应的补救措施,进一步加强数据库的安全性。

以上就是sql server安全配置全面检查与优化方案的详细内容,更多关于sql server安全配置检查与优化的资料请关注代码网其它相关文章!

(0)

您想发表意见!!点此发布评论

推荐阅读

SQL中的参数类型深度解析

10-20

SSH连接服务器超时可能原因与解决方案

10-18

SQL Server建立自动备份的维护计划的全过程

10-16

SQL Server修改数据库名称的常用方法

10-16

PostgreSQL判断字段是否为null或是否为空字符串的几种方法

10-15

在Django中如何执行原生SQL查询详解

10-21

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论