SQL Server 2005如何起用


  本文标签:SQL Server 2005

  xp_cmdshell 扩展存储过程将命令字符串作为操作系统命令 shell 执行,并以文本行的形式返回所有输出  。由于xp_cmdshell 可以执行任何操作系统命令,所以一旦SQL Server管理员帐号(如sa)被攻破,那么攻击者就可以利用xp_cmdshell 在SQL Server中执行操作系统命令,如:创建系统管理员,也就意味着系统的最高权限已在别人的掌控之中  。由于存在安全隐患,所以在SQL Server 2005中,xp_cmdshell 默认是关闭的  。

  两种方式启用xp_cmdshell

  1、打开外围应用配置器—>

  功能的外围应用配置器—>

  实例名Database Enginexp_cmdshell—>

  启用

  2、sp_configure

  

  -- 允许配置高级选项
EXEC sp_configure show advanced options, 1
GO
-- 重新配置
RECONFIGURE
GO
-- 启用xp_cmdshell
EXEC sp_configure xp_cmdshell, 0
GO
--重新配置
RECONFIGURE
GO

  --执行想要的xp_cmdshell语句
Exec xp_cmdshell query user
GO

  --用完后,要记得将xp_cmdshell禁用(从安全角度安全考虑)
-- 允许配置高级选项
EXEC sp_configure show advanced options, 1
GO
-- 重新配置
RECONFIGURE
GO
-- 禁用xp_cmdshell
EXEC sp_configure xp_cmdshell, 1
GO
--重新配置
RECONFIGURE
GO