Exploiting CORS
Last updated
Last updated
Assume a website has insecure CORS configuration that trusts all origins, attacker can craft a malicious HTML to lure the victim to click and extract sensitive information and sent to attacker.
Here is one example from portswigger:
A login user visit /accountDetails
is allowed to get a respond of the user details including apikey and sessions.
If we add any origin for testing, the response will show the origin is allowed.
With this, it has no restriction of javascript origin, we can craft a malicious html page embedded with javascript to steal the respond in accountDetails
After the victim click the link and visit the sites
The logs will store the api keys
Some applications have a whitelisted origins, When a CORS request being made, the server origin is compared to the whitelist, if the origin appears on the whitelists then it reflected in the Access-Control-Allow-origin
header so that the access is granted.
E.g.
The application checks the supplied origin against its list of allowed origins and, if it is on the list, reflects the origin as follows:
Some mistakes when implementing CORS origin whitelists is some organization decide to allow access from all their subdomains e.g. *normal.sites .
An attacker might be able to gain access by registering the domain:
hackerman-normal.sites
The specification for the Origin header supports the value Null
. Browser might send the value null
in the Origin header in various unusual situations:
Cross-origin redirects
Requests from seralized data
Request using the file:
protocol
Sandboxed cross-origin requests
One of the technique is using iframe sandbox, it isolated the iframe
freom the rest of the web context, stripping away any traditional origin and set the origin to null
We modified the previous payload to include a iframe:
With this new payload, it can effective send a null origin iframe that trigger the javascript.
Even "correctly" configured CORS establishes a trust relationship.
If a website trusts an origin that is vulnerable to cross-site scripting (XSS), then an attacker could exploit the XSS to inject some JavaScript that uses CORS to retrieve sensitive information from the site that trusts the vulnerable application.
Ik0nw