Skip to content
RCE Disclosed report Intermediate

Admin Command Injection via username in user_archive ExportCsvFile

An admin could inject shell commands through a username because the username was placed unescaped inside a backtick command used to gzip a user export file. This allowed the admin to run arbitrary commands on the server, escalating to remote code execution.

ziot Follow

Originally disclosed on HackerOne

Bounty$512 High View original
  • Fixed in under an hour
  • Paid in under an hour
  • Disclosed after 58 days

When a user generates a backup of their posts, their username gets sent to the ExportCsvFile job. The username is placed inside of a gzip command in backticks. Although the application prevents special characters in usernames, an admin is able to make modifications to the database via the restore from backup feature. This allows an admin to escalate to command injection.

Steps

  1. Login as an admin on try.discourse.org, e.g.
  1. Make a backup of the website and download it.
  2. Extract the contents of the archive.
  3. Modify one of the usernames of an account you have access to:
  • test.txt;wget mrzioto.com
  1. Repackage the archive.
  2. Upload the modified archive.
  3. Restore from backup.
  4. Log into the account you just modified (you can login via email address, so the special characters won't prevent you from logging into it).
  5. Send the POST request for creating a user export archive:
  1. ---> You forced the server to make a wget leading to RCE/command injection.

Code Flow

      file_name_prefix = if @entity == "user_archive"
        "#{@entity.split('_').join('-')}-#{@current_user.username}-#{Time.now.strftime("%y%m%d-%H%M%S")}"

      file_name = "#{file_name_prefix}-#{file.id}.csv"
      absolute_path = "#{UserExport.base_directory}/#{file_name}"

      `gzip -5 #{absolute_path}`

The original report as published on HackerOne, by ziot. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application used backticks to run a shell command and interpolated the username directly into it without escaping, allowing command injection.

Impact

An admin could execute arbitrary commands on the server, leading to remote code execution.

What the attacker needed

Admin access to the application; ability to restore from backup

How it was found

  1. Log in as an admin on the test site.
  2. Create and download a backup of the website.
  3. Extract the backup archive.
  4. Modify a username in the backup to include a shell command.
  5. Repackage and upload the modified archive, then restore from backup.
  6. Log into the modified account and send a request to create a user export archive, triggering the command.

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 report has not been written yet. The Original tab links to the source.

When a user asks for a backup of their posts, the server runs a command to compress a file. The username is inserted directly into that command without cleaning it. An admin can change a username to include extra shell instructions, so the server runs those instructions too, giving the attacker control over 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.

More by ziot

View all

6 more disclosed reports, best first.

More from Discourse

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.