为什么 xp_cmdshell 在 SQL Server 2012 中不起作用? [英] Why doesn't xp_cmdshell work in SQL Server 2012?

查看:56
本文介绍了为什么 xp_cmdshell 在 SQL Server 2012 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
启用‘xp_cmdshell’ SQL Server

当我在 SQL Server 2012 中运行 xp_cmdshell 命令时,我收到以下消息:

When I run xp_cmdshell command in SQL Server 2012, I get the following message:

SQL Server 阻止访问组件xp_cmdshell"的过程sys.xp_cmdshell"因为这个组件被关闭了作为此服务器安全配置的一部分.系统管理员可以启用xp_cmdshell"通过使用 sp_configure.有关启用xp_cmdshell"的更多信息,在 SQL Server 联机丛书中搜索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', search for 'xp_cmdshell' in SQL Server Books Online.

但是,在 SQL Server 2000 中,此查询已成功执行.

But, in SQL Server 2000 this query is executed successfully.

推荐答案

从 SQL Server 2005 开始,当他们引入 表面区域配置工具,旨在使SQL Server默认更安全.该工具已停用,但您仍然可以使用 sp_configure<控制行为/a>.MSDN 上显示了一个示例:

This has been disabled out of the box starting with SQL Server 2005, when they introduced the Surface Area Configuration Tool, in an effort to make SQL Server more secure by default. That tool has since been retired, but you can still control the behavior using sp_configure. An example is shown on MSDN:

-- 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

(我也多年前写过博客.)

原因是这是一个潜在的安全漏洞.如果允许 SQL Server 执行 xp_cmdshell,那么理论上可以向那里发送任何操作系统命令,绕过您认为拥有的任何和所有安全性.当 SQL Server 服务帐户和/或代理帐户被提升到 sysadmin 或其他级别时,这尤其成问题,因为这比仅明确定义他们应该能够做的确切事情更容易.

The reason is that this is a potential security hole. If you allow SQL Server to execute xp_cmdshell, then they can theoretically send any operating system command there, bypassing any and all security you thought you had. This is especially problematic when the SQL Server service account and/or the proxy account have been elevated to sysadmin or other levels because that's easier than explicitly defining only the exact things they should be able to do.

与其启用和禁用它以支持命令行交互,一种公开操作系统功能同时仍对安全性有一定控制权的流行方法是使用 SQL-CLR 实现您需要的操作系统级功能.这是使用 CLR 访问文件系统的良好起点(但是,如果您四处搜索,您会发现更多现代和详尽的方法).

Rather than enable it and disable it to support command-line interaction, a popular way to expose operating system functionality while still having some control over security is to implement the OS-level functionality you need using SQL-CLR. Here is a good starting point for accessing the file system with CLR (however if you search around you will find much more modern and exhaustive approaches).

这篇关于为什么 xp_cmdshell 在 SQL Server 2012 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