// write-up
HTTP Parameter Pollution
My notes about HPP
Category: [Server-Side / Client-Side]
Severity: [Low to Medium / High to Critical (chained)]
Impact: [Security Control & WAF Bypass, Authentication & Authorization Bypass, Business Logic Flaw, Injection Escalation, Cache Pollution]
Definition
HTTP Parameter Pollution is the process of manipulating how a website treats the parameters it receives during HTTP requests. the vulnerability occurs when an attacker injects extra parameters into http request and the target trusts them, leading to unexpected behavior. It can be both server-side and client-side, HPP depends on how server-side code uses the parameters.
Server-Side HPP
In server-side HPP, you send the server unexpected information to test whether you can receive unexpected results or not. When you send a request to server, it processes the request and return a response, the response may be the output of a code or function which executed to process your request, so server may run a code based on information you send to it. you can see the information you see and get the results, but the code in between is invisible to you.
Example: a bank using three parameters to transfer money: from to amount
so the URL will look like this:
https://bank.com/transfer?from=123456&to=abcdef&amount=5000
the server processes the request and send 5000$ from account 123456 to account abcdef.
Attacker may simply changes the value of from and to to transfer the money to another account illegitimately.
In some cases server may not use a to (or something like that) parameter, so the URL will be something like this:
https://bank.com/transfer?from=123456&amount=5000
but what happens if we put 2 from parameters? like this:
https://bank.com/transfer?from=123456&amount=5000&from=ABCDEF
In this situations server may use the first from parameter which is 123456 to validate the transfer destination but transfer the money to the second from parameter which is ABCDEF.
When a server receives multiple parameters with the same name, it may have a variety of responses:
- Uses the first parameter
- Uses the last parameter
- Uses both of them
- Rejects the request
In some cases, HPP may occur as a result of a hidden server-side behavior from code that isn’t directly visible.
For example: The bank decided not to use from parameter directly in URL, so it becomes invisible to us, imagine that the backend-server uses the following Ruby code for transfer operation:
user.account = 123456
def prepare_transfer(params):
params << user.account
transfer_money(params) # user.account (123456) becomes params[2]
end
def transfer_money(params):
to = params[0]
amount = params[1]
from = params[2]
transfer(to, amount, from)
end
This code creates two functions prepare_transfer & transfer_money. the prepare_transfer function takes an array called params which contains to and amount values from URL and add user.account that is user account ID to the end of params array, for example here:
https://bank.com/transfer?to=67890&amount=5000
The array will be something like this:
[67890, 5000, 123456]
Then params passed to transfer_money, it sets to parameter to params[0] which is 67890, amount to params[1] which is 5000 and from to params[2] which is 123456, Logically, web application is using the from parameter inside the back-end code, but what happens if an attacker pass the from parameter directly in URL like this:
https://bank.com/transfer?to=67890&amount=5000&from=ABCDEF
The result will made the array to look like this:
[67890, 5000, ABCDEF, 123456]
Consequently, params[2] which is supposed to defines from parameter will be ABCDEF, because 123456 will be added to the END of array. As a result, money will transfer from ABCDEF and not 123456.
Client-Side HPP
Client-side HPP allow attackers to inject extra parameters into a URL to create effects on a user’s end. For example, consider the following server-side code:
<? $val = htmlspecialchars($_GET['par'],ENT_QUOTES); ?>
<a href="page.php?action=view&par='.<?=$val?>'">View Me!</a>
In the code above, if attacker use this URL:
https://host/page.php?par=123%26action=edit
The attacker passes the value par=123%26action=edit as the value for par to generate an additional, unintended parameter.
%26 = & -> URL-encoded
This is mean when URL is parsed, %26 is interpreted as &, this adds an extra parameter to server-side code which gives the attacker edit access. the URL with injected URL will sit in href attribute’s value, and then, attacker click it and edit what they want.
If we used 123&action=edit instead of using URL-encoded of &, php would interpret them as 2 separate parameters:
$_GET['par'] = "123"
$_GET['action'] = "edit"
But we used the URL-encoded version, so php will interprets it like this:
$_GET['par'] = "123&action=edit"
Another reason is htmlspecialchars will turn & into &:
<a href="page.php?action=view&par='123&action=edit'">View Me!</a>
URL:
page.php?action=view&par='123&action=edit'
Consequently, we use URL-encoded version of it :)
Real-World examples
HackerOne Social Sharing Buttons One way to find HPP is to look for links that appear to contact other services. HackerOne blog posts do just that by including links to share content on some social media like Facebook, Twitter, etc. When clicked, these links generate content for the user to publish on social media. the published content includes a URL reference to original blog post. a hacker discovers a bug that let you add a parameter which points to another URL, exactly like this:
https://facebook.com.?u=https://hackerone.com/blog/post1/?&u=https://evil.com
In addition to this, when posting on twitter, hackerone includes a default tweet text, attackers could also manipulate this text by adding &text= in URL, like this:
https://hackerone.com/blog/post1/?&u=https://evil.com&text=some_text