Join our Newsletter — 33% off our NHI Course
Home› Guides› Dangerous Database Features Guide: Disabling OS Command, File…
Guide Data Security

Dangerous Database Features Guide: Disabling OS Command, File Access and External Code Paths

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 14 min read
On this page

A handful of built-in database features turn a SQL login into operating system command execution, file system access or outbound network calls, so one stolen application credential or one injectable query can become a server compromise. Every major engine ships such features for legitimate jobs: bulk loading, exporting, integration and maintenance. This guide inventories them for MySQL, Oracle Database, PostgreSQL and Microsoft SQL Server, explains what each one exposes, and shows how to keep each off or tightly restricted, which roles to watch and what to audit. It is written for DBAs, application security engineers and owners of self-managed and cloud databases. Engines are listed alphabetically; order is not a ranking, and each engine documents the controls described here.

Key takeaways

  • Treat these features as privileged code paths. xp_cmdshell, COPY ... PROGRAM, UTL_FILE, LOAD DATA LOCAL and their relatives run with the database server's own operating system identity, not the SQL user's.
  • Most are off or restricted by default. xp_cmdshell, Ole Automation Procedures and MySQL local_infile are disabled on new installs, and PostgreSQL limits server file and program access to superusers and three predefined roles. The risk usually comes from later changes.
  • Privileges matter more than switches. MySQL FILE, PostgreSQL pg_execute_server_program, Oracle CREATE ANY DIRECTORY and SQL Server CONTROL SERVER each unlock these paths; keep them out of application accounts.
  • Constrain where a feature must stay on. Use secure_file_priv, narrow Oracle directory objects and network ACLs, a low-privilege xp_cmdshell proxy account and signed CLR assemblies.
  • Audit the enabling event. Configuration changes and grants of these privileges are rare and high signal; alert on them rather than trying to catch every use.

Why these features matter

Database hardening often stops at network exposure, authentication and encryption. These features sit behind all three: an attacker who reaches SQL through SQL injection (MITRE ATT&CK T1190 Exploit Public-Facing Application) or a leaked connection string (T1078 Valid Accounts) can use them to run commands (T1059 Command and Scripting Interpreter), read configuration and key files, write web shells, or plant persistence in stored code (T1505.001 SQL Stored Procedures). Because the work is done by the database service account, host controls often see a trusted process doing something unusual rather than a new attacker tool.

The practical consequences are consistent across engines:

  • Blast radius: the database service account's file and network permissions become the attacker's. PostgreSQL's documentation says its file and program roles "could be used to gain superuser-level access".
  • Credential exposure: file read paths reach other databases' files, configuration and secrets on the host. MySQL documents that a FILE holder "can read any file on the server host that is either world-readable or readable by the MySQL server".
  • Lateral movement: outbound network packages and linked servers reach other systems. See the Database Links and Linked Servers guide.

For the wider control set (network, authentication, encryption, patching) start with the Database Security Guide; this page goes deep on the feature layer only.

Feature inventory by engine

