?
Solved

XP_CMDSHELL - Secuirty Concerns???

Posted on 2006-07-17
10
Medium Priority
?
517 Views
Last Modified: 2009-12-16
I have a question regarding xp_cmdshell
For some reason our production database and the data managment work database is on the same server (bad maagement)

I have been given the task of improving current data management processes
I want to use the xp_cmdshell command to use simple commands for managing files (ie: rename, move, copy delete, dir, etc)

Because of security issues we do not have access to this sp xp_cmdshell on the master database.

As a work around is it possible to put the xp_cmdshell in  sp with the command that I want to use (ie: rename, move, copy delete, dir, etc) and give certain permissons on the sp to run that xp_cmdshell comand.

So the final result would be that if xp_cmdshell was run separtely we would still get permission not granted to run that sp, but the new sp ie: sp_CopyFile would have permission with the xp_cmdshell command in it that we want to run.


0
Comment
Question by:LJordanMS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 17123601
No ...
but you could have a job set up to say do your file copying ...

which you where allowed to trigger...  
say by posting the filenames to a table...

alternatively  give the list of files... explain the situation to the DBA/SA and
let them set up the required jobs/processes...

the XP_cmdshell procedure is protected since its so powerfull ...
but that doesn't mean it can't be used in your batch processes
with proper safeguards...


hth
0
 

Author Comment

by:LJordanMS
ID: 17123765
So it would be possible to a create table with the values of say the old file name, new file name, file destination where the DBA could set up a schedule task say run hourly that would look for new records in that table and perform the desired task that I want? rename file or move file ?
0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 1000 total points
ID: 17124103
Yes...

keep it simple...
limit the possible exposure...
ie just files in a directory... to another directory..


then it shouldn't be a security issue..
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

Expert Comment

by:Lowfatspread
ID: 17124128
it may help to think of it in terms of ...

getting them to do operation X...

rather than physically specifying that they need to move files ... a , b, and c to ..

although x is moving files..

hth
0
 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 17124385
Or, write stored procedures to do the movement using sp_OA commands on the Scripting.FileSystemObject. Little more involved, but no xp_cmdshell needed.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 17124781
SP_OA  ...

similar problem however in that there availablity is restricted to SA..  
0
 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 17125446
Good point. Still, I'd rather expose those than xp_cmdshell. Any day.
0
 
LVL 27

Expert Comment

by:ptjcb
ID: 17125871
I want to use the xp_cmdshell command to use simple commands for managing files (ie: rename, move, copy delete, dir, etc)

You have to evaluate the profit/cost of enabling xp_cmdshell. If your site is available through the web in any way then do not enable it (it is an open door to hackers to get on your network). You can use it to manage files, but there are better, secure ways (sp_OA, for example (SQL-DMO), vbscripts, etc). I have worked in places where xp_cmdshell was locked down and never used (usually enterprise-level companies) and small companies where they used it to run tasks. If you use it to schedule jobs then the Windows Task Scheduler is a better choice - it has better handling and allows you to kill a job if it has been running past a certain interval.

As a work around is it possible to put the xp_cmdshell in  sp with the command that I want to use (ie: rename, move, copy delete, dir, etc) and give certain permissons on the sp to run that xp_cmdshell comand.

This was changed with 2000, sp 3. Until then xp_cmdshell could only be used by sysadmins. It is possible to grant the rights to use xp_cmdshell to others. When you grant the rights to a login that is not sysadmin you have to set the account that is used to run the xp and any programs it invokes. SP3 changes SQL by making the non-sysadmin accounts based on the value of the SQL Server Agent Properties: Job System:  "Only users with SysAdmin privileges can execute CmdExec and ActiveScripting job" checkbox.

This link has good information about using xp_cmdshell: http://www.databasejournal.com/features/mssql/article.php/1580041
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

752 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