---
title: "2. HTTP Verb Tampering"
date: 2024-12-08
draft: false
---


HTTP protocol works by accepting various HTTP methods as `verbs`. 
- Dep. on config; webapps may be scripted to accept *certain* http methods for various functionalities + perform particular actions based on the type of request received. 

Programmers mainly consider the most two commonly used methods: `GET` and `POST` - however, clients can send any other methods in http requests and see how the webserver handles them. 
- Suppose both webapp + backend are configured to only accept GET/POST 
	- Sending diff reqs will cause webserv error page to be displayed 
		- Not severe in + of itself 
		- info disclosure
	- If webserv configs are not restricted: 
		- webapp is not developed to handle other typs of http reqs like HEAD/PUT 
		- thus we may potentially be able to exploit this insecure configuration to gain access to functionalities we do not have access to or bypass security controls 

---
HTTP has `9 different verbs` that can be accepted as HTTP methods by web servers. 
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

Aside from GET + POST: 

|Verb|Description|
|---|---|
|`HEAD`|Identical to a GET request, but its response only contains the `headers`, without the response body|
|`PUT`|Writes the request payload to the specified location|
|`DELETE`|Deletes the resource at the specified location|
|`OPTIONS`|Shows different options accepted by a web server, like accepted HTTP verbs|
|`PATCH`|Apply partial modifications to the resource at the specified location|

Some of the above perform some very sensitive functions. Writing (PUT) or deleting (DELETE) files to the webroot dir on the back-end server. 

If a webserver isn't configured to manage these, we can use them to gain control over the backend server. What makes http verb tampering attacks more common `(hence more critical)` is that they are caused by a miscconfiguration in either the backend webserv or webapp - either of which are capable of causing this behavior 

---
**Insecure configurations**

Insecure webserv configs cause the first type of HTTP verb tampering vulns: 
- webserver auth conf may be limited to specific http methods, leave some http methods accessible without auth. 
- Sys admin may use the following config to require auth on a particular webpage: 
```bash
<Limit GET POST> 
	Require valid user
</Limit> 
```

Even though the configuration specifies both GET+POST reqs for auth method an attacker may still use a different HTTP method (like `HEAD`) to bypass this authentication mechanism altogether. This eventually leads to an auth bypass and allows attackers to access web pages + domains they otherwise would not be able to. 

---
**Insecure coding**

Insecure coding practices also introduce this vuln even though some may not consider it verb tampering necessarily. 

Dev applies filters to mitigate vulns; not covering all http methods with that filter. 
- EX: Page has a SQLi vuln - Backend devs mitigate the SQLi vuln with the below code: 

```php
$pattern = "/^[A-Za-z\s]+$/";

if(preg_match($pattern, $_GET["code"])) {
    $query = "Select * from ports where port_code like '%" . $_REQUEST["code"] . "%'";
    ...SNIP...
}
```

Sanitization filter only includes the `GET` parameter. 
If GET requests do not contain any bad characters - query would be executed. 
- However, when executed `$_REQUEST["code"]` params are being used which may also use `POST` - **leading to an inconsistency in the use of http verbs**. 
- In this case - attackers may use a POST request to perform SQL injection 
- GET parameters would be empty (not include any bad chars) 
- Request passes security filter 

Both above vulns are found in public - the second one is much more common as it is due to mistakes made in coding 

First is usually avoided by secure webserver configurations as documentation often cautions against it. 

---
**Bypassing basic authentication**

Usually detecting and exploiting this is relatively straightforward. 

*Just need to try alternate HTTP methods and see how they are handled by webserver/webapp*

While many automated vulnerability scanning tools can consistently identify HTTP Verb Tampering vulns caused by **insecure server configurations** they usually miss identifying HTTP tampering vulns caused by **insecure coding**. 
- **Insecure server configurations** : Easily identified 
- **Insecure coding**: Needs active testing to see whether we can bypass the security filters in place. 

**Identifying insecure server configurations**
---

Suppose filesharing app. 
- Add new files 
- Type name + hit enter. 
Supppose we try to use delete functionality on the webpage 
- big red 'reset' button 
- restricted functionality
- prompts the user for `HTTP Basic Auth` 
- without creds - redirected to 401 Unauthorized 

Step 1) 
- Identify which page restricted (in our above example we land on /admin/reset.php)
	- Either /admin or /admin/reset.php
	- By visiting /admin we get a login prompt 
Step 2) 
- Identify http req method used by the webapp, intercept with Burp 
- If page uses `GET` we can try to use `POST` and determine whether the page allows `POST` requests (i.e. whether the authentication covers POST or not.)
	- To do this, rightclick intercepted request in Burp and select `Change Request Method` 
	- Click forward, sending it to browser. 
Step 3) 
- Success? 
- If `POST` is still filtered, try some of the other HTTP methods listed above. 
- Notably `HEAD` (identical to GET but does not return body in http response.)
	- If HEAD is successful we may not get output but the `reset` button in our exaxmple will be executed 
- To see whether server accepts `HEAD` - send an `OPTIONS` request and see what http methods are accepted. 

```zsh
stejwes@htb[/htb]$ curl -i -X OPTIONS http://SERVER_IP:PORT/

HTTP/1.1 200 OK
Date: 
Server: Apache/2.4.41 (Ubuntu)
Allow: POST,OPTIONS,HEAD,GET
Content-Length: 0
Content-Type: httpd/unix-directory
```

Seen above - `HEAD` is acceptable. (This is default behavior for many webservers) 
Repeat above with HEAD, we will see we no longer get a login prompt or 401 unauth page and get empty output. 
Navigating back to file manager app we see all files have been deleted. 

