Exploiting an Exposed Swagger File to Achieve RCE
A publicly exposed Swagger file revealed API endpoints, one of which lacked authorization checks and allowed reading arbitrary files. The attacker read the application configuration file, obtained JWT, database and Hangfire credentials, and used them to gain administrative access and ultimately execute system commands on the server.
medium.com
Published on medium.com
During a recent black-box penetration test, we discovered a publicly exposed Swagger file. This led us down a path of exploitation, uncovering multiple critical vulnerabilities, including broken access control, local file disclosure, sensitive information exposure, and ultimately, remote code execution (RCE).
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could read sensitive configuration files, obtain credentials, gain administrative access to the application and database, and achieve remote code execution on the server.
What the attacker needed
Swagger file publicly accessible; No authentication required for the endpoint
How it was found
- Find the exposed Swagger endpoint that documents the API.
- Test the attachment download endpoint and notice it lacks authorization checks.
- Use the path parameter to read the web.config file, then appsettings.json.
- Extract JWT, MSSQL and Hangfire credentials from appsettings.json.
- Log in to the Hangfire dashboard with the found credentials.
- Connect to MSSQL with the found credentials and enable xp_cmdshell to run system commands.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A Swagger file is like a public map of a website's API, showing all the doors and what they expect. One door (an endpoint) did not check who was allowed to use it, so the tester could ask it to read any file on the server. That file contained passwords, which then let the tester take over the database and run commands on the machine.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.