File System and OS Command Execution
What you'll learn: How attackers can abuse SQL injection vulnerabilities to read/write files on the server and execute operating system commands.
Beyond Data Theft
You've learned how SQL injection lets attackers steal or manipulate database contents. But some database systems offer built-in functions that interact with the underlying operating system—and if you can inject SQL, you might control those too.
Database Functions That Cross Boundaries
Modern databases like MySQL, PostgreSQL, and MSSQL include powerful functions for administrative tasks:
- File operations:
LOAD_FILE()in MySQL reads files from disk;INTO OUTFILEwrites query results to files - Command execution:
xp_cmdshellin MSSQL runs Windows shell commands;COPY PROGRAMin PostgreSQL can invoke system utilities
Think of it like this: If SQL injection is picking the lock to enter a building (the database), these functions are finding that the building has doors leading directly outside to the operating system—and those doors might be unlocked.
The Exploitation Path
An attacker who has already achieved SQL injection can attempt queries like:
- Reading sensitive server files (configuration files, application source code, SSH keys)
- Writing web shells or malicious scripts to web-accessible directories
- Executing system commands to enumerate users, escalate privileges, or establish persistence
Prerequisites and Limitations
Not all SQLi leads to OS access. It requires:
- The vulnerable database account having sufficient privileges
- The dangerous functions being enabled (many are disabled by default)
- File system permissions allowing read/write operations
- Knowledge of correct file paths on the target system
Key Takeaway:
SQL injection vulnerabilities can escalate from database compromise to full operating system access when attackers leverage database functions that interact with the file system or execute commands—turning a data breach into complete server takeover.