From self XSS to RCE in Ruby on rails
A stored self-XSS in a profile field was escalated to remote code execution because the application rendered pages as PDFs using a Ruby on Rails wrapper that executed inline Ruby code embedded in the HTML. An attacker could run arbitrary commands on the server and access sensitive files from other projects.
Published on handball10.medium.com
Hey there, this is my first blog post here about a recent interesting finding I came accross on a private bug bounty target.
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
Root cause
Likely the application passed user-controlled HTML to a PDF renderer that evaluated inline Ruby code, and the same inline Ruby was also executed when rendering the profile page directly.
Impact
An attacker could execute arbitrary commands on the server and access sensitive files from other projects hosted on the same server.
What the attacker needed
A user account; ability to set first name; victim (or attacker) requests .pdf URL
How it was found
- Found a stored self-XSS in the first name profile field.
- Discovered that appending .pdf to a URL returned the page as a PDF.
- Confirmed the self-XSS payload was rendered inside the generated PDF.
- Injected inline Ruby tags into the profile field and saw server time printed in the PDF.
- Used inline Ruby to execute system commands and list files on the server.
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.
The profile page allowed a user to save a script that only ran in their own browser (self-XSS). When the site turned that page into a PDF, it also ran Ruby code hidden in the page, letting the attacker run commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.