EngineFeatureWhat it exposesControl setting or privilege
MySQLLOAD DATA, SELECT ... INTO OUTFILE, LOAD_FILE()Read and write files on the server hostFILE privilege; secure_file_priv set to a dedicated directory
MySQLLOAD DATA LOCALServer can request files from the client hostlocal_infile (disabled by default in 8.4); client --local-infile=0
Oracle DatabaseUTL_FILE and directory objectsRead and write files in directories mapped by directory objectsCREATE DIRECTORY, CREATE ANY DIRECTORY, READ and WRITE on each directory object
Oracle DatabaseUTL_TCP, UTL_HTTP, UTL_SMTP, UTL_INADDROutbound network connections from PL/SQLNetwork ACLs via DBMS_NETWORK_ACL_ADMIN
Oracle DatabaseExternal jobs, external procedures (extproc), Java in the databaseOS programs, native libraries and Java file accessCREATE EXTERNAL JOB; ENFORCE_CREDENTIAL in extproc.ora; dbms_java.grant_permission scoped to paths
PostgreSQLCOPY ... TO/FROM fileRead and write server filesSuperuser, pg_read_server_files, pg_write_server_files
PostgreSQLCOPY ... PROGRAMRun a shell command as the server's OS userSuperuser, pg_execute_server_program
PostgreSQLUntrusted procedural languages (for example plpython3u)Arbitrary code in the server processOnly superusers can create functions in untrusted languages; do not install unless needed
SQL Serverxp_cmdshellWindows command shellsp_configure 'xp_cmdshell' (disabled by default); CONTROL SERVER; ##xp_cmdshell_proxy_account##
SQL ServerOle Automation Procedures (sp_OACreate)COM objects from T-SQLsp_configure 'Ole Automation Procedures' (0 by default)
SQL ServerCLR integration.NET code in the engineclr strict security = 1 (default from SQL Server 2017); signed assemblies; avoid TRUSTWORTHY

Managed cloud services often remove or reshape these features (for example by not granting superuser), so check the provider's documentation for your service before assuming an on-premises setting applies. See the Amazon RDS and Aurora Security Guide, the Azure SQL and Cosmos DB Security Guide and Google Cloud SQL Security.

OS command execution paths

MySQL

In MySQL, command-level risk comes from file writes that land somewhere executable and from loadable functions, so the controls are the FILE privilege and secure_file_priv (below), plus restricting who can install plugins and functions to DBA accounts. See the MySQL Security Guide.

Oracle Database

External jobs run operating system programs through DBMS_SCHEDULER and need CREATE EXTERNAL JOB, which Oracle audits by default. Oracle's guidance is to restrict CREATE ANY JOB and related powerful privileges and grant them only to users who need them. For external procedures, set ENFORCE_CREDENTIAL=TRUE in extproc.ora (Oracle documents FALSE as the default and TRUE as the setting for maximum security). For Java, grant dbms_java file permissions on explicit paths, never <<ALL FILES>>. See the Oracle Database Security Guide.

PostgreSQL

COPY ... PROGRAM runs a command through the shell on the server, which must be "executable by the PostgreSQL user". It is limited to superusers and members of pg_execute_server_program. Keep application roles non-superuser, grant pg_execute_server_program to no one by default, and remember the documentation's warning that the command is invoked by the shell, so any untrusted argument is a shell injection risk. OS mandatory access control such as SELinux can further restrict what the server may execute. See the PostgreSQL Security Guide.

SQL Server

xp_cmdshell is disabled on new installations, and Microsoft states it "should be left disabled" in new code and enabled only for the duration of a task that needs it. When enabled, sysadmin callers run commands as the SQL Server service account; non-sysadmin callers granted EXECUTE run as the Windows account in the ##xp_cmdshell_proxy_account## credential, and the call fails if that credential does not exist. If a legacy job truly needs it, create the proxy with a dedicated low-privilege Windows account via sp_xp_cmdshell_proxy_account and grant EXECUTE only to that job's login. Keep Ole Automation Procedures at 0, its default. See the Microsoft SQL Server Security Guide.

File system access

