How to prevent ANY use of xp_CmdShell?

  • Not to interject a dumb quesiton into this but what does this mean?

    nameminimummaximumconfig_valuerun_value

    xp_cmdshell0100

  • It means xp_cmdshell is disabled within this instance, the default.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Does this not prevent use of xp_CmdShell by SAs, which was the original quesiton?

    This reminds me of a question a few years ago about how to keep SAs from being able to view the data in tables. The way to keep people from having access to 100 percent of functionality is to not put them in the sysadmin group or give them the sa password. At a certain point, you just have to trust certain people.

  • No, it does't. A member of the sysadmin Role can simply enable it.

    You're conflating multiple issues. There is a difference between trusting someone to do all operations within the scope of the database engine, e.g. see all data in all tables within all databases, and trusting someone to do all operations on the server on which SQL Server is hosted, e.g. have access to xp_cmdshell to reach a cmd-shell command line on the host server.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • opc.three (10/23/2013)


    No, it does't. A member of the sysadmin Role can simply enable it.

    You're conflating multiple issues. There is a difference between trusting someone to do all operations within the scope of the database engine, e.g. see all data in all tables within all databases, and trusting someone to do all operations on the server on which SQL Server is hosted, e.g. have access to xp_cmdshell to reach a cmd-shell command line on the host server.

    The privileges obtainable using XP_CMDSHELL are limited to those of the SQL Server Service account. If these are not sufficient to do all operations on the machine, xp_cmdshell doesn't allow a SQL Server admin to do all operations on it. Of course if you choose to run the SQL Service under an enterprise adminiistrator, or domain administrator, or even a local administrator you are giving SQL Admins a lot of privileges, but why would you want to run it that way? Is it too much effort to set up an account specifically to run the SQL Service under and not give it excessive privileges? I found it easy to do that with SQL 2008 and SQL 2008 R2, and SQL 2012 appears to do it for me unless I override it, making it even easier. It was of course a nightmare in SQL 2000, and I never used 2005 so I don't know what it was like there.

    The other thing to remember is that if you run SQL Server Agent under a privileged account then everyone with access to sp_add_jobstep can use those privileges (unless you set up an agent proxy, but of course that won't stop SA); that's another account that ideally shouldn't be a member of any administrator group.

    Tom

  • L' Eomot Inversé (10/24/2013)


    opc.three (10/23/2013)


    No, it does't. A member of the sysadmin Role can simply enable it.

    You're conflating multiple issues. There is a difference between trusting someone to do all operations within the scope of the database engine, e.g. see all data in all tables within all databases, and trusting someone to do all operations on the server on which SQL Server is hosted, e.g. have access to xp_cmdshell to reach a cmd-shell command line on the host server.

    The privileges obtainable using XP_CMDSHELL are limited to those of the SQL Server Service account. If these are not sufficient to do all operations on the machine, xp_cmdshell doesn't allow a SQL Server admin to do all operations on it. Of course if you choose to run the SQL Service under an enterprise adminiistrator, or domain administrator, or even a local administrator you are giving SQL Admins a lot of privileges, but why would you want to run it that way? Is it too much effort to set up an account specifically to run the SQL Service under and not give it excessive privileges? I found it easy to do that with SQL 2008 and SQL 2008 R2, and SQL 2012 appears to do it for me unless I override it, making it even easier. It was of course a nightmare in SQL 2000, and I never used 2005 so I don't know what it was like there.

    I am aware of which security contexts the cmd.exe process can run under when created using xp_cmdshell. you mentioned the proxy account. Note we only have one proxy account per instance and naturally one service account per instance. That is not nearly granular enough to allow for processes that use xp_cmdshell numering more than two to be tightly controlled because inevitably they'll have more permissions than are necessary for them to do their work.

    When you consider the most common use cases for employing the extended stored procedure it is an easy leap to elevating the service account's permissions to allow for copying backups to a network share, writing a file by calling bcp with the out option to somewhere, etc.

    The other thing to remember is that if you run SQL Server Agent under a privileged account then everyone with access to sp_add_jobstep can use those privileges (unless you set up an agent proxy, but of course that won't stop SA); that's another account that ideally shouldn't be a member of any administrator group.

    Agreed. SQL Agent is another attack vector that demands attention.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 6 posts - 31 through 35 (of 35 total)

You must be logged in to reply to this topic. Login to reply