Link to home
Start Free TrialLog in
Avatar of LJordanMS
LJordanMS

asked on

XP_CMDSHELL - Secuirty Concerns???

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.


Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of LJordanMS
LJordanMS

ASKER

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 ?
ASKER CERTIFIED SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Or, write stored procedures to do the movement using sp_OA commands on the Scripting.FileSystemObject. Little more involved, but no xp_cmdshell needed.
SP_OA  ...

similar problem however in that there availablity is restricted to SA..  
Good point. Still, I'd rather expose those than xp_cmdshell. Any day.
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