Bitzu

CPSA ยท Database security

From SQL Server access to host compromise

Extended stored procedures such as xp_cmdshell, service account impact and hardening.

Key points

  • xp_cmdshell: spawns a Windows command shell, returns output as rows.
  • Disabled by default, enabled via sp_configure; needs CONTROL SERVER (sysadmin).
  • The process runs with the SQL Server service account's rights, so sysadmin can mean OS access, and an admin service account means host compromise.
  • Hardening: keep xp_cmdshell off, low-privileged service account, non-admins only through a least-privileged proxy account.

Source: https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-cmdshell-transact-sql

Practice questions

Single choice

Under which security context does a command run by a sysadmin through xp_cmdshell execute on the host?

  1. The SQL Server service account
  2. The sa login itself
  3. The proxy account, always
  4. An anonymous Windows guest
Show answer

Answer: A. The SQL Server service account

The spawned process has the rights of the SQL Server service account. The caller's SQL login has no Windows identity, and the proxy account applies only to non-sysadmin callers.

Select all that apply

Which measures harden a SQL Server against escalation to the host through xp_cmdshell?

  1. Keep xp_cmdshell disabled unless truly required
  2. Run the SQL Server service as a local administrator
  3. Run the service under a least-privileged account
  4. Make application logins members of sysadmin
  5. Share the sa password among all administrators
Show answer

Answer: A. Keep xp_cmdshell disabled unless truly required, C. Run the service under a least-privileged account

Leaving xp_cmdshell disabled and running the service as a least-privileged account limit the damage. Making the service a local administrator or granting sysadmin to applications widens it.

True or false

True or false: when a non-sysadmin user is allowed to run xp_cmdshell, the command runs with the SQL Server service account's rights.

Show answer

Answer: False

False. Non-sysadmin callers run through the ##xp_cmdshell_proxy_account## credential, so the process gets the proxy account's rights. Sysadmin members still get the service account's rights.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More CPSA topics in this module