Discourse SNS webhook RCE
Discourse's unauthenticated AWS SNS webhook handler passed an attacker-influenced SubscribeURL to Ruby's open, which executes shell commands when the value starts with a pipe. A signature-check bypass using a crafted SigningCertURL pointing at an AWS SNS API response containing a certificate let an attacker supply a validly signed message and gain remote command execution.
Published on 0day.click
I was staring at this part of the code for way too long already:
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 code passed a webhook-supplied URL to Ruby's open, which treats a leading pipe as a shell command, and the signature check could be satisfied with a certificate fetched from an AWS API response rather than a genuine SNS signing certificate.
Impact
An unauthenticated attacker could run arbitrary commands on any Discourse instance, as demonstrated against the public try instance.
What the attacker needed
Network access to the webhook endpoint; an AWS account to sign the API URL
How it was found
- Send a POST request to the instance's AWS webhook endpoint with a signed JSON body.
- The body's SubscribeURL value begins with a pipe, so open runs it as a shell command.
- The SigningCertURL points to a signed AWS SNS API URL that returns a certificate in its response.
- The signature check downloads that certificate and accepts the message.
- The server executes the command and the attacker gets a shell.
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.
Discourse accepts messages from Amazon's notification service at a public web address. It then opens a link from that message, and in Ruby opening a link that begins with a pipe character runs a shell command instead. The report also found a way to make the signature check pass without Amazon's real key, so anyone could send such a message.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.