---
![](/img/Pasted image 20241207220213.png)
![](/img/Pasted image 20241207220229.png)
![](/img/Pasted image 20241207220242.png)

![](/img/Pasted image 20241207220311.png)
![](/img/Pasted image 20241207220405.png)
didnt work like the example but PUT worked, trust bro 
![](/img/Pasted image 20241207221206.png)

---
**Bypassing security filters**

The other more common http verb tampering vulnerability is caused by *Insecure coding*
- Commonly found in security filters that detect malicious requests 
	- ie; sec filter used to detect injection vulnerabilities + only checked for injections in `POST` parameters (`$_POST['parameter']`)
	- Potentially bypass-able by simply changing request method to `GET` 

Step 1) 
- Identify
- Same example as before 
- Try creating a new file name with special chars : `Malicious request denied!` 
	- Message demonstrates webapp uses certain filters on backend to identify injection attempts + blocks them. 
		- Assume there's no other bypass here. 
	- We may try an HTTP Verb Tampering attack to try and bypass the security filter altogether. 
Step 2) 
- Exploit
- Intercept, change req with Burp 
- To confirm we bypassed the sec filter may need to attempt exploiting the vulnerability the filter is protecting: In this case it's a `Command Injection` vulnerability. 
	- In this case - just inject a command that creates two files and check whether both files were created. 
	- Payload in our example: `file1; touch file2;`
		- Once again - change request method when we send our request. 
---
![](/img/Pasted image 20241207222337.png)
![](/img/Pasted image 20241207222419.png)

Changed the request method with burp in below image 
![](/img/Pasted image 20241207222504.png)
![](/img/Pasted image 20241207222512.png)

---

**Verb tampering prevention**

Remember: two things involved here 
- Insecure configurations
- Insecure coding

*The below covers insecure configurations. *

Vulns can occur in most modern webservers including Apache, Tomcat, and ASP.NET 
- Usually happens when we limit a page's authorization to a particular set of HTTP verbs/Methods leaving other remaining methods unprotected 

Example of a vulnerable config for Apache located in site configuration file `000-default.conf` or a `.htaccess` webpage conf file 

```xml
<Directory "/var/www/html/admin">
    AuthType Basic
    AuthName "Admin Panel"
    AuthUserFile /etc/apache2/.htpasswd
    <Limit GET>
        Require valid-user
    </Limit>
</Directory>
```

As we see above this configuration is setting the authorization configurations for the `admin` web dir. 
However `<Limit GET>` keyword being used the `Require valid-user` setting will only apply to `GET` requests leaving the page accessible through `POST` requests 
Even if both `GET` and `POST` were specified this would leave the page accessible through other methods like `HEAD` or `OPTIONS` 

```xml
<security-constraint>
    <web-resource-collection>
        <url-pattern>/admin/*</url-pattern>
        <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>
```

This example below shows same vulnerability for Tomcat. (found in `web.xml` ) 
We can see auth is being limited only to the `GET` method with `http-method` leaving other methods accessible 

```xml
<system.web>
    <authorization>
        <allow verbs="GET" roles="admin">
            <deny verbs="GET" users="*">
        </deny>
        </allow>
    </authorization>
</system.web>
```

This is an example of a `ASP.NET` config for `web.config` file of webapp 
`allow` and `deny` scope limited to the `GET` method which leaves the webapp accessible through other HTTP methods 

---
These examples above show it is not secure to limit the authorization configuration to a specific HTTP verb 
We should always avoid restricting authorization to a single method and always allow/deny ALL http verbs and methods 

If we want to specify a single method, we can use safe keywords like `LimitExcept` in apache ; `http-method-omission` in Tomcat and `add/remove` in ASP.NET which should cover all verbs except the specified ones 

To avoid similar attacks - generally conside disabling/denying all HEAD requests unless specifically required by the webapp

---
*The below covers insecure coding*

While identifying + patching insecure webconfs is relatively easy doing the same for insecure code is much more challenging, this is because to identify this vulnerability in the code, we need to find inconsistencies in the use of http parameters across functions, as in some instances, this may lead to unprotected functionalities and filters. 

Consider `PHP` code from our `file manager` exercise 

```php
if (isset($_REQUEST['filename'])) {
    if (!preg_match('/[^A-Za-z0-9. _-]/', $_POST['filename'])) {
        system("touch " . $_REQUEST['filename']);
    } else {
        echo "Malicious Request Denied!";
    }
}
```

If we were only considering command injection vulns we would say this is securely coded. 
the `preg_match` fx properly looks for special chars. 
fatal error? = inconsistent use of HTTP methods. 
- we see preg_match filters only for special chars in POST with `$_POST` 
- however the final `system` command uses the `$_REQUEST['filename']` var which covers both `GET` and `POST` params. 

Thus, in prev section when we were sending our malicious input through a `GET` request it did not get stopped by the `preg_match` function as the `POST` params were empty and hence did not contain any special characters 
- once we reach `system` it used any params found in the request and our `GET` params were used in the command eventually leading to command injection 

Minor inconsistencies in http methods can lead to critical vulnerabilities. 
In a production webapplication these types of vulns will not be as obvious and would likely be spread across the webapp and will not be on two consecutive lines like we have in the aebove example 
- More likely: 
	- Special fx for checking for injections 
	- Different fx for creating files
	- Separation of code makes it more difficult to catch these kinds of inconsistencies 

*Moral of the story here is to be consistent with the use of HTTP methods*
- Ensure same method used for any specific functionality across the webapplication 
- Always advised to expand the scope of testing in security filters by testing all request parameters 

|Language|Function|
|---|---|
|PHP|`$_REQUEST['param']`|
|Java|`request.getParameter('param')`|
|C#|`Request['param']`|
