人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 30, 2006

SQL2005中xp_cmdshell安全性增强

Filed under: SQL&DB Accessing

在程序中用到以下的机制来新建一个account 库
1 datach account 标准库,
2 copy account 标准库的mdf文件,生成新的account库mdf文件.
3 attach 新的account库.

但是这个过程的步骤2会在sql2005上出错.
可用以下的sql语句来重现这个错误

1 create database AA
2 exec sp_detach_db AA,’True’
3 exec xp_cmdshell ‘copy /Y "c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\AA.mdf" "D:\AA.mdf"’

语句1执行后会生成一个AA.mdf文件,在查看其属性中的Sercurity页,会看到以下帐号
Administrator
Network service
Service

sql2000中当语句2执行后查看AA.mdf文件属性中的Sercurity页,会看到以下帐号
Administrator
SQLServer2005MSSQLUser$机器名$实例名
Service

而在sql2005中当语句2执行后查看AA.mdf文件属性中的Sercurity页,只会看到当前操作者的帐号

语句3中的xp_cmdshell是以Service权限执行的,所以在Sql2005下会失败.
提示Access is denined.

同时,如果sqlserver中已经禁止掉xp_cmdshell的使用,会看到以下的错误提示:
SQL Server blocked access to procedure ’sys.xp_cmdshell’ of component ‘xp_cmdshell’ because this
component is turned off as part of the security configuration for this server.
A system administrator can enable the use of ‘xp_cmdshell’ by using sp_configure.
For more information about enabling ‘xp_cmdshell’, see "Surface Area Configuration" in SQL Server Books Online.

 

附:
http://msdn2.microsoft.com/zh-cn/library/ms190693(SQL.90).aspx

sql2005默认情况下,xp_cmdshell 安装时处于禁用状态,但是可以通过使用
外围应用配置器工具(Configuration Tools->SQL Server Surface Area Configuration)
或运行 sp_configure 系统存储过程来启用它,代码如下:

– To allow advanced options to be changed.
EXEC sp_configure ’show advanced options’, 1
GO
– To update the currently configured value for advanced options.
RECONFIGURE
GO
– To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1
GO
– To update the currently configured value for this feature.
RECONFIGURE
GO

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/05/30/p73/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham