获取xp_cmdshell的执行权限
尝试从存储过程中执行 xp_cmdshell 时,我看到一条错误消息。
xp_cmdshell 在实例上已启用。并且执行权限已授予给我的用户,但我仍然看到异常。
对象“xp_cmdshell”、数据库“mssqlsystemresource”、架构“sys”的 EXECUTE 权限被拒绝
部分问题是这是一个共享集群,并且我们在实例上有一个数据库,因此我们没有全方位的管理权限。所以我无法进入并授予权限,等等。
I am seeing an error message when trying to execute xp_cmdshell from within a stored procedure.
xp_cmdshell is enabled on the instance. And the execute permission was granted to my user, but I am still seeing the exception.
The EXECUTE permission was denied on the object ‘xp_cmdshell’, database ‘mssqlsystemresource’, schema ‘sys’
Part of the issue is that this is a shared cluster, and we have a single database on the instance, so we don't have a full range of admin permissions. So I can't go in and grant permissions, and what-not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于不是 SQL Server 实例上 sysadmin 角色成员的用户,您需要执行以下操作来授予对 xp_cmdshell 扩展存储过程的访问权限。此外,如果您忘记了其中一个步骤,我已经列出了将引发的错误。
启用 xp_cmdshell 过程
<块引用>
消息 15281,级别 16,状态 1,过程 xp_cmdshell,第 1 行
SQL Server 阻止了对组件“xp_cmdshell”的过程“sys.xp_cmdshell”的访问,因为该组件作为该服务器安全配置的一部分被关闭。系统管理员可以使用 sp_configure 启用“xp_cmdshell”。有关启用“xp_cmdshell”的详细信息,请参阅 SQL Server 联机丛书中的“外围区域配置”。*
为对 master 数据库具有公共访问权限的非 sysadmin 用户创建登录名< /p>
<块引用>
消息 229,级别 14,状态 5,过程 xp_cmdshell,第 1 行
对对象“xp_cmdshell”、数据库“mssqlsystemresource”、架构“sys”的 EXECUTE 权限被拒绝。*
授予对 xp_cmdshell 存储过程的 EXEC 权限
<块引用>
消息 229,级别 14,状态 5,过程 xp_cmdshell,第 1 行
对对象“xp_cmdshell”、数据库“mssqlsystemresource”、架构“sys”的 EXECUTE 权限被拒绝。*
使用 sp_xp_cmdshell_proxy_account 创建将在其下运行 xp_cmdshell 的代理帐户
<块引用>
消息 15153,级别 16,状态 1,过程 xp_cmdshell,第 1 行
xp_cmdshell代理帐户信息无法检索或无效。验证“##xp_cmdshell_proxy_account##”凭据是否存在并包含有效信息。*
从您的错误来看,似乎错过了步骤 2 或 3。我不熟悉集群,不知道该设置是否有什么特殊之处。
For users that are not members of the sysadmin role on the SQL Server instance you need to do the following actions to grant access to the xp_cmdshell extended stored procedure. In addition if you forgot one of the steps I have listed the error that will be thrown.
Enable the xp_cmdshell procedure
Create a login for the non-sysadmin user that has public access to the master database
Grant EXEC permission on the xp_cmdshell stored procedure
Create a proxy account that xp_cmdshell will be run under using sp_xp_cmdshell_proxy_account
It would seem from your error that either step 2 or 3 was missed. I am not familiar with clusters to know if there is anything particular to that setup.
我想完成 tchester 的回答。
(1) 启用 xp_cmdshell 过程:
(2) 为具有 master 数据库公共访问权限的非 sysadmin 用户创建登录名“Domain\TestUser”(windows 用户)
(3) 授予 xp_cmdshell 存储过程的 EXEC 权限
:( 4) 使用 sp_xp_cmdshell_proxy_account 创建将在其下运行 xp_cmdshell 的代理帐户
(5) 向用户授予控制服务器权限
I want to complete the answer from tchester.
(1) Enable the xp_cmdshell procedure:
(2) Create a login 'Domain\TestUser' (windows user) for the non-sysadmin user that has public access to the master database
(3) Grant EXEC permission on the xp_cmdshell stored procedure:
(4) Create a proxy account that xp_cmdshell will be run under using sp_xp_cmdshell_proxy_account
(5) Grant control server permission to user
扩展通过 SQL Server 代理自动将数据以 csv 格式导出到网络共享的功能。
(1) 启用 xp_cmdshell 过程:
(2) 为对 master 数据库具有公共访问权限的非 sysadmin 用户创建登录名“Domain\TestUser”(Windows 用户)。通过用户映射完成
(3) 将登录作为批处理作业:导航到本地安全策略 ->当地政策 ->用户权利分配。将用户添加到“作为批处理作业登录”
(4) 授予域\用户对网络文件夹的读/写权限
(5) 授予对 xp_cmdshell 存储过程的 EXEC 权限:
(6) 创建将运行 xp_cmdshell 的代理帐户 (7) 如果sp_xp_cmdshell_proxy_account
命令不起作用,请手动创建它
(8) 启用 SQL Server 代理。打开 SQL Server 配置管理器,导航到 SQL Server 服务,启用 SQL Server 代理。
(9)创建自动化作业。打开SSMS,选择SQL Server代理,然后右键单击作业并单击“新建作业”。
(10) 选择“所有者”作为您创建的用户。选择“步骤”,使“类型”= T-SQL。填写类似于下面的命令字段。将分隔符设置为“,”
(11) 相应地填写明细表。
To expand on what has been provided for automatically exporting data as csv to a network share via SQL Server Agent.
(1) Enable the xp_cmdshell procedure:
(2) Create a login 'Domain\TestUser' (windows user) for the non-sysadmin user that has public access to the master database. Done through user mapping
(3) Give log on as batch job: Navigate to Local Security Policy -> Local Policies -> User Rights Assignment. Add user to "Log on as a batch job"
(4) Give read/write permissions to network folder for domain\user
(5) Grant EXEC permission on the xp_cmdshell stored procedure:
(6) Create a proxy account that xp_cmdshell will be run under using sp_xp_cmdshell_proxy_account
(7) If the sp_xp_cmdshell_proxy_account command doesn't work, manually create it
(8) Enable SQL Server Agent. Open SQL Server Configuration Manager, navigate to SQL Server Services, enable SQL Server Agent.
(9) Create automated job. Open SSMS, select SQL Server Agent, then right-click jobs and click "New Job".
(10) Select "Owner" as your created user. Select "Steps", make "type" = T-SQL. Fill out command field similar to below. Set delimiter as ','
(11) Fill out schedules accordingly.
切斯特说:
我转到用户的数据库列表(服务器/安全/连接/我的用户名/属性/用户映射,并想要选中该框我收到一条错误消息,表明该用户已存在于 master 数据库中,删除该用户,返回“用户映射”并选中下面的“公共”框。
之后,您需要在 xp_cmdshell 上重新向“我的用户名”发出 grantexecute
tchester said:
I went to my user's database list (server/security/connections/my user name/properties/user mapping, and wanted to check the box for master database. I got an error message telling that the user already exists in the master database. Went to master database, dropped the user, went back to "user mapping" and checked the box for master. Check the "public" box below.
After that, you need to re-issue the grant execute on xp_cmdshell to "my user name"
现在是时候做出贡献了。我是系统管理员角色,致力于让两个公共访问用户执行 xp_cmdshell。我可以执行 xp_cmdshell,但不能执行两个用户。
我执行了以下步骤:
创建新角色:
使用大师
创建角色 [CmdShell_Executor] 授权 [dbo]
GRANT EXEC ON xp_cmdshell TO [CmdShell_Executor]
在 master 数据库中添加用户:安全 -->用户。成员资格仅检查刚刚创建的[CmdShell_Executor]
设置代理帐户:
EXEC sp_xp_cmdshell_proxy_account 'domain\user1','user1 Windows 密码'
EXEC sp_xp_cmdshell_proxy_account 'domain\user2','users2 Windows 密码'
然后两个用户都可以执行包含调用 R 脚本运行的 xp_cmdshell 的存储过程。我让用户来到我的电脑上输入密码,执行一行代码,然后删除密码。
Time to contribute now. I am sysadmin role and worked on getting two public access users to execute xp_cmdshell. I am able to execute xp_cmdshell but not the two users.
I did the following steps:
create new role:
use master
CREATE ROLE [CmdShell_Executor] AUTHORIZATION [dbo]
GRANT EXEC ON xp_cmdshell TO [CmdShell_Executor]
add users in master database: Security --> Users. Membership checks only [CmdShell_Executor] that is just created
set up proxy account:
EXEC sp_xp_cmdshell_proxy_account 'domain\user1','users1 Windows password'
EXEC sp_xp_cmdshell_proxy_account 'domain\user2','users2 Windows password'
Then both users can execute the stored procedure that contains xp_cmdshell invoking a R script run. I let the users come to my PC to type in the password, execute the one line code, then delete the password.
不要将控制权授予用户,这是完全没有必要的。
对数据库的选择权限就足够了。
在 master 上创建登录名和用户后(参见上面的答案):
Don't grant control to the user, it's totally unnecessay.
Select permission on the database is enough.
After you have created the login and the user on master (see above answers):