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.
Practice questions
Under which security context does a command run by a sysadmin through xp_cmdshell execute on the host?
- The SQL Server service account
- The sa login itself
- The proxy account, always
- 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.
Which measures harden a SQL Server against escalation to the host through xp_cmdshell?
- Keep xp_cmdshell disabled unless truly required
- Run the SQL Server service as a local administrator
- Run the service under a least-privileged account
- Make application logins members of sysadmin
- 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: 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.
