CORS vulnerability with trusted null origin
Description
This website has an insecure CORS configuration in that it trusts the "null" origin.
To solve the lab, craft some JavaScript that uses CORS to retrieve the administrator's API key and upload the code to your exploit server. The lab is solved when you successfully submit the administrator's API key.
You can log in to your own account using the following credentials: wiener:peter
Approach
First, I turned on the FoxyProxy extension to proxy all requests through Burp Suite and started navigating the site after logging in as the user "wiener." In Burp Suite's HTTP History, I noticed an interesting request:
This was the response:
The Access-Control-Allow-Credentials
header caught my attention as it indicates the use of CORS. To confirm this, I added the Origin
header to the request and sent it:
Nothing changed, and the Access-Control-Allow-Origin
header wasn't present in the response, indicating that the provided origin isn't allowed to access the resources on this website. However, when I tried a null origin, I did get that header in the response, which indicates that requests with Origin: null
are allowed to access the resources on this website:
the response was:
This means that in my exploit, the request needs to have null
as an origin. To achieve that, I used a sandboxed iframe cross-origin request:
The use of a data:
URL in conjunction with the iframe's sandbox attribute naturally results in the Origin
header being null
. The exploit will be an iframe containing JavaScript code that accesses the vulnerable website with the origin set to null
. Since the Access-Control-Allow-Credentials: true
header is already set in the response, it means that the response will be session-based, so the victim's cookies and session will be used, and the response will contain their information.
By simply clicking "Store" and "Deliver exploit to victim" and accessing the log, I could see a URL-encoded request. When decoded in Burp Suite's Decoder, the data was as follows:
By submitting the API key of the administrator, the lab is solved.