EngineRead and write pathRestriction to applyCheck
MySQLLOAD DATA, SELECT ... INTO OUTFILE, LOAD_FILE(); LOAD DATA LOCAL from clientsGrant FILE to no application account; set secure_file_priv to a dedicated directory; keep local_infile=OFF on servers and --local-infile=0 on clientsSHOW VARIABLES for secure_file_priv and local_infile; query grants for FILE
Oracle DatabaseUTL_FILE through directory objects; external tables; BFILERestrict CREATE DIRECTORY and CREATE ANY DIRECTORY; one directory object per purpose; no grants to PUBLIC; protect every path component at OS levelReview ALL_DIRECTORIES and directory grants in DBA_TAB_PRIVS
PostgreSQLCOPY to and from server filesNo superuser for applications; grant pg_read_server_files or pg_write_server_files only to named admin roles; use client-side \copy for user exportsQuery role memberships for the three predefined roles and rolsuper
SQL Serverxp_cmdshell, Ole Automation, CLR with external accessKeep these off; clr strict security = 1; sign assemblies or use sys.sp_add_trusted_assemblysys.configurations values; sys.assemblies; databases with is_trustworthy_on = 1
  • MySQL detail: FILE also lets a user create new files "in any directory where the MySQL server has write access", including the data directory. secure_file_priv is the documented way "to limit the location in which files can be read and written". LOAD DATA LOCAL is a client-side risk too: MySQL warns that a malicious or patched server could request any file the client user can read, so clients "should not connect to untrusted servers" and should verify the server with --ssl-mode=VERIFY_IDENTITY.
  • Oracle detail: directory object privileges grant read and write to all files in that directory but not its subdirectories, and Oracle's own example of granting a directory to PUBLIC shows exactly the pattern to avoid in production. Files created through UTL_FILE are owned by the instance's OS user, normally oracle. Oracle also advises that no part of a path given to the database be modifiable by an untrusted user.
  • PostgreSQL detail: the documentation distinguishes server-side COPY from psql's \copy, which reads and writes files on the client with the client's rights. Pointing analysts at \copy removes most reasons to grant server file roles.
  • SQL Server detail: Microsoft explains that code access security is no longer a security boundary, so a SAFE assembly "might be able to access external system resources" unless clr strict security stays at 1. TRUSTWORTHY ON is documented as not recommended.

External code and network calls

  • MySQL: limit plugin and loadable function installation to DBA accounts and review installed plugins after upgrades. Outbound connectivity is better controlled at the host or network layer with egress rules for the database subnet.
  • Oracle Database: network ACLs administered with DBMS_NETWORK_ACL_ADMIN control access from UTL_TCP, UTL_HTTP, UTL_SMTP and UTL_INADDR. Use APPEND_HOST_ACE to grant connect or resolve for a specific host and port range to a specific principal, and review DBA_HOST_ACES regularly. Review which accounts hold EXECUTE on the UTL network and file packages, and grant them to named roles that need them.
  • PostgreSQL: extensions such as dblink and postgres_fdw open connections to other servers; install them only in databases that need them and control who may create user mappings. Untrusted languages run code with the server's rights.
  • SQL Server: keep CLR assemblies signed and inventoried, and review linked servers and their login mappings, which are covered in the Database Links and Linked Servers guide.

At every engine, egress filtering from database hosts is the backstop: a database server rarely needs general internet access, and blocking it limits what any of these features can reach.

Restricting and monitoring

Rollout

  1. Inventory. For each instance record the settings and privileges in the tables above: sys.configurations, SHOW VARIABLES, pg_roles memberships, DBA_SYS_PRIVS and DBA_TAB_PRIVS. Include cloud instances and developer copies.
  2. Find real users. Search job definitions, stored code and application repositories for xp_cmdshell, COPY ... PROGRAM, UTL_FILE, INTO OUTFILE and LOAD DATA LOCAL. Talk to owners before changing anything.
  3. Replace where possible. Move OS work to an external scheduler or ETL tool running under its own managed identity; move exports to client-side tools such as \copy or mysqldump.
  4. Restrict in a test ring. Disable the feature or revoke the privilege on non-production first, run the application test suite and batch jobs for a full business cycle, then roll to production in waves.
  5. Keep a rollback. Script the exact previous setting or grant for each change so an outage can be reversed in minutes, then re-plan the removal.
  6. Enforce. Add the settings to configuration management, Policy-Based Management or infrastructure code, and alert on drift.

Where identity fits

