SQL Server 禁用扩展存储过程 - pursuer.chen
SQL Server 禁用扩展存储过程
2018-01-10 10:45
pursuer.chen
阅读(2451)
评论(0)
编辑
收藏
举报
概述
扩展存储过程是 SQL Server 实例可以动态加载和运行的 DLL。扩展存储过程是使用 SQL Server 扩展存储过程 API 编写的,可直接在 SQL Server 实例的地址空间中运行。扩展存储过程可能会产生内存泄漏或其他降低服务器的性能及可靠性的问题。固定服务器角色 sysadmin 的成员可以使用 SQL Server 实例来注册该扩展存储过程,然后授予其他用户执行该过程的权限。扩展存储过程只能添加到 master 数据库中。有一些系统自带的扩展存储过程操作的权限非常的高,包括修改注册表和修改文件的权限,比如“xp_cmdshell”。为了保证数据库的安全需要将这部分扩展存储过程给禁用。如果你们公司需要面临ICP备案的话那么这个事情是必须要做的。
需要禁用的扩展存储过程包括:
SELECT object_name,state from sys.system_components_surface_area_configuration WHERE state=1 and object_name IN ( \'xp_regdeletevalue\', \'xp_regremovemultistring\', \'xp_regwrite\', \'xp_regaddmultistring\', \'xp_regdeletekey\', \'xp_enumerrorlogs\', \'xp_enumgroups\', ---不中视图中 \'xp_loginconfig\', \'xp_getfiledetails\', \'xp_regenumvalues\', \'sp_makewebtask\', ---对应系统外围配置\'xp_cmdshell\' \'xp_cmdshell\', ---对应系统外围配置\'Ole Automation Procedures\' \'Sp_OACreate\', \'Sp_OADestroy\', \'Sp_OAGetErrorInfo\', \'Sp_OAGetProperty\', \'Sp_OAMethod\', \'Sp_OASetProperty\', \'Sp_OAStop\' )
一、禁用扩展存储过程
有一些扩展存储过程它是属于服务器外围配置选项,可以使用sp_configure来开启和禁用。例如xp_cmdshell
---开启xp_cmdshell sp_configure \'show advanced options\', 1; GO sp_configure \'allow updates\',0 ---开启允许更新系统表,当更改系统配置选项时提示不运行对系统目录即时更新时需要开启改功能 go reconfigure; go sp_configure \'xp_cmdshell\', 1;----开启xp_cmdshell go reconfigure; go sp_configure \'allow updates\',1----关闭更新系统表功能 go sp_configure \'show advanced options\', 0; go ---关闭xp_cmdshell sp_configure \'show advanced options\', 1; GO sp_configure \'allow updates\',0 ---开启允许更新系统表 go reconfigure; go sp_configure \'xp_cmdshell\', 0;----关闭xp_cmdshell go reconfigure; go sp_configure \'allow updates\',1----关闭更新系统表功能 go sp_configure \'show advanced options\', 0;
二、拒绝授予扩展存储过程的可执行权限
而除了系统外围配置选项涉及的扩展存储过程可以通过sp_configure开启和禁用之外,剩下的系统扩展存储过程只能通过拒绝授予可执行权限的方式来禁用。
从SQLServer2005开始就不能通过sp_dropextendedproc 删除系统扩展存储过程
可以通过拒绝 public 角色对扩展存储过程的 EXECUTE 权限
select \'DENY EXECUTE ON \'+object_name+\' TO public\',object_name,state from sys.system_components_surface_area_configuration WHERE state=1 and object_name IN ( \'xp_regdeletevalue\', \'xp_regremovemultistring\', \'xp_regwrite\', \'xp_regaddmultistring\', \'xp_regdeletekey\', \'xp_enumerrorlogs\', \'xp_enumgroups\', ---不中视图中 \'xp_loginconfig\', \'xp_getfiledetails\', \'xp_regenumvalues\', \'sp_makewebtask\', ---对应系统外围配置\'xp_cmdshell\' \'xp_cmdshell\', ---对应系统外围配置\'Ole Automation Procedures\' \'Sp_OACreate\', \'Sp_OADestroy\', \'Sp_OAGetErrorInfo\', \'Sp_OAGetProperty\', \'Sp_OAMethod\', \'Sp_OASetProperty\', \'Sp_OAStop\' );
三、查询权限
USE MASTER ; WITH CET AS( SELECT \'DENY EXECUTE ON \'+object_name+\' TO public\' AS DenySQL,object_name,state from sys.system_components_surface_area_configuration WHERE state=1 and object_name IN ( \'xp_regdeletevalue\', \'xp_regremovemultistring\', \'xp_regwrite\', \'xp_regaddmultistring\', \'xp_regdeletekey\', \'xp_enumerrorlogs\', \'xp_enumgroups\', ---不中视图中 \'xp_loginconfig\', \'xp_getfiledetails\', \'xp_regenumvalues\', \'sp_makewebtask\', ---对应系统外围配置\'xp_cmdshell\' \'xp_cmdshell\', ---对应系统外围配置\'Ole Automation Procedures\' \'Sp_OACreate\', \'Sp_OADestroy\', \'Sp_OAGetErrorInfo\', \'Sp_OAGetProperty\', \'Sp_OAMethod\', \'Sp_OASetProperty\', \'Sp_OAStop\' ) ) SELECT A.name,schema_name(A.schema_id) [schema],A.type,b.permission_name,B.type,B.state_desc,C.name,c.type_desc FROM sys.all_objects AS A LEFT JOIN sys.database_permissions AS B ON B.major_id=A.object_id AND B.minor_id=0 AND B.class=1 LEFT JOIN sys.database_principals AS C ON C.principal_id = B.grantee_principal_id where A.name IN(SELECT object_name FROM CET) ORDER BY A.name
参考:http://blog.csdn.net/kk185800961/article/details/52188556
参考:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-dropextendedproc-transact-sql
总结
备注: 作者:pursuer.chen 博客:http://www.cnblogs.com/chenmh 本站点所有随笔都是原创,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接,否则保留追究责任的权利。 《欢迎交流讨论》 |
.feedbackCon a { border-bottom: 1px dotted rgba(51, 51, 51, 1) }