Solved

Running xp_cmdshell as a non-admin

Posted on 2008-06-18
6
514 Views
Last Modified: 2012-06-27
Hi all,

I have the following stored procedure in SQL Server 2000:

CREATE PROCEDURE [dbo].[sp_CSV_COPROD] AS
BEGIN
DECLARE @bcpCommand VARCHAR(8000)

SET @bcpCommand = 'bcp partman.dbo.vw_export_coprod out \\SQLSVR1\c$\Co-Products.csv -S SQLSVR1 -T  -c -t,'
EXEC master..xp_cmdshell @bcpCommand
            
END
GO

I can run this fine and it outputs the required csv file (this is because I am an admin). However, when a non admin user runs this sp they get an error about permissions for xp_cmshell. I am using windows authentication.
Can someone please explain the best way to go about allowing non-admin users permissions to running this? I don't particularly want to give my Domain Users windows group execute permissions on the master db.

I am a COMPLETE NOVICE at this so hand holding may be required!

Thanks
0
Comment
Question by:FMabey
6 Comments
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21811457
Although xp_cmdshell is a useful tool for administrators, it's really unsecure to give access to it to the common users. Also, the command you are running uses an administrative share on the server, so the user would have to have administrator rights on the box inorder to be able to execute it anyway.....

This website explains why it's so bad and gives you some alternatives.

http://blogs.msdn.com/sqlsecurity/archive/2008/01/10/xp-cmdshell.aspx

0
 
LVL 2

Expert Comment

by:climbingjaffa
ID: 21811568
If you have to use xp_cmdshell you can setup a windows user account and from that a proxy sql login and user, that has the rights to execute xp_cmdshell ....

so when a user trys to run xp_cmdshell but they don't have the rights then SQL Server will use the proxy ....This avoids having to give a user sysadmin rights.....

Check out this out thread on EE its down the road you wantto travel
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_22118390.html

But as was said in the previous comment using xp_cmdshell its not the most favourable approach from a security context. but alot of enterprise systems do use it cause it offers flexibility

0
 
LVL 3

Author Comment

by:FMabey
ID: 21811622
Chrisedebo,

Isn't the link you sent me giving alternatives for SQL 2005?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 3

Author Comment

by:FMabey
ID: 21811684
As I am running this stored procedure through a VB.NET application, could I not connect them as a sysadm, then disconnect once the procedure has run. That way they wont have rights to use xp_cmdshell.
0
 
LVL 7

Accepted Solution

by:
orcic earned 400 total points
ID: 21811900
If this is not a time critical operation I have a tip:
Create a table in your database that would hold your task list (like task Queue). In that table you could put the informations about what kind of task should be run, what user created the task, what are the task parameters,  is the task finished or not, error description etc...
On the other side you can create and schedule a Job that would call a stored procedure (with sa credentials) that would go through all unfinished tasks, test if user has permission to run the task and call xp_cmdShell with task parameters. I'd suggest putting as few info as possible into the parameters because of security - for example in your case if all is fixed you do not need parameters at all or you can put only the name of output file as a parameter. After successfull/unsuccessfull run update your task table with success or error data.
Client would only need to insert a row into the task table and wait for job to finish to see the results.
0
 
LVL 7

Assisted Solution

by:Chrisedebo
Chrisedebo earned 100 total points
ID: 21812013
Apologies, yes it is....

However, you are correct, you could hardcode the sysadmin user details in the vb.net app. But that would mean you'd need to re-compile if you changed the sysadmin password. Also, if someone is able to dissasemble your .net app they might be able to get the password out of it.

I think orcic has the best idea.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question