Search K
Appearance
Appearance
Other ways to support HackTricks:
If an attacker can control a subdomain or the domain of a company or finds an XSS in a subdomain he will be able to perform this attack.
As it was indicated in the Cookies Hacking section, when a cookie is set to a domain (specifying it) it will be used in the domain and subdomains.
โ
Therefore, an attacker is going to be able to set to the domain and subdomains a specific cookie doing something like document.cookie="session=1234; Path=/app/login; domain=.example.com"
This can be dangerous as the attacker may be able to:
When a browser receives two cookies with the same name partially affecting the same scope (domain, subdomains and path), the browser will send both values of the cookie when both are valid for the request.
Depending on who has the most specific path or which one is the oldest one, the browser will set the value of the cookie first and then the value of the other one like in: Cookie: iduser=MoreSpecificAndOldestCookie; iduser=LessSpecific;
Most websites will only use the first value. Then, if an attacker wants to set a cookie it's better to set it before another one is set or set it with a more specific path.
โ ๏ธ
Moreover, the capability to set a cookie in a more specific path is very interesting as you will be able to make the victim work with his cookie except in the specific path where the malicious cookie set will be sent before.
Possible protection against this attack would be that the web server won't accept requests with two cookies with the same name but two different values.
To bypass the scenario where the attacker is setting a cookie after the victim was already given the cookie, the attacker could cause a cookie overflow and then, once the legit cookie is deleted, set the malicious one.
Another useful bypass could be to URL encode the name of the cookie as some protections check for 2 cookies with the same name in a request and then the server will decode the names of the cookies.
A Cookie Tossing attack may also be used to perform a Cookie Bomb attack:
__Host
in the cookie name โOther ways to support HackTricks: