对象 xp_cmdshell 的权限被拒绝

发布于 2024-12-21 17:47:56 字数 287 浏览 3 评论 0原文

我收到对象“xp_cmdshell”的执行权限被拒绝。

情况是这样的,我有一个名为 ExportFile 的存储过程。 我正在通过虚拟 PC 的 Web 应用程序通过 SqlCommand 调用存储过程。 在执行此命令期间,我收到权限错误

然后我通过 SQL 探查器对其进行调试,并将探查器的结果执行到查询窗口(这意味着我使用基于探查器到查询窗口的必要参数运行 StoredProcedure),令人惊讶的是它工作得很好。文件已成功导出。

考虑到我在连接字符串中的登录是所有者和管理员用户,我想知道这有什么问题。

I am getting Execute permission was denied on the object 'xp_cmdshell'.

Here's the situation, I have a stored procedure called ExportFile.
I am calling the stored procedure via SqlCommand from a web application from a Virtual PC..
during the execution of this command i get permission error

Then I debug it via SQL profiler and execute the result from the profiler to a query window (this means i run the StoredProcedure with the necessary parameters basing from the profiler to a Query window) and surprisingly its working just fine. the file was exported successfully.

I wonder whats wrong with this considering that my login in the connection string is an owner and admin user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空宴 2024-12-28 17:47:56

用于 Web 服务器的 SQL 用户帐户没有使用该扩展过程的权限。您必须提升该用户的权限(坏主意)或在 SQL 安全性中分配一个代理帐户,该帐户可以在服务器中执行该过程,而无需将 Web 帐户设置为系统管理员。

The SQL user account being used with the web server doesn't have permissions to use that extended procedure. You would have to elevate the rights of that user (bad idea) or assign a proxy account within SQL security that can execute the procedure within the server without making the web account a Sysadmin.

檐上三寸雪 2024-12-28 17:47:56

我们必须授予该用户执行权限

语法:

GRANT EXECUTE ON xp_cmdshell TO [Domain\User]

注意:确保您必须使用授予执行权限的登录名。我发现很多时候用户确实使用 diff id 并抱怨。

We have to give this user execute permission

Syntax:

GRANT EXECUTE ON xp_cmdshell TO [Domain\User]

Note : Make sure you must be using login on which you give execute permission. I found many times user do use diff id and complain.

心作怪 2024-12-28 17:47:56

假设您收到类似这样的消息

The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.

,那么您首先需要一个 SQL Server 用于访问主机操作系统的代理用户。

  1. 设置代理用户
execute sp_xp_cmdshell_proxy_account 'DOMAIN\USER', 'PASSWORD'

在 SQL Server Management Studio 中,这应如下所示:

SSMS 中的代理用户

  1. 确保 SQL 用户(不是代理用户)映射到主数据库
use [master]
go

execute sp_addrolemember 'public', SQLUSERNAME;
execute sp_addrolemember 'db_datareader', SQLUSERNAME;
execute sp_addrolemember 'db_datawriter', SQLUSERNAME;

在 SQL Server Management Studio 中,这应该看起来像这样:

用户权限是 SSMS

  1. 授予执行权限,以便SQL用户可以使用代理访问操作系统功能
use [master]
go

grant execute on xp_cmdshell to SQLUSERNAME

Assuming you get a message like

The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.

Then you first need a proxy user which SQL Server uses to access the host operating system.

  1. Setup the proxy user
execute sp_xp_cmdshell_proxy_account 'DOMAIN\USER', 'PASSWORD'

In SQL Server Management Studio this should look like the following:

Proxy user in SSMS

  1. Ensure that the SQL user (not the proxy user) is mapped to the master database
use [master]
go

execute sp_addrolemember 'public', SQLUSERNAME;
execute sp_addrolemember 'db_datareader', SQLUSERNAME;
execute sp_addrolemember 'db_datawriter', SQLUSERNAME;

In SQL Server Management Studio, this should look like this:

User permissions is SSMS

  1. Grant the execute permission, such that the SQL user can use the proxy to access OS functionality
use [master]
go

grant execute on xp_cmdshell to SQLUSERNAME
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文