Various commands in SQLMap would allow us to execute system commands upon the underlying operating system.
From the SQLMap Advanced help menu (sqlmap -hh), we have found several switches under the Operating System Access section, which can especially be used in order to take over the operating system.
In this chapter, we will be going to discuss the first three switches to take over the operating system, which are listed below:
- --os-cmd=OSCMD Execute an operating system command
- --os-shell Prompt for an interactive operating system shell
- --os-pwn Prompt for an OOB shell, Meterpreter or VNC
OS-cmd
The --os-cmd switch can be used to execute commands on the target operating system by using the load File functionality.
Let us try executing the “whoami” command, and try to get the result in our previously used URL which consists of a GET parameter.
Use the below command, and supply a Windows command after the --os-cmd switch:
The “whoami” command displays the user, group, and privileges information for the user who is currently logged on to the local system.
On execution, it will prompt basic queries related to your Target system:
Once these are done, SQLMap tries to upload its stager and returns back with a value of the given command.
As you can notice, I have highlighted the standard output. After each operation, the uploaded web file automatically removed.
In this similar way, you can use any shell command to get
Windows output.
OS-Shell
If os-cmd switch looks complicated, then, do not worry. SQLMap
provides --os-shell switch, which can be used to interact with
Windows shell directly.
Fire up the terminal and type the following command:
Similar to the previous switch, it will also prompt some basic platform-related queries. Now, we need to input some basic platform-related queries.
Now we have to provide a comma separate list of absolute directory paths:
Once these are done, SQLMap tries to upload its stager and returns with an interactive shell to the web server.
This feature of SQLMap is quite magnificent and easily allows us to get a shell.
Now, we are ready, let’s input the windows shell command.
This highlighted text of the output of the “whoami” and “dir” commands executed via os-shell. After each operation, the uploaded web file automatically removed.
Type "q" to quit the session:
Let's proceed for next switch.
OS-PWN
The --os-pwn switch of SQLMap allows the attacker to spawn an
interactive command prompt, a Meterpreter session, or a Graphical user interface
(VNC) session.
Its usage is quite simple, use the following command to proceed for spawn a session:
Rembember: The OS-PWN switch may not work properly with normal users, so
run it with the sudo command.
Similar to the previous switch, it will also prompt some basic platform-related queries. Now, we need to input some basic platform-related queries.
Once these are done, SQLMap tries to upload its stager and returns with an interactive shell to the web server. In the end it will prompt us to choose the connection type:
Let’s start with Meterpreter
Type number 1, to create a meterpreter session. On execution SQLMap try to upload a shellcode exec file to \Temp directory.
It will automatically create a shell code and upload it to the temp directory. Once the upload was successful, it will automatically launch the msfconsole.
Now as you can notice, we have got a meterpreter session.
Let’s inject a VNC session
Type number 3, to create a meterpreter session. On execution, SQLMap tries to upload a shellcode exec file to \Temp directory and launch msfconsole.
In the end msfconsole automatically creates a VNC session.
As we can see, we have successfully managed to VNC session via SQL map.