The accounts that matter here are non-human: application logins, ETL service accounts and the database service account itself. Give each application its own login without FILE, superuser, CONTROL SERVER or ANY privileges; run the database service under a dedicated low-privilege OS account; and keep any xp_cmdshell proxy credential in a vault with rotation. See the Database Credential and Access Security Guide.

What to audit

  • Configuration changes: sp_configure changes to xp_cmdshell, Ole Automation Procedures, clr enabled and clr strict security; changes to local_infile; edits to extproc.ora and postgresql.conf.
  • Grants: FILE, pg_execute_server_program, pg_read_server_files, pg_write_server_files, CREATE EXTERNAL JOB, CREATE ANY DIRECTORY, EXECUTE on xp_cmdshell and network ACE changes.
  • Use: statements containing COPY ... PROGRAM, INTO OUTFILE, LOAD_FILE, UTL_FILE.FOPEN or xp_cmdshell, captured by the engine's audit facility.
  • Host signals: the database service process spawning shells or writing files outside data and log directories, from EDR telemetry.

Detection content for these events is covered in the Database Audit Log Detection Guide.

Metrics

  • Percentage of instances with every listed feature at its hardened setting.
  • Number of accounts holding FILE, superuser, server file roles, CONTROL SERVER or CREATE EXTERNAL JOB, trended down.
  • Count of approved exceptions, each with an owner and review date.
  • Mean time from an unapproved configuration change to alert.
  • Number of directory objects and network ACEs granted to PUBLIC (target zero).

Framework mapping

Control areaNIST SP 800-53 Rev. 5NIST CSF 2.0MITRE ATT&CK
Disable unneeded featuresCM-7 Least FunctionalityPR.PS Platform SecurityT1059 Command and Scripting Interpreter
Restrict privileged rolesAC-6 Least PrivilegePR.AA Identity Management, Authentication, and Access ControlT1078 Valid Accounts
Stored code and extensionsCM-7, AC-6PR.PST1505.001 SQL Stored Procedures
Audit enabling eventsAU-2 Event Logging, AU-12 Audit Record GenerationDE.CM Continuous MonitoringT1190 Exploit Public-Facing Application
Protect audit recordsAU-9 Protection of Audit InformationDE.CMNot applicable

Common failure patterns

  • Enabled once, never disabled. xp_cmdshell switched on for a migration and left on for years. Microsoft's guidance is to enable it only for the task.
  • Application accounts with admin rights. An app login with sysadmin, superuser or FILE makes every injection flaw a host compromise.
  • secure_file_priv left empty. An empty value places no limit on file locations; set a dedicated directory instead.
  • Directory objects granted to PUBLIC. Copying documentation examples into production gives every user read and write access to a host directory.
  • TRUSTWORTHY ON for convenience. Used to get an unsigned CLR assembly loading, it widens what database owners can do; sign the assembly instead.
  • Clients loading from untrusted servers. LOAD DATA LOCAL enabled on clients that connect without verifying server identity.

Practitioner checklist

  • Inventory every setting and privilege in the feature table across all instances, including cloud and non-production.
  • Keep xp_cmdshell and Ole Automation Procedures at 0 and clr strict security at 1 on SQL Server.
  • Set secure_file_priv to a dedicated directory and keep local_infile disabled on MySQL servers and clients.
  • Grant pg_execute_server_program and server file roles to no application role in PostgreSQL; use \copy for exports.
  • Restrict CREATE DIRECTORY, CREATE ANY DIRECTORY and CREATE EXTERNAL JOB in Oracle and scope network ACEs to named hosts and principals.
  • Remove FILE, superuser, CONTROL SERVER and ANY privileges from application and ETL accounts.
  • Audit configuration changes and grants of these privileges and alert on them.
  • Block general internet egress from database hosts.
  • Record each exception with an owner, compensating control and review date.

Standards and references

Related NHI Mgmt Group resources: Database Security Guide · Database Credential and Access Security Guide · Database Audit Log Detection Guide · Database Links and Linked Servers

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.